Escaping Local Optima

How local search gets past the first local optimum it reaches. Sideways moves, random restarts and their expected cost, simulated annealing and the logarithmic cooling result of Geman and Geman and of Hajek, tabu search, iterated local search, and populations, compared at equal evaluation budgets on a 100-city TSPLIB instance.

Four methods leave a local optimum while keeping the best state found. Random restarts succeed within $k$ climbs with probability $1 - (1 - p)^k$ and need $1/p$ climbs on average, where $p$ is one climb's success rate; on 8-queens ($p = 0.1402$) that is about 7 climbs and 23 moves. On a finite, connected, weakly reversible neighborhood, simulated annealing reaches a global optimum with probability tending to 1 if and only if $\sum_k e^{-d^*/T_k}$ diverges (Hajek, 1988), so $T_k = c/\log(k + 1)$ needs $c \ge d^*$, the depth of the deepest trap. Sideways moves help only on plateaus. At equal budgets on kroA100 (30 seeded runs, 2-opt), annealing led at 2 million evaluations (median 0.49% above the optimum). At 10 million, iterated local search (0.40%) matched it (0.44%), and restarts and tabu search trailed.

Start a hill climber with the 2-opt neighborhood from a random tour of the 100 cities in the TSPLIB instance kroA100. It stops after about a hundred moves, at a tour roughly 7% longer than the optimum. Nothing in the neighborhood of that tour is shorter. Every way out goes uphill first, through longer tours, and a hill climber never takes such a step. To do better, a search must sometimes accept a worse state, or abandon the current state altogether, and it needs a rule for deciding when.

The methods in this article are different rules of that kind. Each is a rule, layered on top of local search, for leaving a local optimum without losing the best state found. Such general strategies for guiding a heuristic are called metaheuristics, a term Glover (1986) introduced along with tabu search. There are four broad answers for a single search:

  • start again somewhere else (random restarts);
  • accept worse moves at random, less and less often over time (simulated annealing);
  • accept the best available move even when it is worse, and use memory to avoid walking straight back (tabu search);
  • kick the current local optimum just hard enough to leave its basin, and climb again (iterated local search).

A fifth answer, keeping many states at once, leads to evolutionary algorithms.

First we dispose of the cheapest fix, sideways moves, which helps only on plateaus. Then we take the four strategies in turn. Each is worked on a small example where its behavior can be computed exactly: 8-queens for restarts, the one-dimensional example for annealing, and twelve cities for tabu search. Next we race all four on kroA100, every method given the same number of evaluations. Finally we see how a population answers the same question. The article assumes hill climbing, including its plateaus, shoulders, and the one-dimensional example of 61 states.

Sideways moves

The cheapest change helps only on plateaus. A hill climber that accepts only strict improvements stops on a shoulder, a plateau with an uphill exit somewhere along its edge. Accepting sideways moves to neighbors of equal value lets it keep walking until it finds the exit. Hill climbing defines both and shows why the number of consecutive sideways moves must be capped (Russell and Norvig, 2020, §4.1.1).

The 8-queens problem, minimizing the number of pairs of queens that attack each other, shows the size of the effect. In the experiment of hill climbing on 8-queens and the 8-puzzle, 30,000 runs of steepest descent from random placements reached a solution 14.02% of the time. With up to 100 consecutive sideways moves allowed, they reached one 94.28% of the time. The cost was longer climbs:

Setting Mean moves, success Mean moves, failure
No sideways moves 4.09 3.05
Up to 100 sideways moves 19.16 60.68

The same experiment shows that sideways moves need randomness. When ties between equally good neighbors are broken by a fixed rule, the walk across a plateau falls into a loop. The success rate with sideways moves is then only 32.45%.

Sideways moves do nothing for a strict local optimum, where every neighbor is worse. On most problems with real-valued objectives, exact ties are rare. The remaining methods deal with strict local optima.

Random restarts

Random-restart hill climbing runs a hill climber to a local optimum, starts again from a new random state, and keeps the best state found across all climbs. Suppose each climb independently reaches a global optimum with probability $p$. Two questions matter: how likely a budget of $k$ climbs is to succeed, and how many climbs are needed on average.

Here is the idea in one sentence. Each climb is an independent trial with success probability $p$, like a biased coin, so the number of climbs until the first success follows a geometric distribution.

Success within $k$ climbs. The $k$ climbs all fail with probability $(1 - p)^k$, because each fails with probability $1 - p$ independently of the others. At least one succeeds with the complementary probability,

$$P(\text{success within } k \text{ climbs}) = 1 - (1 - p)^k.$$

To succeed with probability at least $c$, set $1 - (1 - p)^k \ge c$, so $(1 - p)^k \le 1 - c$. Then take logarithms. Both sides of $k \ln(1 - p) \le \ln(1 - c)$ are negative, so dividing by $\ln(1 - p)$ reverses the inequality:

$$k \ge \frac{\ln(1 - c)}{\ln(1 - p)}.$$

Expected number of climbs. The first success comes at climb $k$ when the first $k - 1$ climbs fail and the $k$-th succeeds, with probability $(1 - p)^{k-1} p$. This is the geometric distribution, and its mean is

$$\mathbb{E}[\text{climbs}] = \sum_{k=1}^{\infty} k\,(1 - p)^{k-1} p = \frac{1}{p},$$

using $\sum_{k \ge 1} k q^{k-1} = 1/(1 - q)^2$ with $q = 1 - p$. That sum comes from the geometric series. Write $S = \sum_{k \ge 1} k q^{k-1} = 1 + 2q + 3q^2 + \cdots$. Then $qS = q + 2q^2 + \cdots$, and subtracting term by term,

$$S - qS = 1 + q + q^2 + \cdots = \frac{1}{1 - q}, \qquad\text{so}\qquad S = \frac{1}{(1 - q)^2} = \frac{1}{p^2}.$$

The mean is $p \cdot S = p / p^2 = 1/p$.

