NetLogo-不超过5%的人口具有一定的变量值 [英] NetLogo - no more than 5 % of population has a certain value of variable

查看:122
本文介绍了NetLogo-不超过5%的人口具有一定的变量值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我该如何给每个刻度线随机龟一个二进制变量(1或0)的变化,而始终不超过现有种群的5%,该变量的值为0? >

换句话说,我希望变量值0的海龟总数在每个刻度上占海龟总数的0%或5%之间.

我该如何实现?

我的代码是:

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

解决方案

n-of原语选择指定数量的代理.您需要一些数字,所以您还需要随机生成数字.像这样:

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

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

解决方案

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

这篇关于NetLogo-不超过5%的人口具有一定的变量值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