You are on page 1of 24

CSEN2031 |Artificial Intelligence

Dr. MRUDULA OWK


Assistant Professor
Department of Computer Science and Engineering
GITAM Institute of Technology
GITAM University

17 November 2023 CSEN2031 | Artificial Intelligence 1


LOCAL SEARCH ALGORITHMS AND
OPTIMIZATION PROBLEMS
• The search algorithms that we have seen so far are designed to explore search
spaces systematically.
• This systematicity is achieved by keeping one or more paths in memory and by
recording which alternatives have been explored at each point along the path.
• When a goal is found, the path to that goal also constitutes a solution to the
problem. In many problems, the path to the goal is irrelevant.
Example: In 8-queens problem, what matters is the final configuration of queens,
not the order in which they are added.
Applications: integrated-circuit design, factory-floor layout, job-shop scheduling,
automatic programming, telecommunications network optimization, vehicle routing,
and portfolio management.

17 November 2023 CSEN2031 | Artificial Intelligence 2


Local Search Algorithms and Optimization Problems

 The earlier search algorithms are designed to explore search spaces systematically.
 In many problems, the path to the goal is irrelevant.
Ex: 8-queens -- only final configuration matters, not the order in which they are added.
 This class of problems include applications such as:
integrated-circuit design
vehicle routing etc.

Local Search Algorithms:


 They operate using a single current state (rather than multiple paths) and generally move only to neighbors of that
state.
 The paths followed by the search are not retained.

They are not systematic, but have two advantages:


(i) they use very little memory
(ii) they can find reasonable solutions in large state spaces for which systematic algorithms are unsuitable.

17 November 2023 CSEN2031 | Artificial Intelligence 3


Continued...

Consider the state space landscape shown below:

Figure 10.1: A one-dimensional state space landscape in which elevation corresponds to the objective function. The
aim is to find the global maximum. Hill-climbing search modifies the current state to try to improve it, as shown by
the arrow.

17 November 2023 CSEN2031 | Artificial Intelligence 4


Continued...

 A landscape has both:


location -- defined by the state and
elevation -- defined by the value of the heuristic cost function or objective function

 If elevation corresponds to
cost -- aim is to find the lowest valley (a global minimum)
objective function -- aim is to find the highest peak (a global maximum)

 Local Search Algorithms explore this landscape.

 A complete local search algorithm always finds a goal if one exists.


 An optimal algorithm always finds a global minimum / maximum.

17 November 2023 CSEN2031 | Artificial Intelligence 5


Hill-climbing Search

(1) Hill-climbing Search:


There are two methods:
(i) Simple hill-climbing -- considers only one successor of the current state
(ii) Steepest-ascent hill-climbing -- considers all successors of the current state and chooses the best successor

Algorithm: Steepest-ascent

17 November 2023 CSEN2031 | Artificial Intelligence 6


Continued...

 In the above algorithm, if a heuristic cost estimate h is used, the neighbour will have the lowest
h value.

Ex: 8-queens
 Each state has 8 queens on the board.
 Successor function returns all possible states generated by moving a single queen to another
square in the same column.

Heuristic function h :
The number of pairs of queens that are attacking each other, either directly or indirectly.

 Global minimum is zero (i.e., the number of pairs attacking each other is zero).

17 November 2023 CSEN2031 | Artificial Intelligence 7


Continued...

17 November 2023 CSEN2031 | Artificial Intelligence 8


Continued...

 States with h = 12 are best successors.


 Hill-climbing algorithm choose randomly among the set of best successors, if there is more than one.
 Hill-climbing is called greedy local search because it grabs a good neighbour state without thinking ahead where to
go next.
Problems of Hill-climbing: Global peak
Local Maximum: Local maximum

movement

 It is a state that is better than all its neighbours but is not better than some other states farther away.

 When local maxima occur almost within sight of a solution, they are called ‘foothills’.

17 November 2023 CSEN2031 | Artificial Intelligence 9


Continued...

Plateau:
 It is a flat area of the search space, in which all neighbours
have the same value.
 It is not possible to determine the best direction.

Ridge:
valley
 It is a special kind of local maximum.
 This area in the path must be traversed
very carefully because movement in any
direction maintain one at the same level movement
or result in fast descent.

17 November 2023 CSEN2031 | Artificial Intelligence 10


Continued...

Variants of Hill Climbing

1. Stochastic hill climbing : Chooses at random among the uphill moves, the probability of selection can vary with
the steepness of the uphill move.

2. First-choice hill climbing : Implements stochastic hill climbing by generating successors randomly until one is
generated that is better than the current state.

3. Random-restart hill climbing: Conducts a series of hill climbing searches from randomly generated initial states,
until a goal is found.

17 November 2023 CSEN2031 | Artificial Intelligence 11


Simulated Annealing Search

(2) Simulated Annealing Search:


 Downhill moves -- they result in states with lower value (or higher cost)

 Hill-climbing algorithm that never makes downhill moves is guaranteed to be incomplete because it can get stuck
on a local maximum.
 In contrast, a purely random walk (choosing a successor randomly) is complete, but inefficient.

 Simulated annealing is an algorithm that combines hill-climbing with random walk and yields both efficiency and
completeness.
 As a computational process, Simulated annealing is patterned after the physical process of annealing.

