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

define neighbor turtles using in-radius or 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)。这些海龟靠近世界的中心。

关于我做错了什么有什么想法吗?

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

假设第一个移动的乌龟移动到中心附近。 None 的其他海龟已经移动了,所以它们都还在 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