You are on page 1of 131

Informed Search/Heuristic

Search

Abu Saleh Musa Miah


Assist. Professor, Dept. of CSE, BAUST, Bangladesh
email: musa@baust.edu.bd, tel: +8801734264899
web: www.baust.edu.bd/cse
Outline
• Heuristic search
• Greedy First Search
• A* Search
• IDA*
• SMA*
• Hill-climbing
• Simulated annealing
• Genetic algorithms
• Local search in continuous spaces
21/10/04 AIPP Lecture 9: Informed Search Strategies 3
Informed Search

 Also Called heuristic or intelligent search,

 Uses Additional information about the problem to guide


the search,

 Usually guesses the distance to a goal state and therefore


efficient,

21/10/04 AIPP Lecture 9: Informed Search Strategies 4


Advantage of Informed Search

 A search strategy which searches the most promising branches of


the state-space first can:
 find a solution more quickly,
 find solutions even when there is limited time available,
 Often find a better solution, since more profitable parts of the
state-space can be examined, while ignoring the unprofitable
parts.

 A search strategy which is better than another at identifying the


most promising branches of a search-space is said to be more
informed.

21/10/04 AIPP Lecture 9: Informed Search Strategies 5


Heuristic Search
• Heuristic-heuriskein (Greek word)
-to discover
 original: eureka
-heurika (I have found): Archimedes uttering when determining the purity of
gold
The heuristic function is a way to inform the search about the direction to a
goal. 
It provides an informed way to guess which neighbor of a node will lead to a
goal.
Pros
Like a tour guide
Good to the extent that they point in generally interesting direction
Improve the quality of the paths that are explored
Using good heuristic, we can hope to get good solutions to hard problem
It is possible to construct special-purpose heuristics that exploit domain-
specific knowledge to solve particular problems
Heuristic Search Compared with other Search
Heuristic Search
• A heuristic is a method that
-might not always find the best solution
-but is guaranteed to find a good solution in
reasonable time.
 By sacrificing completeness it increases efficiency.
 Useful in solving tough problems which
– could not be solved any other way.
– solutions take an infinite time or very long time to
compute.
• The classic example of heuristic search methods is
the travelling salesman problem.
Heuristic Search
• Traveling Salesman Problem
1. Arbitrarily select a starting city
2. To select the next city, look at all cities not
yet visited,
-select the one closest to the current city.
-Go to it next
3. Repeat step 2 until all cities have been visited
Heuristics Search Technique
Example of Heuristic Function

A heuristic function at a node n is an estimate of


the optimum cost from the current node to a goal.
It is denoted by h(n).
h(n) = estimated cost of the cheapest path from
node n to a goal node

Example 1: We want a path from Kolkata to Guwahati


Heuristic for Guwahati may be straight-line distance
between Kolkata and Guwahati
h(Kolkata) = euclideanDistance(Kolkata, Guwahati)
Heuristic Function
• A heuristic function is a function that maps from problem state
descriptions to measure of desirability, usually represented as numbers
-Which aspects of the problem state are considered?
-How those aspects are evaluated?
-The weights given to individual aspects are chosen in such a way that the
value of the heuristic function at a given node in the search process
gives as good an estimate as possible of whether that node is on the
desired path to a solution
 Well-designed heuristic functions can play an important part in
efficiently guiding a search process toward a solution
 The purpose of a heuristic function is to guide the search process in the
most profitable direction by suggesting which path to follow first when
more than one is available
 The more accurately the heuristic function estimates the true merits of
each node in the search tree/graph, the more direct the solution process
Greedy Best First Search
Idea: use an evaluation function f(n) for each node
f(n) provides an estimate for the total cost.
 Expand the node n with smallest f(n).

Implementation:
Order the nodes in fringe increasing order of cost.

 The algorithm maintains a priority queue of nodes to be


explored.
 A cost function f(n) is applied to each node.
 The nodes are put in OPEN in the order of their f values.
 Nodes with smaller f(n) values are expanded earlier. The
generic best first search algorithm is outlined below.
Algorithm:
Greedy Best First Search
 

Let fringe be a priority queue containing the initial state


Loop
if fringe is empty return failure
Node remove-first (fringe)
if Node is a goal
then return the path from initial state to Node
else generate all successors of Node, and
put the newly generated nodes into fringe
according to their f values
End Loop
Greedy best-first search
• Evaluation function f(n) = h(n) (heuristic)
• = estimate of cost from n to goal
e.g., hSLD(n) = straight-line distance from n to
Bucharest
• Greedy best-first search expands the node
that appears to be closest to goal
Goal state

