HomeSociety & EconomicsTraffic Jams (NaSch)

🚗 Traffic Jams (NaSch)

Cellular-automaton traffic simulation: watch phantom jams emerge from random driver noise on a circular road. Fundamental diagram included.

Society & Economics3DModerate60 FPS
traffic-jam ↗ Open standalone

About this simulation

This is the Nagel–Schreckenberg model, the classic cellular automaton that explains why traffic jams appear on open roads with no accident, junction, or bottleneck in sight. Cars sit on a ring of L cells and, every step, all of them accelerate, brake to keep a safe gap, randomly slow down with probability p, then move forward in parallel. That single random-braking rule is enough to turn a perfectly even stream of traffic into self-sustaining "phantom jams" that drift backwards relative to the road even though every driver is moving forward.

🔬 What it shows

A ring road where each car is colour-coded by speed (red = stopped, green = at v_max), a space-time diagram stacking one row per step so jam waves show up as diagonal stripes, and a live fundamental diagram plotting flow Q against density ρ.

🎮 How to use

Drag Road length L and Cars to set the density, adjust v_max and the randomization p (the source of the noise), then toggle the Slow-to-start rule to see extra hysteresis at jam fronts. Use Pause/Step to inspect the automaton one iteration at a time.

💡 Did you know?

Empty-road capacity is reached near the critical density ρ_c ≈ 1/(v_max+1) — push density past that point and flow collapses even though nobody actually crashed into anybody.

Frequently asked questions

Why do jams appear with no obstacle at all?

The randomization step in the NaSch rule forces a car to brake with probability p even when it has room to accelerate. Once one car slows, the car behind must also slow to avoid the gap shrinking, and that disturbance propagates backward through the traffic stream faster than any single car moves forward.

What do the four NaSch rules actually do?

Each step every car accelerates toward v_max, then brakes to whatever gap is open ahead, then randomly loses one unit of speed with probability p, and finally moves forward by its new velocity. All updates happen in parallel across every car before positions change.

What is the "slow-to-start" rule?

It doubles the effective braking probability for a car that was fully stopped on the previous step. This mimics real driver reaction lag when pulling away from a standstill and makes jams noticeably more persistent and slower to dissolve, matching observed real-world traffic behaviour.

How do I read the space-time diagram?

Each horizontal row is one simulation step, with newer rows appearing toward the bottom; horizontal position along the row is the car's position on the ring. Diagonal stripes running from lower-right to upper-left are jam fronts propagating backward even as the cars inside them still creep forward.

Why does the fundamental diagram look triangular?

At low density, flow rises almost linearly because adding cars barely slows anyone down (free flow). Past the critical density ρ_c ≈ 1/(v_max+1), cars start interfering with each other's gaps, and flow falls again as density keeps rising — that peak-and-decline shape is the fundamental diagram of traffic flow.

⚙ Under the hood

The Nagel–Schreckenberg cellular automaton on a ring: accelerate, brake to gap, randomize, move. Phantom jams emerge from noise; the space-time diagram reveals backward-propagating jam waves.

Canvas 2DCellular AutomatonTraffic FlowNaSchPhantom Jam

3D · Three.js / WebGL renderer · 60 FPS target · runs fully client-side, no install

What did you find?

Add reproduction steps (optional)