如何在netlogo中设置女性百分比?

时间:2014-01-10 18:42:30

标签: modeling agent netlogo

我有这个代码设置年龄段孩子,成人和老年人。如何使用滑块设置一些女性? 我只想建立女性和男性。就像你将滑块设置为30%一样。从孩子,成人和老年人中30%将成为女性

breed [kids kid]

breed [adults adult]

breed [oldies old]



to set-up

  __clear-all-and-reset-ticks

  ask patches [setup-world]

  ask patches with [pcolor = brown ][set plabel count turtles-here]

  set-default-shape turtles "person"


   create-kids number-of-kids 
  [set speed random-float speed-kids
    set body random-float kids-size
    ]


  create-adults number-of-adults 
  [set speed random-float speed-adults
    set body random-float adults-size]

  create-oldies number-of-oldies
  [set speed random-float speed-oldies
    set body random-float oldies-size]

  ask kids[

    set color green
    if(body > 0.9)[
    set size body]         
    setxy random 19 random 80
    facexy 18 43]

  ask adults[

    set color orange
      if(body > 0.9)[
    set size body]                       
    setxy -10 0
    setxy random 19 random 80
    facexy 18 43]

  ask oldies[

    set color blue
      if(body > 0.9)[
    set size body]                                 
    setxy -10 0
    setxy random 19 random 80
    facexy 18 43]

1 个答案:

答案 0 :(得分:2)

假设所有海龟都有is-female?属性和名为percent-female的滑块:

 turtles-own [is-female?]`

一种方法是计算每个人口的30%,例如:

ask n-of (percent-female / 100 * count kids) of kids [set is-female? true]

另一种,更多的是 Nelogo-ish 方式,在创造孩子,成人和老人时,将以概率的方式进行。例如:

    ask kids[
        if random 100 < percent-female [set is-female? true]
        set color green
        if(body > 0.9)[
        set size body]         
        setxy random 19 random 80
        facexy 18 43]