TL;DR
If you want to design smart highway controls—like traffic lights on on-ramps—you need fast, mathematical models of how traffic jams form and spread. While researchers have used two classic "macroscopic" models (CTM and METANET) for decades, there hasn't been a single, open-source Python library that lets you run, compare, and calibrate both on the exact same highway network. This paper introduces traffic-flow-models, a pip-installable Python package that unifies both models, plugs in ramp-metering controllers, and calibrates parameters in under a second per simulation.
What Problem Does This Paper Address?
Traffic simulators come in two main flavours. Microscopic simulators track every individual car's acceleration and lane changes—great for local detail, but way too slow for city-wide networks or real-time control. Macroscopic models treat traffic like a compressible fluid, tracking only aggregate flow, density, and mean speed.
Two workhorses dominate macroscopic highway modelling:
- Cell Transmission Model (CTM): A simple, first-order model where cars instantaneously adopt the speed dictated by a triangular flow-density relationship.
- METANET: A richer, second-order model that adds an explicit dynamic equation for mean speed, capturing driver anticipation, relaxation, and transient effects like capacity drop.
Despite their popularity, open-source implementations that put both models on a unified network structure with shared demand inputs, control interfaces, and calibration tools have been missing. Without that common ground, comparing models or benchmarking controllers under identical conditions is tedious and error-prone.
Methods
The authors built traffic-flow-models around a single, consistent network representation:
- Unified Network: Highways are broken into homogeneous motorway links (further divided into cells respecting the Courant–Friedrichs–Lewy condition so vehicles don't jump more than one cell per time step), on-ramps, off-ramps, virtual origins, and virtual destinations. Ramps and origins act as "store-and-forward" links with virtual queues.
- Model Mechanics: CTM uses proportional node inflow reductions to respect downstream space constraints. METANET, by contrast, determines all degrees of freedom via its speed and density equations, using virtual upstream speeds and downstream densities at merge and diverge nodes.
- Ramp Metering Interfaces: The library supports custom rule-based controllers and ships with two reference implementations: ALINEA (a local feedback controller that meters an on-ramp based on downstream density) and METALINE (a coordinated controller that uses measurements from multiple locations to balance queues across ramps). Both support realistic update intervals and maximum queue-length limits.
- Calibration: To fit model parameters to data, the authors implement a sliding-window non-linear least-squares regression. It smooths noisy initial states with a centred moving average, normalises residuals by link-wide means, and includes optional Tikhonov regularisation.
Datasets
No real-world sensor datasets are used. Instead, the authors evaluate the framework on two synthetic highway scenarios with trapezoidal demand profiles (ramping up, holding peak demand, and ramping down over 60 minutes):
- Scenario 1: A 3 km stretch with one on-ramp and a lane-drop bottleneck (used for model comparison and calibration).
- Scenario 2: A 4 km homogeneous stretch with three on-ramps and no lane drop (used to test local vs. coordinated ramp metering).
For calibration tests, synthetic ground-truth data from METANET is used both noise-free and perturbed with Gaussian noise (7.5% on flow and speed, 15% on density).
Key Insights and Ideas
- Same network, very different physics: Under identical excess demand, CTM caps bottleneck outflow at exact capacity and pushes congestion onto the on-ramp. METANET's transient dynamics allow flow to briefly exceed capacity before settling slightly below it, keeping congestion on the mainline.
- Coordination beats local greed: Local ramp metering (ALINEA) reacts only to local bottlenecks, piling up a massive queue on the last on-ramp. Coordinated metering (METALINE) anticipates downstream congestion and meters upstream ramps earlier, clearing the last queue ~10 minutes sooner.
- Control makes calibration easier: When calibrating METANET on noisy data without control, parameters like $\kappa$ and $\delta$ drift by ~25% due to strong parameter correlations. Adding ALINEA ramp metering produces more informative traffic trajectories, dropping the largest parameter error below 10%.
Key Results
- Ramp Metering (Scenario 2, METANET): Compared to no control (Total Time Spent, $\text{TTS} = 920.8\text{ veh h}$):
- ALINEA cuts TTS by 19.4% ($742.5\text{ veh h}$).
- METALINE cuts TTS by 31.6% ($630.2\text{ veh h}$).
- Even with a strict maximum on-ramp queue of 90 vehicles, ALINEA still reduces TTS by 8.0%.
- Calibration (Scenario 1, METANET): Recovers exact parameters (0.0% error) on noise-free data. Full simulation runs execute in under a second, making repeated evaluations for optimisation fast and practical.
Limitations and Future Work
The current framework focuses on rule-based ramp metering and does not yet include variable speed limits (VSL) or optimisation-based controllers out of the box, though its symbolic non-linear dynamics representation is well-suited for them. On-ramps and off-ramps are simplified as store-and-forward links without modelling physical spillback onto urban streets. Future work could add more macroscopic models, richer network features, alternative calibration schemes, and reinforcement learning environments.
Summary updated