What Is Simulated Annealing and How Does It Work?

Simulated annealing is an optimization algorithm that finds good solutions to complex problems by mimicking the way metals cool and form stable crystal structures. Introduced in 1983 by Kirkpatrick, Gelatt, and Vecchi, the method borrows its central idea from metallurgy: if you heat a metal and then cool it very slowly, its atoms settle into a low-energy, well-ordered state, but if you cool it too fast, you get a brittle, defect-ridden mess.1Applied Soft Computing. An improved Simulated Annealing algorithm based on ancient metallurgy techniques The algorithm applies that same principle to search for optimal solutions in enormous problem spaces, and its willingness to temporarily accept worse answers is what makes it powerful.

The Metallurgy Analogy

To understand why the algorithm works, it helps to picture what happens inside a piece of metal being annealed. When a blacksmith heats steel to a high temperature, the atoms become energetic and mobile, bouncing around freely. As the metal cools slowly, those atoms gradually settle into an orderly crystalline lattice, which is a low-energy, stable configuration. The controlled cooling gives the atoms enough time and freedom to find the best arrangement, avoiding the trap of freezing into a disordered pattern full of defects.

Simulated annealing translates this physical process into a computational one. The “temperature” becomes a numerical parameter that controls how willing the algorithm is to explore. The “energy” of the metal becomes the cost or objective function you are trying to minimize. And the atomic rearrangements become candidate solutions the algorithm considers at each step. Just as slow cooling produces a better crystal, a gradual reduction in the algorithm’s temperature tends to produce a better solution.

How the Algorithm Works Step by Step

The process starts with a random solution to whatever problem you are trying to solve. It could be a random route through a set of cities, a random arrangement of components on a circuit board, or a random configuration of molecules. This initial solution almost certainly is not very good, and that is fine.

At each step, the algorithm makes a small random change to the current solution, producing a “neighbor” solution. It then compares the new solution to the current one. If the neighbor is better (lower cost), the algorithm accepts it immediately and moves on. Here is where things get interesting: if the neighbor is worse, the algorithm does not automatically reject it. Instead, it accepts the worse solution with a certain probability that depends on two things: how much worse the new solution is and how high the current temperature is.

Early in the process, when the temperature is high, the algorithm accepts worse solutions fairly often. This lets it wander broadly through the solution space, hopping over barriers between different regions. As the temperature drops, the algorithm becomes increasingly picky, accepting worse moves less and less frequently. By the end, it behaves almost like a pure downhill optimizer, refining the best solution it has found. The algorithm stops when the temperature falls below some minimum threshold or when a set number of steps have been completed.2Cornell University Computational Optimization Open Textbook. Simulated annealing

Why Accepting Worse Solutions Matters

The defining feature of simulated annealing, and the reason it outperforms simpler approaches on many problems, is that willingness to go uphill. Imagine you are blindfolded in a hilly landscape and your goal is to reach the lowest valley. A naive strategy would be to always walk downhill. The problem is that you will end up at the bottom of whichever valley you happen to start in, even if a much deeper valley sits just on the other side of a ridge. You would be stuck in what optimization researchers call a local minimum.

Simulated annealing escapes local minima by occasionally climbing those ridges, especially early in the search. The high initial temperature means the algorithm is willing to tolerate a significant cost increase, exploring distant parts of the solution space. As temperature decreases, the algorithm gradually commits to exploiting the most promising region it has found. This balance between exploration and exploitation is central to the method’s success.3Hindawi / Advances in Operations Research. Multiobjective Simulated Annealing: Principles and Algorithm Variants

The acceptance probability is typically governed by the Metropolis criterion, which comes directly from statistical physics. In plain terms, the rule says: a small worsening is much more likely to be accepted than a large worsening, and any worsening is more likely to be accepted when the temperature is high. This mirrors real physical systems, where at higher temperatures atoms are more likely to jump to higher-energy states. The mathematical classification of such acceptance rules has been studied rigorously, and the Metropolis criterion remains the most widely used.4INFORMS. Classification of Acceptance Criteria for the Simulated Annealing Algorithm

The Cooling Schedule

If the temperature drops too fast, the algorithm behaves like quenching hot metal in water: it freezes prematurely into whatever local minimum it happens to be near. If the temperature drops too slowly, the algorithm wastes enormous amounts of computation time wandering aimlessly. Getting the cooling schedule right is one of the most important practical decisions when using simulated annealing.

Several standard cooling strategies exist. A logarithmic schedule, where temperature decreases proportionally to the inverse of the logarithm of elapsed time, has been mathematically proven to guarantee finding the global optimum for certain problems. The catch is that it is extraordinarily slow, requiring impractical amounts of computation for most real-world use. In practice, most implementations use either a linear schedule, which subtracts a fixed amount from the temperature at each step, or a geometric (exponential) schedule, which multiplies the temperature by a factor slightly less than one at each step.5Physica A: Statistical Mechanics and its Applications. Investigation of acceptance simulated annealing — A simplified approach to adaptive cooling schedules The geometric schedule is the most common choice in practice, offering a reasonable trade-off between solution quality and computation time.2Cornell University Computational Optimization Open Textbook. Simulated annealing

Choosing the cooling rate is not the only decision. You also need to set the starting temperature high enough that the algorithm initially accepts most moves, and a stopping temperature low enough that the algorithm has time to refine its answer. The number of iterations spent at each temperature level matters too, since spending more time at each step gives the algorithm more chances to explore the neighborhood before cooling further. These interacting parameters can be tricky to tune, which has motivated several adaptive approaches that adjust the schedule on the fly.

Adaptive and Variant Approaches

Researchers have developed many variations on the basic algorithm to address the difficulty of choosing a good cooling schedule. One notable approach is thermodynamic simulated annealing, where the temperature is not forced to follow a predetermined curve at all. Instead, it evolves freely, updated continuously based on changes in internal state functions like energy and entropy. This lets the algorithm adapt its own exploration aggressiveness to the problem landscape it encounters, achieving high-quality results while removing the need to hand-tune a schedule.6Physics Letters A. Placement by thermodynamic simulated annealing

Another variant, fast simulated annealing, replaces the typical Gaussian random step with a Cauchy probability distribution for generating candidate solutions. The heavier tails of the Cauchy distribution allow the algorithm to occasionally make very large jumps in the solution space, which can speed up the search considerably on certain problems.7Physics Letters A. Fast simulated annealing Yet another approach, list-based simulated annealing, replaces the temperature parameter entirely with a list of threshold values, simplifying parameter setting while maintaining competitive performance on well-known benchmark problems.8PubMed Central. List-Based Simulated Annealing Algorithm for Traveling Salesman Problem

These variants share a common motivation: the vanilla algorithm’s performance depends heavily on its parameter settings, and finding good settings often requires trial and error. Any technique that makes the algorithm more self-tuning is a practical win.

Where Simulated Annealing Gets Used

The traveling salesman problem, which asks for the shortest route visiting a set of cities exactly once, is probably the most famous test case for simulated annealing. This problem is a classic example of a combinatorial optimization challenge: the number of possible routes grows explosively with the number of cities, making it impossible to check every option. Simulated annealing handles it well because the landscape of possible routes is full of local minima, and the algorithm’s hill-climbing ability lets it escape mediocre routes and find substantially shorter ones.8PubMed Central. List-Based Simulated Annealing Algorithm for Traveling Salesman Problem

In structural biology, simulated annealing has been used for molecular docking, the problem of figuring out how two molecules fit together. The algorithm searches for the best relative position and orientation of interacting molecules by optimizing a cost function based on geometric constraints.9PubMed. Distance-constrained molecular docking by simulated annealing This application highlights how versatile the method is: it does not care about the specific nature of the problem, only that you can define a solution, a way to modify it, and a way to score it.

That generality is one of simulated annealing’s biggest strengths. The method has been applied to VLSI circuit design, job scheduling, image processing, financial portfolio optimization, and resource allocation. If you can phrase your problem as “find the configuration that minimizes (or maximizes) some score,” simulated annealing is a candidate solver.

Combining Simulated Annealing with Other Methods

Despite its strengths, simulated annealing is a single-solution method: it tracks one candidate solution at a time. Genetic algorithms, by contrast, maintain a population of solutions and evolve them in parallel through selection and recombination, which gives them strong global exploration but sometimes weaker local refinement. Researchers have found that combining the two approaches can get the best of both worlds.

In a typical hybrid, the genetic algorithm handles the broad search, evolving a diverse population of candidate solutions. Simulated annealing then refines the most promising candidates, using its local search ability to polish solutions that the genetic algorithm identified as high-potential. The SA component is particularly good at escaping local optima that the genetic algorithm’s population might otherwise get stuck in.10Scientific Reports. Hybrid genetic algorithm-simulated annealing based electric vehicle charging station placement for optimizing distribution network resilience This kind of hybrid has been applied to problems like finding optimal locations for electric vehicle charging stations in power distribution networks and solving facility location problems in logistics.11Computer and Decision Making: An International Journal. A Hybrid Genetic Algorithm and Simulated Annealing Approach for the Uncapacitated Facility Location Problem

