Traffic Flow Simulation

Cellular automaton traffic models � watch phantom jams, gridlock phase transitions, and bottleneck congestion emerge from simple rules.

ModeRing Highway
Density ?
Flow q
Avg speed
Step0

🚗 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:

Step 1 � Acceleration: if v < v_max, v ? v + 1 Step 2 � Braking: if gap(i) = v, v ? gap(i) - 1 Step 3 � Randomisation: if v > 0 and rand() < p, v ? v - 1 Step 4 � Motion: x ? x + v

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 behaviourLyapunov-like signature
< 0.15Free flow � cars maintain v_max, no interactionSmooth, no jams form
0.15 � 0.30Metastable � small perturbations may nucleate jamsPhantom jams for p > 0.3
0.25 � 0.45Synchronised flow � stop-and-go waves, backward propagationWave speed ~15 km/h back
0.45 � 0.70Congested � near-standstill, v� � v_maxHigh variability in flow
> 0.70Jam � gridlock, q ? 0No 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.

BML order parameter: f = (fraction of cars that move per step) Free phase: f > 0 (proportional to 1 - ?/?_c) Jammed phase: f = 0 for all time
PropertyFree Phase (? < ?_c)Jammed Phase (? > ?_c)
Average velocityv� > 0, decreasing with ?v� = 0 permanently
Order parameter f> 0= 0 (absorbing state)
Phase transition typeFirst-order (discontinuous) � abrupt jump
Critical density ?_c� 0.32�0.37 (depends on grid size G)
Self-healing?Yes � perturbations dissipateNo � 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:

Queue growth rate = arrival flow - downstream capacity (cars/step)

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:

q = ? � v� (flow = density � mean speed)

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 typev_maxCapacity q_max?_c
Urban single lane50 km/h~1 000 veh/h0.35
Rural two-lane80 km/h~1 600 veh/h0.30
Motorway (per lane)120 km/h~2 200 veh/h0.25
Urban signalised (BML)40 km/hPhase transition at ?_c � 0.330.33

Applications of Cellular Automaton Traffic Models

ApplicationNS/BML role
Ramp metering / on-ramp controlRegulate spawn rate to prevent congestion onset upstream
Variable speed limitsSmoothing density by reducing v_max before critical density region
Traffic light optimisationBML predicts optimal synchronisation cycle lengths
Autonomous vehicle (AV) platooningAV with p ? 0 virtually eliminates phantom jams
Pedestrian evacuation planningSimilar CA models (floor-field) for crowd dynamics
City infrastructure investmentBML lockup density guides density-cap policies

Curriculum Relevance

LevelTopicConcepts illustrated
GCSE / A-Level PhysicsDynamics / KinematicsSpeed, density, flow; conservation of vehicles
A-Level Maths / Further MathsDiscrete mathematicsCellular automata, integer arithmetic, probability
A-Level / IB Computer ScienceAlgorithms & modellingRule-based simulation, emergence, agent-based systems
Undergraduate Maths/PhysicsNon-linear dynamics / phase transitionsFirst-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.

Related Simulations