CityFlow: A Multi-Agent Reinforcement Learning Environment for Large Scale City Traffic Scenario

Huichu Zhang, Siyuan Feng, Chang Liu, Yaoyao Ding, Yichen Zhu, Zihan Zhou, Weinan Zhang, Yong Yu, Haiming Jin, Zhenhui LiWWW 2019 · DOI

Abstract

Traffic signal control is an emerging application scenario for reinforcement learning. Besides being as an important problem that affects people's daily life in commuting, traffic signal control poses its unique challenges for reinforcement learning in terms of adapting to dynamic traffic environment and coordinating thousands of agents including vehicles and pedestrians. A key factor in the success of modern reinforcement learning relies on a good simulator to generate a large number of data samples for learning. The most commonly used open-source traffic simulator SUMO is, however, not scalable to large road network and large traffic flow, which hinders the study of reinforcement learning on traffic scenarios. This motivates us to create a new traffic simulator CityFlow with fundamentally optimized data structures and efficient algorithms. CityFlow can support flexible definitions for road network and traffic flow based on synthetic and real-world data. It also provides user-friendly interface for reinforcement learning. Most importantly, CityFlow is more than twenty times faster than SUMO and is capable of supporting city-wide traffic simulation with an interactive render for monitoring. Besides traffic signal control, CityFlow could serve as the base for other transportation studies and can create new possibilities to test machine learning methods in the intelligent transportation domain.

Introduction

Reinforcement learning (RL) is a data-intensive field. Training an effective agent for traffic signal control requires millions of samples. In a real-world setting, a single day provides only 1,440 one-minute data points, which is insufficient for deep learning. Consequently, high-fidelity simulators are essential for progress in this domain.

However, existing open-source tools like SUMO (Simulation of Urban Mobility) face a "scalability wall." SUMO is largely single-threaded and struggles to simulate thousands of intersections simultaneously. Furthermore, its interface for RL—typically via Python sockets—introduces significant communication overhead. This makes city-scale RL research, such as simulating an entire metropolis like Manhattan, prohibitively slow.

Methodology

CityFlow is a microscopic traffic simulator that tracks the physics and behavior of every individual vehicle. To overcome the limitations of previous tools, several architectural improvements were implemented:

  • Multi-threaded Execution: Designed to utilize multi-core processors, allowing parallel simulation of different road network segments.
  • Optimized Data Structures: The environment uses a "Segment" system—small fragments of lanes—to allow vehicles to quickly find neighbors. This converts collision and lane-change checks into constant-time searches.
  • Efficient Intersection Logic: CityFlow precomputes "cross points" where paths intersect. Vehicles notify these points of their arrival, reducing intersection management complexity to $O(N_{crosspoints})$.
  • Ballistic Position Updates: The simulator uses ballistic rather than Euler updates for more realistic vehicle dynamics at larger time-steps (e.g., 1 second).
  • Seamless Python Integration: By using pybind11 for C++/Python bindings instead of socket-based communication, CityFlow eliminates the massive overhead usually associated with retrieving simulation states during training.

Experimental Setup

The paper evaluates CityFlow using a mix of synthetic and real-world inspired road networks:

  • Synthetic Grids: $1 \times 1$, $6 \times 6$, and $30 \times 30$ grid networks used to test scalability and speed.
  • Real-World Data: A digital twin of a portion of the Manhattan road network demonstrates the simulator's ability to handle complex, non-grid layouts.
  • Traffic Flow: Testing was conducted under varying traffic volumes, ranging from 100 to 500 vehicles per hour.
CityFlow supports diverse road networks, including synthetic grids and real-world layouts like Manhattan.

Results and Discussion

CityFlow demonstrates significant performance gains over existing standards. On a large $30 \times 30$ grid with tens of thousands of vehicles, CityFlow achieved a 25x speedup over SUMO when using 8 threads. The system can process approximately 72 simulation steps per second on a city-wide scale, making it feasible to run "years" of traffic simulation in a matter of days.

Speedup of simulation steps per second compared to SUMO across various network sizes and threading configurations.

Key insights from the evaluation include:

  • The "Communication Tax": A significant bottleneck in RL simulation is the data transfer between the engine and the agent. Moving from sockets to direct memory bindings (pybind11) provided a massive efficiency boost.
  • Shadow Vehicles: To manage lane changes, CityFlow creates a "shadow" of a vehicle in its target lane. This shadow acts as a leader for vehicles in the new lane before the physical transition is complete, ensuring smooth traffic flow without complex synchronization.
  • Validated Realism: Vehicle travel durations in CityFlow and SUMO differed by only 0.07% to 1.06%, confirming that CityFlow is a valid drop-in replacement for traffic research.

Conclusion

While CityFlow is a powerful engine for traffic signal control, future work will focus on calibration using real-world traffic observations and expanding support for diverse RL tasks such as dynamic vehicle routing and reversible lane management. CityFlow proves that microscopic detail is viable at a city-wide scale with the right architectural optimizations.

Summary updated

BibTeX
@inproceedings{zhang2019cityflow,
  author = {Huichu Zhang and Siyuan Feng and Chang Liu and Yaoyao Ding and Yichen Zhu and Zihan Zhou and Weinan Zhang and Yong Yu and Haiming Jin and Zhenhui Li},
  title = {{CityFlow: A Multi-Agent Reinforcement Learning Environment for Large Scale City Traffic Scenario}},
  booktitle = {The Web Conference},
  year = {2019},
  doi = {10.1145/3308558.3314139},
}
Figure