Lecture 4 - Search
Lecture 4 - Search
Informed Search
o Informed Search
o Heuristics
o Greedy Search
o A* Search
o Graph Search
Recap: Search
Recap: Search
o Search problem:
o States (configurations of the world)
o Actions and costs
o Successor function (world dynamics)
o Start state and goal test
o Search tree:
o Nodes: represent plans for reaching states
o Plans have costs (sum of action costs)
o Search algorithm:
o Systematically builds a search tree
o Chooses an ordering of the fringe (unexplored
nodes)
o Optimal: finds least-cost plans
Up next: Informed Search
o Uninformed ▪ Informed Search
Search ▪ Heuristics
o DFS ▪ Greedy Search
o BFS ▪ A* Search
o UCS ▪ Graph Search
Example: Pancake Problem
4
2 3
2
3
4
3
4 2
3 2
2
4
3
General Tree Search
Path to reach
Action: flip Action: flip all
goal:
top two four
Flip four, flip
Cost: 2 Cost: 4
three
Total cost: 7
The One Queue
o All these search algorithms
are the same except for
fringe strategies
o Conceptually, all fringes are
priority queues (i.e. collections
of nodes with attached
priorities)
o Practically, for DFS and BFS,
you can avoid the log(n)
overhead from an actual
priority queue, by using stacks
and queues
o Can even code one
Uninformed Search
Uniform Cost Search
o Strategy: expand lowest path cost
… c
1c
2c
3
o The good: UCS is complete and
optimal!
o The bad:
o Explores options in every “direction” Start Goal
o No information about goal location
[Demo: contours UCS empty (L3D1)]
Video of Demo Contours UCS Empty
Video of Demo Contours UCS Pacman
Small Maze
Informed Search
Search Heuristics
A heuristic is:
A function that estimates how close a state is to a goal
Designed for a particular search problem
Examples: Manhattan distance, Euclidean distance for
pathing
10
5
11.2
Example: Heuristic Function
h(x)
Example: Heuristic Function
Heuristic: the number of the largest pancake that is still out of place
3
h(x)
4
3
4
3 0
4
4 3
4
4 2
3
Greedy Search
Example: Heuristic Function
h(x)
Greedy Search
o Expand the node that seems closest…
o A common case:
o Best-first takes you straight to the b
(wrong) goal …
UCS Greedy
A*
Combining UCS and Greedy
o Uniform-cost orders by path cost, or backward cost g(n)
o Greedy orders by goal proximity, or forward cost h(n)
8 g=0
S h=6
h=1 g=1
e a
1 h=5
1 3 2 g=2 g=9
S a d G b d g=4 e
h=6 h=2 h=1
h=6 1 h=5
h=2 h=0
1 g=3 g=6
c b g = 10
h=7 c G h=0 d
h=2
h=7 h=6
g = 12
o A* Search orders by the sum: f(n) = g(n) + h(n) G h=0
S h=3 h=0 G
2 B 3
h=1
o No: only stop when we dequeue a goal
Is A* Optimal?
h=6
1 A 3
S h=7
G h=0
Claim:
o A will exit the fringe before B
Optimality of A* Tree Search: Blocking
Proof:
o Imagine B is on the fringe …
o Some ancestor n of A is on the
fringe, too (maybe A!)
o Claim: n will be expanded before B
1. f(n) is less or equal to f(A)
Definition of f-cost
Admissibility of h
h = 0 at a goal
Optimality of A* Tree Search: Blocking
Proof:
o Imagine B is on the fringe …
o Some ancestor n of A is on the
fringe, too (maybe A!)
o Claim: n will be expanded before B
1. f(n) is less or equal to f(A)
2. f(A) is less than f(B)
B is suboptimal
h = 0 at a goal
Optimality of A* Tree Search: Blocking
Proof:
o Imagine B is on the fringe …
o Some ancestor n of A is on the
fringe, too (maybe A!)
o Claim: n will be expanded before B
1. f(n) is less or equal to f(A)
2. f(A) is less than f(B)
3. n expands before B
o All ancestors of A expand before B
o A expands before B
o A* search is optimal
Properties of A*
Properties of A*
Uniform-Cost A*
b b
… …
UCS vs A* Contours
366
15
o Trivial heuristics
o Bottom of lattice is the zero
heuristic (what does this give us?)
o Top of lattice is the exact heuristic
Graph Search
Tree Search: Extra Work!
o Failure to detect repeated states can cause exponentially
more work.
State Graph Search Tree
Graph Search
o In BFS, for example, we shouldn’t bother expanding the circled nodes (why?)
d e p
b c e h r q
a a h r p q f
p q f q c G
q c G a
a
Graph Search
o Idea: never expand a state twice
o How to implement:
o Tree search + set of expanded states (“closed set”)
o Expand the search tree node-by-node, but…
o Before expanding a node, check to make sure its state
has never been expanded before
o If not new, skip it, if new add to closed set
A S (0+2)
1 1
S h=4 C
h=1 A (1+4) B (1+1)
h=2 1
2
3 C (2+1) C (3+1)
B
h=0
Consistency of Heuristics
o Main idea: estimated heuristic costs ≤ actual costs
o Graph search:
o A* optimal if heuristic is consistent
o UCS optimal (h = 0 is consistent)