如何在netlogo中使模拟运行更快,而不是使用附近的Slider栏来查看更新

时间:2014-10-14 23:14:40

标签: netlogo

是否有任何代码可以让netlogo中的模拟运行速度更快,而不是使用靠近设置的滑块?我的代码需要做的是模拟人群行为,如果海龟数量在100左右就可以正常工作,但是当我将数量增加到300-800只时,模拟需要很长时间才能完成。每个蜱也需要很长时间才能从0到1计数,接着是所有海龟死亡。我怀疑造成缓慢模拟的一件事是当要求乌龟撤离时。没有疏散规则,一切顺利甚至设置了最大数量的海龟。还有其他方法来编写撤离规则,以便它可以更快地运行吗?感谢。

to go
  ask turtles [wander fd 0.01]

  if emergency? = true [move]
  if all? turtles [ pcolor = red ]   ;stops simuation
  [stop]
  tick
end

to wander
  [ do..something]
end

to move
  set time-to-evacuate time-to-evacuate + 1
  ask turtles [avoid-obstacles fd 0.1]
  ask turtles [follow-leader fd 0.1]
  ask turtles [flock fd 0.1]
  ask turtles with [pcolor != red] [evacuate fd 0.1]
  ask turtles with [pcolor = red][die]
end

to evacuate
  ask turtles with [color = black ]
  [let beings-seen patches in-cone 10 135 with [pcolor = red] 
    if any? beings-seen 
    [ let target one-of beings-seen
      face target]]

  ask turtles with [color = white ]
  [let beings-seen patches in-cone 5 135 with [pcolor = red] 
    if any? beings-seen 
    [ let target one-of beings-seen
      face target]]
end

to avoid-obstacles
  [do something]
end

to follow-leader
  [do something]
end

to flock
  [do something]
end

1 个答案:

答案 0 :(得分:1)

在您的move程序中:

ask turtles with [pcolor != red] [ evacuate ... ]

然后在evacuate中你有:

ask turtles with [color = black] [ ... ]

evacuate已经被所有非红海龟运行了,所以你每只非红乌龟都要求每只乌龟在每次蜱虫时都做点什么。

我不认为你打算这样做。

我必须对你的意图进行一些猜测,但我认为如果在evacuate中你将ask替换为if

if color = black [ ... ]

这可能更接近你的意思。