Part 6 · Chapter 23

Introduction to Metaheuristics

Everything so far has leaned on structure — a gradient to follow, a Hessian to trust, a convex set to guarantee that downhill eventually means lowest. Real engineering problems are frequently rude enough to offer none of it: they are discrete, discontinuous, noisy, multimodal, or available only as a simulation that returns a number. Metaheuristics are the general-purpose strategies built for exactly that world — high-level recipes that guide a search using nothing but function evaluations, deliberately trading the guarantee of optimality for the ability to find very good solutions to problems that admit no guarantee at all. This chapter builds the vocabulary and the ideas that Chapters 24–26 turn into specific algorithms.

Optimization Techniques Prof. Mithun Mondal Reading time ≈ 45 min
i What you'll learn
  • Why gradient-based methods fail on discrete, noisy, multimodal and black-box problems, and what combinatorial explosion costs.
  • The difference between a heuristic, a metaheuristic, and a hyper-heuristic.
  • Local search: neighbourhood structures, hill climbing, local optima and basins of attraction.
  • The exploration–exploitation (diversification–intensification) trade-off that governs every method in Part 6.
  • The four devices for escaping local optima — accepting worse moves, memory, restarts, and populations.
  • A taxonomy of single-solution vs population methods, the generic framework they share, and the No Free Lunch theorem.
Section 23-1

Where Classical Methods Run Out

Parts 2 through 5 built a formidable toolkit, but every tool in it was bought with an assumption. The simplex method needs linearity. Newton's method needs two derivatives. The KKT conditions need constraint qualifications and smoothness. Convexity — the property that made a local answer a global one — needs the problem to be convex, which most interesting ones are not. When the assumptions hold, use those methods: they are faster, they are exact, and they come with certificates. This chapter is about what to do when they do not.

Four kinds of rudeness show up repeatedly in engineering practice:

ObstacleWhat breaksTypical example
MultimodalityLocal optimality no longer implies global; descent converges to whichever valley it started inAntenna array design, neural-network training, protein folding
Discreteness / combinatoricsNo gradient exists at all; the feasible set is a finite but astronomically large listUnit commitment, PCB routing, scheduling, the TSP
Non-smoothness & noiseDerivatives are undefined, or finite differences are swamped by simulation noiseMonte-Carlo simulations, measured data, if-then design rules
Black-box objectivesNo formula to differentiate — only a solver that maps a design to a number, at real cost per callFEM stress analysis, CFD, SPICE circuit sweeps

The combinatorial case deserves a number, because intuition consistently underestimates it. A travelling-salesman tour over \(n\) cities has \((n-1)!/2\) distinct routes. That is not a large number for \(n = 8\); it is \(2520\), and you could enumerate it by hand. For \(n = 20\) it is about \(6.1 \times 10^{16}\), and a machine checking a billion tours per second needs roughly two years. For \(n = 50\) the count exceeds the estimated number of atoms in the observable universe. Enumeration is not slow — it is impossible, and no faster computer will rescue it.

🔑
Combinatorial explosion
\[ |S| = \frac{(n-1)!}{2} \quad \text{for a symmetric TSP on } n \text{ cities} \]

Factorial growth defeats brute force permanently. Many such problems are NP-hard: no algorithm is known that solves every instance exactly in polynomial time, and most computer scientists believe none exists. The practical response is not a better exact method — it is to abandon the demand for a proof of optimality.

The bargain at the heart of Part 6. A metaheuristic gives up two things a simplex tableau hands you for free: the guarantee that the answer is optimal, and the certificate that proves it. In exchange it asks almost nothing of the problem — no gradient, no convexity, not even a formula. For a design engineer facing a 40-variable simulation with a deadline, a solution within 2% of optimal by Friday is worth more than a proof of optimality that never arrives. That is the whole argument, and it is an engineering argument rather than a mathematical one.
Section 23-2

Heuristics & Metaheuristics

A heuristic (from heuriskein, to find) is a problem-specific rule of thumb that produces a good solution quickly, with no guarantee of quality. "Always visit the nearest unvisited city" is a heuristic for the TSP: it is fast, it is sensible, and it is sometimes badly wrong. Heuristics are built from domain knowledge and do not transfer — the nearest-neighbour rule says nothing about how to schedule a machine shop.

