Title: Problem Solving as Search
1Problem Solving as Search
2Problem Types
- Deterministic, fully observable ? single-state
problem - Non-observable ? conformant problem
- Nondeterministic and/or partially observable ?
contingency problem - Unknown state space ? exploration problem
3A Starter Activity
- Cannibals and Missionaries
- Three missionaries and three cannibals
- Want to cross a river using one canoe.
- Canoe can hold up to two people.
- Can never be more cannibals than missionaries on
either side of the river. - Get all safely across the river without any
missionaries being eaten. - Find a solution
4Single-State Problem Formulation
- A problem is defined by four items
- initial state
- successor function (which actually defines all
reachable states) - goal test
- path cost (additive) e.g., sum of distances,
number of actions executed, etc. C(x,a,y) is the
step cost, assumed to be ? 0
5Problem Representation Cannibals and
Missionaries
- Initial State
- We can show number of cannibals, missionaries and
canoes on each side of the river. - Start state is therefore
- 3,3,1,0,0,0
6Problem Representation Cannibals and
Missionaries
- Initial State
- However, since the system is closed, we only need
to represent one side of the river, as we can
deduce the other side. - We will represent the finishing side of the
river, and omit the starting side. - So start state is
- 0,0,0
7Problem Representation Cannibals and
Missionaries
- Successor Function
- There are five actions we can represent
- Move one cannibal across the river.
- Move two cannibals across the river.
- Move one missionary across the river.
- Move two missionaries across the river.
- Move one missionary and one cannibal.
8Problem Representation Cannibals and
Missionaries
- Successor Function
- To be a little more mathematical/computer like,
we want to represent this in a true successor
function format - S(state) ? state
- Move one cannibal across the river.
- S(x,y,0) ? x1,y,1
- S(x,y,1) ? x-1,y,0
- Note, this is a slight simplification.
- Obviously, 0 ? x, y, x1, and x-1 ? 3
9Problem Representation Cannibals and
Missionaries
- Successor Function
- S(x,y,0) ? x1,y,1
- S(x,y,1) ? x-1,y,0
- S(x,y,0) ? x2,y,1
- S(x,y,1) ? x-2,y,0
- S(x,y,0) ? x,y1,1
- S(x,y,1) ? x,y-1,0
- S(x,y,0) ? x,y2,1
- S(x,y,1) ? x,y-2,0
- S(x,y,0) ? x1,y1,1
- S(x,y,1) ? x-1,y-1,0
10Problem Representation Cannibals and
Missionaries
- Successor Function
- S(x,y,0) ? x1,y,1 , x2,y,1 , x,y1,1 ,
x,y2,1 , x1,y1,1 - S(x,y,1) ? x-1,y,0 , x-2,y,0 , x,y-1,0 ,
x,y-2,0 , x-1,y-1,0 - Where valid states a,b,c are those such that
- 0 ? a ? 3
- 0 ? b ? 3
- 0 ? c ? 1
11Problem Representation Cannibals and
Missionaries
- Successor Function
- S(x,y,0) ? x1,y,1 , x2,y,1 , x,y1,1 ,
x,y2,1 , x1,y1,1 - S(x,y,1) ? x-1,y,0 , x-2,y,0 , x,y-1,0 ,
x,y-2,0 , x-1,y-1,0 - Where valid states a,b,c are those such that
- 0 ? a ? 3
- 0 ? b ? 3
- 0 ? c ? 1
- Actually one more set of constraints we will
get to later.
12Problem Representation Cannibals and
Missionaries
13Problem Representation Cannibals and
Missionaries
- Path Cost
- One unit per trip across the river.
14Problem Representation Cannibals and
Missionaries
- Initial State
- 0,0,0
- Successor Function
- S(x,y,0) ? x1,y,1 , x2,y,1 , x,y1,1 ,
x,y2,1 , x1,y1,1 - S(x,y,1) ? x-1,y,0 , x-2,y,0 , x,y-1,0 ,
x,y-2,0 , x-1,y-1,0 - Goal State
- 3,3,1
- Path Cost
- One unit per trip across the river.
15Tree Search Algorithms
- Basic ideaoffline, simulated exploration of
state spaceby generating successors of
already-explored states (a.k.a. expanding states)
16Tree Search Example
17Tree Search Example
18Tree Search Example
19Implementation States vs. Nodes
- A state is a representation of a physical
configuration - A node is a data structure constituting part of a
search tree - includes parent, children, depth, path cost g(x)
- States do not have parents, children, depth, or
path cost!
20Implementation 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.
21Search Strategies
- A 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/expanded space complexity maximum
number of nodes in memory optimality
does it always find a least-cost
solution
22Search Strategies
- Time and space complexity are measured in terms
of b maximum branching factor of the search
treed depth of the least-cost solutionm
maximum depth of the state space (may be infinite)
23Uninformed Search Strategies
- Uninformed strategies use only information
available in the problem definition - Breadth-first search
- Uniform-cost search
- Depth-first search
- Depth-limited search
- Iterative deepening search
24Uninformed Search Strategies
- Uninformed strategies use only information
available in the problem definition - Breadth-first search
- Uniform-cost search
- Depth-first search
- Depth-limited search
- Iterative deepening search
25Breadth-First Search
- Expanding shallowest unexpanded
nodeImplementation fringe is a FIFO queue,
i.e., new successors go at end
26Breadth-First Search
- Expanding shallowest unexpanded
nodeImplementation fringe is a FIFO queue,
i.e., new successors go at end
27Breadth-First Search
- Expanding shallowest unexpanded
nodeImplementation fringe is a FIFO queue,
i.e., new successors go at end
28Breadth-First Search
- Expanding shallowest unexpanded
nodeImplementation fringe is a FIFO queue,
i.e., new successors go at end
29Properties of Breadth-First Search
30Properties of Breadth-First Search
- Complete?? Yes (if b is finite)
- Time??
31Properties of Breadth-First Search
- Complete?? Yes (if b is finite)
- Time?? 1 b b2 b3 bd b(bd 1) O(
bd1 ), ie, exp. in d - Space??
32Properties of Breadth-First Search
- Complete?? Yes (if b is finite)
- Time?? 1 b b2 b3 bd b(bd 1) O(
bd1 ), ie, exp. in d - Space?? O( bd1 ) (keep every node in memory)
- Optimal??
33Properties of Breadth-First Search
- Complete?? Yes (if b is finite)
- Time?? 1 b b2 b3 bd b(bd 1) O(
bd1 ), ie, exp. in d - Space?? O( bd1 ) (keep every node in memory)
- Optimal?? Yes (if cost 1 per step) not optimal
in general - Space is the big problem can easily generate
nodes at 10MB/sec, so 24hours 860GB.
34Depth-First Search
- Expand deepest unexpanded nodeImplementation f
ringe LIFO queue, I.e., put successors
at front
35Depth-First Search
- Expand deepest unexpanded nodeImplementation f
ringe LIFO queue, I.e., put successors
at front
36Depth-First Search
- Expand deepest unexpanded nodeImplementation f
ringe LIFO queue, I.e., put successors
at front
37Depth-First Search
- Expand deepest unexpanded nodeImplementation f
ringe LIFO queue, I.e., put successors
at front
38Depth-First Search
- Expand deepest unexpanded nodeImplementation f
ringe LIFO queue, I.e., put successors
at front
39Depth-First Search
- Expand deepest unexpanded nodeImplementation f
ringe LIFO queue, I.e., put successors
at front
40Depth-First Search
- Expand deepest unexpanded nodeImplementation f
ringe LIFO queue, I.e., put successors
at front
41Depth-First Search
- Expand deepest unexpanded nodeImplementation f
ringe LIFO queue, I.e., put successors
at front
42Depth-First Search
- Expand deepest unexpanded nodeImplementation f
ringe LIFO queue, I.e., put successors
at front
43Depth-First Search
- Expand deepest unexpanded nodeImplementation f
ringe LIFO queue, I.e., put successors
at front
44Depth-First Search
- Expand deepest unexpanded nodeImplementation f
ringe LIFO queue, I.e., put successors
at front
45Depth-First Search
- Expand deepest unexpanded nodeImplementation f
ringe LIFO queue, I.e., put successors
at front
46Properties of Depth-first Search
47Properties of Depth-first Search
- Complete?? No fails in infinite-depth spaces,
spaces with loops Modify to avoid repeated
states along path ?complete in
finite spaces - Time??
48Properties of Depth-first Search
- 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
dbut if solutions are dense, may be much faster
than breadth-first - Space??
49Properties of Depth-first Search
- 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
dbut if solutions are dense, may be much faster
than breadth-first - Space?? O(bm), I.e., linear space!
- Optimal??
50Properties of Depth-first Search
- 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
dbut if solutions are dense, may be much faster
than breadth-first - Space?? O(bm), I.e., linear space!
- Optimal?? No.