globals [ percent-similar ;; on the average, what percent of a turtle's neighbors ;; are the same color as that turtle? percent-unhappy ;; what percent of the turtles are unhappy? ] turtles-own [ happy? ;; for each turtle, indicates whether at least %-similar-wanted percent of ;; that turtles' neighbors are the same color as the turtle stubborn? ;; for each turtle, indicates whether that turtle was randomly chosen ;; to be stubborn. Stubborn turtles do not move (they are always "happy). ;; This setting does not change during the model's execution ] patches-own [ reds-nearby ;; how many neighboring patches have a red turtle? greens-nearby ;; ditto for green turtles blues-nearby ;; ditto magentas-nearby ;; ditto whites-nearby ;; ditto total-nearby ;; sum of previous five variables ] to setup ca cct number [ setxy (random screen-size-x) ;; randomize the turtle locations (random screen-size-y) if who <= (number / number-of-races) ;; initializes turtle color -- each color has a 1/n [ set color red ] ;; share of turtles, where 'n' is the number of races if (who > (1 * number) / number-of-races) and (who <= (2 * number) / number-of-races) [ set color green ] if (who > (2 * number) / number-of-races) and (who <= (3 * number) / number-of-races) [ set color blue ] if (who > (3 * number) / number-of-races) and (who <= (4 * number) / number-of-races) [ set color magenta ] if (who > (4 * number) / number-of-races) and (who <= (5 * number) / number-of-races) [ set color white ] if any other-turtles-here ;; make sure each turtle is in its own patch [ find-new-spot ] ] repeat number-of-stubborn ;; randomly selects which to turtles become stubborn [ ask random-one-of turtles [ set pcolor yellow ;; denotes stubborn turtles set stubborn? true ] ] ;; with yellow patches update-variables do-plots end to go move-unhappy-turtles update-variables do-plots if not any turtles with [not happy?] [ stop ] end to move-unhappy-turtles ask turtles [ if not happy? [ find-new-spot ] ] end to find-new-spot rt random 360 fd random 10 if any other-turtles-here [ find-new-spot ] ;; keep going until we find an unoccupied patch end to update-variables update-patches update-turtles update-globals end to update-patches ask patches [ ;; in next eight lines, we use "neighbors" to test the eight patches surrounding ;; the current patch ;; the first two lines (for red and green) are always run because we are guaranteed ;; to use those two colors at the very minimum. set reds-nearby count neighbors with [any turtles-here with [color = red]] set greens-nearby count neighbors with [any turtles-here with [color = green]] if (number-of-races > 2) ;; we use conditionals so these lines aren't run unnecessarily [set blues-nearby count neighbors with [any turtles-here with [color = blue]]] if (number-of-races > 3) [set magentas-nearby count neighbors with [any turtles-here with [color = magenta]]] if (number-of-races > 4) [set whites-nearby count neighbors with [any turtles-here with [color = white]]] set total-nearby (reds-nearby + greens-nearby + blues-nearby + magentas-nearby + whites-nearby) ] end to update-turtles ask turtles [ if color = red [ set happy? reds-nearby >= ( %-similar-wanted * total-nearby / 100 ) ] if color = green [ set happy? greens-nearby >= ( %-similar-wanted * total-nearby / 100 ) ] if color = blue [ set happy? blues-nearby >= ( %-similar-wanted * total-nearby / 100 ) ] if color = magenta [ set happy? magentas-nearby >= ( %-similar-wanted * total-nearby / 100 ) ] if color = white [ set happy? whites-nearby >= ( %-similar-wanted * total-nearby / 100 ) ] if pcolor != black ;; tests to see if turtle is stubborn (since stubborn turtles, and [ set happy? true ] ;; only stubborn turtles, exist on non-black patches). Stubborn ;; turtles are always set to happy so they won't jump ] end to update-globals locals [ similar-neighbors total-neighbors ] set similar-neighbors sum values-from turtles with [color = red] [reds-nearby] + sum values-from turtles with [color = green] [greens-nearby] + sum values-from turtles with [color = blue] [blues-nearby] + sum values-from turtles with [color = magenta] [magentas-nearby] + sum values-from turtles with [color = white] [whites-nearby] set total-neighbors sum values-from turtles [total-nearby] set percent-similar (similar-neighbors / total-neighbors) * 100 set percent-unhappy (count turtles with [not happy?]) / (count turtles) * 100 end to do-plots set-current-plot "Percent Similar" plot percent-similar set-current-plot "Percent Unhappy" plot percent-unhappy end ; ***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 259 10 718 469 25 25 9.0 1 10 0 0 CC-WINDOW 514 478 897 584 Command Center MONITOR 387 477 500 526 Percent Unhappy percent-unhappy 1 1 MONITOR 262 477 370 526 Percent Similar percent-similar 1 1 PLOT 5 125 254 318 Percent Similar time % 0.0 25.0 0.0 100.0 true false PENS "percent" 1.0 0 -65536 true PLOT 6 318 255 517 Percent Unhappy time % 0.0 25.0 0.0 100.0 true false PENS "percent" 1.0 0 -11352576 true SLIDER 12 52 224 85 number number 500 2500 2000 10 1 NIL SLIDER 12 89 224 122 %-similar-wanted %-similar-wanted 0.0 100.0 30.0 1.0 1 % BUTTON 27 18 107 51 setup setup NIL 1 T OBSERVER BUTTON 117 18 197 51 go go T 1 T OBSERVER SLIDER 723 33 895 66 number-of-races number-of-races 2 5 2 1 1 NIL SLIDER 724 84 896 117 number-of-stubborn number-of-stubborn 0 200 0 1 1 NIL @#$#@#$#@ WHAT IS IT? ------------ This project models the behavior of multiple (from two to five) types of turtles in a mythical pond. The red, green, blue, magenta, and white turtles get along with one another. But each turtle wants to make sure that it lives near some of "its own." That is, each red turtle wants to live near at least some red turtles, and each green turtle wants to live near at least some green turtles, etc. The simulation shows how these individual preferences ripple through the pond, leading to large-scale patterns. Additionally, a number of turtles can be termed "stubborn." These randomly selected turtles still have racial characteristics which affect their neighbors, however they obstinately refuse to move, regardless of surroundings. This project was inspired by Thomas Schelling's writings about social systems (such as housing patterns in cities). HOW TO USE IT -------------- Click the SETUP button to set up the turtles. The different races are always represented equally and randomly. The turtles move around until there is at most one turtle on a patch. Click GO to start the simulation. If turtles don't have enough same-color neighbors, they jump to a nearby patch. The NUMBER slider controls the total number of turtles. (It takes effect the next time you click SETUP.) The %-SIMILAR-WANTED slider controls the percentage of same-color turtles that each turtle wants among its neighbors. For example, if the slider is set at 30, each green turtle wants at least 30% of its neighbors to be green turtles. There are two additional sliders. The NUMBER-OF-RACES slider selects from 2 to 5 races to be intialized. The NUMBER-OF-STUBBORN slider selects the number of "stubborn" turtles to be randomly selected. The two sliders' default values of 2 and 0, respectively, retain the original model's characteristics. The "Percent Similar" monitor shows the average percentage of same-color neighbors for each turtle. It starts at about 1/n (where 'n' is the number of races), since each turtle starts (on average) with an even mix of different colored turtles as neighbors. The "Percent Unhappy" monitor shows the percent of turtles that have fewer same-color neighbors than they want (and thus want to move). Both monitors are also plotted. THINGS TO NOTICE ---------------- When you execute SETUP, the red and green (and possibly blue, magenta, and white) turtles are randomly distributed throughout the pond. But many turtles are "unhappy" since they don't have enough same-color neighbors. The unhappy turtles jump to new locations in the vicinity. But in the new locations, they might tip the balance of the local population, prompting other turtles to leave. If a few red turtles move into an area, the local green turtles might leave. But when the green turtles move to a new area, they might prompt red turtles to leave that area. Over time, the number of unhappy turtles decreases. But the pond becomes more segregated, with clusters of same colored turtles emerging. With the default settings of 2000 turtles, 2 races, no "stubborns," and where each turtle wants at least 30% same-color neighbors, the turtles end up with (on average) 71% same-color neighbors. So relatively small individual preferences can lead to significant overall segregation. Surprisingly, adding races does not seem to change these numbers much. Increasing from 2 to 5 races, the final "percent-similar" count is only a few percentage points higher -- around 74% on average. Predictably, using stubborn turtles controls the grouping patterns of the races. Same color clusters emerge around stubborn turtles. THINGS TO TRY ------------ Try different values for %-SIMILAR-WANTED. How does the overall degree of segregation change? If each turtle wants at least 40% same-color neighbors, what percentage (on average) do they end up with? Can you find a combination of settings in which adjusting the number of races significantly impacts the results? In which adjusting the number of "stubborns" shows an impact? NETLOGO FEATURES ---------------- In the UPDATE-GLOBALS procedure, note the use of SUM, COUNT, VALUES-FROM, and WITH to compute the percentages displayed in the monitors and plots. When selecting the stubborns, this models uses the RANDOM-ONE-OF primitive. 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 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. @#$#@#$#@ default true 0 Polygon -7566196 true true 150 5 40 250 150 205 260 250 arrow true 0 Polygon -7566196 true true 150 0 0 150 105 150 105 293 195 293 195 150 300 150 box true 0 Polygon -7566196 true true 45 255 255 255 255 45 45 45 spacecraft true 0 Polygon -7566196 true true 150 0 180 135 255 255 225 240 150 180 75 240 45 255 120 135 thin-arrow true 0 Polygon -7566196 true true 150 0 0 150 120 150 120 293 180 293 180 150 300 150 turtle true 0 Polygon -7566196 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 person false 0 Circle -7566196 true true 155 20 63 Rectangle -7566196 true true 158 79 217 164 Polygon -7566196 true true 158 81 110 129 131 143 158 109 165 110 Polygon -7566196 true true 216 83 267 123 248 143 215 107 Polygon -7566196 true true 167 163 145 234 183 234 183 163 Polygon -7566196 true true 195 163 195 233 227 233 206 159 truck-down false 0 Polygon -7566196 true true 225 30 225 270 120 270 105 210 60 180 45 30 105 60 105 30 Polygon -8716033 true false 195 75 195 120 240 120 240 75 Polygon -8716033 true false 195 225 195 180 240 180 240 225 truck-right false 0 Polygon -7566196 true true 180 135 75 135 75 210 225 210 225 165 195 165 Polygon -8716033 true false 210 210 195 225 180 210 Polygon -8716033 true false 120 210 105 225 90 210 truck-left false 0 Polygon -7566196 true true 120 135 225 135 225 210 75 210 75 165 105 165 Polygon -8716033 true false 90 210 105 225 120 210 Polygon -8716033 true false 180 210 195 225 210 210 circle true 0 Circle -7566196 true true 35 35 230 @#$#@#$#@ NetLogo 1.1 (Rev F) @#$#@#$#@ @#$#@#$#@ @#$#@#$#@