Planning & Search in Rust
Esc

Loading…

↑↓ move ↵ open Esc close
Colour theme
All algorithms

Simulated annealing

Also known as SA

optimization planning-qubo

Simulated annealing looks for a low-energy assignment of a QUBO model by flipping one bit at a time. It starts from uniform random bits; each sweep visits every variable once, in index order, and the Metropolis rule accepts a flip that does not raise the energy, and a rise Δ with probability exp(−β·Δ). The inverse temperature β grows geometrically from a hot to a cold value over the sweeps: either given, or derived from the model so that the largest possible flip is accepted half the time at the start and the smallest nonzero coefficient once in a hundred times at the end. It returns the lowest-energy assignment it visited, not the last one, and a budget of flip attempts can pause a run that later resumes with the same result. It gives no optimality guarantee; use it when a model has too many variables to enumerate and a good assignment is enough.

Pseudocode

algorithm Simulated-Annealing(Q, S, budget)input: QUBO model Q over n variables, S sweeps, an optional range β-hot to β-coldinput: budget of flip attemptsoutput: the lowest-energy assignment visited, with its energyx ← n uniform random bitsE ← energy(Q, x)best, E-best ← x, Eif no β range is given thenβ-hot ← ln 2 / max over i of (|aᵢ| + Σⱼ |bᵢⱼ|)    ▷ the largest flip is accepted with probability ½β-cold ← ln 100 / smallest nonzero coefficient magnitude    ▷ the smallest with probability 1/100for t in 0, …, S − 1 doif S = 1 thenβ ← β-cold                                     ▷ a single sweep runs coldelseβ ← β-hot · (β-cold / β-hot)^(t / (S − 1))     ▷ geometricfor i in 0, …, n − 1 do                          ▷ index orderif exhausted(budget) thenreturn best, E-best                          ▷ resume continues at this variable, sweep and RNG stateΔ ← flip-delta(Q, x, i)if Δ ≤ 0 or uniform(0, 1) < exp(−β · Δ) then   ▷ Metropolis rulex[i] ← ¬x[i]E ← E + Δif E < E-best thenbest, E-best ← x, Ereturn best, E-best

In the crates

Lineage

Comes from

builds on Metropolis algorithm

Led to

Nothing on this site.

Papers

  1. Optimization by Simulated Annealing S. Kirkpatrick, C. D. Gelatt, M. P. Vecchi · 1983· Science introduces doi 10.1126/science.220.4598.671