NetLogo - no more than 5 % of population has a certain value of variable

痴心易碎 提交于 2019-12-11 17:18:07

问题


How can I give each tick a random amount of turtles a change in a binary variable (1 or 0), whereas no more than 5 % of the existing population at all times has a value of 0 in that variable?

In other words, I wish to have that the total amount of turtles having a variable value of 0 is between 0 % or 5 % of the total amount of turtles at every tick.

How can I achieve this?

My code is:

to setup 
     create-turtles 100
     set var random 1 (only 5 % max shall have a 0 at start)
end

to start
    change
end

to change 
    let %draw (random 1)
    if (%draw < 0) … ; than I do not how to continue
end

回答1:


The n-of primitive selects the specified number of agents. You want some number up to that, so you also need to randomly generate the number. Something like this:

to setup 
  create-turtles 100 [ set var 1 ] ; give them all value 1
  ask n-of random 6 turtles [ set var 0 ] ; randomly selects 0 to 5 turtles, assigns value 0
end


来源:https://stackoverflow.com/questions/54901887/netlogo-no-more-than-5-of-population-has-a-certain-value-of-variable

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!