我想保存源和目的地之间最短路径的链接,所以我可以将它们的颜色改为红色,即链接的颜色。但是保存链接并不是原始的 代码是:
ask nodes with [label = "Source" ]
[
show nw:weighted-path-to turtle nodenumberdestination "bandwidth"
]
有人可以告诉我如何保存上面使用的nw原语报告的链接,以便在图表中将其颜色更改为红色?
答案 0 :(得分:4)
我不完全确定保存链接的含义,但您可以将链接列表存储在变量中。所以,如果你有一个海龟自己的变量path-to-destination
,你可以做到
ask nodes with [label = "Source" ] [
set path-to-destination nw:weighted-path-to turtle nodenumberdestination "bandwidth"
]
或者,如果您以后不需要对其进行任何操作,则可以将链接列表存储在本地变量中:
ask nodes with [label = "Source" ] [
let path-to-destination nw:weighted-path-to turtle nodenumberdestination "bandwidth"
]
至于把它们变成红色,nw:weighted-path-to
会返回一个链接列表,所以我们可以遍历该列表,让每个链接变为红色。扩展以前的代码,如下所示:
ask nodes with [label = "Source" ] [
let path-to-destination nw:weighted-path-to turtle nodenumberdestination "bandwidth"
foreach path-to-destination [ ask ? [ set color red ] ]
]