Simulated annealing

On this page 7

Simulated annealing is a probabilistic metaheuristic for optimization that explores a search space by proposing random moves and accepting worse solutions with a probability that decreases as a temperature parameter cools. In artificial intelligence and operations research, it is used for combinatorial and non-convex problems where gradient methods fail and exhaustive search is impossible.

The method borrows its name and logic from metallurgy, where slowly cooling a metal lets atoms settle into a low-energy crystal structure. In the algorithm, the objective function plays the role of energy, and the controlled acceptance of uphill moves lets the search escape local optima before it gradually behaves like greedy local search.

How simulated annealing searches a solution space

Simulated annealing works by repeatedly perturbing a current solution, comparing the new objective value with the old one and deciding whether to move. An improving move is always accepted. A worsening move with an increase in cost of delta E is accepted with probability exp(-delta E / T), known as the Metropolis acceptance criterion, where T is the current temperature.

At a high temperature, almost every move is accepted, so the search behaves like a random walk that samples the landscape broadly. As T falls, the probability of accepting large uphill steps shrinks quickly, and at a temperature near zero the procedure reduces to hill climbing. The best solution seen so far is usually stored separately, because the final state is not guaranteed to be the best one visited.

The core loop has a small number of components, and each one shapes the quality of the result as shown below.

ComponentRoleTypical choice
State representationEncodes one candidate solutionPermutation, bit vector or real vector
Neighborhood moveGenerates a nearby candidateSwap, 2-opt reversal, bit flip, Gaussian step
Energy functionScores each candidateObjective value to be minimized
Acceptance ruleDecides whether to moveMetropolis criterion exp(-delta E / T)
Cooling scheduleLowers T over timeGeometric decay with factor 0.90 to 0.999
Stopping ruleEnds the searchFinal temperature, iteration budget or stagnation
Components of a simulated annealing run

Cooling schedules and key parameters

The cooling schedule is the most influential design decision, because it sets the balance between exploration and exploitation. A theoretical result by Geman and Geman shows that a logarithmic schedule, T proportional to 1 / log(k), converges to a global optimum with probability one, but it is far too slow for practical use. Real implementations accept a loss of that guarantee in exchange for speed.

The initial temperature is commonly calibrated so that roughly 80 percent of worsening moves are accepted at the start. The number of moves per temperature level, often called the Markov chain length, is usually set to a multiple of the neighborhood size so the search can approach equilibrium before cooling continues.

ScheduleFormulaBehaviorPractical use
LogarithmicT = c / log(1 + k)Provably convergent, extremely slowTheoretical analysis
GeometricT = alpha times T, alpha 0.90 to 0.999Simple and predictableDefault in most solvers
LinearT = T0 minus beta times kReaches zero in fixed timeStrict time budgets
AdaptiveT adjusted from acceptance rateReacts to the landscapeIrregular or unknown problems
ReheatingT raised after stagnationRestarts explorationRugged landscapes with deep traps
Common cooling schedules compared

Simulated annealing belongs to the family of single-solution metaheuristics, and its closest relatives differ mainly in how they avoid getting trapped. Hill climbing never accepts a worse move, tabu search forbids recently visited moves through a memory list, and genetic algorithms maintain a population of candidates rather than a single state.

MethodEscape mechanismMemoryMain strength
Simulated annealingProbabilistic uphill movesNone beyond best solutionSimple, few parameters, robust
Hill climbingNone, or random restartsNoneFast convergence on smooth landscapes
Tabu searchDeterministic, forbidden movesShort-term tabu listStrong on scheduling and routing
Genetic algorithmRecombination and mutationPopulation of solutionsParallel exploration of distant regions
Gradient descentNone, depends on initializationOptional momentumEfficient on differentiable objectives
Simulated annealing and neighboring optimization methods

Unlike gradient-based methods, simulated annealing needs no derivatives, so it is a form of derivative-free optimization. It also differs from Bayesian optimization, which builds a surrogate model to save expensive evaluations; simulated annealing instead assumes that each evaluation is cheap enough to repeat thousands or millions of times.

Where the method fits in AI and operations research

Simulated annealing is chosen when the objective is discrete, noisy or highly multimodal, when a good solution is sufficient and when the problem can be expressed with a clear neighborhood move. Classic applications include the traveling salesman problem, VLSI chip placement, timetabling, graph partitioning and feature subset selection in machine learning.

The following decision table summarizes typical situations and whether the method is a sensible first choice.

SituationRecommendationReason
Large permutation or routing problemGood fitNatural swap and reversal moves
Convex, differentiable objectivePoor fitGradient methods converge far faster
Each evaluation takes minutesPoor fitToo many evaluations required
Need for proven optimalityUse exact methodsBranch and bound or integer programming give bounds
Rugged landscape, many local optimaGood fitUphill acceptance escapes traps
When to use simulated annealing

In modern AI systems, the idea also appears indirectly. Temperature in sampling from language models and the annealed learning rate schedules used in neural network training share the same intuition: begin with more randomness and reduce it gradually to settle on a stable result.

Limitations and common mistakes

The method offers no optimality certificate in finite time, and results vary between runs because the search is stochastic. Careful practitioners therefore report the mean and spread over several seeds rather than a single lucky run.

  • Cooling too fast freezes the search in a poor local optimum, a failure known as quenching.
  • Poorly scaled temperature relative to typical cost differences makes the acceptance rule meaningless.
  • Weak neighborhood moves that change too little or too much slow convergence more than any parameter choice.
  • Returning the final state instead of the best state visited discards good solutions found earlier.
  • Ignoring constraints in the move design forces large penalty terms that distort the energy landscape.

Stripped to the essentials

Simulated annealing is a way to search for a very good answer among a huge number of options. It starts with any answer. Then it makes small random changes and keeps the ones that help.

The clever part is that it sometimes keeps a change that makes things worse. Early on, it does this often. Later, it almost never does. This is like a hiker in fog who is willing to walk downhill at first to find a taller mountain. Over time, the hiker becomes more careful and simply climbs. The key idea is controlled risk: wander widely first, then settle down.

Where it is applied

A regional delivery company must plan routes for 25 vans serving about 1,200 stops each morning, with time windows and vehicle capacity limits. Exact solvers cannot finish within the 20-minute planning window, so the planning team uses simulated annealing with moves that swap stops between vans and reverse route segments.

The team sets the starting temperature so that about 80 percent of worse moves are accepted, uses geometric cooling with a factor of 0.995 and runs four independent seeds in parallel. Compared with the earlier greedy plan, the annealed routes reduce total driving distance by roughly 8 to 12 percent on typical days, while every run still completes in under 15 minutes.