Friday, May 25, 2012

Traffic Lights

Back when I was at university, we had a number of computing lectures talking about scheduler priorities. I especially remember the illustrations that were given, which were all to do with road management.

(Incidentally, I'm about to talk about these things in a UK context. If you live in one of those crazy countries where they drive on the wrong side of the road, then by all means swap 'left' for 'right' in what follows... What do you mean that that's just about everyone else?)

See, a roadabout is a good example of both blocking processes and round-robin scheduling. What happens is that every time someone turns right (actually, "not left"), they block the cars trying to come into the roundabout on the next extry along. This, in theory, allows a vehicle from the next-but-one entry to sneak in. And if they're going right, that frees up another entry, and so on.

It's actually quite interesting watching that at work. And it's really interesting seeing just how bad so many drivers are at handling this. Here's a hint, guys: You get a short window of opportunity... take it.

But more interesting than roundabouts, which are largely unstructured, are traffic lights, which have a strict ordering on them, and which therefore impose priorities on the traffic.

(The combined case, where you have traffic lights at a roundabout, are actually no different from just having the traffic lights. Here, the only reason for having the roundabout at all is that it cuts down on sharp turns, which may or may not be beneficial in itself. Unless, of course, the lights are themselves part-time.)

Which brings us to Moodiesburn.

Following the endless work (now finished) on the M80 upgrade, the powers-that-be saw fit to install a new set of lights at one of the entries to Moodiesburn. Which is good, because it's a pretty complex junction with lots of routes and lots of traffic.

I'm constantly bemused at how badly they managed to get it wrong. Not only are there long waits for the other directions to go, often when there are no other cars on any of those paths, but there is an entire section that acts as an airlock - when the light getting in is Green, the light getting out is always Red, and vice versa. It's a mess, leading to long and pointless delays.

But the best thing about the lights became apparent to me a couple of weeks ago, when I came to it from another direction. There, there were two lights, one heading left and the other right. Both were Red when I arrived. But shortly thereafter, the light for the left-most route started changing, and then the light for the right half a second later.

What this means is that somebody, probably somebody very clever indeed, sat down and went through a process of working out exactly how that junction should work in some detail. And that person went far enough to realise that there was obviously a need for the left lane to go a fraction before the right.

Somebody went to a great deal of trouble to get those lights utterly and horribly wrong.

And now, because I'm that sort of a guy, I'm going to tell you how they should have fixed it...

Firstly, they should have built proper filter lanes on both the route out of Moodiesburn and the one from the M80 Eastbound. There are small lanes, but only two cars each. Make the investment, and boost them to at least five cars each (ten or twenty would be better, of course). And then, fit filter signals to the left-turning lanes. This gives you a much greater flow of traffic, at no cost to other road users.

Secondly, fit sensors to the damn lights! Frankly, this should be standard procedure on all traffic lights these days; in fact, it should be illegal to build lights without them. That way, when I'm the only car at the entire junction, I don't need to wait several minutes for all the other lack of cars to go first!

(And, of course, when the junction is busy, you just switch to your hard-coded scheduling algorithms.)

Thirdly, get the guy who wrote this thing to go back, watch cars go through the junction for a week or so (24/7) and then rewrite the algorithms, actually getting them right this time. Bluntly, it's shocking that this hasn't been done, not least since this is the one that can be done without having to fit any more infrastructure.

(Incidentally, this brings me to my invisible point four. If we're really concerned about the environment, why do all our traffic lights run at night? That's a huge waste of energy. Switch them off at non-peak times. If they really want, they could then put sensors on them, so that they relight if a car approaches. But, honestly, in most cases they should just switch them off entirely - when there are only one or two cars about, they're generally able to sort themselves out. And those few muppets who can't are also the sorts of muppets who are liable to ignore the lights anyway.)

Anyway, that's my "traffic lights" rant... for today.

No comments: