Making an age distribution in netlogo

时间:2016-04-04 18:16:41

标签: distribution netlogo

I am very new to coding and I am having a bit of trouble. I am trying to make an age distribution in netlogo based off probabilities of having each age at setup.I set up a random-number variable that I am using to aid in the probability.The age probabilities are as follows:

days | probability

  _0  ____0.476
 _365__    0.229
 _730    __0.142
_1095   _0.081
_1460    _0.044
_1825    _0.019
_2190   _0.007
_2555  _0.002

I also need 2 pDogs to be age 2920

Here is what I have so far, but I'm not sure if there is a better way to do this.

    pDogs-own[family age health random-number]

    ask pDogs [
    set random-number random 1000.5]

    ask pDogs
    [if random-number <= 476 [set age 0]]
    ask pDogs
    [if ((random-number > 476) and (random-number <= 705)) [set age 365]] 
    ask pDogs
    [if ((random-number > 705) and (random-number <= 847)) [set age 730]]
    ask pDogs
    [if ((random-number > 847) and (random-number <= 928)) [set age 1095]]
    ask pDogs
    [if ((random-number > 928) and (random-number <= 972)) [set age 1460]]
    ask pDogs
    [if ((random-number > 972) and (random-number <= 991)) [set age 1825]]
    ask pDogs
    [if ((random-number > 991) and (random-number <= 998)) [set age 2190]]
    ask pDogs
    [if ((random-number > 998) and (random-number <= 1000)) [set age 2555]]

I am also trying another way to accomplish the same thing. First, I ask 2619 pDogs to be age = 0. I am trying to make a code that says:

    ask n-of 2619 pDogs [
    set age 0]
    ask pDogs [
    if age != 0 [
    ask n-of 1262 pDogs [
    set age 365]]] 

... but its not working.I ultimately want something that I can say that if the age is not one of the previously defined 0, 365, 730, etc. apply the next year/age value.

1 个答案:

答案 0 :(得分:0)

请参阅彩票示例。

或使用Payette的rnd扩展: https://github.com/NetLogo/Rnd-Extension#readme

但是如果你想要确切的数字,正如你最后建议的那样,你将需要一种不同的方法。例如:

turtles-own [age]

to setup
  let _numbers [5 10 15 10 5]
  let _ages [0 1 2 3 4]
  (foreach _ages _numbers [
    let _age ?1
    crt ?2 [set age _age]
  ])
end