;;; Luca Alasio - Wealth Distribution and Elections - 08/2013 ;;; globals [ tax-income candidates representatives majority wealth-tax income-tax consumption-tax wealth0 income0 consumption0 ] patches-own [ grain-here max-grain-here ] turtles-own [ age life-expectancy metabolism vision children wealth-tax-pref income-tax-pref consumption-tax-pref candidate representative num-votes income wealth consumption abstention tolerance ] extensions [rserve] ;;; SETUP to setup ca if myseed != 0 [random-seed myseed] ;print myseed set tax-income 0 setup-patches setup-turtles setup-voting-system reset-ticks setup-my-plots update-my-plots end to setup-patches ;; give some patches the highest amount of grain possible -- ;; these patches are the "best land" ask patches [ set max-grain-here 0 if (abs(pxcor) < X and abs(pycor) < Y) [ if (random-float 100.0) <= percent-best-land [ set max-grain-here max-grain set grain-here max-grain-here if (pxcor > X / 2 and pycor > Y / 2) [ set max-grain-here max-grain * 3 set grain-here max-grain-here ] if (pxcor < (-1 * X / 2) and pycor < (-1 * Y / 2)) [ set max-grain-here max-grain / 3 set grain-here max-grain-here ] ] ]] ;; spread that grain around the window a little and put a little back ;; into the patches that are the "best land" found above repeat 5 [ ask patches with [max-grain-here != 0] [ set grain-here max-grain-here ] diffuse grain-here 0.25 ] repeat diffusion [ diffuse grain-here 0.25 ] ;; spread the grain around some more ask patches [ set grain-here floor grain-here ;; round grain levels to whole numbers set max-grain-here grain-here ;; initial grain level is also maximum recolor-patch ] end to recolor-patch ;; patch procedure -- use color to indicate grain level set pcolor scale-color yellow grain-here 0 max-grain end ;; set up the initial values for the turtle variables to setup-turtles set-default-shape turtles "person" crt num-people [ move-to one-of patches set size 1.5 set-initial-turtle-vars set age random life-expectancy ] recolor-turtles end to set-initial-turtle-vars set age 0 face one-of neighbors4 set life-expectancy life-expectancy-min + random (life-expectancy-max - life-expectancy-min + 1) set metabolism metabolism-min + random metabolism-max set wealth metabolism + random 50 set vision 1 + random max-vision set children 0 end ;; Set the class of the turtles -- if a turtle has less than a third ;; the wealth of the richest turtle, color it red. If between one ;; and two thirds, color it green. If over two thirds, color it blue. to recolor-turtles let max-wealth 0 if (count turtles > 0) [ set max-wealth max [wealth] of turtles ] ask turtles [ ifelse (wealth <= max-wealth / 5) [ set color red ] [ ifelse (wealth <= (max-wealth * 2 / 5)) [ set color orange ] [ ifelse (wealth <= max-wealth * 3 / 5) [ set color yellow ] [ ifelse (wealth <= (max-wealth * 4 / 5)) [ set color green ] [ set color blue ] ] ] ] ] end to setup-voting-system set candidates no-turtles set representatives no-turtles ask turtles [ set wealth-tax-pref abs random-normal 0 0.01 set income-tax-pref abs random-normal 0.3 0.1 set consumption-tax-pref abs random-normal 0.2 0.1 set candidate false set representative false set num-votes 0 set abstention 0 set tolerance random-float init-tolerance ] set income-tax random-float 0.4 set wealth-tax random-float 0.005 set consumption-tax random-float 0.2 set majority no-turtles end ;;; GO to go ask turtles [ turn-towards-grain ] ;; choose direction holding most grain within the turtle's vision simulate-economy simulate-gov ask turtles [ move-eat-age-die ] recolor-turtles if update-pref? = true [update-preferences turtles with [representative = false]] if ticks mod grain-growth-interval + floor ( abs( random-normal 0 2 ) ) = 0 [ ask patches [ grow-grain ] ] simulate-elections ifelse show-links = false [ask links [ set hidden? true ]] [ask links [ set hidden? false ]] check-values tick update-my-plots end ;; determine the direction which is most profitable for each turtle in ;; the surrounding patches within the turtles' vision to turn-towards-grain ;; turtle procedure set heading 0 let best-direction 0 let best-amount grain-ahead set heading 90 if (grain-ahead > best-amount) [ set best-direction 90 set best-amount grain-ahead ] set heading 180 if (grain-ahead > best-amount) [ set best-direction 180 set best-amount grain-ahead ] set heading 270 if (grain-ahead > best-amount) [ set best-direction 270 set best-amount grain-ahead ] set heading best-direction end to-report grain-ahead ;; turtle procedure let total 0 let how-far 1 repeat vision [ set total total + [grain-here] of patch-ahead how-far set how-far how-far + 1 ] report total end to grow-grain ;; patch procedure ;; if a patch does not have it's maximum amount of grain, add ;; num-grain-grown to its grain amount if (grain-here < max-grain-here) [ set grain-here grain-here + num-grain-grown + random-normal 0 5 ;; if the new amount of grain on a patch is over its maximum ;; capacity, set it to its maximum if (grain-here < 0 ) [ set grain-here 0 ] if (grain-here > max-grain-here) [ set grain-here max-grain-here ] recolor-patch ] end ;; each turtle harvests the grain on its patch. if there are multiple ;; turtles on a patch, divide the grain evenly among the turtles to simulate-economy ask turtles [ set income grain-here / (count turtles-here) set wealth (wealth + income) ] calc-taxes ask turtles [ set grain-here 0 recolor-patch ] if redistribution? = true [redistribute] end to redistribute ask turtles [ if (color = red) [ set wealth wealth + 0.6 * tax-income / (1 + count turtles with [color = red] ) ] if (color = orange) [ set wealth wealth + 0.3 * tax-income / (1 + count turtles with [color = orange] ) ] ] set tax-income tax-income / 10 end to move-eat-age-die fd 1 ;; consume some grain according to metabolism set wealth (wealth - metabolism) ;; grow older set age (age + 1) if (death = True) [ if (wealth < 0) [ die ] if (age >= life-expectancy + random-normal 0 3) [;set grain-here grain-here + wealth ;set pcolor green die] if (wealth > cost-of-children) and (age <= random-normal 0 5 + life-expectancy / 2) and (age >= random-normal 0 5 + life-expectancy / 5 and count turtles < count patches) [ set wealth ( wealth / 2) hatch 1 [ lt 45 fd 1 set age 0 set children 0 set metabolism floor ( 1 + abs ( metabolism + random-normal 0 2 ) ) set life-expectancy life-expectancy + random-normal 0 5 set income-tax-pref income-tax-pref + random-normal 0 0.1 set wealth-tax-pref income-tax-pref + random-normal 0 0.01 set consumption-tax-pref income-tax-pref + random-normal 0 0.1 ] set children children + 1 ] ] end to simulate-elections ifelse ticks mod gov-duration = 0 [ ask turtles [set num-votes 0] ask links [die] ask turtles [forward random 10 set size 1] choose-candidates vote ] [ ifelse ticks mod gov-duration = 1 [ choose-representatives make-alliances form-majority ] [if rep-retribution? = true [pay-representatives]] ] end to choose-candidates ifelse re-election = true [ cancel-representatives create-candidates ] [ create-candidates cancel-representatives ] end to cancel-representatives ask representatives [set representative false set label ""] set representatives no-turtles end to create-candidates repeat ceiling count turtles / prop-candidates [ ifelse death = true [ let poss-cand turtles with [candidate = false and representative = false and age >= 18 and age <= 90 ] if any? poss-cand [ ask one-of poss-cand [set candidate true] ] ] [ ask one-of turtles with [candidate = false and representative = false ] [set candidate true] ] ] set candidates turtles with [candidate = true] ask candidates [set label "C"] end to vote ask turtles [ let my-wealth-tax-pref [wealth-tax-pref] of self let my-income-tax-pref [income-tax-pref] of self let my-consumption-tax-pref [consumption-tax-pref] of self let my-candidates candidates with [ abs ( income-tax-pref - my-income-tax-pref) < tolerance and abs ( wealth-tax-pref - my-wealth-tax-pref) < tolerance and abs ( consumption-tax-pref - my-consumption-tax-pref) < tolerance ] ifelse any? my-candidates [ ask one-of my-candidates [set num-votes num-votes + 1] set abstention 0 ] [set abstention 1] ] end to choose-representatives repeat ceiling count turtles / prop-representatives [ ask one-of candidates with [num-votes = max [num-votes] of candidates] [ set candidate false set representative true set candidates turtles with [candidate = true] ] ] cancel-candidates set representatives turtles with [representative = true] ask representatives [set label "R"] end to pay-representatives ask representatives [set income income + tax-income / (10 * count representatives)] end to cancel-candidates ask candidates [set candidate false set label ""] set candidates no-turtles end to make-alliances ask representatives [ let my-wealth-tax-pref [wealth-tax-pref] of self let my-income-tax-pref [income-tax-pref] of self let my-consumption-tax-pref [consumption-tax-pref] of self ;let my-gov-spending-pref [gov-spending-pref] of self ;let my-synthesis my-wealth-tax-pref + my-income-tax-pref + my-consumption-tax-pref let my-allies other representatives with [ abs ( income-tax-pref - my-income-tax-pref) < tolerance and abs ( wealth-tax-pref - my-wealth-tax-pref) < tolerance and abs ( consumption-tax-pref - my-consumption-tax-pref) < tolerance ] create-links-with my-allies ;ask my-allies [ create-links-with other my-allies ] ] ask representatives [ let my-allies representatives with [link-neighbor? myself = true] ask my-allies [ create-links-with other my-allies setxy [xcor] of myself [ycor] of myself ] ] end to form-majority set majority representatives with [count my-links = max [count my-links] of turtles] ask majority [set size 2.5] if majority != no-turtles [ let maj-income-tax-pref mean [income-tax-pref] of majority let maj-wealth-tax-pref mean [income-tax-pref] of majority let maj-consumption-tax-pref mean [income-tax-pref] of majority ask representatives [ if size < 2.5 and abs ( income-tax-pref - maj-income-tax-pref) < tolerance and abs ( wealth-tax-pref - maj-wealth-tax-pref) < tolerance and abs ( consumption-tax-pref - maj-consumption-tax-pref) < tolerance [set size 2.5] ] ] set majority turtles with [size = 2.5] ask majority [ create-links-with other majority ] end to simulate-gov if majority != no-turtles [ ifelse income-tax > mean [income-tax-pref] of majority [set income-tax income-tax - 0.01] [set income-tax income-tax + 0.01] ifelse wealth-tax > mean [wealth-tax-pref] of majority [set wealth-tax wealth-tax - 0.001] [set wealth-tax wealth-tax + 0.001] ifelse consumption-tax > mean [consumption-tax-pref] of majority [set consumption-tax consumption-tax - 0.01] [set consumption-tax consumption-tax + 0.01] ] set tax-income (sum [income] of turtles with [income > 0]) * income-tax + (sum [wealth] of turtles with [wealth > 0]) * wealth-tax + (sum [consumption] of turtles with [consumption > 0]) * consumption-tax set income0 0.5 * mean [income] of turtles set wealth0 0.1 * mean [income] of turtles set consumption0 0.5 * mean [income] of turtles end to calc-taxes ask turtles with [income > income0] [ set income income * (1 - income-tax) set consumption metabolism set wealth (wealth + income - consumption) * (1 - wealth-tax) ] end to update-preferences [agentset] ask agentset with [representative = false ] [ ifelse income > income0 [set income-tax-pref income-tax-pref - 0.01] [set income-tax-pref income-tax-pref + 0.01] ifelse wealth > wealth0 [set wealth-tax-pref wealth-tax-pref - 0.001] [set wealth-tax-pref wealth-tax-pref + 0.001] ifelse consumption > consumption0 [set consumption-tax-pref consumption-tax-pref - 0.01] [set consumption-tax-pref consumption-tax-pref + 0.01] ] end to check-values if check = true [ ask turtles [ if income-tax-pref <= 0 [set income-tax-pref 0.01] if income-tax-pref >= 1 [set income-tax-pref 0.99] if wealth-tax-pref <= 0 [set wealth-tax-pref 0.001] if wealth-tax-pref >= 0.1 [set wealth-tax-pref 0.09] if consumption-tax-pref <= 0 [set consumption-tax-pref 0.01] if consumption-tax-pref >= 1 [set consumption-tax-pref 0.99] ] if income-tax <= 0 [set income-tax 0.01] if income-tax >= 1 [set income-tax 0.99] if wealth-tax <= 0 [set wealth-tax 0.001] if wealth-tax >= 0.1 [set wealth-tax 0.09] if consumption-tax <= 0 [set consumption-tax 0.01] if consumption-tax >= 1 [set consumption-tax 0.99] ] end to black-death ask turtles [ if ( xcor > 0 ) [ die ] ] end to crisis ask patches [ set max-grain-here max-grain-here - 1 recolor-patch ] end to boom ask patches [ set max-grain-here max-grain-here + 1 recolor-patch ] end ;;; PLOTTING to setup-my-plots set-current-plot "Class Plot" set-plot-y-range 0 num-people set-current-plot "Class Histogram" set-plot-y-range 0 num-people set-current-plot "people" set-current-plot "children" set-current-plot "metabolism" set-current-plot "wealth" set-current-plot "age" end to update-people-plot set-current-plot "people" plot count turtles end to update-meta-plot set-current-plot "metabolism" plot mean [metabolism] of turtles end to update-wealth-plot set-current-plot "wealth" set-current-plot-pen "wealth" plot mean [wealth] of turtles set-current-plot-pen "max-wealth" plot max [wealth] of turtles end to update-age-plot set-current-plot "age" set-current-plot-pen "age" plot mean [age] of turtles set-current-plot-pen "max-age" plot max [age] of turtles end to update-children-plot set-current-plot "children" set-current-plot-pen "n-children" plot mean [children] of turtles set-current-plot-pen "max" plot max [children] of turtles end to update-tax-plot set-current-plot "tax-income" set-current-plot-pen "tax-income" plot tax-income end to update-my-plots if (count turtles > 0) [ update-class-plot update-class-histogram update-people-plot update-children-plot update-meta-plot update-wealth-plot update-age-plot update-tax-plot ] end ;; this does a line plot of the number of people of each class to update-class-plot set-current-plot "Class Plot" set-current-plot-pen "low" plot count turtles with [color = red] set-current-plot-pen "mid-low" plot count turtles with [color = orange] set-current-plot-pen "mid" plot count turtles with [color = yellow] set-current-plot-pen "mid-up" plot count turtles with [color = green] set-current-plot-pen "up" plot count turtles with [color = blue] end ;; this does a histogram of the number of people of each class to update-class-histogram set-current-plot "Class Histogram" plot-pen-reset set-plot-pen-color red plot count turtles with [color = red] set-plot-pen-color orange plot count turtles with [color = orange] set-plot-pen-color yellow plot count turtles with [color = yellow] set-plot-pen-color green plot count turtles with [color = green] set-plot-pen-color blue plot count turtles with [color = blue] end ;;; Rserve to init carefully [rserve:init 6311 "localhost"] [user-message "Warning, Rserve connection needed"] end to close carefully [rserve:close] [user-message "Warning, Rserve connection needed"] end to experiment carefully [ if myseed = 0 [set myseed new-seed] let temp (word "set " switch-name " false") run temp run-exp num-ticks 1 let temp1 (word "set " switch-name " true") run temp1 run-exp num-ticks 2 ] [user-message "Warning, Rserve connection needed"] end to run-exp [numrep n] setup let var [] set var [runresult(var-name)] of turtles rserve:put "x" mean var rserve:put "t" ticks rserve:eval "df1 <- data.frame(variable = x)" rserve:eval "df2 <- data.frame(time = t)" repeat numrep [ go set var [runresult(var-name)] of turtles rserve:put "x" mean var rserve:put "t" ticks rserve:eval "df1 <- rbind(df1, x)" rserve:eval "df2 <- rbind(df2, t)" ] rserve:eval "df <- cbind(df1, df2)" rserve:eval "attach(df)" rserve:eval "regr <- lm(variable~time)" if n = 1 [rserve:eval "par(mfcol=c(2,2))"] rserve:eval "plot(time, variable)" rserve:eval "abline(regr)" rserve:eval "boxplot(variable)" end ;;; Luca Alasio - Wealth Distribution and Elections - 08/2013 ;;; @#$#@#$#@ GRAPHICS-WINDOW 4 8 502 447 30 25 8.0 1 10 1 1 1 0 1 1 1 -30 30 -25 25 1 1 1 ticks 30.0 BUTTON 4 450 60 484 setup setup NIL 1 T OBSERVER NIL NIL NIL NIL 1 BUTTON 61 450 117 484 go go T 1 T OBSERVER NIL NIL NIL NIL 1 SLIDER 507 67 659 100 max-vision max-vision 1 15 10 1 1 NIL HORIZONTAL SLIDER 665 208 813 241 grain-growth-interval grain-growth-interval 1 10 1 1 1 NIL HORIZONTAL SLIDER 507 135 660 168 metabolism-max metabolism-max 1 25 10 1 1 NIL HORIZONTAL SLIDER 507 28 659 61 num-people num-people 2 1000 100 1 1 NIL HORIZONTAL SLIDER 665 100 815 133 percent-best-land percent-best-land 5 25 25 1 1 % HORIZONTAL SLIDER 505 204 658 237 life-expectancy-max life-expectancy-max 1 100 100 1 1 NIL HORIZONTAL PLOT 4 641 441 791 Class Plot Time Turtles 0.0 50.0 0.0 250.0 true true "" "" PENS "low" 1.0 0 -2674135 true "" "" "mid" 1.0 0 -1184463 true "" "" "up" 1.0 0 -13345367 true "" "" "mid-low" 1.0 0 -955883 true "" "" "mid-up" 1.0 0 -10899396 true "" "" SLIDER 664 243 812 276 num-grain-grown num-grain-grown 1 10 1 1 1 NIL HORIZONTAL SLIDER 507 171 660 204 life-expectancy-min life-expectancy-min 1 100 1 1 1 NIL HORIZONTAL PLOT 450 641 690 791 Class Histogram Classes Turtles 0.0 3.0 0.0 250.0 true false "" "" PENS "default" 1.0 1 -2674135 true "" "" BUTTON 335 449 418 485 max grain - 1 crisis NIL 1 T OBSERVER NIL NIL NIL NIL 1 BUTTON 249 450 332 485 max grain + 1 boom NIL 1 T OBSERVER NIL NIL NIL NIL 1 SLIDER 504 240 659 273 cost-of-children cost-of-children 2 100 50 1 1 NIL HORIZONTAL PLOT 4 488 349 636 people NIL NIL 0.0 10.0 0.0 10.0 true false "" "" PENS "default" 1.0 0 -16777216 true "" "" SLIDER 665 29 814 62 max-grain max-grain 1 100 100 1 1 NIL HORIZONTAL BUTTON 421 449 502 484 black-death black-death NIL 1 T OBSERVER NIL NIL NIL NIL 1 PLOT 317 1098 644 1251 Children Time NIL 0.0 10.0 0.0 3.0 true false "" "" PENS "default" 1.0 0 -16777216 true "" "" "n-children" 1.0 0 -16777216 true "" "" "max" 1.0 0 -2674135 true "" "" SLIDER 665 63 813 96 diffusion diffusion 0 20 20 1 1 NIL HORIZONTAL SLIDER 665 136 813 169 X X 0 30 15 1 1 NIL HORIZONTAL SLIDER 665 170 813 203 Y Y 0 30 15 1 1 NIL HORIZONTAL PLOT 5 794 309 946 metabolism Time NIL 0.0 10.0 0.0 10.0 true false "" "" PENS "default" 1.0 0 -16777216 true "" "" SWITCH 507 280 611 313 death death 0 1 -1000 PLOT 647 792 928 945 wealth NIL NIL 0.0 10.0 0.0 10.0 true false "" "" PENS "default" 1.0 0 -16777216 true "" "" "wealth" 1.0 0 -16777216 true "" "" "max-wealth" 1.0 0 -7500403 true "" "" PLOT 0 1099 309 1248 age NIL NIL 0.0 10.0 0.0 10.0 true false "" "" PENS "default" 1.0 0 -16777216 true "" "" "age" 1.0 0 -16777216 true "" "" "max-age" 1.0 0 -7500403 true "" "" PLOT 4 948 310 1096 tax-income t tax-income 0.0 10.0 0.0 10.0 true false "" "" PENS "default" 1.0 0 -16777216 true "" "" "tax-income" 1.0 0 -16777216 true "" "" SLIDER 507 100 660 133 metabolism-min metabolism-min 0 10 1 1 1 NIL HORIZONTAL SLIDER 511 346 655 379 init-tolerance init-tolerance 0 1 0.06 0.01 1 NIL HORIZONTAL SLIDER 509 449 657 482 gov-duration gov-duration 0 60 10 1 1 NIL HORIZONTAL SWITCH 668 318 771 351 re-election re-election 0 1 -1000 SLIDER 511 381 655 414 prop-candidates prop-candidates 0 100 10 1 1 NIL HORIZONTAL SLIDER 510 416 657 449 prop-representatives prop-representatives 0 100 20 1 1 NIL HORIZONTAL SWITCH 669 351 770 384 show-links show-links 0 1 -1000 PLOT 352 488 699 638 Representatives and majority NIL NIL 0.0 10.0 0.0 10.0 true false "" "" PENS "default" 1.0 0 -16777216 true "" "if representatives != 0 [plot count representatives]" "pen-1" 1.0 0 -2674135 true "" "if representatives != 0 [plot count majority]" BUTTON 119 450 175 484 go-once go NIL 1 T OBSERVER NIL NIL NIL NIL 1 PLOT 697 640 928 791 Wealth distribution turtle wealth 0.0 10.0 0.0 10.0 true false "" "" PENS "default" 1.0 0 -16777216 true "" "clear-plot\nforeach sort [wealth] of turtles plot" PLOT 315 795 643 946 Mean income NIL NIL 0.0 10.0 0.0 10.0 true false "" "" PENS "default" 1.0 0 -16777216 true "" "plot mean [income] of turtles" "pen-1" 1.0 0 -7500403 true "" "plot variance [income] of turtles" PLOT 315 949 643 1096 Tax levels NIL NIL 0.0 10.0 0.0 1.0 true true "" "" PENS "income tax" 1.0 0 -2674135 true "" "plot income-tax" "wealth tax" 1.0 0 -13345367 true "" "plot wealth-tax" "cons tax" 1.0 0 -987046 true "" "plot consumption-tax" "half" 1.0 0 -16777216 true "" "plot 0.5" "zero" 1.0 0 -16777216 true "" "plot 0" SWITCH 669 285 771 318 check check 0 1 -1000 SWITCH 670 385 796 418 redistribution? redistribution? 1 1 -1000 TEXTBOX 517 10 633 28 Turtles settings 11 0.0 1 TEXTBOX 672 10 788 28 Patch settings 11 0.0 1 TEXTBOX 561 329 677 347 Social settings 11 0.0 1 PLOT 647 946 928 1097 tax preferences NIL NIL 0.0 10.0 0.0 1.0 true true "" "" PENS "itp" 1.0 0 -2674135 true "" "plot mean [income-tax-pref] of turtles" "ctp" 1.0 0 -1184463 true "" "plot mean [consumption-tax-pref] of turtles" "wtp2" 1.0 0 -13345367 true "" "plot mean [wealth-tax-pref] of turtles" SWITCH 669 418 796 451 update-pref? update-pref? 0 1 -1000 PLOT 704 489 930 637 Abstention NIL NIL 0.0 10.0 0.0 1.0 true false "" "" PENS "default" 1.0 0 -16777216 true "" "plot count turtles with [abstention = 1] / count turtles" BUTTON 838 131 902 165 NIL init NIL 1 T OBSERVER NIL NIL NIL NIL 1 BUTTON 834 443 898 477 NIL close NIL 1 T OBSERVER NIL NIL NIL NIL 1 BUTTON 834 406 914 440 NIL experiment NIL 1 T OBSERVER NIL NIL NIL NIL 1 INPUTBOX 835 40 899 100 myseed -331142251 1 0 Number SLIDER 834 196 926 229 num-ticks num-ticks 0 1000 250 1 1 NIL HORIZONTAL INPUTBOX 832 274 915 334 switch-name redistribution? 1 0 String INPUTBOX 831 337 915 399 var-name income 1 0 String (reporter) TEXTBOX 838 100 938 128 Create connection to Rserve 11 0.0 1 TEXTBOX 838 168 928 196 Experiment duration 11 0.0 1 TEXTBOX 837 231 920 273 Choose a switch and a turtle numeric variable 11 0.0 1 TEXTBOX 835 10 935 38 Seed = 0 means random seed 11 0.0 1 SWITCH 669 452 796 485 rep-retribution? rep-retribution? 1 1 -1000 PLOT 647 1099 928 1249 life-expectancy NIL NIL 0.0 10.0 0.0 10.0 true false "" "" PENS "default" 1.0 0 -16777216 true "" "plot mean [life-expectancy] of turtles" @#$#@#$#@ ## WHAT IS IT? The simulation of a simplified society includes agents able to find, consume and store resources (grain) coming from the environment. It shows how wealth distribution and resource availability are related and how they evolve. In addition, an elementary democratic system has been included. Representatives can change three different taxation levels. Taxation income is transferred to the poorest creating a primitive redistribution system. The goal is to study how redistribution, taxation and elections affect the economy of such agents. ## HOW IT WORKS Two sliders allow the observer to choose a rectangle of space in which resources will be present. There is only one resource, called “grain”, and its amount varies in spece. Turtles collect grain, store it, and consume a certain part of their resources in each time unit. They have a limited “vision”, in fact they notice the presence of grain only if it is not too far, furthermore they are able to move towards the patch with the highest grain quantity they can see. Grin income, storage and consumption are liable for taxation. Besides such basic skills, all turtles are required to choose a number of representatives proportional to their number. Voting for a particular candidate id determined by the difference between agent’s and candidate’s preferences about taxation levels. Elections consist of two steps: the creation of candidates and the choice of representatives; a switch allows to decide whether reelection is possible or not. Representatives can form alliances, represented by links, on the basis of their preferences in the field of taxation. The largest alliance becomes the majority and it will be able to vary taxation levels. The observer can channel taxation income into grain redistribution for the poorest agents’ benefit. It is possible to choose if agents are subject to death caused by absence of grain or by old age; if so, and if the agents’ wealth crosses a certain threshold, they can reproduce and they have share their current grain amount with the new agent. The “go” procedure is the core of the model. First of all it makes turtles move towards the best source of grain. When different turtles reach the same patch, they divide up the grain available. The procedure “go-towards-grain” is very similar to the one used in the NetLogo Library model “Wealth Distribution”. The procedure “update-economy” updates incomes and wealths, implements taxation and redistribution, while “simulate-gov” allows majority to modify taxation levels and updates redistribution levels (“wealth0” ,…). “recolor-turtles” enables the observer to recognize turtles of different classes at a glance, since they are colored according to their wealth class. The democratic system is regulated by “simulate-elections”: candidates are chosen randomly, reelection can be forbidden by the observer as well as government duration. The number of representatives is proportional to the population number by means of a constant fixed by the observer. ## HOW TO USE IT Globals and interface Taxation variables and election-related agentsets are represented by global variables and are updated regularly; “wealth0”, etc. can be interpreted as artificial poverty levels: if a turtle’s values get under them, the turtle is suitable for redistribution. In our case such levels are fractions of the respective mean value. The interface is divided into three groups of operating controls, which govern, respectively, turtles, patches and social behavior. Two important regulations concern the already mentioned death switch and the “check” switch: the first one strongly influences the evolution of the model and the second one ensures that taxation levels make sense (between 1 and 99 per cent). Patches There are two variables related to patches, grain-here reports the current amount of grain present on each patch, while max-grain here is the maximum amount of grain that a patch can contain. The first variable changes in each time unit, while the second one is determined (up to a random variable) only at the beginning of every simulation. Patches whose coordinates are smaller (in absolute value) of X and Y will contain grain, the other won’t. Grain is not uniformly distributed: it is abundant in the upper right corner of the world and it is lacking in the opposite corner. In order to have a gradual variation of grain quantity, patches are asked to diffuse their grain; the process is repeated five times so that the result is (aesthetically) better. The intensity of patches color is proportional to their grain abundance. Turtles If the death switch is on, turtles grow in age, consume grain and con reproduce (with a sort of mitosis), age, predetermined life expectancy, grain consumption (metabolism) and number of children is saved in two corresponding variables. Every turtle has a non-negative grain income and consumption (for the sake of simplicity, the last one is equal to metabolism). Obviously, Income is added to wealth while consumption is subtracted, which means wealth might be negative (if turtles can’t die). “Candidate” and “representative” are true if the considered turtle belongs to the corresponding agentset. Turtles identify a set of candidates whose three taxation preferences differ less than “tolerance” from their own. If such set is empty, “abstention” becomes true, otherwise they chose randomly one of their candidates and make his number of votes increase. Links Links represent alliances between representatives. First representatives with similar preferences create a link, then all turtles connected in some way create new links with each other (complete graph). This last operation is repeated by the largest alliance in order to form the majority. ## THINGS TO NOTICE Several experiments can be conducted from the interface using Rserve extension: after creating a connection between NetLogo and R (“init”), the observer should write in two input boxes the name of the desired switch and turtle variable. Pressing “experiment” button we get a table consisting of four plot: the first column is referred to the “off” state of the switch, the second one to the “on” state. The upper plots contain time on the horizontal axis and the evolution of the mean of our variable on the vertical one; also the regression line of these data is drawn. The underlying plots are “boxplot” of the previous sequences. I used commands “run” and “runresult” in order to make Netlog transform input strings into variables, then I sent data to R and put them in the form of “data frames”, finally I used “lm” (linear model) to perform linear regression. ## THINGS TO TRY I suggest trying different combinations of patch parameters and different dimension of the “fertile rectangle”. Furthermore the observer can choose to activate only a part of the many switches present in the model. It could be interesting to change maximum grain available on patches, creating artificial economic crisis or expansion, or to simulate a catastrophe with button “black death”. ## EXTENDING THE MODEL This model could be improved in a huge number of ways: public services and public costs might be included, different electoral rules could be implemented. It would be challenging to introduce competition or cooperation between turtles, as well making them change preferences according to a suitable happiness indicator. ## RELATED MODELS, CREDITS AND REFERENCES Wilensky, U. (1998). NetLogo Wealth Distribution model. Center for Connected Learning and Computer-Based Modeling, Northwestern Institute on Complex Systems, Northwestern University, Evanston, IL. Jan C. Thiele, Boxplot example of Rserve-extension, University of Goettingen. @#$#@#$#@ default true 0 Polygon -7500403 true true 150 5 40 250 150 205 260 250 airplane true 0 Polygon -7500403 true true 150 0 135 15 120 60 120 105 15 165 15 195 120 180 135 240 105 270 120 285 150 270 180 285 210 270 165 240 180 180 285 195 285 165 180 105 180 60 165 15 arrow true 0 Polygon -7500403 true true 150 0 0 150 105 150 105 293 195 293 195 150 300 150 box false 0 Polygon -7500403 true true 150 285 285 225 285 75 150 135 Polygon -7500403 true true 150 135 15 75 150 15 285 75 Polygon -7500403 true true 15 75 15 225 150 285 150 135 Line -16777216 false 150 285 150 135 Line -16777216 false 150 135 15 75 Line -16777216 false 150 135 285 75 bug true 0 Circle -7500403 true true 96 182 108 Circle -7500403 true true 110 127 80 Circle -7500403 true true 110 75 80 Line -7500403 true 150 100 80 30 Line -7500403 true 150 100 220 30 butterfly true 0 Polygon -7500403 true true 150 165 209 199 225 225 225 255 195 270 165 255 150 240 Polygon -7500403 true true 150 165 89 198 75 225 75 255 105 270 135 255 150 240 Polygon -7500403 true true 139 148 100 105 55 90 25 90 10 105 10 135 25 180 40 195 85 194 139 163 Polygon -7500403 true true 162 150 200 105 245 90 275 90 290 105 290 135 275 180 260 195 215 195 162 165 Polygon -16777216 true false 150 255 135 225 120 150 135 120 150 105 165 120 180 150 165 225 Circle -16777216 true false 135 90 30 Line -16777216 false 150 105 195 60 Line -16777216 false 150 105 105 60 car false 0 Polygon -7500403 true true 300 180 279 164 261 144 240 135 226 132 213 106 203 84 185 63 159 50 135 50 75 60 0 150 0 165 0 225 300 225 300 180 Circle -16777216 true false 180 180 90 Circle -16777216 true false 30 180 90 Polygon -16777216 true false 162 80 132 78 134 135 209 135 194 105 189 96 180 89 Circle -7500403 true true 47 195 58 Circle -7500403 true true 195 195 58 circle false 0 Circle -7500403 true true 0 0 300 circle 2 false 0 Circle -7500403 true true 0 0 300 Circle -16777216 true false 30 30 240 cow false 0 Polygon -7500403 true true 200 193 197 249 179 249 177 196 166 187 140 189 93 191 78 179 72 211 49 209 48 181 37 149 25 120 25 89 45 72 103 84 179 75 198 76 252 64 272 81 293 103 285 121 255 121 242 118 224 167 Polygon -7500403 true true 73 210 86 251 62 249 48 208 Polygon -7500403 true true 25 114 16 195 9 204 23 213 25 200 39 123 cylinder false 0 Circle -7500403 true true 0 0 300 dot false 0 Circle -7500403 true true 90 90 120 face happy false 0 Circle -7500403 true true 8 8 285 Circle -16777216 true false 60 75 60 Circle -16777216 true false 180 75 60 Polygon -16777216 true false 150 255 90 239 62 213 47 191 67 179 90 203 109 218 150 225 192 218 210 203 227 181 251 194 236 217 212 240 face neutral false 0 Circle -7500403 true true 8 7 285 Circle -16777216 true false 60 75 60 Circle -16777216 true false 180 75 60 Rectangle -16777216 true false 60 195 240 225 face sad false 0 Circle -7500403 true true 8 8 285 Circle -16777216 true false 60 75 60 Circle -16777216 true false 180 75 60 Polygon -16777216 true false 150 168 90 184 62 210 47 232 67 244 90 220 109 205 150 198 192 205 210 220 227 242 251 229 236 206 212 183 fish false 0 Polygon -1 true false 44 131 21 87 15 86 0 120 15 150 0 180 13 214 20 212 45 166 Polygon -1 true false 135 195 119 235 95 218 76 210 46 204 60 165 Polygon -1 true false 75 45 83 77 71 103 86 114 166 78 135 60 Polygon -7500403 true true 30 136 151 77 226 81 280 119 292 146 292 160 287 170 270 195 195 210 151 212 30 166 Circle -16777216 true false 215 106 30 flag false 0 Rectangle -7500403 true true 60 15 75 300 Polygon -7500403 true true 90 150 270 90 90 30 Line -7500403 true 75 135 90 135 Line -7500403 true 75 45 90 45 flower false 0 Polygon -10899396 true false 135 120 165 165 180 210 180 240 150 300 165 300 195 240 195 195 165 135 Circle -7500403 true true 85 132 38 Circle -7500403 true true 130 147 38 Circle -7500403 true true 192 85 38 Circle -7500403 true true 85 40 38 Circle -7500403 true true 177 40 38 Circle -7500403 true true 177 132 38 Circle -7500403 true true 70 85 38 Circle -7500403 true true 130 25 38 Circle -7500403 true true 96 51 108 Circle -16777216 true false 113 68 74 Polygon -10899396 true false 189 233 219 188 249 173 279 188 234 218 Polygon -10899396 true false 180 255 150 210 105 210 75 240 135 240 house false 0 Rectangle -7500403 true true 45 120 255 285 Rectangle -16777216 true false 120 210 180 285 Polygon -7500403 true true 15 120 150 15 285 120 Line -16777216 false 30 120 270 120 leaf false 0 Polygon -7500403 true true 150 210 135 195 120 210 60 210 30 195 60 180 60 165 15 135 30 120 15 105 40 104 45 90 60 90 90 105 105 120 120 120 105 60 120 60 135 30 150 15 165 30 180 60 195 60 180 120 195 120 210 105 240 90 255 90 263 104 285 105 270 120 285 135 240 165 240 180 270 195 240 210 180 210 165 195 Polygon -7500403 true true 135 195 135 240 120 255 105 255 105 285 135 285 165 240 165 195 line true 0 Line -7500403 true 150 0 150 300 line half true 0 Line -7500403 true 150 0 150 150 pentagon false 0 Polygon -7500403 true true 150 15 15 120 60 285 240 285 285 120 person false 0 Circle -7500403 true true 110 5 80 Polygon -7500403 true true 105 90 120 195 90 285 105 300 135 300 150 225 165 300 195 300 210 285 180 195 195 90 Rectangle -7500403 true true 127 79 172 94 Polygon -7500403 true true 195 90 240 150 225 180 165 105 Polygon -7500403 true true 105 90 60 150 75 180 135 105 plant false 0 Rectangle -7500403 true true 135 90 165 300 Polygon -7500403 true true 135 255 90 210 45 195 75 255 135 285 Polygon -7500403 true true 165 255 210 210 255 195 225 255 165 285 Polygon -7500403 true true 135 180 90 135 45 120 75 180 135 210 Polygon -7500403 true true 165 180 165 210 225 180 255 120 210 135 Polygon -7500403 true true 135 105 90 60 45 45 75 105 135 135 Polygon -7500403 true true 165 105 165 135 225 105 255 45 210 60 Polygon -7500403 true true 135 90 120 45 150 15 180 45 165 90 square false 0 Rectangle -7500403 true true 30 30 270 270 square 2 false 0 Rectangle -7500403 true true 30 30 270 270 Rectangle -16777216 true false 60 60 240 240 star false 0 Polygon -7500403 true true 151 1 185 108 298 108 207 175 242 282 151 216 59 282 94 175 3 108 116 108 target false 0 Circle -7500403 true true 0 0 300 Circle -16777216 true false 30 30 240 Circle -7500403 true true 60 60 180 Circle -16777216 true false 90 90 120 Circle -7500403 true true 120 120 60 tree false 0 Circle -7500403 true true 118 3 94 Rectangle -6459832 true false 120 195 180 300 Circle -7500403 true true 65 21 108 Circle -7500403 true true 116 41 127 Circle -7500403 true true 45 90 120 Circle -7500403 true true 104 74 152 triangle false 0 Polygon -7500403 true true 150 30 15 255 285 255 triangle 2 false 0 Polygon -7500403 true true 150 30 15 255 285 255 Polygon -16777216 true false 151 99 225 223 75 224 truck false 0 Rectangle -7500403 true true 4 45 195 187 Polygon -7500403 true true 296 193 296 150 259 134 244 104 208 104 207 194 Rectangle -1 true false 195 60 195 105 Polygon -16777216 true false 238 112 252 141 219 141 218 112 Circle -16777216 true false 234 174 42 Rectangle -7500403 true true 181 185 214 194 Circle -16777216 true false 144 174 42 Circle -16777216 true false 24 174 42 Circle -7500403 false true 24 174 42 Circle -7500403 false true 144 174 42 Circle -7500403 false true 234 174 42 turtle true 0 Polygon -10899396 true false 215 204 240 233 246 254 228 266 215 252 193 210 Polygon -10899396 true false 195 90 225 75 245 75 260 89 269 108 261 124 240 105 225 105 210 105 Polygon -10899396 true false 105 90 75 75 55 75 40 89 31 108 39 124 60 105 75 105 90 105 Polygon -10899396 true false 132 85 134 64 107 51 108 17 150 2 192 18 192 52 169 65 172 87 Polygon -10899396 true false 85 204 60 233 54 254 72 266 85 252 107 210 Polygon -7500403 true true 119 75 179 75 209 101 224 135 220 225 175 261 128 261 81 224 74 135 88 99 wheel false 0 Circle -7500403 true true 3 3 294 Circle -16777216 true false 30 30 240 Line -7500403 true 150 285 150 15 Line -7500403 true 15 150 285 150 Circle -7500403 true true 120 120 60 Line -7500403 true 216 40 79 269 Line -7500403 true 40 84 269 221 Line -7500403 true 40 216 269 79 Line -7500403 true 84 40 221 269 x false 0 Polygon -7500403 true true 270 75 225 30 30 225 75 270 Polygon -7500403 true true 30 75 75 30 270 225 225 270 @#$#@#$#@ NetLogo 5.0.4 @#$#@#$#@ @#$#@#$#@ @#$#@#$#@ @#$#@#$#@ @#$#@#$#@ default 0.0 -0.2 0 1.0 0.0 0.0 1 1.0 0.0 0.2 0 1.0 0.0 link direction true 0 Line -7500403 true 150 150 30 225 Line -7500403 true 150 150 270 225 @#$#@#$#@ 0 @#$#@#$#@