agent_urban_planning.Environment¶
- class Environment(zones, transport, ahlfeldt_params=None, transport_matrix=None, transport_matrix_index=None)[source]¶
Bases:
objectSpatial environment holding zones and transportation network.
The geographic backbone of a simulation. Holds the per-zone properties (housing supply, base prices, amenities, facilities, and Ahlfeldt fundamentals where applicable) and a graph-based
TransportNetwork. Optionally also carries an Ahlfeldt-style dense travel-time matrix keyed by zone name when the scenario is a Berlin replication. The edge-listTransportNetworkremains the primary interface;transport_matrixis a zero-copy alternative used byAhlfeldtUtilityEnginefor vectorized distance lookups.- Parameters:
zones (
list[Zone]) – List ofZoneinstances comprising the simulation geography.transport (
TransportNetwork) – ATransportNetworkdescribing edges between zones.ahlfeldt_params (
Optional[AhlfeldtParams]) – OptionalAhlfeldtParamsdescribing the structural elasticities of the Berlin model. Present only for Berlin/Ahlfeldt scenarios.transport_matrix (
Optional[ndarray]) – Optional dense(N, N)travel-time matrix in zone-name order.transport_matrix_index (
Optional[list[str]]) – Zone names corresponding to the rows / columns oftransport_matrix.
Examples
>>> import agent_urban_planning as aup >>> # Typically built from a scenario YAML, not constructed manually: >>> # env = aup.Environment.from_config(scenario) >>> # env.travel_time("Mitte", "Charlottenburg")
- classmethod from_config(config)[source]¶
Build an
Environmentfrom a parsedScenarioConfig.Materializes per-zone records (including Ahlfeldt fundamentals and synthesized total-floor-area where missing), constructs the
TransportNetworkfrom edge records, and optionally loads a dense travel-time matrix fromconfig.transport_matrix_pathwhen present.- Parameters:
config (
ScenarioConfig) – A loadedScenarioConfigwithzones,transport, and optionalahlfeldt_params/transport_matrix_pathfields.- Return type:
- Returns:
A fully wired
Environmentready for use as thebase_envof aSimulationEngine.- Raises:
ValueError – If
transport_matrix_pathis set but the resulting matrix shape does not matchlen(zones).
Examples
>>> import agent_urban_planning as aup >>> # scenario = aup.data.builtin.load("singapore_real_v2") >>> # env = aup.Environment.from_config(scenario)
- travel_time(origin, destination)[source]¶
Return the travel time in minutes between two zones.
Uses the dense
transport_matrixwhen available (Berlin scenarios); falls back to the edge-listTransportNetworkotherwise. Returnsfloat('inf')if no route exists.- Parameters:
- Return type:
- Returns:
Travel time in minutes (
float('inf')if disconnected).
Examples
>>> import agent_urban_planning as aup >>> # env = aup.Environment.from_config(scenario) >>> # env.travel_time("Mitte", "Mitte") 0.0
- get_zone(name)[source]¶
Look up a zone by name.
- Parameters:
name (
str) – Zone name (must be present in this environment).- Return type:
- Returns:
The
Zonewith that name.- Raises:
KeyError – If
nameis not a known zone in this environment.
Examples
>>> import agent_urban_planning as aup >>> # env = aup.Environment.from_config(scenario) >>> # zone = env.get_zone("Mitte") >>> # zone.housing_supply
- apply_policy(policy)[source]¶
Apply a policy and return a new
Environmentwith the changes baked in.Does not mutate the original environment. Adds new
Facilityinstances to zones that receive facility investments, and updates transport routes (in both directions) for transit investments.- Parameters:
policy (
PolicyConfig) – APolicyConfigdescribing facility and transit investments.- Return type:
- Returns:
A new
Environmentinstance with the policy’s investments applied. The original environment is unchanged.
Examples
>>> import agent_urban_planning as aup >>> # env = aup.Environment.from_config(scenario) >>> # env_after = env.apply_policy(policy)