Netlogo 比较补丁

Netlogo 比较补丁,netlogo,Netlogo,我想比较某个半径内的补丁,看它们上面某类代理的数量。代理应该移动到代理最多(在本例中为人类)的补丁。如果他们已经和大多数人在同一块,那么他们就不能移动。我对它和人类群体进行了编码,但他们中的大多数人不会排队(一个在另一个后面)跑来跑去。如果你们中有人能快速查看一下我的代码,那就太好了。谢谢 if Strategy = "Gathering-Simple" [ if ((count(humans-on max-one-of patches in-radius rad [count(hum

我想比较某个半径内的补丁,看它们上面某类代理的数量。代理应该移动到代理最多(在本例中为人类)的补丁。如果他们已经和大多数人在同一块,那么他们就不能移动。我对它和人类群体进行了编码,但他们中的大多数人不会排队(一个在另一个后面)跑来跑去。如果你们中有人能快速查看一下我的代码,那就太好了。谢谢

if Strategy = "Gathering-Simple" [

    if ((count(humans-on max-one-of patches in-radius rad [count(humans-here)] )) ) >= count(humans-here) [
    if count(humans-on patches in-radius rad) - count(humans-here) > 0 [


      face max-one-of patches in-radius rad [count(humans-here)]
    fd 1
    ]]
    ]

这是一个使用您的代码的完整工作示例。这是否显示了你的意思?它确实有海龟互相追逐

to setup
  clear-all
  create-turtles 100 [ setxy random-xcor random-ycor ]
  reset-ticks
end

to go
  let rad 5
  ask turtles
  [ let target-patch max-one-of patches in-radius rad [count turtles-here]
    if count turtles-on target-patch >= count turtles-here              ; comment 1
    [ if count turtles-on patches in-radius rad > count turtles-here    ; comment 2
      [ face target-patch
        forward 1
      ]
    ]
  ]
  tick
end
如果是这样,请看一下我对这两行的评论

注释1:>=意味着,即使海龟已经在最高计数的补丁上,该条件也将得到满足,因为这里的
计数海龟
将等于最高计数补丁(该补丁)上的海龟计数

注释2:这条线意味着,只要在半径范围内的任何一块地上有海龟,但在询问海龟所在的特定块地上没有海龟,那么海龟就会向前移动

如果您只想让海龟在不使用最大计数补丁的情况下移动,请尝试以下方法:

to setup
  clear-all
  create-turtles 100 [ setxy random-xcor random-ycor ]
  reset-ticks
end

to go
  let rad 5
  ask turtles
  [ let target-patch max-one-of patches in-radius rad [count turtles-here]
    if count turtles-on target-patch > count turtles-here
    [ face target-patch
      forward 1
    ]
  ]
  tick
end

我去掉了注释1行中的=并完全删除了第二个条件,因此,如果海龟当前的补丁数量较少(严格地说,不是我同意上一篇文章,但有一些额外的信息),那么它们就会移动

如果您想在每次迭代中完全移动到目标面片,而不是朝目标面片移动一步,在上面的回答中,您可以替换产生一步移动的代码

[ face target-patch
  forward 1
]


我通过实验证实,两种移动方法的结果会产生相似但略有不同的结果。

非常感谢JenB!这很有道理。我不知道目标命令!:-)没有目标-命令。我创建了一个名为target patch的临时变量来存储海龟数量最多的补丁。谢谢。是的,move to命令很方便,但在我的示例中,海龟的移动速度不允许超过1/tick
 [ 
    move-to target-patch
 ]