信息传播

时间:2016-01-14 18:15:54

标签: network-programming netlogo information-visualization

我遇到netlogo的问题:我想在网络中传播信息。一只乌龟有信息,并以恒定的概率将其提供给其链接邻居。这是我到目前为止的代码:

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

现在我想知道:我怎样才能确保每只乌龟只获得ONCE信息并且不会被告知两次?我试过“如果没有通知?”,但这只是给我错误信息。如果我希望信息以2%的常数概率传播,我是否将命令“if(random-float 1&lt; = 0.02)”改为正确?

1 个答案:

答案 0 :(得分:1)

这应该有效(未经测试)。假设您在设置海龟时已经完成了set informed? FALSE

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