Professional Documents
Culture Documents
Chapter 3 2 Chapter 3 5
Chapter 3 3 Chapter 3 6
Problem types Example: vacuum world
Deterministic, fully observable =⇒ single-state problem Single-state, start in #5. Solution??
Agent knows exactly which state it will be in; solution is a sequence [Right, Suck] 1 2
Chapter 3 7 Chapter 3 10
Chapter 3 8 Chapter 3 11
Chapter 3 9 Chapter 3 12
Selecting a state space Example: vacuum world state space graph
R
L
⇒ state space must be abstracted for problem solving S S
L L
(Abstract) action = complex combination of real actions S S
S S
e.g., “Arad → Zerind” represents a complex set R
of possible routes, detours, rest stops, etc. L R
(Abstract) solution = states??: integer dirt and robot locations (ignore dirt amounts etc.)
set of real paths that are solutions in the real world actions??: Lef t, Right, Suck, N oOp
goal test??
Each abstract action should be “easier” than the original problem!
path cost??
Chapter 3 13 Chapter 3 16
Example: vacuum world state space graph Example: vacuum world state space graph
R R
L R L R
L L
S S S S
R R R R
L R L R L R L R
L L L L
S S S S
S S S S
R R
L R L R
L L
S S S S
states?? states??: integer dirt and robot locations (ignore dirt amounts etc.)
actions?? actions??: Lef t, Right, Suck, N oOp
goal test?? goal test??: no dirt
path cost?? path cost??
Chapter 3 14 Chapter 3 17
Example: vacuum world state space graph Example: vacuum world state space graph
R R
L R L R
L L
S S S S
R R R R
L R L R L R L R
L L L L
S S S S
S S S S
R R
L R L R
L L
S S S S
states??: integer dirt and robot locations (ignore dirt amounts etc.) states??: integer dirt and robot locations (ignore dirt amounts etc.)
actions?? actions??: Lef t, Right, Suck, N oOp
goal test?? goal test??: no dirt
path cost?? path cost??: 1 per action (0 for N oOp)
Chapter 3 15 Chapter 3 18
Example: The 8-puzzle Example: The 8-puzzle
7 2 4 5
1 2 3 7 2 4 5
1 2 3
5 6 4 5 6 5 6 4 5 6
8 3 1 7 8 8 3 1 7 8
Chapter 3 19 Chapter 3 22
5 6 4 5 6 5 6 4 5 6
8 3 1 7 8 8 3 1 7 8
states??: integer locations of tiles (ignore intermediate positions) states??: integer locations of tiles (ignore intermediate positions)
actions?? actions??: move blank left, right, up, down (ignore unjamming etc.)
goal test?? goal test??: = goal state (given)
path cost?? path cost??: 1 per move
[Note: optimal solution of n-Puzzle family is NP-hard]
Chapter 3 20 Chapter 3 23
5 6 4 5 6
R
8 3 1 7 8
Chapter 3 21 Chapter 3 24
Tree search algorithms Tree search example
Basic idea: Arad
offline, simulated exploration of state space
by generating successors of already-explored states
Sibiu Timisoara Zerind
(a.k.a. expanding states)
function Tree-Search( problem, strategy) returns a solution, or failure Arad Fagaras Oradea Rimnicu Vilcea Arad Lugoj Arad Oradea
Chapter 3 25 Chapter 3 28
depth = 6
State 5 4 Node
g=6
6 1 88
state
7 3 22
The Expand function creates new nodes, filling in the various fields and
using the SuccessorFn of the problem to create the corresponding states.
Chapter 3 26 Chapter 3 29
Chapter 3 27 Chapter 3 30
Search strategies Breadth-first search
A strategy is defined by picking the order of node expansion Expand shallowest unexpanded node
Chapter 3 31 Chapter 3 34
Uniform-cost search A
Depth-first search
Depth-limited search
B C
Chapter 3 32 Chapter 3 35
B C B C
D E F G
D E F G
Chapter 3 33 Chapter 3 36
Properties of breadth-first search Properties of breadth-first search
Complete?? Complete?? Yes (if b is finite)
Time?? 1 + b + b2 + b3 + . . . + bd + b(bd − 1) = O(bd+1), i.e., exp. in d
Space?? O(bd+1) (keeps every node in memory)
Optimal??
Chapter 3 37 Chapter 3 40
Chapter 3 38 Chapter 3 41
Chapter 3 39 Chapter 3 42
Depth-first search Depth-first search
Expand deepest unexpanded node Expand deepest unexpanded node
Implementation: Implementation:
fringe = LIFO queue, i.e., put successors at front fringe = LIFO queue, i.e., put successors at front
A A
B C B C
D E F G D E F G
H I J K L M N O H I J K L M N O
Chapter 3 43 Chapter 3 46
B C B C
D E F G D E F G
H I J K L M N O H I J K L M N O
Chapter 3 44 Chapter 3 47
B C B C
D E F G D E F G
H I J K L M N O H I J K L M N O
Chapter 3 45 Chapter 3 48
Depth-first search Depth-first search
Expand deepest unexpanded node Expand deepest unexpanded node
Implementation: Implementation:
fringe = LIFO queue, i.e., put successors at front fringe = LIFO queue, i.e., put successors at front
A A
B C B C
D E F G D E F G
H I J K L M N O H I J K L M N O
Chapter 3 49 Chapter 3 52
B C B C
D E F G D E F G
H I J K L M N O H I J K L M N O
Chapter 3 50 Chapter 3 53
B C B C
D E F G D E F G
H I J K L M N O H I J K L M N O
Chapter 3 51 Chapter 3 54
Properties of depth-first search Properties of depth-first search
Complete?? Complete?? No: fails in infinite-depth spaces, spaces with loops
Modify to avoid repeated states along path
⇒ complete in finite spaces
Time?? O(bm): terrible if m is much larger than d
but if solutions are dense, may be much faster than breadth-first
Space?? O(bm), i.e., linear space!
Optimal??
Chapter 3 55 Chapter 3 58
Chapter 3 56 Chapter 3 59
Chapter 3 57 Chapter 3 60
Iterative deepening search Iterative deepening search l = 2
for depth ← 0 to ∞ do D E F G D E F G D E F G D E F G
Chapter 3 61 Chapter 3 64
Limit = 0 A A Limit = 3 A A A A
B C B C B C B C
D E F G D E F G D E F G D E F G
H I J K L M N O H I J K L M N O H I J K L M N O H I J K L M N O
A A A A
B C B C B C B C
D E F G D E F G D E F G D E F G
H I J K L M N O H I J K L M N O H I J K L M N O H I J K L M N O
A A A A
B C B C B C B C
D E F G D E F G D E F G D E F G
H I J K L M N O H I J K L M N O H I J K L M N O H I J K L M N O
Chapter 3 62 Chapter 3 65
B C B C B C B C
Chapter 3 63 Chapter 3 66
Properties of iterative deepening search Properties of iterative deepening search
Complete?? Yes Complete?? Yes
Time?? Time?? (d + 1)b0 + db1 + (d − 1)b2 + . . . + bd = O(bd)
Space?? O(bd)
Optimal?? Yes, if step cost = 1
Can be modified to explore uniform-cost tree
Numerical comparison for b = 10 and d = 5, solution at far right leaf:
N (IDS) = 50 + 400 + 3, 000 + 20, 000 + 100, 000 = 123, 450
N (BFS) = 10 + 100 + 1, 000 + 10, 000 + 100, 000 + 999, 990 = 1, 111, 100
IDS does better because other nodes at depth d are not expanded
BFS can be modified to apply goal test when a node is generated
Chapter 3 67 Chapter 3 70
Chapter 3 68 Chapter 3 71
Chapter 3 69 Chapter 3 72
Graph search
Chapter 3 73
Summary
Problem formulation usually requires abstracting away real-world details to
define a state space that can feasibly be explored
Variety of uninformed search strategies
Iterative deepening search uses only linear space
and not much more time than other uninformed algorithms
Graph search can be exponentially more efficient than tree search
Chapter 3 74