在斑块上堆叠龟(品种)

时间:2013-10-23 19:41:06

标签: netlogo

我有两个品种,我想在设置程序中将每个品种分成10个,每个品种分别堆叠。我尝试过如下的简单表达式,但它们似乎不起作用。关于如何安排这个的任何想法?

ask breed1
  [
    if count breed1 patch-here < 10 and count breed2 patch-here = 0
   [move-to patch-here]
   ]

ask breed2
  [
    if count breed2 patch-here < 10 and count breed1 patch-here = 0
   [move-to patch-here]
   ]

更新

这段代码应该如何工作,但仍然没有做我想要的。感谢Seth指出模型库示例代码。它部分起作用,它会集中一些海龟,但仍然存在混合种群的斑块。我怀疑在go程序或某种循环它可能会工作,但在设置过程中它没有实现它应该的。

to concentrate

  ask breed1
  [
    let like-patches patches with [ any? breed1-here and not any? breed2-here]
    if any? like-patches
      [if count breed1-here < 10  
        [let target one-of like-patches
        face target
        move-to target ]  ]
  ] 

  ask breed2
  [
    let like-patches patches with [ any? breed2-here and not any? breed1-here]
    if any? like-patches 
    [if count breed2-here < 10     
      [let target one-of like-patches
        face target
        move-to target ]]

  ] 

如果我为每个品种创建一个补丁网格,这个简单的代码行似乎部分工作,所以它们在空间上与开头分开:

ask breed1
  [
    if count breed1-here > 10
    [move-to one-of patches with [count breed1-here >= 1]]
   ]

  ask breed2
  [
    if count breed2-here > 10
    [move-to one-of patches with [count breed2-here >= 1]]
   ]

2 个答案:

答案 0 :(得分:1)

您似乎要记住,patch-here会以某种方式引用您可能希望乌龟站在的所有可能的补丁?但事实并非如此;它只是指龟正在当前站立的单个补丁。所以move-to patch-here没有完成任何事情(除了将乌龟移动到它已经存在的补丁的中心点)。

您需要添加一些实际尝试不同候选补丁的代码。

我建议在模型库的代码示例部分中查看One Turtle Per Patch示例。它显示了每个补丁安排一个海龟的不同可能方法。然后,采用其中一种方法并将其推广以解决稍微复杂的问题。

<强>更新

您的新代码绝对更接近解决方案。但它有一个逻辑缺陷。

你写道:

let like-patches patches with [ any? breed1-here and not any? breed2-here]

但是如果 没有这样的补丁怎么办?很容易就没有了。在这种情况下,乌龟会留在原处。

你需要提出一些保证海龟会找到新家的逻辑。 (如果你自己手工安排海龟,你会怎么做?)

答案 1 :(得分:1)

比我想象的要简单得多!

patches-own [patchc]
to setup
  clear-all
  ask patches [set patchc false]
  ask n-of 30 patches [ sprout 10 [set breed breed1] set patchc true]
  ask n-of 30 patches with [patchc = false][ sprout 10 [set breed breed2] ]
end
相关问题