Heuristic Search
Heuristic Search
(Heuristic search)
Unit-3
Sub Topics
• Greedy best-first search
• A* search
• Local search algorithms
• Hill-climbing search
• Simulated annealing search
• Local beam search
• Genetic algorithms
Heuristic Search
• Heuristic - a “rule of thumb” used to help guide search
– often, something learned experientially and recalled when needed
• Heuristic Function - function applied to a state in a search space to
indicate a likelihood of success if that state is selected
– heuristic search methods are known as “weak methods” because of
their generality and because they do not apply a great deal of
knowledge
– the methods themselves are not domain or problem specific, only
the heuristic function is problem specific
• Heuristic Search –
– given a search space, a current state and a goal state
– generate all successor states and evaluate each with our heuristic
function
– select the move that yields the best heuristic value
• Here and in the accompanying notes, we examine various heuristic
search algorithms
Recall tree search…
1 2 3 1 2 3
7 8 4 8 4
6 5 7 6 5
6
1 2 3 GOAL 1 2 3
8 4 7 8 4
7 6 5 6 5
right
1 2 3 1 2 3 1 2 3
7 8 4 7 8 4 7 4
6 5 6 5 6 8 5
8
8 Puzzle Heuristics
• For now - we just want to establish some
ordering to the possible moves (the values
of our heuristic does not matter as long as
it ranks the moves).
• Later - we will worry about the actual
values returned by the heuristic function.
9
A Simple 8-puzzle heuristic
• Number of tiles in the correct position.
– The higher the number the better.
– Easy to compute (fast and takes little
memory).
– Probably the simplest possible heuristic.
10
Another approach
• Number of tiles in the incorrect position.
– This can also be considered a lower bound on
the number of moves from a solution!
– The “best” move is the one with the lowest
number returned by the heuristic.
– Is this heuristic more than a heuristic (is it
always correct?).
• Given any 2 states, does it always order them
properly with respect to the minimum number of
moves away from a solution?
11
1 2 3 GOAL 1 2 3
8 4 7 8 4
7 6 5 6 5
right
1 2 3 1 2 3 1 2 3
7 8 4 7 8 4 7 4
6 5 6 5 6 8 5
h=2 h=4 h=3
12
Another 8-puzzle heuristic
• Count how far away (how many tile
movements) each tile is from it’s correct
position.
• Sum up this count over all the tiles.
• This is another estimate on the number of
moves away from a solution.
13
1 2 3 GOAL 1 2 3
8 4 7 8 4
7 6 5 6 5
right
1 2 3 1 2 3 1 2 3
7 8 4 7 8 4 7 4
6 5 6 5 6 8 5
h=2 h=4 h=4
14
Techniques
• There are a variety of search techniques
that rely on the estimate provided by a
heuristic function.
• In all cases - the quality (accuracy) of the
heuristic is important in real-life application
of the technique!
15
Greedy Best First Search
53
Properties of GBFS
• Complete? Not unless it keeps track of all states
visited (otherwise can get stuck in loops)
• e.g., Iasi Neamt Iasi Neamt
•
• Time? O(bm), but a good heuristic can give
dramatic improvement
• Space? O(bm) -- keeps all nodes in memory
• Optimal? No e.g. AradSibiuRimnicu
VireaPitestiBucharest is shorter!
Romania with step costs in km
A* search
• Idea: avoid expanding paths that are
already expensive
• Evaluation function f(n) = g(n) + h(n)
• g(n) = cost so far to reach n
• h(n) = estimated cost from n to goal
• f(n) = estimated total cost of path through
n to goal
A* search example
A* search example
A* search example
A* search example
A* search example
A* search example
A* Algorithm
G(n)= cost of n from root, h(n)= cost estimate from n to goal
1. Open={s}, closed={ },g(s)=0, f(s)=h(s)
2. If open=empty, return failure
3. Select min cost state n from open, add it to closed
4. If nЄ G, terminate with success and return f(n)
5. For each successor m of n
1. If m does not belong to (open or closed)// add all successors to
open first
1. Set g(m)=g(n)+c(n,m)
2. Set f(m)=g(m)+h(m)
3. Insert m in open
2. Else If m belongs to (open or closed)
1. Set g(m)=min (g(m), g(n)+c(n,m))// min cost from start to m
2. Set f(m)=g(m)+h(m)
3. If f(m) has decreased and m Є closed, move m to open
6. Go to step 2
Admissible heuristics
• A heuristic h(n) is admissible if for every node n,
h(n) ≤ h*(n), where h*(n) is the 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
Proof of Admissibility:
• Problem definition
– Given [G,s,T] where
• G : Implicitly specified AND/OR graph
• S : Start node of the AND/OR graph
• T : Set of terminal nodes
• H(n) heuristic function estimating the cost of
solving the sub-problem at n
– To find :
• A minimum cost solution tree
AO* Algorithm
• h = number of pairs of queens that are attacking each other, either directly
or indirectly
• h = 17 for the above state
•
Hill-climbing search: 8-queens problem