heuristic search

HEURISTIC
SEARCH
(INFORMED SEARCH)
1
HEURISTICS
 From Greek heuriskein, “to find”.
 Of or relating to a usually speculative formulation
serving as a guide in the investigation or solution
of a problem.
 Computer Science: Relating to or using a
problem-solving technique in which the most
appropriate solution, of several found by
alternative methods, is selected at successive
stages of a program for use in the next step of
the program.
2
HEURISTICS
 the study of methods and rules of discovery and
invention.
 In state space search, heuristics are formalized
as rules for choosing those branches in a state
space that are most likely to lead to an
acceptable problem solution.
3
HEURISTIC SEARCH
Introduction:
• Al problem solvers employ heuristics in two
situations:– First: A problem may not have an exact
solution, because of inherent ambiguities in
the problem statement or available data.
• Medical diagnosis is an example of this. A
given set of symptoms may have several
possible causes. Doctors use heuristics to chose
the most likely diagnosis and formulate a plan of
treatment.
4
HEURISTIC SEARCH
Introduction:
• Al problem solvers employ heuristics in two
situations:– First: A problem may not have an exact
solution, because of inherent ambiguities in
the problem statement or available data.
• Vision is another example of an inherently
inexact problem.
• Visual scenes are often ambiguous, allowing
multiple interpretations of the connectedness,
extent and orientation of objects.
5
HEURISTIC SEARCH
Introduction:
• Al problem solvers employ heuristics in two
situations:– First: A problem may not have an exact
solution, because of inherent ambiguities in
the problem statement or available data.
• Optical illusions exemplify these ambiguities.
• Vision systems use heuristics to select the most
likely of several possible interpretations of a
given scene.
6
HEURISTIC SEARCH
Introduction:
• Al problem solvers employ heuristics in two
situations:– Second: A problem may have an exact
solution, but the computational cost of
finding it may be prohibitive.
• In many problems, state space growth is
combinatorially explosive, with the number of
possible states increasing exponentially or
factorially with the depth of the search.
7
HEURISTIC SEARCH
Introduction:
• Al problem solvers employ heuristics in two
situations:– Second: A problem may have an exact
solution, but the computational cost of
finding it may be prohibitive.
• Heuristic search handles above problem by
guiding the search along the most “promising”
path through the space.
8
HEURISTIC SEARCH
Introduction:
• Al problem solvers employ heuristics in two
situations:– Second: A problem may have an exact
solution, but the computational cost of
finding it may be prohibitive.
• By eliminating unpromising states and their
descendants from consideration, a heuristic
algorithm can defeat this combinatorial explosion
and find an acceptable solution.
9
HEURISTIC SEARCH
Introduction:
• Heuristics and the design of algorithms to
implement heuristic search have been an
important part of artificial intelligence research.
• Game playing and theorem proving require
heuristics to reduce search space to simplify the
solution finding.
10
HEURISTIC SEARCH
Introduction:
• It is not feasible to examine every inference that
can be made in search space of reasoning or
every possible move in a board game to reach
to a solution. In this case, heuristic search
provides a practical answer.
11
HEURISTIC SEARCH
Introduction:
• Heuristics are fallible.
– A heuristics is only an informed guess of the
next step to be taken in solving a problem. It
is often based on experience or intuition.
– Heuristics use limited information, such as
the descriptions of the states currently on
the OPEN List.
12
HEURISTIC SEARCH
Introduction:
• Heuristics are fallible.
– Heuristics are seldom able to predict the
exact behavior of the state space farther
along in the search.
– A heuristics can lead a search algorithm to a
sub optimal solutions.
– At times a heuristic method may fail to find
any solution at all.
13
Tic-Tac-Toe
• The combinatorics for
exhaustive search are high.
– Each of the nine first
moves has eight
possible responses.
– which in turn have seven
continuing moves, and
so on.
– As simple analysis puts
exhaustive search at 9 x
8 x7x … or 9!.
14
Tic-Tac-Toe
• Symmetry reduction can
decrease the search space,
there are really only three
initial moves.
– To a corner.
– To the center of a side.
– To the center of the grid.
15
Tic-Tac-Toe
Symmetry reductions on the second level of states further reduce the
number of possible paths through the space. In following figure the
search space is smaller then the original space.
16
Tic-Tac-Toe
• Most Win Heuristics
– Algorithm analys the moves in which X has the
most winning lines.
– Algorithm then selects and moves to the state with
the highest heuristic value i.e. X takes the center
of the grid.
17
Tic-Tac-Toe
• Most Win Heuristics
– Other alternatives and their descendants are
eliminated.
– Approximately two-thirds of the space is pruned
away with the first move .
18
Tic-Tac-Toe
• Most Win Heuristics
– After the first move, the
opponent can choose
either of two alternative
moves.
19
Tic-Tac-Toe
• Most Win Heuristics
– After the move of opponent,
The heuristics can be applied
to the resulting state of the
game.
– As search continues, each
move evaluates the children
of a single node: exhaustive
search is not required.
– Figure shows the reduced
search after three steps in
the games (States are
marked with their heuristics
values).
20
Tic-Tac-Toe
• COMPLEXITY
– It is difficult to compute the exact number
of states that must be examined. However,
a crude upper bound can be computed by
assuming a maximum of nine moves in a
game and eight children per move.
21
Tic-Tac-Toe
• COMPLEXITY
– In reality:
• The number of states will be smaller, as
board fills and reduces our options.
• In addition opponent is responsible for
half the moves.
• Even this crude upper bound of 8 x 9 or
72 states is an improvement of four
orders of magnitude over 9!.
22
ALGORITHM FOR HEURISTICS
SEARCH
Best-First-Search
• Best first search uses lists to maintain states:
– OPEN LIST to keep track of the current fringe of
the search.
– CLOSED LIST to record states already visited.
• Algorithm orders the states on OPEN according to
some heuristics estimate of their closeness to a
goal.
23
ALGORITHM FOR HEURISTICS
SEARCH
Best-First-Search
• Each iteration of the loop consider the most
promising state on the OPEN list.
• Algorithm sorts and rearrange OPEN in precedence
of lowest heuristics value.
24
BEST-FIRST-SEARCH
25
BEST-FIRST-SEARCH
• At each iteration best-first–search removes the first
element from the OPEN list. If it meets the goal
conditions, the algorithm returns the solution path
that led to the goal.
• Each state retains ancestor information to determine
if it had previously been reached by a shorter path
and to allow the algorithm to return the final solution
path.
• If the first element on OPEN is not a goal, the
algorithm generate its descendants.
26
BEST-FIRST-SEARCH
• If a child state is already on OPEN or CLOSED, the
algorithm checks to make sure that the state records
the shorter of the two partial solution paths.
• Duplicate states are not retained.
• By updating the ancestor history of nodes on OPEN
and CLOSED when they are rediscovered, the
algorithm is more likely to find a shorter path to a
goal.
27
BEST-FIRST-SEARCH
• Best-first-search applies a heuristic evaluation to the
states on OPEN, and the list is sorted accordingly to
the heuristic values of those states. This brings the
best states to the front of OPEN .
• Because these estimates are heuristic in nature, the
next state to be examined may be from any level of
the state space. When OPEN is maintained as a
sorted list, it is referred to as a priority queue.
28
BEST-FIRST-SEARCH
A HYPOTHETICAL SEARCH SPACE
29
BEST-FIRST-SEARCH
TRACES OF OPEN AND CLOSED LISTS
30
BEST-FIRST-SEARCH
Heuristic search of a
hypothetical state space with
OPEN and CLOSED states
highlighted.
31
BEST-FIRST-SEARCH
• The goal of best–first search is to find the goal state
by looking at as few states as possible: the more
informed the heuristic, the fewer states are
processed in finding the goal.
• The best-first search algorithm always selects the
most promising states on OPEN for further
expansion.
• It does not abandon all the other states but maintains
them on OPEN .
32
BEST-FIRST-SEARCH
• In the event when a heuristic leads the search down
a path that proves incorrect, the algorithm will
eventually retrieve some previously generated next
best state from OPEN and shift its focus to another
part of the space.
• In the example after the children of state B were
found to have poor heuristic evaluations, the search
shifted its focus to state C.
• In best-first-search the OPEN list allows
backtracking from paths that fail to produce a goal.
33
IMPLEMENTING HEURISTIC EVALUATION FUNCTIONS
• Performance of
various heuristics is
evaluated for solving
the 8-puzzle.
• Figure shows a start
and goal state for the
8-puzzle, along with
the first three states
generated in the
search.
34
IMPLEMENTING HEURISTIC EVALUATION FUNCTIONS
• Heuristic 1
– The simplest heuristic, counts the tiles out of place in
each state when it is compared with the goal.
– The state that had fewest tiles out of place is probably
closer to the desired goal and would be the best to
examine next.
– However, this heuristic does not use all of the information
available in a board configuration, because it does not
take into account the distance the tiles must be moved.
35
IMPLEMENTING HEURISTIC EVALUATION FUNCTIONS
• Heuristic 2
– A “better” heuristic would sum all the
distances by which the tiles are out of place,
one for each square a tile must be moved to
reach its position in the goal state.
36
IMPLEMENTING HEURISTIC EVALUATION FUNCTIONS
• Heuristic 3
– Above two heuristics fail to take into account the problem
of tile reversals.
– If two tiles are next to each other and the goal requires
their being in opposite locations, it takes more than two
moves to put them back to place, as the tiles must “go
around” each other.
– A heuristic that takes this into account multiplies a small
number (2 , for example) times each direct title reversal.
37
IMPLEMENTING HEURISTIC EVALUATION FUNCTIONS
38
IMPLEMENTING HEURISTIC EVALUATION FUNCTIONS
• The “sum of distances” heuristic provides a
more accurate estimate of the work to be
done than the “number of titles out of place”
heuristic.
• Title reversal heuristic gives out an
evaluation of ‘0’ since non of these states
have any direct tile reversals.
39
IMPLEMENTING HEURISTIC EVALUATION FUNCTIONS
• Good Heuristics
– Good heuristics are difficult to devise.
Judgment and intuition help, but the final
measure of a heuristic must be its actual
performance on problem instances.
– Each heuristic proposed above ignores
some critical information and needs
improvement.
40
IMPLEMENTING HEURISTIC EVALUATION FUNCTIONS
• Devising A Good Heuristic
– The distance from the starting state to its
descendants can be measured by maintaining a
depth count for each state. This count is ‘0’ for the
beginning state and may be incremented by 1 for
each level of the search.
– It records the actual number of moves that have
been used to go from the starting state in the
search space to each descendant.
41
IMPLEMENTING HEURISTIC EVALUATION FUNCTIONS
• Devising A Good Heuristic
– Let evaluation function f(n), be the sum of two
components:
f(n) = g(n) + h(n)
– Where:
• g(n) measures the actual length of the path from
start state to any state n.
• h(n) is a heuristic estimate of the distance from the
state n to a goal.
42
IMPLEMENTING HEURISTIC EVALUATION FUNCTIONS
h(n) = 5
h(n) = 3
h(n) = 5
43
• Each state is labeled with a letter and its
heuristic weight, f(n) = g(n) + h(n).
• The number at the top
of each state indicates
the order in which it
was taken off the
OPEN list.
44
Successive stages of OPEN and CLOSED that generates the
graph are:
45
46
IMPLEMENTING HEURISTIC EVALUATION FUNCTIONS
• The g(n) component of the evaluation function gives
the search more of a breadth-first flavor.
• This prevent it from being misled by an erroneous
evaluation, If a heuristic continuously returns “good”
evaluations for states along a path that fails to reach
a goal, the g value will grow to dominate h and force
search back to a shorter solution path.
• This guarantees that the algorithm will not become
permanently lost, descending an infinite branch.
47
ADMISSIBILITY MEASURES
•
A search algorithm is admissible if it is guaranteed to find a minimal path
to solution, whenever such a path exists.
•
Breadth-first search is an admissible search strategy .
• In determining the properties of admissible heuristics, we define
an evaluation function f*.
f*(n) = g*(n) + h*(n)
Let:
f(n) = g(n) + h(n)
Let:
f*(n) = g*(n) + h*(n)
• g(n) measures the depth(cost) at which
state n has been found in the graph.
• g*(n) is the cost of the shortest path
from the start node to node n
• h(n) is the heuristic estimate of the cost
from n to a goal.
• h*(n) returns the actual cost of the
shortest path from n to the goal.
• f(n) is the estimate of total cost of the
path from the start state through node n
to the goal state.
• f*(n) is the actual cost of the optimal
path from a start node through node
n to a goal node.
48
ADMISSIBILITY MEASURES
• In an algorithm A, Ideally function f should be a close
estimate of f*.
– The cost of the current path, g(n) to state n, is a reasonable estimate of g*(n).
Where:
g(n)  g*(n).
– These are equal only if the search has discovered the optimal path to state n.
• Similarly, compare h*(n) with h(n).
• h(n) is bounded from above by h*(n) i.e, h(n) is always less
than or equal to the actual cost of a minimal path h*(n) i.e.
h(n)  h*(n).
• If algorithm A uses an evaluation function f in which h(n) 
h*(n), the algorithm is called algorithm A*.
49
The heuristic of counting the number of tiles out of place is certainly
less than or equal to the number of moves required to move them to
their goal position. Thus this heuristic is admissible and guarantees an
optimal solution path.
h(n)
h*(n)
50
•Comparison of
search using
heuristics with
search by breadthfirst search.
•Heuristic used is
f(n) = g(n) + h(n)
where h(n) is tiles
out of place.
The portion of the
graph searched
heuristically is
shaded. The
optimal solution
path is in bold.
51
• If breadth first search is considered a A*
algorithm with heuristic h1, then it must be less
than h* (as breadth first search is admissible).
• Also number of tiles out of place with respect
to goal state is a heuristic h2. As this is also
admissible therefore, h2 is less than h*.
52
• In this case h1  h2  h*. It follows that the
number of tiles out of place heuristic is more
informed than breadth-first search.
• Both h1 and h2 find the optimal path, but h2
evaluates many fewer states in the process.
• Similarly the heuristic that calculates the sum
of the direct distances by which all the tiles
are out of place is again more informed than the
calculation of the number of tiles out of place
with respect to the goal state.
53
• If a heuristic h2 is more informed then h1 then
the set of states examined by h2 is a subset of
those examined by h1.
• In general, more informed an A* algorithm
the less of the space it needs to expand to
get the optimal solution.
54
OPTIMIZATION IN SEARCH
• Optimization Problems:
– Trying to find a schedule for flights to minimize
congestion at an airport.
– To find a lowest cost route in case of Traveling
Sales Person Problem.
• Typically in most optimization problems the
branching factor is very large.
• Best First Search become inefficient and
slows down because it has to store so many
nodes to keep track of what nodes to explore
next.
55
OPTIMIZATION IN SEARCH
• We need to find a solution to go round
the problem.
• Use algorithms which do not store
nodes which have earlier been rejected
because they did not meet heuristic
merit.
56
HILL CLIMBING SEARCH
• A variation of Best First Search.
• Uses heuristic evaluation function for
comparison of states.
• Do not store nodes which earlier have been
rejected on the basis of heuristic merit.
• Two types:
– Simple Hill Climbing Search.
– Steepest Ascent Hill Climbing Search.
57
SIMPLE HILL CLIMBING
• Use heuristic to move to states that are
better than the current state.
• Always move to better state when
possible.
• The process ends when all operators
have been applied and none of the
resulting states are better than the
current state.
58
SIMPLE HILL CLIMBING
Heuristic Merit: A state having larger heuristic
evaluation is selected.
4
3
Local
Maximum
5
7
3
6
4
?
?
?
?
5
?
?
?
?
?
?
Goal
59
SIMPLE HILL CLIMBING
Potential Problems
• Search terminates when a local maximum is
found.
• The order of application of operators can
make a difference.
• Can’t see past a single move in the state
space.
60
HILL CLIMBING TERMINATION
• Both simple and steepest ascent hill climbing
may fail to find a solution.
• Either algorithm may terminate not by finding a
goal state but by getting to a state from which
no better states can be generated.
• This happens if the program has reached:
– A local maximum.
– A plateau.
– Or a ridge.
61
HILL CLIMBING TERMINATION
• Local Maximum: all
neighboring states
are worse.
• Plateau - all
neighboring states
are the same as the
current state.
• Ridge - local
maximum that is
caused by inability to
apply 2 operators at
once.
10
6
4
5
9
9
9
9
9
6
10
8
15
7
12
62
HILL CLIMBING TERMINATION
Techniques for Dealing With the Problems of
Local Maximum, Plateau and Ridge.
• Backtrack and try going in some other direction. To
implement this strategy maintain a list of paths.
Particularly suitable for Local maximum Problems.
• Make a big jump in some other direction in order to try to
get to a new section of the search space. If the rules
available describe single small steps , apply them
several times in the same direction. Particularly suitable
for dealing with Plateaus.
• Apply two or more rules before comparing heuristic
evolutions. Particularly good strategy for dealing with
ridges.
63
HILL CLIMBING
• Hill climbing is intrinsically a local method i.e.
it decides what to do next by looking only at
the immediate consequences of its choice.
• The heuristic used by a hill climbing algorithm
does not need to be a static function of a
single state.
• Therefore information in the global context
may be encoded in the heuristic function. So
that the heuristic can look ahead many states.
64
HILL CLIMBING
• Main advantage of Hill Climbing Search
methods is that it is less combinatorially
explosive.
• Main disadvantage is the lack of
guarantee that it will be effective.
65
ADVERSARY
SEARCH
66
MINIMAX
PROCEDURE
67
HEURISTICS IN GAMES
The Minimax Procedure
• Applicable to two person games.
• Such games are complicated to program
because of a “hostile and an unpredictable”
opponent.
• The problem is characterized as
systematically searching the space of:– Own possible moves.
– And countermoves by the opponent.
• Because of enormity of the search space, the
game player must use heuristics to guide play
along a path to a winning state.
68
MINIMAX PROCEDURE
A Game Called NIM
•State space can be exhaustively
searched.
•A pile of token is placed on table.
•At each move the player must divide
the pile into piles of different sizes.
•New piles must not hold equal number
of tokens.
•The player who no longer makes a
legal move losses the game.
•Figure: A space for a game with 7
tokens.
69
MINIMAX PROCEDURE
A Game Called NIM
•Main difficulty is the accounting
for the actions of the opponent.
•The opponents in a game are
referred to as the MIN and MAX.
•Max: A player trying to win.
•Min: A player trying to minimize
the score of MAX.
•Each level in the search space is
labeled according to whose move
it is at that point in the game.
•Each leaf node is given a value
I or 0 (win for MAX or win for MIN)
70
MINIMAX PROCEDURE
A Game Called NIM
•MINIMAX propagates I or 0 up
the graph through parent
nodes according to rules:
• Parent state is MAX: Give the
parent maximum value of its
children.
• Parent state is MIN: Give the
parent minimum value of its
children.
•These derived values are then
used to choose among possible
moves.
71
MINIMAX PROCEDURE
Minimaxing to Fixed Ply Depth
• N-Ply Look Ahead: For games having large state
space, exhaustive search is not possible.
• In such games state space is searched by levels or ply.
• Game playing programs typically look ahead a fixed ply
depth.
• The states on that ply are measured heuristically and the
values are propagated back up the graph using MINIMAX.
• The search algorithm then uses these derived values to
select among possible moves.
72
MINIMAX PROCEDURE
Fixed Depth MINIMAX
•Evaluations are assigned to
each state on the ply.
•These values are then
propagated up to each parent
node.
•If the parent is on the MIN
level, then the minimum value
MINIMAX with a 4-ply look ahead
of the children is backed up.
73
MINIMAX PROCEDURE
Fixed Depth MINIMAX
•If the parent is on the MAX
level, then the maximum
value of the children is backed
up.
•This way the values backed
up the graph to the children
of the current state.
•Values are then used by
current state to select among
MINIMAX with a 4-ply look ahead
its children.
74
MINIMAX PROCEDURE
Nature of Heuristics in Game Playing:
• Each player attempts to overcome the other.
• Heuristics can measure the advantage of one
player over another.
• In Chess:
– A Simple Heuristic: Piece advantage is important,
so a simple heuristic takes the difference in the
number of pieces belonging to MAX and MIN
– Then it tries to maximize the difference between
these piece measures.
75
MINIMAX PROCEDURE
Nature of Heuristics in Game Playing:
• Each player attempts to overcome the other.
• Heuristics can measure the advantage of one
player over another.
• In Chess:
– A Sophisticated Heuristic: Assign different values
to the pieces:
• Depending on their values (Queen, Pawn or King).
• Depending on their locations on the board.
76
HEURISTIC FOR TIC-TAC-TOE
Two Ply MINIMAX
• Heuristic attempts to
measure the conflict in
the game.
• Counts all winning lines
open to MAX.
• Subtract the winning
lines available to MIN.
• Attempts to maximize
this difference though
search.
77
HEURISTIC FOR TIC-TAC-TOE
MAX
MIN
MAX
TWO-PLY MINIMAX: APPLIED TO THE OPENING MOVE
78
HEURISTIC FOR TIC-TAC-TOE
MAX
MIN
MAX
79
TWO-PLY MINIMAX: ONE OF TWO POSSIBLE MAX SECOND MOVES
HEURISTIC FOR TIC-TAC-TOE
MAX
MAX
MIN
+ : A forced win
for MAX
- : A forced win
for MIN
80
TWO-PLY MINIMAX: Applied to MAX move near the end of the game