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.
| Component | Role | Typical choice |
|---|---|---|
| State representation | Encodes one candidate solution | Permutation, bit vector or real vector |
| Neighborhood move | Generates a nearby candidate | Swap, 2-opt reversal, bit flip, Gaussian step |
| Energy function | Scores each candidate | Objective value to be minimized |
| Acceptance rule | Decides whether to move | Metropolis criterion exp(-delta E / T) |
| Cooling schedule | Lowers T over time | Geometric decay with factor 0.90 to 0.999 |
| Stopping rule | Ends the search | Final temperature, iteration budget or stagnation |
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.
| Schedule | Formula | Behavior | Practical use |
|---|---|---|---|
| Logarithmic | T = c / log(1 + k) | Provably convergent, extremely slow | Theoretical analysis |
| Geometric | T = alpha times T, alpha 0.90 to 0.999 | Simple and predictable | Default in most solvers |
| Linear | T = T0 minus beta times k | Reaches zero in fixed time | Strict time budgets |
| Adaptive | T adjusted from acceptance rate | Reacts to the landscape | Irregular or unknown problems |
| Reheating | T raised after stagnation | Restarts exploration | Rugged landscapes with deep traps |
Simulated annealing compared with related methods
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.
| Method | Escape mechanism | Memory | Main strength |
|---|---|---|---|
| Simulated annealing | Probabilistic uphill moves | None beyond best solution | Simple, few parameters, robust |
| Hill climbing | None, or random restarts | None | Fast convergence on smooth landscapes |
| Tabu search | Deterministic, forbidden moves | Short-term tabu list | Strong on scheduling and routing |
| Genetic algorithm | Recombination and mutation | Population of solutions | Parallel exploration of distant regions |
| Gradient descent | None, depends on initialization | Optional momentum | Efficient on differentiable objectives |
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.
| Situation | Recommendation | Reason |
|---|---|---|
| Large permutation or routing problem | Good fit | Natural swap and reversal moves |
| Convex, differentiable objective | Poor fit | Gradient methods converge far faster |
| Each evaluation takes minutes | Poor fit | Too many evaluations required |
| Need for proven optimality | Use exact methods | Branch and bound or integer programming give bounds |
| Rugged landscape, many local optima | Good fit | Uphill acceptance escapes traps |
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.