模型的效率:轮流灌溉与谁编号
Efficiency of the model: Turn by turn irrigate with who numbers
我写了NetLogo代码让海龟轮流改变值。乌龟是沿着水流放置的农民。他们将根据他们的人数在空间可用水量方面有所不同,并且他们将根据谁的人数轮流取水。代码运行良好。每个滴答声都比平时花费更多的时间。我看到完整的模型将花费更多时间 运行。是否可以根据附图中给出的设置模式更改这些代码以使模型有效 运行?
感谢帮助
代码如下
Breed [farmers farmer]
Farmers-own [water irrigation-turn]
to setup
clear-all
create-farmers 30 [ set irrigation-turn [0]
ask farmer 0 [ setxy min-pxcor + 1 0]
ask farmer 1 [ setxy min-pxcor + 1 2]
ask farmer 20 [ setxy min-pxcor + 1 4]
ask farmer 2 [ setxy min-pxcor + 3 0]
ask farmer 3 [ setxy min-pxcor + 3 2]
ask farmer 21 [ setxy min-pxcor + 3 4]
ask farmer 4 [ setxy min-pxcor + 5 0]
ask farmer 5 [ setxy min-pxcor + 5 2]
ask farmer 22 [ setxy min-pxcor + 5 4]
ask farmer 6 [ setxy min-pxcor + 7 0]
ask farmer 7 [ setxy min-pxcor + 7 2]
ask farmer 23 [ setxy min-pxcor + 7 4]
ask farmer 8 [ setxy min-pxcor + 9 0]
ask farmer 9 [ setxy min-pxcor + 9 2]
ask farmer 24 [ setxy min-pxcor + 9 4]
ask farmer 10 [ setxy min-pxcor + 11 0]
ask farmer 11 [ setxy min-pxcor + 11 2]
ask farmer 25 [ setxy min-pxcor + 11 4]
ask farmer 12 [ setxy min-pxcor + 13 0]
ask farmer 13 [ setxy min-pxcor + 13 2]
ask farmer 26 [ setxy min-pxcor + 13 4]
ask farmer 14 [ setxy min-pxcor + 15 0]
ask farmer 15 [ setxy min-pxcor + 15 2]
ask farmer 27 [ setxy min-pxcor + 15 4]
ask farmer 16 [ setxy min-pxcor + 17 0]
ask farmer 17 [ setxy min-pxcor + 17 2]
ask farmer 28 [ setxy min-pxcor + 17 4]
ask farmer 18 [ setxy min-pxcor + 19 0]
ask farmer 19 [ setxy min-pxcor + 19 2]
ask farmer 29 [ setxy min-pxcor + 19 4]
ask farmers [ set label who
set size 2]
]
reset-ticks
end
to go
define-irrigation-turn
irrigate
tick
end
to define-irrigation-turn ; 11 turtle ; 24 hours irrigation policy
ask farmers [set irrigation-turn [0]
ask farmer 0 [
repeat 235 [
set irrigation-turn lput 1 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
]]
ask farmer 1 [
repeat 235 [
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 1 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
]]
ask farmer 2 [
repeat 235 [
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 1 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
]]
ask farmer 3 [
repeat 235 [
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 1 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
]]
ask farmer 4 [
repeat 235 [
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 1 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
]]
ask farmer 5 [
repeat 235 [
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 1 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
]]
ask farmer 6 [
repeat 235 [
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 1 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
]]
ask farmer 7 [
repeat 235 [
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 1 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
]]
ask farmer 8 [
repeat 235 [
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 1 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
]]
ask farmer 9 [
repeat 235 [
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 1 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
]]
ask farmer 10 [
repeat 235 [
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 1 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
]]
ask farmer 11 [
repeat 235 [
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 1 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
]]
ask farmer 12 [
repeat 235 [
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 1 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
]
; Turtles 13-16 will follow the same pattern
]
ask farmer 17 [
repeat 235 [
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 1 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
]]
ask farmer 18 [
repeat 235 [
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 1 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
]]
ask farmer 19 [
repeat 235 [
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 1 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
]]
ask farmer 20 [
repeat 235 [
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 1 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
]]
ask farmer 21 [
repeat 235 [
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 1 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
]]
; farmers from 26-29 will follow the same pattern as of 20 t0 21
]
end
to irrigate
foreach [0 1 2 3 4 5 6 7 8 9 10 12 14 16 18 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30]
[ ?1 ->
ask farmers with [who = ?1] [
if (item ticks irrigation-turn) = 1
[ set color red
set shape "person"
]]]
end
您的速度问题是因为您正在使用创建一个长列表:
set irrigation-turn lput 1 irrigation-turn
您需要确保该列表不会随时间变化呈线性增长
您对时间在这些模型中的工作原理存在根本性的误解。命令 tick
指示模型提前时钟。它嵌入在一个 go 过程中,并且那个 go 过程(大概)运行每个滴答声。在 go 过程中你需要的是在一个时间步内发生的事情。相反,目前,您正在追加另外五年的时间表。
如果您需要一个时间表,因为您希望每只乌龟转一圈,然后在下一个刻度移动到下一只乌龟,请在设置过程中构建时间表,而不是在运行过程中。您可能还应该使用 mod
运算符,因为它是一个循环,所以您不需要五年的时间表,您可以只存储一个循环。您也不需要使用 lput
单独附加每个项目,只需一次提供整个列表即可。
像这样(注意我已经完全放弃了时间表,只使用 mod
循环):
breed [farmers farmer]
farmers-own [water irrigation-turn]
to setup
clear-all
create-farmers 30
[ set label who
set size 2
]
ask farmer 0 [ setxy min-pxcor + 1 0 set irrigation-turn 0]
ask farmer 1 [ setxy min-pxcor + 1 2 set irrigation-turn 1]
ask farmer 20 [ setxy min-pxcor + 1 4 set irrigation-turn 2]
; and similarly for remaining farmers
reset-ticks
end
to go
irrigate
tick
end
to irrigate
ask turtles with [irrigation-turn = (ticks mod count farmers)]
; do whatever it is they do when it's their turn
ask turtles with [irrigation-turn != (ticks mod count farmers)]
; do whatever it is they do when it's not their turn
end
或者如果你想保持一个时间表(例如,因为有些周不适合一个周期),那么直接构建一个。例如,如果您想要 4 周周期的第 3 周,您可以简单地执行:
set irrigation-turn [ 0 0 1 0]
还有其他技术可以使用 reduce sentence n-values
来制作更长的列表,但我认为没有它们也可以解决您的效率问题。
我写了NetLogo代码让海龟轮流改变值。乌龟是沿着水流放置的农民。他们将根据他们的人数在空间可用水量方面有所不同,并且他们将根据谁的人数轮流取水。代码运行良好。每个滴答声都比平时花费更多的时间。我看到完整的模型将花费更多时间 运行。是否可以根据附图中给出的设置模式更改这些代码以使模型有效 运行? 感谢帮助
代码如下
Breed [farmers farmer]
Farmers-own [water irrigation-turn]
to setup
clear-all
create-farmers 30 [ set irrigation-turn [0]
ask farmer 0 [ setxy min-pxcor + 1 0]
ask farmer 1 [ setxy min-pxcor + 1 2]
ask farmer 20 [ setxy min-pxcor + 1 4]
ask farmer 2 [ setxy min-pxcor + 3 0]
ask farmer 3 [ setxy min-pxcor + 3 2]
ask farmer 21 [ setxy min-pxcor + 3 4]
ask farmer 4 [ setxy min-pxcor + 5 0]
ask farmer 5 [ setxy min-pxcor + 5 2]
ask farmer 22 [ setxy min-pxcor + 5 4]
ask farmer 6 [ setxy min-pxcor + 7 0]
ask farmer 7 [ setxy min-pxcor + 7 2]
ask farmer 23 [ setxy min-pxcor + 7 4]
ask farmer 8 [ setxy min-pxcor + 9 0]
ask farmer 9 [ setxy min-pxcor + 9 2]
ask farmer 24 [ setxy min-pxcor + 9 4]
ask farmer 10 [ setxy min-pxcor + 11 0]
ask farmer 11 [ setxy min-pxcor + 11 2]
ask farmer 25 [ setxy min-pxcor + 11 4]
ask farmer 12 [ setxy min-pxcor + 13 0]
ask farmer 13 [ setxy min-pxcor + 13 2]
ask farmer 26 [ setxy min-pxcor + 13 4]
ask farmer 14 [ setxy min-pxcor + 15 0]
ask farmer 15 [ setxy min-pxcor + 15 2]
ask farmer 27 [ setxy min-pxcor + 15 4]
ask farmer 16 [ setxy min-pxcor + 17 0]
ask farmer 17 [ setxy min-pxcor + 17 2]
ask farmer 28 [ setxy min-pxcor + 17 4]
ask farmer 18 [ setxy min-pxcor + 19 0]
ask farmer 19 [ setxy min-pxcor + 19 2]
ask farmer 29 [ setxy min-pxcor + 19 4]
ask farmers [ set label who
set size 2]
]
reset-ticks
end
to go
define-irrigation-turn
irrigate
tick
end
to define-irrigation-turn ; 11 turtle ; 24 hours irrigation policy
ask farmers [set irrigation-turn [0]
ask farmer 0 [
repeat 235 [
set irrigation-turn lput 1 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
]]
ask farmer 1 [
repeat 235 [
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 1 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
]]
ask farmer 2 [
repeat 235 [
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 1 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
]]
ask farmer 3 [
repeat 235 [
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 1 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
]]
ask farmer 4 [
repeat 235 [
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 1 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
]]
ask farmer 5 [
repeat 235 [
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 1 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
]]
ask farmer 6 [
repeat 235 [
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 1 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
]]
ask farmer 7 [
repeat 235 [
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 1 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
]]
ask farmer 8 [
repeat 235 [
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 1 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
]]
ask farmer 9 [
repeat 235 [
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 1 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
]]
ask farmer 10 [
repeat 235 [
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 1 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
]]
ask farmer 11 [
repeat 235 [
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 1 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
]]
ask farmer 12 [
repeat 235 [
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 1 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
]
; Turtles 13-16 will follow the same pattern
]
ask farmer 17 [
repeat 235 [
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 1 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
]]
ask farmer 18 [
repeat 235 [
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 1 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
]]
ask farmer 19 [
repeat 235 [
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 1 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
]]
ask farmer 20 [
repeat 235 [
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 1 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
]]
ask farmer 21 [
repeat 235 [
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 1 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
set irrigation-turn lput 0 irrigation-turn
]]
; farmers from 26-29 will follow the same pattern as of 20 t0 21
]
end
to irrigate
foreach [0 1 2 3 4 5 6 7 8 9 10 12 14 16 18 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30]
[ ?1 ->
ask farmers with [who = ?1] [
if (item ticks irrigation-turn) = 1
[ set color red
set shape "person"
]]]
end
您的速度问题是因为您正在使用创建一个长列表:
set irrigation-turn lput 1 irrigation-turn
您需要确保该列表不会随时间变化呈线性增长
您对时间在这些模型中的工作原理存在根本性的误解。命令 tick
指示模型提前时钟。它嵌入在一个 go 过程中,并且那个 go 过程(大概)运行每个滴答声。在 go 过程中你需要的是在一个时间步内发生的事情。相反,目前,您正在追加另外五年的时间表。
如果您需要一个时间表,因为您希望每只乌龟转一圈,然后在下一个刻度移动到下一只乌龟,请在设置过程中构建时间表,而不是在运行过程中。您可能还应该使用 mod
运算符,因为它是一个循环,所以您不需要五年的时间表,您可以只存储一个循环。您也不需要使用 lput
单独附加每个项目,只需一次提供整个列表即可。
像这样(注意我已经完全放弃了时间表,只使用 mod
循环):
breed [farmers farmer]
farmers-own [water irrigation-turn]
to setup
clear-all
create-farmers 30
[ set label who
set size 2
]
ask farmer 0 [ setxy min-pxcor + 1 0 set irrigation-turn 0]
ask farmer 1 [ setxy min-pxcor + 1 2 set irrigation-turn 1]
ask farmer 20 [ setxy min-pxcor + 1 4 set irrigation-turn 2]
; and similarly for remaining farmers
reset-ticks
end
to go
irrigate
tick
end
to irrigate
ask turtles with [irrigation-turn = (ticks mod count farmers)]
; do whatever it is they do when it's their turn
ask turtles with [irrigation-turn != (ticks mod count farmers)]
; do whatever it is they do when it's not their turn
end
或者如果你想保持一个时间表(例如,因为有些周不适合一个周期),那么直接构建一个。例如,如果您想要 4 周周期的第 3 周,您可以简单地执行:
set irrigation-turn [ 0 0 1 0]
还有其他技术可以使用 reduce sentence n-values
来制作更长的列表,但我认为没有它们也可以解决您的效率问题。