nw:path-to
nw:path-to target-turtle
Finds the shortest path to the target turtle and reports the actual path between the source and the target turtle. The path is reported as the list of links that constitute the path.
If no path exist between the source and the target turtles, false
will be reported instead.
Note that the NW-Extension remembers paths that its calculated previously unless the network changes. Thus, you don’t need to store paths to efficiently move across the network; you can just keep re-calling one of the path primitives. If the network changes, however, the stored answers are forgotten. Example:
links-own [ weight ]
to go
clear-all
create-turtles 5
ask turtle 0 [ create-link-with turtle 1 ]
ask turtle 1 [ create-link-with turtle 2 ]
ask turtle 0 [ create-link-with turtle 3 ]
ask turtle 3 [ create-link-with turtle 4 ]
ask turtle 4 [ create-link-with turtle 2 ]
ask turtle 0 [ show nw:path-to turtle 2 ]
end
Will output:
(turtle 0): [(link 0 1) (link 1 2)]
Take me to the full Networks Extension Dictionary