I have written NetLogo code to make turtles change value turn by turn. Turtles are the farmers placed along a water stream. They will have differences in spatial water availability based on their who numbers and they will withdraw water as per their turn based on who number. Codes are doing fine. Every tick is taking more than usual time. I am seeing that the complete model will take even more time to run. Can these codes be changed to make the model efficiently run as per the set pattern given in the attached picture? Thanks for the help
Codes are given below
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
Your speed issue is because you are creating a long list using :
You'll need to make sure the list isn't growing linear with respect to ticks