根据百分比分配变量
我试图根据百分比分配称为“撤离”年龄的品种。撤离人员的数量基于界面中的滑块,这意味着我没有固定的人口可以使用。他们有两个属性,“性别”和“年龄”,它们都是基于百分比的。 我以以下方式分配了性别:
let women n-of (count evacuees * 0.513) evacuees
ask women [set sex "female"]
ask evacuees [if not member? self women [set sex "male"]]
如果您只有两个类别,那就可以了。但是,当您有两个以上(我有五个不同的年龄段)时,这已经不再起作用了。我试图仍然使用n-of
,但是如果条件,则不会从整个撤离者的整个池中绘制代理,而只是尚未分配的年龄的代理:
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"]
。 ..等所有五个类别等等。但是最后,我仍然会有一些没有分配年龄的男性撤离者。我认为这可能是因为的n of
的使用始终是从整个撤离者中汲取的,即使使用 - 条件。或者可能是Netlogo计划的一个问题,所有撤离者仍然是池的一部分,因为在完成过程后,年龄组绝对会分配。
是否有另一种方法可以创建根据一定百分比分配年龄的五个代理集?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个通用解决方案,可让您在设置中以不错的表格格式分配性别和年龄组,然后将每个组的这些百分比应用于多大的海龟,并报告结果。它似乎有效。
Here's a generic solution that lets you assign sexes and age-groups in a nice table format in setup, then applies those percentages of each group to however many turtles you have, and reports on the results. It seems to work.