NetLogo:如何找到每个补丁的平均/总数?

时间:2015-08-18 06:55:48

标签: netlogo

我想计算每个特定颜色斑块的平均(或最小/最大)海龟数量。我想我必须使用类似show max-one-of patches with [pcolor = red] [count turtles-here]之类的东西,但如果我使用它,我会得到p.ex.补丁0 1.但是,我想知道这个补丁上的海龟数量,而不使用inspect patch 0 1。当我运行ask patches with [pcolor = red] [sum turtles-here]时出现错误expected comand

感谢您的每一个建议!

to setup
  clear-all
  crt 1000 [ setxy random-xcor random-ycor ] ; randomly distribute turtles
  setup-patches
  show max-one-of patches with [pcolor = red] [count turtles-here] ; show patch with max number of turtles here
  reset-ticks
end

to setup-patches
  ask patches [set pcolor green]
  ask n-of (count patches / 2) patches [set pcolor red]  ; turn half of patches red
  ; ask patches with [pcolor = red] [sum turtles-here] ; - how to run this?
end

; how to count max number of turtles per red patch?

1 个答案:

答案 0 :(得分:2)

这实际上比它看起来更棘手。 turtles-here原语在调用者的补丁上创建了乌龟的代理集,下面的代码将遍历所有红色补丁,然后创建乌龟计数列表。您可以通过在其前面放置一个打印语句来自己查看,然后您将获得一个数字列表。

  [count turtles-here] of patches with [pcolor = red]

然后直接采用该列表的平均值(或类似的最大值或最小值)。

  mean [count turtles-here] of patches with [pcolor = red]