o1.city
Type members
Classlikes
A CityMap
is a square grid that represents a simplified map of a city. It is a
Grid whose elements are Demographic objects. That is, each
GridPos (“street address”) on a CityMap
is either Vacant
or stores a household that belongs to aparticular demographic.
A CityMap
is a square grid that represents a simplified map of a city. It is a
Grid whose elements are Demographic objects. That is, each
GridPos (“street address”) on a CityMap
is either Vacant
or stores a household that belongs to aparticular demographic.
A CityMap
is mutable. As a household moves, the corresponding Demographic
object moves to a different GridPos
on the CityMap
.
- Value parameters:
- homesPerSide
the number of street addresses in each row and each column of the city grid (which is always square)
- populations
a vector of pairs in which each
Demographic
is matched with a count of how many times it appears on this city map
A Demographic
indicates which demographic (“slice of the overall population”)
a particular household belongs to (if any). It is used by the simulator
to mark households on a city map.
A Demographic
indicates which demographic (“slice of the overall population”)
a particular household belongs to (if any). It is used by the simulator
to mark households on a city map.
There are two kinds of Demographic
objects: Vacant
and Occupied
:
-
The singleton object Vacant is used for indicating that a residence is empty and does not belong to any demographic.
-
Occupied objects indicate that a residence belongs to a specific demographic; each different demographic is assigned a different
Color
. For instance, a residence may be “occupied by the red demographic”, or “occupied by the blue demographic”.
What exactly constitutes a demographic is unimportant for the purposes of this class. Demographics could be based on people’s socioeconomic status, political views, ethnicity, age, or something else.
All Demographic
objects are immutable.
The trait Demographic
itself does not define any methods; it merely serves
as a supertype for Occupied and Vacant.
An Occupied
object signals that a household belongs to a demographic
specific by the color label stored within the Occupied
object.
For instance, a residence may be “occupied by the red demographic”,
or “occupied by the blue demographic”.
An Occupied
object signals that a household belongs to a demographic
specific by the color label stored within the Occupied
object.
For instance, a residence may be “occupied by the red demographic”,
or “occupied by the blue demographic”.
An Occupied
object is immutable
- Value parameters:
- label
a color that distinguishes the occupying demographic from others
A Simulator
object is a city simulator based on Schelling’s model of emergent
social segregation. Its key methods are startNew
, which launches a new simulation,
and moveResidents
, which advances the most recently launched simulation by moving
dissatisfied residents into vacant homes. A selection of other methods is also
provided for examining the state of the simulation.
A Simulator
object is a city simulator based on Schelling’s model of emergent
social segregation. Its key methods are startNew
, which launches a new simulation,
and moveResidents
, which advances the most recently launched simulation by moving
dissatisfied residents into vacant homes. A selection of other methods is also
provided for examining the state of the simulation.
As implied above, a Simulator
is mutable: Calling startNew
causes the
simulator to discard any previously active simulation and start processing
a new one. Calling moveResidents
modifies the state of the active simulation.