Simulated Annealing (SA): Working Mechanism and Worked Example
Simulated Annealing Simulated annealing (SA) is a stochastic optimization method inspired by annealing in metallurgy. In each iteration, SA perturbs the current candidate solution to generate a neighboring state; if the new state is better (lower “energy” / objective value), it is accepted. If it is worse, SA may still accept it with probability that depends on the current temperature and the objective increase . This allows SA to escape local minima early, while later it becomes greedier as decreases according to a cooling schedule. The method is built around the Metropolis-style acceptance rule and a temperature update rule with .2
Key concepts (used throughout):
- Temperature parameter
- Neighboring solution generation
- [Cooling schedule]{def="Rule that decreases temperature over time (e.g., geometric)}}
- Metropolis criterion
Footnotes
-
Simulated annealing - Cornell University Computational Optimization Open Textbook - Provides SA pseudocode, , and acceptance probability plus geometric cooling discussion. ↩
-
Chapter 2 - Temperature and Cooling Schedules | Algorithm Afternoon - Explains Metropolis acceptance probability and temperature effect with numeric example. ↩
Simulated Annealing Explained (Metropolis criterion & cooling)
Core working loop of simulated annealing
A standard SA loop can be described as:
- Initialize: pick an initial solution and a high initial temperature .
- Neighbor generation: from the current solution , generate a neighbor (a small random modification).
- Evaluate objective/energy: compute
- Accept/reject:
- If , accept (the neighbor improves the objective).
- If , accept with probability
- Cool down: reduce temperature, commonly using geometric cooling
- Stop: when temperature is low enough () or after a max number of iterations.
This matches commonly cited pseudocode and temperature/acceptance rules.3
Footnotes
-
Simulated annealing - Cornell University Computational Optimization Open Textbook - Provides SA pseudocode, , and acceptance probability plus geometric cooling discussion. ↩
-
Chapter 2 - Temperature and Cooling Schedules | Algorithm Afternoon - Explains Metropolis acceptance probability and temperature effect with numeric example. ↩
-
LAB 8 – SIMULATED ANNEALING (Tufts University PDF) - Describes geometric vs linear cooling and guidance on initial temperature and cooling rate. ↩
Simulated Annealing: step-by-step procedure
- 1Step 1
Define to minimize. Specify how a solution is represented (e.g., a permutation for TSP) and how neighbors are generated.
- 2Step 2
Set initial solution and initial temperature (high enough to allow frequent acceptance of worse moves early).
- 3Step 3
Sample a neighbor using a small perturbation of the current solution.
- 4Step 4
Compute . If , the move improves the objective.
- 5Step 5
If , accept. Otherwise accept with probability , i.e., ; accept if a uniform random draw is below .
- 6Step 6
Update temperature using a cooling schedule such as geometric cooling with .
- 7Step 7
Optionally store the best solution encountered. Stop when or after a maximum iteration budget.
Why the acceptance probability depends on
At high temperature, the factor becomes closer to 1, so SA is more likely to accept worse moves—behaving more like a random walk that can cross barriers between basins of attraction.2 As decreases, the probability of accepting worse moves drops, so SA transitions from exploration to exploitation (local refinement).
Interpretation by cases (for ):
- If is small, is relatively large, so slight worsenings are tolerated.
- If is large, the probability becomes tiny.
- If is high, worsenings are frequently accepted early.
- If is low, worsenings are rarely accepted, making the algorithm increasingly greedy.2
Footnotes
-
Chapter 2 - Temperature and Cooling Schedules | Algorithm Afternoon - Explains Metropolis acceptance probability and temperature effect with numeric example. ↩ ↩2
-
LAB 8 – SIMULATED ANNEALING (Tufts University PDF) - Describes geometric vs linear cooling and guidance on initial temperature and cooling rate. ↩
-
Simulated Annealing: How the Algorithm Works (beon.tech) - Highlights exploration vs exploitation via temperature and the role of . ↩
-
Simulated Annealing - GeeksforGeeks - Summarizes acceptance of worse solutions using . ↩
Cooling schedules and practical tuning
A geometric cooling schedule is frequently described as: or equivalently .2 Lab/teaching references often recommend:
- start with a temperature high enough to “melt” the system (high probability of accepting bad moves),
- reduce temperature gradually, especially near the “freezing point,”
- recognize that finding a good schedule may require experimentation.
Common alternatives (mentioned in educational references) include linear and logarithmic schedules, each affecting exploration/exploitation balance differently.2
Footnotes
-
LAB 8 – SIMULATED ANNEALING (Tufts University PDF) - Describes geometric vs linear cooling and guidance on initial temperature and cooling rate. ↩ ↩2 ↩3
-
Rafael E. Banchs - Simulated Annealing (PDF) - Presents common cooling schedule forms including logarithmic and geometric and discusses typical behavior. ↩
-
ENAC - HAL (Simulated annealing: From basics to applications) - Discusses schedule choices and stopping conditions in SA applications. ↩
Worked example: Simulated annealing for the Traveling Salesman Problem (TSP)
We will use the SA mechanism on a small TSP instance to show the working decisions.
Setup
Let the objective be the total tour length (distance traveled). In TSP, a state is a permutation of cities. A typical neighbor move is swap two cities in the tour.
This is consistent with descriptions of SA applied to TSP:
- start with an initial route,
- propose a neighbor by swapping two cities,
- accept improvements and probabilistically accept worsenings based on temperature,
- gradually decrease temperature and track the best tour seen so far.
Mini numerical walk-through
Assume at some iteration:
- Current tour length:
- Proposed neighbor length:
- So (worse move)
- Acceptance probability:
Case 1: High temperature
So SA is very likely to accept this worse route early, supporting exploration.
Case 2: Lower temperature
So the same worse move is much less likely to be accepted late in the run, supporting convergence.
Full iteration view (conceptual)
At each SA step for TSP:
- pick a neighbor by swapping two cities in the current permutation,
- compute the new tour length,
- if it’s shorter, accept; if longer, accept with probability ,
- cool .
In a TSP-specific explanation, SA’s neighbor generation via swapping and the probabilistic acceptance rule (Metropolis criterion) are explicitly described.2
Footnotes
-
Simulated annealing - Wikipedia - Describes SA as a random walk over states and TSP neighbor generation via swapping cities. ↩ ↩2
-
Simulated Annealing : Methods and Real-World Applications – OMSCS 7641 (Georgia Tech) - Explains SA applied to TSP: initial route, swapping two cities, probabilistic acceptance, and tracking best solution. ↩ ↩2
-
Chapter 2 - Temperature and Cooling Schedules | Algorithm Afternoon - Explains Metropolis acceptance probability and temperature effect with numeric example. ↩ ↩2
Acceptance probability for a worse move () at different temperatures
Illustrates how decreasing T reduces acceptance of worsening neighbors: .
Pro Tip
When implementing SA, always track the best solution found so far. Even if later iterations accept worse moves, you still retain the best objective value seen during the run (common in SA descriptions and implementations).2
Footnotes
-
Simulated annealing - Cornell University Computational Optimization Open Textbook - Provides SA pseudocode, , and acceptance probability plus geometric cooling discussion. ↩
-
Simulated Annealing : Methods and Real-World Applications – OMSCS 7641 (Georgia Tech) - Explains SA applied to TSP: initial route, swapping two cities, probabilistic acceptance, and tracking best solution. ↩
Warning: Cooling schedule choice affects results
SA’s performance is sensitive to how fast temperature decreases. If you cool too quickly (small / aggressive schedule), SA can “freeze” before it escapes local minima; if you cool too slowly, it may take too long to converge. Educational sources explicitly describe this trade-off and tuning necessity.2
Footnotes
-
LAB 8 – SIMULATED ANNEALING (Tufts University PDF) - Describes geometric vs linear cooling and guidance on initial temperature and cooling rate. ↩
-
Rafael E. Banchs - Simulated Annealing (PDF) - Presents common cooling schedule forms including logarithmic and geometric and discusses typical behavior. ↩
Common edge questions about SA
Simulated Annealing: key terms
Knowledge Check
In simulated annealing, a worse move with objective increase is accepted with probability: