I'm new to Netlogo and trying to build a model imported from GIS city plan in which agents ("walkers") find the closest of several set destinations, walk there along the streets, and then return to their "home". I have three breeds: walkers, nodes, and destinations. I've created a network of nodes that are linked on which the walkers move. So far I've only figured out the first step where a single walker finds the closet route to a destination using nw:turtles-on-path-to and then moves towards it. The problem is when I then move the walker to a new location to test whether it can find the closest destination to this new location. It can identify the proper closest destination, but the path reverts back to the walker's original location, and it moves the walker back there when I move them. I cannot figure out why it does this, nor how to fix it.
This is snippet of the setup:
ask patches with [ destination? ]
[ sprout-destinations 1 [
set size 3
set shape "circle"
set color blue
]
]
ask patches with [ street? ]
[ sprout-nodes 1 [
set color pcolor
set size 0.5
set shape "circle"
set color green
]
]
set near-destination nodes-on destinations
create-walkers 1 [
set color red
set size 3
set shape "person"
move-to one-of nodes
set mypath []
if draw-route = true ;; if true, a route will be traced following the leader
[ pen-down ]
ask nodes [
create-links-with turtles-on neighbors [
set color green
]
This is how the route to the closest destination is identified:
to find-nearest-destination
nw:set-context turtles links
set mypath []
ask walkers [
set mynode one-of nodes-on patch-here
set my-destination min-one-of near-destination [
length nw:turtles-on-path-to mynode]]
ask walkers [
set mypath nw:turtles-on-path-to my-destination]
end
And this is how the walkers move towards it:
to go
ask walkers [
if xcor != [xcor] of my-destination or ycor != [ycor] of my-destination[
move-to item 0 mypath
ifelse length mypath > 0
[ set mypath remove-item 0 mypath ]
[ print "at destination" ]
]
end
I thought that by resetting "mypath" before finding the new path it should use the new "mynode" as the starting point, but it somehow always ends up with the first one. mynode and near-destination are global, but mypath and my-destination are owned by the walkers.
Thanks to anybody who can straighten me out!