0% found this document useful (0 votes)
108 views59 pages

Review: Search Problem Formulation Review: Search Problem Formulation

The document discusses search problem formulation and tree search algorithms. It describes the components of a search problem including the initial state, actions, transition model, goal state, and path cost. It then explains tree search, initializing the fringe with the starting state and expanding nodes according to a search strategy until the goal is found. Finally, it covers uninformed search strategies like breadth-first, uniform-cost, depth-first, and iterative deepening search and compares their properties.

Uploaded by

ria jain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
108 views59 pages

Review: Search Problem Formulation Review: Search Problem Formulation

The document discusses search problem formulation and tree search algorithms. It describes the components of a search problem including the initial state, actions, transition model, goal state, and path cost. It then explains tree search, initializing the fringe with the starting state and expanding nodes according to a search strategy until the goal is found. Finally, it covers uninformed search strategies like breadth-first, uniform-cost, depth-first, and iterative deepening search and compares their properties.

Uploaded by

ria jain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 59

Review: Search problem formulation

Review: Search problem formulation
• Initial state
Initial state
• Actions
• Transition model
ii d l
• Goal state
• Path cost

• What is the optimal solution?
• What is the state space?
Wh i h ?
Review: Tree search
Review: Tree search
• Initialize the fringe using the starting state
the fringe using the starting state
• While the fringe is not empty
– Choose a fringe node to expand according to search strategy
g p g gy
– If the node contains the goal state, return solution
– Else expand the node and add its children to the fringe
Search strategies
Search strategies
• A search strategy is defined by picking the order of node 
expansion
• Strategies are evaluated along the following dimensions:
– Completeness: does it always find a solution if one exists?
does it always find a solution if one exists?
– Optimality: does it always find a least‐cost solution?
– Time complexity: number of nodes generated
– Space complexity: maximum number of nodes in memory
Space complexity: maximum number of nodes in memory
• Time and space complexity are measured in terms of 
– b: maximum branching factor of the search tree
– d: depth of the optimal solution
d d h f h i l l i
– m: maximum length of any path in the state space (may be infinite)
Uninformed search strategies
Uninformed search strategies
• Uninformed search strategies use only the 
search strategies use only the
information available in the problem definition

• Breadth‐first search
• Uniform‐cost search
• Depth‐first search
p
• Iterative deepening search
Breadth‐first
Breadth first search
search
• Expand shallowest unexpanded node
Expand shallowest unexpanded node
• Implementation:
– fringe
fi i FIFO
is a FIFO queue, i.e., new successors go at end
i t d

B C

D E F G
Breadth‐first
Breadth first search
search
• Expand shallowest unexpanded node
Expand shallowest unexpanded node
• Implementation:
– fringe
fi i FIFO
is a FIFO queue, i.e., new successors go at end
i t d

B C

D E F G
Breadth‐first
Breadth first search
search
• Expand shallowest unexpanded node
Expand shallowest unexpanded node
• Implementation:
– fringe
fi i FIFO
is a FIFO queue, i.e., new successors go at end
i t d

B C

D E F G
Breadth‐first
Breadth first search
search
• Expand shallowest unexpanded node
Expand shallowest unexpanded node
• Implementation:
– fringe
fi i FIFO
is a FIFO queue, i.e., new successors go at end
i t d

B C

D E F G
Breadth‐first
Breadth first search
search
• Expand shallowest unexpanded node
Expand shallowest unexpanded node
• Implementation:
– fringe
fi i FIFO
is a FIFO queue, i.e., new successors go at end
i t d

B C

