Short answer: Simulated annealing searches a rough cost surface by proposing a neighbor of the current state and accepting it when the cost falls. When the cost rises by Δ, the move is accepted with probability e^{−Δ/T}. The temperature T decreases on a schedule. High T accepts uphill moves and crosses barriers. Low T behaves like greedy local search. The method is a heuristic. A finite schedule does not promise the global minimum.
What the problem actually asks
Greedy local search stops at the first local minimum. A cost surface with barriers needs a way back out. The Metropolis rule accepts a worse move with a probability that depends on how much worse it is and on the temperature. Slow cooling is the analogy with physical annealing, where a crystal reaches a low-energy state if cooled slowly enough.
The theory that an infinitely slow logarithmic schedule reaches the global minimum is real and useless as a clock. Practical schedules are geometric, T ← αT with α close to 1, and they are heuristics. The algorithm’s value is the uphill probability, not a certificate.
What the algorithm guarantees
Each fixed temperature is a Metropolis chain on the state graph. If every state is reachable and the chain is run long enough, its stationary distribution prefers low costs, with the preference sharpening as T falls. A practical run uses a finite number of proposals per temperature and a geometric schedule, and it returns the best state seen, not a certified optimum. Extra memory is the current state and the best state.
The proposal distribution is part of the algorithm. A proposal that never changes a critical coordinate cannot repair it. The acceptance test uses the cost difference of that proposal, not a global ranking.
The working steps
- Start at a feasible state and a high temperature. Record the best state seen.
- Propose a neighbor. If its cost is lower, accept it. If its cost is higher by Δ, accept it with probability e^{−Δ/T}.
- Repeat a budget of proposals at this temperature, always updating the best-so-far when a new low cost appears.
- Cool, typically by multiplying T by a factor slightly below 1. Stop when T is tiny or the best cost has stalled.
- Return the best state seen, which may not be the final state. The chain at low T can sit above the best earlier discovery.
A finite geometric schedule is a heuristic. The logarithmic schedule’s convergence theorem is not a description of that geometric schedule. Greedy search is the T = 0 limit. Metropolis-Hastings is the Markov-chain theory behind the acceptance rule, used in sampling as well as in optimization.
Approaches that look simpler and fail
| Approach | Why it fails when an uphill move is never accepted |
|---|---|
| Accept only improvements | The temperature never acts. The search is greedy local search and stops in the first basin. |
| Cool so fast that T is tiny before the state has moved | The chain has not mixed at high temperature. Later uphill moves are rejected and the start is frozen in place. |
| Return the final state rather than the best seen | The last state is a sample from a cold chain, not a record of the lowest cost the run encountered. |
| Cite the logarithmic-schedule theorem for a geometric schedule | The theorem’s cooling is far slower than any geometric schedule used in practice. The practical run is a heuristic. |
Sampling from a distribution, rather than hunting a minimum, is Metropolis-Hastings with a fixed temperature. Greedy improvement is local search. Simulated annealing is the cooling Metropolis search.
A working example
This Python fragment accepts an uphill move with probability e^{−Δ/T} and cools the temperature. The state is a permutation and the cost is the length of a tiny tour. It prints the best length seen, 4.
import math, random
cities = [(0, 0), (1, 0), (1, 1), (0, 1)]
def length(order):
total = 0
for a, b in zip(order, order[1:] + order[:1]):
dx = cities[a][0] - cities[b][0]
dy = cities[a][1] - cities[b][1]
total += abs(dx) + abs(dy)
return total
rng = random.Random(0)
state = [0, 1, 2, 3]
cur = best = length(state)
temp = 2.0
for _ in range(200):
i, j = sorted(rng.sample(range(4), 2))
trial = state[:]
trial[i:j + 1] = reversed(trial[i:j + 1])
nxt = length(trial)
if nxt <= cur or rng.random() < math.exp(-(nxt - cur) / temp):
state, cur = trial, nxt
best = min(best, cur)
temp *= 0.97
assert best == 4
print(best)
Where it is used
TimberWolf and later chip placers used simulated annealing for VLSI placement, and the same cooling loop is a traveling-salesman heuristic. The temperature is what allows an uphill move. A pure greedy placement freezes into the first local minimum.
When you can drop this algorithm
Drop annealing when the landscape is convex or a local move already has a proof. Use the exact method. Keep annealing as a heuristic on a combinatorial landscape full of local minima, and return the best state seen.
Why this stays published
We publish this so a search for simulated annealing returns the Metropolis acceptance probability and the warning that a practical schedule is a heuristic. Simulated annealing accepts an uphill move of size Δ with probability e to the minus Δ over T, and a finite cooling schedule is a heuristic rather than a global-minimum proof.
本文由 HoHo 與 AI 協作整理,最後更新於 2026 年 11 月 13 日。
