PPHPC - Predator-Prey for High-Performance Computing
Model was written in NetLogo 5.1.0
•
Viewed 394 times
•
Downloaded 31 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
globals [ sheep-count ;; how many sheep are there? wolves-count ;; how many wolves are there? grass-alive ;; how much alive grass there is sheep-energy ;; mean sheep energy wolves-energy ;; mean wolf energy grass-countdown ;; mean grass countdown maxwho ;; youngest agent to date ] ;; Sheep and wolves are both breeds of turtle. breed [sheep a-sheep] ;; sheep is its own plural, so we use "a-sheep" as the singular. breed [wolves wolf] turtles-own [energy] ;; both wolves and sheep have energy patches-own [countdown] ;; patches have a countdown variable for grass ;; Initialization to setup clear-all ;; Set random number generator seed random-seed rngseed ;; show-params ask patches [ ifelse random 2 = 1 [ set countdown 1 + random grass-regrowth-time ;; initialize grass grow clocks randomly set pcolor brown ] [ set countdown 0 set pcolor green ] ] set-default-shape sheep "sheep" create-sheep initial-number-sheep ;; create the sheep, then initialize their variables [ set color white set size 1 ;; easier to see set label-color blue - 2 set energy 1 + random (2 * sheep-gain-from-food) setxy random-pxcor random-pycor ] set-default-shape wolves "wolf" create-wolves initial-number-wolves ;; create the wolves, then initialize their variables [ set color black set size 1 ;; easier to see set energy 1 + random (2 * wolf-gain-from-food) setxy random-pxcor random-pycor ] gather-stats display-labels reset-ticks end ;; Simulation loop to go ;; 1 - Agent movement ask turtles [ move set energy energy - 1 if energy < 1 [ die ] ;; if energy dips below zero, die ] ;; 2 - Grow food ask patches [ grow-grass ] ;; 3 - Act ask turtles [ ifelse is-a-sheep? self [ ;; is a sheep eat-grass reproduce sheep-reprod-thres sheep-reprod-prob ] [ ;; is a wolf catch-sheep reproduce wolf-reprod-thres wolf-reprod-prob ] ] ;; 4 - Gather stats gather-stats display-labels ;; New iteration tick ;; Time to stop? if ticks = iterations [ stop ] end to gather-stats set maxwho max [who] of sheep set sheep-count count sheep set wolves-count count wolves set grass-alive count patches with [countdown <= 0] if show-energy? [ ifelse sheep-count > 0 [ set sheep-energy mean [energy] of sheep ] [ set sheep-energy 0 ] ifelse wolves-count > 0 [ set wolves-energy mean [energy] of wolves ] [ set wolves-energy 0 ] set grass-countdown mean [countdown] of patches ] end to move ;; turtle procedure let direction random 5 if direction < 4 [ set heading 90 * direction fd 1 ] end to eat-grass ;; sheep procedure ;; sheep eat grass, turn the patch brown if pcolor = green [ set pcolor brown ask patch-here [set countdown grass-regrowth-time] set energy energy + sheep-gain-from-food ;; sheep gain energy by eating ] end to reproduce [ reprod-thres reprod-prob ] ;; turtle procedure if energy > reprod-thres [ if random 100 < reprod-prob [ ;; throw "dice" to see if you will reproduce let energy_offspring int (energy / 2) set energy energy - energy_offspring ;; divide energy between parent and offspring hatch 1 [ ;; hatch an offspring which stays in the same place set energy energy_offspring ] ] ] end to catch-sheep ;; wolf procedure let prey one-of sheep-here with [ who <= maxwho ] ;; grab a random sheep, cannot be a newly born sheep if prey != nobody ;; did we get one? if so, [ ask prey [ die ] ;; kill it set energy energy + wolf-gain-from-food ] ;; get energy from eating end to grow-grass ;; patch procedure ;; countdown on brown patches: if reach 0, grow some grass if pcolor = brown [ set countdown countdown - 1 if countdown <= 0 [ set pcolor green set countdown 0 ] ] end to display-labels if show-energy? [ ask wolves [ set label energy ] ask sheep [ set label energy ] ] end to show-params print word " INIT_SHEEP = " initial-number-sheep print word " SHEEP_GAIN_FROM_FOOD = " sheep-gain-from-food print word " SHEEP_REPRODUCE_THRESHOLD = " sheep-reprod-thres print word " SHEEP_REPRODUCE_PROB = " sheep-reprod-prob print word " INIT_WOLVES = " initial-number-wolves print word " WOLVES_GAIN_FROM_FOOD = " wolf-gain-from-food print word "WOLVES_REPRODUCE_THRESHOLD = " wolf-reprod-thres print word " WOLVES_REPRODUCE_PROB = " wolf-reprod-prob print word " GRASS_RESTART = " grass-regrowth-time print word " GRID_X = " world-width print word " GRID_Y = " world-height print word " ITERS = " iterations end ; Copyright 1997 Uri Wilensky. All rights reserved. ; Copyright 2015 Nuno Fachada. All rights reserved. ; The full copyright notice is in the Information tab.
There is only one version of this model, created over 8 years ago by Nuno Fachada.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
PPHPC - Predator-Prey for High-Performance Computing.png | preview | Preview for 'PPHPC - Predator-Prey for High-Performance Computing' | over 8 years ago, by Nuno Fachada | Download |
This model does not have any ancestors.
This model does not have any descendants.