Of these climbs, on average $1/p - 1 = (1 - p)/p$ fail before the one that succeeds. Let $c_f$ be the average cost in evaluations of a failed climb and $c_s$ that of a successful one. A trial consists of some number $j$ of failed climbs followed by one successful climb. Given $j$, its expected cost is $j\,c_f + c_s$, because each failed climb costs $c_f$ on average whatever the others did. Averaging over $j$, whose mean is $(1 - p)/p$, the expected cost of finding the optimum is

$$\mathbb{E}[\text{cost}] = c_s + \frac{1 - p}{p}\, c_f.$$

Example (sideways moves and restarts on 8-queens). On 8-queens, sideways moves raise the success rate of a single climb from 14% to 94%, but they do not make a solution cheaper to find by restarting. Without sideways moves, $p = 0.1402$, so about $1/0.1402 \approx 7.1$ climbs are needed on average. The expected number of moves is $4.09 + (0.8598 / 0.1402) \times 3.05 \approx 22.8$. With sideways moves, $p = 0.9428$, and the expected number of moves is $19.16 + (0.0572 / 0.9428) \times 60.68 \approx 22.8$ as well. The two strategies cost about the same. Sideways moves buy fewer restarts with longer climbs.

The success formula can be checked directly. The 8-queens experiment ran 10,000 restart trials for each setting. Each trial climbed from fresh random boards until one climb succeeded, and recorded how many climbs it took. Without sideways moves:

Climbs $k$ Predicted $1 - (1 - 0.1402)^k$ Measured share of trials solved within $k$
1 0.1402 0.1385
2 0.2607 0.2523
5 0.5301 0.5322
10 0.7792 0.7753
20 0.9513 0.9515
30 0.9892 0.9890

For 90% confidence the bound asks for $k \ge \ln 0.1 / \ln 0.8598 = 15.2$, so 16 climbs, and 90.90% of the trials finished within 16. For 99%, it asks for 31, and 99.04% finished within 31. With sideways moves, $p = 0.9428$; a single climb succeeds 94.4% of the time in the trials, and two climbs 99.7%. The agreement is what independence predicts. Each climb starts from a fresh random board and keeps no memory of earlier ones.

Probability that random-restart hill climbing on 8-queens has found a solution within k climbs. Lines: the geometric prediction 1 - (1 - p)^k with the single-climb success rates p measured in the main experiment. Hollow markers: the share of 10,000 restart trials that finished within k climbs. Notice how closely the markers sit on the lines. Without sideways moves the curve rises slowly and passes 90% at 16 climbs; with up to 100 sideways moves it is above 94% after one.
Probability that random-restart hill climbing on 8-queens has found a solution within k climbs. Lines: the geometric prediction 1 - (1 - p)^k with the single-climb success rates p measured in the main experiment. Hollow markers: the share of 10,000 restart trials that finished within k climbs. Notice how closely the markers sit on the lines. Without sideways moves the curve rises slowly and passes 90% at 16 climbs; with up to 100 sideways moves it is above 94% after one.

What sets $p$? It is the fraction of the search space inside the basin of attraction of the global optimum, weighted by how starting states are drawn. On small problems it can be computed exactly. The table below uses the NK fitness landscapes of fitness landscapes, the same random instances, with $N = 16$ loci each interacting with $K$ others. Steepest-ascent hill climbing with one-bit flips was run from every one of the $2^{16} = 65{,}536$ starting strings. A climb of $s$ moves costs $1 + 16(s + 1)$ evaluations: the start, one scan per move, and a final scan that finds no improvement. The script is tools/experiments/evolution/hill_climbing.py in the site repository.

$K$ Local optima $p$ Expected climbs $1/p$ Mean moves per climb Expected evaluations to reach the optimum
0 1 1.0000 1.0 8.0 145
2 64 0.1266 7.9 5.0 772
4 173 0.0352 28.4 4.1 2,337
8 931 0.0079 127.0 2.6 7,512
15 3,813 0.0007 1,337.5 1.6 56,182

On these five instances, as epistasis grows, the basin of the global optimum shrinks, the climbs get shorter, and the number of restarts needed grows quickly. The table is a measurement on one random instance per value of $K$, not a general law. On these small instances restarts are still effective. With $K = 4$, random restarts need about 2,300 evaluations on average. The $(1+1)$ EA in fitness landscapes found the optimum of the same instance in only 10 of 30 runs within 20,000 evaluations.

Restarts become less useful as problems grow. Each climb is an independent sample from the distribution of local optima, so restarts can only find what that distribution puts some weight on. Lourenço, Martin, and Stützle (2003) point out what happens to that distribution on large instances. Empirical studies and general arguments indicate that the costs of local optima found from random starts have a mean a fixed percentage above the optimum. Their distribution also becomes more and more sharply peaked around that mean as the instance grows. Independent sampling then almost never reaches the lower tail, where the good solutions are.

The remaining methods search near good solutions already found, instead of sampling afresh. The first of them steps out of a local optimum by accepting worse moves.

Simulated annealing

Simulated annealing accepts worse moves at random. The probability depends on how much worse a move is and on a parameter, the temperature, that falls during the run.

The method comes from statistical physics. Metropolis, Rosenbluth, Rosenbluth, Teller, and Teller (1953) wanted to estimate the properties of a system of interacting particles. They moved one particle at a time. A move that changed the energy by $\Delta$ was accepted always if $\Delta \le 0$, and otherwise with probability $e^{-\Delta / kT}$. Run long enough at a fixed temperature, this process samples states with the Boltzmann distribution, in which a state of energy $E$ has probability proportional to $e^{-E/kT}$. At low temperature that distribution is concentrated on the lowest-energy states. The same acceptance rule is the symmetric case of the Metropolis–Hastings sampler of Markov Chain Monte Carlo, which proves that it satisfies detailed balance for any target distribution.

Kirkpatrick, Gelatt, and Vecchi (1983) proposed treating the cost of an optimization problem as the energy, and lowering the temperature slowly. The model is a metal annealed by slow cooling to reach a low-energy crystal structure. They applied the method to the partitioning and placement of circuits on computer chips and to the traveling salesman problem. Černý (1985) developed the same idea independently for the traveling salesman problem.

