【问题标题】:How to divide turtles into different size-groups according to a turtle-own variable?如何根据海龟自身的变量将海龟分成不同大小的组?
【发布时间】:2019-09-02 10:02:35
【问题描述】:

我正在尝试通过根据收入(公司自有)为它们分配不同的规模来在一个行业(世界)中建立公司(海龟)。小型、中型和大型之间的区别应取决于收入占总收入的百分比。

更具体地说,根据他们的收入,我希望收入最低 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


    【解决方案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
    

    【讨论】:

      【解决方案2】:

      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
      

      【讨论】:

      • 这正是我想要的。非常感谢!
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-17
      • 2021-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多