3 Problem Solving
3 Problem Solving
Spring 2018
a These notes were originally developed by Stuart Russell and are used with permission. They are
copyrighted material and may not be used in other course settings outside of the University of Iowa in their
current or modified form without the express written consent of the copyright holders.
Formulate problem:
states: various cities
actions: drive between cities
Formulate goal:
be in Bucarest
Formulate solution:
sequence of cities (eg, Arad, Sibiu, Fagaras, Bucharest)
Zerind 87
75 151
Iasi
Arad 140
92
Sibiu Fagaras
99
118 Vaslui
80
Timisoara Rimnicu Vilcea
142
111 Pitesti 211
Lugoj 97
70 98
146 85 Hirsova
Mehadia 101 Urziceni
75 138 86
Bucharest
Dobreta 120
90
Craiova Eforie
Giurgiu
1 2
3 4
5 6
7 8
1 2
3 4
5 6
7 8
1 2
3 4
5 6
7 8
1 2
3 4
5 6
7 8
1 2
3 4
5 6
7 8
1 2
3 4
5 6
7 8
S S
R R
L R L R
L L
S S
S S
R
L R
S S
States?
Actions?
Goal test?
Path cost?
S S
R R
L R L R
L L
S S
S S
R
L R
S S
4
D E G
2 3
There may be several possible ways. Or none!
Factors to consider:
• cost of finding a path
• cost of traversing a path
2 8 3
1 6 4
7 5
2 8 3
1 6 4
7 5
L
R
D U
L R
2 8 3 2 8 3 2 8 3
1 6 4 1 4 1 6 4
7 5 7 6 5 L 7 5
R
D U D U D U
L R
2 8 3 2 8 3 2 3 2 8 3 2 8 3
6 4 1 4 1 8 4 1 4 1 6
1 7 5 7 6 5 7 6 5 7 6 5 7 5 4
Note:
• There are 9! = 362, 880 possible states: all permutations of
{0, 1, 2, 3, 4, 5, 6, 7, 8} where 0 is the empty space
• Not all states are directly reachable from a given state
How can an artificial agent represent the states and the state space for
this problem?
2 8 3 2 8 3
1 6 4 becomes A= 1 6 4
7 5 7 0 5
Example:
2 8 3 2 8 3
OP 3,2,L
1 6 4 =⇒ 1 6 4
7 0 5 0 7 5
2 8 3 2 8 3
OP 3,2,R
1 6 4 =⇒ 1 6 4
7 0 5 7 5 0
Preconditions: A[3, 2] = 0
(
A[3, 2] ← A[3, 3]
Effects:
A[3, 3] ← 0
2 8 3 2 8 3
OP 3,2,R
1 6 4 =⇒ 1 6 4
7 0 5 7 5 0
Preconditions: A[3, 2] = 0
(
A[3, 2] ← A[3, 3]
Effects:
A[3, 3] ← 0
2 8 3 2 8 3
1 6 4 becomes ( 1 6 4 , (3, 2) )
7 5 7 0 5
Example:
2 8 3 2 8 3
OP
( 1 6 4 , (3, 2) ) =⇒L ( 1 6 4 , (3, 1) )
7 0 5 0 7 5
2 8 3 2 8 3
OP
( 1 6 4 , (3, 2) ) =⇒L ( 1 6 4 , (3, 1) )
7 0 5 0 7 5
Preconditions: c0 > 1
A[r0 , c0 ]
← A[r0 , c0 − 1]
Effects: A[r0 , c0 − 1] ← 0
(r0 , c0 ) ← (r0 , c0 − 1)
3gl 4gl
0 ≤ J3 ≤ 3, 0 ≤ J4 ≤ 4
J_3 = 0 J_3 = 0
J_4 = 0 J_4 = 2 F4 J_4 = 0 F3
J_3 = 0 J_3 = 3
J_4 = 4 J_4 = 0
F3 P4-3
F4 E3-4
J_3 = 2 ...
E4 J_4 = 4
J_3 = 2
J_4 = 0
E3-4
J_3 = 0
J_4 = 2
• 8-queen problem
• scheduling problems
• layout problems
CS:4420 Spring 2018 – p.34/34