Reputation: 33
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.
Upvotes: 2
Views: 1384
Reputation: 33
Figured I would share the completed section of code for this, in case any other folks are looking to structure a model with specific turtle behavior in habitat edge. Each "if pcolor =" identifies a particular type of patch, separating habitat, matrix, and the three edge boundaries with specific movement parameters for each. Also note the special use of the wrapped Cauchy with Alan's bit of code - this is structured according to the bias correlated random walk from Schultz and Crone 2001.
If anyone has more feedback, I would appreciate it.
to fly-butterflies
ask butterflies [
if pcolor = green [
set heading ((heading * pi / 180 + 2 * atan (( (1 - cos TurningAngleLupine) / (1 + cos TurningAngleLupine) ) * tan(pi * ( random-float 1 - 0.5 ))) 1)) * 180 / pi
set step-length random-exponential MoveLengthLupine
set xc xc + (step-length * dx)
set yc yc + (step-length * dy)]
if pcolor = black [
set heading ((heading * pi / 180 + 2 * atan (( (1 - cos TurningAngleMatrix) / (1 + cos TurningAngleMatrix) ) * tan(pi * ( random-float 1 - 0.5 ))) 1)) * 180 / pi
set step-length random-exponential MoveLengthMatrix
set xc xc + (step-length * dx)
set yc yc + (step-length * dy)]
if pcolor = cyan [
set heading ((heading * pi / 180 + 2 * atan (( (1 - cos TurningAngleEdge) / (1 + cos TurningAngleEdge) ) * tan(pi * ( random-float 1 - 0.5 ))) 1)) * 180 / pi
set step-length random-exponential MoveLengthEdge
set xc xc + (step-length * dx)
set yc yc + (step-length * dy)]
if pcolor = blue [
set heading ((heading * pi / 180 + 2 * atan (( (1 - cos TurningAngleEdge) / (1 + cos TurningAngleEdge) ) * tan(pi * ( random-float 1 - 0.5 ))) 1)) * 180 / pi
set step-length random-exponential MoveLengthMatrix
set xc xc + (step-length * dx)
set yc yc + (step-length * dy)]
if pcolor = sky [
let %closest nobody
ask patch-here [set %closest min-one-of (other patches with [pcolor = green]) [distance myself]]
set heading (Bias * towards %closest) + ((1 - Bias) * ((heading * pi / 180 + 2 * atan (( (1 - cos TurningAngleEdge) / (1 + cos TurningAngleEdge) ) * tan(pi * ( random-float 1 - 0.5 ))) 1)) * 180 / pi)
set step-length random-exponential MoveLengthEdge
set xc xc + (step-length * dx)
set yc yc + (step-length * dy)]
ifelse patch-at (xc - xcor) (yc - ycor) = nobody
[ ht ]
[ st
set xcor xc
set ycor yc ]
]
end
Upvotes: 0
Reputation: 9610
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
Upvotes: 1