initial state
Greedy Best‐First Search
• f(n) = h(n) : Expand node that appears to be
closest to the goal
Greedy Best‐First Tree Search Example
• Go from Arad to Bucharest
• f(n) = hSLD(n) = straight‐line distance from
n.STATE to Bucharest h (n)

SLD
234
Greedy Best‐First Tree Search Example

h (n)
Greedy Best‐First Tree Search Example

h (n)
Greedy Best‐First Tree Search Example

h (n)

h=176

h=193
Greedy Best‐First Tree Search Example

h (n)
Greedy Best‐First Tree Search Example

Solution turns out


not to be optimal

Optimal solution
Properties of greedy best-first search
Complete? No – can get stuck in loops, e.g., Iasi
 Neamt  Iasi  Neamt 
• Complete in finite space with repeated-state
checking
• Time? O(bm), but a good heuristic can give
dramatic improvement
• Space? O(bm) -- keeps all nodes in memory

• Optimal? No
Figure 2 is an example of a route finding problem. S is the starting state, G is the goal state.

Figure 2

Let us run the greedy search algorithm for the graph given in Figure 2.
The straight line distance heuristic estimates for the nodes are shown
in Figure
Figure 3
Step 1: S is expanded. Its children are A and D.

Step 2: D has smaller cost and is expanded next.


