Only a Fool

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 i, with 1D position x_i and velocity v_i. 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

\frac{dv_i}{dt} = \lambda(v_{i+1} - v_i)

where \lambda represents how hard the driver likes to accelerate. We can integrate this equation once to give

\frac{dx_i}{dt} = \lambda(x_{i+1} - x_i) + C

where C is some integration constant. The term inside the brackets is the distance between the cars, which can be related to the density of cars

\rho = \frac{1}{x_{i+1} - x_i}.

Now cars have a certain length L, so there is a maximum peak density the traffic can reach, \rho_{max} = 1/L. At this point we have a traffic jam, so

v_i = \frac{dx_i}{dt} = 0 \Rightarrow C = -\frac{\lambda}{\rho_{max}}.

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 v_{max}. We then know the car speed as a function of traffic density

v_i = \left\{ \begin{array}{ll} v_{max} & \rho < \rho_{min} \\ \frac{\lambda}{\rho} - \frac{\lambda}{\rho_{max}} & \rho_{min} < \rho < \rho_{max} \end{array} \right.

where the minimum density \rho_{min} = \lambda/(L\lambda + v_{max}). This is plotted below for different \lambda, and it is obvious that as drivers get dopier (\lambda getting smaller), they start to balk at dense traffic and slow down more quickly.

Density

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 s(x,t), then we have

\frac{\partial\rho}{\partial t} + \frac{\partial(v\rho)}{\partial x} = s(x,t).

We also know from the ‘microscopic’ analysis above of individual cars that the mean velocity is dependent on density such that

v\rho = \frac{\lambda}{\rho_{max}}(\rho_{max} - \rho)

and

\frac{\partial(v\rho)}{\partial x} = \frac{d(v\rho)}{d\rho}\frac{\partial \rho}{\partial x} = -\frac{\lambda}{\rho_{max}}\frac{\partial \rho}{\partial x} .

Putting everything together then, the car density distribution satisfies

\left(\frac{\partial}{\partial t} - \frac{\lambda}{\rho_{max}}\frac{\partial}{\partial x}\right)\rho = s(x,t).

This should be recognisable as a wave equation, for backwards-travelling waves with velocity \lambda/\rho_{max}. 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.

ExampleTraffic

Now if we scale this up a bit we can simulate a longer section of road to see how the traffic pattern develops:

Traffic1We 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.

Traffic2

What if the drivers are more alert? We can adjust the \lambda 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!

Traffic3

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.

SpaceTime

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.

TrafficJam

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.

Advertisement

10 thoughts on “Only a Fool

  1. 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 :-)?

    Like

      1. Hey Jason,

        Any chance that code can be made available?
        The plots(and your blog) are great, awesome work keep it up!!!

        Like

  2. 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.

    Like

    1. 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.

      Like

  3. 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:

    http://desdelamediterrania.cat/2014/03/07/boles-que-cauen-experimentant-amb-la-resistencia-aerodinamica/

    cheers from Barcelona!

    Like

    1. 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

      Liked by 1 person

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s