For minimizing a cost $f$, with the constant $k$ absorbed into $T$:

  1. Start from a state $x$ and a temperature $T_0$.
  2. At step $k$, draw a neighbor $y$ of $x$ uniformly at random and compute $\Delta = f(y) - f(x)$.
  3. If $\Delta \le 0$, move to $y$. Otherwise move to $y$ with probability $e^{-\Delta / T_k}$.
  4. Lower the temperature according to the cooling schedule, and repeat until the budget runs out. Keep the best state seen.

At high temperature nearly every move is accepted, and the search is close to a random walk. At low temperature almost no worsening move is accepted, and the search is a first-choice hill climber. The schedule controls the passage between the two. For a move that lengthens a tour by 50, the acceptance probability is $e^{-0.5} = 0.61$ at $T = 100$, $e^{-5} = 0.0067$ at $T = 10$, and $e^{-50} \approx 2 \times 10^{-22}$ at $T = 1$. The same calculation for three sizes of worsening move, rounded to three significant figures:

Increase $\Delta$ $T = 1$ $T = 10$ $T = 100$ $T = 1000$
10 $4.54 \times 10^{-5}$ 0.368 0.905 0.990
50 $1.93 \times 10^{-22}$ 0.00674 0.607 0.951
200 $1.38 \times 10^{-87}$ $2.06 \times 10^{-9}$ 0.135 0.819

Example (the ratio decides). A move that worsens the cost by 50 at $T = 100$ is accepted more often than one that worsens it by 10 at $T = 10$: 0.607 against 0.368. What matters is the ratio $\Delta / T$, which is 0.5 for the first move and 1 for the second.

Two general points follow. First, the temperature has the same units as the cost, and only $\Delta / T$ matters. A move is accepted about half the time when $\Delta \approx 0.69\,T$, since $e^{-0.69} \approx 0.5$. Second, at every temperature, small worsening moves are accepted far more readily than large ones. So annealing climbs out of shallow valleys long before it climbs out of deep ones.

The Metropolis acceptance probability exp(-Δ/T) against temperature (log scale) for moves that worsen the cost by Δ = 10, 50 and 200; the markers are the values in the table. Notice that each curve is the same S shape shifted along the axis: it passes one half at T = Δ / ln 2, so a move ten times larger needs a temperature ten times higher to be accepted equally often.
The Metropolis acceptance probability exp(-Δ/T) against temperature (log scale) for moves that worsen the cost by Δ = 10, 50 and 200; the markers are the values in the table. Notice that each curve is the same S shape shifted along the axis: it passes one half at T = Δ / ln 2, so a move ten times larger needs a temperature ten times higher to be accepted equally often.

What annealing does at a fixed temperature

Before cooling enters, it helps to see what the acceptance rule achieves when $T$ is held fixed. Back to the one-dimensional example of hill climbing: states $x = 0, \ldots, 60$, neighbors $x \pm 1$, and integer heights $f(x)$ from 3 to 21 to be maximized, with the global maximum $f(36) = 21$. Annealing proposes $x - 1$ or $x + 1$ with probability $\tfrac{1}{2}$ each (a proposal off either end is refused). It accepts a rise always, and a fall of $d$ with probability $e^{-d/T}$.

Run long enough at fixed $T$, this process spends a fraction of its time at each state given by the Boltzmann distribution

$$\pi_T(x) = \frac{e^{f(x)/T}}{\sum_{z} e^{f(z)/T}},$$

the maximization version of the $e^{-E/kT}$ of Metropolis and colleagues.

Here is the plan of the argument. Suppose the chain is in the distribution $\pi_T$. If, for every pair of states, the probability of being at $x$ and stepping to $y$ equals the probability of being at $y$ and stepping to $x$, then every state gains exactly as much probability in one step as it loses, so the distribution cannot change. It is enough to check that pairwise balance for neighbors. For two states that are not neighbors both sides are zero.

The formal version. Let $y$ be a neighbor of $x$ with $f(y) < f(x)$.

  • The probability of being at $x$ and moving to $y$ in one step is $\pi_T(x) \cdot \tfrac{1}{2} \cdot e^{-(f(x) - f(y))/T}$.
  • The probability of being at $y$ and moving to $x$ is $\pi_T(y) \cdot \tfrac{1}{2} \cdot 1$, since a rise is always accepted.

Write $Z = \sum_z e^{f(z)/T}$ and substitute $\pi_T$. The first is

$$\frac{e^{f(x)/T}}{Z} \cdot \frac{1}{2} \cdot e^{-(f(x) - f(y))/T} = \frac{1}{2} \cdot \frac{e^{f(y)/T}}{Z},$$

because the exponents add to $f(x)/T - f(x)/T + f(y)/T$. The second is $\tfrac{1}{2} e^{f(y)/T} / Z$ directly. The two are equal. Two neighbors of equal height, as on the shoulder and the flat maximum, balance as well: each move is accepted with probability 1, and $\pi_T(x) = \pi_T(y)$.

Write $P(x, y)$ for the probability of stepping from $x$ to $y$, with $P(y, y)$ the probability of staying at $y$. Equal flow in each direction between every pair of states, $\pi_T(x) P(x, y) = \pi_T(y) P(y, x)$, is the detailed balance condition. Summing it over $x$ gives the probability of being at $y$ after one step:

$$\sum_x \pi_T(x)\, P(x, y) = \sum_x \pi_T(y)\, P(y, x) = \pi_T(y),$$

since the probabilities of leaving $y$ or staying there sum to 1. So $\pi_T$ does not change from one step to the next: it is the chain's stationary distribution.

