确定netlogo中的最大,最小和平均乌龟簇大小以及乌龟簇数 [英] Determining max, min and mean turtle cluster size, as well as number of turtle clusters in netlogo
问题描述
请参阅下面的代码,用于确定随机分布的未定居海龟(黑色)中已定居的海龟群集(红色和灰色海龟)的数量,以及最大,最小和平均群集大小(径向)范围)在netlogo世界/界面中.
See the code below intended for determining the number of settled turtle clusters (Red and grey turtles) out of a number of randomly distributed non-settled turtles (black), as well as the maximum, minimum and mean cluster size (radial extent) in a netlogo world/ interface.
globals[ cluster-size cluster-count cluster-size-growth cluster-count-growth ]
to setup
clear-all
ask patches [ set pcolor white ]
create-turtles 1000 [
set color black
set label-color blue
setxy random-xcor random-ycor
set cluster-size 1
]
ask n-of 5 turtles [
ask turtles in-radius one-of [1 2 3] [
set color one-of [red grey]
]
]
end
to cluster-collect
let base-settlers turtles with [ color = red ]
let consp-settlers turtles with [ color = grey ]
ask base-settlers [
set cluster-count count consp-settlers in-radius cluster-size
set cluster-size-growth cluster-size + 1
set cluster-count-growth count consp-settlers in-radius cluster-size-growth
if cluster-count >= 1 [
ifelse ( cluster-count-growth - cluster-count != 0 ) [
set cluster-size cluster-size + 1
][
print count base-settlers with [ count turtles with [ color = grey ] >= 1 ]
]
]
]
print [ max cluster-size-growth ] of base-settlers
print [ max cluster-count-growth ] of base-settlers
print [ mean cluster-size-growth ] of base-settlers
print [ mean cluster-count-growth ] of base-settlers
print [ min cluster-size-growth ] of base-settlers
print [ min cluster-count-growth ] of base-settlers
print [ standard-deviation cluster-size-growth ] of base-settlers
print [ standard-deviation cluster-count-growth ] of base-settlers
print [ variance cluster-size-growth ] of base-settlers
print [ variance cluster-count-growth ] of base-settlers
end
我得到的错误如下:MAX expected input to be a list but got the number 10 instead.
我敢打赌,它对于均值和最小值函数也将执行相同的操作,因为它无法将基本定居者识别为代理集.关于如何转换此代码以获取最大,最小和平均集群大小(径向范围)以及已定居(红色和灰色)海龟数量的想法?
The error i get is the following: MAX expected input to be a list but got the number 10 instead.
I bet it would do the same for the mean and min functions as well because it is not recognizing base-settlers as an agent set. Any thoughts on how to transform this code to get the maximum, minimum and mean cluster size (Radial extent) and number of settled (red and grey) turtles?
推荐答案
运行代码时,NetLogo突出显示生成错误的行.问题行是print max cluster-size-growth
.如果您较早看,则在此之前有let cluster-size-growth cluster-size + 1
和let cluster-size 1
.因此cluster-size-growth
是1 + 1或数字2.变量cluster-count-growth
也是数字.
When you run the code, NetLogo highlights the line that generates the error. The problem line is print max cluster-size-growth
. If you look earlier, you have let cluster-size-growth cluster-size + 1
and let cluster-size 1
prior to that. So cluster-size-growth
is 1 + 1, or the number 2. The variable cluster-count-growth
is also a number.
我认为(但不确定)您正在尝试为每只乌龟计算这两个变量,然后取相同类型乌龟的最大/平均值/最小.如果是这样,则需要首先为所有海龟创建变量(即,结束ask []
语句),然后再执行类似print max cluster-size-growth of base-settlers
的操作.您可能还需要为这些变量建立turtle-own
变量,因为局部变量值将在ask []
块的末尾丢失.
I think (but am not sure) that you are trying to calculate these two variables for each turtle and then take the max/mean/min over the turtles of the same type. If so, you need to create the variable for all the turtles first (that is, end the ask []
statement), and then do something like print max cluster-size-growth of base-settlers
. You may also need to establish turtle-own
variables for these as the local variable values will be lost at the end of the ask []
block.
这篇关于确定netlogo中的最大,最小和平均乌龟簇大小以及乌龟簇数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!