Reputation: 189
Hi i am doing a model and i need to make a list of elements using the values of a temporal variable. This is the code that i have used to define my temporal variables
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
So i need to make a list of the Ai1...Ai6 values and then choose ramdomly one of this 6 values to use it in the next multiplication of the temporal variable Aimax so is posible to do that? If i use the command random it can be used in lists? Tks for reading.
Upvotes: 0
Views: 52
Reputation: 9620
Don't do it that way. You are having each cell compute all the counts, which only need to be determined once. You also repeated filter your turtles on the color blue. If we stick with your bounds, we can write
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
Note that if you turtles never change colors you could turn blues
into a global, although there would be small gain to that and each global has a cost in referential transparency.
Upvotes: 0
Reputation: 12580
one-of
will pick a random item from a list:
set calories (44.5 * one-of Aimax)
Upvotes: 1