Francesca Carta

Simulation models for economics

Project work on

"Rat Race."

 

The applet requires Java 5 or higher. Java must be enabled in your browser settings. Mac users must have Mac OS X 10.4 or higher. Windows and Linux users may obtain the latest Java from Oracle's Java site.


Here you can find an introduction to the Rat Race application.


powered by NetLogo

view/download model file: rat_race.nlogo

WHAT IS IT?

(a general understanding of what the model is trying to show or explain)

HOW IT WORKS

(what rules the agents use to create the overall behavior of the model)

HOW TO USE IT

(how to use the model, including a description of each of the items in the Interface tab)

THINGS TO NOTICE

(suggested things for the user to notice while running the model)

THINGS TO TRY

(suggested things for the user to try to do (move sliders, switches, etc.) with the model)

EXTENDING THE MODEL

(suggested things to add or change in the Code tab to make the model more complicated, detailed, accurate, etc.)

NETLOGO FEATURES

(interesting or unusual features of NetLogo that the model uses, particularly in the Code tab; or where workarounds were needed for missing features)

RELATED MODELS

(models in the NetLogo Models Library and elsewhere which are of related interest)

CREDITS AND REFERENCES

(a reference to the model’s URL on the web if it has one, as well as any other necessary credits, citations, and links)

CODE

breed [workers worker]

breed [firms firm]

workers-own [myFirm productivity friends pastFirm myFriends My_Friends]

firms-own [employees wage_rate total_productivity  workers_hired average_productivity past_employees]



to setup 
  ca
  setup-patches
  setup-workers
  setup-firms
  friend
 
  reset-ticks
 
end

to setup-patches
  ask patches [set pcolor blue]
end

to setup-workers
  
  
  create-workers initial_lowP_workers [set color red set productivity 1.0 set friends random 4]
  
  create-workers initial_medP_workers [set color yellow set productivity 2.0 set friends random 4]

  create-workers initial_highP_workers [set color green set productivity 3.0 set friends random 4]


  ask workers [
                                set shape "person"
                                set size 1
                                setxy random-xcor random-ycor
                                
                                set myFirm nobody  
                                set pastFirm []
                                set myFriends []  
                                set My_Friends[] ]
  
  
end


to setup-firms
  
  
  
create-firms initial_lowW_firms [set size 1.5 set wage_rate 1.0]
  
create-firms initial_medW_firms [set size 2.0 set wage_rate 2.0]
  
create-firms initial_highW_firms [set size 2.5 set wage_rate 3.0]
  
  
ask firms [
                   set shape "factory"
                   set color white
                   setxy random-xcor random-ycor 
                   set employees [] 
                   set past_employees [] ]
end
                  

 to friend
   
   ask workers with [ myFriends = []] 
   [ if friends = 3
   
   [ set myFriends workers with [friends = 3]  
     ask myFriends [set My_Friends lput myself My_Friends]]
   
    if friends = 2
   
   [ set myFriends  workers with [friends = 2] 
     ask myFriends [set My_Friends lput myself My_Friends]]
   
    
    if friends = 1
   
   [ set myFriends workers with [friends = 1] 
     ask myFriends [set My_Friends lput myself My_Friends]]]
     
   
end
 
 


to go
  search-for-job                                                                    
  show-firms
  hire-workers
  show-workers
  research-for-job
  ;do-plots
  
  if (count firms with [ color = white ]) = 0 [stop]
  if (count workers with [ size = 1] + count workers with [ size = 2 ]) = 0 [stop]
  
  tick

end


