Beruflich Dokumente
Kultur Dokumente
Example: Romania
Problem:
Formulate problem:
Example: Romania
Oradea
71
75
Neamt
Zerind
87
151
Iasi
Arad
140
Sibiu
92
99
Fagaras
118
Timisoara
111
Vaslui
80
Rimnicu Vilcea
Lugoj
Pitesti
97
142
211
70
98
Mehadia
75
Dobreta
146
85
101
86
138
Bucharest
120
Craiova
Hirsova
Urziceni
90
Giurgiu
Eforie
Problem types
Deterministic, fully observable = single-state problem
Agent knows exactly which state it will be in; solution
is a sequence
Non-observable = conformant problem
Agent may have no idea where it is; solution (if any)
is a sequence
Nondeterministic and/or partially observable =
contingency problem
percepts provide new information about current state
solution is a tree or policy
often interleave search, execution
Unknown state space = exploration problem (online)
Problem Solving
We will start by considering the simpler cases in which the
following holds.
The agents world (environment) is representable by a
discrete set of states.
The agents actions are representable by a discrete set of
operators.
The world is static and deterministic.
Single-state,
start in #5.
Solution??
Contingency, start in #5
Contingency, start in #5
R
L
S
L
S
S
R
L
R
L
S
states??
actions??
goal test??
path cost??
R
L
S
L
S
S
R
L
R
L
S
Search Graph
How do we reach a goal state?
initial state
B
7
goal states
search
execute
2 8 3
1 6 4
7
5
It can be generalized to 15-puzzle, 24-puzzle, or
(n2 1)-puzzle for n 6.
1 2 3
8
4
7 6 5
(S)
(G)
2 8 3
1 6 4
7
5
R
D
L
2 8 3
1 6 4
7 5
D
2 8 3
6 4
1 7 5
2 8 3
1
4
7 6 5
L
2 8 3
1 4
7 6 5
2
3
1 8 4
7 6 5
2 8 3
1 6 4
7 5
D
R
2 8 3
1 4
7 6 5
2 8 3
1 6
7 5 4
How can an artificial agent represent the states and the state
space for this problem?
Problem Formulation
1. Choose an appropriate data structure to represent the
world states.
2. Define each operator as a precondition/effects pair
where the
precondition holds exactly in the states the operator
applies to,
effects describe how a state changes into a
successor state by the application of the operator.
3. Specify an initial state.
4. Provide a description of the goal (used to check if a
reached state is a goal state).
2 8 3
1 6 4
5
7
2 8 3
becomes A = 1 6 4
7 0 5
Operators:
2 8 3
1 6 4
7 0 5
Op (3,2,L)
2 8 3
1 6 4
0 7 5
Op (3,2,R)
2 8 3
1 6 4
7 5 0
A[3,
( 2] = 0
A[3, 2] A[3, 3]
A[3, 3] 0
A Better Formulation
States:
A is a 3 3 array of numbers in [0 . . . 8]
(i, j) is the position of the empty space (0) in the array.
2 8 3
1 6 4
5
7
2 8 3
becomes ( 1 6 4 , (3, 2))
7 0 5
A Better Formulation
4 operators of the form Op d where
d {L, R, U, D}.
Operators:
Op L
2 8 3
1 6 4
0 7 5
Effects:
c0 > 1
A[r0 , c0 1]
A[r0 , c0 ]
A[r0 , c0 1] 0
(r , c )
(r0 , c0 1)
0 0
any steps
1 2 3
4 5 6
8 7
a2
a3
a4
a5
a6
a7
a8
a9
2 3
1 2 3
5 6
4 5 6
8 7
3gl
4gl
0 J4 4
J4 = 0
E4:
J4 < 4
effect:
J4 = 4
effect:
J4 = 0
E4-3:
J4 > 0
J3 < 3,
effect:
J4 = J4 (3 J3 )
J4 3 J3
P3-4:
J4 < 4,
effect:
J3 + J4 < 4,
J3 > 0
...
J4 = 4,
J3 = J3 (4 J4 )
J3 4 J4
E3-4:
J3 = 3,
effect:
J4 = J3 + J4 ,
J3 = 0
Search Graph
F4
J_4 = 2
F3
J_3 = 0
J_4 = 4
J_3 = 0
J_4 = 0
J_3 = 3
J_4 = 0
P4-3
J_3 = 3
J_4 = 4
J_3 = 3
J_4 = 1
...
...
F3
F4
J_3 = 0
J_4 = 4
...
P3-4
E4
E3-4
J_3 = 2
J_4 = 4
E3-4
F3
J_3 = 0
J_4 = 3
J_3 = 3
J_4 = 3
...
J_3 = 2
J_4 = 0
J_3 = 0
J_4 = 2
Problem Solution
Problems whose solution is a description of how to
reach a goal state from the initial state:
n-puzzle
route-finding problem
assembly sequencing
More on Graphs
A graph is a set of notes and edges (arcs) between them.
C
A
Directed Graphs
C
A
For 1 i < j k + 1,
Ni is a ancestor of Nj ; Nj is a descendant of Ni .
depth 1
depth 0
G
D
...
depth 2
depth 3
depth 4
a solution, or failure
initialize the search tree using the initial state of problem
loop do
end
Timisoara
Sibiu
Arad
Fagaras
Oradea
Rimnicu Vilcea
Arad
Zerind
Lugoj
Arad
Oradea
Timisoara
Sibiu
Arad
Fagaras
Oradea
Rimnicu Vilcea
Arad
Zerind
Lugoj
Arad
Oradea
Timisoara
Sibiu
Arad
Fagaras
Oradea
Rimnicu Vilcea
Arad
Zerind
Lugoj
Arad
Oradea
State
Node
depth = 6
g=6
6
7
1
3
88
22
state
Search Strategies
A strategy is defined by picking the order of node
expansion. Strategies are evaluated along the following
dimensions:
completenessdoes it always find a solution if one
exists?
time complexitynumber of nodes
generated/expanded
space complexitymaximum number of nodes in
memory
optimalitydoes it always find a least-cost solution?
Time and space complexity are measured in terms of
bmaximum branching factor of the search tree
ddepth of the least-cost solution
mmaximum depth of the state space (may be )
Breadth-First Search
Expand shallowest unexpanded node
Implementation: fringe is a FIFO queue, i.e., new
successors go at end
A
B
D
C
E
Breadth-First Search
Expand shallowest unexpanded node
Implementation: fringe is a FIFO queue, i.e., new
successors go at end
A
B
D
C
E
Breadth-First Search
Expand shallowest unexpanded node
Implementation: fringe is a FIFO queue, i.e., new
successors go at end
A
B
D
C
E
Breadth-First Search
Expand shallowest unexpanded node
Implementation: fringe is a FIFO queue, i.e., new
successors go at end
A
B
D
C
E
Uniform-Cost Search
Expand least-cost unexpanded node
Implementation: fringe = queue ordered by path cost
Equivalent to breadth-first if step costs all equal
Complete?? Yes, if step cost
Time?? # of nodes with g cost of optimal solution,
C
O(b / ) where C is the cost of the optimal solution
Space?? # of nodes with g cost of optimal solution,
C
O(b / )
Optimal?? Yesnodes expanded in increasing order of g(n)
Depth-First Search
Expand deepest unexpanded node
Implementation: fringe = LIFO queue, i.e., put successors at
front
A
B
D
H
E
I
F
K
G
M
Depth-First Search
Expand deepest unexpanded node
Implementation: fringe = LIFO queue, i.e., put successors at
front
A
B
D
H
E
I
F
K
G
M
Depth-First Search
Expand deepest unexpanded node
Implementation: fringe = LIFO queue, i.e., put successors at
front
A
D
H
E
I
F
K
G
M
Depth-First Search
Expand deepest unexpanded node
Implementation: fringe = LIFO queue, i.e., put successors at
front
A
B
D
H
E
I
F
K
G
M
Depth-First Search
Expand deepest unexpanded node
Implementation: fringe = LIFO queue, i.e., put successors at
front
A
B
D
H
E
I
F
K
G
M
Depth-First Search
Expand deepest unexpanded node
Implementation: fringe = LIFO queue, i.e., put successors at
front
A
B
D
H
E
I
F
K
G
M
Depth-First Search
Expand deepest unexpanded node
Implementation: fringe = LIFO queue, i.e., put successors at
front
A
B
D
H
E
I
F
K
G
M
Depth-First Search
Expand deepest unexpanded node
Implementation: fringe = LIFO queue, i.e., put successors at
front
A
B
D
H
E
I
F
K
G
M
Depth-First Search
Expand deepest unexpanded node
Implementation: fringe = LIFO queue, i.e., put successors at
front
A
D
H
E
I
F
K
G
M
Depth-First Search
Expand deepest unexpanded node
Implementation: fringe = LIFO queue, i.e., put successors at
front
A
B
D
H
E
I
F
K
G
M
Depth-First Search
Expand deepest unexpanded node
Implementation: fringe = LIFO queue, i.e., put successors at
front
A
B
D
H
E
I
F
K
G
M
Depth-First Search
Expand deepest unexpanded node
Implementation: fringe = LIFO queue, i.e., put successors at
front
A
D
H
E
I
F
K
G
M
Depth-Limited Search
= depth-first search with depth limit l, i.e., nodes at depth l
have no successors
A
B
A
C
A
C
A
C
B
D
C
E
B
G
C
E
A
C
E
C
E
C
E
B
G
C
E
B
G
B
D
C
E
B
G
B
G
C
E
D
H
E
J
F
L
G
M
E
I
C
E
G
M
E
I
E
I
F
L
G
M
F
K
E
I
F
K
F
K
E
I
F
K
C
E
F
K
G
M
D
O
E
I
F
K
G
M
N (BFS) =
10 + 100 + 1, 000 + 10, 000 + 100, 000 + 999, 990 = 1, 111, 100
Summary of Algorithms
Criterion
Breadth-
Uniform-
Depth-
Depth-
Iterative
First
Cost
First
Limited
Deepening
Complete?
Yes
Yes
No
Yes, if l d
Yes
Time
bd+1
bm
bl
bd
C /
bm
bl
bd
Yes
No
No
Yes
d+1
Space
Optimal?
Yes
bC
b
Repeated states
Failure to detect repeated states can turn a linear problem
into an exponential one!
A
B
C
B
C
B
C
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
Example: Romania
For a given strategy, what is the order of nodes to be generated (or stored), and expanded?
With or without checking duplicated nodes?
Oradea
71
Breadth-first
Depth-first
Uniform-cost
Depth-limited
75
Neamt
Zerind
Iasi
Arad
140
Sibiu
92
99
Fagaras
118
Vaslui
80
Rimnicu Vilcea
Timisoara
111
Iterative-deepening
87
151
Lugoj
Pitesti
97
142
211
70
98
Mehadia
75
Dobreta
146
85
101
86
138
Bucharest
120
Craiova
Hirsova
Urziceni
90
Giurgiu
Eforie