A metaheuristic sits one level up (Greek meta, beyond). It is a problem-independent strategy for guiding a search, a template into which problem-specific pieces are plugged. Simulated annealing does not know what a tour is; it knows how to accept and reject candidate moves. Supply it with a way to represent a solution, evaluate it, and perturb it, and the same code anneals a tour, a truss, or a controller.

🔑
Metaheuristic
A high-level, problem-independent strategy that guides subordinate heuristics toward good regions of a search space, using only evaluations of the objective

The prefix matters: a metaheuristic orchestrates search rather than performing it. Its three obligations are to represent solutions, to explore broadly enough to find promising regions, and to exploit deeply enough to refine them.

One level higher still sits the hyper-heuristic, which searches the space of heuristics rather than the space of solutions — it decides which heuristic to apply next, and is the natural home of automated algorithm selection. The three-level picture is worth fixing:

LevelSearches overProblem-specific?Example
HeuristicSolutions, by a fixed ruleYes — built from domain knowledgeNearest-neighbour tour construction
MetaheuristicSolutions, by a general strategyNo — the strategy transfers; the operators do notSimulated annealing, genetic algorithms
Hyper-heuristicHeuristicsNoChoosing which local-search operator to apply next

Metaheuristics are also derivative-free and almost always stochastic. Randomness is not laziness; it is the mechanism that lets a search leave a region that a deterministic rule would never leave, and it is why two runs on the same instance give different answers. A metaheuristic result is therefore a sample, and honest reporting quotes a best, a mean, and a standard deviation over many runs — never a single lucky number.

Section 23-3

Local Search & Neighbourhoods

Nearly every metaheuristic is a modification of one embarrassingly simple idea. Take a solution, look at solutions "near" it, move to a better one, repeat. This is local search, and making it precise requires a single new concept: the neighbourhood.

Neighbourhood structure
\[ N : S \rightarrow 2^{S}, \qquad N(\mathbf{x}) \subseteq S \ \text{ is the set of solutions reachable from } \mathbf{x} \text{ by one move} \]

The neighbourhood is defined by the move operator, and choosing it is the single most consequential modelling decision in the whole of Part 6 — it is what imposes a geometry on a set that has none. Flip one bit of a binary string; swap two cities in a tour; add a small Gaussian perturbation to a real vector. Each choice creates a completely different landscape over the same solutions.

RepresentationMove operatorNeighbourhood size \(|N(\mathbf{x})|\)
Binary string, length \(n\)Flip one bit\(n\)
Permutation of \(n\) itemsSwap two positions\(\binom{n}{2} = n(n-1)/2\)
TSP tour, \(n\) cities2-opt (reverse a segment)\(n(n-3)/2\)
Real vector in \(\mathbb{R}^n\)\(\mathbf{x} + \sigma\boldsymbol{\varepsilon}\), \(\boldsymbol{\varepsilon}\sim\mathcal{N}(\mathbf{0},\mathbf{I})\)Infinite (sampled)

With a neighbourhood in hand, hill climbing (for a minimisation problem, more honestly descent) writes itself: from \(\mathbf{x}_k\), examine \(N(\mathbf{x}_k)\), move to a neighbour with lower cost, stop when none exists. Two variants differ in how much of the neighbourhood they inspect — steepest ascent evaluates all of it and takes the best; first improvement takes the first improving neighbour it stumbles on, which is cheaper per step and often better overall because it wastes less effort.

And here is the flaw that defines the entire field. Hill climbing stops when no neighbour is better — but "no neighbour is better" is a statement about \(N(\mathbf{x})\), not about \(S\). The point it stops at is a local optimum with respect to that neighbourhood, and there is no reason it should be global. Change the move operator and the same solution may stop being a local optimum at all.

start local global barrier
Hill climbing stops at the first valley it enters
basin 1 basin 2 basin 3 where you start decides where you finish
Basins of attraction partition the landscape

The right-hand picture names the second key idea. The basin of attraction of a local optimum is the set of starting points from which pure descent ends there. Descent is deterministic, so the basins partition the search space, and the entire outcome of a hill-climbing run is decided by the initial point. If the global optimum's basin occupies 1% of the space, a single random start finds it 1% of the time — and no amount of clever descent changes that arithmetic.

Section 23-4

Exploration vs Exploitation

