I’ve spend an unreasonably significant fraction of my life sitting in traffic, particularly along the infamous M4 corridor in England. Now, living in London I’m well acquainted with the various ways traffic jams can form. The ones which result from stuffing too many cars into too tiny streets have an obvious cause. Somewhat more irritating are those forming for seemingly no reason out on the motorway – queueing for ages at a standstill only to suddenly drive away like nothing happened. I’ve spent enough time in this unenviable state that it’s almost (though inevitably not quite) worth dedicating some brain time to thinking about why.
Now the science and analysis of traffic flow is apparently so dull to most people that spies can use the job as cover. Undeterred, we can take a peek at some exposition on the subject and realise there’s much more going on under the surface.
We’d like to construct a model of traffic flow to try and understand where this ghost traffic comes from. For some basic definitions, lets assume each car is labelled , with 1D position and velocity . Further assume a given car will accelerate to match the one in front of it (up to the speed limit), and slow down to avoid a collision. The equation of motion for a car is then
where represents how hard the driver likes to accelerate. We can integrate this equation once to give
where is some integration constant. The term inside the brackets is the distance between the cars, which can be related to the density of cars
Now cars have a certain length , so there is a maximum peak density the traffic can reach, . At this point we have a traffic jam, so
Now for the other limit, at the moment our cars will keep on accelerating as they get more spread out. At some point this becomes illegal, so we need to impose a maximum speed limit . We then know the car speed as a function of traffic density
where the minimum density . This is plotted below for different , and it is obvious that as drivers get dopier ( getting smaller), they start to balk at dense traffic and slow down more quickly.
This is interesting to know (and confirms a privately-held hypothesis that all of this bloody traffic is caused by stupid drivers), but we can steal a bit of intuition from other areas of physics. For a simple 1-lane road with no junctions or exits, cars coming in = cars going out, or the flux of cars is conserved. This implies that the car density and velocity must together satisfy the continuity equation, used in physics wherever a flux is conserved. If there is some source of cars , then we have
We also know from the ‘microscopic’ analysis above of individual cars that the mean velocity is dependent on density such that
Putting everything together then, the car density distribution satisfies
This should be recognisable as a wave equation, for backwards-travelling waves with velocity . Traffic disturbances then travel backwards towards the incoming traffic. If the drivers are alert or the traffic density is low the traffic information propagates quickly. If the traffic is dense and the drivers dopy then traffic disturbances take a long time to travel back to the unwary commuter. I should note that there are many empirical and observational models relating traffic density and velocity, and this is only the simplest choice. The general form of the equation above is known rather tastily as the inviscid form of Burgers’ equation.
This is nice to know, so let’s try some numerical experiments to see if we can reproduce this behaviour. Specifically I model a simple straight road full of cars. Each car reacts to the one ahead of it by matching speed, as above. If the distance between cars gets too low, the driver panics and slams on the brakes to slow down much more quickly. The cars are ‘injected’ into the road with a small uniform random spread in speeds and distances, and get deleted as they exit the road.
To simulate a traffic jam, I insert a short section of the road with a lower speed limit where the drivers try to slow down to match the speed limit. I’ll plot these results as distance-speed plots, with dots representing cars, as in the example animation below. Cars enter from the left and begin reacting to the car ahead of them. The horizontal line represents the lower speed limit.
Now if we scale this up a bit we can simulate a longer section of road to see how the traffic pattern develops:
We can note a few things: the initial random velocity distribution smooths itself out quickly as the drivers react to one another. The traffic flows fairly smoothly despite the reduced speed limit, and cars accelerate smoothly out of the reduced speed zone.
We can have a look what happens when the speed limit is switched off. Annoyingly, the low-speed region persists despite there being no reason for it – the speed limit is maximum! This is the first hint that traffic can stick around for a while even after the original reason for it has gone.
What if the drivers are more alert? We can adjust the parameter to make the drivers react more aggressively to changes in velocity. As plotted below, we can see that the region of traffic now slides smoothly back towards the incoming cars. Now not only is there traffic for no reason, it’s not even in the right place!
This is easy to see in a space-time diagram too. The low-speed region is created by the restriction, then propagates backwards and flattens as it goes – the traffic gradually speeds up as cars are able to spread out.
For a proper traffic jam though, we’ll need a bit of gridlock. Lets suppose the drivers aren’t being sensible and obeying the 2-second rule, but are bunched up more closely than that. Using the same speed limits and driver awareness as above, the following animation shows what happens if instead the drivers are instead obeying a 1-second rule.
In this case a traffic jam appears immediately as cars begin to pile up the start of the speed limit (coloured red), and persists long after the restriction is lifted.
Don’t be a fool then, and let us all enjoy our dreary M4 drives in peace.
10 thoughts on “Only a Fool”
Those graphs are pretty interesting and fun to look at!
Any chance you could put the code to generate them somewhere, so that we can play and create our own traffic jams :-)?
Yes of course, once the code is cleaned up a bit! I’ll comment back here once it’s uploaded.
Any chance that code can be made available?
The plots(and your blog) are great, awesome work keep it up!!!
Hi Steve, thanks! And the .m file is here: https://www.dropbox.com/s/fkvk55dbrezit1v/CarSim2.m?dl=0
It’s not very good I’m afraid, and I’m not sure why I wrapped it in a function when it takes no inputs, but hopefully it’s useful.
I have recently started following your blog after your article on WiFi.. and this article has made me feel so justified in doing so. I have noticed these standing waves of traffic and been so incredibly frustrated with them. It is amazing that you’ve found some basic physics principles to model them as such. Kudos.
Hi Steve, I’m glad you like the post, thanks for the kind words. I didn’t invent any of this, just quoted some lecture notes I found on Google. I do think a little animation goes a long way though, so I hope I’m adding some tangible value to what’s already out there.
Hello Jason! It’s so interesting to see a simulation of your models and how easily you define them. When I was at the school of eng. we used some models to predict traffic behaviour in complex networks (containing roads of different capacities and diferent nodes) and used Wardrop model. But never examined this efect of “stupid drivers” who accelerate-brake.
BTW I’d be very honoured if you could check out my blog and this humble contribution to another blog, modelling air resistance in 1-D:
cheers from Barcelona!
Hi from London! I’m glad you like the post, I don’t really know anything about traffic modelling but it seems quite interesting – I’ll have a look at the model you mentioned. I had a look at (a translated version) of your post, I like the ‘phase space’ diagrams of your ODE solutions. It is also possible to get an analytic solution for constant quadratic drag, see e.g. here http://www.physics.udel.edu/~szalewic/teach/419/cm08ln_quad-drag.pdf
LikeLiked by 1 person
Ok, I’ll take a look!! thanks for reading the translated version (it was written in catalan and it was aimed at general public)