如何根据龟自己的变量将海龟分成不同的大小组?

问题描述 投票:0回答:2

我试图通过根据收入(企业自己)分配不同的规模来建立一个行业(世界)的公司(海龟)。小,中,大规模之间的区别应取决于收入占总收入的百分比。

更具体地说,根据他们的收入,我希望收入最低的30%的公司的规模为0.5,中等收入的60%的公司规模为1,收入最高的公司的规模为10%。 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

我知道代码不起作用,因为我没有告诉公司何时将他们的公司设置为“低”,“中”或“高”。但我不知道如何让他们按总收入的百分比来设定它。

感谢您的投入!

math netlogo percentage agent-based-modeling economics
2个回答
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

0
投票

卢克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
© www.soinside.com 2019 - 2024. All rights reserved.