After my blog post about how maths means trains seem more frequent than they are, here’s another even more irritating rail-based maths problem.

From Germany, I’ve been feeling quietly smug watching the chaos on the UK Northern and Thameslink lines over the past few days. Well, joke’s on me, because I got my own transport chaos this morning. One tram didn’t show up this morning, which was mildly annoying. But they’re frequent – every five minutes or less at peak times – so I wasn’t too worry. Five minutes later, along came the next tram, but it was so full up that no-one could board. Another five minutes, and another totally packed tram arrived. By the time I managed to squeeze my way onto a tram, I’d missed my train to work.

How could this happen? How could a well-trafficked route, which doesn’t normally run anywhere near capacity, completely collapse with a single cancelled tram?

Here’s an simplified model of the tram line. Let’s assume there are six stops total – five in residential areas, and one at the end at a central railway station. In the morning at rush hour, 20 people show up every minutes at each residential stop, all wanting to go to the central station. The tram can hold 120 people, so it can easily hold all those passengers, with 20 spare seats.

On a normal day that will work fine – the tram never fills up, so it can deal with normal variations in passenger load – and in total, with a tram every 5 minutes, this system can transport 1,200 people an hour in comfort – with space for an extra 240 passengers if needed. That means 2 trams an hour could be cancelled without ill effect, right?

So, let’s cancel one. Five minutes pass, no tram shows up, and another five minutes pass. Another 20 people arrive at each stop, so there are now 40 at each. The tram picks up the first 40, second 40, third 40… and now it’s full. No-one can board at the fourth or fifth stops.

OK, so another five minutes pass. Again, 20 people show up at every stop. This means the first three stops each have 20 passengers, and last two stops each have 60 passengers. The tram picks up 20 passengers, another 20, then 20 more, and finally 60 people at stop 4. And that makes 120. It’s full again. Still no-one can board at the last stop.

Yet another five minutes. It’s now been 20 minutes since the last tram took on passengers at the fifth stop. The people waiting will be getting horribly impatient. Another tram shows up, and *finally*, there’s some space onboard. After taking on 20 people at each preceding stop, it has 80 people on board, meaning there’s space for 40 more. Of the 80 waiting, only half of them can board.

We’re down to just 40 at the fifth stop… but in the next five minutes another 20 people arrive. That means the next tram can’t quite take everyone, so it takes one more tram to move everyone. The tram chaos lasted a full 30 minutes, with some passengers left waiting at least 20 minutes, even though only one tram on a 5-minute schedule was actually cancelled.

You can’t escape this maths by driving either, because this is related to the kind of maths that mean tiny traffic variations can cause absolute gridlock. Given a junction that can handle 10 cars a minute, if 11 cars a minute are showing up it takes just half an hour to develop a 30 car traffic jam. Queueing theory is a cruel mistress.