我想在netlogo中创建权重的有向图。我搜索了文档,但我找不到在我的链接上加权的方法。这是我的代码:
to setup
clear-all ;; clear everything on canvas
setup-nodes ;; a procedure to set nodes
setup-edges ;; a procedure to set edges
ask turtles [ set color red] ;; paint nodes red
ask links [set color white] ;; paint edges white
reset-ticks
end
to setup-nodes
set-default-shape turtles "circle"
crt number-of-nodes ;; users give this number from the interface
[
; for visual reasons, we don't put any nodes *too* close to the edges
setxy (random-xcor * 0.95) (random-ycor * 0.95)
]
end
to setup-edges
while [ count links < num-links ] ;; num-links given by the user from interface
[
ask one-of turtles
[
let choice one-of other turtles
if choice != nobody [ create-link-to choice ]
]
]
; make the network look a little prettier
repeat 10
[
layout-spring turtles links 0.3 (world-width / (sqrt number-of-nodes)) 1
]
end
答案 0 :(得分:4)
links-own [weight]
(在“代码”标签的顶部)向链接添加名为weight
的变量。
NetLogo模型库中使用links-own
的一些模型:小世界,团队装配,有向网络上的扩散,人工神经网络,链接品种示例,网络导入示例。