D E F G
Properties of breadth‐first
Properties of breadth first search
search
• Complete? 
p
Yes (if branching factor b is finite)
• Optimal?
Yes – if cost = 1 per step
• Time?
Number of nodes in a b‐ary
N b f d i b f d h d O(bd)
tree of depth d: O(b
(d is the depth of the optimal solution)
• Space?
O(bd)

• Space is the bigger problem (more than time)
Uniform‐cost
Uniform cost search
search
• Expand least‐cost unexpanded node
• Implementation: fringe
p f g is a queue ordered by path cost (priority 
q yp (p y
queue)
• Equivalent to breadth‐first if step costs all equal

• Complete?
Yes, if step cost is greater than some positive constant ε
• Optimal?
Yes – nodes expanded in increasing order of path cost
• Time?
Number of nodes with path cost
Number of nodes with path cost ≤ cost of optimal solution (C O(bCC*// εε)
cost of optimal solution (C*)), O(b
This can be greater than O(bd): the search can explore long paths consisting 
of small steps before exploring shorter paths consisting of larger steps 
• Space?
O(bC*/ ε)
Depth‐first
Depth first search
search
• Expand deepest unexpanded node
Expand deepest unexpanded node
• Implementation:
– fringe 
fringe = LIFO queue, i.e., put successors at front
LIFO queue, i.e., put successors at front

B C

D E F G
Depth‐first
Depth first search
search
• Expand deepest unexpanded node
Expand deepest unexpanded node
• Implementation:
– fringe 
fringe = LIFO queue, i.e., put successors at front
LIFO queue, i.e., put successors at front

B C

D E F G
Depth‐first
Depth first search
search
• Expand deepest unexpanded node
Expand deepest unexpanded node
• Implementation:
– fringe 
fringe = LIFO queue, i.e., put successors at front
LIFO queue, i.e., put successors at front

B C

D E F G
Depth‐first
Depth first search
search
• Expand deepest unexpanded node
Expand deepest unexpanded node
• Implementation:
– fringe 
fringe = LIFO queue, i.e., put successors at front
LIFO queue, i.e., put successors at front

B C

D E F G
Depth‐first
Depth first search
search
• Expand deepest unexpanded node
Expand deepest unexpanded node
• Implementation:
– fringe 
fringe = LIFO queue, i.e., put successors at front
LIFO queue, i.e., put successors at front

B C

D E F G
Depth‐first
Depth first search
search
• Expand deepest unexpanded node
Expand deepest unexpanded node
• Implementation:
– fringe 
fringe = LIFO queue, i.e., put successors at front
LIFO queue, i.e., put successors at front

B C

D E F G
Depth‐first
Depth first search
search
• Expand deepest unexpanded node
Expand deepest unexpanded node
• Implementation:
– fringe 
fringe = LIFO queue, i.e., put successors at front
LIFO queue, i.e., put successors at front

B C

D E F G
Depth‐first
Depth first search
search
• Expand deepest unexpanded node
Expand deepest unexpanded node
• Implementation:
– fringe 
fringe = LIFO queue, i.e., put successors at front
LIFO queue, i.e., put successors at front

B C

D E F G
Depth‐first
Depth first search
search
• Expand deepest unexpanded node
Expand deepest unexpanded node
• Implementation:
– fringe 
fringe = LIFO queue, i.e., put successors at front
LIFO queue, i.e., put successors at front

B C

D E F G
Properties of depth‐first
Properties of depth first search
search
• Complete?
p
Fails in infinite‐depth spaces, spaces with loops
Modify to avoid repeated states along path
Æ complete in finite spaces
complete in finite spaces
• Optimal?
No – returns the first solution it finds
• Time?
Could be the time to reach a solution at maximum depth m: O(bm)
Terrible if m is much larger than d
Terrible if m is much larger than d
But if there are lots of solutions, may be much faster than BFS
• Space?
O(bm), i.e., linear space!
Iterative deepening search
Iterative deepening search
• Use DFS as a subroutine
Use DFS as a subroutine
1. Check the root
2 Do a DFS searching for a path of length 1
2. Do a DFS searching for a path of length 1
3. If there is no path of length 1, do a DFS searching 
for a path of length 2
for a path of length 2
4. If there is no path of length 2, do a DFS searching 
for a path of length 3
for a path of length 3…
Iterative deepening search
Iterative deepening search
Iterative deepening search
Iterative deepening search
Iterative deepening search
Iterative deepening search
Iterative deepening search
Iterative deepening search
Properties of iterative deepening 
searchh
• Complete?
Yes
• Optimal?
Yes, if step cost = 1
• Time?
(d+1)b0 + d b1 + (d‐1)b2 + … + bd = O(bd)
• Space?
O(bd)
( )
Informed search
Informed search
• Idea:
Idea: give the algorithm 
give the algorithm “hints”
hints  about the 
about the
desirability of different states 
– Use an evaluation function
Use an evaluation function to rank nodes and 
to rank nodes and
select the most promising one for expansion

• Greedy best‐first search
• A* search
A* h
Heuristic function
• Heuristic function h(n) estimates the cost of 
reaching goal from node n
reaching goal from node n
• Example:
Start state

Goal state
Heuristic for the Romania problem
Heuristic for the Romania problem
Greedy best‐first
Greedy best first search
search
• Expand
Expand the node that has the lowest value of 
the node that has the lowest value of
the heuristic function h(n)
Greedy best‐first
Greedy best first search example
search example
Greedy best‐first
Greedy best first search example
search example
Greedy best‐first
Greedy best first search example
search example
Greedy best‐first
Greedy best first search example
search example
Properties of greedy best‐first
Properties of greedy best first search
search
• Complete?
p
No – can get stuck in loops

start
goal
Properties of greedy best‐first
Properties of greedy best first search
search
• Complete?
p
No – can get stuck in loops
• Optimal?
No
Properties of greedy best‐first
Properties of greedy best first search
search
• Complete?
p
No – can get stuck in loops
• Optimal?
No
• Time?
( m)
Worst case: O(b
Best case: O(bd) – If h(n) is 100% accurate
• Space?
Worst case: O(bm)
How can we fix the greedy problem?
How can we fix the greedy problem?
A* search
• Idea:
Idea: avoid expanding paths that are already expensive
avoid expanding paths that are already expensive
• The evaluation function f(n) is the estimated total cost 
of the path through node n
p g to the goal:
g

ff(n) = g(n)
g + h(n)

g(n): cost so far to reach n (path cost)
h(n): estimated cost from n to goal (heuristic)
A* search example
search example
A* search example
search example
A* search example
search example
A* search example
search example
A* search example
search example
A* search example
search example
Admissible heuristics
Admissible heuristics
• A
A heuristic h(n) is admissible
heuristic h(n) is admissible if for every node n, h(n)
if for every node n, h(n)
≤ h*(n), where h*(n) is the true cost to reach the goal 
state from n
• An admissible heuristic never overestimates the cost 
to reach the goal, i.e., it is optimistic
• Example: straight line distance never overestimates 
the actual road distance
• Theorem: If h(n) is admissible, A* is optimal
Optimality of A*

n'

n*
n
• Proof by contradiction
– Let n
Let n* be an optimal goal state, i.e., f(n
be an optimal goal state, i.e., f(n*)) = C
C*
– Suppose a solution node n with f(n) > C* is about to be expanded
– Let n' be a node in the fringe that is on the path to n*
– We have f(n') = g(n') + h(n') ≤ C*
– But then, n' should be expanded before n – a contradiction
Optimality of A*

f(n*) = C* n*
n f( ) *
f(n) > C* 

n'
n g(n') ≥ f(n) > C* 
• In other words:
– Suppose A* terminates its search at n* 
– It has found a path whose actual cost
h f d h h l f( *) ( *) l
f(n*) = g(n*) is lower 
than the estimated cost f(n) of any path going through any 
g
fringe node
– Since f(n) is an optimistic estimate, there is no way n can have 
a successor goal state n’ with g(n’) < C*
Optimality of A*
Optimality of A
• A*
A  is optimally efficient 
is optimally efficient – no other tree
no other tree‐based
based 
algorithm that uses the same heuristic can 
expand fewer nodes and still be guaranteed to
expand fewer nodes and still be guaranteed to 
find the optimal solution
– Any algorithm that does not expand all nodes with 
Any algorithm that does not expand all nodes with
f(n) < C* risks missing the optimal solution
Properties of A*
Properties of A
• Complete?
p
Yes – unless there are infinitely many nodes with f(n) ≤ C*
• Optimal?
Yes
• Time?
Number of nodes for which f(n) ≤
( ) C* (exponential)
*( )
• Space?
Exponential
Designing heuristic functions
• Heuristics for the 8‐puzzle
h1(n) = number of misplaced tiles
number of misplaced tiles
h2(n) = total Manhattan distance (number of squares from 
desired location of each tile)

h1(start) = 8
h2(start) = 3+1+2+2+2+3+3+2 = 18
• Are h1 and h2 admissible?
Heuristics from relaxed problems
• A problem with fewer restrictions on the actions is 
called a relaxed problem
called a relaxed problem
• The cost of an optimal solution to a relaxed problem 
is an admissible heuristic for the original problem
is an admissible heuristic for the original problem
• If the rules of the 8‐puzzle are relaxed so that a tile 
can move anywhere, then h1(n) gives the shortest 
solution
• If the rules are relaxed so that a tile can move to any 
adjacent square then h
adjacent square, then h2(n) gives the shortest 
gives the shortest
solution
Dominance
• If h1 1 and h2 2 are both admissible heuristics and
h2(n) ≥ h1(n) for all n, (both admissible) then 
h2 dominates h1
• Which one is better for search?
Whi h i b tt f h?
– A* search expands every node with f(n) < C* or
h(n) < C* –
( ) g(n))
g(
– Therefore, A* search with h1 will expand more nodes
Dominance
• Typical search costs for the 8‐puzzle (average number of 
yp p ( g
nodes expanded for different solution depths):

• d=12 IDS  = 3,644,035 nodes


A*(h1) = 227 nodes 
A*((h2)) = 73 nodes 

• d=24  IDS  ≈ 54,000,000,000 nodes 


A*(h1) = 39,135 nodes 
A*(h2) = 1,641 nodes 
Heuristics from subproblems
Heuristics from subproblems
• Let h3((n) be the cost of getting a subset of tiles 
) g g
(say, 1,2,3,4) into their correct positions
• Can precompute and save the exact solution cost for every 
possible subproblem
ibl b bl i t
instance – pattern database
tt d t b
Combining heuristics
Combining heuristics
• Suppose
Suppose we have a collection of admissible heuristics 
we have a collection of admissible heuristics
h1(n), h2(n), …, hm(n), but none of them dominates 
the others
• How can we combine them?
h(n) = max{h1(n), h
h(n) = max{h (n) h2(n), …, h
(n) hm(n)}
Memory‐bounded
Memory bounded search
search
• The memory usage of A* can still be exorbitant
y g
• How to make A* more memory‐efficient while 
maintaining completeness and optimality?

• Iterative deepening A* search
• Recursive best‐first search, SMA*
– Forget some subtrees but remember the best f‐value in 
these subtrees and regenerate them later if necessary
these subtrees and regenerate them later if necessary

• Problems: memory‐bounded strategies can be 
y g
complicated to implement, suffer from “thrashing”
Comparison of search strategies
Time  Space 
Algorithm Complete? Optimal?
complexity complexity

Yes If all step  O(bd) O(bd)


BFS
costs are equal

UCS Yes Yes Number of nodes with g(n) ≤ C*

DFS No No O(bm) O(bm)

If all step 
IDS Yes O(bd) O(bd)
costs are equal
costs are equal

Worst case: O(bm)
Greedy No No
Best case: O(bd)

A* Yes Yes Number of nodes with g(n)+h(n) ≤ C*

You might also like