Annealing: A process in which physical substances such as metals are melted (i.e., raised to high energy levels [high
temperatures]) and then gradually cooled until some solid state is reached.

 The goal of this process is to produce a minimum-energy final state.

17 November 2023 CSEN2031 | Artificial Intelligence 12


Continued...

Algorithm:

17 November 2023 CSEN2031 | Artificial Intelligence 13


Continued...

 The algorithm is similar to hill-climbing, but instead of picking the best move, it picks a random move.
 If the move improves the situation, it is always accepted. Otherwise, it accepts the move with some probability
less than 1.
 The probability decreases exponentially with the “badness” of the move – the amount ΔE by which the evaluation
is worsened.

Ex: Value of current: 20 (for example)


Value of next: 20, …… T = 10
next ΔE ΔE/T e ΔE/T (ΔE = Value[next] –
Value[current])
20 0 0 1
18 -2 -0.2 1/e0.2 Probability decreases
15 -5 -0.5 1/e0.5
10 -10 -1 1/e
5 -15 -1.5 1/e1.5
0 -20 -2 1/e2

17 November 2023 CSEN2031 | Artificial Intelligence 14


Continued...

 The probability also decreases as the “temperature” T goes down.


 “Bad” moves are more likely to be allowed at the start when temperature is high and they become more unlikely
as T decreases.

Ex: Value of current: 20 (for example)


Value of next: 20, …… T=5
next ΔE ΔE/T e ΔE/T (ΔE -- Value[next] –
Value[current])
20 0 0 1
18 -2 -0.4 1/e0.4 Probability decreases
15 -5 -1 1/e
10 -10 -2 1/e2
5 -15 -3 1/e3
0 -20 -4 1/e4

17 November 2023 CSEN2031 | Artificial Intelligence 15


Continued...

 Consider the rows having ‘next’ value as 5 in the above two tables.

 The probability value (1/e3) when T=5 is less than the probability value (1/e 1.5) when T=10
(i.e., if temperature decreases, then probability also decreases)

 If the schedule lowers T slowly enough, the algorithm will find a global optimum with
probability approaching 1.

 The schedule input determines the value of T as a function of time.

17 November 2023 CSEN2031 | Artificial Intelligence 16


Local Beam Search

(3) Local Beam Search:

 It keeps track k states rather than one.


 It begins with k randomly generated states.
At each step, all the successors of all k states are generated.
 If any one is a goal, the algorithm halts.
 Otherwise, it selects the k best successors from the complete list and repeats.

k random states

all the successors of all k states

17 November 2023 CSEN2031 | Artificial Intelligence 17


Continued...

 In this search, useful information is passed among the k parallel search threads.

For example,

if one state generates several good successors and the other k-1 states all generate bad
successors,

then the algorithm quickly abandons unfruitful searches and moves its resources to where the
most progress is being made.

17 November 2023 CSEN2031 | Artificial Intelligence 18


Continued...

(4) Genetic Algorithms (GAs):

 In this search, successor states are generated by combining two parent states, rather than by modifying a
single state.
 GAs begin with a set of k randomly generated states, called the population.
 Each state or individual is represented as a string over a finite alphabet – most commonly a string of 0s and 1s.

Ex: An 8-queen state must specify the positions of 8 queens, each in a column of 8 squares and so requires
8 x log28 = 24 bits.

Alternatively, the state could be represented as 8 digits, each in the range from 1 to 8.

17 November 2023 CSEN2031 | Artificial Intelligence 19


Continued...

(b): Each state is ranked by the fitness function (or an evaluation function).
 A fitness function should return higher values for better states, so for this problem we use:
number of non-attacking pairs of queens.

17 November 2023 CSEN2031 | Artificial Intelligence 20


Continued...

Its value for the -- solution is 28.


-- states in (a): 24, 23, 20 and 11.

In this particular variant of the GA, the probability of being chosen for reproducing is directly proportional to the
fitness score and the percentages are shown next to the raw scores.
Explanation for ‘the number of non-attacking pairs’:
Consider the 4th state in (a) : 32543213 (positions are from bottom to top)
All pairs:
1-2 1-3 1-4 1-5 1-6 1-7 1-8
• 2-3 2-4 2-5 2-6 2-7 2-8
Q
• 3-4 3-5 3-6 3-7 3-8 Direct or Indirect attacking :
Q
• 4-5 4-6 4-7 4-8 Not marked with Red
• 5-6 5-7 5-8
Q Q Q
• 6-7 6-8 Total no. of Pairs : 28
Q Q
• 7-8 No. of non-attacking pairs : 11
Q

17 November 2023 CSEN2031 | Artificial Intelligence 21


Continued...

(c) A random choice of two pairs is selected for reproduction in accordance with the probabilities
in (b).
(one individual is selected twice and one not at all)

(d) The offspring are created by crossing over the parent strings at the crossover point.

(e) Each location is subject to random mutation.

One digit was mutated in the 1st, 3rd and 4th offspring.

17 November 2023 CSEN2031 | Artificial Intelligence 22


Continued...

Algorithm:

17 November 2023 CSEN2031 | Artificial Intelligence 23


Continued...

In this algorithm,

each mating of two parents produces only one offspring, not two.

(In the figure 4.8, two offspring are shown).

****

17 November 2023 CSEN2031 | Artificial Intelligence 24

You might also like