globals [ ticks ] breeds [ sheep wolves ] turtles-own [ energy ] sheep-own [ grabbed? ] ;; used to prevent two wolves from eating the same sheep patches-own [ countdown ] to setup ca set ticks 0 ask patches [ set pcolor green ] if grass? [ ;; indicates whether the grass switch is on ;; if it is true, then grass grows and the sheep eat it ;; if it false, then the sheep don't need to eat ask patches [ set countdown random grass-regrowth-time ;; initialize grass grow clocks randomly if (random 2) = 0 ;;half the patches start out with grass [ set pcolor brown ] ] ] set-default-shape sheep "sheep" create-custom-sheep initial-number-sheep ;; create the sheep, then initialize their variables [ set color white set label-color blue - 2 set energy random (2 * sheep-gain-from-food) setxy random-float screen-size-x random-float screen-size-y set grabbed? false ] set-default-shape wolves "wolf" create-custom-wolves initial-number-wolves ;; create the wolves, then initialize their variables [ set color black set energy random (2 * wolf-gain-from-food) setxy random-float screen-size-x random-float screen-size-y ] display-labels do-plot end to go ask sheep [ move if grass? [ set energy energy - 1 ;; deduct energy for sheep only if grass? switch is on eat-grass ] reproduce-sheep death ] ask wolves [ move set energy energy - 1 ;; wolves lose energy as they move catch-sheep reproduce-wolves death ] if grass? [ ask patches [ grow-grass ] ] do-plot ;; plot populations every 0.5 [ display-labels ] set ticks ticks + 1 if not any? turtles [ stop ] end to move ;; turtle procedure rt random-float 50 - random-float 50 fd 1 end to eat-grass ;; sheep procedure ;; sheep eat grass, turn the patch brown if pcolor = green [ stamp brown set energy energy + sheep-gain-from-food ;; sheep gain energy by eating ] end to reproduce-sheep ;; sheep procedure if random-float 100 < sheep-reproduce [ ;; throw "dice" to see if you will reproduce set energy (energy / 2) ;; divide energy between parent and offspring hatch 1 [ rt random-float 360 fd 1 ] ;; hatch an offspring and move it forward 1 step ] end to reproduce-wolves ;; wolf procedure if random-float 100 < wolf-reproduce [ ;; throw "dice" to see if you will reproduce set energy (energy / 2 ) ;; divide energy between parent and offspring hatch 1 [ rt random-float 360 fd 1 ] ;; hatch an offspring and move it forward 1 step ] end to catch-sheep ;; wolf procedure locals [prey] set prey random-one-of sheep-here ;; grab a random sheep with [not grabbed?] ;; that no one else is grabbing if prey != nobody ;; did we get one? if so, [ set grabbed?-of prey true ;; prevent other wolves from grabbing it ask prey [ die ] ;; kill it set energy energy + wolf-gain-from-food ] ;; get energy from eating end to death ;; turtle procedure ;; when energy dips below zero, die if energy < 0 [ die ] end to grow-grass ;; patch procedure ;; countdown on brown patches, if reach 0, grow some grass if pcolor = brown [ ifelse countdown <= 0 [ set pcolor green set countdown grass-regrowth-time ] [ set countdown (countdown - 1) ] ] end to do-plot set-current-plot "populations" set-current-plot-pen "sheep" plot count sheep set-current-plot-pen "wolves" plot count wolves if grass? [ set-current-plot-pen "grass / 4" plot count patches with [ pcolor = green ] / 4 ;; divide by four to keep it within similar ;; range as wolf and sheep populations ] end to display-labels ifelse show-energy? [ ifelse grass? [ ask turtles [ set label round energy ] ] [ ask wolves [ set label round energy ] ask sheep [ set label no-label ] ] ] [ ask turtles [ set label no-label ] ] end ; *** NetLogo Model Copyright Notice *** ; ; This model was created as part of the project: CONNECTED MATHEMATICS: ; MAKING SENSE OF COMPLEX PHENOMENA THROUGH BUILDING OBJECT-BASED PARALLEL ; MODELS (OBPML). The project gratefully acknowledges the support of the ; National Science Foundation (Applications of Advanced Technologies ; Program) -- grant numbers RED #9552950 and REC #9632612. ; ; Copyright 1998 by Uri Wilensky. All rights reserved. ; ; Permission to use, modify or redistribute this model is hereby granted, ; provided that both of the following requirements are followed: ; a) this copyright notice is included. ; b) this model will not be redistributed for profit without permission ; from Uri Wilensky. ; Contact Uri Wilensky for appropriate licenses for redistribution for ; profit. ; ; This model was converted to NetLogo as part of the project: ; PARTICIPATORY SIMULATIONS: NETWORK-BASED DESIGN FOR SYSTEMS LEARNING IN ; CLASSROOMS. The project gratefully acknowledges the support of the ; National Science Foundation (REPP program) -- grant number REC #9814682. ; Converted from StarLogoT to NetLogo, 2000. Updated 2002. ; ; To refer to this model in academic publications, please use: ; Wilensky, U. (1998). NetLogo Wolf Sheep Predation model. ; http://ccl.northwestern.edu/netlogo/models/WolfSheepPredation. ; Center for Connected Learning and Computer-Based Modeling, ; Northwestern University, Evanston, IL. ; ; In other publications, please use: ; Copyright 1998 by Uri Wilensky. All rights reserved. See ; http://ccl.northwestern.edu/netlogo/models/WolfSheepPredation ; for terms of use. ; ; *** End of NetLogo Model Copyright Notice *** @#$#@#$#@ GRAPHICS-WINDOW 350 10 688 369 20 20 8.0 1 14 1 1 1 CC-WINDOW 347 373 690 500 Command Center SLIDER 3 164 177 197 initial-number-sheep initial-number-sheep 0 250 82 1 1 NIL SLIDER 3 201 177 234 sheep-gain-from-food sheep-gain-from-food 0.0 50.0 4.0 1.0 1 NIL SLIDER 3 236 177 269 sheep-reproduce sheep-reproduce 1.0 20.0 4.0 1.0 1 % SLIDER 181 164 346 197 initial-number-wolves initial-number-wolves 0 250 49 1 1 NIL SLIDER 181 200 346 233 wolf-gain-from-food wolf-gain-from-food 0.0 100.0 20.0 1.0 1 NIL SLIDER 181 236 346 269 wolf-reproduce wolf-reproduce 0.0 20.0 5.0 1.0 1 % SWITCH 5 101 99 134 grass? grass? 1 1 -1000 SLIDER 106 102 318 135 grass-regrowth-time grass-regrowth-time 0 100 30 1 1 NIL BUTTON 8 42 77 75 setup setup NIL 1 T OBSERVER T BUTTON 90 42 157 75 go go T 1 T OBSERVER T PLOT 8 333 317 530 populations time pop. 0.0 100.0 0.0 100.0 true true PENS "sheep" 1.0 0 -16776961 true "wolves" 1.0 0 -65536 true "grass / 4" 1.0 0 -11352576 true MONITOR 87 275 158 324 sheep count sheep 3 1 MONITOR 162 275 244 324 wolves count wolves 3 1 MONITOR 248 275 324 324 grass / 4 count patches with [ pcolor = green ] / 4 0 1 TEXTBOX 8 144 148 163 Sheep settings TEXTBOX 186 144 299 162 Wolf settings TEXTBOX 9 82 161 100 Grass settings MONITOR 5 275 83 324 time-ticks ticks 0 1 SWITCH 167 42 303 75 show-energy? show-energy? 1 1 -1000 @#$#@#$#@ WHAT IS IT? ----------- This model explores the stability of predator-prey ecosystems. (The construction of this model is described in two papers by Wilensky & Reisman referenced below.) Such systems are called unstable when they tend to result in extinction for one or more species involved. In contrast, systems are stable when they tend to maintain themselves over time, despite fluctuations in population sizes. There are two main variations to this model. In the first variation, wolves and sheep wonder randomly around the landscape, while the wolves look for sheep to prey on. Each step costs the wolves energy, and they must eat sheep in order to replenish their energy - when they run out of energy they die. To allow the population to continue, each wolf or sheep has a fixed probability of reproducing at each time step. This variation produces interesting population dynamics, but is ultimately unstable. The second variation includes grass (green) in addition to wolves and sheep. The behavior of the wolves is identical to the first variation, however this time the sheep must eat grass in order to maintain their energy - when they run out of energy they die. Once grass is eaten it will only regrow after a fixed amount of time. This variation is more complex than the first, but it is generally stable. HOW TO USE IT ------------- 1. Set the GRASS? switch to TRUE to include grass in the model, or to FALSE to only include wolves (red) and sheep (white). 2. Adjust the slider parameters (see below), or use the default settings. 3. Press the SETUP button. 4. Press the GO button to begin the simulation. 5. View the POPULATIONS plot to watch the populations fluctuate over time 6. View the count-sheep/count-wolves monitors to view current population sizes Parameters: INITIAL-NUMBER-SHEEP: The initial size of sheep population INITIAL-NUMBER-WOLVES: The initial size of wolf population SHEEP-GAIN-FROM-FOOD: The amount of energy sheep get for every grass patch eaten WOLF-GAIN-FROM-FOOD: The amount of energy wolves get for every sheep eaten SHEEP-REPRODUCE: The probability of a sheep reproducing at each time step WOLF-REPRODUCE: The probability of a wolf reproducing at each time step GRASS?: Whether or not to include grass in the model GRASS-REGROWTH-TIME: How long it takes for grass to regrow once it is eaten SHOW-ENERGY?: Whether or not to show the energy of each animal in the Graphics Window Notes: - one unit of energy is deducted for every step a wolf takes - when grass is included, one unit of energy is deducted for every step a sheep takes THINGS TO NOTICE ---------------- When grass is not included, watch as the sheep and wolf populations fluctuate. Notice that increases and decreases in the sizes of each population are related. In what way are they related? What eventually happens? Once grass is added, notice the green line added to the population plot representing fluctuations in the amount of grass. How do the sizes of the three populations appear to relate now? What is the explanation for this? Why do you suppose that some variations of the model might be stable while others are not? THINGS TO TRY ------------- Try adjusting the parameters under various settings. How sensitive is the stability of the model to the particular parameters? Can you find any parameters that generate a stable ecosystem that includes only wolves and sheep? Try setting GRASS? to TRUE, but setting INITIAL-NUMBER-WOLVES to 0. This gives a stable ecosystem with only sheep and grass. Why might this be stable while the variation with only sheep and wolves is not? Notice that under stable settings, the populations tend to fluctuation at a predictable pace. Can you find any parameters that will speed this up or slow it down? Try changing the reproduction rules -- for example, what would happen if reproduction depended on energy rather than being determined by a fixed probability? EXTENDING THE MODEL ------------------- There are a number ways to alter the model so that it will be stable with only wolves and sheep (no grass). Some will require new elements to be coded in or existing behaviors to be changed. Can you develop such a version? NETLOGO FEATURES ---------------- Note the use of breeds to model two different kinds of "turtles": wolves and sheep. Note the use of patches to model grass. Note use of the RANDOM-ONE-OF agentset command to select a sheep to be eaten by a wolf. RELATED MODELS --------------- Look at Rabbit Grass Weeds for another model of interacting populations with different rules. CREDITS AND REFERENCES ---------------------- Wilensky, U. & Reisman, K. (1999). Connected Science: Learning Biology through Constructing and Testing Computational Theories -- an Embodied Modeling Approach. International Journal of Complex Systems, M. 234, pp. 1 - 12. (This model is a slightly extended version of the model described in the paper.) Wilensky, U. & Reisman, K. (in press). Thinking like a Wolf, a Sheep or a Firefly: Learning Biology through Constructing and Testing Computational Theories -- an Embodied Modeling Approach. Cognition & Instruction. To refer to this model in academic publications, please use: Wilensky, U. (1998). NetLogo Wolf Sheep Predation model. http://ccl.northwestern.edu/netlogo/models/WolfSheepPredation. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL. In other publications, please use: Copyright 1998 by Uri Wilensky. All rights reserved. See http://ccl.northwestern.edu/netlogo/models/WolfSheepPredation for terms of use. @#$#@#$#@ default true 0 Polygon -7566196 true true 150 5 40 250 150 205 260 250 sheep false 15 Rectangle -1 true true 90 75 270 225 Circle -1 true true 15 75 150 Rectangle -16777216 true false 81 225 134 286 Rectangle -16777216 true false 180 225 238 285 Circle -16777216 true false 1 88 92 wolf false 0 Rectangle -7566196 true true 15 105 105 165 Rectangle -7566196 true true 45 90 105 105 Polygon -7566196 true true 60 90 83 44 104 90 Polygon -16777216 true false 67 90 82 59 97 89 Rectangle -1 true false 48 93 59 105 Rectangle -16777216 true false 51 96 55 101 Rectangle -16777216 true false 0 121 15 135 Rectangle -16777216 true false 15 136 60 151 Polygon -1 true false 15 136 23 149 31 136 Polygon -1 true false 30 151 37 136 43 151 Rectangle -7566196 true true 105 120 263 195 Rectangle -7566196 true true 108 195 259 201 Rectangle -7566196 true true 114 201 252 210 Rectangle -7566196 true true 120 210 243 214 Rectangle -7566196 true true 115 114 255 120 Rectangle -7566196 true true 128 108 248 114 Rectangle -7566196 true true 150 105 225 108 Rectangle -7566196 true true 132 214 155 270 Rectangle -7566196 true true 110 260 132 270 Rectangle -7566196 true true 210 214 232 270 Rectangle -7566196 true true 189 260 210 270 Line -7566196 true 263 127 281 155 Line -7566196 true 281 155 281 192 @#$#@#$#@ NetLogo 2.0beta5 @#$#@#$#@ setup set grass? true repeat 75 [ go ] @#$#@#$#@ @#$#@#$#@