Sei sulla pagina 1di 18

1

Chapter 4: Heuristic Search



Instructor: Dr. Ebaa Fayyoumi
IT 229
email: enfayyoumi@hu.edu.jo


Introduction
AI problem solvers employ heuristics in two situations:

1. A problem may not have an exact solution because of inherent ambigu-
ities in the problem statement or available data.
2. A problem may have an exact solution, but the computational cost of
finding it may be prohibitive.
A heuristic is an informed guess of the next step to be taken in solving a
problem.
A heuristic is based on the experience and intuition. In other words, it is
based on the knowledge of the present and current situation.
It sometimes leads to suboptimal solution or it fails to find a solution at all.

Examples: Consider the game of tic-tac-toe.
1. The complexity of this game is 9! = 9 8 7 6 5 4 3 2 1

2. By using symmetry reduction heuristic, many configurations are actually
equivalent. (Note! apply this rule at the first 3 level it will reduce the search
space to 12 7!)


3. By applying a heuristic function which is Move to the board where X has
most win line. (if there are two or more boards have the same number of
win lines chose the first one found)
2





Figure 1: The most wins heuristic applied to the first children in tic tac toe.





Figure 2: Heuristically reduced state space for tic tac toe.
3
1 The Best first Search Algorithm


The goal of the best-first search algorithm is to find the goal state by looking
at as few states as possible.

The more informed heuristic, the fewer states are processed in finding
the goal
This algorithm expands current node in the search space and evaluates
heuristically its children.
The best child is selected for further expansion, Neither its sibling nor its
parents are retained.
The search halts, when we reach state which has better heuristic than any
of its children.
This strategy can mainly fail because of two main factors:-

1. It does not keep history, therefore it may go on an infinite loop.

2. It can stuck at local maxima, when it reaches state with better evalua-
tion than all of its children. Then the algorithm halts, if such state is
local maximum.

4






2 Implement Heuristic Evaluation Function


Here we want to evaluate performance of several heuristics to solve the 8-puzzle
game.

5
1. Count the tiles out of place: In each state we compare the position of
all tiles with respect to the goal board (State with fewest tiles out of place
is closer to the desired goal).

2. Distance Summation: Sum all the distance by which the tiles are out of
place(State with the shortest distance is closer to the desired goal).

3. Count reversal Tiles: If two tiles are next to each other, and the goal
requires their position to be swaped. The heuristic takes this into account
by evaluating the expression (2 number of direct tiles reversal)







Heuristics might be wrong:
The search could continue down a wrong path
Solution:
Maintain depth count, i.e., give preference to shorter paths

Modified evaluation function f:
f (n) = g(n) + h(n)
f(n) estimate of total cost along path through n
6
g(n) actual cost of path from start to node n

h(n) estimate of cost to reach goal from node n

Example:-





Best first search: ABDEF with cost = 13 = (2 + 4 + 3 + 4)
algorithm A: ABC GF with cost = 7 = (2 + 3 + 2)






























7
8
Another interesting approach to implement heuristic function is the use of

Confidence Measure by expert systems to weight the result of the rules.
Usually the expert employs a heuristic to estimate the confidence of the
conclusion.
Expert systems employ confidence measure to select the conclusion with
the highest likelihood of success.

Games in general are ideal fields to explore and design behavior of
heuristic because of many reasons:-

1. Search space is very large, therefore, we need heuristic techniques.

2. Games are complex, so It has many heuristic evaluations.

3. Games do not involve with a complex representation, so It does not focus
on knowledge representation problem.

4. We can easily apply heuristic techniques because all nodes have a common
representation.


3 Admissibility, Monotonicity and Informedness

The goal is to evaluate the behavior of the heuristic function, in order to
be able to plane a path for a machine.
Admissibility: guarantees to find the shortest path to the goal, if it exists.
Monotonicity: It is local admissibility and it guarantees to find the shortest
path to each state encountered in the search.
Monotonicity: If there is any guarantee that the same state will not be
found in the search at cheaper cost.
Informedness: It measures the quality of a heuristic function. It searches
for any better available heuristic function.
9
Admissibility





In order to explain the property of admissible heuristic let:-
f

(n) = g

(n) + h

(n), where

g

(n) : Cost of the shortest path from start node to n.


h

(n) : Actual cost of the shortest path from n to the goal.


f

(n) : Actual cost of optimal path from the start node to goal node through
n state.

Notes:-
If the best first search algorithm apply the f

(n) this means that It is


admissible.
Practically, f

can not be determine in the most problem due to the follow-
ing reasons:-
1. f is used to be close to the estimated f

.
2. g is a reasonable estimate of g

, but they may not be equal g(n) >=