Convergence to $\pi_T$ from any start needs two more properties. The chain can reach every state from every other (it is irreducible), since every step to a neighbor has positive probability. It can also stay put: at $x = 0$ a proposal off the end is refused with probability $\tfrac{1}{2}$, so $P(0, 0) > 0$. That one state makes the whole chain aperiodic. Any state can go to $0$, stay there for one step or not, and come back, so it can return to itself in two numbers of steps that differ by one. A finite chain with both properties has exactly one stationary distribution and approaches it from any start. That is the standard convergence theorem for Markov chains, which PageRank states and uses; it is cited here, not proved, and Markov Chains and Stationary Distributions proves it (Theorems 3 and 6). The script checks the conclusion on this chain. At $T = 2$, after $2^{20}$ steps the distribution from each of the starts $x = 0$, 8 and 60 agrees with $\pi_T$ to within $10^{-9}$ at every state.

The Boltzmann distribution makes the role of the temperature exact. The higher a state, the more weight it gets, and lowering $T$ sharpens the preference.

Example (six lower states outweigh the top). At $T = 5$, the flat maximum, six states at height 18, holds more probability than the single global maximum at height 21: 0.1907 against 0.0579. At high temperature, six states three units lower outweigh one state at the top. The table shows how cooling reverses that:

Temperature $\pi_T(36)$ $\pi_T(35) + \pi_T(36) + \pi_T(37)$ Flat maximum, $x = 45$ to 50 Local maximum, $x = 8$
5 0.0579 0.1527 0.1907 0.0078
2 0.1630 0.3607 0.2182 0.0011
1 0.3959 0.6872 0.1183 $1.8 \times 10^{-5}$
0.5 0.7526 0.9563 0.0112 $1.6 \times 10^{-9}$

At $T = 0.5$ three quarters of the time is spent at $x = 36$. As $T \to 0$ the distribution concentrates entirely on the global maxima. That is the idea of annealing in one sentence: sample the Boltzmann distribution, and lower the temperature so that it concentrates on the best states.

The catch is time. At low temperature the chain needs a very long time to reach its stationary distribution. Leaving the local maximum at $x = 8$ requires six consecutive downhill steps, each proposed with probability $\tfrac{1}{2}$ and accepted with probability $e^{-1/T}$. That is about $(e^{-1/T}/2)^6$ in all: $7.8 \times 10^{-4}$ at $T = 2$ and $9.6 \times 10^{-8}$ at $T = 0.5$. A schedule has to keep the temperature high long enough for the search to move between basins. It must then lower it slowly enough that the search settles in the right one.

Hill climbing and simulated annealing on the one-dimensional example. Choose a method, then Step or Run. Under annealing, the readout gives the probability of accepting a move to each neighbor at the current temperature, and the blue bars show where the search has spent its time since the last reset or change of temperature; the dashed outline is the Boltzmann distribution it should approach. Notice the difference between temperatures: at T = 2 the search wanders over the whole range; at T = 0.5, started on the left hill, it can stay there for thousands of steps. Switching on cooling lowers T by a factor 0.999 per step. The two hill-climbing modes stop at the first local maximum, or cross the shoulder at x = 20 to 26 when sideways moves are allowed.

Cooling schedules

The remaining choice is how fast the temperature falls. The most common schedule in practice is geometric: $T_{k+1} = \alpha T_k$ for a constant $\alpha$ slightly below 1. The experiment below cools geometrically from $T_0 = 100$ to $T = 1$ over the whole run. For 2 million steps that means $\alpha = 0.01^{1/2{,}000{,}000} \approx 0.9999977$.

The figure below follows one of those runs on kroA100 (seed 0 of the experiment later in this article) through its 2 million steps. It found a tour of length 21,431, 0.70% above the optimum.

One simulated annealing run on kroA100 with geometric cooling from T = 100 to T = 1, summarized every 20,000 steps. Top: the temperature, a straight line on the log scale. Middle: the current tour length (dashed) fluctuates above the best found (solid) while worsening moves are still accepted; notice that the two merge after about 1.2 million steps. Bottom: the share of proposed worsening moves that were accepted falls from 1.3% to zero.
One simulated annealing run on kroA100 with geometric cooling from T = 100 to T = 1, summarized every 20,000 steps. Top: the temperature, a straight line on the log scale. Middle: the current tour length (dashed) fluctuates above the best found (solid) while worsening moves are still accepted; notice that the two merge after about 1.2 million steps. Bottom: the share of proposed worsening moves that were accepted falls from 1.3% to zero.

Three features of this run are worth reading off the plot.

  1. Few worsening moves were accepted, even when hot. With $T$ close to 100, only 1.28% of the proposed worsening moves were accepted. The reason is the size of a typical move. A 2-opt move chosen at random usually joins cities that are far apart. The median increase among the worsening moves proposed in each window was between 2,570 and 2,849. At $T = 100$ an increase of 2,570 is accepted with probability $e^{-25.7} \approx 7 \times 10^{-12}$. So the worsening moves that were accepted were the rare small ones. There were 2,184 of them over the run, with a median increase of 49, nine in ten below 180, and none above 563.
  2. The run finished early. The best tour of the run was found at step 635,286, when $T$ was about 23. The current tour kept moving above it and was back at the same length by about 1.2 million steps. The last accepted worsening move came at step 1,490,922, and after step 1,496,923 the tour never changed again. The final quarter of the budget was spent proposing moves that were all refused.
  3. The useful temperatures are set by the moves that matter. These are increases of tens to a few hundreds here, not the typical proposed move. The temperatures used, from 100 to 1, were chosen in a small pilot, described below. This run shows that they work, and it suggests that for this instance the lowest temperatures add little.

A practical schedule works, but does any schedule come with a guarantee? For finite problems, the question was settled in the 1980s. Geman and Geman (1984) were working on image restoration with a related sampler. They proved convergence to the global minima for schedules of the form

$$T_k = \frac{c}{\log(k + 1)}$$

when the constant $c$ is large enough (log is the natural logarithm). Hajek (1988) found the exact condition.

Here is the idea in one sentence: the search must keep enough heat, for long enough, to climb out of the deepest trap infinitely often. The theorem makes "deepest trap" and "enough" precise.

