04 – Problem Solving by Searching:�Informed Search
Agenda
Last time: Problem-Solving
3
Last time: Finding a solution
Function General-Search(problem, strategy) returns a solution, or failure
initialize the search tree using the initial state problem
loop do
if there are no candidates for expansion then return failure
choose a leaf node for expansion according to strategy
if the node contains a goal state then return the corresponding solution
else expand the node and add resulting nodes to the search tree
end
4
Solution: is a sequence of operators that bring you from current state to the goal state
Basic idea: offline, systematic exploration of simulated state-space by generating successors of explored states (expanding)
Strategy: The search strategy is determined by the order in which the nodes are expanded.
A Clean Robust Algorithm
5
Function UniformCost-Search(problem, Queuing-Fn) returns a solution, or failure
open 🡨 make-queue(make-node(initial-state[problem]))
closed 🡨 [empty]
loop do
if open is empty then return failure
currnode 🡨 Remove-Front(open)
if Goal-Test[problem] applied to State(currnode) then return currnode
children 🡨 Expand(currnode, Operators[problem])
while children not empty
[… see next slide …]
end
closed 🡨 Insert(closed, currnode)
open 🡨 Sort-By-PathCost(open)
end
A Clean Robust Algorithm
6
[… see previous slide …]
children 🡨 Expand(currnode, Operators[problem])
while children not empty
child 🡨 Remove-Front(children)
if no node in open or closed has child’s state
open 🡨 Queuing-Fn(open, child)
else if there exists node in open that has child’s state
if PathCost(child) < PathCost(node)
open 🡨 Delete-Node(open, node)
open 🡨 Queuing-Fn(open, child)
else if there exists node in closed that has child’s state
if PathCost(child) < PathCost(node)
closed 🡨 Delete-Node(closed, node)
open 🡨 Queuing-Fn(open, child)
end
[… see previous slide …]
Last time: search strategies
Uninformed: Use only information available in the problem formulation
Informed: ?
7
Evaluation of search strategies
8
Uninformed vs Informed Search
9
Informed Search
10
Informed Search
11
Last time: uninformed search strategies
Uninformed search:
Use only information available in the problem formulation
12
This time: informed search
Informed search:
Use heuristics to guide the search
13
Search Heuristics
14
A heuristic is:
10
5
11.2
Example: Euclidean distance to Bucharest
15
h(state) 🡪 value
Effect of heuristics
Guide search towards the goal instead of all over the place
16
Start
Goal
Start
Goal
Uninformed
Informed
Best-first search
use an evaluation function for each node; estimate of “desirability”
QueueingFn = insert successors in decreasing order of desirability
greedy search
A* search
17
Romania with step costs in km
18
374
329
253
Greedy Search
19
Greedy search
h(n) = estimate of cost from n to goal (heuristic)
hSLD(n) = straight-line distance from n to Bucharest
20
21
22
23
24
Greedy Search
25
h=193
h= 253
h=100
h=0
h=176
Sibiu-Fagaras-Bucharest =
99+211 = 310
Sibiu-Rimnicu Vilcea-Pitesti-Bucharest =
80+97+101 = 278
1000000
Greedy Search
26
…
b
Properties of Greedy Search
e.g., Iasi > Neamt > Iasi > Neamt > …
Complete in finite space with repeated-state checking.
dramatic improvement
27
A* Search
28
A* search
evaluation function: f(n) = g(n) + h(n) with:
g(n) – cost so far to reach n
h(n) – estimated cost to goal from n
f(n) – estimated total cost of path through n to goal
h(n) ≤ h*(n) where h*(n) is the true cost from n.
For example: hSLD(n) never overestimates actual road distance.
29
Combining UCS and Greedy
30
S
a
d
b
G
h=5
h=6
h=2
1
8
1
1
2
h=6
h=0
c
h=7
3
e
h=1
1
S
a
b
c
e
d
d
G
G
g = 0 h=6
g = 1 h=5
g = 2 h=6
g = 3 h=7
g = 4 h=2
g = 6 h=0
g = 9 h=1
g = 10 h=2
g = 12 h=0
31
32
33
34
35
36
Optimality of A* (standard proof)
Suppose some suboptimal goal G2 has been generated and is in the queue. Let n be an unexpanded node on a shortest path to an optimal goal G1.
37
1
Optimality of A* (more useful proof)
38
f-contours
39
How do the contours look like when h(n) =0?
Properties of A*
40
Is A* Optimal?
41
A
G
S
1
3
h = 6
h = 0
5
h = 7
Admissible Heuristics
42
Admissible Heuristics
0 ≤ h(n) ≤ h*(n)
where h*(n) is the true cost to a nearest goal
43
15
Admissible Heuristics
44
Admissible heuristics
45
Optimality of A* Tree Search
Assume:
Claim:
46
…
A
B
Optimality of A* Tree Search: Blocking
Proof:
47
f(n) = g(n) + h(n) Definition of f-cost
f(n) ≤ g(A) Admissibility of h
…
g(A) = f(A) h = 0 at a goal
A
B
n
Optimality of A* Tree Search: Blocking
Proof:
48
…
A
B
n
g(A) < g(B) Suboptimality of B
f(A) < f(B) h = 0 at a goal
Optimality of A* Tree Search: Blocking
Proof:
49
…
A
B
n
f(n) ≤ f(A) < f(B)
Properties of A*
50
…
b
…
b
Uniform-Cost
A*
UCS vs A* Contours
51
Start
Goal
Start
Goal
Comparison
52
Greedy
Uniform Cost
A*
A* Search Algorithms
53
54
function UNIFORM-COST-SEARCH(problem) returns a solution, or failure
initialize the explored set to be empty
initialize the frontier as a priority queue using g(n) as the priority
add initial state of problem to frontier with priority g(S) = 0� loop do
if the frontier is empty then
return failure� choose a node and remove it from the frontier� if the node contains a goal state then
return the corresponding solution
add the node state to the explored set
for each resulting child from node
if the child state is not already in the frontier or explored set then
add child to the frontier
else if the child is already in the frontier with higher g(n) then
replace that frontier node with child
55
function A-STAR-SEARCH(problem) returns a solution, or failure
initialize the explored set to be empty
initialize the frontier as a priority queue using f(n) = g(n) + h(n) as the priority
add initial state of problem to frontier with priority f(S) = 0 + h(S)� loop do
if the frontier is empty then
return failure� choose a node and remove it from the frontier� if the node contains a goal state then
return the corresponding solution
add the node state to the explored set
for each resulting child from node
if the child state is not already in the frontier or explored set then
add child to the frontier
else if the child is already in the frontier with higher f(n) then
replace that frontier node with child
A* Applications
56
Image: maps.google.com
Creating Heuristics
57
Creating Admissible Heuristics
58
15
366
Example: 8 Puzzle
59
Start State
Goal State
Actions
8 Puzzle I
60
8
| Average nodes expanded when the optimal path has… | ||
| …4 steps | …8 steps | …12 steps |
UCS | 112 | 6,300 | 3.6 x 106 |
A*TILES | 13 | 39 | 227 |
Start State
Goal State
Statistics from Andrew Moore
8 Puzzle II
61
3 + 1 + 2 + … = 18
| Average nodes expanded when the optimal path has… | ||
| …4 steps | …8 steps | …12 steps |
A*TILES | 13 | 39 | 227 |
A*MANHATTAN | 12 | 25 | 73 |
Start State
Goal State
Combining heuristics
∀n ha(n) ≥ hc(n)
h(n) = max( ha(n), hb(n) )
62
Optimality of A* Graph Search
63
Consistency of Heuristics
heuristic cost ≤ actual cost to goal
h(A) ≤ actual cost from A to G
“heuristic step cost” ≤ actual cost for each step
h(A) – h(C) ≤ cost(A to C)
triangle inequality
h(A) ≤ cost(A to C) + h(C)
64
A
C
G
h=4
h=1
1
h=2
Optimality of A* Graph Search
65
…
f ≤ 3
f ≤ 2
f ≤ 1
Optimality
66
Relaxed Problem
67
A*: Summary
68
A*: Summary
69
Next time
70
QUESTIONS