Pick two traffic states and watch the queue boundary move
Light traffic (upstream) runs into heavy traffic (downstream). The boundary between them is a shock wave. Its speed is the slope of the chord joining the two states on the fundamental diagram:
w = \frac{q_D - q_U}{k_D - k_U}.
The diagram is the course triangle (Lecture 3): free-flow speed 100 km/h, wave speed 20 km/h, jam density 120 veh/km, so one lane carries at most 2,000 veh/h, at 20 veh/km. Drag the sliders. When the shock speed is negative, the queue grows backward, against the traffic.
NoteBefore you play: predict
A queue stands at a red light, and light traffic keeps arriving. Does the back of the queue move with the traffic, stand still, or move backward? How fast?
viewof kU =knob({min:5,max:115,step:1,value:10,label:"Upstream density kU",format: k =>`${k} veh/km`})viewof kD =knob({min:5,max:115,step:1,value:110,label:"Downstream density kD",format: k =>`${k} veh/km`})
panel(row(viewof kU, viewof kD))
vf =100// free-flow speed, km/hww =20// backward wave speed, km/hkj =120// jam density, veh/kmkc = kj * ww / (vf + ww) // critical density: 20 veh/kmQ = k =>Math.min(vf * k, ww * (kj - k))V = k => k >0?Q(k) / k : vfC = k => k <= kc ? vf :-ww // characteristic (wave) speed dQ/dkqU =Q(kU)qD =Q(kD)isShock = kU < kDw =Math.abs(kD - kU) <1e-9?C(kU) : (qD - qU) / (kD - kU)
md`${isShock?`**Shock wave speed: ${w.toFixed(1)} km/h** ${w <0?"(moving backward: the queue grows upstream)":"(moving forward)"}`:C(kU) ===C(kD)?`**No fan:** both states are on the same side of capacity, so the boundary simply moves at ${C(kU).toFixed(0)} km/h.`:`**Rarefaction:** dense traffic upstream of light traffic spreads out as a *fan* of waves, like a queue discharging at a green light. The fan's edges move at ${C(kU).toFixed(0)} and ${C(kD).toFixed(0)} km/h.`}`
{const T =0.1, X =4;// 6 minutes, ±4 kmconst m =Math.max(1,Math.ceil(Math.max(kU, kD) * X /20));// draw every m-th vehicleconst vU =V(kU), vD =V(kD);const paths = [];let id =0;// upstream vehicles, starting behind the boundary at x < 0for (let x0 =-m / kU; x0 >-X - vU * T; x0 -= m / kU) {let pts;if (isShock) {const ts = w < vU -1e-9?Math.min(T, x0 / (w - vU)) : T;// time the vehicle meets the shock (never, if it is not faster) pts = [[0, x0], [ts, x0 + vU * ts], [T, x0 + vU * ts + vD * (T - ts)]]; } else { pts = [[0, x0], [T, x0 + vU * T]];// simplified: fan interaction not drawn } pts.forEach(([t, x]) => paths.push({id,t: t *60, x})); id++; }// downstream vehicles, ahead of the boundary at x >= 0for (let x0 =0; x0 < X; x0 += m / kD) { [[0, x0], [T, x0 + vD * T]].forEach(([t, x]) => paths.push({id,t: t *60, x})); id++; }const waves = isShock? [[{t:0,x:0,g:0}, {t: T *60,x: w * T,g:0}]]: d3.range(0,1.0001,1/6).map((f, g) => {const c =C(kU) + f * (C(kD) -C(kU));return [{t:0,x:0, g}, {t: T *60,x: c * T, g}]; });return Plot.plot({title:"Time-space diagram",width: colW,height:340,x: {label:"Time (min)",domain: [0, T *60]},y: {label:"Position (km)",domain: [-X, X]},clip:true,marks: [ Plot.line(paths, {x:"t",y:"x",z:"id",stroke:"#bbb"}), Plot.line(waves.flat(), {x:"t",y:"x",z:"g",stroke: accent,strokeWidth: isShock ?4:2}), Plot.ruleY([0], {stroke:"#ddd"}) ] });}
Things to try
With k_U = 10, slowly lower k_D from 110. At what downstream density does the shock stop moving backward? Why there?
Make k_U and k_D lie on opposite sides of the critical density k_c = 20 but at the same flow. What is the shock speed? Why?
Swap the two states so that k_U > k_D. What changes, and why is there no single shock line?
This builder uses the course triangle: v_f = 100 km/h, w = 20 km/h, k_j = 120 veh/km. Grey lines are vehicle trajectories; the violet line is the shock.
import {knob, panel, row} from"../assets/controls.js"theme = Generators.observe(notify => {const read = () =>notify(document.body.classList.contains("quarto-dark") ?"dark":"light");read();const watcher =newMutationObserver(read); watcher.observe(document.body, {attributes:true,attributeFilter: ["class"]});return () => watcher.disconnect();})accent = theme ==="dark"?"#c9a0ff":"#57068c"accentRange = theme ==="dark"? ["#4b3a5c","#ecdcff"] : ["#dccbee","#3a0463"]ink = theme ==="dark"?"#f2f2f2":"black"// Width of one column: the real column on a wide screen, the whole card on a phone or tablet (columns stack < 992 px),// so the charts are drawn to fit instead of being shrunk (and their text with them).colW = Generators.observe(notify => {let last;const read = () => {const col =document.querySelector("main .columns > .column");const w =Math.max(240,Math.min(640,Math.floor((col ? col.clientWidth:640) -8)));if (w !== last) notify(last = w); };read();window.addEventListener("resize", read);return () =>window.removeEventListener("resize", read);})