Reputation:
I've got a problem with netlogo: I want to spread an information in a network. One turtle has the information and gives it to its link-neighbors with a constant probability. This is the code i have so far:
to spread
if (count turtles with [informed? = true] > .7 * count turtles) [stop]
ask turtles with [ informed? = true ]
[
ask link-neighbors
[
if (random-float 1 <= 0.02)
[
set informed? true
show-turtle
set color green
]
]
]
set num-informed count turtles with [informed? = true]
tick
end
Now I want to know: How can I ensure, that every turtle gets the information only ONCE and is not informed twice? I tried "if not informed?", but that only got me error messages. And did I get the command "if (random-float 1 <= 0.02)" right, if i want the information to be spread with a constant probability of 2%?
Upvotes: 1
Views: 82
Reputation: 2096
This should work (not tested). Assumes that you have done set informed? FALSE
when you set up the turtles.
to spread
if (count turtles with [informed?] > .7 * count turtles) [stop]
ask turtles with [ informed? ]
[ ask link-neighbors with [ not informed? ] ; **<= my change**
[ if (random-float 1 <= 0.02)
[ set informed? true
show-turtle
set color green
]
]
]
set num-informed count turtles with [informed?]
tick
end
Upvotes: 1