NetLogo:如何找到每个补丁的 mean/sum 海龟数量?
NetLogo: how to find the mean/sum number of turtles per patch?
我想计算每个特定颜色斑块的平均(或 min/max)海龟数量。我想我必须使用 show max-one-of patches with [pcolor = red] [count turtles-here]
之类的东西,但如果我使用它,结果会是 p.ex。 patch 0 1. 但是,我想知道这个 patch 上海龟的数量,而不使用 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?
这实际上比看起来更棘手。 turtles-here
原语在调用者的补丁上创建海龟代理集,以下代码将 运行 遍历所有红色补丁,然后创建海龟计数列表。你可以通过在它前面放一个打印语句来自己看到它,你会得到一个数字列表。
[count turtles-here] of patches with [pcolor = red]
然后直接取该列表的平均值(或类似地取最大值或最小值)。
mean [count turtles-here] of patches with [pcolor = red]
我想计算每个特定颜色斑块的平均(或 min/max)海龟数量。我想我必须使用 show max-one-of patches with [pcolor = red] [count turtles-here]
之类的东西,但如果我使用它,结果会是 p.ex。 patch 0 1. 但是,我想知道这个 patch 上海龟的数量,而不使用 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?
这实际上比看起来更棘手。 turtles-here
原语在调用者的补丁上创建海龟代理集,以下代码将 运行 遍历所有红色补丁,然后创建海龟计数列表。你可以通过在它前面放一个打印语句来自己看到它,你会得到一个数字列表。
[count turtles-here] of patches with [pcolor = red]
然后直接取该列表的平均值(或类似地取最大值或最小值)。
mean [count turtles-here] of patches with [pcolor = red]