Reputation: 7577
I want to create a directed graph with weights in netlogo. I searched documentions but I couldn't find a way to put weights on my links. Here is my code:
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
Upvotes: 2
Views: 1166
Reputation: 30453
links-own [weight]
(at the top of the Code tab) adds a variable named weight
to links.
Some models in the NetLogo Models Library that use links-own
: Small Worlds, Team Assembly, Diffusion on a Directed Network, Artificial Neural Net, Link Breeds Example, Network Import Example.
Upvotes: 4