Articles / AI · Part 21

Local Search Algorithms in Artificial Intelligence

Understand how local search algorithms improve candidate solutions by exploring neighbouring alternatives. Learn about objective functions, local and global optima, Hill Climbing, Simulated Annealing, Tabu Search, Genetic Algorithms, and real-world applications.

Local Search Algorithms in Artificial Intelligence

Local Search Algorithms: Finding Better Solutions Step by Step

Imagine you are standing on a mountain, surrounded by hills and valleys. Your goal is to reach the highest possible point.

You cannot see the entire landscape. You can only examine the area around you.

So, you look at the nearby positions and move towards a higher point. You repeat this process until you cannot find a better position nearby.

This is a simple way to understand Local Search.

In Artificial Intelligence, many problems do not require us to explore every possible path from a starting point. Instead, we need to find a good solution among a large number of possibilities.

Local search algorithms approach these problems by starting with a candidate solution and repeatedly trying to improve it.

Local Search is a search and optimization approach that explores neighbouring candidate solutions to find a solution that satisfies a goal or optimizes an objective.

Unlike traditional search algorithms such as BFS and DFS, local search does not usually focus on finding a path from an initial state to a goal state.

Instead, it focuses on improving the current solution.

For example, imagine a delivery company trying to find the most efficient route for delivering packages to 20 different locations.

There may be millions of possible delivery orders. Exploring every possibility would be expensive.

A local search algorithm can begin with one delivery route, make small changes, and keep improving it until it finds a good route.

This makes local search useful for large optimization problems.

2. How Does Local Search Work?

The basic process is straightforward:

  1. Generate an initial candidate solution.
  2. Evaluate how good the solution is.
  3. Generate neighbouring solutions by making small changes.
  4. Compare their quality with the current solution.
  5. Move to a better neighbour when one is available.
  6. Repeat until a stopping condition is reached.

The quality of a solution is measured using an objective function or evaluation function.

For example, if we are trying to minimize delivery distance, the objective function calculates the total distance of a route.

A lower value represents a better solution.

If we are trying to maximize profit, a higher value would represent a better solution.

3. Understanding the Search Space

A search space is the collection of all possible candidate solutions to a problem.

In local search, each candidate solution can be treated as a state or position in this search space.

For example, suppose a company has four delivery locations: A, B, C, and D.

Different delivery orders represent different candidate solutions:

  • A → B → C → D
  • A → C → B → D
  • B → A → D → C

Each route has a different total cost.

Local search moves from one candidate solution to a neighbouring candidate by making a small change, such as swapping two locations.

The algorithm evaluates the new route and decides whether it should continue from there.

Traditional search algorithms and local search approach problems differently.

Feature Traditional Search Local Search
Main focus Finding a path to a goal Improving a candidate solution
Search process Explores nodes and paths Explores neighbouring solutions
Path tracking Often important Usually unnecessary
Memory usage Can be high Often relatively low
Common applications Maze solving, route search, puzzles Scheduling, optimization, resource allocation

BFS and DFS are examples of traditional search strategies. Hill Climbing and Simulated Annealing are examples of local search methods.

5. Objective Functions

An objective function measures the quality of a candidate solution.

It tells the algorithm whether a solution is better or worse according to the problem’s requirements.

For example:

Route optimization: Minimize total travel distance.

Business planning: Maximize expected profit.

Scheduling: Minimize delays or conflicts.

Resource allocation: Maximize the use of available resources.

The algorithm uses the objective function to compare candidate solutions.

The direction of optimization matters:

  • Minimization: Find the smallest possible value.
  • Maximization: Find the largest possible value.

A local search algorithm needs a way to evaluate solutions before deciding which direction to move.

6. Types of Local Search Algorithms

Several algorithms use the local search approach. Some important examples are:

A. Hill Climbing

Hill Climbing repeatedly moves from the current solution to a better neighbouring solution.

It continues until no neighbouring solution improves the current one.

For a maximization problem, imagine climbing a hill. At every step, you move towards a higher point.

However, the algorithm may stop at a local maximum even when a higher point exists elsewhere.

