Reputation: 3
I'm running a traffic interaction simulator with an imported shapefile that generates a road network. Nodes and links between nodes along this network are created that agents travel between. This has all been ironed out with the network extension, nw:turtles-on-path-to command, but to incorporate speed limits I'm trying to implement weighted path-finding. So links between nodes also have a speedLimit weight variable.
This is the current code which works - what I'm trying to do is change the 'nw:turtles-on-path-to [destination]' into 'nw:turtles-on-weighted-path-to [destination speedLimit]'. However, the 'of' nesting is proving problematic when adding the weight variable and throws up errors seemingly no matter how I try and add it in.
to set-location
set current-location min-one-of nodes [distance myself]
end
to set-destination
let test current-location
nested-set-destination
while [destination = test] [nested-set-destination]
set next-node item 1 [nw:turtles-on-path-to [destination] of myself] of current-location
face next-node
end
to nested-set-destination
set destination one-of [ nodes with [is-number? [ nw:distance-to myself ] of myself] ] of current-location
end
to move
let test-location min-one-of nodes [distance myself]
if (any? nodes with [distance myself < 1]) and (test-location != current-location) [
set current-location min-one-of nodes [distance myself]
ifelse current-location = destination [
set-destination
]
[
set next-node item 1 [nw:turtles-on-path-to [destination] of myself] of current-location
face next-node
]
]
fd speed
end
Throws up 'Error - expected closing bracket' and highlights speedLimit if I make the described changes. If I instead enclose it like so...
set next-node item 1 [[nw:turtles-on-weighted-path-to destination speedLimit] of myself] of current-location
... this can make it past code check, but once the function is called returns "ITEM expected input to be a string or list but got the TRUE/FALSE false instead."
Upvotes: 0
Views: 115
Reputation: 17678
Sometimes the easiest way to deal with awkward syntax is to avoid it entirely, and that also makes for more readable code. In this case, I would create a temporary variable for the destination and use that. So instead of doing it all in one command, something like:
let target [destination] of myself
set next-node item 1 nw:turtles-on-weighted-path-to target speedLimit
But if you definitely want it in one line, brackets could help:
set next-node item 1 nw:turtles-on-weighted-path-to ([destination] of myself) speedLimit
Upvotes: 1