Total Pageviews

22 May 2006

Prawn mayonnaise and genetic algorithm sandwich

When I was at High School in the 1980s I took it upon myself one summer to take the school's only computer (!) home and teach myself programming. By the end of the summer I had written a 3,000 line program (back in the days when lines of code mattered!) that managed the school's shop for snacks and drinks. I wrote to Apple, who were really impressed and suggested I entered a competition they were running, which I ended up winning 2nd prize in - Young Programmer of the Year.

However, what is more surprising is that the basic elements of quality control, getting close to the customer and applying simple arithmetic when I wrote that program still seem to be eluding multi-billion pound companies. It doesn't take an award winning program to sort it out, it's something that's easy for us all to understand.

Roll forward about 15 years. I was working for a very small company with no on-site canteen and when I went out for lunch I went to a very large supermarket for a sandwich. It was fine if you got there before 12 but as lunch wore on, if you got to the sandwich bar anytime after 1pm, your only choice was prawn mayonnaise on white bread. I have nothing against prawn mayonnaise and wouldn't be averse to having it with a meal, but the idea of trying to eat a sandwich of it and the prawns and or mayo oozing out between the bread and all over my desk and keyboard is a scary thought - why don't they have keyboards you can actually clean, there's a thought!

Anyway, here's the "rocket science secret formula" I devised at High School.

X is your current stock level of a product just before going to the shops.
Y was the stock level of the product at the same time last week
Z was the amount of stock you bought at the shops last week after the stock take.

So the amount you had at the start of the week was Y+Z.
The amount you've sold is this number minus X, or Y+Z-X.
Therefore if you know you go through Y+Z-X in a week the amount you need to buy is this amount minus what you've already got, or X
Hence, what you need to buy this week is Y +Z -X -X

So last Friday you had two boxes of crisps left (Z), you bought another 3 (Y) and at the moment there's one left (X). So this week you need to buy 2+3-1-1 or three.

It's not perfect, and doesn't deal with the fact you could have sold more if a stock ran out half way through the week. Nor does it deal with seasonal variations such as no-one wanting to buy creme eggs after Easter. But it does the job, and it does it a lot better than major supermarkets manage, hence the glut of prawn mayo at 1pm. Also, being aware of the shortcomings, it can be improved over time.

Genetic algorithms are the same. They are a way of trying lots of different ways of solving a problem and of trying to get close to the optimal solution but usually a good solution rather than the optimal solution is good enough. One example is playing chess - so long as the computer chooses a decent legal move within a reasonable time then it's good enough - there simply isn't the computing power available to wait for the perfect move. These algorithms are great at problems for where there are multiple correct answers and which are difficult or impossible to solve via more traditional means. However, they really score when all you want to do is make a good choice in a reasonable time frame, it doesn't have to be perfect.

The concept is just as true for delivering a completed project to a customer - it may not need a genetic algorithm to solve it, but cracking the core of the problem and coming up with a good solution in a reasonable time-frame is usually far more preferable then a great solution in a completely unrealistic time-frame and at astronomic cost. A good solution which delivers on time is what the customer wants. In XP terminology, it's do the simplest thing that works.

This customer wants a bit more choice and for supermarkets to look at their algorithm for making sandwiches. It doesn't have to be perfect, but three simple changes will be enough to improve it.

1. Note which type sells out soonest, and make more of these tomorrow.
2. Note which type sells out last, and make less of these tomorrow.
3. Listen to your customers and what they tell you.

Lettuce remember this, make no beef about it and remember which side our bread is buttered on.

The customer is king, and a happy customer keeps both supermarkets and programmers in business.

Food for thought.
Post a Comment

Popular Posts