Académique Documents
Professionnel Documents
Culture Documents
Announcements:
Problem Solving Lise’s office hours: Thu 1:30-3:00 and by
appt
HW1 due next Tue
Russell and Norvig: Chapter 3 Outline:
Problem Solving Agents
CSMSC 421 – Fall 2003 Problem Formulation
Basic Search
? ?
environment environment
agent agent
actuators actuators
• Formulate Goal
• Formulate Problem
•States
•Actions
• Find Solution
1
Example: Route finding 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
142 S S
111 Pitesti 211 S S
Lugoj 97
R
70 98 L R
85 Hirsova
146 101
Mehadia Urziceni
L
75 138 86
Bucharest
S S
Goal
Dobreta 120
90
Craiova Eforie
Giurgiu
2
Search Problem Search Problem
3
Search Problem Example: 8-puzzle
State space
Initial state 8 2 1 2 3
Successor function 3 4 7 4 5 6
Goal test 5 1 6 7 8
Path cost:
[path Æ positive number] Initial state Goal state
usually, path cost = sum of step costs
e.g., number of moves of the empty tile
4
Your Turn: Search Problem Search of State Space
State space
Initial state
Successor function
Goal test
Path cost
5
Search of State Space Search of State Space
Æ search tree
6
Example: 8-queens Example: 8-queens
Place 8 queens in a chessboard so that no two queens Formulation #1:
are in the same row, column, or diagonal. •States: any arrangement of
0 to 8 queens on the board
• Initial state: 0 queens on the
board
• Successor function: add a
queen in any square
• Goal test: 8 queens on the
board, none attacked
7
Example: Robot navigation Example: Robot navigation
Initial state
Complex function:
Goal state
it must find if a collision-free
merging motion exists
Successor function:
• Merge two subassemblies
8
Example: Assembly Planning Assumptions in Basic Search
Æ search tree
9
Basic Search Concepts Search Nodes ≠ States
Search tree 8 2
3 4 7
Search node 5 1 6
Node expansion
8 2 7
The search
search tree
tree may
may be
be infinite
infinite even
even
Search strategy: At each stage it 3 4
The
when the
the state
state space
space isis finite
finite
when
determines which node to expand 5 1 6
8 2 8 2 8 4 2 8 2
3 4 7 3 4 7 3 7 3 4 7
5 1 6 5 1 6 5 1 6 5 1 6
Set of search nodes that have not been 1. If GOAL?(initial-state) then return initial-state
2. INSERT(initial-node,FRINGE)
expanded yet 3. Repeat:
Implemented as a queue FRINGE If FRINGE is empty then return failure
INSERT(node,FRINGE) n Å REMOVE(FRINGE)
s Å STATE(n)
REMOVE(FRINGE) For every state s’ in SUCCESSORS(s)
The ordering of the nodes in FRINGE Create a node n’
defines the search strategy If GOAL?(s’) then return path or goal state
INSERT(n’,FRINGE)
10
Search Strategies Important Remark
A strategy is defined by picking the order of node
expansion Some problems formulated as search
Strategies are evaluated along the following problems are NP-hard problems. We
dimensions:
Completeness – does it always find a solution if one exists? cannot expect to solve such a problem
Time complexity – number of nodes generated/expanded in less than exponential time in the
Space complexity – maximum number of nodes in memory
worst-case
11
Blind Strategies Breadth-First Strategy
New nodes are inserted at the end of FRINGE New nodes are inserted at the end of FRINGE
1 1
4 5 6 7 4 5 6 7
12
Breadth-First Strategy Evaluation
b: branching factor
New nodes are inserted at the end of FRINGE
d: depth of shallowest goal node
1
Complete
2 3 FRINGE = (4, 5, 6, 7) Optimal if step cost is 1
Number of nodes generated:
4 5 6 7 1 + b + b2 + … + bd + b(bd-1) = O(bd+1)
Time and space complexity is O(bd+1)
13
Bidirectional Strategy Depth-First Strategy
2 fringe queues: FRINGE1 and FRINGE2
New nodes are inserted at the front of FRINGE
1
2 3
FRINGE = (1)
4 5
New nodes are inserted at the front of FRINGE New nodes are inserted at the front of FRINGE
1 1
2 3 2 3
FRINGE = (2, 3) FRINGE = (4, 5, 3)
4 5 4 5
14
Depth-First Strategy Depth-First Strategy
New nodes are inserted at the front of FRINGE New nodes are inserted at the front of FRINGE
1 1
2 3 2 3
4 5 4 5
New nodes are inserted at the front of FRINGE New nodes are inserted at the front of FRINGE
1 1
2 3 2 3
4 5 4 5
15
Depth-First Strategy Depth-First Strategy
New nodes are inserted at the front of FRINGE New nodes are inserted at the front of FRINGE
1 1
2 3 2 3
4 5 4 5
New nodes are inserted at the front of FRINGE New nodes are inserted at the front of FRINGE
1 1
2 3 2 3
4 5 4 5
16
Evaluation Depth-Limited Strategy
b: branching factor
d: depth of shallowest goal node
Depth-first with depth cutoff k
(maximal depth below which nodes are
m: maximal depth of a leaf node
not expanded)
Complete only for finite search tree
Not optimal
Three possible outcomes:
Number of nodes generated:
1 + b + b2 + … + bm = O(bm) Solution
Time complexity is O(bm) Failure (no solution)
Space complexity is O(bm) Cutoff (no solution within cutoff)
17
Repeated States Avoiding Repeated States
No Few Many
Requires comparing state descriptions
1 2 3 Breadth-first strategy:
search tree is finite search tree is infinite
4 5 Keep track of all generated states
7 8 6
If the state of a new node already exists,
then discard the node
18
Uniform-Cost Strategy Modified Search Algorithm
• Each step has some cost ≥ ε > 0.
• The cost of the path to each fringe node N is 1. INSERT(initial-node,FRINGE)
g(N) = Σ costs of all steps. 2. Repeat:
• The goal is to generate a solution path of minimal cost. If FRINGE is empty then return failure
• The queue FRINGE is sorted in increasing cost. n Å REMOVE(FRINGE)
s Å STATE(n)
A S
0 If GOAL?(s) then return path or goal state
1 10
S
For every state s’ in SUCCESSORS(s)
5 B 5 G
A B C
1 5 15 Create a node n’
5 INSERT(n’,FRINGE)
15 C
G G
11 10
Exercises Summary
19