02 Search
02 Search
02 Search
Chapter 3
(Based on slides by Stuart Russell, Subbarao Kambhampati,
Dan Weld, Oren Etzioni, Henry Kautz, Richard Korf, and
other UW-AI faculty)
Agent’s Knowledge Representation
Output:
• Path: start a state satisfying goal test
• [May require shortest path]
4
What is Search?
• Search is a class of techniques for systematically
finding or constructing solutions to problems.
• Examples:
• Path planning
• Games
• Natural Language Processing
• Machine learning
• …
6
Example: The 8-puzzle
• states?
• actions?
• goal test?
• path cost?
7
Example: The 8-puzzle
8
Search Tree Example:
Fragment of 8-Puzzle Problem Space
9
Example: robotic assembly
11
Example: N Queens
• Input: Q
– Set of states Q
Q
– Operators [and costs] Q
– Start state
• Output
12
Implementation: states vs. nodes
• The Expand function creates new nodes, filling in the various fields and using the
SuccessorFn of the problem to create the corresponding states.
•
13
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?
– time complexity: number of nodes generated
– space complexity: maximum number of nodes in memory
– optimality: does it always find a least-cost solution?
– systematicity: does it visit each state at most once?
14
Uninformed search strategies
• Breadth-first search
• Depth-first search
• Depth-limited search
16
Depth First Search
• Maintain stack of nodes to visit
• Evaluation
– Complete? No
– Time Complexity?
O(b^m) a
– Space Complexity?
O(bm)
b c
d e f g h
http://www.youtube.com/watch?v=dtoFAvtVE4U
17
Breadth First Search: shortest first
• Maintain queue of nodes to visit
• Evaluation
– Complete? Yes (b is finite)
– Time Complexity?
O(b^d) a
– Space Complexity?
O(b^d)
b c
– Optimal?
Yes, if stepcost=1
d e f g h
18
Uniform Cost Search: cheapest first
• Maintain queue of nodes to visit
• Evaluation
– Complete? Yes (b is finite)
– Time Complexity?
O(b^(C*/e)) a
1 5
– Space Complexity?
O(b^(C*/e))
b c
– Optimal?
Yes 2 6 1
3 4
d e f g h
http://www.youtube.com/watch?v=z6lUnb9ktkE
19
Memory Limitation
• Suppose:
2 GHz CPU
1 GB main memory
100 instructions / expansion
5 bytes / node
20
Idea 1: Beam Search
• Maintain a constant sized frontier
• Whenever the frontier becomes large
– Prune the worst nodes
Optimal: no
Complete: no
Idea 2: Iterative deepening search
22
Iterative deepening search l =0
23
Iterative deepening search l =1
24
Iterative deepening search l =2
25
Iterative deepening search l =3
26
Iterative deepening search
• Number of nodes generated in a depth-limited search to depth d with branching
factor b:
• NDLS = b0 + b1 + b2 + … + bd-2 + bd-1 + bd
• For b = 10, d = 5,
•
– NDLS = 1 + 10 + 100 + 1,000 + 10,000 + 100,000 = 111,111
–
– NIDS = 6 + 50 + 400 + 3,000 + 20,000 + 100,000 = 123,456
–
• Time?
– (d+1)b0 + d b1 + (d-1)b2 + … + bd = O(bd)
• Space?
– O(bd)
• Optimal?
– Yes, if step cost = 1
– Can be modified to explore uniform cost tree (iterative lengthening)
• Systematic?
28
Cost of Iterative Deepening
b ratio ID to DLS
2 3
3 2
5 1.5
10 1.2
25 1.08
100 1.02
29
Summary of algorithms
31
A
BFS: A,B,G
DFS: A,B,C,D,G
B IDDFS: (A), (A, B, G)
DFS: A,B,A,B,A,B,A,B,A,B
B IDDFS: (A), (A, B, G)
35
vs. Bidirectional
• Time?
– O(bd/2)
• Space?
– O(bd/2)
• Optimal?
– Yes if uniform cost search used in both directions
37
Breadth-First goes level by level
Visualizing Breadth-First & Uniform Cost Search
This is also a proof of
optimality…
41