NetLogo根据特定标准继续搜索

时间:2014-08-01 20:09:37

标签: netlogo

我正在模拟雌性动物从母亲的领土分散,寻找自己的领地。基本上他们需要找到其他女性领地无人居住的区域。补丁有一个变量owner-fem,用于标识它所属的女性。理想情况下,我想要女性:

  1. 转到补丁

  2. 在该补丁周围的某个半径范围内搜索任何其他区域,如果该半径范围内还有另一个女性区域

  3. 转到另一个补丁,再次启动搜索过程。下面是我到目前为止,但我认为我没有正确使用in-radius

  4. 我不确定最好的方法是告诉女性继续寻找,直到病情满足为止。任何帮助将非常感激。

    to female-disperse
      move-to one-of patches with [owner-fem = nobody]
      if [owner-fem] of patches in-radius 3 != nobody
        [
          move-to one-of patches with [owner-fem = nobody]
        ]
    end
    

1 个答案:

答案 0 :(得分:2)

如果你想“一次性”,你可以让他们直接移动到合适的补丁:

to female-disperse
  move-to one-of patches with [
    not any? patches in-radius 3 with [owner-fem != nobody]
  ]
end

请注意patches in-radius包含乌龟所在的补丁,因此不需要单独的move-to one-of patches with [owner-fem = nobody]

我不知道你的模特需要什么,但如果我是你,我可能会尝试让它们逐渐分散。这是您可以从go过程(或任何其他永久运行的过程)调用的另一个版本:

to female-disperse
  ask females with [owner-fem != self ] [
    move-to one-of neighbors ; or however you want them to move
    if not any? patches in-radius 3 with [owner-fem != nobody] [
      set owner-fem self
    ]
  ]
end

在此版本中,所有不在其所有者的补丁上的女性移动到其中一个邻近的补丁。然后他们检查新补丁是否合适。如果是,他们就成了它的拥有者。如果不是,他们暂时停在那里:他们将继续搜索go的下一次迭代。你没有必要这样做;它可能只是松散地沿着这些方向发展。