嗨,我正在做一个模型,我需要使用时间变量的值创建一个元素列表。这是我用来定义时间变量的代码
to react
ask cells
[
let Ai1 count turtles with [color = blue and xcor < -13 and ycor > -26]
let Ai2 count turtles with [color = blue and xcor < -13 and ycor < -27]
let Ai3 count turtles with [color = blue and xcor > -12 and xcor < 11 and ycor > -26]
let Ai4 count turtles with [color = blue and xcor > -12 and xcor < 11 and ycor < -26]
let Ai5 count turtles with [color = blue and xcor > 11 and ycor > -26]
let Ai6 count turtles with [color = blue and xcor > 11 and ycor < -26]
let Aimax list (Ai1 Ai2 Ai3 Ai4 Ai5 Ai6)
set calories (44.5 * random Aimax)
]
end
所以我需要创建一个Ai1...Ai6值的列表,然后随机选择这6个值中的一个,在时间变量Aimax值的下一个乘法中使用它,那么这样做是可能的吗?如果我使用随机命令,它可以在列表中使用吗?Tks用于阅读。
发布于 2015-10-14 02:21:24
one-of
将从列表中随机挑选一项:
set calories (44.5 * one-of Aimax)
发布于 2015-10-14 20:18:33
不要那样做。您让每个单元格计算所有的计数,这些计数只需要确定一次。你还用蓝色重复过滤你的乌龟。如果我们坚持你的界限,我们就可以写
to-report countblues
let blues (turtles with [color = blue])
let counts (list
count blues with [xcor < -13 and ycor > -26]
count blues with [xcor < -13 and ycor < -27]
count blues with [xcor > -12 and xcor < 11 and ycor > -26]
count blues with [xcor > -12 and xcor < 11 and ycor < -26]
count blues with [xcor > 11 and ycor > -26]
count blues with [xcor > 11 and ycor < -26]
)
report counts
end
to react
let counts countblues
ask cells[
set calories (44.5 * one-of counts)
]
end
请注意,如果你的乌龟从来不改变颜色,你可以把blues
变成一个全局的,尽管这会有很小的收益,并且每个全局都有引用透明度的代价。
https://stackoverflow.com/questions/33109084
复制相似问题