How to calculate the total link cost between two nodes that are not neighbors?

StackOverflow https://stackoverflow.com/questions/23569787

  •  19-07-2023
  •  | 
  •  

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.

Was it helpful?

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 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top