Professional Documents
Culture Documents
Part I: Topic 3A
Heuristic Search
1
Part I: Topic 3-A Heuristic Search
Outline
Key Terms
• What is it?
• Why Designing Heuristics?
• Heuristic Search Algorithms Search Strategies
Hill-Climbing Complete/Optimal
Best-First (greedy) Uninformed/ Informed search
A* strategies
Heuristic Search
Designing Heuristics
Hill-Climbing Search
Best-First /Greedy Search
Admissible Heuristics
A* Search
2
Search Strategies
A strategy is defined by picking the order of node expansion
3
Uninformed vs Informed Search Strategies
Uninformed Strategies use only the Informed Strategies use problem-specific
information available in the problem knowledge to guide the search.
definition. - Use an evaluation function to estimate
- Systematic generate new states the ‘desirability’ of each node
- Inefficient - Usually more efficient
- Popular methods: - Popular methods:
o Breadth-first search o Hill-Climbing
o Depth-First search o Best-First (Greedy)
o Iterative Deepening search o A*
5
Why Heuristics ?
We are forced to use heuristics because the computational cost of
finding the solution is often prohibitive excessively high
In many problems, state space growth is combinatorially explosive, with
the number of possible states increasing exponentially or factorially with
the depth of the search
In these cases, exhaustive, brute force search techniques may fail to
find a solution within any practical length of time
Heuristics attack the above complexity by guiding the search along the
most "promising" path through the space
By eliminating states and their descendants from consideration, a
heuristic algorithm is expected to defeat combinatorial explosion of
state space graphs and find an acceptable answer
For example, chess, go, “large” TSP (n > 25)
Average branching factor=35, 250
6
Limitations of Heuristic Algorithm
• Like many rules of discovery and invention, heuristics
are fallible
• A heuristic is only an informed guess. Because heuristics use
limited information, such as the description of the states
currently under evaluation, they are seldom able to predict the
exact behavior of the state space farther along the search
• A heuristic can lead a search algorithm to a sub-optimal solution
or fail to find any solution at all. This inherent limitation of
heuristic search cannot be eliminated by "better" heuristics or
more efficient search algorithms
7
Two Key Components of Heuristic Search
• A heuristic measure
8
Tic-Tac-Toe Example Total 9!
How to get h ?
9
Reduced State Space
“fitness”
10
Heuristic Search Algorithm- Hill Climbing
First h-search algorithm
11
Hill-Climbing (cont.)
Hill-climbing works?
13
2nd h-search algorithm Best-First Search
The example below, the numbers are the heuristic cost of the states
14
The Best-First Algorithm
17
1)
2)
//leave it.
3)
// sorting !
16
Example 1 on Heuristic Search h = cost here
Best-first work ?
17
Fig 4.5 Heuristic search of a hypothetical state
space with open and closed states highlighted.
21
Example: Designing Heuristics
Fig 4.6 The start state, first moves, and goal state for an example-8 puzzle. 22
Example: Designing Heuristics (cont.)
h1 h2 h3
23
Devising Heuristics (cont.)
• A depth count can be added to the heuristic evaluation of each state to
bias search in favour of states found shallower in the graph
• This makes the evaluation function (cost), f, the sum of two
components:
f(n) = g(n) + h(n)
24
Best-First: greedy
f(n) = g(n) + h(n)
• g(n) : path-cost function = 0
25
Best-First: A*
26
A* Algorithm -- optimal solution = admissibility
f(n) = g(n) + h(n)
o g(n) measures the actual length of the path from any state n to the start state (depth count)
o h(n) is an admissible heuristic estimate (cost) of state n
Fig 4.10 State space generated in heuristic search of the 8-puzzle graph. 30
Example: Best-First Search for 8-puzzle
The successive stages for open and closed using the best-first-
search algorithm on Fig.4.10
open ………………… closed..........................
1. [a4] []
2. [c4, b6, d6] [a4]
3. [e5, f5, g6, b6, d6] [a4, c4]
4. [f5, h6, g6, b6, d6, I7] [a4, c4, e5]
5. [j5, h6, g6, b6, d6, k7, I7] [a4, c4, e5, f5]
6. [l5, h6, g6, b6, d6, k7, I7] [a4, c4, e5, f5, j5]
7. [m5, h6, g6, b6, d6, n7, k7, I7] [a4, c4, e5, f5, j5, l5]
8. success, m=goal !
31
Example: Best-First Search for 8-puzzle
The successive stages for open and closed using the best-
first-search algorithm on Fig.4.10
open …………… closed......................
1. [a4] []
2. [c4, b6, d6] [a4]
3. [e5, f5, g6, b6, d6] [a4, c4]
4. [f5, h6, g6, b6, d6, I7] [a4, c4, e5]
5. [j5, h6, g6, b6, d6, k7, I7] [a4, c4, e5, f5]
6. [l5, h6, g6, b6, d6, k7, I7] [a4, c4, e5, f5, j5]
7. [m5, h6, g6, b6, d6, n7, k7, I7] [a4, c4, e5, f5, j5, l5]
8. success, m=goal !
32
Fig 4.11 Open and closed as they appear after the 3rd iteration of heuristic search 33
Find better move ?
Fig 4.12 Comparison of state space searched using heuristic search with space searched by breadth-first search.
The proportion of the graph searched heuristically is shaded. The optimal search selection is in bold. Heuristic
used is f(n) = g(n) + h(n) where h(n) is tiles out of place. 34
Example : Breadth-First vs Depth-First Search
breadthѪfirst depthѪfirst
35
Example: Best-First (greedy) to Find a Path from Arad to Bucharest
h(n) : evaluation function =estimate of cost from n to the closest goal
hSLD(n) = straight-line distance from n to Bucharest
f(n) = hSLD(n)
176
100
b) After expandingArad
176
100
35
176
100
36
d) The total distance from A to B:
140+99+211 = 450
176
100
37
Example: A* to Find a Path from Arad to Bucharest
f(n) : estimated total cost of path through n to goal (Whole Life)
evaluation function f(n) = h(n) + g(n)
h(n) = straight-line distance from n to Bucharest
g(n) = straight-line distance from Arad to n
176
100
176
100
39
366+160
366+160
40
Example: A* to Find a Path from Arad to Bucharest
366
393
413
415
366+160 417
41
Properties of Best-First vs A*
Properties of Best-First (Greedy) – without g
Complete ?? No, can get stuck in loops
Optimal?? No
Time complexity ?? O(bm)
Space complexity ?? O(bm), keep all nodes in memory
Criteria Characteristics
completeness does it always find a solution if one exists?
optimality does it always find a least-cost solution?
time complexity number of nodes generated/expanded
space complexity maximum number of nodes in memory
42
Exercise Questions
1. “Hand run” the best-first algorithm starting from node A in the graph of Fig.ex1,
where the heuristic measure of the cost for each node is given as h. Write down the
nodes being visited in order until it finds the target node O.
Fig.ex1
Fig.ex3
Open Closed
A []
B(8), D(10), C(12), E(19) A
M(4),H(5),G(6),F(9), D(10), C(12), E(19) B, A
N(1), H(5),G(6),F(9), D(10), C(12), E(19) M,B,A
…
F(9), D(10), C(12), E(19) G,H,N,M,B,A Fig.ex1
L(3), D(10), C(12), E(19) F,G,H,N,M,B,A
D(10), C(12), E(19) L,F,G,H,N,M,B,A
C(12), J(13), I(14), E(19) D, L,F,G,H,N,M,B,A
J(13), I(14), E(19) C, D, L,F,G,H,N,M,B,A
O(2), I(14), E(19) J, C, D, L,F,G,H,N,M,B,A
44
Sometimes there is no good evaluation function for
a problem, but there is a good comparison method:
Exercise 2 _Discussions a way to tell if one node is better than another,
without assigning them numerical values. Is this
enough to do a best-first greedy search?
• As long as we are able to select the best state from all the
states in the Open, the Best-First search can be performed
normally.
45
Exercise 3 Admissible Heuristics
p1 at (x1, y1) and p2 at (x2, y2),
Manhattan d(p1,p2) = |x1 - x2| + |y1 - y2|
46
Example : Dominates h – Better for search
47
Summary on Topic 3-A
48