Every metaheuristic in this book is an answer to one question, and the question is not "which direction is downhill?" It is: given a finite budget of function evaluations, how much of it should be spent examining new regions, and how much refining the best region found so far?

🔑
The central trade-off
Exploration (diversification) ⟷ Exploitation (intensification)

Exploration samples widely to discover promising basins; too much of it degenerates into random search, which finds everything and refines nothing. Exploitation searches intensively near the incumbent; too much of it degenerates into hill climbing, which refines beautifully and finds nothing. Every parameter you will tune in Chapters 24–26 is a knob on this one dial.

The two failure modes have names. Pure exploration is random search — unbiased, robust, and hopeless: it never uses what it learns. Pure exploitation is hill climbing — efficient and blind, converging fast to whatever it happened to land near. Useful methods live between, and most of them shift the balance over time: explore early, when the incumbent is worthless and information is cheap; exploit late, when the budget is nearly gone and the best region is known.

iterations → effort exploration exploitation balance random search metaheuristics hill climbing useful methods sit between the two extremes — and slide rightward as the budget runs out
The exploration–exploitation dial, and the spectrum it defines

Read the classical methods of Parts 4 and 5 on this dial and they sit at the far right: steepest descent is pure exploitation, which is exactly why it is so good on convex problems (where exploitation is all you need) and so useless on rugged ones. Recognising the dial explains why parameters like a cooling schedule, a mutation rate, or an inertia weight are not incidental tuning constants — each is the mechanism by which its algorithm sets the balance.

Section 23-5

Escaping Local Optima

If hill climbing's sole defect is that it halts at a local optimum, then the entire design space of metaheuristics is the space of answers to one question: how do you get out? Remarkably, there are only four fundamental devices, and every algorithm in Part 6 is a combination of them.

DeviceMechanismRealised by
Accept worse movesSometimes go uphill, with a probability that shrinks over timeSimulated annealing (Ch. 26)
MemoryForbid recently visited solutions, so the search cannot fall straight backTabu search (Ch. 26)
Restart / perturbKick the incumbent hard, or start again somewhere newIterated local search, random restarts, GRASP
PopulationSearch many basins at once and recombine what they learnGenetic algorithms (Ch. 24), PSO and ACO (Ch. 25)

The first device is the most counter-intuitive and the most important: a search that never accepts a worse solution can never leave a valley. Getting out requires climbing the wall, which means going uphill, which means temporarily accepting a worse objective value. Simulated annealing makes this explicit with the Metropolis criterion, which accepts an uphill move of size \(\Delta\) with probability

Metropolis acceptance probability
\[ P(\text{accept}) = \begin{cases} 1, & \Delta \le 0 \\[4pt] e^{-\Delta/T}, & \Delta > 0 \end{cases} \qquad \Delta = f(\mathbf{x}_{\text{new}}) - f(\mathbf{x}_{\text{old}}) \]

Read the formula as a policy on the dial of Section 23-4. Large \(T\): the exponent is near zero, almost everything is accepted, the search wanders — exploration. Small \(T\): uphill moves are rejected almost surely and the method degenerates into hill climbing — exploitation. The cooling schedule that lowers \(T\) over the run is the exploration-to-exploitation slide, made into arithmetic. Notice also that the criterion is size-aware: a slightly worse solution is accepted far more readily than a disastrous one.

The fourth device is different in kind. A population does not merely search several basins in parallel — that would be no better than several independent runs. Its power is recombination: two mediocre solutions, good in different ways, can be combined into one that is better than both. That is a mechanism no single-solution method possesses, and it is why Chapter 24 opens the population half of Part 6.

Every algorithm ahead is a recipe from these four ingredients. Simulated annealing takes device 1 alone. Tabu search takes device 2 alone. Iterated local search takes device 3. Genetic algorithms take device 4 with a dash of 3 (mutation). Particle swarms take device 4 with a memory of past bests, which is device 2 in disguise. Once you can name the ingredients, no metaheuristic — however elaborate the biological metaphor — is unfamiliar.
Section 23-6

A Taxonomy of Metaheuristics

Hundreds of metaheuristics have been published, many differing only in the animal on the cover. Three cuts organise the useful ones.