A* search
• Idea: avoid expanding paths that are already expensive
- include cost of reaching node
Evaluation function f(n) = g(n) + h(n)
-g(n) = cost of reaching n (sum of edge costs from start to n
(distance current node from start)
-h(n) = estimate of lowest cost path from goal to current node n.
-f(n) = estimated cost of the cheapest path to a goal state that
goes through path of n
.
Best First search has f(n)=h(n)
The A* Algorithm
 Input:
– QUEUE: Path only containing root
 Algorithm:
– WHILE (QUEUE not empty && first path not reach goal) DO
 Remove first path from QUEUE
 Create paths • to all children
 Reject paths with loops
 Add paths and sort QUEUE (by f = cost + heuristic)
 IF QUEUE contains paths: P, Q
AND P ends in node Ni && Q contains node Ni
AND cost_P ≥ cost_Q
THEN remove P
– IF goal reached THEN success ELSE failure
A* Search
• f(n) = g(n) + h(n) : Expand node that appears
to be on cheapest paths to the goal
A* search example

• Go from Arad to Bucharest


• f(n) = g(n) + hSLD(n)
A* search example

h(n)
A* search example

h(n)
A* search example

h(n)
h(n)
h(n)
Solution is optimal!
is this a coincidence?

No, when h(n)


underestimates the cost
of reaching a goal, A* (tree
search) is optimal
Admissible Heuristics
• A heuristic h(n) is admissible if for every node n,
h(n) ≤ h*(n), where h*(n) is the minimum/true cost to
reach the goal state from n

• An admissible heuristic never overestimates the cost to


reach the goal, i.e., it is optimistic
• Example: hSLD(n) (never overestimates the actual road
distance)

• Theorem: If h(n) is admissible, A* using TREE-SEARCH


is optimal
Admissible heuristics
• E.g., for the 8-puzzle:
Manhattan distance
• h1(n) = number of misplaced tiles
• h2(n) = total Manhattan distance
(no. of squares from desired location of each tile)

h1(S) =?? h1(S) =?? 6


h2(S) =?? h2(S) =?? 4+0+3+3+1+0+2+1 = 14
Optimality of A (proof) *
-Suppose some suboptimal goal G2 has been generated and
is in the fringe. Let n be an unexpanded node in the fringe
such that n is on a shortest path to an optimal goal G.
f(G2) = g(G2) + h(G2) = g(G2) > C*
f(G) = g(G) + h(G) = g(G) C*

• f(G2) = g(G2) since h(G2) = 0


• g(G2) > g(G) since G2 is suboptimal
• f(G) = g(G) since h(G) = 0
• f(G2) > f(G) from above
Optimality of A (proof)*

• h(n) ≤ h^*(n) since h is admissible


• g(n) + h(n) ≤ g(n) + h*(n)
• f(n) ≤ f(G)

Hence f(G2) > f(n), and A* will never select G2 for


expansion
Properties of A
• Complete?? Yes, unless there are infinitely many
nodes with f ≤ f(G)
• Time?? Exponential in [relative error in h x length of soln.]
• Space?? Keeps all nodes in memory
• Optimal?? Yes-cannot expand fi+1 until fi is finished
 A expands all nodes with f(n) < C*
 A expands some nodes with f(n) = C*
 A expands no nodes with f(n) > C*
Proof of lemma: Consistency
• A heuristic is consistent if
h(n) ≤ c(n,a,n') + h(n')
• If h is consistent, we have
f(n') = g(n') + h(n')
= g(n) + c(n,a,n') + h(n')
≥ g(n) + h(n)
= f(n)
i.e., f(n) is non decreasing along any path.
Theorem: If h(n) is consistent, A* using GRAPH-SEARCH is optimal
Relaxed Problems
• A problem with fewer restrictions on the actions is called a
relaxed problem
• The cost of an optimal solution to a relaxed problem is an
admissible heuristic for the original problem
• Admissible heuristics can be derived from the exact solution
cost of a relaxed version of the problem
• Example:
 If the rules of the 8-puzzle are relaxed so that a tile can move
anywhere, then h1(n) gives the shortest solution
 If the rules are relaxed so that a tile can move to any adjacent
square, then h2(n) gives the shortest solution
• Key point: the optimal solution cost of a relaxed problem is no
greater than the optimal solution cost of the real problem
An alternative: IDA*
IDA* = Iterative Deepening A*
Performs a series of depth-first searches, each
with a certain cost cut-off.
When the f value for a node exceeds this cut-
off, then the search must backtrack.
If the goal node was not found during the search,
then more depth-first searches are conducted with
higher cut-offs until the goal is found.
IDA* Algorithm
 Iterativedeepening A* or IDA* is similar to iterative-deepening
depth-first, but with the following modifications:
The depth bound modified to be an f-limit

f-bound ôf(S)
• Algorithm:
– WHILE (goal is not reached) DO
• f-bound ôf-limitted_search(f-bound)
– Perform f-limited search with f-bound
(See next slide)
IDA* Algorithm
Problem
IDA* Search
IDA* Search
IDA* Search
IDA* Search
IDA* Search
IDA* Search
IDA* Search
IDA* Search
IDA* Search
IDA* Search
IDA* Search
IDA* Search
IDA* Search
IDA* Search
IDA* Search
IDA* Search
Why do we use IDA*?

IDA* is complete, optimal, and optimally efficient


(assuming a consistent, admissible heuristic), and
requires only a polynomial amount of storage in the
worst case:

IDA* uses very little


memory
SMA*
Simplified Memory Bounded A* is a
shortest path algorithm based on the A*
algorithm.
The main advantage of SMA* is that it uses a
bounded memory, while the A* algorithm
might need exponential memory.
All other characteristics of SMA* are
inherited from A*.
SMA* Algorithm
Optimizes A* to work within reduced memory
• Key Idea:
– IF memory full for extra node (C)
– Remove highest f-value leaf (A)
– Remember best-forgotten child in
each parent node (15 in S)

E.g. Memory of 3 nodes only


SMA* Algorithm
SMA* Algorithm
SMA* Algorithm
SMA* By Example
Perform SMA* (memory: 3 nodes) on the following figure.
SMA* By Example
SMA* By Example
SMA* By Example
SMA* By Example
SMA* By Example
SMA* By Example

6
SMA* By Example
SMA* By Example
SMA* By Example
Hill Climbing Search
 Hill Climbing is heuristic search used for mathematical optimization
problems in the field of Artificial Intelligence .

 Given a large set of inputs and a good heuristic function, it tries to find a
sufficiently good solution to the problem. This solution may not be the
global optimal maximum.

7
9
Hill Climbing
• It is simply a loop that continually moves in the direction of increasing value
that is uphil.
• It terminates when it reaches a peak where no neighbor has a higher value.
• Example: unfamiliar city, no map, you want to get downtown
• You simply aim for the tall buildings
• The algorithm does not maintain a search tree, so the data structure for the
current node need only record the state and the value of the objective
function.

• Does not look ahead beyond the immediate neighbors of the current state.
• Trying to find the top of Mount Everest in a thick fog while suffering from
amnesia
Features of Hill Climbing

Following are some main features of Hill Climbing Algorithm:


 Generate and Test variant: Hill Climbing is the variant of Generate and Test method. The
Generate and Test method produce feedback which helps to decide which direction to move in
the search space.

 Greedy approach: Hill-climbing algorithm search moves in the direction which optimizes the
cost.

 No backtracking: It does not backtrack the search space, as it does not remember the previous
states.

Types of Hill Climbing


 Simple hill Climbing:
 Steepest-Ascent hill-climbing:
 Stochastic hill Climbing: 81
Simple Hill Climbing
 It only evaluates the neighbor node state at a time and selects the first one which
optimizes current cost and set it as a current state.
It only checks it's one successor state, and if it finds better than the current state, then
move else be in the same state.
This algorithm has the following features:
 Less time consuming
 Less optimal solution and the solution is not guaranteed

Steepest-Ascent hill climbing


The steepest-Ascent algorithm is a variation of simple hill climbing algorithm. This
algorithm examines all the neighboring nodes of the current state and selects one
neighbor node which is closest to the goal state. This algorithm consumes more time as
it searches for multiple neighbors

Stochastic hill climbing:


Stochastic hill climbing does not examine for all its neighbor before moving. Rather,
this search algorithm selects one neighbor node at random and decides whether to
choose it as a current state or examine another state. 82
Simple Hill Climbing
1. Evaluate the initial state. If it is goal state quit;
2. otherwise current state is initial state.
2. Loop until a solution is found or there are
no new operators left to be applied in the current state
(a) Select a new operator for this state and generate a new state.
(b) Evaluate the new state
- if it is a goal state, then return it & quit
– if it is closer to goal state than current state make it current state
– if it is no better ignore & continue in the loop
 A vague question (Is one state is better than other?)
 Precise definition of better must be provided
Steepest-Ascent Hill Climbing
• Useful variation on simple hill climbing
• Considers all the moves from the current state
& selects the best one as the next state
• Steepest-ascent (act of climbing/moving up)
hill climbing or gradient search
Algorithm: Steepest-Ascent Hill Climbing
1. Evaluate the initial state. If it is also goal state, then return it & quit. Otherwise, continue with
the initial state as the current state
2. Loop until a solution is found or until a complete iteration procedure no change to current
state

(a) Let SUCC be a state such that any


possible successor of the current state
will be better than SUCC

(b) For each operator that applies to the


current state do:
- apply the operator & generate a new state
- evaluate the new state. If it is a good state, then return it
& quit. If not, compare it to SUCC. If it is better, then set
SUCC to this state. If it is not better, leaves SUCC alone

(c) if the SUCC is better than current state, then set current state to
SUCC
Advantages of Hill Climbing
 It can be used in continuous as well as discrete
domains.
Problems of Hill-climbing search
• Both basic & steepest-ascent hill climbing may
fail to find a solution
• Either algo may terminate not by finding a
goal state but by getting to a state from which
no better states can be generated.
• This will happen if the program reached either
a local maximum, a plateau, or a ridge
Local maximum

-Is a state that is better


than all its neighbors but
is not better than some
other states farther
away.
-At a local maximum, all
moves appear to make
things worse.
-Particularly frustrating
because they often occur
almost within sight of a Solution: Backtracking technique can be a
solution of the local maximum in state space
solution. In this case, landscape. Create a list of the promising path
they are called foothills. so that the algorithm can backtrack the search
space and explore other paths as well.
Plateau
-is a flat area of the search space in which a whole
set of neighboring state have the same value
-on a plateau, it is not possible to determine the best
direction in which to move by making local
comparisons
Ridge
-is a special kind of local maximum.
-it is an area of the search space that is higher than surrounding areas
& that itself has a slope
-but the orientation of the high region, compared to the set of
available moves & the directions in which they move, makes it
impossible to traverse a ridge by single moves.
Ways of dealing
1. Backtrack on some earlier node & try going in a different direction.
-this particularly reasonable if at that node there was another direction that looked as
promising/almost as promising as the one that was chosen earlier
-to implement this strategy, maintain a list of paths almost taken & go back to one of
them if the path that was taken leads to a dead end.
-good way of dealing with local maximum

2.Skip- Make a big jump in some direction to try to get a new section of the search
space.
-this is particularly good way of dealing with plateaus
-if the only rules available describe single small steps, apply several times in the same
direction

3. explore several directions to figure out the correct path


Apply 02/more rules before doing the test.
-this corresponds to moving in several directions at once.
-good for dealing with ridges
An Example: Block world Problem

• Heuristic function +1

Local: +1
+1
-add 1 point for every +1
block that is resting on +1
thing it is supposed to be +1
resting on. +1

-Subtract 1 point for every


block that is sitting on Total score= 8
the wrong thing
An Example: Block world Problem

-1
• Hill climbing will halt +1
+1
-because all these states +1 +1
+1 +1 +1
have lower scores +1 +1 +1
than the current state +1 +1 +1
+1 -1 +1 +1 -1 +1
-the process has -1 +1 -1 -1
reached a local
Score= 6-2=4 Score= 6-2=4
maximum that is not Score= 6-2=4

the global maximum


A hill climbing example (2)

 A local heuristic function


 Count +1 for every block that sits on the correct thing.
The goal state has the value +8.
 Count -1 for every block that sits on an incorrect thing.
In the initial state blocks C, D, E, F, G, H count +1 each.
Blocks A, B count -1 each , for the total of +4.
 Move 1 gives the value +6 (A is now on the correct
support). Moves 2a and 2b both give +4 (B and H are
wrongly situated). This means we have a local
maximum of +6.
Modify Heuristic Function
• Global: +7
-for each block that has correct +6
support structure (complete +5
structure underneath it is +4

exactly as it should be), add 1 +3

point for every block in the +2


+1
support structure
-for each block that has an
incorrect support structure, Total score= 28
subtract 1 point for every
block in the existing support
structure.
A hill climbing example (3)

A global heuristic function


Count +N for every block that sits on a correct stack of N
things. The goal state has the value +28.
Count -N for every block that sits on an incorrect stack of N
things. That is, there is a large penalty for blocks tied up in
a wrong structure.
In the initial state C, D, E, F, G, H count -1, -2,
-3, -4, -5, -6. A counts -7 , for the total of -28.
continued
A hill climbing example (4)

Move 1 gives the value -21 (A is now on the correct support).


Move 2 a gives -16, because C, D, E, F, G, H
count -1, -2, -3, -4, -5, -1.
Move 2b gives -15, because C, D, E, F, G
count -1, -2, -3, -4, -5.
There is no local maximum!
Moral: sometimes changing the heuristic function is all we
need.
Modify Heuristic Function
-7
• Move to (c) -6
• This function -5 -5 -5
-4 -4 -4
works proporly -3 -3 -3
-2 -2 -2
-1 -1 -1 -1

Score= -28 Score= -15-1=-16 Score= -15


Simulated annealing search
• This is a variation on hill climbing in which at the beginning of the
process, some downhill moves may be made
• Idea: escape local maxima by allowing some "bad" moves but
gradually decrease their frequency
• There are two additional changes;
- we use the term objective function rather than heuristic function
- we go for minimize rather than maximize the value of objective
function
 valley descending rather than hill climbing.
 Widely used in VLSI layout, airline scheduling, etc
Physical Phenomenon

• Simulated annealing as a computational process is


patterned after the physical processing of annealing, in
which physical substances (metals) are melted (raised to
high energy levels) and then gradually cooled until some
solid state is reached
• The goal of this process is to produce a minimal-energy
final state.
• Thus this process is one of valley descending in which the
objective function is the energy level
• Physical substances usually move from higher energy
configurations to lower ones, so the valley descending
occurs naturally
Simulated annealing search
• The probability, p
p  e  E / kT
E  ( Ei  Ej ) : positive change in the energy level
T : temperatu re
k : Boltzmann' s Constant

• Thus, in the physical valley descending that


occurs during annealing, the probability of a large
uphill move is lower than the probability of a
small one.
• Also, the probability that an uphill move will be
made decreases as the temp decreases.
Annealing schedule
• The rate at which the system is cooled is called the
annealing schedule
• Physical annealing processes are very sensitive to the
annealing schedule
• If cooling occurs too rapidly, stable regions of high
energy will form
• In other words, a local but not global minimum is
reached
• The optimal annealing schedule for each particular
annealing problem must be discovered empirically
Simulated annealing search
Difference from simple Hill Climbing

1. the annealing schedule must be maintained


2. moves to worse states may be accepted
• It is a good idea to maintain, current state, the
best state found so far.
• Then, if the final state is worse than that
earlier state, the earlier state is still available
Algorithm: Simulated Annealing
1. Evaluate the initial state. If it is goal state, then quit. otherwise make the current state
this initial state and proceed.
2. Initialize BEST-So-Far  to current state
3. Set temperature, T, according to the annealing schedule
4. Loop until a solution is found.
(a) select an operator that has not yet been applied to the current state & apply it to
produce a new state
(b) Evaluate the new state. Compute
E=(value of current)-(value of new state)
-if the new state is a goal state, then return it & quit
-if it is not a goal state but better than the current circuit, then make it current state. Set
BEST-SO-FAR to this new state
-if it is not better than the current state, then make it current state with probability p`. This
step is usually implemented by invoking a random number generator to produce a
number in the range [0, 1]. If that number is less than p`, then the move is accepted.
Otherwise, do nothing
(c) Revise T as necessary according to the annealing schedule
5. Return BEST-SO-FAR as the answer
SA Steps
• Algorithm
• Step 1 − Generate a random solution.
• Step 2 − Calculate its cost using some cost function.
• Step 3 − Generate a random neighboring solution.
• Step 4 − Calculate the new solution cost by the same cost function.
• Step 5 − Compare the cost of a new solution with that of an old
solution as follows −
• If CostNew Solution < CostOld Solution then move to the new solution.
• Step 6 − Test for the stopping condition, which may be the maximum
number of iterations reached or get an acceptable solution.
SA Steps
• Algorithm
• Step 1 − Generate a random solution.
• Step 2 − Calculate its cost using some cost function.
• Step 3 − Generate a random neighboring solution.
• Step 4 − Calculate the new solution cost by the
same cost function.
• Step 5 − Compare the cost of a new solution with
that of an old solution as follows −
• If CostNew Solution < CostOld Solution then move to the new
solution.
• Step 6 − Test for the stopping condition, which may
be the maximum number of iterations reached or
get an acceptable solution.
SA use in ANN
 SA is a stochastic computational method, inspired by
Annealing analogy, for approximating the global
optimization of a given function.
 We can use SA to train feed-forward neural networks.
Properties of simulated annealing
• At fixed “temperature” T, state occupation
probability reaches Boltzman distribution
E(x)

p ( x )  e kT

• T decreased slowly enough  always reach


best state x*
• Because E kT( x *) EkT( x ) E ( x *) E ( x )

e /e e  1 for small T
kT

• Is this necessarily an interesting guarantee??


WHAT IS GENETIC
ALGORITHM?

 A genetic algorithm is a heuristic search method used in artificial


intelligence and computing.

 It is used for finding optimized solutions to search problems based


on the theory of natural selection and evolutionary biology
Search Space
 The GA aims to use selective `breeding' of the solutions to
produce `offspring' better than the parents by combining
information from the chromosomes.

The GA maintains a population of n chromosomes (solutions) with associated fitness values.


Parents are selected to mate, on the basis of their fitness, producing offspring via a reproductive
plan. Consequently highly fit solutions are given more opportunities to reproduce, so that
offspring inherit characteristics from each parent. As parents mate and produce offspring, room
must be made for the new arrivals since the population is kept at a static size. Individuals in the
population die and are replaced by the new solutions, eventually creating a new generation once
all mating opportunities in the old population have been exhausted. In this way it is hoped that
over successive generations better solutions will thrive while the least fit solutions die out.
Introduction to Genetic Algorithms 113
Implementation Details
Based on Natural Selection
After an initial population is randomly generated, the algorithm
evolves the through three operators:

1. selection which equates to survival of the fittest;


2. crossover which represents mating between individuals;
3. mutation which introduces random modifications.

Introduction to Genetic Algorithms 114


1. Selection Operator

• Selection replicates the most successful solutions found


in a population at a rate proportional to their relative
quality.
• key idea: pass on their genes to the next generation.
• The goodness of each individual depends on its fitness.
• Fitness may be determined by an objective function or by
a subjective judgment.

Introduction to Genetic Algorithms 115


2. Crossover Operator
• Recombination/Crossover decomposes two distinct solutions and then
randomly mixes their parts to form novel solutions

• Prime distinguished factor of GA from other optimization techniques


• Two individuals are chosen from the population using the selection
operator
• A crossover site along the bit strings is randomly chosen
• The values of the two strings are exchanged up to this point
• If S1=000000 and s2=111111 and the crossover point is 2 then S1'=001111
and s2'=110000
• The two new offspring created from this mating are put into the next
generation of the population
• By recombining portions of good individuals, this process is likely to create
even better individuals

Introduction to Genetic Algorithms 116


2. Crossover Operator

Introduction to Genetic Algorithms 117


3. Mutation Operator
• Mutation randomly perturbs a candidate solution
• With some low probability, a portion of the new
individuals will have some of their bits flipped.
• Its purpose is to maintain diversity within the
population and inhibit premature convergence.
• Mutation alone induces a random walk through the
search space
• Mutation and selection (without crossover) create a
parallel, noise-tolerant, hill-climbing algorithms

Introduction to Genetic Algorithms 118


3. Mutation Operator

Introduction to Genetic Algorithms 119


Effects of Genetic Operators
Using selection alone will tend to fill the
population with copies of the best individual
from the population
Using selection and crossover operators will
tend to cause the algorithms to converge on a
good but sub-optimal solution
Using mutation alone induces a random walk
through the search space.
Using selection and mutation creates a parallel,
noise-tolerant, hill climbing algorithm
Introduction to Genetic Algorithms 120
Simple Genetic Algorithm

1. randomly initialize population(t)


2. determine fitness of population(t)
3. repeat
1. select parents from population(t)
2. perform crossover on parents creating
population(t+1)
3. perform mutation of population(t+1)
4. determine fitness of population(t+1)
4. until best individual is good enough
Introduction to Genetic Algorithms 121
Figure 1: A flowchart of working principle of a genetic algorithm

Introduction to Genetic Algorithms 122


Advantages of GA

 GA have various advantages which have made them immensely


popular. These include −
 Does not require any derivative information (which may not be
available for many real-world problems).
 Is faster and more efficient as compared to the traditional methods.
 Has very good parallel capabilities.
 Optimizes both continuous and discrete functions and also multi-
objective problems.
 Provides a list of “good” solutions and not just a single solution.
 Always gets an answer to the problem, which gets better over the
time.
 Useful when the search space is very large and there are a large
number of parameters involved.
Problem:
• The three major operation in genetic algorithm. The
initial population in

(a)Is ranked by the fitness function


(b)Resulting in pairs for mating
(c)They produce offspring
(d)Which are subject to mutation
(e)Th -15
solve
• Figure 4.15 The genetic algorithm.
• The initial population in (a)
• is ranked by the fitness function in (b),
• resulting in pairs for mating in (c).
• They produce offspring in (d),
• which are subject to mutation in (e).

• Each state, or individual, is represented as a string over a finite alphabet-most


• Total non-attacking pair: 24+23+20+11=78
• Th-15, last number not count because 11 less
than 15.
• Now—
1. (24/78)*100% = 31%
2.(23/78)*100% =29%
3.(20/78)* 100% = 26%
Genetic Algorithms
The production of the next generation of states is shown in Figure 4.15(b)-(e).

In (b), each state is rated by the evaluation function or (in C;A terminology) the fitness
function.

A fitness function should return higher values for better states, so, for the 8-queens problem we
use the number of non attacking pairs of queens, which has a value of 28 for a solution.
The values of the four states are 24, 23, 20, and 11. I in this particular variant of the genetic
algorithm, ithe probability of being chosen for reproducing is directly proportional to the
fitness score, and the percentages are shown next to the raw score

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

For each pair to be mated, a crossover point is randomly chosen from the positions in the string.
In Figure 4.15 the crossover points are after the third digit in the first pair and after the fifth digit
in the second pair

In (d), the offspring themselves are created by crossing over the parent strings at the
crossover point. For example, the first child of the first pair gets the first three digits from the
first parent and the remaining digits from the second parent, whereas the second child gets the
129
first three digits from the second parent and the rest from the first parent
When to Use Genetic Algorithms ?

GAs are not good for all kinds of problems. They’re best for problems where there is
a clear way to evaluate fitness. If your search space is not well constrained or your
evaluation process is computationally expensive, GAs may not find solutions in a
sane amount of time. In my experience, they’re most helpful when there is a decent
algorithm in place, but the “knobs” just need to be tweaked.
Limitations of GA

• Like any technique, GA also suffer from a few


limitations. These include −
• GAs are not suited for all problems, especially
problems which are simple and for which derivative
information is available.
• Fitness value is calculated repeatedly which might
be computationally expensive for some problems.
• Being stochastic, there are no guarantees on the
optimality or the quality of the solution.
• If not implemented properly, the GA may not
converge to the optimal solution.

You might also like