forest-seekers

forest-seekers preview image

1 collaborator

Army_coat_pix R. Wade Schuette (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by the author
Model was written in NetLogo 6.2.0 • Viewed 512 times • Downloaded 36 times • Run 0 times
Download the 'forest-seekers' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


WHAT IS IT?

A simple tutorial model where turtles move through patches that have variable resistance to motion, at each step each turtle moves to the neigbhoring patch with least resistance of patches which are closer to the forest centroid than it is.

HOW IT WORKS

    The world is in yellow and has resistance to motion > 2
    The target forest is in green and has resistance to motion <= 2 

    centroid <- ( XC, YC ) of the center of mass of the forest  
    which we compute once in setup and use globally

    listplace is a utility list like [ 0 1 2 3 4 5 6 7 ] of possible list indexes

    If there are stray turtles, each tick, for each turtle not yet in the forest:
     compute:

     nearbylist  <-  ordered list of my neighboring patches  
     dlist       <-  list of the computed distance from each of those to the forest
     shortlist   <-  just those patches in  nearbylist closer to our goal than us 
     rlist       <-  list of the resistances of each patch in the shortlist 
     target      <-  the patch in rlist with the smallest resistance

     and move to the target

HOW TO USE IT

 Use the VERBOSE switch to toggle on or off verbose printed commments
 Set a number of turtles with the slider ( 1 to 10 )
 Click SETUP
 Click either ONESTEP or GO.

THINGS TO NOTICE

All the decision-making is local. The turtles do not compute global paths or store information about where they have been.

Motion is towards the forest centroid, which will not always be the nearest part of a forest especially if the forest has a complex shape.

THINGS TO TRY

EXTENDING THE MODEL

* modify the code so a turtle can run into an obstacle or dead-end and figure out
  how to get out and get in motion towards the goal again.

* much harder - figure out how to get to the nearest part of the forest, not the 
  centroid of the forest.

NETLOGO FEATURES

  • illustrates anonymous procedures, foreach
  • illustrates one way to scan down two lists in parallel looping over an index variable
  • Solves a stated requirement that the turtle not backtrack without requiring either turtles or patches to store lists of prior visits

  • illustrates breaking complex calculations into a sequence of simpler steps which -- will run more slowly but -- is much easier to understand and debug -- requires scanning down two or more lists simulteously in parallel to assemble related information that would be all "right there" in a more complex code statement that did many things at once.

  • A switch to toggle on/off debugging comments is handy in development ( and when are we ever sure we are done with development?! )

  • The world doesn't wrap around but correctly treats neighbors on edges or in a corner

RELATED MODELS

there are ants and swarm models already in the model library. I didn't explore how those relate to this solution.

CREDITS AND REFERENCES

Author: R. Wade Schuette Posted Date: 19 FEB 2021 Copyright (c) 2021 Anyone can use this for any purpose but please give me credit

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 over 4 years ago by R. Wade Schuette.

Attached files

File Type Description Last updated
forest-seekers.png preview Preview for 'forest-seekers' over 4 years ago, by R. Wade Schuette Download

This model does not have any ancestors.

This model does not have any descendants.