Segregation By Neighbor Preference
WHAT IS IT?
This project explores the segregation of a community based on neighbor preference. It is based on research carried out by Thomas Schelling in the 1950's when he sought to figure out why cities were divided into neighborhoods along racial boundaries even when a large percentage of the population considered itself to be accepting of others of different races. In this model, there are two different brees of agents: frogs and toads. The environment has gray roads through dividing it. Frogs will stay where they are if happypct of their neighbors are also frogs. The same goes for toads. If a frog or toad is not happy in their current location, then it moves to a random new location to see if it could be happy there.
HOW TO USE IT
Click the SETUP button to clear away the previous frogs and toads and setup the new ones. Click the GO button to start the simulation at the current settings. The pctcover (read as "percent cover") slider controls the percentage of patches that are covered by frogs or toads. The happypct (read as "happy percent") slider sets the percentage of similar neightbors a frog of toad needs to be happy. The randomness slider controls the percent of time a frog or toad moves regardless of what breed their neighbors are. Change the slider settings and see what happens.
THINGS TO NOTICE
Watch the neighborhoods changing on the canvas. Do you see any patterns? Watch the avgHappy monitor to see how the average happiness of changes over time.
EXPLORATIONS
Is there a happypct setting at which frogs and toads can maintain mixed (heterogenous) neighborhoods? Is there a happypct setting at which segregated neighborhoods always emerge? What is the affect of lowering or raising the pctcover? How does the randomness rate affect the outcome? There are many extensions of this model such as adding different happypct's for each breed or adding more breeds. Can you implement some of them? Can you add a plot window to graph the average happiness over time?
STARLOGO FEATURES
The thishappypct? procedure searches the neighborhood surrounding a turtle in a clever way. Think of a clock face with the minutes hand facing North. This is the first position checked. If one of the turtles there is of the same breed, we add one to the happycount and add one to the totalcount. If the turtle is of another breed, we add one to the totalcount but not to the happycount. Then the hand moves 45 degrees clockwise and we check the patch for a turtle and if found, we count it in the same way. This continues for the remaining 6 increments of 45 degrees.
Turtle procedures
turtles-own [happy] ; boolean value, either true or false
breeds [frogs toads] ; two breeds of turtles: frogs and toads
;; placeUnique procedure
;; called by placehappy and by itself (recursively)
;; If there is only one turtle here then stop (leave this procedure)
;; If there is more than one turtle on the patch, move to a new
;; random position then call placeUnique until a spot is found where
;; the turtle will be the only one there.
;;
to placeUnique
if count-turtles-here = 1 [stop]
setxy random screen-width random screen-height
placeUnique
end
;; findhappy procedure
;; called in the observer go procedure
;; Sets the turtle variable to true if the turtle's happiness here
;; is greater than the user-specified happypct value.
;;
to findhappy
sethappy (thishappypct? > happypct)
end
;; placehappy
;; called by the observer go procedure
;; A turtle will try to find a new place if one of the following is true
;; it is not happy
;; picking a number between 0 - 99 results in a number less than randomness
;; it is on a gray patch
;;
to placehappy
if (not happy) or ((random 100) < randomness) or (pc = gray) [
setxy random screen-width random screen-height
placeUnique
]
end
;; thishappypct? procedure
;; called by the findhappy procedure
;; Calculate the current turtle's happiness by looking at each of the eight
;; patches encircling it ("in its neighborhood"). When a turtle of the same
;; breed as the current turtle is found, it is counted then the number of
;; turtles of the same breed found divided by the total number of turtles
;; found is returned as the value of this procedure.
;;
to thishappypct?
let [ :happycount 0
:totalcount 0
:currentdir 0
:current 0
]
repeat 8 [
set :current (one-of-turtles-towards :currentdir 1)
if :current > -1 [
if (breed-of :current) = breed
[set :happycount :happycount + 1]
set :totalcount :totalcount + 1
]
set :currentdir :currentdir + 45
]
ifelse :totalcount = 0
[output 100]
[output ((:happycount / :totalcount) * 100)]
end
Observer procedures
;; setup procedure
;; called by the setup button
;; Clears turtles remaining from previous run then creates a number of turtles
;; derived using the pctcover value on the slider pctcover. Roughly half of the
;; turtles become green frogs, and the rest become red toads. Each turtle gets
;; placed on a unique patch (so no two turtles will ever occupy the same patch.)
;;
to setup
ct
crt screen-width * screen-height * (pctcover / 100)
ask-turtles [
setshape frogtoad-shape
ifelse (random 2) = 0
[setbreed frogs setcolor green]
[setbreed toads setcolor red]
placeUnique
]
end
;; go procedure
;; called by the go button
;; This is the main loop of the program that has each turtle find if it is happy
;; then uses this to determine whether or not it should move.
to go
ask-turtles [findhappy]
ask-turtles [placehappy]
end
;; avgHappy procedure
;; called by the avgHappy monitor
;; This procedure returns the average happy percent of all the turtles so it
;; can be reported in the monitor.
;;
to avgHappy
output ((sum-of-turtles [thishappypct?]) / count-turtles)
end
