Loading the engineShared by all simulations, so the next one opens instantly.
The physics

Kai Nagel and Michael Schreckenberg proposed this cellular automaton for motorway traffic in 1992. The road is a row of cells, each car has an integer speed, and four local rules move the cars. With nothing but random hesitation of single drivers, the model produces the phantom jams known from real motorways: at high enough density, stop-and-go waves form without any accident or bottleneck and travel backwards against the direction of driving.

What you see

A space-time diagram of a ring road of 256 cells. Each row is the whole road at one step, with cars driving to the right and leaving on the right edge to come back on the left. The newest row is at the top, and the picture scrolls down by one row per step, so the full height shows the last 256 steps. Cars are coloured by speed, from red (stopped) through yellow to green (maximum speed); empty road is black.

A car’s track runs up and to the right, steeper the slower it drives. A jam is a red band in which cars pile up, wait and leave again at its front. The band itself drifts to the left, upstream, by 0.4 to 0.6 cells per step in these presets: cars join it at its back while the cars at its front drive off.

Rule

Every step applies four rules to all cars, using the positions from the previous step, where gi is the number of empty cells in front of car i:

  1. accelerate: vi←min⁡(vi+1,vmax),
  2. brake to avoid the car ahead: vi←min⁡(vi,gi),
  3. dawdle: with probability p, vi←max⁡(vi−1,0),
  4. move: xi←xi+vi.

Cars never collide or overtake. The flow, the number of cars passing a point per step, is J=ρ⟨v⟩ for density ρ=N/L. Without dawdling (p=0) the model is deterministic and the fundamental diagram is exactly

J=min⁡(ρvmax,1−ρ),

with its maximum at ρ=1/(vmax+1), about 43 cars here for vmax=5. Dawdling lowers the curve and moves the maximum to lower density: with p=0.3 the flow peaks at about 0.49 cars per step near 30 cars, against 0.83 at 43 cars without dawdling.

Presets

Every run starts with the cars evenly spaced at maximum speed. Times are at 60 frames per second and one step per frame.

Free flow: 25 cars (ρ≈0.10), vmax=5, p=0.1. The gaps are large enough that a dawdling car never forces the one behind it to stop: the mean speed stays at 4.9 and no jam forms.

Onset of jams: 35 cars (ρ≈0.14), vmax=5, p=0.3, just above the density of maximum flow. The first car comes to a stop after about 50 steps (under a second), and from then on jams keep forming out of free flow and drifting upstream, with at least one car standing somewhere on the road at almost every step. On average 13% of the cars are standing, the mean speed is 3.4 and the flow 0.46 cars per step.

Congested: 150 cars (ρ≈0.59), vmax=5, p=0.5. Most of the road is one long series of jams with short gaps of moving cars: 77% of the cars are standing at any time, the mean speed is 0.3 and the flow drops to 0.17 cars per step.

Slow road: 80 cars (ρ≈0.31), vmax=2, p=0.4. A lower speed limit moves the flow maximum to higher density, 1/(vmax+1)=1/3 without dawdling, so this road carries 80 cars at about its best flow of 0.3 cars per step while a third of them are standing at any time.

Parameters

Cars: the number of cars on the 256 cells, 1 to 200. A change applies at once and places all cars again, evenly spaced at maximum speed.

Maximum speed (cells per step): the speed limit vmax, 1 to 10. It applies after Reset.

Dawdle probability: the chance p per step that a car slows down by one for no reason, 0 to 1. It applies at once and is the noise that starts the jams.