1

我的模型代表流感通过成人和儿童两个不同品种的传播。

我想做的是为成人和儿童添加单独的疫苗接种,允许我从界面中指定两个疫苗接种值,从而为两种不同品种的海龟接种疫苗

我当前的代码如下,我想做的是使用接口值 Adult-vaccination 为该品种中的一定比例的海龟接种疫苗。

ask turtles with [ adult? = true ]
   [
   if (adult-vaccination = 1) 
   [
    reset-node
    set exposed? false
    set susceptible? false
    set temp-infected? false
    show-turtle
    set color pink
    ]
    ]
4

1 回答 1

2

如果adult-vaccination是从 0 到 1 的概率,您可以像这样以概率方式为成年人接种疫苗:

ask turtles with [ adult? ] [
  if random-float 1 < adult-vaccination [
    ... ; vaccination code here
  ]
]

如果您想adult-vaccination实际确定接种疫苗的人口比例,您可以这样做:

let adults turtles with [ adult? ]
ask n-of round (adult-vaccination * count adults) adults [
  ...; vaccination code here
]

其他一些花絮:

  • variable = true将与variableif variableis always trueor相同false
  • 这看起来是使用品种的绝佳机会。你会有一个adults品种和children品种。然后你可以做一些事情,比如ask adults [ do stuff ]给成人和孩子不同的变量等等。
于 2014-03-04T15:29:17.787 回答