File size: 1,752 Bytes
3d2dbcf | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | # env
CityFlow environment implementation for intersection-level RL with district-type metadata.
## Main files
- [traffic_env.py](/Users/aditya/Developer/traffic-llm/env/traffic_env.py)
Main environment. One episode corresponds to one `(city, scenario)` pair.
- [cityflow_adapter.py](/Users/aditya/Developer/traffic-llm/env/cityflow_adapter.py)
Thin wrapper around the CityFlow Python engine.
- [observation_builder.py](/Users/aditya/Developer/traffic-llm/env/observation_builder.py)
Converts variable city topology into fixed-size per-intersection tensors.
- [reward.py](/Users/aditya/Developer/traffic-llm/env/reward.py)
Configurable local reward calculation.
- [utils.py](/Users/aditya/Developer/traffic-llm/env/utils.py)
Topology parsing and helper functions.
- [intersection_config.py](/Users/aditya/Developer/traffic-llm/env/intersection_config.py)
Internal topology dataclasses.
## How it works
- Reads `roadnet.json`, `district_map.json`, and district types from `metadata.json`.
- Identifies non-virtual controllable intersections with at least two green phases.
- Uses one action per controllable intersection.
- Enforces `min_green_time` inside the environment.
- Advances CityFlow for `decision_interval` simulator steps between policy decisions.
- Returns a batched observation for all controlled intersections.
## Observation model
Per intersection:
- padded incoming lane vehicle counts
- padded incoming lane waiting counts
- incoming lane mask
- current green phase index
- elapsed time in current phase
- optional outgoing congestion summary
- district-type one-hot features
- optional small district context
- boundary-intersection indicator
The observation dimension is exposed as `TrafficEnv.observation_dim`.
|