These hybrids reflect a broader trend in optimization research: rather than treating algorithms as competitors, researchers increasingly combine them, assigning each method to the part of the search it does best. Simulated annealing’s role in many modern hybrid systems is as a fine-tuning local optimizer layered on top of a global search framework.

Energy Landscapes and Why Some Problems Are Harder

One useful way to think about optimization problems is through the concept of an energy landscape. Imagine the solution space as a three-dimensional terrain, where the height at any point represents how bad the solution at that point is. A smooth landscape with one deep valley is easy: any downhill method will find the bottom. A rugged landscape with thousands of local valleys of different depths is hard: an optimizer can easily get trapped in a shallow valley while the deepest one sits far away.

The structure of this landscape determines how well simulated annealing performs. When researchers have visualized the energy landscapes of combinatorial optimization problems, they find that the difficulty comes from both energetic barriers (tall ridges separating good solutions) and entropic barriers (vast flat regions where many mediocre solutions cluster). Problems with many deep, well-separated local minima and high barriers between them are genuinely hard for any optimizer, simulated annealing included.12PubMed. Energy landscapes of combinatorial optimization in Ising machines

This landscape perspective also explains why the cooling schedule matters so much. A landscape with a few broad valleys and gentle ridges can tolerate a fast cooling schedule, since the algorithm does not need much hill-climbing ability to find the deepest valley. A landscape full of narrow, jagged peaks requires a much slower schedule, giving the algorithm time to explore widely before committing. In practice, you rarely know the landscape’s shape in advance, which is why tuning these parameters often involves experimentation.

Common Misconceptions

One widespread misunderstanding is that simulated annealing guarantees finding the best possible solution. It does not, at least not in any practical sense. The logarithmic cooling schedule can guarantee convergence to the global optimum in theory, but the required computation time is so enormous that the guarantee is essentially mathematical rather than practical. In real use, simulated annealing finds very good solutions, often near-optimal ones, but there is no practical way to confirm whether the result is truly the best.

Another misconception is that simulated annealing is outdated, having been introduced over 40 years ago. While newer metaheuristics like particle swarm optimization and differential evolution have joined the toolkit, simulated annealing remains actively used and researched. Its simplicity, its theoretical grounding in statistical physics, and its effectiveness as a local search component in hybrid systems keep it relevant. The algorithm is also remarkably easy to implement: the core loop can be written in a few dozen lines of code in most programming languages, making it an accessible first tool for anyone facing a hard optimization problem.

A third misconception is that simulated annealing works the same way on every problem and just needs more time for harder ones. In reality, the way you define the neighborhood (how you generate candidate solutions from the current one) matters enormously and is problem-specific. For the traveling salesman problem, a good neighborhood operation might swap two cities in the tour. For a scheduling problem, it might move one task to a different time slot. Choosing the wrong neighborhood structure can cripple the algorithm regardless of how carefully you tune the temperature. The algorithm is general-purpose in concept, but getting good results requires thoughtful problem-specific design.

When Simulated Annealing Is and Is Not the Right Choice

Simulated annealing shines on problems where the solution space is large, riddled with local minima, and difficult to exploit with gradient-based methods. If your problem has a smooth, well-behaved objective function and you can compute derivatives, you are usually better off with gradient descent or one of its modern variants. Simulated annealing is designed for the messy cases: combinatorial problems, discrete decision spaces, objective functions that are noisy or discontinuous, and situations where you cannot easily compute a gradient.

It is also a strong choice when you need a decent solution quickly and cannot afford the time to run a population-based method. Because it maintains only one solution at a time, its memory footprint is minimal, and it can start producing improving solutions almost immediately. For very large problems where even storing a population of solutions is expensive, simulated annealing’s single-solution approach is a practical advantage.

On the other hand, simulated annealing can struggle with problems that have highly constrained feasible regions, since random perturbations frequently produce infeasible solutions that must be repaired or penalized. Problems with multiple competing objectives also pose challenges for the basic algorithm, though multiobjective variants that maintain an archive of non-dominated solutions have been developed to handle these cases.3Hindawi / Advances in Operations Research. Multiobjective Simulated Annealing: Principles and Algorithm Variants And for problems where you need a verified optimal solution rather than a probably-good one, exact methods like integer programming are more appropriate, assuming the problem is small enough for them to finish in reasonable time.