【问题标题】:NetLogo: set initial turtles number with empty neighbors around?NetLogo:用周围的空邻居设置初始海龟数量?
【发布时间】:2014-06-26 19:10:13
【问题描述】:

我要求补丁在界面上发芽数量等于滑块初始种群的海龟,现在我不希望每个海龟在空周围有邻居并且每个补丁包含一只海龟。在我的错误代码下方

to setup-turtles

  set-default-shape turtles "circle"
  ask n-of initial-population patches with [(pcolor = white - 1) and (not any? other turtles-here) and (not any? turtles-on neighbors)] [
    sprout-normals 1 [       
        set color blue
        set size 1        
    ]
  ]

end

但没有结果邻居为空 foreach turtle..为什么?

【问题讨论】:

    标签: netlogo


    【解决方案1】:

    我不确定这是否真的是您要问的,因为“每只乌龟周围都有空的邻居,并且每个补丁包含一只乌龟”这句话真的很难理解,但这是我的猜测:

    您希望海龟只出现在它们没有任何邻居的补丁上。但它不起作用,因为在您选择补丁时每个补丁都满足(not any? other turtles-here) and (not any? turtles-on neighbors) 的标准。一旦您开始使海龟发芽,该条件就不再适用于每个补丁,但您的代码并未考虑这一事实,因为您已经要求补丁让海龟发芽。

    您需要做的是每次添加海龟时再次检查条件。您可以使用repeat 然后one-of 而不是n-of 来做到这一点:

      repeat initial-population [
        ask one-of patches with [(pcolor = white - 1) and (not any? other turtles-here) and (not any? turtles-on neighbors)] [
          sprout-normals 1 [       
            set color blue
            set size 1        
          ]
        ]
      ]
    

    【讨论】:

    • 如果运行速度足以满足您的需求,那就太好了。如果你发现它太慢了,你可能需要一个稍微不同的算法,一个不涉及每次放置海龟时迭代所有补丁的算法。
    猜你喜欢
    • 2019-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-11
    • 1970-01-01
    相关资源
    最近更新 更多