Professional Documents
Culture Documents
Chapter4 - Heuristic Search
Chapter4 - Heuristic Search
Introduction
AI problem solvers employ heuristics in two situations:
1. A problem may not have an exact solution because of inherent ambiguities 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)
Figure 1: The most wins heuristic applied to the first children in tic tac toe.
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 evaluation than all of its children. Then the algorithm halts, if such state is
local maximum.
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)
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 following 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).
9
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 h1 (n) : number of tiles out of place compared to
h2 (n) : number of movement required to reach the goal state. We find
that h1 (n) <= h2 (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 S1 , S2 , S3 , . . . Sg , where S1 is the start
state and Sg is the goal state.
S1 to S2 : h(S1 ) h(S2 ) cost(S1 , S2 )
10
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.
11
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 differentlysized 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).
12
13
14
15
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
18