Académique Documents
Professionnel Documents
Culture Documents
Chapter 3
Chapter 3
Reminders
Assignment 0 due 5pm today Assignment 1 posted, due 2/9 Section 105 will move to 9-10am starting next week
Chapter 3
Outline
Problem-solving agents Problem types Problem formulation Example problems Basic search algorithms
Chapter 3
Problem-solving agents
Restricted form of general agent:
function Simple-Problem-Solving-Agent( percept) returns an action static: seq, an action sequence, initially empty state, some description of the current world state goal, a goal, initially null 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 Recommendation(seq, state) seq Remainder(seq, state) return action
Note: this is oine problem solving; solution executed eyes closed. Online problem solving involves acting without complete knowledge.
Chapter 3 4
Example: Romania
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, e.g., Arad, Sibiu, Fagaras, Bucharest
Chapter 3
Example: Romania
Oradea
71
Zerind
Neamt
75
Arad
151
87
Iasi
140
Sibiu
92 99
Fagaras Vaslui
118
Timisoara
80 Rimnicu Vilcea
Pitesti
111 70
Lugoj Mehadia
211
142 98
97 146
101 138
85
Hirsova
Urziceni
75
Dobreta
86
Bucharest
120
Craiova
90
Giurgiu Eforie
Chapter 3
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 contingent plan or a policy often interleave search, execution Unknown state space = exploration problem (online)
Chapter 3
Chapter 3
Chapter 3
Chapter 3
10
Chapter 3
11
successor function S(x) = set of actionstate pairs e.g., S(Arad) = { Arad Zerind, Zerind , . . .} goal test, can be explicit, e.g., x = at Bucharest implicit, e.g., N oDirt(x) path cost (additive) e.g., sum of distances, number of actions executed, etc. c(x, a, y) is the step cost, assumed to be 0 A solution is a sequence of actions leading from the initial state to a goal state
Chapter 3
12
Chapter 3
13
Chapter 3
14
states??: integer dirt and robot locations (ignore dirt amounts etc.) actions?? goal test?? path cost??
Chapter 3
15
states??: integer dirt and robot locations (ignore dirt amounts etc.) actions??: Lef t, Right, Suck, N oOp goal test?? path cost??
Chapter 3
16
states??: integer dirt and robot locations (ignore dirt amounts etc.) actions??: Lef t, Right, Suck, N oOp goal test??: no dirt path cost??
Chapter 3
17
states??: integer dirt and robot locations (ignore dirt amounts etc.) actions??: Lef t, Right, Suck, N oOp goal test??: no dirt path cost??: 1 per action (0 for N oOp)
Chapter 3
18
4 6 1
5 1 4 7
2 5 8
Goal State
3 6
Chapter 3
19
4 6 1
5 1 4 7
2 5 8
Goal State
3 6
states??: integer locations of tiles (ignore intermediate positions) actions?? goal test?? path cost??
Chapter 3
20
4 6 1
5 1 4 7
2 5 8
Goal State
3 6
states??: integer locations of tiles (ignore intermediate positions) actions??: move blank left, right, up, down (ignore unjamming etc.) goal test?? path cost??
Chapter 3
21
4 6 1
5 1 4 7
2 5 8
Goal State
3 6
states??: integer locations of tiles (ignore intermediate positions) actions??: move blank left, right, up, down (ignore unjamming etc.) goal test??: = goal state (given) path cost??
Chapter 3
22
4 6 1
5 1 4 7
2 5 8
Goal State
3 6
states??: integer locations of tiles (ignore intermediate positions) actions??: move blank left, right, up, down (ignore unjamming etc.) goal test??: = goal state (given) path cost??: 1 per move [Note: optimal solution of n-Puzzle family is NP-hard]
Chapter 3
23
states??: real-valued coordinates of robot joint angles parts of the object to be assembled actions??: continuous motions of robot joints goal test??: complete assembly with no robot included! path cost??: time to execute
Chapter 3
24
Chapter 3
25
Sibiu
Timisoara
Zerind
Arad
Fagaras
Oradea
Rimnicu Vilcea
Arad
Lugoj
Arad
Oradea
Chapter 3
26
Sibiu
Timisoara
Zerind
Arad
Fagaras
Oradea
Rimnicu Vilcea
Arad
Lugoj
Arad
Oradea
Chapter 3
27
Sibiu
Timisoara
Zerind
Arad
Fagaras
Oradea
Rimnicu Vilcea
Arad
Lugoj
Arad
Oradea
Chapter 3
28
State
5 6 7
4 1 3 8 8 2 2
Node
depth = 6 g=6
state
The Expand function creates new nodes, lling in the various elds and using the SuccessorFn of the problem to create the corresponding states.
Chapter 3
29
Chapter 3
30
Search strategies
A strategy is dened by picking the order of node expansion Strategies are evaluated along the following dimensions: completenessdoes it always nd a solution if one exists? time complexitynumber of nodes generated/expanded space complexitymaximum number of nodes in memory optimalitydoes it always nd 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 )
Chapter 3
31
Chapter 3
32
Breadth-rst search
Expand shallowest unexpanded node Implementation: fringe is a FIFO queue, i.e., new successors go at end
A B D E F C G
Chapter 3
33
Breadth-rst search
Expand shallowest unexpanded node Implementation: fringe is a FIFO queue, i.e., new successors go at end
A B D E F C G
Chapter 3
34
Breadth-rst search
Expand shallowest unexpanded node Implementation: fringe is a FIFO queue, i.e., new successors go at end
A B D E F C G
Chapter 3
35
Breadth-rst search
Expand shallowest unexpanded node Implementation: fringe is a FIFO queue, i.e., new successors go at end
A B D E F C G
Chapter 3
36
Chapter 3
37
Chapter 3
38
Chapter 3
39
Chapter 3
40
Chapter 3
41
Uniform-cost search
Expand least-cost unexpanded node Implementation: fringe = queue ordered by path cost, lowest rst Equivalent to breadth-rst if step costs all equal Complete?? Yes, if step cost Time?? # of nodes with g cost of optimal solution, O(b where C is the cost of the optimal solution Space?? # of nodes with g cost of optimal solution, O(b Optimal?? Yesnodes expanded in increasing order of g(n)
C /
) )
C /
Chapter 3
42
Depth-rst search
Expand deepest unexpanded node Implementation: fringe = LIFO queue, i.e., put successors at front
A B D H I J E K L F M N C G O
Chapter 3
43
Depth-rst search
Expand deepest unexpanded node Implementation: fringe = LIFO queue, i.e., put successors at front
A B D H I J E K L F M N C G O
Chapter 3
44
Depth-rst search
Expand deepest unexpanded node Implementation: fringe = LIFO queue, i.e., put successors at front
A B D H I J E K L F M N C G O
Chapter 3
45
Depth-rst search
Expand deepest unexpanded node Implementation: fringe = LIFO queue, i.e., put successors at front
A B D H I J E K L F M N C G O
Chapter 3
46
Depth-rst search
Expand deepest unexpanded node Implementation: fringe = LIFO queue, i.e., put successors at front
A B D H I J E K L F M N C G O
Chapter 3
47
Depth-rst search
Expand deepest unexpanded node Implementation: fringe = LIFO queue, i.e., put successors at front
A B D H I J E K L F M N C G O
Chapter 3
48
Depth-rst search
Expand deepest unexpanded node Implementation: fringe = LIFO queue, i.e., put successors at front
A B D H I J E K L F M N C G O
Chapter 3
49
Depth-rst search
Expand deepest unexpanded node Implementation: fringe = LIFO queue, i.e., put successors at front
A B D H I J E K L F M N C G O
Chapter 3
50
Depth-rst search
Expand deepest unexpanded node Implementation: fringe = LIFO queue, i.e., put successors at front
A B D H I J E K L F M N C G O
Chapter 3
51
Depth-rst search
Expand deepest unexpanded node Implementation: fringe = LIFO queue, i.e., put successors at front
A B D H I J E K L F M N C G O
Chapter 3
52
Depth-rst search
Expand deepest unexpanded node Implementation: fringe = LIFO queue, i.e., put successors at front
A B D H I J E K L F M N C G O
Chapter 3
53
Depth-rst search
Expand deepest unexpanded node Implementation: fringe = LIFO queue, i.e., put successors at front
A B D H I J E K L F M N C G O
Chapter 3
54
Chapter 3
55
Chapter 3
56
Chapter 3
57
Chapter 3
58
Chapter 3
59
Depth-limited search
= depth-rst search with depth limit l, i.e., nodes at depth l have no successors Recursive implementation:
function Depth-Limited-Search( problem, limit) returns soln/fail/cuto Recursive-DLS(Make-Node(Initial-State[problem]), problem, limit) function Recursive-DLS(node, problem, limit) returns soln/fail/cuto cuto-occurred? false if Goal-Test(problem, State[node]) then return node else if Depth[node] = limit then return cuto else for each successor in Expand(node, problem) do result Recursive-DLS(successor, problem, limit) if result = cuto then cuto-occurred? true else if result = failure then return result if cuto-occurred? then return cuto else return failure
Chapter 3
60
Chapter 3
61
Chapter 3
62
Chapter 3
63
A B D E F C G D B E
A C F G D B E
A C F G D B E
A C F G
Chapter 3
64
A B D H I J E K L F M N C G O H D I J B E K
A C F L M N G O H D I J B E K
A C F L M N G O H D I J B E K
A C F L M N G O
A B D H I J E K L F M N C G O H D I J B E K
A C F L M N G O H D I J B E K
A C F L M N G O H D I J B E K
A C F L M N G O
Chapter 3
65
Chapter 3
66
Chapter 3
67
Chapter 3
68
Chapter 3
69
IDS does better because other nodes at depth d are not expanded BFS can be modied to apply goal test when a node is generated
Chapter 3 70
Summary of algorithms
Criterion Complete? Time Space Optimal? BreadthFirst Yes bd+1 bd+1 Yes UniformCost Yes bC/ C / b Yes DepthFirst No bm bm No DepthLimited Yes, if l d bl bl No Iterative Deepening Yes bd bd Yes
Chapter 3
71
Repeated states
Failure to detect repeated states can turn a linear problem into an exponential one!
A B C D C A
B C C
B C
Chapter 3
72
Graph search
function Graph-Search( problem, fringe) returns a solution, or failure closed an empty set fringe Insert(Make-Node(Initial-State[problem]), fringe) loop do if fringe is empty then return failure node Remove-Front(fringe) if Goal-Test(problem, State[node]) then return node if State[node] is not in closed then add State[node] to closed fringe InsertAll(Expand(node, problem), fringe) end
Chapter 3
73
Summary
Problem formulation usually requires abstracting away real-world details to dene 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 Graph search can be exponentially more ecient than tree search
Chapter 3
74