I'm trying to assign my breed called "evacuees" their age based on a percentage. The number of evacuees is based on a slider in the interface, meaning that I don't have a fixed population to work with. They have two properties, "sex" and "age", which are both based on a percentage. I assigned the sex the following way:
let women n-of (count evacuees * 0.513) evacuees
ask women [set sex "female"]
ask evacuees [if not member? self women [set sex "male"]]
That works fine if you only have two categories. But when you have more than two (I have five different age groups) this doesn't work anymore. I tried to still use n-of
but with if conditions, so that the agents are not drawn from the whole pool of the evacuees, but only the ones that haven't had an age assigned yet:
set men-0-14 n-of (count evacuees with [sex = "male"] * 0.11) evacuees
ask men-0-14 [set age "0-14"]
ask evacuees [
if not member? self men-0-14 [
set men-15-19 n-of (count evacuees with [sex = "male"] * 0.04) evacuees with [sex = "male" AND
not member? self men-0-14]
]
]
ask men-15-19 [set age "15-19"]
ask evacuees [
if not member? self men-0-14 AND not member? self men-15-19 [
set men-20-39 n-of (count evacuees with [sex = "male"] * 0.26) evacuees with [sex = "male" AND
not member? self men-0-14 AND not member? self men-15-19]
]
]
ask men-20-39 [set age "20-39"]
... and so on for all five categories. But in the end I will still have some male evacuees that don't have an age assigned. I think that might be because of the usage of n-of
, that it always draws from the whole evacuees, even if using if
-conditions. Or it might be a problem of scheduling in NetLogo, that all of the evacuees are still part of the pool because the age group gets assigned definitely when the procedure is finished.
Is there another way to create the five agentsets that have an age assigned based on a certain percentage?