0

I'm trying to set up firms (turtles) in an industry (world) by assigning them different sizes according to their income (firms-own). The distinction between small, medium and large size should be dependent on the percentage of income in relation to the total income.

More specifically, dependent on their income I want the firms with the 30% lowest income to be of size 0.5, the firms with the 60% middle income to be of size 1, and the firms with the 10% highest income to be of size 1.5. So far I have:

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

I know the code does not work because I have not told the firms when to set their firms-own to "low", "medium", or "high". But I don't know how to get them to set it by percentage of the total income.

Thanks for your input here!

user11277648
  • 53
  • 1
  • 5

2 Answers2

1

If you only have the three classes, you could probably get away with a nested ifelse statement:

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

Outputs something like:

[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
Luke C
  • 10,081
  • 1
  • 14
  • 21
0

Luke Cs answer is pretty good, thumbs up! In case of only 3 income classes, you could also work max-n-of for the 10 % highest income firms and with min-n-of for 30 % lowest income firms. Everything else could be considered medium, but please check the example code below:

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
geruter
  • 386
  • 1
  • 6