Packages

c

o1.city

Simulator

class Simulator extends AnyRef

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.

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Simulator
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Instance Constructors

  1. new Simulator()

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. def allAddresses: Vector[grid.GridPos]

    Returns all the locations in the city.

  5. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  6. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native() @HotSpotIntrinsicCandidate()
  7. def dissatisfiedResidents: Vector[grid.GridPos]

    Returns the locations of all dissatisfied households in the city.

    Returns the locations of all dissatisfied households in the city. A household is dissatisfied if it does not have a sufficient proportion of neighbors that share its demographic. For example, if the city-dwellers desire a similarity of 50%, at least four of a household's eight neighbors need to share its demographic or it will be dissatisfied. (Dissatisfied residents will move when moveResidents is next called.)

    When determining a household's neighbors, diagonally adjacent grid locations count, and many households will have a full eight neighbors. However, Vacant locations don’t count as neighbors, nor do locations that are beyond the edges of the grid. A corner location, then, will only have a maximum of three neighbors, less if any of the three locations are vacant.

    For example, consider a non-vacant corner location. There are three locations next to it on the grid. If one of them shares the corner’s demographic, another doesn’t, and the third one is vacant (and therefore ignored), then 50% of the corner’s two neighbors are similar to the corner.

    Vacant locations are never returned by this method (i.e., they count as satisfied). Any household with zero neighbors is considered to be satisfied.

  8. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  9. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  10. def findDemographic(demographic: Demographic): Vector[grid.GridPos]

    Returns all the locations in the city that contain the given demographic.

  11. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  12. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  13. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  14. def moveResidents(): Unit

    Advances the most recently launched simulation by one step, moving all dissatisfied households to vacant locations on the grid.

    Advances the most recently launched simulation by one step, moving all dissatisfied households to vacant locations on the grid. During the simulation step, the dissatisfied households move one at a time, in random order, each receiving a random home among the ones that are vacant at that moment. (That is, a household may move to a home vacated by another dissatisfied household earlier during the same simulation step.)

    Satisfied residents stay where they are. If a satisfied resident becomes dissatisfied during this simulation step (because others move), that does not cause them to move (yet).

    If there are no vacant addresses at all in the city, this method does nothing.

    See also

    dissatisfiedResidents

    startNew

  15. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  16. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  17. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  18. def residents: Map[Demographic, Vector[o1.GridPos]]

    Returns a Map whose keys are all the demographics present in the city (Vacant included) and whose values list all the locations where that demographic is present.

    Returns a Map whose keys are all the demographics present in the city (Vacant included) and whose values list all the locations where that demographic is present.

    Note to students: This method will only be implemented in Chapter 9.2. You won't need it before that.

  19. def satisfactionLevel: Double

    Returns the proportion of satisfied residents in the city.

    Returns the proportion of satisfied residents in the city. For example, a return value of 0.0 means that nobody is satisfied, 1.0 that everyone is, and 0.95 that most are.

    See also

    dissatisfiedResidents

  20. def squaresPerSide: Int

    The number of residences in each row and column of the city grid.

  21. def startNew(squaresPerSide: Int, fillPercent: Int, demographics: Vector[Occupied], occupiedRatio: Int, similarityDesired: Int): Unit

    Launches a new simulation.

    Launches a new simulation. The simulation will take place on a newly initialized city grid as specified by the parameters provided. After calling this method, moveResidents will advance the newly launched simulation; any previously ongoing simulation is simply discarded.

    squaresPerSide

    the number of residences in each row and column (the city grid is always square)

    fillPercent

    the percentage of residences that have a resident and are not vacant (between 0 and 100)

    demographics

    the demographics that populate the non-vacant residences; the first element of the collection is the "main" demographic

    occupiedRatio

    the percentage of non-vacant residences occupied by the "main" demographic (between 0 and 100); the remaining residences are evenly split between the other demographics

    similarityDesired

    the minimum percentage of neighboring residences that must match a household's demographic in order for the household to be satisfied (between 0 and 100)

  22. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  23. def toString: String
    Definition Classes
    AnyRef → Any
  24. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  25. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  26. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])

Deprecated Value Members

  1. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable]) @Deprecated @deprecated
    Deprecated

    (Since version ) see corresponding Javadoc for more information.

Inherited from AnyRef

Inherited from Any

Ungrouped