We will explore Hill Climbing in detail in the next article.

B. Simulated Annealing

Simulated Annealing is inspired by the process of heating and gradually cooling materials.

Unlike basic Hill Climbing, it sometimes accepts a worse solution to avoid getting trapped in a local optimum.

As the algorithm progresses, the probability of accepting worse solutions gradually decreases.

This allows it to explore different areas of the search space.

Tabu Search uses memory to avoid repeatedly exploring recently visited solutions or making certain previously used moves.

It maintains a structure called a Tabu List, which records moves or solutions that should temporarily be avoided.

This helps the algorithm escape repetitive search patterns.

D. Genetic Algorithms

Genetic Algorithms are inspired by natural selection and evolution.

They maintain a population of candidate solutions and use operations such as selection, crossover, and mutation to generate new candidates.

They are commonly used for optimization problems.

Genetic Algorithms are often discussed alongside local search and metaheuristic optimization methods, although they are population-based evolutionary algorithms rather than simple single-solution local search methods.

7. Understanding Local Optima

One of the biggest challenges in local search is getting trapped in a solution that looks good nearby but is not the best overall solution.

Consider a landscape with several peaks.

There may be:

  • Local maximum: A point higher than its immediate neighbours, but not the highest point overall.
  • Global maximum: The highest point in the entire search space.
  • Local minimum: A point lower than its immediate neighbours, but not the lowest point overall.
  • Global minimum: The lowest point in the entire search space.

For minimization problems, the same ideas apply in reverse.

A local search algorithm may find a local optimum and stop, even though a better solution exists somewhere else.

This is an important limitation of many local search methods.

  • Low memory requirements: Many local search algorithms need to store only the current solution and a limited amount of additional information.
  • Useful for large problems: They can work with search spaces that are too large to explore completely.
  • Flexible: They can be adapted to many optimization problems.
  • Can find good solutions quickly: A useful neighbourhood structure can help improve a candidate solution efficiently.
  • Does not always require a complete path: The algorithm often needs only the current candidate and its quality.
  • Local optima: An algorithm may stop at a solution that is not globally optimal.
  • Dependence on the initial solution: Different starting points may lead to different results.
  • No universal guarantee of optimality: Many local search methods find good solutions without guaranteeing the best possible one.
  • Neighbourhood design matters: Poorly designed neighbouring moves may make it difficult to reach useful solutions.
  • Stopping conditions can be difficult: The algorithm needs a suitable way to decide when to stop searching.

Different local search algorithms address some of these limitations in different ways.

Local search is useful when a problem has many possible solutions and finding a sufficiently good one is more practical than exploring every possibility.

Some applications include:

  • Timetable scheduling: Assigning classes, teachers, and rooms while reducing conflicts.
  • Route optimization: Improving delivery routes and travel plans.
  • Resource allocation: Distributing limited resources efficiently.
  • Job scheduling: Assigning jobs to machines while minimizing delays.
  • Engineering design: Improving the design of a system according to selected objectives.
  • Machine learning: Optimizing model parameters and other objective functions.

These problems often have large search spaces, making local search a practical approach.

Conclusion

Local Search provides a different way to solve problems in Artificial Intelligence.

Instead of exploring every possible path, it begins with a candidate solution and tries to improve it by examining nearby alternatives.

This makes it useful for complex optimization problems, although it can sometimes become trapped in local optima.

In the next article, we will study one of the most fundamental local search methods: Hill Climbing, including its working process, variations, and limitations.

Quick quiz

5 questions
What is the main focus of local search?
What does an objective function measure?
What is a local maximum?
Which algorithm sometimes accepts worse solutions to escape local optima?
What does Tabu Search use to avoid repeatedly exploring certain moves?

Keep a copy

Read offline as a printout or PDF.

farhanpaal.com

Keep reading

AI · Part 15

Depth-First Search (DFS)

Learn how Depth-First Search explores a search tree by following one branch deeply before backtracking. Understand stacks, the DFS algorithm, Python implementation,…

7 min read

Ask Farhan

Ask anything about Farhan