Search code examples
netlogoagent-based-modelingeconomics

How to divide turtles in groups by percent?


In my world, turtles are firms. 30 % of all firms have a low output (Y = 1), 60 % a medium (Y = 2) and 10 % a high production output (Y = 3).

How can I assign an input for Y to 30 % of my turtles/firms? Best would be to have a slider in order to change the values if needed.

I have given the turtles a firm-own variable called Y which is their output. I have also created number-of-firms slider where I can decide how many firms will be in the world for each setup.

breed [ firm firms ]

firm-own [
  Y    ;; output
  ]

to setup
  clear-all  
  setup-industry  
  reset-ticks
end

to setup-industry
  create-firm number-of-firms [   ;; number of firms to be defined through slider
  ask n-of ( count firms * 0.3 ) firms [
    set Y 1 ]
  ask n-of ( count firms * 0.6 ) firms [
    set Y 2 ]
  ask n-of ( count firms * 0.1 ) firms [
    set Y 3 ]
  ]
end

The error message says that when I have "ask n-of ( count firms ... )" firms are expected to have 1 input, meaning a number.


Solution

  • The first input in breed defines the agentset whereas the second input goes for a single member. Consider following modifications:

        breed [ firms firm ]
    
        firms-own [
        Y    ;; output
        ]
        ...
        create-firms number-of-firms [   ;; number of firms to be defined through slider
    

    Now you won't have any error messages.