The first and most informative cut is how many solutions are carried. Single-solution (or trajectory) methods maintain one incumbent and trace a path through the space; they are simple, memory-light, and strong exploiters. Population-based methods maintain a set, sample many regions at once, and can recombine; they explore better and cost proportionally more evaluations.

Single-solution (trajectory)Population-based
CarriesOne incumbent, moving step by stepA set of solutions, evolving together
StrengthIntensification — refines a region wellDiversification — surveys many regions
Escapes optima byAccepting worse moves; memoryDiversity; recombination
Evaluations per iterationOne (or a neighbourhood)One per individual — parallelises trivially
ExamplesSimulated annealing, tabu search, iterated local searchGenetic algorithms, PSO, ACO, differential evolution

The second cut is memory: does the method remember where it has been? Simulated annealing is memoryless — its next move depends only on the current point and the temperature, making it a Markov chain, which is precisely what allows its convergence to be proved. Tabu search is built entirely on memory. Ant colony optimization stores memory outside the solutions altogether, in a shared pheromone matrix.

The third cut is inspiration — annealing from metallurgy, evolution from biology, swarming from ethology. It is the cut that sells papers and the least useful of the three. Judge a method by its mechanism, not its metaphor: a "firefly algorithm" whose fireflies do what particles already do is not a new idea.

MethodTypeEscape deviceKey parameterChapter
Genetic algorithmPopulationRecombination + mutationPopulation size, crossover & mutation rates24
Particle swarmPopulationSocial attraction + inertiaInertia weight \(w\), coefficients \(c_1, c_2\)25
Ant colonyPopulationPheromone reinforcement + evaporationEvaporation rate \(\rho\)25
Simulated annealingSingleAccepts worse movesCooling schedule \(T_k\)26
Tabu searchSingleShort-term memoryTabu tenure26
Section 23-7

The Generic Framework & No Free Lunch

Strip away the metaphors and every method in Part 6 has the same skeleton. Learning it once means Chapters 24–26 are about filling in three boxes, not about learning three algorithms.

🔑
The generic metaheuristic
initialise → generate candidates → evaluate → accept/select → update memory → repeat until stop

An algorithm is specified by three choices: the representation (what a solution is), the generation rule (how candidates are produced — mutate, recombine, perturb, sample), and the acceptance rule (which survive). Everything else is bookkeeping.

initialise generate candidates evaluate f accept / select update memory stop? → x★ mutate · recombine · perturb Metropolis · elitism · tabu every method in Part 6 fills the same three boxes differently
The generic metaheuristic loop

Because there is no optimality condition to check — no \(\nabla f = \mathbf{0}\) to satisfy — a metaheuristic never knows it is finished. Stopping is a budget decision, taken on one of these grounds: a fixed number of evaluations or wall-clock seconds; stagnation (no improvement in the last \(k\) iterations); a target value reached; or, for population methods, collapse of diversity. Note the honest consequence: the best solution found is reported, but never certified. Always keep the incumbent best separately from the current point — a search that wanders uphill will otherwise throw away the answer it already found.

Finally, a theorem that should temper any enthusiasm. Wolpert and Macready's No Free Lunch result says that averaged over all possible objective functions, every search algorithm has identical expected performance. No metaheuristic is universally best; a method that beats random search on one class of problems must lose to it on another.

🔑
No Free Lunch theorem (informal)
Averaged over all objective functions, all search algorithms perform equally well

Superior performance on real problems comes from matching the algorithm's assumptions to the problem's structure — never from the algorithm alone. The theorem is not a counsel of despair: real problems are a vanishingly small, highly structured subset of all functions, and exploiting that structure is exactly the job.

So when a paper claims a new metaheuristic is best "on average", the theorem says the claim is either meaningless or an admission that the benchmark set was chosen favourably. The right question is never "which metaheuristic is best?" but "what does my landscape look like, and which method's assumptions fit it?"

Section 23-8

Worked Examples

1 How big is the search space?

Problem. A symmetric TSP has 20 cities. How many distinct tours exist, and how long would exhaustive enumeration take at \(10^9\) tours per second?

Solution. Fix a starting city (any tour can be rotated to start anywhere) and halve for direction: \(|S| = (n-1)!/2 = 19!/2\). Now \(19! \approx 1.216 \times 10^{17}\), so \(|S| \approx 6.08 \times 10^{16}\) tours. At \(10^9\) per second that is \(6.08 \times 10^{7}\) seconds \(\approx 1.93\) years. Adding just five more cities multiplies the count by \(20\cdot21\cdot22\cdot23\cdot24 \approx 5.1\) million — pushing the same enumeration past ten million years. This is why exact enumeration is not a slow method but an impossible one, and why we accept "very good" instead.

