Professional Documents
Culture Documents
Informed Search
Informed Search
Assistant Professor
Department of Computer Science and Engineering
Islamic University of Technology
1
=49
1/49
Example: Pancake Problem
2
=49
2/49
Example: Pancake Problem
3
=49
3/49
Example: Pancake Problem
3
=49
3/49
Example: Pancake Problem
3
=49
3/49
Example: Pancake Problem
3
=49
3/49
Example: Pancake Problem
3
=49
3/49
Example: Pancake Problem
4
=49
4/49
Example: Pancake Problem
State space graph1 with costs as weights
1
Slide does not contain the entire state space graph 5
=49
5/49
General Search Tree
function Tree-Search(problem, strategy) returns a solution, or failure
initialize the search tree using the initial state of problem
loop do
if there are no candidates for expansion then return failure
choose a leaf node according to strategy
if the node contains a goal state then return the corresponding solution
else expand the node and add the resulting node to the search tree
end
6
=49
6/49
General Search Tree
function Tree-Search(problem, strategy) returns a solution, or failure
initialize the search tree using the initial state of problem
loop do
if there are no candidates for expansion then return failure
choose a leaf node according to strategy
if the node contains a goal state then return the corresponding solution
else expand the node and add the resulting node to the search tree
end
2 4
3
6
=49
6/49
General Search Tree
function Tree-Search(problem, strategy) returns a solution, or failure
initialize the search tree using the initial state of problem
loop do
if there are no candidates for expansion then return failure
choose a leaf node according to strategy
if the node contains a goal state then return the corresponding solution
else expand the node and add the resulting node to the search tree
end
2 4
3
6 7
6
=49
6/49
Informed Search
Video: ContoursPacmanSmallMaze-UCS
7
=49
7/49
Search Heuristics
A function that estimates how close a state is to a goal
Designed for a particular search problem
8
=49
8/49
Search Heuristics
A function that estimates how close a state is to a goal
Designed for a particular search problem
8
=49
8/49
Search Heuristics
A function that estimates how close a state is to a goal
Designed for a particular search problem
Example: Manhatten distance
10
8
=49
8/49
Search Heuristics
A function that estimates how close a state is to a goal
Designed for a particular search problem
Example: Manhatten distance, Euclidean distance for pathing
10
5
11.2
8
=49
8/49
Example: Heuristic Function
9
=49
9/49
Example: Heuristic Function
Straight-line distance to
Bucharest
Arad 366
Bucharest 0
Craiova 160
Dobreta 242
Eforie 161
Fagaras 178
Giurgiu 77
Hirsova 151
Iasi 226
Lugoj 244
Mehadia 241
Neamt 234
Oradea 380
Pitesti 98
Rimnieu Vileea 193
Sibiu 253
Timisoara 329
Urziceni 80
Vaslui 199
Zerind 374
9
=49
9/49
Example: Heuristic Function
10
=49
10/49
Example: Heuristic Function
10
=49
10/49
Example: Heuristic Function
10
=49
10/49
Example: Heuristic Function
11
=49
11/49
Greedy Search
12
=49
12/49
Greedy Search
Arad
366
12
=49
12/49
Greedy Search
Arad
366
12
=49
12/49
Greedy Search
Arad
366
12
=49
12/49
Greedy Search
Arad
366
Sibiu Bucharest
253 0
12
=49
12/49
Greedy Search
Arad
366
Sibiu Bucharest
253 0
12
=49
12/49
Greedy Search
A common case:
Best-first takes you straight to the (wrong)
goal
A common case:
Best-first takes you straight to the (wrong)
goal
Worst-case: like a badly-guided DFS
14
=49
14/49
A* Search
15
=49
15/49
A* Search
UCS
15
=49
15/49
A* Search
UCS Greedy
15
=49
15/49
A* Search
UCS Greedy
A*
15
=49
15/49
Combining UCS and Greedy
e
1
8
1
S a d G
6 1 5 3 2 2 0
1
c b
7 1 6
16
=49
16/49
Combining UCS and Greedy
e
1
8
1
S a d G
6 1 5 3 2 2 0
1
c b
7 1 6
16
=49
16/49
Combining UCS and Greedy
e
1
8
1
S a d G
6 1 5 3 2 2 0
1
c b
7 1 6
16
=49
16/49
Combining UCS and Greedy
e
1
8
1
S a d G
6 1 5 3 2 2 0
1
c b
7 1 6
16
=49
16/49
When should A* terminate?
Should we stop when we enqueue a goal?
17
=49
17/49
When should A* terminate?
Should we stop when we enqueue a goal?
A
2
2 2
S G
3 0
2 3
B
1
17
=49
17/49
When should A* terminate?
Should we stop when we enqueue a goal?
A
2
2 2
S G
3 0
2 3
B
1
No: only stop when you dequeue the goal
17
=49
17/49
Is A* optimal?
18
=49
18/49
Is A* optimal?
A
6
1
3
S
5
7 G
0
18
=49
18/49
Is A* optimal?
A
6
1
3
S
5
7 G
0
18
=49
18/49
Is A* optimal?
A
6
1
3
S
5
7 G
0
18
=49
18/49
Is A* optimal?
A
6
1
3
S
5
7 G
0
18
=49
18/49
Admissible Heuristics
19
=49
19/49
Admissible Heuristics
20
=49
20/49
Admissible Heuristics
A heuristic h is admissible (optimistic) if:
0 h(n) h (n)
21
=49
21/49
Admissible Heuristics
A heuristic h is admissible (optimistic) if:
0 h(n) h (n)
21
=49
21/49
Admissible Heuristics
A heuristic h is admissible (optimistic) if:
0 h(n) h (n)
21
=49
21/49
Admissible Heuristics
A heuristic h is admissible (optimistic) if:
0 h(n) h (n)
21
=49
21/49
Optimality of A* Tree Search
22
=49
22/49
Optimality of A* Tree Search
Assume:
A is an optimal goal node
B is a suboptimal goal node
h is admissible
Claim:
A will exit the fringe before B
23
=49
23/49
Optimality of A* Tree Search
Proof:
24
=49
24/49
Optimality of A* Tree Search
Proof:
Imagine B is on the fringe
24
=49
24/49
Optimality of A* Tree Search
Proof:
Imagine B is on the fringe
Some ancestor n of A is also on the fringe, too (maybe A)
24
=49
24/49
Optimality of A* Tree Search
Proof:
Imagine B is on the fringe
Some ancestor n of A is also on the fringe, too (maybe A)
Claim: n will be expanded before B
24
=49
24/49
Optimality of A* Tree Search
Proof:
Imagine B is on the fringe
Some ancestor n of A is also on the fringe, too (maybe A)
Claim: n will be expanded before B
1. f (n) f (A)
24
=49
24/49
Optimality of A* Tree Search
Proof:
Imagine B is on the fringe
Some ancestor n of A is also on the fringe, too (maybe A)
Claim: n will be expanded before B
1. f (n) f (A)
I f (n) = g(n) + h(n) [Definition of f-cost]
24
=49
24/49
Optimality of A* Tree Search
Proof:
Imagine B is on the fringe
Some ancestor n of A is also on the fringe, too (maybe A)
Claim: n will be expanded before B
1. f (n) f (A)
I f (n) = g(n) + h(n) [Definition of f-cost]
I f (n) g(A) [Admissiblity of heuristics]
24
=49
24/49
Optimality of A* Tree Search
Proof:
Imagine B is on the fringe
Some ancestor n of A is also on the fringe, too (maybe A)
Claim: n will be expanded before B
1. f (n) f (A)
I f (n) = g(n) + h(n) [Definition of f-cost]
I f (n) g(A) [Admissiblity of heuristics]
I g(A) = f (A) [h(A)=0 at goal]
24
=49
24/49
Optimality of A* Tree Search
Proof:
Imagine B is on the fringe
Some ancestor n of A is also on the fringe, too (maybe A)
Claim: n will be expanded before B
1. f (n) f (A)
I f (n) = g(n) + h(n) [Definition of f-cost]
I f (n) g(A) [Admissiblity of heuristics]
I g(A) = f (A) [h(A)=0 at goal]
2. f (A) < f (B)
24
=49
24/49
Optimality of A* Tree Search
Proof:
Imagine B is on the fringe
Some ancestor n of A is also on the fringe, too (maybe A)
Claim: n will be expanded before B
1. f (n) f (A)
I f (n) = g(n) + h(n) [Definition of f-cost]
I f (n) g(A) [Admissiblity of heuristics]
I g(A) = f (A) [h(A)=0 at goal]
2. f (A) < f (B)
I g(A) < g(B) [B is suboptimal]
24
=49
24/49
Optimality of A* Tree Search
Proof:
Imagine B is on the fringe
Some ancestor n of A is also on the fringe, too (maybe A)
Claim: n will be expanded before B
1. f (n) f (A)
I f (n) = g(n) + h(n) [Definition of f-cost]
I f (n) g(A) [Admissiblity of heuristics]
I g(A) = f (A) [h(A)=0 at goal]
2. f (A) < f (B)
I g(A) < g(B) [B is suboptimal]
I f (A) < f (B) [h=0 at goal]
24
=49
24/49
Optimality of A* Tree Search
Proof:
Imagine B is on the fringe
Some ancestor n of A is also on the fringe, too (maybe A)
Claim: n will be expanded before B
1. f (n) f (A)
I f (n) = g(n) + h(n) [Definition of f-cost]
I f (n) g(A) [Admissiblity of heuristics]
I g(A) = f (A) [h(A)=0 at goal]
2. f (A) < f (B)
I g(A) < g(B) [B is suboptimal]
I f (A) < f (B) [h=0 at goal]
3. f (n) f (A) < f (B) ! n expands before B
24
=49
24/49
Optimality of A* Tree Search
Proof:
Imagine B is on the fringe
Some ancestor n of A is also on the fringe, too (maybe A)
Claim: n will be expanded before B
1. f (n) f (A)
I f (n) = g(n) + h(n) [Definition of f-cost]
I f (n) g(A) [Admissiblity of heuristics]
I g(A) = f (A) [h(A)=0 at goal]
2. f (A) < f (B)
I g(A) < g(B) [B is suboptimal]
I f (A) < f (B) [h=0 at goal]
3. f (n) f (A) < f (B) ! n expands before B
All ancestor of A expand before B
24
=49
24/49
Optimality of A* Tree Search
Proof:
Imagine B is on the fringe
Some ancestor n of A is also on the fringe, too (maybe A)
Claim: n will be expanded before B
1. f (n) f (A)
I f (n) = g(n) + h(n) [Definition of f-cost]
I f (n) g(A) [Admissiblity of heuristics]
I g(A) = f (A) [h(A)=0 at goal]
2. f (A) < f (B)
I g(A) < g(B) [B is suboptimal]
I f (A) < f (B) [h=0 at goal]
3. f (n) f (A) < f (B) ! n expands before B
All ancestor of A expand before B
A expands before B ! A* search is optimal
24
=49
24/49
UCS vs A*
UCS
A*
25
=49
25/49
UCS vs A*
Greedy UCS A*
26
=49
26/49
A* Applications
Video games
Pathing/routing problems
Resource planning problems
Robot motion planning
Language analysis
Machine translation
Speech recognition
:::
27
=49
27/49
Creating Admissible Heuristics
28
=49
28/49
Creating Admissible Heuristics
Most of the work in solving hard search problems optimally is in coming up with
admissible heuristics
29
=49
29/49
Creating Admissible Heuristics
Most of the work in solving hard search problems optimally is in coming up with
admissible heuristics
Often, admissible heuristics are solutions to relaxed problems, where new actions
are available
29
=49
29/49
Creating Admissible Heuristics
Most of the work in solving hard search problems optimally is in coming up with
admissible heuristics
Often, admissible heuristics are solutions to relaxed problems, where new actions
are available
29
=49
29/49
Example: 8 Puzzle
31
=49
31/49
Example: 8 Puzzle
Attempt 1:
Number of misplaced tiles
Why is it admissible?
31
=49
31/49
Example: 8 Puzzle
Attempt 1:
Number of misplaced tiles
Why is it admissible?
h(start) = 8
31
=49
31/49
Example: 8 Puzzle
Attempt 1:
Number of misplaced tiles
Why is it admissible?
h(start) = 8
31
=49
31/49
Example: 8 Puzzle
Attempt 1:
Number of misplaced tiles
Why is it admissible?
h(start) = 8
Relaxed-problem heuristic
31
=49
31/49
Example: 8 Puzzle
Attempt 1:
Number of misplaced tiles
Why is it admissible?
h(start) = 8
Relaxed-problem heuristic
31
=49
31/49
Example: 8 Puzzle
Attempt 2:
What if we had an easier 8-puzzle
where any tile could slide any direction
at any time, ignoring other tiles?
32
=49
32/49
Example: 8 Puzzle
Attempt 2:
What if we had an easier 8-puzzle
where any tile could slide any direction
at any time, ignoring other tiles?
Total Manhatten distance
32
=49
32/49
Example: 8 Puzzle
Attempt 2:
What if we had an easier 8-puzzle
where any tile could slide any direction
at any time, ignoring other tiles?
Total Manhatten distance
Why is it admissible?
32
=49
32/49
Example: 8 Puzzle
Attempt 2:
What if we had an easier 8-puzzle
where any tile could slide any direction
at any time, ignoring other tiles?
Total Manhatten distance
Why is it admissible?
h(start) = 3 + 1 + 2 + = 18
32
=49
32/49
Example: 8 Puzzle
Attempt 2:
What if we had an easier 8-puzzle
where any tile could slide any direction
at any time, ignoring other tiles?
Total Manhatten distance
Why is it admissible?
h(start) = 3 + 1 + 2 + = 18
32
=49
32/49
Example: 8 Puzzle
Attempt 3?
What if we use the actual costs as
heuristics?
Would it be admissible?
Would we save on nodes expanded?
What’s wrong with it?
33
=49
33/49
Example: 8 Puzzle
Attempt 3?
What if we use the actual costs as
heuristics?
Would it be admissible?
Would we save on nodes expanded?
What’s wrong with it?
With A*: a trade-off between quality of estimate and work per node
33
=49
33/49
Example: 8 Puzzle
Attempt 3?
What if we use the actual costs as
heuristics?
Would it be admissible?
Would we save on nodes expanded?
What’s wrong with it?
With A*: a trade-off between quality of estimate and work per node
As heuristics get closer to the true cost, you will expand fewer nodes but usually do
more work per node to compute the heuristic itself
33
=49
33/49
Semi-Lattice of Heuristics
Trivial heuristics
Bottom of lattice is the zero heuristic
Top of lattice is the exact heuristic
Dominance: ha hc if
8n : ha (n) hc (n)
34
=49
34/49
Graph Search
35
=49
35/49
Graph Search
Tree search requires extra work: Failure to detect repeated states can cause
exponentially more work
State Space
Graph
36
=49
36/49
Graph Search
Tree search requires extra work: Failure to detect repeated states can cause
exponentially more work
State Space
Search Tree
Graph
36
=49
36/49
Graph Search
Idea: never expand a state twice
37
=49
37/49
Graph Search
Idea: never expand a state twice
How to implement?
Tree search + set of expanded states (”closed set”)
Expand the search tree node-by-node, but...
Before expanding a node, check to make sure its state has never been expanded before
If not new, skip it, if new add to closed set
37
=49
37/49
Graph Search
Idea: never expand a state twice
How to implement?
Tree search + set of expanded states (”closed set”)
Expand the search tree node-by-node, but...
Before expanding a node, check to make sure its state has never been expanded before
If not new, skip it, if new add to closed set
Important: store the closed set as a set, not a list
37
=49
37/49
Graph Search
Idea: never expand a state twice
How to implement?
Tree search + set of expanded states (”closed set”)
Expand the search tree node-by-node, but...
Before expanding a node, check to make sure its state has never been expanded before
If not new, skip it, if new add to closed set
Important: store the closed set as a set, not a list
Can graph search wreck completeness? Why/why not?
37
=49
37/49
Graph Search
Idea: never expand a state twice
How to implement?
Tree search + set of expanded states (”closed set”)
Expand the search tree node-by-node, but...
Before expanding a node, check to make sure its state has never been expanded before
If not new, skip it, if new add to closed set
Important: store the closed set as a set, not a list
Can graph search wreck completeness? Why/why not?
How about optimality?
37
=49
37/49
A* Graph Search Gone Wrong?
A
1 1
S C
1
2 3
B
38
=49
38/49
A* Graph Search Gone Wrong?
h=4
A
1 1
h=1
S C
h=2
1
2 3
B
h=1
G
h=0
38
=49
38/49
A* Graph Search Gone Wrong?
h=4 S(0+2)
A
1 1
h=1
S C
h=2
1
2 3
B
h=1
G
h=0
38
=49
38/49
A* Graph Search Gone Wrong?
h=4 S(0+2)
A
1 1 A(1+4) B(1+1)
h=1
S C
h=2
1
2 3
B
h=1
G
h=0
38
=49
38/49
A* Graph Search Gone Wrong?
h=4 S(0+2)
A
1 1 A(1+4) B(1+1)
h=1
S C
h=2
1 C(3+1)
2 3
B
h=1
G
h=0
38
=49
38/49
A* Graph Search Gone Wrong?
h=4 S(0+2)
A
1 1 A(1+4) B(1+1)
h=1
S C
h=2
1 C(3+1)
2 3
B
h=1 G(6+0)
G
h=0
38
=49
38/49
A* Graph Search Gone Wrong?
h=4 S(0+2)
A
1 1 A(1+4) B(1+1)
h=1
S C
h=2
1 C(2+1) C(3+1)
2 3
B
h=1 G(6+0)
G
h=0
38
=49
38/49
A* Graph Search Gone Wrong?
h=4 S(0+2)
A
1 1 A(1+4) B(1+1)
h=1
S C
h=2
1 C(2+1) C(3+1)
2 3
B
h=1 G(5+0) G(6+0)
G
h=0
38
=49
38/49
Consistency of Heuristics
39
=49
39/49
Consistency of Heuristics
39
=49
39/49
Consistency of Heuristics
39
=49
39/49
Consistency of Heuristics
39
=49
39/49
Consistency of Heuristics
39
=49
39/49
Consistency of Heuristics
39
=49
39/49
Consistency of Heuristics
39
=49
39/49
Consistency of Heuristics
39
=49
39/49
Optimality of A* Graph Search
40
=49
40/49
Optimality of A* Graph Search
Sketch: consider what A* does with a
consistent heuristic:
Fact 1: In tree search, A* expands nodes in
increasing total f value (f-contours)
Fact 2: For every state s, nodes that reach s
optimally are expanded before nodes that
reach s suboptimally
Result: A* graph search is optimal
41
=49
41/49
Optimality
Tree search:
A* is optimal if heuristic is admissible
UCS is a special case (h = 0)
Graph search:
A* optimal if heuristic is consistent
UCS optimal (h = 0 is consistent)
Consistency implies admissiblity
In general, most natural admissible
heuristics tend to be consistent, especially if
from relaxed problems
42
=49
42/49
A* Search: Summary
43
=49
43/49
A* Search: Summary
A* uses both backward costs and (estimates of) forward costs
A* is optimal with admissible / consistent heuristics
Heuristic design is key: often use relaxed problems
44
=49
44/49
Tree Search Pseudo-Code
function Tree-Search(problem, fringe) returns a solution, or failure
fringe Insert(Make-Node(initial-state[problem]), fringe)
loop do
if fringe is empty then return failure
node Remove-Front(fringe)
if Goal-Test(problem, state[node]) then return node
for child-node in Expand(state[node], problem) do
fringe Insert(child-node, fringe)
end
end
45
=49
45/49
Graph Search Pseudo-Code
function Graph-Search(problem, fringe) return a solution, or failure
closed an empty set
fringe Insert(Make-Node(initial-state[problem]), fringe)
loop do
if fringe is empty then return failure
node Remove-Front(fringe)
if Goal-Test(problem, state[node]) then return node
if state[node] is not in closed then
add state[node] to closed
for child-node in Expand(state[node], problem) do
fringe Insert(child-node, fringe)
end
end
46
=49
46/49
Optimality of A* Graph Search
47
=49
47/49
Optimality of A* Graph Search
Proof:
New possible problem: some n on path to G*
isn’t in queue when we need it, because some
worse n0 for the same state dequeued and
expanded first (disaster!)
Take the highest such n in tree
Let p be the ancestor of n that was on the
queue when n0 was popped
f (p) < f (n) because of consistency
f (n) < f (n0 ) because n0 is suboptimal
p would have been expanded before n0
Contradiction!
48
=49
48/49
Optimality of A* Graph Search
Proof:
New possible problem: some n on path to G*
isn’t in queue when we need it, because some
worse n0 for the same state dequeued and
expanded first (disaster!)
Take the highest such n in tree
Let p be the ancestor of n that was on the
queue when n0 was popped
f (p) < f (n) because of consistency
f (n) < f (n0 ) because n0 is suboptimal
p would have been expanded before n0
Contradiction!
48
=49
48/49
Optimality of A* Graph Search
Proof:
New possible problem: some n on path to G*
isn’t in queue when we need it, because some
worse n0 for the same state dequeued and
expanded first (disaster!)
Take the highest such n in tree
Let p be the ancestor of n that was on the
queue when n0 was popped
f (p) < f (n) because of consistency
f (n) < f (n0 ) because n0 is suboptimal
p would have been expanded before n0
Contradiction!
48
=49
48/49
Optimality of A* Graph Search
Proof:
New possible problem: some n on path to G*
isn’t in queue when we need it, because some
worse n0 for the same state dequeued and
expanded first (disaster!)
Take the highest such n in tree
Let p be the ancestor of n that was on the
queue when n0 was popped
f (p) < f (n) because of consistency
f (n) < f (n0 ) because n0 is suboptimal
p would have been expanded before n0
Contradiction!
48
=49
48/49
Optimality of A* Graph Search
Proof:
New possible problem: some n on path to G*
isn’t in queue when we need it, because some
worse n0 for the same state dequeued and
expanded first (disaster!)
Take the highest such n in tree
Let p be the ancestor of n that was on the
queue when n0 was popped
f (p) < f (n) because of consistency
f (n) < f (n0 ) because n0 is suboptimal
p would have been expanded before n0
Contradiction!
48
=49
48/49
Suggested Reading
Russell & Norvig: Section 3.5-3.6
49
=49
49/49