I'm building a model where I want to distribute animals around a landscape. They have discrete amounts of energy and hence get a variable called energy
. The landscape has an overall set amount of energy that it could support set at 10950
.
These are the energy categories of the animals: 75, 216, 700, 2500, 5000, 8500, 25000
And they should appear in the landscape according to the following percentages (or probabilities if we divide by 100): 20.85714667, 7.24206481, 2.23469429, 0.6257144, 0.3128572, 0.18403365, 0.06257144
I can monitor the amount of energy in the system with:
set total_energy sum [energy] of turtles with [shape = "circle"]
Every day in the model I want to replenish the animals in the system up to a limit of energy set at 10950.
So the simulation should be populated with animals of the above listed energies according to the probabilities. I don't mind that on occasion a huge animal will be selected that would exceed the limit for the simulation (e.g. if a 25000 energy animal occurs, that will break the threshold which is fine).
It looks like I should combine while
with the rnd
extension but I can't quite crack it. Here's what I've got based on a related question:
extensions [ rnd ]
to replenish
while energy < 10950 [
let values [1 2 3] ; swap out for mine, should correspond to energy
let probabilities [0.2 0.3 0.5] ; swap out for mine
let pairs (map list values probabilities)
let state first rnd:weighted-one-of pairs [ last ? ] ; how to produce the turtles based on this?
]
end