Species metapopulation model

Species metapopulation model preview image

1 collaborator

Default-person Matthew Reynolds (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by everyone
Model was written in NetLogo 6.1.1 • Viewed 25 times • Downloaded 2 times • Run 0 times
Download the 'Species metapopulation model' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

;; Metapopulation simulation v1.0 - Jon Bennie 03/08/2020
;; any lines starting with semicolons are comments and are ignored by Netlogo

;; this "globals" command just defines any variables that are used throughout the whole code and are not specified in the graphical interface

;-----------------------------------------------------------

globals [Generations ButterflyPopulation OccupiedHabitats HabitatsOccupied MyList CapacityTotal] ; MR: Added relevant things to here.


;; this section just defines the types of 'agent' or 'object' - called 'turtles' in Netlogo - that can interact in the model
;; here we just tell Netlogo that we have things called butterflies (singular butterfly) and habitats (singular habitats)
breed [butterflies butterfly]
breed [habitats habitat]

;; this defines characteristics of the agents - eg. each habitat has a capacity (size) and occupancy (occupied or not)
;; by default all 'turtles' already have some characteristics - eg. shape, colour, size etc...
habitats-own [capacity occupancy]

;; this section (from 'to setup' up to 'end') is called every time you click the setup button on the interface
;; it clears the screen, creates 10 habitat [patches], and specifies the colour, shape, capacity and location in space of each one
;; the capacity of each patch is between 1 and 5 (random 4 creates a random number between 0 and 4, then it adds one)
;; initially all patches are coloured white and occupied
;; the location is set by x and y coordinates, which are randomised
;; it also resets the count of generations and refreshes the display

to setup
  clear-turtles
  set MyList n-values Number_of_habitats [random 100000000000 + 1]  ; MR: This is where I have changed the random number to that big number rather than 10, also creating a list.
  set CapacityTotal sum(mylist)
  create-habitats Number_of_habitats [
       set capacity one-of MyList
          set mylist remove(capacity) MyList
       set shape "flower"
       set color yellow
       set size ((capacity) * (total_size_of_all_habitats / CapacityTotal))
       setxy random-xcor random-ycor
       set occupancy 1
  ]
  set Generations 0
display
end 

;----------------------------------------------------

;; this section is called when you click the 'disperse button, or in continuous mode each generation
;; it update the number of generations, and 'asks' each habitat patch that is occupied to hatch new butterflies
;; the number of butterflies is the capacity (1-5) times 10
;; turns out netlogo has an inbuilt defined shape called "butterfly", so I used that and coloured them blue
;; then it calls the "move" section (details below) 100 times before killing them off

to disperse
  set Generations Generations + 1
  ask habitats with [occupancy = 1] [
    hatch-butterflies size * random 9 + 1
    [set size 1.5
    set shape "butterfly"
    set color blue
    ]
  ]
  repeat 100 [move]
  set OccupiedHabitats count habitats with [occupancy = 1]
  set HabitatsOccupied habitats with [occupancy = 1]
  ;set ButterflyPopulation ((sum [size] of HabitatsOccupied) + (count butterflies))
  set ButterflyPopulation count butterflies
  ask butterflies [die]
end 

;; this section defines how butterflies move in each time step.
;; each butterfly turns right a random angle, then left a random angle
;; then moves forward one unit
;; then each butterfly 'asks' any habitat that it is on to become occupied (and turn white if it isn't already)

to move
    ask butterflies [
    rt random 18
    lt random 10
    fd 1
    ask habitats-here [
      set occupancy 1
      set color yellow
    ]
  ]
end 

;; this section is triggered when you click "extinction" or in continuous mode
;; it 'asks' each occupied habitat patch to think of a random number between 0 and 100
;; if this number is lower than (100 / capacity) then the habitat patch goes extinct (occupancy set to zero) and turns blue
;; so patch size 1 goes extinct 100% of the time (every time step) and patch size 5 goes extinct 20% of the time (on average every 5 timesteps)

to extinction
  ask habitats with [occupancy = 1] [
    if random 100 < 100 / size [
      set occupancy 0
      set color brown
    ]
  ]
end 

;; this section is triggered when you click the "continuous" button
;; it just checks to see if all habitat is empty - if so then it stops the simulation
;; otherwise it keeps repeating the dispersal and extinction procedure and updates the landscape forever...
;; it might be useful to put an on/off switch here somewhere if you can figure out how to do it!

to continuous
  loop [
    disperse
    extinction
    update-plots
    export-plot "Plot to show the population of butterflies over time" "plot.csv" ; MR: This is the part of the code that, as expected, exports the results of the plot. It overwrites the file 'plots.csv' each time.
    export-world "results.csv" ; MR: This is the section of code that if uncommented doesn't terminate the model once the population of the butterflies hits zero (I believe the line above to do the same).
    if all? habitats [occupancy = 0] [stop]
    ]
  reset-ticks
end 

There is only one version of this model, created 3 months ago by Matthew Reynolds.

Attached files

File Type Description Last updated
Species metapopulation model.png preview Preview for 'Species metapopulation model' 3 months ago, by Matthew Reynolds Download

This model does not have any ancestors.

This model does not have any descendants.