Professional Documents
Culture Documents
SearchInformed, Best First and A Star Algos
SearchInformed, Best First and A Star Algos
CSAL3243
Dr. Anam Nazir
1
INFORMED SEARCH
2
Using problem specific knowledge to aid
searching
• With knowledge, one can search the state space as
if he was given “hints” when exploring a maze.
– Heuristic information in search = Hints
• Leads to dramatic speed up in efficiency.
B C D E
Search only in
F G H I J
this subtree!!
K L M N
O 3
More formally, why heuristic functions work?
• Previous: at most b choices at each node
and a depth of d at the goal node
– An uninformed search algorithm would have to,
in the worst case, search around O(bd) nodes
before finding a solution (Exponential Time
Complexity).
5
Approach 1
• measures the value of the current state (i.e. its
“goodness”)
• Usually the case when solving optimization
problems
– Finding a state such that the value of the heuristic
function is optimized
• Often, in these cases, f could be a weighted sum of
a set of component values:
– N-Queens
• Example: the number of queens under attack …
– Used in Local search (we’ll study it later)
6
Approach 2
• Evaluation function measures the
estimated cost of getting to the goal
from the current state:
•
• where
• an estimate of the cost to get from state
to a goal state
7
Example 8–Puzzle tree
8
Possible heuristics for 8–Puzzle
• h1: The number of misplaced tiles (squares with
number).
• h2: The sum of the distances of the tiles from their
goal positions.
9
h1: The number of misplaced tiles (not including the blank)
• Notation:
• h(current state) = 1
• Because this state has one Y.
where
an exact cost to get to (from initial state)
an estimate of the cost to get from state to a
goal state
12
Summary of Evaluation / Heuristic Function
• Evaluation function f(n) = g(n) + h(n)
– g(n) = exact cost so far to reach n
– h(n) = estimated cost to goal from n
– f(n) = estimated total cost of cheapest
path through n to goal
• Special cases:
– Greedy (best-first) Search:
– A* Search:
How it works?
• Idea: use heuristic function for each node
– that estimates desirability
• Expands most desirable unexpanded node
• Implementation:
– fringe is a queue sorted in order of desirability
• Special cases:
– Greedy (best-first) Search (informed)
– A* Search (informed)
14
Informed Search Strategies
G F F 178
G 193
97
H 98
H 211
I 0
101
I
Goal f(n) = h (n) = straight-line distance heuristic
16
Greedy Search
State Heuristic: h(n)
Start
A A 366
118 75
B 374
140 B
C C 329
111
E D 244
D 80 99
E 253
G F F 178
G 193
97
H 98
H 211
I 0
101
I
Goal f(n) = h (n) = straight-line distance heuristic
17
Greedy Search
State Heuristic: h(n)
Start
A A 366
118 75
B 374
140 B
C C 329
111
E D 244
D 80 99
E 253
G F F 178
G 193
97
H 98
H 211
I 0
101
I
Goal f(n) = h (n) = straight-line distance heuristic
18
Greedy Search
State Heuristic: h(n)
Start
A A 366
118 75
B 374
140 B
C C 329
111
E D 244
D 80 99
E 253
G F F 178
G 193
97
H 98
H 211
I 0
101
I
Goal f(n) = h (n) = straight-line distance heuristic
19
Greedy Search
State Heuristic: h(n)
Start
A A 366
118 75
B 374
140 B
C C 329
111
E D 244
D 80 99
E 253
G F F 178
G 193
97
H 98
H 211
I 0
101
I
Goal f(n) = h (n) = straight-line distance heuristic
20
Greedy Search
State Heuristic: h(n)
Start
A A 366
118 75
B 374
140 B
C C 329
111
E D 244
D 80 99
E 253
G F F 178
G 193
97
H 98
H 211
I 0
101
I
Goal f(n) = h (n) = straight-line distance heuristic
21
Greedy Search
State Heuristic: h(n)
Start
A A 366
118 75
B 374
140 B
C C 329
111
E D 244
D 80 99
E 253
G F F 178
G 193
97
H 98
H 211
I 0
101
I
Goal f(n) = h (n) = straight-line distance heuristic
22
Greedy Search
State Heuristic: h(n)
Start
A A 366
118 75
B 374
140 B
C C 329
111
E D 244
D 80 99
E 253
G F F 178
G 193
97
H 98
H 211
I 0
101
I
Goal f(n) = h (n) = straight-line distance heuristic
23
Greedy Search
State Heuristic: h(n)
Start
A A 366
118 75
B 374
140 B
C C 329
111
E D 244
D 80 99
E 253
G F F 178
G 193
97
H 98
H 211
I 0
101
I
Goal f(n) = h (n) = straight-line distance heuristic
24
Greedy Search
State Heuristic: h(n)
Start
A A 366
118 75
B 374
140 B
C C 329
111
E D 244
D 80 99
E 253
G F F 178
G 193
97
H 98
H 211
I 0
101
I
Goal f(n) = h (n) = straight-line distance heuristic
25
Greedy Search: Tree Search
Start
A
26
Greedy Search: Tree Search
Start
A 75
118
[253] E
27
Greedy Search: Tree Search
Start
A 75
118
[253] E
80 99
[193] [178]
G F
[366] A
28
Greedy Search: Tree Search
Start
A 75
118
[253] E
80 99
[193] [178]
G F
[366] A
211
[253] I [0]
E
Goal
29
Greedy Search: Tree Search
Start
A 75
118
[253] E
80 99
[193] [178]
G F
[366] A
211
[253] I [0]
E
Path cost(A-E-F-I) = 253 + 178 + 0 = 431
Goal
dist(A-E-F-I) = 140 + 99 + 211 = 450
30
Greedy Search: Optimal?
State Heuristic: h(n)
Start
A A 366
118 75
B 374
140 B
C C 329
111
E D 244
D 80 99
E 253
G F F 178
G 193
97
H 98
H 211
I 0
101
I
Goal f(n) = h (n) = straight-line distance heuristic
Not optimal! dist(A-E-G-H-I) =140+80+97+101=418 31
Greedy Search: Complete ?
State Heuristic: h(n)
Start
A A 366
118 75
B 374
140 B
C ** C 250
111
E D 244
D 80 99
E 253
G F F 178
G 193
97
H 98
H 211
I 0
101
I
Goal f(n) = h (n) = straight-line distance heuristic
32
Greedy Search: Tree Search
Start
A
33
Greedy Search: Tree Search
Start
A 75
118
[253] E
34
Greedy Search: Tree Search
Start
A 75
118
[253] E
111
[244] D
35
Greedy Search: Tree Search
Start
A 75
118
[253] E
111
[244] D
Infinite Branch !
[250] C
36
Greedy Search: Tree Search
Start
A 75
118
[253] E
111
[244] D
Infinite Branch !
[250] C
[244] D
37
Greedy Search: Tree Search
Start
A 75
118
[253] E
111
[244] D
Infinite Branch !
[250] C
Even Incomplete in finite state
space much like depth first search
[244] D (Complete in finite space with
repeated-state checking) 38
Greedy Search: Time and Space Complexity ?
Start
A
118 75 • Greedy search is not optimal.
140 B
C • Greedy search is incomplete
111
E
D 80 99 • In the worst case, the Time and
Space Complexity of Greedy
G F
Search are both O(bm)
97
Where b is the branching factor and m
H 211 the maximum path length
101
I
Goal
39
Informed Search Strategies
A* Search
eval-fn:
A* (A Star)
• Although Greedy Search can considerably cut the
search time (efficient), it is neither optimal nor
complete.
• Uniform Cost Search minimizes the cost from the
initial state to . UCS is optimal and complete but
not efficient.
• New Strategy: Combine Greedy Search and UCS to
get an efficient algorithm which is complete and
optimal.
41
A* (A Star)
• A* uses a heuristic function which combines g(n)
and h(n):
• g(n) is the exact cost to reach node n from the
initial state. Cost so far up to node n.
• h(n) is an estimation of the remaining cost to
reach the goal.
42
A* (A Star)
g(n)
f(n) = g(n)+h(n) n
h(n)
43
A* Search
State Heuristic: h(n)
Start
A A 366
118 75
B 374
140 B
C C 329
111
E D 244
D 80 99
E 253
G F F 178
G 193
97
H 98
H 211
I 0
101
I
Goal f(n) = g(n) + h (n)
g(n): is the exact cost to reach node n from the initial state. 44
A* Search: Tree Search
A Start
45
A* Search: Tree Search
A Start
118 75
140
E [140+253=393] B [75+374=449]
[118+329=447] C
46
A* Search: Tree Search
A Start
118 75
140
E [140+253=393] B [75+374=449]
[118+329=447] C
80 99
G F [239+178=417]
[220+193=413]
47
A* Search: Tree Search
A Start
118 75
140
E [140+253=393] B [75+374=449]
[118+329=447] C
80 99
G F [239+178=417]
[220+193=413]
97
[317+98=415] H
48
A* Search: Tree Search
A Start
118 75
140
E [140+253=393] B [75+374=449]
[118+329=447] C
80 99
G F [239+178=417]
[220+193=413]
97
[317+98=415] H
101
Goal I [418+0=418]
49
A* Search: Tree Search
A Start
118 75
140
E [140+253=393] B [75+374=449]
[118+329=447] C
80 99
G F [239+178=417]
[220+193=413]
97 211
[317+98=415] H I [450+0=450]
101
Goal I [418+0=418]
50
A* Search: Tree Search
A Start
118 75
140
E [140+253=393] B [75+374=449]
[118+329=447] C
80 99
G F [239+178=417]
[220+193=413]
97 211
[317+98=415] H I [450+0=450]
101
Goal I [418+0=418]
51
A* Search: Tree Search
A Start
118 75
140
E [140+253=393] B [75+374=449]
[118+329=447] C
80 99
G F [239+178=417]
[220+193=413]
97 211
[317+98=415] H I [450+0=450]
101
Goal I [418+0=418]
dist(A-E-G-H-I) =140+80+97+101=418 52
A* with h() not Admissible
If h() overestimates the cost to reach
the goal state
Admissible Heuristic Functions
• A heuristic is admissible if never overestimates the
cost to reach the goal.
– Admissible heuristics are “optimistic” approximation
• Mathematically h is admissible if
For all n,
Where
• n is the node, h is heuristic
• h(n) is the cost indicated by h to reach goal from n
• C(n) is actual cost to reach a goal from n
54
Admissible heuristics Examples
• hSLD(n) Straight line distance heuristic
– Because never overestimate the actual road distance.
56
Consistent Heuristic
• The admissible heuristic h is consistent if for every node N
and every successor N’ of N:
(triangular inequality)
N
c(N,N’)
• A consistent heuristic is admissible. N’ h(N)
h(N’)
57
A* Search: if h not admissible
State Heuristic: h(n)
Start
A A 366
118 75
B 374
140 B
C C 329
111
E D 244
D 80 99
E 253
G F F 178
G 193
97
H 138
H 211
I 0
101
I
f(n) = g(n) + h (n) – (H-I) Overestimated
Goal
g(n): is the exact cost to reach node n from the initial state. 58
A* Search: Tree Search
A Start
59
A* Search: Tree Search
A Start
118 75
140
E [393] B [449]
[447] C
60
A* Search: Tree Search
A Start
118 75
140
E [393] B [449]
[447] C
80 99
[413] G F [417]
61
A* Search: Tree Search
A Start
118 75
140
E [393] B [449]
[447] C
80 99
[413] G F [417]
97
[455] H
62
A* Search: Tree Search
A Start
118 75
140
E [393] B [449]
[447] C
80 99
[413] G F [417]
97 211
63
A* Search: Tree Search
A Start
118 75
140
E [393] B [449]
[447] C
80 99
97 211
64
A* Search: Tree Search
A Start
118 75
140
E [393] B [449]
[447] C
80 99
97 211
65
A* Search: Tree Search
A Start
118 75
140
E [393] B [449]
[447] C
80 99
97 211
66
A* Search: Tree Search
A Start
118 75
140
E [393] B [449]
[447] C
80 99
97 211
• Time? Exponential
– It depends on the quality of heuristic but is still exponential.
• Optimal? Yes
– A* is optimal if heuristic h is admissible (optimal).
Conclusions
• Frustration with uninformed search led to the idea of using
domain specific knowledge in a search
• so that one can intelligently explore only the relevant part of
the search space that has a good chance of containing the
goal state.
• These new techniques are called informed (heuristic) search
strategies.