Documente Academic
Documente Profesional
Documente Cultură
Last Time
Structure of Agents
Program
function that implements the mapping from percepts to actions
Outline
Outline
Outline
Problem-solving agents
Problem types
Problem formulation
Example problems
Basic search algorithms
Problem-solving agents
Example: Romania
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
10
e.g., at Arad
R
L
S
S
R
R
L
L
S
S
S
S
R
L
R
L
S
states??: integer dirt and robot locations (ignore dirt amounts etc.)
actions??: Lef t, Right, Suck, N oOp
transition model??: arcs in the digraph
goal test??: no dirt
path cost??: 1 per action (0 for N oOp)
13
5
8
3
Start State
5
1
8
Goal State
R
R
15
Problem types
16
17
Example Problems
Toy problems
vacuum cleaner agent
8-puzzle
8-queens
cryptarithmetic
missionaries and cannibals
Real-world problems
route finding
traveling salesperson
VLSI layout
robot navigation
assembly sequencing
18
Outline
19
Objectives
22
Search: Terminology
23
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
24
Arad
Timisoara
Sibiu
Arad
Fagaras
Oradea
Rimnicu Vilcea
Arad
Zerind
Lugoj
Arad
Oradea
25
26
State
Node
88
22
depth = 6
g=6
state
The Expand function creates new nodes, filling in the various fields using the
Transition Model of the problem to create the corresponding states.
27
Search strategies
Outline
30
31
Breadth-first search
B
D
C
E
C
E
Implementation:
fringe is a FIFO queue, i.e., new successors go at end
32
33
Uniform-cost search
34
Depth-first search
Expand deepest unexpanded node
A
B
D
H
E
I
F
K
G
M
Implementation:
fringe = LIFO queue, i.e., put successors at front
35
36
Depth-limited search
37
38
Limit = 3
D
H
E
I
F
K
G
M
E
I
F
L
G
M
E
I
F
K
E
I
F
K
E
I
F
K
G
N
F
K
E
I
G
M
F
K
E
I
F
K
A
C
E
I
A
B
D
C
E
G
M
G
M
D
O
E
I
F
K
G
M
39
N (BFS)
10 + 100 + 1, 000 + 10, 000 + 100, 000 + 999, 990 = 1, 111, 100
IDS does better because other nodes at depth d are not expanded
BFS can be modified to apply goal test when a node is generated
Iterative lenghtening not as successul as IDS
40
Bidirectional Search
41
42
Summary of algorithms
Criterion
Complete?
Time
Space
Optimal?
BreadthFirst
UniformCost
DepthFirst
DepthLimited
Iterative
Deepening
Yes
bd+1
bd+1
Yes
Yes
No
bm
bm
No
Yes, if l d
bl
bl
No
Yes
bd
bd
Yes
bd1+C /e
bd1+C /e
Yes
43
Summary
46
Outline
47
48
best-first search
greedy search
A search
49
Best-first search
50
71
75
Oradea
Neamt
Zerind
87
151
Iasi
Arad
140
92
Sibiu
99
Fagaras
118
Vaslui
80
Rimnicu Vilcea
Timisoara
111
Lugoj
Pitesti
97
142
211
70
98
Mehadia
75
Dobreta
146
85
101
138
120
Hirsova
Urziceni
86
Bucharest
90
Craiova
Giurgiu
Eforie
Straightline distance
to Bucharest
Arad
366
Bucharest
0
Craiova
160
Dobreta
242
Eforie
161
Fagaras
178
Giurgiu
77
Hirsova
151
Iasi
226
Lugoj
244
Mehadia
241
Neamt
234
Oradea
380
Pitesti
98
Rimnicu Vilcea 193
Sibiu
253
Timisoara
329
Urziceni
80
Vaslui
199
Zerind
374
51
Greedy search
52
Arad
366
53
54
A search
55
A search example
Arad
Sibiu
Fagaras
Arad
646=280+366
Timisoara
Zerind
447=118+329
449=75+374
Rimnicu Vilcea
Oradea
671=291+380
Sibiu
Bucharest
Craiova
591=338+253
450=450+0
526=366+160
Bucharest
418=418+0
Pitesti
Sibiu
553=300+253
Craiova
Rimnicu Vilcea
615=455+160 607=414+193
56
Suppose some suboptimal goal G2 has been generated and is in the queue.
Let n be an unexpanded node on a shortest path to an optimal goal G1 .
Start
f (G2 )
G2
= g(G2 )
since h(G2 ) = 0
>
since G2 is suboptimal
g(G1 )
f (n)
since h is admissible
O
N
A
S
380
400
R
P
U
B
420
C
G
58
59
Properties of A
Complete?? Yes, unless there are infinitely many nodes with f f (G)
Optimal?? Yescannot expand fi+1 until fi is finished
A expands all nodes with f (n) < C
A expands some nodes with f (n) = C
A expands no nodes with f (n) > C
Time?? Exponential in [relative error in h length of sol.]
Space?? Keeps all nodes in memory
60
A heuristic is consistent if
h(n) c(n, a, n0 ) + h(n0 )
If h is consistent, we have
f (n0 )
= g(n0 ) + h(n0 )
= g(n) + c(n, a, n0 ) + h(n0 )
g(n) + h(n)
= f (n)
n
c(n,a,n)
n
h(n)
h(n)
G
61
Admissible heuristics
E.g., for the 8-puzzle:
h1 (n) = number of misplaced tiles
h2 (n) = total Manhattan distance
(i.e., no. of squares from desired location of each tile)
5
8
3
Start State
5
1
8
Goal State
h1 (S) =??
h2 (S) =??
62
Admissible heuristics
E.g., for the 8-puzzle:
h1 (n) = number of misplaced tiles
h2 (n) = total Manhattan distance
(i.e., no. of squares from desired location of each tile)
5
8
5
1
Start State
Goal State
h1 (S) =?? 6
h2 (S) =?? 4+0+3+3+1+0+2+1 = 14
63
Dominance
d = 24
Relaxed problems
65
67
Iterative Deepening A
IDA
depth-first search, but only nodes with f -cost less than or equal to
smallest f -cost of nodes expanded at last iteration
was the "best" search algorithm for many practical problems
68
Properties of IDA
Complete?? Yes
Time complexity?? Still exponential
Space complexity?? linear
Optimal?? Yes. Also optimal in the absence of monotonicity
69
Simple Memory-Bounded A
70
Propeties of SMA
Complete?? yes, if there is enough memory for the shortest solution path
Time?? same as A if enough memory to store the tree
Space?? use available memory
Optimal?? yes, if enough memory to store the best solution path
In practice, often better than A and IDA trade-off between time and space
requirements
71
72
Arad
366
Timisoara
447
393
Zerind
449
415
Arad
646
Fagaras
415
Oradea
Rimnicu Vilcea
671
413
Craiova
526
Pitesti
Arad
646
417
Fagaras
415
Sibiu
591
Sibiu
553
417
Arad
366
Timisoara
447
393
Oradea
Zerind
449
Rimnicu Vilcea
671
413 417
Bucharest
450
Arad
366
Timisoara
393
Zerind
447
449
447
Arad
646
Fagaras
415 450
Rimnicu Vilcea
Oradea
671
417
447
Pitesti
Craiova
Bucharest
418
Sibiu
417
526
553
Rimnicu Vilcea
Craiova
615
607
73
Outline
75
76
77
Backtracking search
78
Backtracking search
79
Summary
Uninformed Search
Breadth-first search
Uniform-cost search
Depth-first search
Depth-limited search
Informed Search
best-first search
greedy search
A search
Iterative Deepening A
Memory bounded A
Recursive best first
80