globals [ ticks light-amount day-time prev-time prev-display-mode] breeds [ sheep wolves ] turtles-own [ energy alpha freq offset activity mating? light-threshold zeitgeber-refresh new-offset] sheep-own [ grabbed?] ;; used to prevent two wolves from eating the same sheep patches-own [ countdown material] to setup ca set mutfactor 5 set ticks 0 set day-time 0 ask patches [ set material 1 shade-patch ] 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 material 0 ] ] ] 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 ] 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 ] ask turtles [ set alpha random-float 1 set freq random 99 + 1 set activity random 100 set offset random 360 - 180 set light-threshold random 100 set new-offset random 360 - 180 ] display-labels do-plot end to go update-light update-display ask turtles [ if mating? > 0 [set mating? mating? - 1] zeitgeber turtle-activity ] ask turtles [set energy energy - 0.2] ask sheep [ move if grass? [ eat-grass ] reproduce-sheep death ] ask wolves [ move-wolf 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 turtle-activity ;set activity (alpha * sin (ticks / freq * 360 + offset)) * 50 + 50 set activity (alpha * sin (ticks / freq * 360 + offset) + (1 - alpha ) * (sgn sin (ticks / freq * 360 + offset))) * 50 + 50 end to move ;; turtle procedure if random 100 < activity [ set energy energy - 1 rt random-float 50 - random-float 50 fd 1 ] end to move-wolf ;; turtle procedure if random 100 < activity [ catch-sheep set energy energy - 4 rt random-float 50 - random-float 50 fd 1 ] end to shade-patch if material = 1 [set pcolor scale-color green day-time -1 3] if material = 0 [set pcolor scale-color brown day-time -1 3] end to update-display update-turtle-display-mode if (display-mode = "daytime") [update-display-daytime-mode] set prev-display-mode display-mode end to update-display-daytime-mode set prev-time day-time if light-amount < 33 [set day-time 0] if (light-amount >= 33) and (light-amount <= 66) [set day-time 1] if light-amount > 66 [set day-time 2] if prev-time != day-time [ask patches [shade-patch]] end to update-turtle-display-mode if ((display-mode = "silly") and (prev-display-mode != "silly")) [switch-display-turtles-mode "sheep" "wolf"] if ((display-mode != "silly") and (prev-display-mode = "silly")) [switch-display-turtles-mode "default" "default"] end to switch-display-turtles-mode [shape1 shape2] ask sheep [ set shape shape1] set-default-shape sheep shape1 ask wolves [ set shape shape2] set-default-shape wolves shape2 end to update-light set prev-time light-amount set light-amount (- cos (ticks / day-frequency * 360 ) ) * 50 + 50 end to zeitgeber set zeitgeber-refresh zeitgeber-refresh - 1 if zeitgeber-refresh = 0 [ if (light-amount > light-threshold) [ set offset ((offset + (new-offset * activity ) + 180) mod 360) - 180 set zeitgeber-refresh freq ] ] end to eat-grass ;; sheep procedure ;; sheep eat grass, turn the patch brown if material = 1 [ set material 0 shade-patch set energy energy + sheep-gain-from-food ;; sheep gain energy by eating ] end to reproduce-sheep ;; sheep procedure locals [partner nalpha noffset nfreq nthreshold nnewoffset] set partner random-one-of sheep-here with [mating? = 0] without-interruption [ if partner != nobody [ if random-float 10 < sheep-reproduce [ ;; throw "dice" to see if you will reproduce set mating? 2 set mating?-of partner 20 set energy (energy / 2) ;; divide energy between parent and offspring set nalpha (alpha + alpha-of partner) / 2 + random-float (1 * 0.1 * mutfactor) - 0.05 * mutfactor set noffset (offset + offset-of partner) / 2 + random (360 * 0.1 * mutfactor) - 18 * mutfactor set nfreq (freq + freq-of partner) / 2 + random-float (100 * 0.1 * mutfactor) - 5 * mutfactor set nthreshold (light-threshold + light-threshold-of partner)/ 2 + random-float (100 * 0.1 * mutfactor) - 5 * mutfactor set nnewoffset (new-offset + new-offset-of partner) / 2 + random (360 * 0.1 * mutfactor) - 18 * mutfactor set nalpha cut-off nalpha 0 1 set noffset ((noffset + 180) mod 360) - 180 set nfreq cut-off nfreq 1 100 set nthreshold cut-off nthreshold 0 100 set nnewoffset ((nnewoffset + 180) mod 360) - 180 hatch 1 [ set alpha nalpha set freq nfreq set offset noffset set light-threshold nthreshold set new-offset nnewoffset rt random-float 360 fd 1 ] ;; hatch an offspring and move it forward 1 step ] ] ] end to reproduce-wolves ;; wolf procedure locals [partner nalpha noffset nfreq nthreshold nnewoffset] set partner random-one-of wolves-here with [mating? = 0] without-interruption [ if partner != nobody [ if random-float 5 < wolf-reproduce [ ;; throw "dice" to see if you will reproduce set mating? random 20 + 10 set mating?-of partner random 20 + 10 set nalpha (alpha + alpha-of partner) / 2 + random-float (1 * 0.1 * mutfactor) - 0.05 * mutfactor set noffset (offset + offset-of partner) / 2 + random (360 * 0.1 * mutfactor) - 18 * mutfactor set nfreq (freq + freq-of partner) / 2 + random-float (100 * 0.1 * mutfactor) - 5 * mutfactor set nthreshold (light-threshold + light-threshold-of partner)/ 2 + random-float (100 * 0.1 * mutfactor) - 5 * mutfactor set nnewoffset (new-offset + new-offset-of partner) / 2 + random (360 * 0.1 * mutfactor) - 18 * mutfactor set nthreshold (light-threshold + light-threshold-of partner)/ 2 + random-float (100 * 0.1 * mutfactor) - 5 * mutfactor set nnewoffset (new-offset + new-offset-of partner) / 2 + random (360 * 0.1 * mutfactor) - 18 * mutfactor set nalpha cut-off nalpha 0 1 set noffset ((noffset + 180) mod 360) - 180 set nfreq cut-off nfreq 1 100 set nthreshold cut-off nthreshold 0 100 set nnewoffset ((nnewoffset + 180) mod 360) - 180 hatch 1 [ set alpha nalpha set freq nfreq set offset noffset set light-threshold nthreshold set new-offset nnewoffset set energy (energy / 2 ) ;; divide energy between parent and offspring ] ] ] ] 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 and random 100 < light-amount) ;; 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 material = 0 [ ifelse countdown <= 0 [ set material 1 shade-patch set countdown grass-regrowth-time ] [ set countdown (countdown - 1) ] ] end to do-plot set-current-plot "populations" if ((ticks mod 600) = 0) [ clear-plot] ;set-plot-x-range ticks - 300 ticks 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 [ material = 1 ] / 4 ;; divide by four to keep it within similar ;; range as wolf and sheep populations ] ;set-current-plot-pen "Day Time" ;plot day-time * 100 set-current-plot-pen "Day Light" plot light-amount * 2 if graph-display [ if graph-select = "frequency" [ set-current-plot "sheep" set-histogram-num-bars 18 set-plot-x-range 0 100 set-current-plot-pen "Sheep" set-plot-pen-mode 1 histogram-from sheep [freq] set-current-plot "wolf" set-histogram-num-bars 18 set-plot-x-range 0 100 set-current-plot-pen "Wolves" set-plot-pen-mode 1 histogram-from wolves [freq] ] if graph-select = "alpha" [ set-current-plot "sheep" set-histogram-num-bars 18 set-plot-x-range 0 1 set-current-plot-pen "Sheep" set-plot-pen-mode 1 histogram-from sheep [alpha] set-current-plot "wolf" set-histogram-num-bars 18 set-plot-x-range 0 1 set-current-plot-pen "Wolves" set-plot-pen-mode 1 histogram-from wolves [alpha] ] if graph-select = "offset" [ set-current-plot "sheep" set-histogram-num-bars 18 set-plot-x-range -180 180 set-current-plot-pen "Sheep" set-plot-pen-mode 1 histogram-from sheep [offset] set-current-plot "wolf" set-histogram-num-bars 18 set-plot-x-range -180 180 set-current-plot-pen "Wolves" set-plot-pen-mode 1 histogram-from wolves [offset] ] if graph-select = "phase diagram" [ set-current-plot "sheep" set-current-plot-pen "Sheep" plot-pen-reset set-plot-x-range -180 180 set-plot-y-range 0 100 set-plot-pen-mode 2 scatterplot (values-from sheep [offset]) (values-from sheep [freq]) set-current-plot "wolf" set-current-plot-pen "Wolves" set-plot-x-range -180 180 set-plot-y-range 0 100 plot-pen-reset set-plot-pen-mode 2 scatterplot (values-from wolves [offset]) (values-from wolves [freq]) ] if graph-select = "zeitgeber phases" [ set-current-plot "sheep" set-current-plot-pen "Sheep" plot-pen-reset set-plot-x-range -180 180 set-plot-y-range 0 100 set-plot-pen-mode 2 scatterplot (values-from sheep [new-offset]) (values-from sheep [light-threshold]) set-current-plot "wolf" set-current-plot-pen "Wolves" set-plot-x-range -180 180 set-plot-y-range 0 100 plot-pen-reset set-plot-pen-mode 2 scatterplot (values-from wolves [new-offset]) (values-from wolves [light-threshold]) ] if graph-select = "activity phases" [ set-current-plot "sheep" set-current-plot-pen "Sheep" if ((ticks mod day-frequency) < 1) [plot-pen-reset] set-plot-x-range -180 180 set-plot-y-range 0 100 set-plot-pen-mode 2 scatterplot (n-values (count sheep) [(ticks / day-frequency * 360) mod 360 - 180] )(values-from sheep [activity]) set-current-plot "wolf" set-current-plot-pen "Wolves" set-plot-x-range -180 180 set-plot-y-range 0 100 if ((ticks mod day-frequency) < 1) [plot-pen-reset] set-plot-pen-mode 2 scatterplot (n-values count wolves [(ticks / day-frequency * 360) mod 360 - 180]) (values-from wolves [activity]) ] ] 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 to-report sgn [x] ifelse x < 0 [report -1] [report 1] end to-report cut-off [x min-x max-x] report max (list (min (list max-x x ) ) min-x ) end to scatterplot [a1 b1] (foreach a1 b1 [ plotxy ?1 ?2 ]) end ; *** NetLogo Model Copyright Notice *** ; ; This model (sleeping patters v0.1) is based on Uri Wilenskys wolf-sheep predation modell ; and was extended to a sleeping patterns simulation by Carlo Comis ; and Martin Schneider at AMHSO 2004, Bielefeld ; ; *** End of NetLogo Model Copyright Notice *** @#$#@#$#@ GRAPHICS-WINDOW 492 10 992 531 28 28 8.6 1 14 1 1 1 CC-WINDOW 597 551 992 824 Command Center SLIDER 16 139 190 172 initial-number-sheep initial-number-sheep 0 400 350 1 1 NIL SLIDER 16 176 190 209 sheep-gain-from-food sheep-gain-from-food 0.0 50.0 4.0 1.0 1 NIL SLIDER 16 211 190 244 sheep-reproduce sheep-reproduce 1.0 20.0 3.0 1.0 1 % SLIDER 194 139 359 172 initial-number-wolves initial-number-wolves 0 250 97 1 1 NIL SLIDER 194 175 359 208 wolf-gain-from-food wolf-gain-from-food 0.0 100.0 68.0 1.0 1 NIL SLIDER 194 211 359 244 wolf-reproduce wolf-reproduce 0.0 20.0 11.0 1.0 1 % SWITCH 17 74 111 107 grass? grass? 0 1 -1000 SLIDER 118 75 330 108 grass-regrowth-time grass-regrowth-time 0 100 55 1 1 NIL BUTTON 20 15 89 48 setup setup NIL 1 T OBSERVER T BUTTON 102 15 169 48 go go T 1 T OBSERVER T PLOT 12 302 414 469 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 "Day Time" 1.0 0 -16777216 true "Day Light" 1.0 0 -16745473 true "Activity" 1.0 0 -8716033 true MONITOR 419 68 483 117 sheep count sheep 3 1 MONITOR 420 125 483 174 wolves count wolves 3 1 MONITOR 421 180 483 229 grass / 4 count patches with [ material = 1 ] / 4 0 1 TEXTBOX 20 117 160 136 Sheep settings TEXTBOX 198 117 311 135 Wolf settings TEXTBOX 21 55 173 73 Grass settings MONITOR 418 12 485 61 time-ticks ticks 0 1 SWITCH 179 15 315 48 show-energy? show-energy? 0 1 -1000 SLIDER 16 248 188 281 day-frequency day-frequency 0.1 100 33.8 0.1 1 NIL PLOT 10 473 210 623 wolf NIL NIL 0.0 1000.0 0.0 2000.0 false false PENS "Wolves" 1.0 0 -65536 true "Sheep" 1.0 0 -16777216 true "Wolves" 1.0 0 -65536 true PLOT 212 473 412 623 sheep NIL NIL 0.0 100.0 0.0 100.0 true false PENS "default" 0.1 0 -16776961 true "Sheep" 1.0 0 -16777216 true CHOICE 418 573 564 618 graph-select graph-select "frequency" "alpha" "offset" "phase diagram" "zeitgeber phases" "activity phases" 5 SWITCH 422 539 554 572 graph-display graph-display 0 1 -1000 CHOICE 191 249 329 294 display-mode display-mode "daytime" "activity" "silly" 0 SLIDER 341 256 473 289 mutfactor mutfactor 0 1 1.0 0.01 1 NIL @#$#@#$#@ WHAT IS IT? ----------- This model (sleeping patters v0.1) is based on Uri Wilenskys wolf-sheep predation modell and was extended to a sleeping patterns simulation by Carlo Comis and Martin Schneider at AMHSO 2004, Bielefeld. @#$#@#$#@ 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.0.0 @#$#@#$#@ setup set grass? true repeat 75 [ go ] @#$#@#$#@ @#$#@#$#@