The formal version. Assume three things:

  • the state space is finite;
  • any state can be reached from any other by a sequence of moves;
  • the neighborhood satisfies weak reversibility: if state $j$ can be reached from state $i$ without passing through any state of cost above $E$, then $i$ can be reached from $j$ in the same way. (A symmetric neighborhood, such as 2-opt, satisfies this.)

Take a local minimum $s$ that is not global. Its depth is the smallest $d > 0$ such that some state of lower cost than $s$ can be reached from $s$ without exceeding cost $f(s) + d$. It is the height of the lowest pass out of its valley. Let $d^*$ be the largest depth of any local minimum that is not global, and suppose $T_k$ is nonincreasing and tends to 0. Hajek's Theorem 1 concerns the probability that the state at step $k$ is a global minimum. It tends to 1 if and only if

$$\sum_{k=1}^{\infty} e^{-d^* / T_k} = \infty.$$

For the logarithmic schedule, $e^{-d^* \log(k+1)/c} = (k+1)^{-d^*/c}$, and this series diverges exactly when $d^*/c \le 1$: a series $\sum_k k^{-s}$ diverges for $s \le 1$ and converges for $s > 1$. Annealing with $T_k = c/\log(k+1)$ therefore converges if and only if $c \ge d^*$.

The theorem guarantees convergence, not speed, and the logarithmic schedule is extremely slow. With $T_k = c / \log(k + 1)$, the temperature is $c/10$ when $\log(k + 1) = 10$, that is, only after $e^{10} \approx 22{,}000$ steps. It is $c/20$ after $e^{20} \approx 4.9 \times 10^8$ steps. Lowering it from 100 at the first step to 1 would take about $2^{100} \approx 1.3 \times 10^{30}$ steps: $T_1 = c/\log 2 = 100$ fixes $c = 100 \log 2$, and then $T_k = 1$ requires $\log(k + 1) = 100 \log 2$, which is $k + 1 = 2^{100}$. Practical schedules cool much faster and give up the guarantee. Simulated annealing as used is a heuristic whose schedule must be tuned, with convergence theory as a statement about the limit.

Hajek's condition on a small example

The one-dimensional example is small enough to apply the theorem by hand and then to compute exactly what happens. The theorem is stated for minimizing a cost. For maximizing $f$, the depth of a local maximum is how far the search must go down before it can reach a strictly higher state. The example has three local maxima that are not global:

  • $x = 8$, height 11. Every higher state lies to the right, and the path there passes through the valley at $x = 14$, height 5. Its depth is $11 - 5 = 6$.
  • the flat maximum $x = 45$ to 50, height 18. To its left, the path to the global maximum passes through $x = 42$, height 15: depth 3. (To its right nothing is higher.)
  • $x = 60$, height 16. The nearest higher states are on the flat maximum, through the valley at $x = 56$, height 12: depth 4.

The shoulder is not a local maximum in this sense, since a higher state can be reached from it without going down at all. So $d^* = 6$.

Example (a constant of 4 is too small). Annealing with $T_k = 4 / \log(k + 1)$ does not converge to the global maximum on this example. The condition is $c \ge d^* = 6$, and $c = 4$ is too small for the peak at $x = 8$. The depths of the other two traps, 3 and 4, do not matter: the deepest trap sets the constant. Annealing converges with probability tending to 1 if and only if $c \ge 6$.

Depths of the three local maxima of the one-dimensional example that are not global. Each arrow measures how far a search must descend from the local maximum (dotted level) before a strictly higher state is reachable: 6 for the peak at x = 8, 3 for the flat maximum, and 4 for the peak at the right edge. Notice that the left peak, though lowest, is the deepest trap: its depth, d = 6, is the constant in Hajek's condition.
Depths of the three local maxima of the one-dimensional example that are not global. Each arrow measures how far a search must descend from the local maximum (dotted level) before a strictly higher state is reachable: 6 for the peak at x = 8, 3 for the flat maximum, and 4 for the peak at the right edge. Notice that the left peak, though lowest, is the deepest trap: its depth, d* = 6, is the constant in Hajek's condition.

An informal argument, not Hajek's proof, shows why the condition has this form. Take the peak at $x = 8$. To leave it, the search must accept falls totaling 6, which at temperature $T_k$ has probability of order $e^{-6/T_k}$. With $T_k = c/\log(k + 1)$ that is $(k + 1)^{-6/c}$.

  • For $c = 6$ it is $1/(k + 1)$. The sum of these chances over all steps diverges, like the harmonic series, so a search caught there gets unboundedly many opportunities to leave.
  • For $c = 2$ it is $(k + 1)^{-3}$, whose sum is finite. The chances of leaving add up to a finite total, which suggests that a search caught there may never leave. The theorem confirms that convergence fails for $c = 2 < d^*$, and the exact computation below finds about a quarter of the probability still on that peak after a million steps.

This is a heuristic reading, not a proof. Hajek's proof (1988) makes it precise by estimating how long the chain takes to leave the neighborhood of each local minimum.

The chain is also small enough that its distribution can be computed exactly, step by step, with no sampling. Start with probability $1/61$ on each state and apply the transition probabilities of the annealing step a million times. Four schedules were compared:

  • logarithmic, with $c = 6 = d^*$;
  • logarithmic, with $c = 2 < d^*$;
  • geometric, cooling from 10 to 0.1 over the million steps;
  • fixed, holding $T = 0.5$.

The probability of being at the global maximum $x = 36$, rounded to four decimals:

