如何根据乌龟拥有的变量将乌龟分为不同的大小组?

时间:2019-04-11 17:22:25

标签: math netlogo percentage agent-based-modeling economics

我正试图通过根据他们的收入(公司拥有)分配不同的规模来在一个行业(世界)中建立公司(乌龟)。小,中,大三者之间的区别应取决于收入相对于总收入的百分比。

更具体地说,根据收入,我希望收入最低的30%的公司的规模为0.5,中等收入的60%的公司的规模为1,而收入最高的10%的公司的规模为1。尺寸为1.5。 到目前为止,我有:

breed [ firms firm ]

firms-own [
  income
]

to setup
  create-firms number-of-firms [   ;; number of firms to be defined through slider
  set income random 100
   if income = "low" [ set size 0.5 ]   ;; firms with low output are of a small size
   if income = "medium" [ set size 1 ]   ;; firms with medium output are of a medium size
   if income = "high" [ set size 1.5 ]   ;; firms with high output are of a large size
end

我知道代码不起作用,因为我没有告诉企业何时将其企业所有者设置为“低”,“中”或“高”。但是我不知道如何让他们根据总收入的百分比来设置它。

谢谢您的输入!

2 个答案:

答案 0 :(得分:1)

如果只有三个类,则可能会使用嵌套的ifelse语句:

breed [ firms firm ]

firms-own [
  income
  income-class
]

to setup
  ca
  create-firms 10 [   
    while [ any? other turtles-here ] [
      move-to one-of neighbors 
    ]
    set income random 100
  ]
  let firm-incomes sort [income] of firms
  print firm-incomes

  ask firms [
    ifelse income < item ( length firm-incomes / 3 ) firm-incomes [
      set income-class "low"
      set size 0.5
    ] [
      ifelse income < item ( length firm-incomes * 9 / 10 ) firm-incomes [
        set income-class "medium"
        set size 1
      ] [
        set income-class "high"
        set size 1.5
      ]
    ]
  ]

  ; Just to check output:
  foreach sort-on [ income ] turtles [
    t ->
    ask t [
      show income
      show income-class
    ]
  ]
  reset-ticks
end

输出类似:

[16 20 20 47 52 58 69 83 88 97]
(firm 9): 16
(firm 9): "low"
(firm 0): 20
(firm 0): "low"
(firm 3): 20
(firm 3): "low"
(firm 5): 47
(firm 5): "medium"
(firm 7): 52
(firm 7): "medium"
(firm 4): 58
(firm 4): "medium"
(firm 2): 69
(firm 2): "medium"
(firm 1): 83
(firm 1): "medium"
(firm 6): 88
(firm 6): "medium"
(firm 8): 97
(firm 8): "high

答案 1 :(得分:0)

Luke Cs的回答非常好,竖起大拇指!在只有3个收入类别的情况下,您也可以为收入最高的10%的公司max-n-of工作,为收入最低的30%的公司使用min-n-of。其他所有内容都可以视为中等,但是请检查以下示例代码:

breed [ firms firm ]

firms-own [
  income
  income-class
]

to setup

  clear-all
  create-firms number-of-firms [   ;; number of firms to be defined through slider
    set income random 100
    set color red
    setxy random-xcor random-ycor
  ]  

  ask ( max-n-of ( number-of-firms * 0.1 ) firms [income] ) [ set income-class "high" set size 1.5] ;; the 10% firms with the highest value of income 
  ask ( min-n-of ( number-of-firms * 0.3 ) firms [income] ) [ set income-class "low" set size 0.5] ;; the 30% firms with the lowest value of income 

  ask firms with [income-class = 0 ] [set income-class "medium" set size 1] ;; all firms who have no income-class yet are set to "medium"


end