如何计算不是邻居的两个节点之间的总链路成本?

时间:2014-05-09 16:36:04

标签: netlogo

我有一个网络,其中每个链接的成本计算如下:

ask links [ set link-cost sum [node-cost] of both-ends ]

如何计算不是邻居的两个节点之间的总链路成本(链路成本之和)?

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"

提前感谢您的帮助。

1 个答案:

答案 0 :(得分:4)

以下是使用Seth建议的扩展NW中nw:path-to的可能解决方案(您也可以使用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