1
Heuristic Search Heuristic Search
RN, Chapter 4.1 – 4.2
Some material from: D Lin, J You, JC Latombe
Best-First A* Heuristic Functions
Heuristic Search Heuristic Search Best-First A * Heuristic - - PowerPoint PPT Presentation
RN, Chapter 4.1 4.2 Heuristic Search Heuristic Search Best-First A * Heuristic Functions Some material from: D Lin, J You, JC Latombe 1 Search Overview Introduction to Search Blind Search Techniques Heuristic
1
Some material from: D Lin, J You, JC Latombe
Best-First A* Heuristic Functions
2
Introduction to Search Blind Search Techniques
Best-First A* Heuristic Functions
Stochastic Algorithms Game Playing search Constraint Satisfaction Problems
3
“Blind” methods only know Goal / NonGoal Often ∃ other problem-specific knowledge
Heuristic fn
Use: Given list of nodes to expand,
4
h(n) estimates cost of cheapest path
Example: 8-puzzle
n
5
h(n) estimates cost of cheapest path
Example: 8-puzzle
n
+ 3 + 0 + 2 + 1 + 0 + 3
6
;; “most promising” node in L according to h(.)
7
9
10
11
12
14
hSLD finds path:
Not optimal!
BestFirst is greedy:
15
Consider: Iasi → Fagaras
Worse: Unless search alg detects repeated
Loops are a real problem…
? ?
16
If state space is finite and
If state space is finite and
If the state space is infinite,
17
Complete? Optimal? Time: Space: Worst of both worlds
≈DFS: too greedy! ≈BFS: too much space!
18
Find cheapest path, quickly
Path from start to n:
Path from n to goal (est.):
f(n) = g(n)+h(n)
est of cost of path from start to goal, via n
Start n Goal g(n) h(n) f(n)
19
A* selects node with min'l f(n)
…ie, node with lowest estimated distance from start to goal, constrained to go via that node
lowest-cost-first best-first (so far) (to go)
21
A* expands
Rimnicu (f = (140+80)+193 = 413)
Faragas (f = (140+99)+178 = 417)
Why?
22
1+10 0+11
23
Contour-lines of “equal-f values” A* expands nodes with increasing f(n)
If use h(.)≡ 0 (UniformCost)
24
h*(n) = cost of optimal path
Heuristic h(n) is admissible if:
Admissible heuristic is always optimistic True for
Straight Line [map traversal] Manhattan distances [8-puzzle] Number of attacking queens [n-queens]
[place all queens, then move]
25
= 6
… = 13
= 45
= 6
26
f (n) ≤ f (n’) , as
S E n
n’
27
f(.) is “monotonic" ≡
Always true if
If true:
If f (.) not monotonic,
Eg, n’ ∈ Successor(n) f(n) = g(n)+h(n) = 3+4 = 7 f(n’) = g(n’)+h(n’) = 4+2 = 6
through n, so f(n) must be ≥ 7 ⇒ should reset f(n’) = 7 ⇒ use
Called “path-max equation” … ignores misleading numbers in heuristic
28
∃ solution h(n) is under-estimate
PROOF: Let G be optimal goal, with f(G) = g(G) = f G2 be suboptimal goal, with f(G2) = g(G2 ) > f If A* returns G2 ⇒ G2 is chosen over n, where n is node on optimal path to G This only happens if f(G2 ) ≤ f(n) As f is monotonically increasing along every path, ⇒ f = f(G) ≥ f(n) Hence, f ≥ f(G2 ) … ie, if g(G) ≥ g(G2) … contradicting claim that G2 is suboptimal! []
29
A* is Optimally Efficient
A* is Complete
A* is Complete
if branching factor is finite & arc costs bounded above zero (∃ε > 0 s.t. c(ai)≥ε )
Time/ Space Complexity:
30
0+4 1+5 1+5 1+3 3+3 3+4 3+4 3+2 4+1 5+2 5+0 2+3 2+4 2+3
31
Cost of one horizontal/vertical step = 1 Cost of one diagonal step = √2
f(n) = g(n) + h(n), with h(n) = straight-line distance from n to goal
32
Which heuristic? Avoiding Loops Iterative Deepening A*
34
= 6
…= 13
… = 45
35
A*( hi ) expands all nodes with
h1(n) < h2(n)
So LARGER hi() means fewer n's expanded!
f* - g(n) h1 (n) h2 (n) n
36
LARGER hi() means
As hC ≤ hM ≤ h*,
Gen'l:
f* - g(n) h1 (n) h2 (n)
37
“Effective Branching Factor” b is solution to
38
39
Solve problem, then compute backwards... If {h1, … hk} all underestimates,
Relaxation:
“exact answer to approx problem"
40
5 8 4 2 1 7 3 6
Original: Relaxed version#1:
Ie, can TELEPORT tile to blank
Relaxed version#2:
Ie, can walk over non-blank tile
Can move tile from sq A to sq B if … A is adjacent to B and B is blank.
5 8 4 2 1 7 3 6 5 8 4 2 1 7 3 6 1 2
Can move tile from sq A to sq B if … A is adjacent to B and B is blank. Can move tile from sq A to sq B if … A is adjacent to B and B is blank.
41
Patterns Databases Learning from part experiences
42
Let CLOSED be the list of states
When a new node n is generated:
If its state is in CLOSED, then discard n If it has the same state as another node in
43
s =|S|
size of the state space
r = |A|
max number of states that can be reached
Assume test if state s ∈ CLOSED is O(1)
44
Use f(n) = g(n) + h(n)
Each iteration is depth-first with cutoff
45
4 6
46
4 4 6
6
47
4 4 6
6 5
48
4 4 6
6 5 5
49
4
4 6
6 5 5 6
No more nodes to expand with Cutoff =4 Now consider Cutoff = 5
50
4 6
51
4 4 6
6
52
4 4 6
6 5
53
4 4 6
6 5 7
54
4 4 6
6 5 7 5
55
4 4 6
6 5 7 5 5
56
4 4 6
6 5 7 5 5
57
Heuristic function Greedy Best-first search Admissible heuristic A* is complete and optimal
Optimally efficient !
Consistent heuristic and repeated states Inventing Heuristics IDA*