Schedule $k = 10^2$ $k = 10^3$ $k = 10^4$ $k = 10^5$ $k = 10^6$
Logarithmic, $c = 6$ 0.1389 0.3239 0.5183 0.6519 0.7536
Logarithmic, $c = 2$ 0.3365 0.4345 0.4541 0.4604 0.4625
Geometric, 10 to 0.1 0.0265 0.0329 0.0346 0.0470 0.9953
Fixed, $T = 0.5$ 0.3158 0.3634 0.4576 0.5905 0.6875
(a) Four temperature schedules over a million steps, on log-log axes. (b) The exact probability that annealing on the one-dimensional example is at the global maximum, from a uniformly random start. Notice that the logarithmic schedule with c = 2 cools quickly at first and then stalls near 0.46, with about a quarter of the probability trapped on the peak at x = 8. With c = 6 the probability keeps rising, but slowly. The geometric schedule is nearly a random walk for most of the run and then concentrates almost all of the probability on the global maximum in the last few hundred thousand steps.
(a) Four temperature schedules over a million steps, on log-log axes. (b) The exact probability that annealing on the one-dimensional example is at the global maximum, from a uniformly random start. Notice that the logarithmic schedule with c = 2 cools quickly at first and then stalls near 0.46, with about a quarter of the probability trapped on the peak at x = 8. With c = 6 the probability keeps rising, but slowly. The geometric schedule is nearly a random walk for most of the run and then concentrates almost all of the probability on the global maximum in the last few hundred thousand steps.

The table shows the theorem and its limits at once.

  • $c = 2$. Cooling is too fast for the deepest trap. The probability of being at the global maximum climbs early and then stops near 0.46. The probability of being at $x = 8$ stays near 0.24 (0.2372 at a million steps), which is the mass that never escaped.
  • $c = 6$. The probability at $x = 8$ falls (0.0606 at a million steps), and the probability at the global maximum keeps rising, as the theorem promises. But at a million steps it is still only 0.75.
  • Fixed $T = 0.5$. It cannot do better than the Boltzmann value 0.7526 in the limit, and the chain is still approaching it.
  • Geometric. This schedule carries no guarantee, yet it ends at 0.9953, the best of the four by a wide margin. It spends most of the run hot enough to move freely between basins, then cools steadily through the range where the global maximum takes over.

A schedule that is provably convergent in the limit can lose badly at a fixed budget. That is why practice uses fast schedules tuned to the problem. The exact computation is in tools/experiments/evolution/escaping_examples.py in the site repository. So are the other worked examples in this article: the acceptance table, the annealing run, the tabu trace and the restart check.

Annealing escapes at random. The next method escapes deliberately, and uses memory to avoid falling straight back.

Tabu search, introduced by Glover (1986) and developed systematically in Glover (1989, 1990), takes a deterministic route. At every step it moves to the best neighbor, even if that neighbor is worse than the current state. On its own this would cycle. From a local optimum, the best move goes slightly uphill, and the best move from there goes straight back down.

Tabu search prevents this with short-term memory. Some attribute of each recent move, such as the edges a 2-opt move removed, is declared tabu for a fixed number of iterations, the tabu tenure. Moves that would restore a tabu attribute are forbidden. An aspiration criterion overrides the prohibition for a move good enough to be worth making anyway, most simply one that would produce the best state found so far.

The version used below for the TSP is:

  1. Start from a random tour. At each iteration, evaluate every 2-opt move.
  2. A move is tabu if either edge it would add was removed within the last 40 iterations. A tabu move is still admissible if it would produce a tour shorter than the best found so far.
  3. Make the admissible move with the smallest change in length, whether that change is negative or positive (ties broken by move order). Mark the two removed edges tabu for 40 iterations. If no move is admissible, the iteration makes no move.
  4. Keep the best tour found, and stop when the budget is spent.

Because it evaluates the whole neighborhood every iteration, tabu search pays the cost of steepest ascent at every step. The tenure governs the balance between staying near good solutions and moving away. Too short, and the search falls back into the local optimum it just left; too long, and good moves stay forbidden. Glover's full method adds longer-term memory for intensification and diversification, which the plain version here omits.

A trace on twelve cities

The mechanism is easiest to follow on an instance small enough to solve exactly. Take the first 12 cities of kroA100, numbered 0 to 11, with 54 possible 2-opt moves per tour. The Held-Karp dynamic program gives the optimal tour length, 9,775. Steepest descent from a seeded random tour (length 21,857) stops at a 2-opt local optimum of length 9,842, 0.7% too long. Tabu search starts from there with tenure 3: an edge removed at iteration $i$ cannot be added back at iterations $i + 1$ and $i + 2$, unless the aspiration criterion applies.

Example (no memory at all). With tenure 0 the search alternates between two tours forever. From the local optimum, the best move lengthens the tour by 11, by removing the edges 2-11 and 8-10 and adding 2-8 and 11-10. From the new tour, the best move is the exact reverse, which shortens the tour by 11 and returns to the local optimum. The same two moves then repeat.

With tenure 3, the reverse move is forbidden, and the search is pushed further:

Iteration Edges removed Edges added Change Length Best Better moves that were tabu
1 2-11, 8-10 2-8, 11-10 +11 9,853 9,842 none
2 2-8, 6-11 2-6, 8-11 +32 9,885 9,842 -11 (adds 2-11, 8-10)
3 9-3, 5-0 9-5, 3-0 +113 9,998 9,842 -32 (adds 2-8, 6-11); -1 (adds 2-11)
4 3-0, 7-1 3-7, 0-1 -180 9,818 9,818 none
5 2-6, 8-11 2-8, 6-11 -32 9,786 9,786 none
6 2-8, 11-10 2-11, 8-10 -11 9,775 9,775 none

Read the trace iteration by iteration.

  • In iteration 2 the best move by far would undo iteration 1. It is tabu because it adds back two edges removed one iteration earlier.
  • In iteration 3 two better moves are tabu, and the search accepts a large increase of 113.
  • That increase is what opens the way. The move in iteration 4 shortens the tour by 180, leaving it shorter than the starting local optimum.
  • Two more improving moves reach the optimum at iteration 6. Iterations 5 and 6 add back edges removed in iterations 2 and 1, which is allowed because their tenure has expired.

The whole escape took three uphill moves totaling +156 followed by three downhill moves totaling -223.

