使用半径或距离定义邻居海龟

时间:2015-04-27 12:57:57

标签: netlogo

我想使用in-radius或distance来定义邻居。到目前为止我的解决方案是:

turtles-own [
  my-neighbors
  num-neighbors]

to setup

ca
crt 100 [
  move-to one-of patches with [ not any? turtles-here ]
  set my-neighbors (other turtles) in-radius 3
  set num-neighbors count my-neighbors
]

end

这个问题是大多数海龟都有0到4个邻居,但其中一些邻居有相对数量的邻居(例如34和65)。这些海龟靠近世界的中心。

关于我做错了什么的想法?

1 个答案:

答案 0 :(得分:4)

它与你的程序中副作用的时间有关。

假设第一只移动的乌龟在中心附近移动。其他海龟都没有移动过,所以它们仍在patch 0 0上,而set my-neighbors (other turtles) in-radius 3将全部捕获它们。即使他们搬到其他地方,他们仍然会被包含在第一只海龟的my-neighbors代理人中。

您可以通过首先移动所有海龟然后计算他们的邻居来避免此问题:

to setup
  clear-all
  crt 100 [
    move-to one-of patches with [ not any? turtles-here ]
  ]
  ask turtles [
    set my-neighbors (other turtles) in-radius 3
    set num-neighbors count my-neighbors
  ]
end
相关问题