The Lab · Metropolis, 1953 · Kirkpatrick, Gelatt & Vecchi, 1983

Road Trip

The obvious way to improve anything is to try small changes and keep the ones that help. It soon gets stuck. Simulated annealing's secret is that now and then, on purpose, it keeps a change that makes things worse.

Try this

Press Start. Both computers begin with the same tangled scribble and make the same kind of change: pick two towns and swap their places in the order. The one on the right keeps a swap only if the trip gets shorter. It improves fast, then stops: stuck, usually with a few roads still crossing in red. The one on the left has a thermometer. While it's hot, it often keeps a swap that makes the trip longer; as it cools it gets pickier, until it only takes improvements. It finishes with the shorter trip almost every time.

Try Slowly too: the slower it cools, the better the trip, usually.

Why a worse step helps

Think of every possible route as a place in a huge, bumpy landscape, where low ground means a short trip. Keeping only improvements is walking downhill: you soon reach the bottom of a valley, but it may not be the deepest, and from there every step goes up. Accepting the occasional uphill step lets the search climb out of a shallow valley and find a deeper one. Early on, while it's hot, it accepts big uphill steps and wanders widely; later it accepts only small ones, and finally none, settling into the best valley it has found.

Where it came from

The name comes from metalwork. To anneal steel or glass, you heat it and cool it slowly, so its atoms have time to settle into a strong, orderly arrangement instead of freezing in a jumble. In 1953 Nicholas Metropolis and colleagues worked out how to simulate atoms doing this on one of the first computers, using exactly the rule here: always accept a move downhill, and accept one uphill with a chance that shrinks as the temperature falls. In 1983 Scott Kirkpatrick, Daniel Gelatt and Mario Vecchi realised the same trick could solve puzzles that have nothing to do with metal, including this one, the travelling salesman problem. It is still one of the most used ways to search for good answers, and the method behind many of the records in our contests.

Links