Heuristic Search
Heuristic Search
Chapter 3
(Based on Slides by Stuart Russell,
Richard Korf and UW-AI faculty)
Informed (Heuristic) Search
Idea: be smart
about what paths
to try.
2
Blind Search vs. Informed Search
• What’s the difference?
3
General Tree Search Paradigm
function tree-search(root-node)
fringe successors(root-node)
while ( notempty(fringe) )
{node remove-first(fringe)
state state(node)
if goal-test(state) return solution(node)
fringe insert-all(successors(node),fringe) }
return failure
end tree-search
4
General Graph Search Paradigm
function tree-search(root-node)
fringe successors(root-node)
explored empty
while ( notempty(fringe) )
{node remove-first(fringe)
state state(node)
if goal-test(state) return solution(node)
fringe insert-all(successors(node),fringe, if node not in explored)
explored insert(node,explored)
}
return failure
end tree-search
5
Best-First Search
• Use an evaluation function f(n) for node n.
• Always choose the node from fringe that has
the lowest f value.
3 5 1
4 6
6
Best-first search
• A search strategy is defined by picking the order of node
expansion
• Idea: use an evaluation function f(n) for each node
– estimate of "desirability“
• Implementation:
Order the nodes in fringe in decreasing order of desirability
• Special cases:
– greedy best-first search
– A* search
Romania with step costs in km
Greedy best-first search
• Evaluation function f(n) = h(n) (heuristic)
= estimate of cost from n to goal
12
13
14
15
16
17
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.
• Time? Exponential
• Optimal?
Yes (depending upon search algo and heuristic property)
http://www.youtube.com/watch?v=huJEgJ82360
Admissible heuristics
E.g., for the 8-puzzle:
• h1(S) = ?
• h2(S) = ?
Admissible heuristics
E.g., for the 8-puzzle:
• h1(S) = ? 8
• h2(S) = ? 3+1+2+2+2+3+3+2 = 18
Dominance
• If h2(n) ≥ h1(n) for all n (both admissible)
then h2 dominates h1
• h2 is better for search
• 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
Memory Problem?
• Iterative deepening A*
– Similar to ID search
Non-optimal variations
• Use more informative, but inadmissible
heuristics
• Weighted A*
– f(n) = g(n)+ w.h(n) where w>1
– Typically w=5.
– Solution quality bounded by w for admissible h
Sizes of Problem Spaces
3 1 1 3
3 1 1 3
3 1 3
1
3 1 3
1
3 1 3
1
1 3 1 3
1 3 1 3
7 13 3
12 7 M.d. is 20 moves, but 28 moves are
15 3 11 needed
11 14 12 13 14 15
12 11 3
7 14 7 M.d. is 17 moves, but 27 moves are
13 3 11 needed
15 12 13 14 15
Pattern Database Heuristics
• Culberson and Schaeffer, 1996
• A pattern database is a complete set of such
positions, with associated number of moves.
• e.g. a 7-tile pattern database for the Fifteen
Puzzle contains 519 million entries.
Heuristics from Pattern Databases
5 10 14 7 1 2 3
8 3 6 1 4 5 6 7
15 12 9 8 9 10 11
2 11 4 13 12 13 14 15
5 10 14 7 1 2 3
8 3 6 1 4 5 6 7
15 12 9 8 9 10 11
2 11 4 13 12 13 14 15
1 2 3
4 5 6 7
8 9 10 11
12 13 15 14
The 7-tile database contains 58 million entries. The 8-tile database contains
519 million entries.
Computing the Heuristic
5 10 14 7 1 2 3
8 3 6 1 4 5 6 7
15 12 9 8 9 10 11
2 11 4 13 12 13 14 15