Coral Reef Simulation
Model was written in NetLogo 6.4.0
•
Viewed 13 times
•
Downloaded 0 times
•
Run 0 times
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
Info tab cannot be displayed because of an encoding error
Comments and Questions
Please start the discussion about this model!
(You'll first need to log in.)
Click to Run Model
; set up the agents breed [ clams clam ] breed [ pfishes pfish ] breed [ larvae larva ] breed [ butterflyfishes butterflyfish ] breed [ sharks shark ] turtles-own [ energy ] ; all agent will have a parameter energy patches-own [ coral-growth neighbor-factor ind-growth-rate ] globals [ clam-energy-max bfish-energy-max pfish-energy-max shark-energy-max coral-maturity-size dynamite-fishing-event-tick ] to setup clear-all clear-output print "Let's simulate a small reef !" ; globals parameters definition set clam-energy-max 100 set bfish-energy-max 150 set pfish-energy-max 500 set shark-energy-max 1000 set coral-maturity-size 100 set dynamite-fishing-event-tick random time-before-explosion ; environment definition setup-background setup-coral-blobs setup-larvae setup-planktivore setup-pfishes reset-ticks end to go ; stopping conditions: if ticks > 10000 [user-message "10,000 ticks reached" stop] if all? patches [pcolor = 49] [user-message "All the coral is dead, it's the end of the world !"] if (count pfishes + count butterflyfishes) >= ecosystem-capacity and count sharks = 0 [ setup-sharks print "All these fishes have attracted sharks !"] ask larvae [ move-larvae set energy energy - random-float 1 ; at each step, deduct 1 point of energy if random-float 1 < 0.1 [ settle ] death ] ask pfishes [ move-pfishes set energy energy - random 5 ; at each step, deduct 5 points of energy because a fish need more energy to swim if energy <= pfish-energy-max and random-float 1 < 0.3 [ eat-coral ] reproduce-pfish death ] if count pfishes <= 1 [ if random-float 1 < 0.001 [ create-pfishes 1 [ setxy random-xcor random-ycor set shape "parrot fish" set color cyan set size 15 set energy random (parrotfish-energy / 2) + (parrotfish-energy / 2) ] print "A parrot fish has been attracted." ] ] ask sharks [ move-shark set energy energy - 20 if energy <= shark-energy-max and random-float 1 < 0.5 [ eat-fish] death ] ask patches with [pcolor = orange or pcolor = 116 or pcolor = green] [ grow if random-float 1 < 0.0005 [ seed-new-coral self] ; check maturity if coral-growth < 0 [ set coral-growth 0 ] ; cannot be negative if coral-growth > 0 and coral-growth <= 100 [ set pcolor orange ] if coral-growth >= coral-maturity-size [ set pcolor 116 ] ; mature coral turns purple if coral-growth = 0 [ set pcolor 49 set ind-growth-rate 0 ] hatch-larvae_ ] if Planktivores [ ask butterflyfishes[ if energy <= bfish-energy-max and random-float 1 < 0.3 [ butterflyfish-eats-larvae ] move-bfishes set energy energy - ( random 2 ) ; smaller than a parrot fish thus movement costs less energy reproduce-bfish death ] ask clams [ if energy <= clam-energy-max and random-float 1 < 0.8 [ clam-eats-larvae ] set energy energy - (random-float 1 ) reproduce-clam death ] if Planktivore-species = "butterflyfishes" or Planktivore-species = "both" [ if (count butterflyfishes) <= 1 [ if random-float 1 < 0.001 [ create-butterflyfishes 1 [ set shape "butterflyfish" set color green set size 15 set energy random (bfish-energy-max / 2) + (bfish-energy-max / 2) setxy random-xcor random-ycor ] print "A butterflyfish has been attracted." ] ] ] if Planktivore-species = "clams" or Planktivore-species = "both" [ if (count clams) = 0 [ if random-float 1 < 0.001 [ let eligible-patches patches with [ (pcolor = orange or pcolor = 116) and count neighbors with [pcolor = orange or pcolor = 116] >= 4 ] if any? eligible-patches [ ask n-of 1 eligible-patches [ sprout-clams 1 [ set shape "giant clam" set color 107 set size 18 set energy random (clam-energy-max / 2) + (clam-energy-max / 2)]] ] print "A giant clam has just settled." ] ] ] ] ; Define the threats if Global-warming and (ticks mod 50 = 0) [ ; global-warming significantly decrease the growth rate but progressively ask patches with [pcolor = orange or pcolor = 116] [ if random-float 1 < 0.2 [ ; 20% chance per patch every 50 ticks set ind-growth-rate ind-growth-rate * (1 - random-float 0.05 - 0.025) ; cap at a minimum value to prevent collapse if ind-growth-rate < 0.01 [ set ind-growth-rate 0.01 ] ] ] ] if Acidification [ ; acidification significantly decrease the size of coral (make it harder to reach maturity and then die) but progressively ask patches with [pcolor = orange or pcolor = 116] [ if random-float 1 < 0.005 [ set coral-growth coral-growth * (1 - random-float 0.05 )] if coral-growth < 0.01 [ set coral-growth 0] ] ] if Dynamite-fishing and (ticks = dynamite-fishing-event-tick) [ ; Destroy most of the grid ask patches [ if random-float 1 < 0.5 [ ; 50% chance to destroy each patch set pcolor 49 ; sand set coral-growth 0 set ind-growth-rate 0 ] ] ; Kill all agents ask turtles [ if random-float 1 < 0.7 [ die ] ] user-message "Oh no! Your reef has been dynamited!" ; schedule next event set dynamite-fishing-event-tick ticks + round( random (time-before-explosion / 2 ) + (time-before-explosion / 2 ) ) print (word "Next explosion at tick: " dynamite-fishing-event-tick) ] tick end to setup-background ; Set sandy background ask patches [ set pcolor 49] end to setup-coral-blobs repeat number-of-blobs [ let cx random-xcor ;cx and cy for the center of the blob let cy random-ycor ask patches [ let dx_ abs (pxcor - cx) ; dx_ and dy_ are the absolute value from the patch to the center of the current blob let dy_ abs (pycor - cy) let dist sqrt (dx_ * dx_ + dy_ * dy_) ; euclidean distance from the patch to the blob center let noise random-float 1.3 - 0.5 ; add randomness to the distance of the plot to make it more irregular and with a more "organic" shape let dist-fuzzed dist + noise ; apply the noise/randomness to the distance ; to pick an overall round shape let blob-size random (blob-radius / 2) + 2 * (blob-radius / 2) if dist-fuzzed <= blob-size [ let edge-factor 1 - (dist-fuzzed / blob-size) if random-float 1 < (edge-factor ^ 1.2) [ set coral-growth random (reef-age / 2) + (reef-age / 2) ifelse coral-growth = 0 [ set pcolor 49] [ set pcolor orange] set ind-growth-rate random-float (coral-growth-rate / 2) + (coral-growth-rate / 2) if coral-growth >= coral-maturity-size [ set pcolor 116 ] ] ] ] ] end to setup-larvae create-larvae Nb-larvae [ setxy random-xcor random-ycor set color gray set size 3 set energy random ((larva-energy / 2)) + ((larva-energy / 2)) ; when a larvae is created its energy level take a random value between [Larva-energy/2 ; Larva-energy] ] end to setup-pfishes create-pfishes Nb-parrotfishes [ setxy random-xcor random-ycor set shape "parrot fish" set color cyan set size 15 set energy random (parrotfish-energy / 2) + (parrotfish-energy / 2) ] end to setup-planktivore if Planktivores [ if Planktivore-species = "clams" [ let eligible-patches patches with [ (pcolor = orange or pcolor = 116) and count neighbors with [pcolor = orange or pcolor = 116] >= 4 ] if any? eligible-patches [ ask n-of Nb-clams eligible-patches [ sprout-clams 1 [ set shape "giant clam" set color 107 set size 18 set energy random (clam-energy-max / 2) + (clam-energy-max / 2) ] ] ] ] if Planktivore-species = "butterflyfishes" [ create-butterflyfishes Nb-butterflyfishes [ set shape "butterflyfish" set color green set size 15 set energy random (bfish-energy-max / 2) + (bfish-energy-max / 2) setxy random-xcor random-ycor ] ] if Planktivore-species = "both" [ let eligible-patches patches with [ (pcolor = orange or pcolor = 116) and count neighbors with [pcolor = orange or pcolor = 116] >= 4 ] if any? eligible-patches [ ask n-of Nb-clams eligible-patches [ sprout-clams 1 [ set shape "giant clam" set color 107 set size 18 set energy random (clam-energy-max / 2) + (clam-energy-max / 2)] ] ] create-butterflyfishes Nb-butterflyfishes [ set shape "butterflyfish" set color green set size 15 setxy random-xcor random-ycor set energy random (bfish-energy-max / 2) + (bfish-energy-max / 2) ] ] ] end to setup-sharks create-sharks random Nb-sharks [ set shape "shark" set color gray set size 30 set energy random (shark-energy-max / 2) + (shark-energy-max / 2) setxy random-xcor random-ycor ] ; ] end to grow ; make the coral grow and adding a neighbor factor to mimic competition let neighbor-coral count neighbors with [pcolor = orange or pcolor = 116 or pcolor = green] ; calculate neighbor influence with competition set neighbor-factor 1 ; default value if member? neighbor-coral [1 2 3 ] [ set neighbor-factor 1.05] ; when few neighbor the growth is boosted if member? neighbor-coral [4 5 6 7 8] [ set neighbor-factor 0.8 ] ; when too many neighbor, the growth is slow down because of competition ; ensure neighbor-factor stays positive (so growth can't go negative) if neighbor-factor < 0 [ set neighbor-factor 0 ] ; apply growth ifelse ind-growth-rate = 0 [ set coral-growth coral-growth ] [ if ind-growth-rate > 0 [ set coral-growth coral-growth + (ind-growth-rate * neighbor-factor) ] ] end to seed-new-coral [origin] let target-patch one-of neighbors if target-patch != nobody [ ask target-patch [ ; if there is already coral, high chance (50 %) to have a growth boost ifelse pcolor = orange or pcolor = 116 or pcolor = green [ if random-float 1 < 0.5 [ set coral-growth coral-growth + random 5 ] ] [ if pcolor = 49 [ ; low probability (30%) to establish on sand if random-float 1 < 0.3 [ set pcolor orange set coral-growth 0.1 set ind-growth-rate random-float (coral-growth-rate / 2) + (coral-growth-rate / 2) ] ] ] ] ] end to hatch-larvae_ if pcolor = 116 [ ifelse Full-moon [ if ticks mod 150 = 0 and random-float 1 < (spawning-frequency * 1.8) [ sprout random (Nb-larvae-produced / 2) + (Nb-larvae-produced / 2) [ set breed larvae set color grey set size 3 set energy random (larva-energy / 2) + (larva-energy / 2) rt random 360 fd 1 ] ] ] [ if random-float 1 < (spawning-frequency / 100) [ sprout random (Nb-larvae-produced / 2) + (Nb-larvae-produced / 2) [ set breed larvae set color grey set size 3 set energy random (larva-energy / 2) + (larva-energy / 2) rt random 360 fd 1 ] ] ] ] end to move-larvae ; movement right random 360 ; turn a random number of degrees between 1 and 359 forward 1 ; move forward 1 step end to settle ifelse pcolor = orange or pcolor = 116 [ if random-float 1 < 0.05 [ set ind-growth-rate ind-growth-rate + random-float 0.1 set color orange die ; the larvae disappear after settlement ] ] [ if pcolor = 49 [ if random-float 1 < 0.3 [ set pcolor orange set coral-growth 0.01 set ind-growth-rate ind-growth-rate + (random-float (coral-growth-rate / 2) + (coral-growth-rate / 2)) die ] ] ] end to move-pfishes ifelse random-float 1 < 0.1 [ let nearby-coral patches in-radius 50 with [pcolor = orange or pcolor = 116] if any? nearby-coral [ let target min-one-of nearby-coral [distance myself] face target fd 1 ] ; move toward coral ] [ ; random movement rt random 50 lt random 50 fd 1 ] ; move forward 1 step end to move-bfishes ifelse random-float 1 < 0.1 [ let nearby-larvae larvae in-radius 50 if any? nearby-larvae [ let target min-one-of nearby-larvae [distance myself] face target fd 1 ] ; move toward larvae ] [ ; random movement rt random 50 lt random 50 fd 1 ] ; move forward 1 step end to move-shark ifelse random-float 1 < 0.3 [ let nearby-fish turtles in-radius 30 with [ breed = butterflyfishes or breed = pfishes ] if any? nearby-fish [ let target min-one-of nearby-fish[distance myself] face target fd 3 ] ; move toward fish, sharks are fast ] [ ; random movement rt random 50 lt random 50 fd 2 ] ; move forward 2 steps because sharks are fast end to eat-coral if pcolor = orange or pcolor = 116 [ let nearby-coral-fish patches in-radius 3 with [pcolor = orange or pcolor = 116] ; For each nearby coral patch: ask nearby-coral-fish [ ; Fish gains energy from each coral patch ; Coral loses growth set coral-growth coral-growth - (random (energy-gain-from-coral / 2) + (energy-gain-from-coral / 2))] set energy energy + (random (energy-gain-from-coral / 2) + (energy-gain-from-coral / 2)) ] end to clam-eats-larvae let clam-prey larvae in-radius 12 ; Clams eat larvae within radius 12 if any? clam-prey [ ask clam-prey [ die ] set energy energy + (random (larva-energy / 2) + (larva-energy / 2)) ] end to butterflyfish-eats-larvae let bfish-prey larvae in-radius 4 ; Butterflyfish eat larvae within radius 4 because they can move and are fast if any? bfish-prey [ ask bfish-prey [ die ] set energy energy + (random-float (larva-energy / 2) + (larva-energy / 2)) ] end to eat-fish let prey-pool turtles in-radius 3 with [ breed = butterflyfishes or breed = pfishes ] if any? prey-pool [ let prey one-of prey-pool set energy energy + (random ([energy] of prey) / 2 + ([energy] of prey) / 2 ) ask prey [ die ] ] end to reproduce-clam let eligible-patches patches with [ (pcolor = orange or pcolor = 116) and count neighbors with [pcolor = orange or pcolor = 116] >= 4 ] if any? eligible-patches in-radius 90 [ if random-float 100 < (clam-reproduction / 100 ) [ set energy energy / 2 ask one-of eligible-patches [ sprout-clams 1 [ set shape "giant clam" set color 107 set size 18 set energy random (clam-energy-max / 2) + (clam-energy-max / 2) ] ] ] ] end to reproduce-bfish if count butterflyfishes in-radius 30 >= 2 [ if random-float 100 < (bfish-reproduction / 100 ) [ set energy energy / 2 hatch 1 [ set breed butterflyfishes set shape "butterflyfish" set color green set size 15 set energy random (bfish-energy-max / 2) + (bfish-energy-max / 2) rt random 360 fd 1 ] ] ] end to reproduce-pfish if count pfishes in-radius 30 >= 2 [ if random-float 100 < (pfish-reproduction / 100 ) [ set energy energy / 2 hatch 1 [ set breed pfishes set shape "parrot fish" set color cyan set size 15 set energy random (pfish-energy-max / 2) + (pfish-energy-max / 2) rt random 360 fd 1 ] ] ] end to death ; turtle procedure (i.e. all agents will have this propriety). ; when energy dips below zero, die if energy < 0 [ die ] end ;;;;;;;;;;;;;;;;;;;;;;
There is only one version of this model, created 6 days ago by Claire P..
This model does not have any ancestors.
This model does not have any descendants.