4

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

Derek Corcoran
  • 3,930
  • 2
  • 25
  • 54

2 Answers2

2

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.

King-Ink
  • 2,096
  • 12
  • 18
  • That is a great answer, I could not do it that way before, so I moved on to another way of solving it since I posted this question a couple of months ago, but I think your answer was better that the one I got. I finally quit on the network and used patch properties in order to get it done. – Derek Corcoran Nov 25 '15 at 23:49
  • 1
    you should never really need a construction like `setxy ([xcor] of node-here) ([ycor] of node-here)` since you can just use `move-to node-here` – JenB Nov 26 '15 at 08:04
2

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" ]
...
JenB
  • 17,620
  • 2
  • 17
  • 45
  • I try to implement this solution but I keep getting the error "expected command" regarding remove-item. It is as if the command doesn't as it is stated in the documentation and your answer... Did something change? What is going wrong? – DeMelkbroer Jul 05 '22 at 10:20