g (n).
10
Any algorithm use heuristic h(n), where h(n) <= h (n) finds the shortest

path.
Breadth first is A

where h(n) = 0. Then its f (n) = g(n).
8 Puzzle Game where h
1
(n) : number of tiles out of place compared to
h
2
(n) : number of movement required to reach the goal state. We find

that h
1
(n) <= h
2
(n). Both of them are admissible algorithm.

Monotonicity
A

Algorithm does not require that g(n) = g

(n).
Admissible heuristic can reach non goal state a long sub optimal path.




It is admissible because it reaches each state a long shortest path from its
ancestors.
When the best first search algorithm applies monotone heuristic, It will be
able to find the shortest path to any state, therefore there is no need to
check the open nor the close lists.
Any monotone heuristic is admissible.

Proof

Assume that any path on space is S
1
, S
2
, S
3
, . . . S
g
, where S
1
is the start
state and S
g
is the goal state.
S
1
to S
2
: h(S
1
) h(S
2
) cost(S
1
, S
2
)
11
S
2
to S
3
: h(S
2
) h(S
3
) cost(S
2
, S
3
)

S
3
to S
4
: h(S
3
) h(S
4
) cost(S
3
, S
4
)

.

.
S
g1
to S
g
: h(S
g
1
) h(S
g
) cost(S
g1
, S
g
)
Sum all the columns the h(S
1
) cost(S
1
, S
g
)

Informedness
For two A

heuristic algorithm h
1
and h
2
, if h
1
(n) h
2
(n) n in space search
h, then heuristic h
2
is said to be more informed than h
1
.
Examples:-
Breadth-first search algorithm is A

: h(x) = 0 x, so h
1
< h

.
number of tiles out of place h
2
< h


h
1
h
2
.


4 Game playing

Classical application for heuristic search

1. Simple game: Exhaustively searchable.

2. Complex games: Only partial search possible.

3. Additional problem: playing against opponent.
Two persons adversarial games (win, lose or tie).
Assume that both player extract the same knowledge from the configuration
board and they do apply it consistently to win the game.

MiniMax Search

Game between two opponents, MIN and MAX means

MAX tries to win.

MIN tries to minimize MAXs score.
12
MiniMax procedure:


1. Label each level according to players move.

2. Leaves get a value of 1 or 0 (win for MAX or MIN).

3. Propagate this value up:

If parent=MAX, give it max value of children.

If parent=MIN, give it min value of children.

Nim Game
Rules

1. Two players start with a pile of tokens.

2. Legal move: Split (any) existing pile into two non-empty differently-
sized piles.
3. Game ends when no pile can be unevenly split.

4. Player who cannot make his move loses the game.
Search strategy: Existing heuristic search methods do not work.

Label nodes as MIN or MAX, alternating for each level.
Define utility function (payoff function).
Do full search on tree (expand all nodes until game is over for each branch).
Label leaves according to outcome.
Propagate result up the tree with:

M(n) = max( child nodes ) for a MAX node.

M(m) = min( child nodes ) for a MIN node.
Best next move for MAX is the one leading to the child with the highest
value (and vice versa for MIN).





































































13
14
MiniMAx with Heuristic
Exhaustive search for interesting games is rarely feasible.
Search only to predefined level.
It is called n-ply look-ahead where n is number of levels.
No exhaustive search (why)

Nodes evaluated with heuristics and not win/loss.

It indicates best state that can be reached.

Horizon effect.
simple strategy: try to maximize difference between players.




Figure 3: MiniMax with Fixed Ply Depth
15
Applying MiniMax to tic-tac-toe
Heuristic tries to measure conflict in game.
How to evaluate a state?

Count all winning lines open to MAX.

Subtract all winning lines open to MIN.
Forced win for MAX as +
Forced win for MIN as
Search attempts to maximize this difference.







































































16
Figure 4: MiniMax to tic-tac-toe

Alpha-beta search
Search algorithm design for 2-player games.
Unlike MiniMax, does not search entire depth.
Ignore (cut off, prune) entire branches of the tree that cannot possibly lead
to a better solution.
Reduces branching factor.
Allows deeper search with same effort.
It starts with depth-first search down to n-ply depth.
It applies heuristic to a state and its siblings.
Propagate result to parent as in minimax.
It deals with two values:

alpha value is attached to MAX nodes: The best (highest) choice for
MAX on path (never decreases).

beta is associated with MIN nodes: The best (lowest) choice for MIN
on path (never increases).
It prunes search tree by using:
alpha cutoff: Prune tree below MIN node, if value alpha.
beta cutoff: Prune tree below MAX node, if value beta.





















17


















Figure 5: Alpha Beta Search




















18

Potrebbero piacerti anche