【问题标题】:NetLogo: Calculate turtles' offsprings on patches (by sprout function?)NetLogo:计算海龟在补丁上的后代(通过发芽函数?)
【发布时间】:2015-08-10 19:47:51
【问题描述】:

在我的 NetLogo 世界表面上,我想计算粉红色补丁上的海龟数量。接下来,我想包括复制过程。更具体地说,我想将这些斑块上的海龟数量乘以每只海龟的后代数量 (3),从而创建新海龟。 后代应该具有其父母的品质。

按步骤: 1. 在粉红色的补丁上创建 100 只海龟(父母) 2.确定每个粉红色补丁的海龟数量(我想将此模型合并到更大的模型中)并将其乘以 3 -> 100 个父母有 300 个后代 3.让父母死,只留下后代 4.每个粉红色补丁产生的乌龟数量:300

似乎使用sprout 足以在每个粉红色的补丁上产生海龟。但是我不明白如何包含这个后代创作?我知道我可以通过

计算每个补丁的海龟数量

用 [pcolor = pink] 显示 [count turtles-here] 补丁

但是如何在我的新海龟(后代)创建中包含这些信息?又如何“复制”父母的品质? (变红了?)

我尝试合并此处发布的答案,但没有成功:Sprouting turtles in NetLogo based on patch value

非常感谢,这是我的代码:

to setup
  clear-all
  setup-patches
  setup-turtles
  reset-ticks
end

; create diverse landscape
to setup-patches
  ask n-of 5 patches [ set pcolor pink ]
end

; create turtles on pink patches

to setup-turtles 
  ask patches with [pcolor = pink] [sprout 100 [ set color red ]]   
  ; ask patches with [pcolor = pink] [count turtles-here]
  ; show [count turtles-here] of patches with [pcolor = pink]        ; calculate number of turtles on every pink patch
  let patch-list [count turtles-here] of patches with [pcolor = pink] 
  let i 0
  foreach patch-list [
    ask ? [
      sprout item i patch-list
      set plabel count turtles-here
    ]
    set i i + 1
  ]
  reset-ticks
end

【问题讨论】:

    标签: netlogo


    【解决方案1】:

    您要查找的原语是hatch。如果你 ask 一个父级到 hatch 一个后代,它会自动复制所有父级在后代中的属性:

    to setup
      clear-all
      ask n-of 5 patches [ set pcolor pink ]
    
      ; create 100 parent turtles on pink patches
      ask patches with [ pcolor = pink ] [ sprout 100 ]
    
      ; show that each pink patch has 100 turtles on it (the parents)
      show [ count turtles-here ] of patches with [ pcolor = pink ]
    
      ; ask each parent to hatch 3 offsprings and then die
      ask turtles [
        hatch 3
        die
      ]
    
      ; show that each pink patch now has 300 turtles on it (the offsprings)
      show [ count turtles-here ] of patches with [ pcolor = pink ]
    
    end
    

    【讨论】:

      【解决方案2】:

      简单的解决方案,结合

      发芽数龟-这里

      进入我的简单公式:

      to setup
        clear-all
        setup-patches
        setup-turtles
        reset-ticks
      end
      
      to setup-patches
        ask n-of 5 patches [ set pcolor pink ]
      end
      
      to setup-turtles 
        ; create parents
        ask patches with [pcolor = pink] [sprout 100 [ set color red ]]  
        ; create offsprings (*3) and let parents die (- count turtles-here)
        ask patches with [pcolor = pink] 
          [sprout count turtles-here * 3 - count turtles-here [ set color red ]]
        ; show [count turtles-here] of patches with [pcolor = pink] 
        ask patches with [pcolor = pink] [set plabel count turtles-here]  
      end
      

      【讨论】:

      • 这不符合您问题的要求。你说你想在每个粉红色的补丁上创建 100 只父母海龟,让他们在每个补丁上创建 300 只后代,然后杀死 100 只父母。您的代码所做的是在每个粉色补丁上创建 100 个海龟,然后在每个补丁上再创建 200 个。这有点不同。
      • 谢谢@NicolasPayette! :) 是的,您的解决方案要好得多。
      猜你喜欢
      • 2014-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多