globals [ percent-similar ;; on the average, what percent of a turtle's neighbors ;; are the same color as that turtle? percent-similar-red percent-similar-green percent-unhappy ;; what percent of the turtles are unhappy? percent-unhappy-green percent-unhappy-red segregation-index stabilised? percent-unhappy-history ] turtles-own [ my-%-similar-wanted subpopulation happy? ;; for each turtle, indicates whether at least %-similar-wanted percent of ;; that turtles' neighbors are the same color as the turtle ] patches-own [ reds-nearby ;; how many neighboring patches have a red turtle? greens-nearby ;; ditto for green turtles total-nearby ;; sum of previous two variables red-percentage ;; reds-nearby / total-nearby ] to setup ;; (for this model to work with NetLogo's new plotting features, ;; __clear-all-and-reset-ticks should be replaced with clear-all at ;; the beginning of your setup procedure and reset-ticks at the end ;; of the procedure.) clear-all if behaviorspace-run-number > 0 [ ifelse identical-tolerance? ;; the distribution of the tolerance level is the same in both subpopulations [ ifelse random-tolerance? ;; ;; in experiments this is typically true to analyse the sensitivity of output metrics with respect to the tolerance level [ set %-similar-red-mean 5 + random-float 70 ;; the mean in this run is anything between 5 and 75 per cent set %-similar-green-mean %-similar-red-mean ;; in both subpopulations ] [ set %-similar-green-mean %-similar-red-mean ;; in this case the value of both is taken from the slider, mainly for analysing the effect of other input parameters ] ] [ ;; the two subpopulations have different distributions set %-similar-red-mean 5 + random-float 70 set %-similar-green-mean 5 + random-float 70 ] ;; the following lines allow for analysing the effect of identical/unidentical tolerance levels within subpopulations and of simple search/tolerance related search set %-similar-wanted-std-dev 0 if not identical-tolerance? and behaviorspace-run-number mod 4 < 2 [ set %-similar-wanted-std-dev 15 ] set search-mode "simple search" if not identical-tolerance? and behaviorspace-run-number mod 2 = 0 [ set search-mode "tolerance related search" ] if random-density-and-minority? ;; in experiments this is typcially true, otherwise the values are taken from the sliders [ set percentage-red 0.1 + random-float 0.4 set number 1500 + random 875 ] ] ;; the following two lines are for keeping a history and stopping a run which converges where, however, not all turtles are happy set percent-unhappy-history ( list 0 ) set stabilised? false ;; patches give birth to turtles, this makes sure that no patch has more then one inhabitant ask n-of number patches [ sprout 1 [ ifelse who < ( number * percentage-red ) ;; turn a certain percentage of the turtles red, the others green [ set subpopulation "red" set my-%-similar-wanted random-normal %-similar-red-mean %-similar-wanted-std-dev if my-%-similar-wanted < 5 [ set my-%-similar-wanted 5 ] if my-%-similar-wanted > 95 [ set my-%-similar-wanted 95 ] set color scale-color red my-%-similar-wanted 100 0 ] [ set subpopulation "green" set my-%-similar-wanted random-normal %-similar-green-mean %-similar-wanted-std-dev if my-%-similar-wanted < 5 [ set my-%-similar-wanted 5 ] if my-%-similar-wanted > 95 [ set my-%-similar-wanted 95 ] set color scale-color green my-%-similar-wanted 100 0 ] set happy? false ;; all turtles are unhappy at the beginning, mainly because when they start into life most of their neighbours do not exist yet ;; in the first tick, all turtles move except when in case of tolerance-related search they find that there is no better patch ] ] update-variables ;; do-plots reset-ticks end to go ask turtles [ if not happy? [ move-to delta ] ] update-variables tick if not any? turtles with [ not happy? ] or stabilised? [ stop ] end to-report delta ;; find the optimal patch let optimal-patch patch-here let my-local-distribution [ red-percentage ] of patch-here if search-mode = "simple search" [ set optimal-patch one-of patches in-radius 10 with [ not any? other turtles-here ] if optimal-patch = nobody [ set optimal-patch one-of patches with [ not any? other turtles-here ] ] ] if search-mode = "tolerance related search" ;; if no better patch is found, the turtle stays [ ifelse subpopulation = "red" [ set optimal-patch one-of patches in-radius 10 with [ not any? turtles-here and ( red-percentage > my-local-distribution or red-percentage = 2 ) ] ] [ set optimal-patch one-of patches in-radius 10 with [ not any? turtles-here and ( red-percentage < my-local-distribution or red-percentage = 2 ) ] ] if optimal-patch = nobody [ set optimal-patch patch-here ] ] report optimal-patch end to update-variables update-patches update-turtles update-globals end to update-patches ask patches ;; do the bookkeeping for neighbourhood characteristic [ ;; in next two lines, we use "neighbors" to test the eight patches surrounding ;; the current patch set reds-nearby count neighbors with [any? turtles-here with [subpopulation = "red"]] set greens-nearby count neighbors with [any? turtles-here with [subpopulation = "green"]] set total-nearby reds-nearby + greens-nearby set red-percentage 2 if total-nearby > 0 [ set red-percentage reds-nearby / total-nearby ] ] end to update-turtles if adaptive-tolerance? [ ask turtles ;; adapt tolerance threshold [ let my-%-similar-seen phi set my-%-similar-wanted my-%-similar-wanted * ( 1 - epsilon ) + epsilon * my-%-similar-seen if subpopulation = "red" [ set color scale-color red my-%-similar-wanted 100 0 ] if subpopulation = "green" [ set color scale-color green my-%-similar-wanted 100 0 ] ] ] ask turtles ;; find out whether they are happy [ if subpopulation = "red" [ set happy? reds-nearby >= ( my-%-similar-wanted * total-nearby / 100 ) ] if subpopulation = "green" [ set happy? greens-nearby >= ( my-%-similar-wanted * total-nearby / 100 ) ] ] end to-report phi ;; calculates the percentage neighbours of the same colour in the Moore neighbourhood; only needed if adaptive-tolerance? let likes reds-nearby if subpopulation = "green" [ set likes greens-nearby ] ifelse total-nearby = 0 [ set likes 0 ] [ set likes likes * 100 / total-nearby ] report likes end to update-globals let similar-neighbors 0 let similar-neighbors-red 0 let similar-neighbors-green 0 let total-neighbors 0 let total-neighbors-red 0 let total-neighbors-green 0 set similar-neighbors-red sum [reds-nearby] of turtles with [subpopulation = "red"] set similar-neighbors-green sum [greens-nearby] of turtles with [subpopulation = "green"] set similar-neighbors similar-neighbors-red + similar-neighbors-green set total-neighbors sum [total-nearby] of turtles set total-neighbors-red sum [total-nearby] of turtles with [subpopulation = "red"] set total-neighbors-green sum [total-nearby] of turtles with [subpopulation = "green"] set percent-similar-red similar-neighbors-red / total-neighbors-red * 100 set percent-similar-green similar-neighbors-green / total-neighbors-green * 100 set percent-similar ( similar-neighbors / total-neighbors ) * 100 set percent-unhappy (count turtles with [not happy?]) / (count turtles) * 100 set percent-unhappy-red ( count turtles with [ not happy? and subpopulation = "red" ] ) / ( count turtles with [ subpopulation = "red" ] ) * 100 set percent-unhappy-green ( count turtles with [ not happy? and subpopulation = "green" ] ) / ( count turtles with [ subpopulation = "green" ] ) * 100 ifelse length percent-unhappy-history < 20 [ set percent-unhappy-history lput percent-unhappy percent-unhappy-history set stabilised? false ] [ set percent-unhappy-history lput percent-unhappy but-first percent-unhappy-history let standard-deviation-unhappy standard-deviation percent-unhappy-history set stabilised? ( standard-deviation-unhappy < 1 and percent-unhappy > 1 or standard-deviation-unhappy < 0.001 ) ] set segregation-index duncan end to-report duncan ;; calculates the segragation index for overlapping neighbourhoods (each 49 patches in size) let si 0 let all-red count turtles with [ subpopulation = "red" ] let all-green count turtles with [ subpopulation = "green" ] ask patches [ let local-red count turtles in-radius 4 with [ subpopulation = "red" ] let local-green count turtles in-radius 4 with [ subpopulation = "green" ] let xi local-red / all-red let yi local-green / all-green set si si + abs ( xi - yi ) ] report si / 98 * 100 end ; *** Modified Version Copyright Notice *** ; This model was adapted from Uri Wilensky's version as of 1998/2001. ; Uri Wilensky's copyright notice is included (below) ; Permission to use, modify and redistribute this model is hereby granted, ; provided that both of the following requirements are followed: ; a) both copyright notices are included. ; b) this model will not be redistributed for profit without permission ; from both Uri Wilensky and Klaus G. Troitzsch. ; To refer to this model in academic publications, please use: ; Troitzsch, Klaus G. (2017) Extended NetLogo Segregation model. ; http://ccl.northwestern.edu/netlogo/community/SegregationExtended ; Center for Connected Learning and Computer-Based Modeling, ; Northwestern University, Evanston, IL. ; *** Original NetLogo Model Copyright Notice*** ; This model was adapted from the MIT Media Lab Slime model as part ; of the project: CONNECTED MATHEMATICS: MAKING SENSE OF COMPLEX ; PHENOMENA THROUGH BUILDING OBJECT-BASED PARALLEL MODELS (OBPML). ; The project gratefully acknowledges the support of the National ; Science Foundation (Applications of Advanced Technologies Program) ; -- grant numbers RED #9552950 and REC #9632612. ; Copyright 1998 by Uri Wilensky. All rights reserved. ; Converted from StarLogoT to NetLogo, 2001. ; Permission to use, modify or redistribute this model is hereby granted, ; provided that both of the following requirements are followed: ; a) this copyright notice is included. ; b) this model will not be redistributed for profit without permission ; from Uri Wilensky. ; Contact Uri Wilensky for appropriate licenses for redistribution for ; profit. ; To refer to this model in academic publications, please use: ; Wilensky, U. (1998). NetLogo Segregation model. ; http://ccl.northwestern.edu/netlogo/models/Segregation. ; Center for Connected Learning and Computer-Based Modeling, ; Northwestern University, Evanston, IL. ; ***End NetLogo Model Copyright Notice*** @#$#@#$#@ GRAPHICS-WINDOW 260 10 903 674 25 25 12.412 1 10 1 1 1 0 1 1 1 -25 25 -25 25 0 0 1 ticks 30.0 MONITOR 910 610 1026 655 Percent Unhappy percent-unhappy 3 1 11 MONITOR 910 563 1026 608 Percent Similar percent-similar 1 1 11 PLOT 910 182 1120 352 Percent Similar time % 0.0 10.0 0.0 100.0 true false "" "" PENS "percent" 1.0 0 -16777216 true "" "plot percent-similar" "percent-red" 1.0 0 -2674135 true "" "plot percent-similar-red" "percent-green" 1.0 0 -10899396 true "" "plot percent-similar-green" PLOT 910 354 1120 514 Percent Unhappy time % 0.0 10.0 0.0 100.0 true false "" "" PENS "percent" 1.0 0 -11352576 true "" "plot percent-unhappy-green" "pen-1" 1.0 0 -2674135 true "" "plot percent-unhappy-red" "pen-2" 1.0 0 -7500403 true "" "plot percent-unhappy" SLIDER 10 202 250 235 number number 500 2500 1500 10 1 NIL HORIZONTAL SLIDER 10 307 250 340 %-similar-red-mean %-similar-red-mean 0.0 100.0 30 1.0 1 % HORIZONTAL BUTTON 10 10 92 43 setup setup NIL 1 T OBSERVER NIL NIL NIL NIL 1 BUTTON 102 10 182 43 go go T 1 T OBSERVER NIL NIL NIL NIL 1 PLOT 910 10 1120 180 Segregation Index NIL NIL 0.0 10.0 0.0 10.0 true false "" "" PENS "default" 1.0 0 -16777216 true "" "plot segregation-index" SLIDER 10 237 250 270 percentage-red percentage-red 0 0.5 0.1 0.01 1 NIL HORIZONTAL MONITOR 910 516 1026 561 NIL segregation-index 3 1 11 MONITOR 1028 610 1113 655 sd unhappy standard-deviation percent-unhappy-history 2 1 11 CHOOSER 10 50 250 95 search-mode search-mode "simple search" "tolerance related search" 1 SLIDER 10 342 250 375 %-similar-green-mean %-similar-green-mean 0 100 30 1 1 % HORIZONTAL SLIDER 10 377 250 410 %-similar-wanted-std-dev %-similar-wanted-std-dev 0 15 0 1 1 %p HORIZONTAL SWITCH 10 272 250 305 adaptive-tolerance? adaptive-tolerance? 0 1 -1000 PLOT 1122 10 1332 180 Tolerance level red NIL NIL 0.0 100.0 0.0 10.0 true false "set-plot-pen-mode 1" "set-plot-y-range 0 5\nauto-plot-on" PENS "default" 1.0 0 -16777216 true "" "histogram [ my-%-similar-wanted ] of turtles with [ subpopulation = \"red\" ]" PLOT 1122 182 1332 352 Tolerance level green NIL NIL 0.0 100.0 0.0 10.0 true false "set-plot-pen-mode 1" "set-plot-y-range 0 5\nauto-plot-on" PENS "default" 1.0 0 -16777216 true "" "histogram [ my-%-similar-wanted ] of turtles with [ subpopulation = \"green\" ]" MONITOR 1122 516 1215 561 mean red precision mean [ my-%-similar-wanted ] of turtles with [ subpopulation = \"red\" ] 2 17 1 11 MONITOR 1217 516 1292 561 sd red standard-deviation [ my-%-similar-wanted ] of turtles with [ subpopulation = \"red\" ] 2 1 11 MONITOR 1122 563 1215 608 mean green mean [ my-%-similar-wanted ] of turtles with [ subpopulation = \"green\" ] 2 1 11 MONITOR 1217 563 1292 608 sd green standard-deviation [ my-%-similar-wanted ] of turtles with [ subpopulation = \"red\" ] 2 1 11 SWITCH 10 132 250 165 identical-tolerance? identical-tolerance? 1 1 -1000 SWITCH 10 167 250 200 random-density-and-minority? random-density-and-minority? 0 1 -1000 SWITCH 10 97 250 130 random-tolerance? random-tolerance? 0 1 -1000 PLOT 1122 354 1332 514 Tolerance distribution NIL NIL 0.0 10.0 0.0 100.0 true false "" "" PENS "meanred" 1.0 0 -2674135 true "" "plot mean [ my-%-similar-wanted ] of turtles with [ subpopulation = \"red\" ]" "meangreen" 1.0 0 -10899396 true "" "plot mean [ my-%-similar-wanted ] of turtles with [ subpopulation = \"green\" ]" "upperred" 1.0 0 -955883 true "" "plot mean [ my-%-similar-wanted ] of turtles with [ subpopulation = \"red\" ] + standard-deviation [ my-%-similar-wanted ] of turtles with [ subpopulation = \"red\" ]" "lowerred" 1.0 0 -955883 true "" "plot mean [ my-%-similar-wanted ] of turtles with [ subpopulation = \"red\" ] - standard-deviation [ my-%-similar-wanted ] of turtles with [ subpopulation = \"red\" ]" "uppergreen" 1.0 0 -13840069 true "" "plot mean [ my-%-similar-wanted ] of turtles with [ subpopulation = \"green\" ] + standard-deviation [ my-%-similar-wanted ] of turtles with [ subpopulation = \"green\" ]" "lowergreen" 1.0 0 -13840069 true "" "plot mean [ my-%-similar-wanted ] of turtles with [ subpopulation = \"green\" ] - standard-deviation [ my-%-similar-wanted ] of turtles with [ subpopulation = \"green\" ]" SLIDER 10 412 250 445 epsilon epsilon 0 0.25 0.05 0.01 1 NIL HORIZONTAL @#$#@#$#@ ## WHAT IS IT? This project models the behaviour of two groups of turtles (red and green, red being the minority) in virtual world. Turtles prefer to live in the neighbourhood of turtles of the same colour. Whether they are happy at their current patches depends on the percentage of turtles of the same colour in their Moore neighbourhoods and on their individual tolerance thresholds: If `%-similar-seen` is greater or equal `%-similar-wanted`, they are happy. In this extended version of earlier models, the thresholds of the individual turtles can be different both within and between subpopulations, and they can change depending on the current neighbourhood. The "classical" version with identical and constant thresholds for all turtles and subpopulations of equal size can, of course, also be simulated. This project was inspired by Thomas Schelling's writings about social systems (such as housing patterns in cities). ## HOW TO USE IT The SEARCH-MODE chooser tells the model whether each unhappy turtle moves to a random uninhabited patch or whether it moves only when it finds a patch where it would have a higher `%-similar-seen` than before. The RANDOM-TOLERANCE? switch is only interesting for behaviour-space experiments, it overrides the %-SIMILAR-RED-MEAN and %-SIMILAR-GREEN-MEAN sliders. The IDENTICAL-TOLERANCE? switch decides whether the two subpopulations have the same or different means of their) tolerance levels. It overrides the %-SIMILAR-GREEN-MEAN slider. The RANDOM-DENSITY-AND-MINORITY? switch is only interesting in behaviour-space experiments. It controls the size of the minority and the density and hence overrides the PERCENTAGE-RED and NUMBER sliders. The PERCENTAGE-RED slider controls the size of the minority and the majority. The NUMBER slider controls the total number of turtles and hence the density of the overall population in this virtual world. The ADAPTIVE-TOLERANCE? slider decides whether the individual tolerance levels remain the same over the complete simulation run or whether they change as a consequence of the experience the individual turtles have over time. In the latter case they adjust their individual tolerance level each time step according to `set my-%-similar-wanted my-%-similar-wanted * ( 1 - epsilon ) + epsilon * my-%-similar-seen`. The four other sliders set the distribution of the tolerance levels within the two subpopulations (`%-similar-wanted-std-dev = 0` makes sure that all turtles have the same tolerance level within each subpopulation). `epsilon = 0` overrides the ADAPTIVE-TOLERANCE? slider. Click the SETUP button to set up the turtles, and the world is filled with turtles at random patches, not more than one per patch. Click GO to start the simulation. If turtles don't have enough same-colour neighbors, they jump elswewhere, either randomly or, in the case of the tolerance-related search, to a patch where the percentage of similar turtles is higher (if they don't find such a place, they stay in this round). ## THINGS TO NOTICE Three plots to the right of the virtual world show the history of the segregation index, of the overall and subpopulation-wise percentage of similar neighbours and of the overall and subpopulation-wise percentage of similar neighbours. The three plots at the extreme right show the current distribution of the tolerance levels within the two subpopulations and the history of these distributions (the red and green curves show the mean and the mean plus/minus one standard deviation of either distribution). The monitors below the plots show the current values of the output metrics shown in the plots. ## THINGS TO TRY Use the experiments prepared in the bebaviour space and extend them. ## NETLOGO FEATURES Nothing very special. But in contrast to many other implementations some calculations are outsourced into functions instead of procedures. ## CREDITS AND REFERENCES Schelling, T. (1978). Micromotives and Macrobehavior. New York: Norton. Seee also a recent Atlantic article: Rauch, J. (2002). Seeing Around Corners; The Atlantic Monthly; April 2002;Volume 289, No. 4; 35-48. http://www.theatlantic.com/issues/2002/04/rauch.htm Troitzsch, Klaus G. (2017). Axiomatic Theiry and Simulation: A Philosophy of Science Perspective in Schelling's Segregation Model. Journal of Artificial Societies and Social Simulation 20 (1) 10 http://jasss.soc.surrey.ac.uk/20/1/10.html doi:10.18564/jasss.3372 See the copyright notice at the end of the code. @#$#@#$#@ default true 0 Polygon -7500403 true true 150 5 40 250 150 205 260 250 arrow true 0 Polygon -7500403 true true 150 0 0 150 105 150 105 293 195 293 195 150 300 150 box true 0 Polygon -7500403 true true 45 255 255 255 255 45 45 45 circle true 0 Circle -7500403 true true 35 35 230 person false 0 Circle -7500403 true true 155 20 63 Rectangle -7500403 true true 158 79 217 164 Polygon -7500403 true true 158 81 110 129 131 143 158 109 165 110 Polygon -7500403 true true 216 83 267 123 248 143 215 107 Polygon -7500403 true true 167 163 145 234 183 234 183 163 Polygon -7500403 true true 195 163 195 233 227 233 206 159 spacecraft true 0 Polygon -7500403 true true 150 0 180 135 255 255 225 240 150 180 75 240 45 255 120 135 thin-arrow true 0 Polygon -7500403 true true 150 0 0 150 120 150 120 293 180 293 180 150 300 150 truck-down false 0 Polygon -7500403 true true 225 30 225 270 120 270 105 210 60 180 45 30 105 60 105 30 Polygon -8630108 true false 195 75 195 120 240 120 240 75 Polygon -8630108 true false 195 225 195 180 240 180 240 225 truck-left false 0 Polygon -7500403 true true 120 135 225 135 225 210 75 210 75 165 105 165 Polygon -8630108 true false 90 210 105 225 120 210 Polygon -8630108 true false 180 210 195 225 210 210 truck-right false 0 Polygon -7500403 true true 180 135 75 135 75 210 225 210 225 165 195 165 Polygon -8630108 true false 210 210 195 225 180 210 Polygon -8630108 true false 120 210 105 225 90 210 turtle true 0 Polygon -7500403 true true 138 75 162 75 165 105 225 105 225 142 195 135 195 187 225 195 225 225 195 217 195 202 105 202 105 217 75 225 75 195 105 187 105 135 75 142 75 105 135 105 @#$#@#$#@ NetLogo 5.3.1 @#$#@#$#@ @#$#@#$#@ @#$#@#$#@ setup go segregation-index percent-unhappy percent-similar setup go %-similar-red-mean segregation-index percent-unhappy percent-similar setup go percentage-red number %-similar-red-mean segregation-index percent-unhappy percent-similar setup go percentage-red number %-similar-red-mean %-similar-green-mean %-similar-wanted-std-dev search-mode segregation-index percent-unhappy percent-unhappy-red percent-unhappy-green percent-similar setup go percentage-red number %-similar-red-mean %-similar-green-mean %-similar-wanted-std-dev search-mode segregation-index percent-unhappy percent-unhappy-red percent-unhappy-green percent-similar @#$#@#$#@ @#$#@#$#@ default 0.0 -0.2 0 0.0 1.0 0.0 1 1.0 0.0 0.2 0 0.0 1.0 link direction true 0 Line -7500403 true 150 150 90 180 Line -7500403 true 150 150 210 180 @#$#@#$#@ 0 @#$#@#$#@