Tour length over 12 iterations of tabu search on the 12-city instance, starting from a 2-opt local optimum of length 9,842. Without memory (tenure 0) the search alternates between two tours forever. With tenure 3 it climbs for three iterations and descends to the optimum 9,775 at iteration 6. Notice what happens next: three iterations of memory are too few to block a cycle of eight, so it repeats iterations 1 to 8 from iteration 9 on.
Tour length over 12 iterations of tabu search on the 12-city instance, starting from a 2-opt local optimum of length 9,842. Without memory (tenure 0) the search alternates between two tours forever. With tenure 3 it climbs for three iterations and descends to the optimum 9,775 at iteration 6. Notice what happens next: three iterations of memory are too few to block a cycle of eight, so it repeats iterations 1 to 8 from iteration 9 on.

The trace also shows the limit of short-term memory. After reaching the optimum, the search has to keep moving. It takes the least bad move that is not tabu (+180; two smaller increases, +11 and +42, are tabu), which undoes iteration 4. Iteration 8 undoes iteration 3 and returns to the starting tour, and from iteration 9 the whole sequence repeats with period 8. A tenure of 3 forbids only moves that undo the last two iterations, so it cannot prevent a longer cycle. In practice the tenure is set long enough to make cycles rare (the experiment below uses 40 on 100 cities). The best tour found is kept regardless of where the search wanders afterwards.

Tabu search pays for a full scan at every step, including the many steps it spends near one local optimum. The last single-trajectory method jumps straight to a nearby, different local optimum instead.

Iterated local search treats a hill climber as a black box and searches the space of its local optima (Lourenço, Martin, and Stützle, 2003). Its structure is:

  1. Run the local search from an initial state to a local optimum $s^*$.
  2. Perturb $s^*$ to get a new state $s'$.
  3. Run the local search from $s'$ to a local optimum $s^{*\prime}$.
  4. Apply an acceptance criterion to choose between $s^*$ and $s^{*\prime}$ as the new current state, and return to step 2.

The perturbation must be strong enough that the local search does not simply return to $s^*$. It must be weak enough that the result is not effectively a random restart.

For the TSP, the standard perturbation is the double-bridge move: cut the tour into four segments $A\,B\,C\,D$ and reconnect them as $A\,C\,B\,D$. Lourenço, Martin, and Stützle (2003) note that nearly all iterated local search studies of the TSP use this kind of perturbation. It changes four edges, can join cities that are far apart, and is not easily undone by 2-opt, 3-opt, or Lin-Kernighan local search. It descends from the large-step Markov chains of Martin, Otto, and Felten (1991), which applied a special four-edge change followed by local search, with an annealing-like acceptance rule.

The acceptance criterion ranges from Better, which accepts $s^{*\prime}$ only if it improves on $s^*$, to a random walk that always accepts it. The version used below:

  • accepts $s^{*\prime}$ if it is no longer than $s^*$;
  • uses steepest-descent 2-opt as the local search;
  • chooses the three cut points uniformly at random.
The double-bridge kick on a 16-city tour cut into four segments A, B, C and D. Reconnecting them in the order A C B D replaces the four edges between segments (dashed) with four new ones, while every edge inside a segment and the direction of travel through it are kept. Notice that four edges change: a 2-opt move changes only two, so no single 2-opt move can undo the kick.
The double-bridge kick on a 16-city tour cut into four segments A, B, C and D. Reconnecting them in the order A C B D replaces the four edges between segments (dashed) with four new ones, while every edge inside a segment and the direction of travel through it are kept. Notice that four edges change: a 2-opt move changes only two, so no single 2-opt move can undo the kick.

Why this particular kick? It keeps all four segments in their original direction and swaps the middle two, a change of four edges. No single 2-opt or 3-opt move, changing two or three edges, can make or undo it. And after the kick, most of the tour is still as good as before. Only the four new edges, which may join distant cities, are likely to be poor, so the local search has to repair the tour only around them. That is why the descent after a kick is short, as the experiment below measures.

The four methods side by side

Method How it leaves a local optimum What it remembers Settings that decide its behavior
Random restarts abandons it and starts from a new random state the best state found none beyond the climber
Simulated annealing accepts a worse neighbor with probability $e^{-\Delta/T}$ nothing starting temperature, cooling schedule
Tabu search always takes the best allowed neighbor, worse or not recently changed attributes tenure, aspiration rule
Iterated local search kicks it and climbs again, keeping the result if acceptable the current local optimum kick strength, acceptance rule

Which works best? That depends on what a step costs, so the comparison has to fix a budget.

Experiment: four methods at equal budgets

The four methods were compared on kroA100 (100 cities, optimal tour length 21,282), all with the 2-opt neighborhood. An evaluation is the computation of one move's change in tour length. Every run of every method had the same budget of evaluations, starting from a random tour.

  • Hill climbing with restarts: steepest-descent 2-opt to a local optimum, then a new random tour, until the budget is spent.
  • Simulated annealing: one random 2-opt move per evaluation, geometric cooling from $T_0 = 100$ to $T = 1$ over the budget.
  • Tabu search: as specified above, with tenure 40 (an edge removed at one iteration stays tabu through the next 39).
  • Iterated local search: as specified above.

The annealing temperatures and the tabu tenure were chosen in a small pilot on seeds outside the reported runs. The pilot used the smaller budget, and the settings were not retuned for the larger one. Each method had 30 seeded runs.

Example (the leader at 2 million evaluations). At 2 million evaluations annealing leads, by far. It spends one evaluation per move, and the other three spend 4,850 per scan. The table gives the median excess of the best tour over the optimum, with the interquartile range, and the number of runs that found an optimal tour.

Method 2 million evaluations Optimal 10 million evaluations Optimal
Hill climbing with restarts 4.64% (3.33 to 5.12) 0 / 30 1.93% (1.33 to 2.61) 0 / 30
Simulated annealing 0.49% (0.30 to 0.84) 4 / 30 0.44% (0.26 to 0.62) 3 / 30
Tabu search 3.20% (2.21 to 4.29) 0 / 30 1.79% (0.93 to 2.73) 0 / 30
Iterated local search 2.27% (1.35 to 3.02) 0 / 30 0.40% (0.01 to 1.10) 8 / 30