to search-for-job
  
 
  ask workers 
  
  [ ifelse discrimination?  and ticks > (discrimination)
     
     [ 
       ask workers with [myFirm = nobody and size = 1 and myFriends != [] ]
          [ move-to one-of myFriends with [size = 2 and myFirm != nobody ] 
           set myFirm one-of firms with [color = white] in-radius 0
                      if myFirm != nobody  [set size 2       
           
                      
                      ask myFirm [set employees lput myself employees
                                  set total_productivity (sum [ productivity] of workers-here with [myFirm != nobody])
                                  set workers_hired  (count workers-here with [myFirm != nobody])
                                  set average_productivity (total_productivity / workers_hired) ]]]
          ]
    
      [
       ask workers
    
      [ if myFirm = nobody and pastFirm = [] 
                  [
                     set myFirm one-of firms with [color = white] in-radius (searchRadius)
                      if myFirm != nobody  [set size 2        
           
                       move-to myFirm 
                       
               
                                ask myFirm [set employees lput myself employees
                                    set total_productivity (sum [productivity] of workers-here with [myFirm != nobody])
                                    set workers_hired  (count workers-here with [ myFirm != nobody])
                                    set average_productivity (total_productivity / workers_hired)
                                       ]]]
        if myFirm = nobody and pastFirm != [ ]
                  [
                     set myFirm one-of firms with [color = white]  in-radius (searchRadius)
                      if myFirm != nobody and [who] of myFirm != length pastFirm [set size 2      
           
                       move-to myFirm 
                       
               
                                ask myFirm [set employees lput myself employees
                                    set total_productivity (sum [productivity] of workers-here with [myFirm != nobody])
                                    set workers_hired  (count workers-here with [myFirm != nobody])
                                    set average_productivity (total_productivity / workers_hired)
                                       ]]]]
      ] 
      
      ]
                    
                 
    end 
 


to show-firms    
    
  ask firms
  [
    show length employees 
     ]
  
 end
   
         
 to hire-workers
  
  ask firms  with [employees != []]
  [
    
   if average_productivity =  wage_rate [set color black
    ask workers-here  with [ myFirm != nobody] [set size 3.5 ]]
      
    
    
    
   if average_productivity < wage_rate 
   [ 
     ask min-one-of workers-here  with [ myFirm != nobody]  [productivity] [set size 1  
         set pastFirm lput myself pastFirm  
        ask myFirm [ set employees remove myself employees set past_employees lput myself past_employees] 
        set myFirm nobody
        ]
       ] 
       
      
       
  
  if average_productivity > wage_rate 
  [ 
    ask max-one-of workers-here  with [ myFirm != nobody] [productivity] [set size 1   
       set pastFirm lput myself pastFirm  
      ask myFirm [ set employees remove myself employees set past_employees lput myself past_employees]
       set myFirm nobody
       ]]
     
     ]
     
     
  
  
  end 
 
  to show-workers
   
   ask firms
  
  [
    show length past_employees 
    set workers_hired  (  count workers-here with [myFirm != nobody] )
    set total_productivity ( sum [ productivity] of workers-here with [myFirm != nobody] )
                          
             ifelse employees = []
                          [set average_productivity 0 ]
                          [set average_productivity (total_productivity / workers_hired) ]
                          
    if length past_employees > 5 [set past_employees [] ] ]
 
  
   
    end


 to research-for-job
  
 ask workers with [myFirm = nobody]   [ setxy random-xcor random-xcor]

  ask workers[
 
   if length pastFirm > 5 [set pastFirm [] ]]
 

  
 end
 
 to do-plots
   
   set-current-plot "Unemployed workers"
   set-current-plot-pen "LowP_workers"
   plot count workers with [size = 1 and color = red]
   set-current-plot-pen "MedP_workers"
   plot count workers with [size = 1 and color = yellow]
   set-current-plot-pen "HighP_workers"
   plot count workers with [size = 1 and color = green]
   
   
   set-current-plot "Firms with jobs available"
   set-current-plot-pen "Firms with jobs available"
   plot count firms with [color = white]
   
   set-current-plot "Total unemployed workers"
   set-current-plot-pen "Unemployed workers"
   plot count workers with [size = 1] + count workers with [size = 2]
   
   
 end