Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Environments and space

Environments

Requires the environment feature (implied by model).

An environment holds model-wide values — state that is not per-agent, such as a price index, a policy rate, or an audit record. Values are keyed by name and type. Register a key up front to get a typed handle (EnvKey):

let key = builder.register_environment::<Prices>("prices", Prices::default())?;

Each environment key owns a channel, so a system that reads an environment value is automatically ordered after the systems that write it (see scheduling). Reads and writes go through the environment store by name and type:

let prices: Prices = model.environment().get::<Prices>("prices")?;

Because the environment is a boundary, writes made during a parallel stage are finalised deterministically at the stage edge. See use environment values.

Space

Requires the environment feature (implied by model).

The space layer provides spatial structure — a discrete grid and a continuous 2-D space — for models where agents have positions and interact by locality. A SpaceHandle owns a channel, so systems that update and read space are ordered correctly relative to one another.

Grid geometry uses saturating integer conversions, returns empty ranges for queries that do not intersect the space, and wraps explicitly on a torus where toroidal boundaries are requested. The same cell math backs the spatial message specialisation, so spatial messaging and spatial queries agree on which cell a position falls in.

See use grids and continuous space.