Here is a possible solution by using nw:path-to
in the Extension NW as suggested by Seth (you can also used nw:weighted-path-to
) :
to total-link-node [a b]
ask a [
show nw:path-to b
print sum (map [ [link-cost] of ? ] nw:path-to b) ]
end
Question
I have a network where each link has a cost that is calculated as follows:
ask links [ set link-cost sum [node-cost] of both-ends ]
How can I calculate the total link cost (sum of link cost) between two nodes that are not neighbors ?
to total-link-node [ a b ] ;; where a and b are nodes
ask a [
print [link-cost] of (link-with b) ]
end
gives "OF expected input to be a link agentset or link but got NOBODY instead"
Thanks in advance for your help.
Solution
Here is a possible solution by using nw:path-to
in the Extension NW as suggested by Seth (you can also used nw:weighted-path-to
) :
to total-link-node [a b]
ask a [
show nw:path-to b
print sum (map [ [link-cost] of ? ] nw:path-to b) ]
end