Unit 2 - Heuristics Searching
Unit 2 - Heuristics Searching
(Heuristic search)
Sub Topics
• Greedy best-first search
• A* search
• AO* search algorithm
• Local search algorithms
• Hill-climbing search
• Simulated annealing search
• Local beam search
• Genetic algorithms
Recall tree search…
1 2 3 1 2 3
7 8 4 8 4
6 5 7 6 5
4
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
6
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.
7
A Simple 8-puzzle heuristic
• Number of tiles in the correct position.
– The higher the number is the better.
– Easy to compute (fast and takes little
memory).
– Probably the simplest possible heuristic.
8
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?
9
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
10
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.
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=4
12
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!
13
Romania with step costs in km
Best-first search
• Idea: use an evaluation function f(n) for each node
– estimate of "desirability"
→ Expand most desirable unexpanded node
• Implementation:
Order the nodes in fringe in decreasing order of
desirability
• Special cases:
– greedy best-first search
– A* search
Greedy best-first search
• Evaluation function f(n) = h(n) (heuristic)
= estimate of cost from n to goal
Hence f(G2) > f(n), and A* will never select G2 for expansion
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
Heuristic functions
• 8-puzzle
– Avg. solution cost is about 22 steps
– branching factor ~ 3
– Exhaustive search to depth 22:
• 3.1 x 1010 states.
– A good heuristic function can reduce the search process.