2 Hill climbing gets stuck

Problem. A search space has eight states \(1,\dots,8\) arranged in a line, with costs \(f = (8,\ 5,\ 3,\ 6,\ 9,\ 4,\ 1,\ 7)\). The neighbourhood of a state is its immediate line-neighbours. Trace steepest-descent hill climbing from state 1, and from state 6.

Solution. From state 1 (\(f = 8\)): the only neighbour is 2 (\(f = 5\)) — move. From 2, neighbours are 1 (\(8\)) and 3 (\(3\)); move to 3. From 3, neighbours are 2 (\(5\)) and 4 (\(6\)) — both worse, so stop at state 3 with \(f = 3\). From state 6 (\(f=4\)): neighbours 5 (\(9\)) and 7 (\(1\)); move to 7. From 7, neighbours 6 (\(4\)) and 8 (\(7\)) — both worse, stop at \(f = 1\). The same deterministic algorithm returns \(3\) or \(1\) depending only on where it started: state 3 is a local optimum, state 7 the global one, and the barrier at state 5 (\(f=9\)) is what separates their basins. Escaping requires accepting the uphill move \(3 \to 4\).

3 Counting neighbourhoods

Problem. For a 20-city TSP, compare the size of the swap neighbourhood, the 2-opt neighbourhood, and the whole space. For a 30-bit binary problem, the bit-flip neighbourhood.

Solution. Swap: \(\binom{20}{2} = 190\). 2-opt: \(n(n-3)/2 = 20\cdot17/2 = 170\). The full space, from Example 1, is \(6.08\times10^{16}\). So one hill-climbing step inspects roughly \(170\) of \(6\times10^{16}\) solutions — a fraction of \(3\times10^{-15}\), yet it reliably improves. Bit-flip on 30 bits: \(|N| = 30\), against a space of \(2^{30} \approx 1.07\times10^{9}\). The moral is that neighbourhoods are tiny relative to the space; local search works not by covering ground but by using structure — near solutions have related costs.

4 The Metropolis criterion at two temperatures

Problem. A proposed move worsens the objective by \(\Delta = 5\). Find the acceptance probability at \(T = 10\), \(T = 1\), and \(T = 0.1\). Repeat for \(\Delta = 0.5\) at \(T = 1\).

Solution. \(P = e^{-\Delta/T}\). At \(T = 10\): \(e^{-0.5} = 0.607\) — accepted three times in five, the search roams freely. At \(T = 1\): \(e^{-5} = 0.0067\) — accepted once in 150. At \(T = 0.1\): \(e^{-50} \approx 2\times10^{-22}\) — never, and the method has become hill climbing. For \(\Delta = 0.5\) at \(T = 1\): \(e^{-0.5} = 0.607\), the same as the first case, because only the ratio \(\Delta/T\) matters. Two lessons: cooling converts exploration into exploitation continuously, and at any fixed temperature a small worsening is far likelier to be accepted than a large one.

5 Do random restarts fix hill climbing?

Problem. The global optimum's basin covers 5% of the search space. Hill climbing always finds the optimum of the basin it starts in. What is the probability of success after 1 restart? After 50? How many restarts give 99% confidence?

Solution. Each restart succeeds independently with \(p = 0.05\), so after \(r\) restarts \(P = 1 - (1-p)^r\). For \(r = 1\): \(0.05\). For \(r = 50\): \(1 - 0.95^{50} = 1 - 0.0769 = 0.923\). For 99% we need \(0.95^r \le 0.01\), i.e. \(r \ge \ln(0.01)/\ln(0.95) = 89.8\), so 90 restarts. Restarting is a genuine method — but notice what it costs: 90 full descents to be fairly sure. And if the basin were 0.1% of the space, 99% confidence would take about 4600 restarts. Restarts throw away everything learned each time; the methods of Chapters 24–26 earn their keep by not doing that.

6 A deceptive landscape

Problem. Maximise \(f\) over 4-bit strings, where \(f(\mathbf{b})\) is the number of 1s — except \(f(0000) = 5\). Neighbourhood: flip one bit. Where does hill climbing end?

