03 Heuristic Search
03 Heuristic Search
Kalev Kask
Arad
• Theorem:
if h(n) is admissible, A* using Tree-Search is optimal
Example: Admissible heuristics
Zerind
Iasi
Arad 380 Sibiu Fagaras
Vaslui
Timisoara Rimnicu Vilcea
400
Lugoj Pitesti
85 Hirsova
Mehadia Urziceni
Bucharest
Dobreta
420
Cralova Eforie
Giurgiu
Properties of A* search
• Complete? Yes
– Unless infinitely many nodes with f < f(G)
– Cannot happen if step-cost ≥ ε > 0
• Time/Space? Depends on heuristic. Informally, O(bm).
– Except if |h(n) – h*(n)| ≤ O( log h*(n) )
• Unlikely to have such an excellent heuristic function
– More formally, it depends on the heuristic function (see R&N p. 98)
• In simplest cases, complexity is O(bh*-h) O( (b(h*-h)/h*))d )
• Thus, in simplest cases, b(h*-h)/h*) is the effective branching factor
(discussed below)
• Optimal? Yes
– With: Tree-Search, admissible heuristic; Graph-Search, consistent
heuristic
• Optimally efficient? Yes
– No optimal algorithm with same heuristic is guaranteed to expand
fewer nodes
Optimality of A* tree search with an
admissible heuristic
• Proof:
– Suppose some suboptimal goal G2 has been generated & is
on the frontier. Let n be an unexpanded node on the path
to an optimal goal G
– Show: f(n) < f(G2) (so, n is expanded before G2)
f(G2) = g(G2) since h(G2) = 0
f(G) = g(G) since h(G) = 0
g(G2) > g(G) since G2 is suboptimal
f(G2) > f(G) from above, with h=0
• Tree search
– Need admissibility
• Graph search, without re-opening closed nodes
– Need consistency
• Graph search, with re-opening closed nodes
– Admissibility is enough
Complexity of A*
• A* is optimally efficient (Dechter and Pearl 1985):
– It can be shown that all algorithms that do not expand a node which A*
did expand (inside the contours) may miss an optimal solution
• A* worst-case time complexity:
– is exponential unless the heuristic function is very accurate
• If h is exact (h = h*)
– search focus only on optimal paths
• Main problem:
– space complexity is exponential
– Not anytime; all or nothing … but largest f expanded is lower bound on C*
• Effective branching factor:
– Number of nodes generated by a “typical” search node
– Approximately : b* = N^(1/d)
• Q: what if you are given a solution (not necessarily optimal); can
you improve A* performance?
A* properties
• A* expands every path along which f(n) < C*
• R&N section 3.5.5, pp. 92-95, gives methods for A* that use
less memory (but more time & book-keeping)
– Iterative-deepening A* (IDA*), recursive best-first search (RBFS), memory-
bounded A* (MA*), simplified MA* (SMA*)
• Idea: recursive best-first search (RBFS)
– Try something like depth-first search, but don’t forget everything
about the branches we have partially explored
– Remember the best f(n) value we have found so far in the branch
we’re deleting
RBFS:
best alternative
over frontier nodes,
which are not children:
i.e. do I want to back up?
B G
I D
15 24 C 25
24
20
Algorithm can tell you when best solution found within memory constraint is optimal or not.
Branch-and-Bound Depth-First
Search
Branch-and-Bound (DFS)
• Upper and Lower bounds
– U upper bound, corresponding to current best known solution
– L lower bound = admissible f(n)
• Pick a node to expand, then
– If L=f(n) ≥ U, prune n
– Otherwise keep
• BnB DFS
– Not Best-First algorithm!
– Always expand deepest node
– Linear space complexity
– Exp time complexity
– Complete and optimal if run to completion
Path finding
1 4
A B C
2
S 2 5 G
5 3
2 4
D E F
A 10.4 B C
6.7 4.0
11.0 G
S
8.9 3.0
6.9
D E F
Example of Branch and Bound in Action
S 1 5+8.9=13.9
2+10.4=12.4
A 2 D
3+6.7=9.7 8
7+4=11
B 3 D 4+8.9=12.9
8+6.9=14.9 5
C 4 E 9
E 6+6.9=12.9
10+8.9=18.9
12+3=15
F 6
D 11+6.7=17.7
10+3=13 F 10 B
U=15+0=15
G 7 A10.4 B C
6.7 4.0
U=13+0=13
A 1 B 4 C G 11 S 11.0 G
2
S 5 G
2 8.9 3.0
5 3 D E 6.9 F
D 2 E 4 F
Example of A* Algorithm in Action
1
2 +10.4 = 12.4
S 5 + 8.9 = 13.9
2 D
3 + 6.7 = 9.7 A 5
B 3 D 4 + 8.9 = 12.9
7 + 4 = 11 4 8 + 6.9 = 14.9 6
C E 6 + 6.9 = 12.9
E
7
Dead End
B F 10 + 3.0 = 13
1 4 11 + 6.7 = 17.7
A B C 8
2 A10.4 B C
6.7 4.0 G
5 G 13 + 0 = 13
2
S S 11.0 G
5 3
2 4 8.9 3.0
D E F D E 6.9 F
Properties of Branch-and-Bound
• Not guaranteed to terminate unless
– admissible f and reasonable upper bound U
• Note : U imposes a depth-bound
• Optimal:
– finds an optimal solution (f is admissible)
• Time complexity: exponential
• Space complexity: can be linear
• Advantage:
– anytime property
• Note : unlike A*, BnB may (will) expand nodes f>C*.
Effectiveness of Heuristic Search
R&N 3.6.1
Effectiveness of heuristic search
• How quality of the heuristic impacts search?
• Pattern databases
– Solve a subproblem of the true problem
( = a lower bound on the cost of the true problem)
– Store the exact solution for each possible subproblem
Summary
• Uninformed search has uses but also severe limitations
• Heuristics are a structured way to make search smarter