At 2 million evaluations, the reason for annealing's lead is the cost of a step. The other three scan all 4,850 moves before each move, so 2 million evaluations allow them only 412 full scans. A steepest descent from a random tour needs about 100 of those.

  • Hill climbing with restarts managed a median of 3 complete climbs.
  • Tabu search had 412 iterations in total, a quarter of them spent on the first descent.
  • Iterated local search did better than both. After a double-bridge kick only a few edges are wrong, and the descent back to a local optimum takes a few scans instead of a hundred. It completed a median of 59 kicks.

At 10 million evaluations, the order changes.

  • Hill climbing with restarts improves, with 19 climbs per run, but remains the weakest.
  • Tabu search, with 2,061 iterations, improves to about the same level.
  • Iterated local search, with a median of 384 kicks, now matches simulated annealing in median and found the optimum in 8 runs, although its spread is wider.
  • Simulated annealing barely improves with the longer schedule. Its temperatures were tuned at the smaller budget, and a schedule that cools five times more slowly is not automatically better.

These numbers describe plain textbook implementations on one instance. They should not be read as a general ranking. Fast implementations restrict each scan to candidate lists of each city's nearest neighbors. In iterated local search they also skip cities whose surroundings have not changed since the last scan (Lourenço, Martin, and Stützle, 2003). That greatly reduces the cost of a step, increasingly so on larger instances, and would change this comparison.

The general point survives that caveat. Comparisons at an equal budget depend on what a step costs. Every method here also has parameters, such as a schedule, a tenure, or a perturbation strength, that decide its behavior as much as its idea does. The No Free Lunch theorems add that no ranking can hold over all problems. The script is tools/experiments/evolution/local_search.py in the site repository.

A population as another answer

Every method above follows a single trajectory, and escapes by changing how that trajectory moves. A different answer is to keep many states at once.

Russell and Norvig (2020, §4.1.3) describe local beam search, which keeps $k$ states, generates all their neighbors, and keeps the best $k$ of the combined set. It is not the same as $k$ independent restarts. States with good neighbors attract the search, and the beam can collapse onto one region. Their stochastic beam search chooses the $k$ survivors at random, with probability increasing in fitness. As Russell and Norvig observe (2020, §4.1.3–4.1.4), this resembles natural selection and leads directly to evolutionary algorithms.

An evolutionary algorithm adds two things to a stochastic beam.

  • Recombination builds new states from parts of several existing ones (the evolutionary algorithm loop introduces it). A population can then combine features that separate trajectories found independently.
  • Selection pressure, how strongly the fitter states are preferred, plays a part similar to temperature in annealing. Strong pressure behaves like hill climbing and loses diversity quickly (selection pressure and premature convergence). Weak pressure behaves like a random walk.

The simple genetic algorithm is the standard example. Population methods and local search are also combined. Eiben and Smith (2015, ch. 10) describe memetic algorithms, which apply local search to the members of an evolving population, so that the population explores and the local search refines.

What we have learned

A local optimum can be left in four ways, and each costs something different. Sideways moves cross plateaus but do nothing at a strict optimum. Restarts are simple and their cost is exact, $1/p$ climbs on average, but $p$ shrinks quickly as the problem grows rugged. Annealing samples the Boltzmann distribution, and Hajek's condition says how slowly it must cool to be sure of the optimum. Yet on the one-dimensional example a guaranteed schedule lost to an unguaranteed one at a fixed budget. Tabu search escapes deliberately, with memory to stop it falling back, and iterated local search jumps between neighboring local optima. On kroA100 the winner depended on the budget and on what a step costs.

The next article takes these methods to an assignment, where the problem and the heuristic are fixed in advance. Hill climbing on 8-queens and the 8-puzzle applies steepest descent, sideways moves, and restarts to two classic puzzles, and finds that one yields easily and the other almost never does.

References

  • Černý, V. (1985). Thermodynamical approach to the traveling salesman problem: An efficient simulation algorithm. Journal of Optimization Theory and Applications, 45(1), 41–51. record
  • Eiben, A. E., and Smith, J. E. (2015). Introduction to Evolutionary Computing, 2nd ed., chapter 10. Springer. record · 35 pages
  • Geman, S., and Geman, D. (1984). Stochastic relaxation, Gibbs distributions, and the Bayesian restoration of images. IEEE Transactions on Pattern Analysis and Machine Intelligence, PAMI-6(6), 721–741. record · 3 pages
  • Glover, F. (1986). Future paths for integer programming and links to artificial intelligence. Computers & Operations Research, 13(5), 533–549. record
  • Glover, F. (1989). Tabu search, part I. ORSA Journal on Computing, 1(3), 190–206. record
  • Glover, F. (1990). Tabu search, part II. ORSA Journal on Computing, 2(1), 4–32. record
  • Hajek, B. (1988). Cooling schedules for optimal annealing. Mathematics of Operations Research, 13(2), 311–329. record
  • Kirkpatrick, S., Gelatt, C. D., Jr., and Vecchi, M. P. (1983). Optimization by simulated annealing. Science, 220(4598), 671–680. record
  • Lourenço, H. R., Martin, O. C., and Stützle, T. (2003). Iterated local search. In F. Glover and G. A. Kochenberger (Eds.), Handbook of Metaheuristics, 320–353. Kluwer Academic Publishers. record · 2 pages
  • Martin, O., Otto, S. W., and Felten, E. W. (1991). Large-step Markov chains for the traveling salesman problem. Complex Systems, 5(3), 299–326. record
  • Metropolis, N., Rosenbluth, A. W., Rosenbluth, M. N., Teller, A. H., and Teller, E. (1953). Equation of state calculations by fast computing machines. Journal of Chemical Physics, 21(6), 1087–1092. record · 2 pages
  • Russell, S., and Norvig, P. (2020). Artificial Intelligence: A Modern Approach, 4th ed., section 4.1. Pearson. record · 6 pages

Reviewed: verified, 16 Nov 2026 · citations checked, 16 Nov 2026 · editorial review, 23 Nov 2026 · 9 revisions