Solution. The global maximum is \(0000\) with \(f = 5\). Start anywhere with at least one 1 — say \(0100\) (\(f=1\)). Its neighbours are \(1100, 0110, 0101\) (all \(f=2\)) and \(0000\) (\(f=5\)). Steepest ascent would in fact spot \(0000\) here. But start from \(0110\) (\(f=2\)): every neighbour has one bit flipped, giving \(f = 1\) or \(f = 3\) — the string \(0000\) is not in the neighbourhood, so the climb proceeds \(0110 \to 0111 \to 1111\) and halts at \(f = 4\), never seeing the peak. The landscape is deceptive: its gradient points consistently away from the global optimum. No amount of exploitation helps, restarts help only from the handful of strings adjacent to \(0000\), and this is precisely the failure mode that motivates recombination and worse-move acceptance.

Review

Chapter Summary

Why we're here

Multimodal, discrete, noisy, or black-box problems offer no gradient and no convexity; factorial spaces defeat enumeration permanently.

The bargain

Metaheuristics drop the guarantee of optimality in exchange for needing almost nothing from the problem but function values.

Local search

A neighbourhood \(N(\mathbf{x})\) imposes geometry on the space; hill climbing halts at a local optimum decided entirely by its basin.

The dial

Exploration finds basins, exploitation refines them; pure forms are random search and hill climbing, and every parameter tunes the balance.

Four escapes

Accept worse moves \(\big(P = e^{-\Delta/T}\big)\), remember, restart, or carry a population — every method in Part 6 mixes these.

No Free Lunch

Averaged over all functions no method wins; performance comes from matching the algorithm to the problem's structure.

Practice

Problems

Several of these ask for judgement rather than arithmetic — say which method fits and why, in terms of the four escape devices and the exploration–exploitation dial. Difficulty rises down the list.

  1. Distinguish a heuristic, a metaheuristic, and a hyper-heuristic, giving one example of each.
  2. Give two engineering problems on which a gradient method is the right tool, and two on which it cannot even be started. Justify each.
  3. Compute the number of tours for a symmetric TSP with 12 cities, and the enumeration time at \(10^{6}\) tours per second.
  4. Define a neighbourhood structure formally. Give the size of the swap neighbourhood for a permutation of 15 items and of the bit-flip neighbourhood for a 15-bit string.
  5. Explain why the same solution can be a local optimum under one neighbourhood and not under another. Illustrate with a TSP tour under swap and under 2-opt.
  6. Define the basin of attraction of a local optimum, and explain why the basins of a deterministic descent method partition the search space.
  7. Explain the exploration–exploitation trade-off, and describe what an algorithm at each extreme degenerates into.
  8. For \(\Delta = 2\), tabulate the Metropolis acceptance probability at \(T = 5,\ 2,\ 1,\ 0.5,\ 0.2\), and comment on the trend.
  9. An optimum's basin covers 2% of the space. How many random restarts of hill climbing give at least a 95% chance of finding it? What does this tell you about restarts as a strategy?
  10. Name the four devices for escaping local optima, and classify simulated annealing, tabu search, and genetic algorithms by which they use.
  11. Argue why a population method can outperform running the same number of independent hill climbs — identify the mechanism a population has that independent runs do not.
  12. State the No Free Lunch theorem and explain why it does not imply that metaheuristics are useless in practice.
  13. Design a metaheuristic for scheduling 20 jobs on 3 machines to minimise makespan: specify the representation, the neighbourhood or recombination operator, the acceptance rule, and the stopping criterion — and defend each choice.
Tip: resist the pull of the metaphors. The chapters ahead describe evolution, swarms, ants, and cooling metal, and the vocabulary can make five algorithms feel like five unrelated subjects. They are not. Ask three questions of every method and it will fall into place: What is a solution? (the representation) How are new candidates made? (mutation, crossover, velocity update, pheromone-guided construction) Which candidates survive? (elitism, Metropolis, tabu tenure). Then ask the fourth question, the one that decides whether it works: where does this method sit on the exploration–exploitation dial, and which knob moves it? A genetic algorithm with a mutation rate of zero and a simulated annealer at \(T = 0\) are the same algorithm — hill climbing — wearing different costumes.