Optimization1983intermediate10 min read

Optimization by Simulated Annealing

الأمثَلة بالتلدين المحاكى

Kirkpatrick, S. · Gelatt, C. D. · Vecchi, M. P. — Science

The problem

Many real-world problems — circuit layout, scheduling, routing — have rugged cost landscapes with countless local minima. Greedy algorithms that only accept improving moves get trapped in the nearest , which may be far from the global optimum. Exact methods are computationally intractable for large instances because combinatorial problems grow factorially. By 1983, no general-purpose heuristic could reliably escape local minima across diverse problem domains.

The contribution

A direct analogy between statistical mechanics and . In metallurgy, slowly cooling a molten metal lets atoms find their lowest-energy crystal arrangement. Kirkpatrick et al. mapped this to optimization: the is the energy, a candidate solution is an atomic configuration, and a control parameter called "" governs how readily the accepts uphill (worsening) moves via the Metropolis criterion. At high temperature, the algorithm explores freely; as temperature decreases on a "," it becomes increasingly greedy and converges toward the global optimum. Experiments on graph partitioning and the demonstrated competitive results on NP-hard problems.

The impact

One of the most cited papers in optimization history (46,000+ citations). became a standard tool in VLSI design, operations research, protein folding, and machine learning. It spawned an entire family of physics-inspired metaheuristics — genetic algorithms, particle swarm optimization, and quantum annealing. Its core insight — that controlled randomness can escape local minima — remains foundational to modern stochastic optimization and even influenced the design of MCMC sampling methods in Bayesian inference.

Imagine a blindfolded hiker dropped onto a mountain range at night, searching for the lowest valley. A greedy hiker only walks downhill — she reaches the bottom of the nearest dip and stops, never knowing a deeper valley lies two ridges away.

Simulated annealing gives the hiker a flashlight that dims over time. While the light is bright (high temperature), she deliberately climbs uphill to explore new territory. As the light fades, she becomes more cautious, refusing to climb unless the uphill path is short. By dawn (zero temperature), she walks only downhill — but by then she has surveyed enough terrain that the valley she settles into is almost certainly the deepest one.

The problem: greedy search gets trapped

Many optimization problems are like navigating a rugged landscape in the dark. The cost function defines the height at every point, and the goal is to find the lowest valley — the . The simplest approach, iterative improvement (hill climbing in reverse), repeatedly moves to a neighboring solution with lower cost. It always converges, but it converges to the nearest local minimum, which may be arbitrarily far from the best solution.

For small or smooth problems this is fine. But real-world combinatorial optimization problems — laying out millions of transistors on a chip, routing a delivery truck through hundreds of cities, scheduling thousands of tasks — have cost surfaces riddled with local minima. A greedy optimizer applied to a random starting point almost never reaches the global optimum.

Open in Lab
Click "Greedy" to watch iterative improvement get stuck, then "Anneal" to see how simulated annealing explores and escapes.
The demo wakes as you arrive…

The inspiration: how metals crystallize

When a blacksmith heats metal until it melts, atoms vibrate wildly and explore many configurations. If the metal is cooled slowly (annealed), atoms gradually settle into a regular crystal lattice — the arrangement with the lowest energy. But if cooled too fast (quenched), atoms freeze in a disordered arrangement with higher energy — they got trapped in a local energy minimum.

Kirkpatrick, Gelatt, and Vecchi noticed a deep analogy: the cost function of an optimization problem is like the energy of a physical system, and a candidate solution is like an atomic configuration. The , invented in 1953 to simulate thermal equilibrium, already provided a recipe for sampling configurations at a given temperature. The key insight was to decrease the temperature over time — importing the annealing schedule from metallurgy into the optimization world.

Open in Lab
Slow cooling (annealing) lets atoms find the crystal lattice. Fast cooling (quenching) freezes them in disorder. Drag the cooling rate to see the difference.
The demo wakes as you arrive…

The engine: the Metropolis criterion

The Metropolis algorithm is the engine inside simulated annealing. At each step it proposes a small random change to the current solution, computes the change in cost ΔE\Delta E, and decides whether to accept or reject. The decision rule is elegantly simple:

  • If the new solution is better (ΔE≤0\Delta E \leq 0): always accept.
  • If the new solution is worse (ΔE>0\Delta E > 0): accept with exp⁡(−ΔE/T)\exp(-\Delta E / T).

