This is the real Nagel-Schreckenberg cellular automaton: a ring of L discrete cells, each holding at most one car with an integer speed 0..v_max. Every step applies the same four rules to every car in parallel, using the state from the previous step only:
1. Accelerate: v = min(v + 1, v_max)
2. Brake: v = min(v, gap-to-next-car - 1)
3. Randomise: if v > 0 and rand() < p: v = v - 1
4. Move: position = (position + v) mod L
- Rule 3 is the only source of randomness. In dense traffic one unlucky slowdown forces the car behind to brake too, and the perturbation grows into a phantom jam that drifts backwards through the ring even though the road ahead is completely clear.
- The fundamental diagram panel plots measured flow q against density ρ: each point is the time-averaged throughput actually recorded by this automaton at that density, not a theoretical curve, accumulated live as you change the Density slider or run Auto-sweep.
- Auto-sweep steps the density from empty to jammed and back automatically so the whole q(ρ) curve — including its peak — fills in without manual dragging.
This unrolled 2D view and its live-measured fundamental diagram are mechanically the same automaton as the 3D ring-and-point-cloud version of this sim, read out and plotted differently.