Skip to content
CoreSource checked

Simulated Annealing

Searches for good solutions while sometimes accepting worse moves early on.

Quick Facts

Compact metadata for implementation and discovery.

Category
Optimization
Difficulty
Intermediate
Family
Metaheuristic
Tier
Core
Status
Verified
Review
Source Checked
Sources
1
Formulas
1
Relationships
5
Code example
Not ready
Visualization
Ready

Overview

Simulated Annealing explores candidate solutions using a temperature value that gradually lowers the chance of accepting worse states.

Core Concepts

objective functionmetaheuristic searchrandom samplingneighbor movemetaheuristiciterative improvementstopping rule

Quick facts

Complexity

Runtime and memory behavior at a glance.

Best

O(t)

Average

O(t)

Worst

O(t)

Space

O(1)

When to Use

  • Use Simulated Annealing when you need to explore nearby candidate solutions.
  • Use it for hard combinatorial optimization with inputs like initial solution.
  • Use it when you can define a score, objective, constraint, or feasibility test clearly.
  • Use it when the Metaheuristic tradeoff is acceptable for the problem size.

When Not to Use

  • Avoid it when repeatability is required but seeds and random sources are not controlled.
  • Avoid it when the objective is noisy or changing and the algorithm assumes stable feedback.
  • Avoid it when the required output is not best solution found.

What It Does

  • Explores nearby candidate solutions
  • Escapes local traps with random worse moves

Use Cases

  • Hard combinatorial optimization
  • Layout optimization
  • Approximate route planning

Inputs

  • Initial solution
  • Neighbor generator
  • Temperature schedule

Outputs

  • Best solution found

Key Formulas (1)

Acceptance probability

p = exp(−(newcost − oldcost) / temperature)
p = exp(-(new_cost - old_cost) / temperature)

Allows worse moves early in the search and becomes stricter as temperature cools.

Pseudocode

  1. 1.Start with an initial solution
  2. 2.Create a nearby candidate solution
  3. 3.Accept the candidate if it improves the score
  4. 4.Sometimes accept a worse candidate based on temperature
  5. 5.Lower the temperature and repeat

Canonical Example

Input
objective = minimize (x - 3)^2, start = x = 0
Output
x moves toward 3
Explanation
Simulated Annealing: The algorithm repeatedly improves a candidate solution according to the objective.

Implementation Notes

  • Keep the input contract explicit: Initial solution; Neighbor generator; Temperature schedule.
  • Use this step as the implementation spine: Start with an initial solution.
  • Then preserve the next state change: Create a nearby candidate solution.
  • Thread a seedable random source through the implementation for repeatable tests.
  • Log objective values across iterations so regressions and stalled progress are visible.

Common Pitfalls

  • The cooling schedule has a large effect on result quality.
  • Stopping after one good-looking result without checking convergence or constraints.
  • Returning best solution found without handling empty, invalid, or boundary inputs.

Interactive Mechanism Walkthrough

Indexed Interval & Boundary Probe

Show a search path accepting fewer uphill moves as temperature falls.

Target key: 41low=0, mid=4, high=9
4[0]
9[1]
15[2]
22[3]
27[4]
34[5]
41[6]
49[7]
58[8]
63[9]
Step 1 of 5: Start with an initial solution
temperature-search

Notes

Simulated Annealing operates in O(t) time and O(1) space within the Metaheuristic family. Key governing relation: p = exp(-(new_cost - old_cost) / temperature). Often compared with Genetic Algorithm and Gradient Descent.

Sources (1)

What each reference supports for this entry.

Kirkpatrick, Gelatt, and Vecchi 1983

Paper

Foundational simulated annealing paper connecting optimization to annealing schedules.

Open source

Explore Next

Good next jumps from the relationship graph, ranked for useful discovery.

Alternative toGenetic Algorithm

Both search difficult spaces without requiring gradients.

Improves onHill Climbing

Simulated annealing allows occasional worse moves to escape local optima.

Tags

OptimizationMetaheuristicStochasticLocal Search