CitySim Docs
Fall 2025
API

# o1.city

package o1.city

## Members list

### Packages

package o1.city.gui

### Type members

#### Classlikes

class CityMap(val `homesPerSide`: Int, `populations`: Vector[(Demographic, Int)]) extends Grid[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 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`.

## 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

## Attributes

Supertypes
  trait Grid[Demographic]
  class Object
  trait Matchable
  class Any

sealed trait Demographic

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.

## Attributes

Supertypes
  class Object
  trait Matchable
  class Any
Known subtypes
  class Occupied
  object Vacant

final class Occupied(val `label`: Color) extends 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 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

## Parameters

label

  a color that distinguishes the occupying demographic from others

## Attributes

Supertypes
  trait Demographic
  class Object
  trait Matchable
  class Any

class Simulator

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.

## Attributes

Supertypes
  class Object
  trait Matchable
  class Any

object Vacant extends Demographic

This immutable singleton object effectively means “no demographic at all”. It can be used on a CityMap to indicate that a residence is empty.

This immutable singleton object effectively means “no demographic at all”. It can be used on a CityMap to indicate that a residence is empty.

## Attributes

Supertypes
  trait Demographic
  class Object
  trait Matchable
  class Any
Self type
  Vacant.type