Problem Solving
Problem Solving
Problem Solving
Problem-Solving
Agent
sensors
environment
agent
actuators
Problem-Solving Agent
sensors
?
environment
agent
actuators
Formulate Goal
Formulate Problem
States
Actions
Find Solution
Holiday Planning
On holiday in Romania; Currently in Arad.
Flight leaves tomorrow from Bucharest.
Formulate Goal:
Be in Bucharest
Formulate Problem:
States: various cities
Actions: drive between cities
Find solution:
Sequence of cities: Arad, Sibiu, Fagaras,
Bucharest
Problem Solving
States
Actions
Start
Solution
Goal
Vacuum World
Problem-solving agent
Four general steps in problem solving:
Goal formulation
What are the successful world states
Problem formulation
What actions and states to consider given the goal
Search
Determine the possible sequence of actions that
Execute
Give the solution perform the actions.
Problem-solving agent
function SIMPLE-PROBLEM-SOLVING-AGENT(percept) return an action
static: seq, an action sequence
state, some description of the current world state
goal, a goal
problem, a problem formulation
state UPDATE-STATE(state, percept)
if seq is empty then
goal FORMULATE-GOAL(state)
problem FORMULATE-PROBLEM(state,goal)
seq SEARCH(problem)
action FIRST(seq)
seq REST(seq)
return action
environment is static
environment is discretizable
environment is observable
actions are deterministic
Problem formulation
A problem is defined by:
States??
Initial state??
Actions??
Goal test??
Path cost??
Example: 8-puzzle
States??
Initial state??
Actions??
Goal test??
Path cost??
Example: 8-puzzle
Example: 8-puzzle
8
Initial state
Goal state
Example: 8-puzzle
Example: 8-puzzle
Size of the state space = 9!/2 = 181,440
15-puzzle .65 x 1012
0.18 sec
6 days
24-puzzle .5 x 1025
12 billion years
10 million states/sec
Example: 8-queens
A solution
Not a solution
Example: 8-queens
problem
Example: 8-queens
Formulation #1:
States: any arrangement of
0 to 8 queens on the board
Initial state: 0 queens on the
board
Actions: add a
queen in any square
Goal test: 8 queens on the
board, none attacked
Path cost: none
Example: 8-queens
Formulation #2:
States: any arrangement of
k = 0 to 8 queens in the k
leftmost columns with none
attacked
Initial state: 0 queens on the
board
Successor function: add a
queen to any square in the
leftmost empty column such
that it is not attacked
by any other queen
2,067 states Goal test: 8 queens on the
board
Real-world Problems
Route finding
Touring problems
VLSI layout
Robot Navigation
Automatic assembly sequencing
Drug design
Internet searching
States??
Initial state??
Actions??
Goal test??
Path cost??
search tree
Search Strategies
A strategy is defined by picking the order of node
expansion
Performance Measures:
Uninformed search
strategies
(a.k.a. blind search) = use only information
available in problem definition.
When strategies can determine whether one nongoal state is better than another informed search.
Breadth-first search
Uniform-cost search
Depth-first search
Depth-limited search
Iterative deepening search.
Bidirectional search
Breadth-First Strategy
Expand shallowest unexpanded node
Implementation: fringe is a FIFO queue
New nodes are inserted at the end of the queue
1
2
4
8
FRINGE = (1)
3
5
6
9
Breadth-First Strategy
Expand shallowest unexpanded node
Implementation: fringe is a FIFO queue
New nodes are inserted at the end of the queue
1
2
4
8
FRINGE = (2, 3)
3
5
6
9
Breadth-First Strategy
Expand shallowest unexpanded node
Implementation: fringe is a FIFO queue
New nodes are inserted at the end of the queue
1
2
4
8
FRINGE = (3, 4, 5)
3
5
6
9
Breadth-First Strategy
Expand shallowest unexpanded node
Implementation: fringe is a FIFO queue
New nodes are inserted at the end of the queue
1
2
4
8
FRINGE = (4, 5, 6, 7)
3
5
6
9
Breadth-First Strategy
Expand shallowest unexpanded node
Implementation: fringe is a FIFO queue
New nodes are inserted at the end of the queue
1
2
4
8
FRINGE = (5, 6, 7, 8)
3
5
6
9
Breadth-First Strategy
Expand shallowest unexpanded node
Implementation: fringe is a FIFO queue
New nodes are inserted at the end of the queue
1
2
4
8
FRINGE = (6, 7, 8)
3
5
6
9
Breadth-First Strategy
Expand shallowest unexpanded node
Implementation: fringe is a FIFO queue
New nodes are inserted at the end of the queue
1
2
4
8
FRINGE = (7, 8, 9)
3
5
6
9
Breadth-First Strategy
Expand shallowest unexpanded node
Implementation: fringe is a FIFO queue
New nodes are inserted at the end of the queue
1
2
4
8
FRINGE = (8, 9)
3
5
6
9
Breadth-first search:
evaluation
Completeness:
YES
If shallowest goal node is at some finite depth d
Condition: If b is finite
Breadth-first search:
evaluation
Completeness:
Time complexity:
Breadth-first search:
evaluation
Completeness:
Time complexity:
1 + b + b2 + + bd + b(bd-1) =
O(bd+1)
Space complexity:O(bd+1)
Breadth-first search:
evaluation
Completeness:
Time complexity:
1 + b + b2 + + bd + b(bd-1) = O(bd+1)
Space complexity:O(bd+1)
Optimality:
Breadth-first search:
evaluation
lessons:
1100
0.11seconds
1megabyte
111100
11seconds
106
megabytes
107
19minutes
10gigabytes
109
31hours
1terabyte
10
1011
129days
101terabytes
12
1013
35years
10petabytes
14
1015
3523years
1exabyte
Uniform-cost search
Extension of BF-search:
Uniform-cost search
Completeness:
Time complexity:
C */
O(b
Space complexity:
Optimality:
Depth-First Strategy
Expand deepest unexpanded node
Implementation: fringe is a LIFO queue
(=stack)
1
2
4
FRINGE = (1)
5
Depth-First Strategy
Expand deepest unexpanded node
Implementation: fringe is a LIFO queue
(=stack)
1
2
4
FRINGE = (2, 3)
5
Depth-First Strategy
Expand deepest unexpanded node
Implementation: fringe is a LIFO queue
(=stack)
1
2
4
FRINGE = (4, 5, 3)
5
Depth-First Strategy
Expand deepest unexpanded node
Implementation: fringe is a LIFO queue
(=stack)
1
2
4
3
5
Depth-First Strategy
Expand deepest unexpanded node
Implementation: fringe is a LIFO queue
(=stack)
1
2
4
3
5
Depth-First Strategy
Expand deepest unexpanded node
Implementation: fringe is a LIFO queue
(=stack)
1
2
4
3
5
Depth-First Strategy
Expand deepest unexpanded node
Implementation: fringe is a LIFO queue
(=stack)
1
2
4
3
5
Depth-First Strategy
Expand deepest unexpanded node
Implementation: fringe is a LIFO queue
(=stack)
1
2
4
3
5
Depth-First Strategy
Expand deepest unexpanded node
Implementation: fringe is a LIFO queue
(=stack)
1
2
4
3
5
Depth-First Strategy
Expand deepest unexpanded node
Implementation: fringe is a LIFO queue
(=stack)
1
2
4
3
5
Depth-First Strategy
Expand deepest unexpanded node
Implementation: fringe is a LIFO queue
(=stack)
1
2
4
3
5
Depth-First Strategy
Expand deepest unexpanded node
Implementation: fringe is a LIFO queue
(=stack)
1
2
4
3
5
Depth-First Strategy
Expand deepest unexpanded node
Implementation: fringe is a LIFO queue
(=stack)
1
2
4
3
5
Depth-first search:
evaluation
Completeness;
NO
unless search space is finite and no loops
are possible.
Depth-first search:
evaluation
Completeness;
O(b )
Time complexity;
Depth-first search:
evaluation
Completeness;
O(b m )
Time complexity;
O(bm 1)
Space complexity;
Depth-first search:
evaluation
Completeness;
Time complexity;O(b m )
Space complexity;O(bm 1)
Optimality; No
Depth-Limited Strategy
Depth-first with depth cutoff k (maximal depth below
which nodes are not expanded)
Three possible outcomes:
Solution
Failure (no solution)
Cutoff (no solution within cutoff)
Iterative Deepening
Strategy
Repeat for k = 0, 1, 2, :
Perform depth-first with depth cutoff k
Complete
Optimal if step cost =1
Time complexity is:
(d+1)(1) + db + (d-1)b2 + + (1) bd = O(bd)
Comparison of Strategies
Breadth-first is complete and
optimal, but has high space
complexity
Depth-first is space efficient, but
neither complete nor optimal
Iterative deepening combines
benefits of DFS and BFS and is
asymptotically optimal
Bidirectional Strategy
2 fringe queues: FRINGE1 and FRINGE2
Summary of algorithms
Criterion
Breadth
First
Uniform
cost
Depth
First
Depth
limited
Iterative
deepening
Bidirectio
nalsearch
Complete
?
YES*
YES*
NO
YES
YES*
Time
bd+1
bC*/e
bm
YES,
ifld
bl
bd
bd/2
Space
bd+1
bC*/e
bm
bl
bd
bd/2
Optimal?
YES*
YES*
NO
NO
YES
YES
Repeated states
Failure to detect repeated states can turn a solvable
problems into unsolvable ones.
Solution 1:
Keep track of all states associated with nodes in
current tree
If the state of a new node already exists, then discard
the node
Avoids loops
Solution 2:
Keep track of all states generated so far
If the state of a new node has already been
cost
Summary
Problem Formulation: state space, initial
state, successor function, goal test, path
cost
Search tree state space
Evaluation of strategies: completeness,
optimality, time and space complexity
Uninformed search strategies: breadthfirst, depth-first, and variants
Avoiding repeated states