Local search · optimization

Also known as: local search algorithm

On this page 8

Local search is a family of optimization methods that start from one complete candidate solution and repeatedly replace it with a better solution from its neighborhood, stopping when no neighbor improves the objective. In the Optimization topic of artificial intelligence, a local search algorithm is the standard tool for large combinatorial problems such as scheduling, routing and satisfiability, where exhaustive search is impossible and a good answer found quickly is worth more than a proven optimum found too late.

The approach trades guarantees for scalability. Local search usually cannot prove that its result is globally optimal, but it needs little memory, works on problems with millions of variables and can be stopped at any time with a usable answer, which makes it an anytime algorithm.

How local search moves through the search space

Local search works by defining a neighborhood function that maps each solution to a set of nearby solutions, then walking through that landscape one move at a time. A move is a small, cheap modification: swapping two cities in a tour, flipping one Boolean variable or reassigning one job to another machine. The algorithm evaluates neighbors with the objective function and accepts a move according to its acceptance rule.

The process has four components that together determine its behavior. Changing any one of them produces a different named method, which is why local search is better understood as a design template than as a single algorithm.

ComponentRoleTypical choice
Solution representationEncodes a candidatePermutation, bit vector, assignment
NeighborhoodDefines reachable solutions2-opt, bit flip, swap, insert
Acceptance ruleDecides whether to moveFirst improvement, best improvement
Stopping criterionEnds the searchLocal optimum, time limit, iteration cap
Core components of a local search algorithm

Efficient implementations rely on incremental evaluation: instead of recomputing the full objective, they compute only the change caused by a move, often in constant time. This delta evaluation is the main reason local search scales to very large instances.

Local optima and the shape of the landscape

A local optimum is a solution that no single move can improve, and every pure descent method eventually stops at one. Whether that point is close to the global optimum depends on the fitness landscape, meaning the objective values arranged by the neighborhood structure. Smooth landscapes with few, wide basins are easy; rugged landscapes with many shallow basins trap simple methods quickly.

The neighborhood defines what counts as local. A larger neighborhood produces fewer local optima, because more moves are available, but each step costs more time to evaluate. The 3-opt neighborhood for the traveling salesman problem, for example, contains roughly cubic numbers of moves in the tour length, compared with quadratic numbers for 2-opt.

Plateaus are a second obstacle. On a plateau, many neighbors share the same objective value, so the search has no gradient to follow and may wander without progress. Satisfiability solvers handle this with sideways moves and random noise.

Variants of local search differ mainly in how they escape local optima. Pure hill climbing does not escape at all, while metaheuristics add memory, randomness or restarts to continue exploring after the first stall.

VariantEscape mechanismTypical use
Hill climbingNone; stops at first local optimumFast baseline, polishing step
Random-restart searchRestarts from new random pointsCheap diversification
Simulated annealingAccepts worse moves with decreasing probabilityRugged continuous or discrete landscapes
Tabu searchForbids recently reversed movesScheduling, routing, assignment
Iterated local searchPerturbs the optimum, then descends againTraveling salesman, flow shop
Variable neighborhood searchSwitches between neighborhood sizesLocation and clustering problems
Common local search variants and their escape mechanisms

Stochastic local search for satisfiability, such as WalkSAT, mixes greedy flips with random flips at a fixed noise probability, typically between 0.2 and 0.6. Population methods such as genetic algorithms often embed local search as an improvement step, a combination known as memetic algorithms.

Local search compared with other optimization approaches

Local search sits between exact methods and constructive heuristics. Exact solvers based on branch and bound or mixed-integer linear programming prove optimality but may need exponential time, while greedy construction builds one answer quickly and never revises it. Local search revises a complete answer and therefore usually reaches better quality than construction at far lower cost than exact solving.

ApproachWorks onOptimality proofScales to
Local searchComplete solutionsNoMillions of variables
Branch and boundPartial solutions in a treeYes, if it finishesModerate instances
Greedy constructionPartial solutions built onceNoVery large instances
Gradient descentContinuous parametersOnly for convex problemsVery large models
How local search relates to neighboring methods

Gradient descent is formally a continuous local search in which the neighborhood is an infinitesimal step along the negative gradient. The distinction matters in practice: discrete local search needs explicit move operators, whereas gradient methods derive the direction analytically.

Good local search design starts with a representation that keeps solutions feasible or measures infeasibility as a penalty in the objective. Practitioners then choose neighborhoods that make meaningful structural changes while remaining cheap to evaluate, and they test the method on instances with known optimal values before trusting it on production data.

SituationRecommended choiceReason
Hard constraints are tightPenalty function with adaptive weightsLets the search cross infeasible regions
Neighborhood is very largeFirst improvement with random orderAvoids scanning every neighbor
Search stalls earlyAdd perturbation or tabu memoryEscapes shallow basins
Results vary between runsReport best and median of many seedsGives an honest quality estimate
Design decisions and their recommended defaults
  • Start from a good initial solution, often a greedy construction, to save iterations.
  • Use delta evaluation for every move operator before tuning any parameter.
  • Tune temperature schedules, tabu tenure and noise on a separate set of instances.

Limitations and common mistakes

The central limitation of local search is the absence of a quality guarantee: without a lower bound from relaxation or duality, a user cannot tell how far the result is from optimal. Performance also depends heavily on problem-specific neighborhoods, so a method that excels on routing may fail on timetabling.

  • Comparing methods on a single run hides the large variance of stochastic search.
  • Overly small neighborhoods produce many poor local optima and premature stops.
  • Recomputing the full objective for each move makes the search orders of magnitude slower.
  • Ignoring constraint handling lets the search report infeasible solutions as good ones.

Put simply

Local search is a way to improve an answer by making small changes, one at a time. You start with any reasonable answer. You try a small change. If the change helps, you keep it. If not, you try another one.

Think of a hiker in fog who wants to reach the lowest valley. The hiker cannot see the whole map. So the hiker always steps downhill. This often works well. But the hiker may stop in a small dip that is not the lowest point. Smarter versions sometimes step uphill on purpose, or start again elsewhere, to find a deeper valley.

In practice

A regional parcel carrier plans routes for 120 vans and about 4,000 daily stops. An exact solver cannot finish before the morning departure, so the planning team builds a first plan with a greedy insertion rule and then runs local search for ten minutes. The moves relocate single stops between vans, swap pairs of stops and apply 2-opt inside each route, with tabu memory to avoid cycling.

On historical days, the greedy plan alone needs about 9 percent more driving distance than the best known plans. After local search, the gap falls to roughly 2 percent, and every route still respects time windows and van capacity. The team runs eight random seeds in parallel and keeps the best plan, which gives consistent quality within the fixed planning window.