I am at somewhat of a conceptual and practical impasse in writing a correlated-random walk code (according to a wrapped Cauchy distribution) for a specific organism. In the landscape, the organism's movement will be determined based on its location (in habitat, outside of habitat, and in edge boundary). The correlated-random walk code is as follows, where rho and step-size will be determined based on whether the organism is either in habitat or outside of habitat.
set heading ((heading * pi / 180 + 2 * atan (( (1 - rho) / (1 + rho)
) * tan(pi * ( random-float 1 - 0.5 ))) 1)) * 180 / pi
set step-size random-gamma alpha lambda
set xc xc + (step-size * dx)
set yc yc + (step-size * dy)
The tricky part, and where I am stuck, is in the edge boundary. Here, the organism's movement is influenced by the direction of the organism to the closest habitat patch. This direction is multiplied by a parameter to result in a modified correlated-random walk code. In order to write this bit of the code, it is necessary to know each turtle's heading to the closest patch identified as habitat in the landscape. Once that is known, I believe I can modify the correlated-random walk code as follows:
set heading [(EdgeParameter * TurtleDirectionToClosestHabitat) + [(1 -
EdgeParameter)*[((heading * pi / 180 + 2 * atan (( (1 - rho) / (1 +
rho) ) * tan(pi * ( random-float 1 - 0.5 ))) 1)) * 180 / pi]]]
After browsing through the NetLogo dictionary, and poking around several sample models, and poking around the Internet, I have yet to find an elegant way to calculate TurtleDirectionToClosestHabitat. The "toward" primitive seems to be the ticket, though I cannot reason a way to specify the primitive to return the heading for only the turtles in the edge boundary of the landscape toward the habitat patch closest to them. This is where my conceptual and practical impasse lies.
Advice, suggestions, criticisms, and potential bits of code to play with are all welcome. Thank you all.
From what you've said so far, the three procs below shd get you what you're after: the heading to the closest other habitat for each turtle at the boundary. (We do not guard against a habitat patch having a turtle on it.)
to-report edge-turtles ;;observer proc
;;assume wrapping has been turned off in this world
report turtles with [count neighbors < 8]
end
to-report closest-habitat ;;turtle-proc
;;here we assume habitat patches are green (change appropriately)
let %closest nobody
ask patch-here [
set %closest min-one-of (other patches with [pcolor = green]) [
distance myself
]
]
report %closest
end
to-report heading-to-closest-habitat ;;turtle-proc
report towards closest-habitat
end