forest-seekers
Model was written in NetLogo 6.2.0
•
Viewed 352 times
•
Downloaded 21 times
•
Run 0 times
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
globals [XC YC] patches-own [ R ] to setup clear-all ;;set VERBOSE true; ;; make some patches, forest is all resistance <= 2 ask patches [ set R 2.1 + random-float 5 set pcolor yellow] ask patches [ if pxcor > 12 and pycor > 8 and pycor < 12 [set R 1 + random-float 1 set pcolor green]] ;; compute centroid of the green set XC mean [pxcor] of patches with [ pcolor = green ] set YC mean [pycor] of patches with [ pcolor = green ] if VERBOSE [ print (word " centroid of green is (" XC " , " YC " ) ") ] ask patch XC YC [ set pcolor ( green + 2 ) ] ;; I'll use test of R to determine when to stop create-turtles NUMTURTLES [ set size 2 setxy random-xcor random-ycor set shape "turtle" ] ask turtles [pen-down] reset-ticks end to go if ( 0 = count turtles with [ R > 2 ] ) [ stop ] ;; since turtles don't own a variable R the next statement checks the patch each turtle is on for an R value ask turtles with [ R > 2 ] [ ;; get my distance from the forest centroid let Z distancexy XC YC if VERBOSE [ print (word " x: " xcor " y: " ycor "patch R: " R " Z = " Z ) ] ;; get a list of my neighbors let nearbylist [self] of neighbors if VERBOSE [ print ( word "neighbors of turtle " who "shows") ] ;; create a list of indices let listplace n-values ( length nearbylist) [ i -> i] ;; create a list of distance of each neighbor from the forest centroid let dlist []; foreach nearbylist [ x -> ask (patch xc yc) [ set dlist lput distance x dlist] ] if VERBOSE [ show dlist ] ;; let's be sure we have this correctly, so report the patch and the distance if VERBOSE [ foreach listplace [ x -> print (word x " " ( item x nearbylist) " is " ( item x dlist) " from XC YC" )]] if VERBOSE [ print ( word " and I am now distance " Z " from XC YC " ) ] if VERBOSE [ print "so i need to discard items further away from me to get a new better short candiate list "] ;; create a list of just those neighbors closer to the forest centroid than I am let shortlist []; foreach listplace [ x -> if item x dlist < Z [ set shortlist lput item x nearbylist shortlist ]] if VERBOSE [ show shortlist ] if VERBOSE [ print " and these patches have these resistances "] if VERBOSE [ foreach shortlist [ x -> ask x [ print R ] ] ] ;; create a list of the resistances of those candidates for my next move let rlist [ ] foreach shortlist [ x -> ask x [set rlist lput R rlist] ] if VERBOSE [ show rlist ] ;; find the smallest resistance ( may be duplicated ) let minr min rlist if VERBOSE [ print (word "min resistance is " minr )] ;; find the first neighbor with the minimum resistance ( stops looking when it finds one ) set listplace n-values (length shortlist) [ i -> i] if VERBOSE [ print (word " listplace is now : " listplace) ] ;; initialize target to something in all cases so the compiler is happy let target patch 0 0 if VERBOSE [ print "target initialized" ] foreach listplace [ x -> if ( item x rlist = minr ) [ set target ( item x shortlist ) ] ] if VERBOSE [ print ( word "moving to " target )] move-to target ] tick end
There is only one version of this model, created almost 4 years ago by R. Wade Schuette.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
forest-seekers.png | preview | Preview for 'forest-seekers' | almost 4 years ago, by R. Wade Schuette | Download |
This model does not have any ancestors.
This model does not have any descendants.