At high temperature TT, even large uphill moves have a reasonable chance of acceptance — the algorithm explores freely. As TT decreases, the probability of accepting a worsening move shrinks exponentially, and the algorithm becomes increasingly greedy. This is the controlled transition from to .

P(accept)={1if ΔE≤0exp⁡ ⁣(−ΔE/T)if ΔE>0P(\text{accept}) = \begin{cases} 1 & \text{if } \Delta E \leq 0 \\ \exp\!\bigl(-\Delta E / T\bigr) & \text{if } \Delta E > 0 \end{cases}
The Metropolis acceptance criterion — ΔE is the cost difference (new − current). T is the temperature. When T is large the exponential is close to 1 even for large ΔE. When T → 0, only improvements pass. This single formula encodes the entire exploration–exploitation tradeoff.

Think of it like a coin toss with a biased coin. The bias depends on two things: how bad the proposed move is (ΔE\Delta E), and how hot the system is (TT). A barely-worse move at high temperature is almost certainly accepted. A much-worse move at low temperature is almost certainly rejected. The genius is that this simple mechanism is enough to guarantee to the global optimum — given a sufficiently slow cooling schedule.

Open in Lab
Adjust temperature and ΔE to see how the acceptance probability changes. Watch the coin toss decide in real time.
The demo wakes as you arrive…

The cooling schedule: from chaos to order

The cooling schedule controls how temperature decreases over time. It is the bridge between the physical analogy and practical optimization. Too fast and the algorithm quenches into a poor local minimum — too slow and it wastes computation exploring territory it has already mapped.

The original paper used a geometric schedule: Tk+1=α⋅TkT_{k+1} = \alpha \cdot T_k with α\alpha typically between 0.9 and 0.99. At each temperature the algorithm runs enough iterations to reach quasi-equilibrium before cooling further. Other schedules include linear decay and logarithmic decay (Tk=C/ln⁡(1+k)T_k = C / \ln(1+k)), which has a theoretical guarantee of convergence but is impractically slow.

In practice, tuning the schedule is part art, part experiment: start hot enough that ~95% of moves are accepted, cool slowly through the temperature range where the acceptance ratio drops from 90% to 10% (this is where structure forms), then quench at the end.

Tk+1=α⋅Tk,0<α<1T_{k+1} = \alpha \cdot T_k, \quad 0 < \alpha < 1
Geometric cooling schedule — The simplest and most common schedule. α close to 1 (e.g. 0.99) cools slowly for thorough exploration; α closer to 0.9 cools faster for quicker convergence at the risk of missing the global optimum.
Open in Lab
Compare geometric, linear, and logarithmic cooling. Watch how each schedule affects the temperature curve and the quality of the final solution.
The demo wakes as you arrive…

The algorithm: step by step

Putting it all together, simulated annealing works in four stages:

  • Initialize. Pick a random starting solution ss and a high initial temperature T0T_0.
  • Propose. Generate a random neighbor s′s' of the current solution.
  • Decide. Compute ΔE=cost(s′)−cost(s)\Delta E = \text{cost}(s') - \text{cost}(s). If ΔE≤0\Delta E \leq 0, accept s′s'. Otherwise, accept with probability exp⁡(−ΔE/T)\exp(-\Delta E / T).
  • Cool. After enough iterations at the current temperature, reduce TT according to the cooling schedule. Repeat until TT is near zero or the solution has stabilized.

The key design choices are: how to define the neighborhood (what counts as a "small change"), how to set the initial temperature, and which cooling schedule to use. These are problem-specific — there is no universal best setting, which is both the method's flexibility and its limitation.

Open in Lab
Click each step to walk through the simulated annealing algorithm visually.
The demo wakes as you arrive…

The theory: why it works

The theoretical backbone of simulated annealing comes from the in statistical mechanics. At thermal equilibrium, a physical system at temperature TT occupies ss with probability proportional to exp⁡(−E(s)/T)\exp(-E(s) / T). This means lower-energy states are exponentially more likely, but higher-energy states are not impossible — they occur with a frequency that depends on temperature.

The Metropolis algorithm generates a whose stationary is exactly the Boltzmann distribution at the current temperature. When TT is high, the distribution is nearly uniform — all states are explored. When TT is low, probability mass concentrates on the lowest-energy (lowest-cost) states. As T→0T \to 0, the distribution converges to a point mass on the global minimum.

The convergence theorem states: if the temperature decreases slowly enough (Tk≥C/ln⁡(1+k)T_k \geq C / \ln(1+k) for a constant CC related to the energy landscape), then the algorithm converges to the global optimum with probability 1. This is a powerful guarantee — but the required cooling rate is too slow for practice, so real implementations use faster schedules and accept near-optimal solutions.

P(s)=exp⁡(−E(s)/T)∑s′exp⁡(−E(s′)/T)P(s) = \frac{\exp\bigl(-E(s)/T\bigr)}{\displaystyle\sum_{s'} \exp\bigl(-E(s')/T\bigr)}
Boltzmann distribution — the equilibrium the algorithm targets — At high T, all states have roughly equal probability (exploration). At low T, probability concentrates on low-energy states (exploitation). The denominator is the partition function Z(T).

Applications: TSP and circuit design

The original paper demonstrated simulated annealing on two NP-hard problems:

The Traveling Salesman Problem (TSP) — find the shortest route visiting every city exactly once. The neighborhood move is a 2-opt swap: reverse a segment of the tour. Kirkpatrick et al. tested on instances with hundreds to thousands of cities and found results competitive with the best-known heuristics of the time.

Graph partitioning for VLSI — divide a circuit's components into two groups so that the number of wires crossing the partition (the "cut") is minimized. This directly impacts chip manufacturing cost. The neighborhood move swaps a component between groups. Simulated annealing found partitions that significantly beat rapid quenching (greedy optimization from a random start), demonstrating that the controlled acceptance of uphill moves is essential.

Open in Lab
Watch simulated annealing optimize a traveling salesman tour. The path starts chaotic and gradually untangles as temperature drops.
The demo wakes as you arrive…

The same idea in code

Simulated annealing — complete minimal implementationpython

Simplified to show the idea — not the real implementation.

import math, random

def simulated_annealing(cost_fn, neighbor_fn, s0, T0=100, alpha=0.995, n_iter=1000):
    """
    cost_fn(s)    — returns the cost of solution s
    neighbor_fn(s) — returns a random neighbor of s
    s0             — initial solution
    T0, alpha      — initial temperature and geometric decay rate
    """
    s = s0
    best = s
    T = T0

    for _ in range(n_iter):
        s_new = neighbor_fn(s)                      # propose a neighbor
        delta = cost_fn(s_new) - cost_fn(s)         # cost difference

        if delta <= 0 or random.random() < math.exp(-delta / T):
            s = s_new                               # accept: better or lucky

        if cost_fn(s) < cost_fn(best):
            best = s                                # track the best ever seen

        T *= alpha                                  # cool down

    return best

# That's it. The entire algorithm fits in 12 lines.
# The magic is in cost_fn, neighbor_fn, and the cooling schedule.

Why it mattered

  1. 1953

    Metropolis Algorithm

    Metropolis, Rosenbluth et al. invent the algorithm for sampling states of a physical system at thermal equilibrium — the engine that simulated annealing would later repurpose.

  2. 1983

    Simulated Annealing (this paper)

    Kirkpatrick, Gelatt, and Vecchi bridge statistical mechanics and combinatorial optimization. The paper appears in Science and ignites a wave of physics-inspired metaheuristics.

  3. 1985

    Černý's independent proposal

    Vojtěch Černý independently proposes a similar thermodynamic approach for the traveling salesman problem, confirming the power of the idea.

  4. 1989

    Convergence proofs

    Hajek proves that logarithmic cooling guarantees convergence to the global optimum, providing the theoretical foundation for the method.

  5. 1994

    Genetic Algorithms gain traction

    Holland's genetic algorithms — inspired by evolution rather than physics — become another pillar of metaheuristic optimization, directly influenced by SA's success.

  6. 1998

    Quantum Annealing

    Kadowaki and Nishimori propose quantum annealing, replacing thermal fluctuations with quantum tunneling to escape local minima even faster — a direct descendant of the SA idea.

  7. 2011

    D-Wave quantum annealer

    D-Wave Systems builds the first commercial quantum annealing processor, demonstrating that Kirkpatrick's analogy extends all the way to hardware.

Simulated annealing showed that borrowing ideas across fields — physics to computer science — could yield powerful algorithms with both theoretical guarantees and practical utility. Today it remains a go-to baseline for any new combinatorial optimization problem, and its descendants power everything from drug discovery to chip design.

CitationKirkpatrick, Gelatt, Vecchi. Optimization by Simulated Annealing. Science, 1983.

Terms in this paper