I apologise upfront if this is a stupid question.
When one calls nw:weighted-path-to a list of links is returned describing the shortest path between origin and destination turtles.
Similarly, calling nw:turtles-on-weighted-path-to returns a list of the turtles on the shortest path between origin and destination.
It is my understanding that if there are 2 equally weighted paths between origin and destination both functions returns one of these paths at random. This happens independently and as such one set of links can be produced for the shortest path, but another set of turtles. This can be replicated using the following code:
extensions [nw] links-own [ weight ] to go clear-all create-turtles 4 ask turtle 0 [ create-link-with turtle 1 [ set weight 2 ] ] ask turtle 0 [ create-link-with turtle 2 [ set weight 2 ] ] ask turtle 1 [ create-link-with turtle 3 [ set weight 2] ] ask turtle 2 [ create-link-with turtle 3 [ set weight 2] ] ask turtle 0 [ let pathLinks nw:weighted-path-to turtle 3 "weight" let pathNodes nw:turtles-on-weighted-path-to turtle 3 "weight" let pathUtility nw:weighted-distance-to turtle 3 "weight" show pathLinks show pathNodes show pathUtility ] end
Which will happily produce:
(turtle 0): [(link 0 2) (link 2 3)] (turtle 0): [(turtle 0) (turtle 1) (turtle 3)] (turtle 0): 4
Obviously, this is not an error but it has unfortunately tripped me up.
My question is - what is the most sensible way to link these two procedures to produce lists of links and turtles that make up a single randomly selected shortest path?
I am assuming it would be best to return the links with nw:weighted-path-to, then ask the links to return both-ends and do some sort of unique operation to produce a set of turtles on that path, if that is the case I'm not sure how to preserve the order of turtles. Does this make sense? Is that how you would do it?
As ever, thanks for reading.
Edit: this also applies to path-to and turtles-on-path-to in a topological network with multiple equal length paths.