Traffic Flow Simulation
Cellular automaton traffic models � watch phantom jams, gridlock phase transitions, and bottleneck congestion emerge from simple rules.
🚗 Nagel-Schreckenberg Model
The NS model (1992) is a 1D cellular automaton where each car follows four rules each time step: accelerate if below v_max, brake to avoid collision, randomly decelerate with probability p, then move forward v cells. Despite its simplicity it reproduces free flow, synchronised flow, and stop-and-go waves.
👻 Phantom Traffic Jams
At moderate densities (20�35%) with p > 0.2, backward-propagating shock waves spontaneously form. No accident caused them � they are an emergent property of the system. Real-world studies show these waves travel at ~15 km/h upstream, matching the NS model prediction.
🔄 BML Phase Transition
The Biham-Middleton-Levine model on a 2D lattice shows a sharp first-order phase transition. Below ?_c � 0.32�0.37 the city flows freely. Above it the grid instantly freezes into complete deadlock � a striking example of emergent criticality in a simple deterministic system.
📊 Fundamental Diagram
Traffic flow theory relates density ? (cars/km), speed v (km/h), and flow q (cars/h) via the flow conservation law q = ?�v. The fundamental diagram plots q vs ? � an inverted U with a maximum at the critical density. The NS model reproduces this curve including the capacity drop at breakdown.
The Nagel-Schreckenberg Model (1992)
Kai Nagel and Michael Schreckenberg published their cellular automaton model in 1992. Unlike fluid-continuum models, the NS model treats each vehicle individually as discrete cells. The road is a 1D lattice with L cells; each cell is either empty or occupied by one car with integer velocity v ? {0, 1, � , vmax}.
Each time step applies four deterministic + stochastic rules simultaneously to all cars:
Here gap(i) is the number of empty cells between car i and the next car ahead. The random deceleration probability p (slider) models human reaction time variability and over-braking.
| Density ? | Typical behaviour | Lyapunov-like signature |
|---|---|---|
| < 0.15 | Free flow � cars maintain v_max, no interaction | Smooth, no jams form |
| 0.15 � 0.30 | Metastable � small perturbations may nucleate jams | Phantom jams for p > 0.3 |
| 0.25 � 0.45 | Synchronised flow � stop-and-go waves, backward propagation | Wave speed ~15 km/h back |
| 0.45 � 0.70 | Congested � near-standstill, v� � v_max | High variability in flow |
| > 0.70 | Jam � gridlock, q ? 0 | No forward movement |
Space-Time Diagram (Kymograph)
The inset diagram in Ring mode is a kymograph: the horizontal axis is position along the ring road (1 px = 1 cell) and time advances downward. Coloured pixels show occupied cells (green = fast, red = slow). The diagonal stripes running from upper-right to lower-left are shock waves � traffic jams propagating backwards against the flow of cars. Their slope gives the wave speed.
In free-flow conditions the kymograph is mostly uniform; at moderate densities with p > 0.2, you will see the classic dark, backward-slanting bands of phantom jams.
Biham-Middleton-Levine Model (1992)
The BML model uses a G � G torus with two types of car: right-movers (orange) and up-movers (blue). On even steps all right-movers advance one cell if the cell ahead is empty; on odd steps all up-movers advance. This idealises a city with perfectly synchronised traffic lights � green every other second for each direction.
Oded Biham, Alan Middleton and Dov Levine discovered a remarkably sharp phase transition at critical density ?_c � 0.32�0.37. Below ?_c all cars reach their destinations freely. Above ?_c the entire grid seizes into a frozen, checkerboard-like deadlock pattern � no car can ever move again. The transition is first-order (discontinuous), occurring almost instantaneously.
| Property | Free Phase (? < ?_c) | Jammed Phase (? > ?_c) |
|---|---|---|
| Average velocity | v� > 0, decreasing with ? | v� = 0 permanently |
| Order parameter f | > 0 | = 0 (absorbing state) |
| Phase transition type | First-order (discontinuous) � abrupt jump | |
| Critical density ?_c | � 0.32�0.37 (depends on grid size G) | |
| Self-healing? | Yes � perturbations dissipate | No � frozen forever |
Bottleneck and Lane-Drop Congestion
When a road narrows from two lanes to one (a lane drop), the capacity decreases abruptly. If vehicles arrive at a rate exceeding the downstream capacity, a queue grows indefinitely upstream. The growth rate is:
In the Bottleneck mode, lane 1 (lower road) ends at the drop marker. Cars must merge left into lane 0, reducing average speed at the merge point and creating back-of-queue shock waves. Increasing spawn probability or density makes the queue grow faster.
The Fundamental Diagram of Traffic Flow
The relationship between the three macroscopic traffic variables is given by the flow conservation law:
In free flow, v� � v_max, so q rises linearly. Beyond the capacity point (?_c, q_max), v� drops faster than ? rises, so flow decreases even as density increases. This creates the characteristic inverted-U shape (also called the "Greenshields" or "LWR" curve in macroscopic models).
| Road type | v_max | Capacity q_max | ?_c |
|---|---|---|---|
| Urban single lane | 50 km/h | ~1 000 veh/h | 0.35 |
| Rural two-lane | 80 km/h | ~1 600 veh/h | 0.30 |
| Motorway (per lane) | 120 km/h | ~2 200 veh/h | 0.25 |
| Urban signalised (BML) | 40 km/h | Phase transition at ?_c � 0.33 | 0.33 |
Applications of Cellular Automaton Traffic Models
| Application | NS/BML role |
|---|---|
| Ramp metering / on-ramp control | Regulate spawn rate to prevent congestion onset upstream |
| Variable speed limits | Smoothing density by reducing v_max before critical density region |
| Traffic light optimisation | BML predicts optimal synchronisation cycle lengths |
| Autonomous vehicle (AV) platooning | AV with p ? 0 virtually eliminates phantom jams |
| Pedestrian evacuation planning | Similar CA models (floor-field) for crowd dynamics |
| City infrastructure investment | BML lockup density guides density-cap policies |
Curriculum Relevance
| Level | Topic | Concepts illustrated |
|---|---|---|
| GCSE / A-Level Physics | Dynamics / Kinematics | Speed, density, flow; conservation of vehicles |
| A-Level Maths / Further Maths | Discrete mathematics | Cellular automata, integer arithmetic, probability |
| A-Level / IB Computer Science | Algorithms & modelling | Rule-based simulation, emergence, agent-based systems |
| Undergraduate Maths/Physics | Non-linear dynamics / phase transitions | First-order transitions, order parameter, shock waves, LWR PDE |
Frequently Asked Questions
What is a phantom traffic jam?
A phantom (or ghost) traffic jam arises without any physical obstacle � no accident, no roadwork. In the NS model it emerges when one car brakes slightly due to the random-deceleration rule; the car behind must brake harder, and backward-propagating density waves form. These stop-and-go waves are self-sustaining on a ring road and travel at roughly 15 km/h upstream regardless of the cars' average forward speed.
Why does the BML city grid freeze so suddenly?
The BML model has no randomness � it is completely deterministic after the initial placement. The phase transition is first-order: the order parameter (fraction of cars moving) jumps discontinuously from a positive value to zero as density crosses ?_c. Just below ?_c the grid self-organises into flowing lanes; just above it the two species of car form a mutually blocking deadlock. The absence of noise means there is no gradual degradation � the transition is as sharp as mathematical models allow.
How does increasing v_max affect phantom jams?
Higher v_max increases the gap required to brake safely, making the braking rule (Step 2) activate more aggressively. This amplifies the shock-wave amplitude. Conversely, setting v_max = 1 (all cars at speed 0 or 1) produces a TASEP (totally asymmetric simple exclusion process), which has an exact analytic solution. Higher v_max values (5 as used here) reproduce empirically observed stop-and-go waves closer to reality.
How can AVs reduce phantom jams?
In the NS model, phantom jams arise from the random-deceleration term (probability p). Autonomous vehicles using adaptive cruise control maintain a smooth speed profile and effectively operate with p � 0. Simulations show that even a small fraction (10�20%) of AVs in a mixed-traffic stream dramatically reduces jam formation. In BML-style city grids, AVs communicating with traffic lights (V2I, vehicle-to-infrastructure) can suppress the gridlock transition by coordinating departures.