Derek Corcoran
Derek Corcoran

Reputation: 4082

Netlogo, how to make turtles follow paths between patches of the towards a destination

Hello I am trying to model the movement of tourists within a national park, the Idea of the model is that the tourists follow the paths of this national park and they stop in the camp-grounds for a time.

I have two problems, using the NW I found out how to get the shorthest path between two nodes, but I can't make the Tourists follow that path. The second problem I have is that the Tourists have a destination and I want the node using the same patch as the tourist to get the same destination and give the order to the tourist so that it will follow that path.

This script uses both the NW and GIS extension, I uploaded the script and raster that I used in https://github.com/derek-corcoran-barrios/netlogoPNTP so that you can run it easily with the raster.

Thank you for your help

Cheers

Upvotes: 4

Views: 1917

Answers (2)

King-Ink
King-Ink

Reputation: 2096

1) I assume you have procedure that reports the length of the path between a patch and its target. For this answer lets call it distance-to-target. Have each of the link-neighbors of the tourists node run it and move the tourist to the node with the shortest value.

keep in mind this is generic code and may have to be adapted to your needs.

ask tourists  
   [
    set node-here min-of ([link-neighbors] of node-here) [distance-to-target]
   move-to node-here; this makes them move 
   ]

actually I think that may answer both of your questions if I understand them correctly.

Upvotes: 2

JenB
JenB

Reputation: 17678

The network extension primitive nw:turtles-on-path-to returns a list of nodes that are on the shortest path to the destination. Is this the primitive you found? Assuming you have a turtle variable called mypath to store that in, you want something like this to get the path:

ask turtles
[ ... ; decides target
  set mypath nw:turtles-on-path-to target
]

and something like this to move on the path. It will move to the location of the first node in the list, then remove that first node from the list so that the new first node is the next step.

...
move-to item 0 mypath
ifelse length mypath > 0
  [ remove-item 0 mypath ]
  [ print "at destination" ]
...

Upvotes: 2

Related Questions