Skip to content

Simulated Annealing

Classical

Simulated Annealing (SA) metaheuristic optimization algorithm.

Algorithm Overview

This module provides an implementation of the Simulated Annealing optimization algorithm. Simulated Annealing is a metaheuristic optimization algorithm that is inspired by the annealing process in metallurgy. It is used to find the global minimum of a given objective function in a search space.

Usage

python
from opt.classical.simulated_annealing import SimulatedAnnealing
from opt.benchmark.functions import sphere

optimizer = SimulatedAnnealing(
    func=sphere,
    lower_bound=-5.12,
    upper_bound=5.12,
    dim=10,
    max_iter=500,
    population_size=50,
)

best_solution, best_fitness = optimizer.search()
print(f"Best solution: {best_solution}")
print(f"Best fitness: {best_fitness:.6e}")

Parameters

ParameterTypeDefaultDescription
funcCallableRequiredObjective function to minimize.
lower_boundfloatRequiredLower bound of search space.
upper_boundfloatRequiredUpper bound of search space.
dimintRequiredProblem dimensionality.
population_sizeint100Number of independent runs.
max_iterint1000Maximum iterations per run.
init_temperaturefloat1000Initial temperature.
stopping_temperaturefloat1e-08Temperature stopping criterion.
cooling_ratefloat0.99Geometric cooling factor (0<α<1).

Algorithm Metadata

PropertyValue
Algorithm NameSimulated Annealing
AcronymSA
Year Introduced1983
AuthorsKirkpatrick, Scott; Gelatt, C. Daniel; Vecchi, Mario
Algorithm ClassClassical
ComplexityO(iterations×evaluations)
PropertiesDerivative-free, Stochastic
ImplementationPython 3.10+
COCO CompatibleYes

Mathematical Formulation

Acceptance probability (Metropolis criterion):

P(accept)={1if ΔE<0eΔE/Tif ΔE0

where:

  • ΔE=E(xnew)E(xcurrent) is energy (fitness) change
  • T is the current temperature
  • Cooling schedule: Tk+1=αTk (geometric cooling)

Constraint handling:

  • Boundary conditions: Clamping to bounds
  • Feasibility enforcement: Reject out-of-bounds solutions

Hyperparameters

ParameterDefaultBBOB RecommendedDescription
init_temperature100.010-1000Initial temperature
stopping_temperature1e-81e-10Stopping criterion
cooling_rate0.990.95-0.999Temperature reduction factor
max_iter100010000Maximum iterations per run
population_size10010-50Number of restarts

Sensitivity Analysis:

  • cooling_rate: High impact (slower=better exploration, faster=faster convergence)
  • init_temperature: Medium impact on early exploration
  • Recommended: α[0.95,0.999], T0[10,1000]

COCO/BBOB Benchmark Settings

Search Space:

  • Dimensions tested: 2, 3, 5, 10, 20, 40
  • Bounds: Function-specific (typically [-5, 5] or [-100, 100])
  • Instances: 15 per function (BBOB standard)

Evaluation Budget:

  • Budget: dim×10000 function evaluations
  • Independent runs: 15 (for statistical significance)
  • Seeds: 0-14 (reproducibility requirement)

Performance Metrics:

  • Target precision: 1e-8 (BBOB default)
  • Success rate at precision thresholds: [1e-8, 1e-6, 1e-4, 1e-2]
  • Expected Running Time (ERT) tracking

Raises

ValueError: If search space is invalid or function evaluation fails.

Notes

  • Modifies self.history if track_history=True
  • Uses self.seed for all random number generation
  • BBOB: Returns final best solution after max_iter or convergence

Computational Complexity:

  • Time per iteration: O(1) per proposal
  • Space complexity: O(n)
  • BBOB budget usage: 30-70% of dim×10000

BBOB Performance Characteristics:

  • Best function classes: Multimodal, Rugged landscapes
  • Weak function classes: Highly smooth (slower than gradient methods)
  • Success rate at 1e-8: 40-70% (dim=5, multimodal)

Convergence Properties:

  • Convergence rate: Probabilistic, depends on cooling schedule
  • Local vs Global: Can escape local optima (probabilistic acceptance)
  • Premature convergence risk: Low (if cooling slow enough)

Reproducibility:

  • Deterministic: Yes (given same seed)
  • BBOB compliance: seed required for 15 runs
  • RNG: numpy.random.default_rng(self.seed)

Known Limitations:

  • Cooling schedule critical to performance
  • Slow convergence compared to gradient methods on smooth functions
  • No convergence guarantees for arbitrary schedules

Version History:

  • v0.1.0: Initial implementation
  • v0.1.2: COCO/BBOB compliance

References

[1] Kirkpatrick, S., Gelatt, C. D., & Vecchi, M. P. (1983). "Optimization by simulated annealing." Science, 220(4598), 671-680. https://doi.org/10.1126/science.220.4598.671

[2] Metropolis, N., et al. (1953). "Equation of state calculations by fast computing machines." The Journal of Chemical Physics, 21(6), 1087-1092. https://doi.org/10.1063/1.1699114

[3] Hansen, N., Auger, A., et al. (2021). "COCO: A platform for comparing continuous optimizers." Optimization Methods and Software, 36(1), 114-144. https://doi.org/10.1080/10556788.2020.1808977

COCO Data Archive:

See Also

HillClimbing: Greedy local search without probabilistic acceptance BBOB Comparison: SA better on multimodal, HC faster on unimodal TabuSearch: Memory-based metaheuristic BBOB Comparison: Both escape local optima, different mechanisms

Benchmark Performance

Interactive fitness landscape of a representative multimodal benchmark function (drag to rotate, scroll to zoom):

Convergence, final-fitness distribution and performance profile on rastrigin (5D), averaged over independent runs (compared against representative baselines):


Source Code

View the implementation: simulated_annealing.py

Released under the MIT License.