Problem-solving agents function Simple-Problem-Solving-Agent ( percept ) returns an action static : seq , an action sequence, initially empty state , some description of the current world state Solving Problems by Searching goal , a goal, initially null problem , a problem formulation state ← Update-State ( state, percept ) if seq is empty then goal ← Formulate-Goal ( state ) Chapter 3 problem ← Formulate-Problem ( state, goal ) seq ← Search ( problem ) if seq is failure then return a null action action ← First ( seq ) seq ← Rest ( seq ) return action Note: this is offline problem solving; solution executed “eyes closed.” Online problem solving involves acting without complete knowledge. Chapter 3 1 Chapter 3 3 Outline Example: Romania ♦ Problem-solving agents On holiday in Romania; currently in Arad. Flight leaves tomorrow from Bucharest ♦ Problem types Formulate goal: ♦ Problem formulation be in Bucharest ♦ Example problems Formulate problem: states: various cities ♦ Basic search algorithms actions: drive between cities Find solution: sequence of cities, e.g., Arad, Sibiu, Fagaras, Bucharest Chapter 3 2 Chapter 3 4
Example: Romania Example: vacuum world Oradea Single-state, start in #5. Solution?? 71 Neamt 1 2 Zerind 87 151 75 Iasi 3 4 Arad 140 92 Sibiu Fagaras 99 5 6 118 Vaslui 80 Rimnicu Vilcea Timisoara 7 8 142 Pitesti 211 111 Lugoj 97 70 98 Hirsova 146 85 Mehadia Urziceni 101 86 75 138 Bucharest Dobreta 120 90 Craiova Eforie Giurgiu Chapter 3 5 Chapter 3 7 Problem types Example: vacuum world Deterministic, fully observable = ⇒ single-state problem Single-state, start in #5. Solution?? 1 2 Agent knows exactly which state it will be in; solution is a sequence [ Right, Suck ] Non-observable = ⇒ conformant problem Conformant, start in { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 } 3 4 Agent may have no idea where it is; solution (if any) is a sequence e.g., Right goes to { 2 , 4 , 6 , 8 } . Solution?? Nondeterministic and/or partially observable = ⇒ contingency problem 5 6 percepts provide new information about current state solution is a contingent plan or a policy 7 8 often interleave search, execution Unknown state space = ⇒ exploration problem (“online”) Chapter 3 6 Chapter 3 8
Example: vacuum world Single-state problem formulation A problem is defined by four items: Single-state, start in #5. Solution?? 1 2 [ Right, Suck ] ♦ initial state e.g., “at Arad” Conformant, start in { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 } 3 4 ♦ successor function S ( x ) = set of action–state pairs e.g., Right goes to { 2 , 4 , 6 , 8 } . Solution?? e.g., S ( Arad ) = {� Arad → Zerind, Zerind � , . . . } [ Right, Suck, Left, Suck ] 5 6 ♦ goal test, can be Contingency explicit, e.g., x = “at Bucharest” ♦ Murphy’s Law (non-deterministic): Suck 7 8 implicit, e.g., NoDirt ( x ) can dirty a clean carpet; start in #5 ♦ Local sensing (partially-observable): dirt, ♦ path cost (additive) location only, start in { #5,#7 } . e.g., sum of distances, number of actions executed, etc. Solution?? 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 9 Chapter 3 11 Example: vacuum world Selecting a state space Real world is absurdly complex Single-state, start in #5. Solution?? 1 2 ⇒ state space must be abstracted for problem solving [ Right, Suck ] Conformant, start in { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 } ♦ (Abstract) state = set of real states 3 4 e.g., Right goes to { 2 , 4 , 6 , 8 } . Solution?? ♦ (Abstract) action = complex combination of real actions [ Right, Suck, Left, Suck ] e.g., “Arad → Zerind” represents a complex set 5 6 Contingency of possible routes, detours, rest stops, etc. ♦ Murphy’s Law (non-deterministic): Suck 7 8 can dirty a clean carpet; start in #5 ♦ For guaranteed realizability, any real state “in Arad” ♦ Local sensing (partially-observable): dirt, must get to some real state “in Zerind” location only, start in { #5,#7 } . Solution?? ♦ (Abstract) solution = [ Right, while dirt do Suck ] set of real paths that are solutions in the real world [ Right, if dirt then Suck ] ♦ Each abstract action should be “easier” than the original problem! Chapter 3 10 Chapter 3 12
Example: vacuum world state space graph Example: vacuum world state space graph R R L R L R L L S S S S R R R R L R L R L R L R L L L L S S S S S S S S R R L R L R L L S S S S states?? states??: integer dirt and robot locations (ignore dirt amounts etc.) actions?? actions??: Left , Right , Suck , NoOp goal test?? goal test?? path cost?? path cost?? Chapter 3 13 Chapter 3 15 Example: vacuum world state space graph Example: vacuum world state space graph R R L R L R L L S S S S R R R R L R L R L R L R L L L L S S S S S S S S R R L R L R L L S S S S states??: integer dirt and robot locations (ignore dirt amounts etc.) states??: integer dirt and robot locations (ignore dirt amounts etc.) actions?? actions??: Left , Right , Suck , NoOp goal test?? goal test??: no dirt path cost?? path cost?? Chapter 3 14 Chapter 3 16
Example: vacuum world state space graph Example: The 8-puzzle R L R 7 2 4 5 1 2 3 L S S 5 6 4 5 6 R R L R L R L L 8 3 1 7 8 S S S S R Start State Goal State L R L states??: integer locations of tiles (ignore intermediate positions) S S actions?? states??: integer dirt and robot locations (ignore dirt amounts etc.) goal test?? actions??: Left , Right , Suck , NoOp path cost?? goal test??: no dirt path cost??: 1 per action (0 for NoOp ) Chapter 3 17 Chapter 3 19 Example: The 8-puzzle Example: The 8-puzzle 7 2 4 1 5 2 3 7 2 4 5 1 2 3 5 6 4 5 6 5 6 4 5 6 8 3 1 7 8 8 3 1 7 8 Start State Goal State Start State Goal State states?? states??: integer locations of tiles (ignore intermediate positions) actions?? actions??: move blank left, right, up, down (ignore unjamming etc.) goal test?? goal test?? path cost?? path cost?? Chapter 3 18 Chapter 3 20
Example: The 8-puzzle Example: robotic assembly P 7 2 4 1 5 2 3 R R R R 5 6 4 5 6 R 8 3 1 7 8 Start State Goal State states??: real-valued coordinates of robot joint angles states??: integer locations of tiles (ignore intermediate positions) parts of the object to be assembled actions??: move blank left, right, up, down (ignore unjamming etc.) goal test??: = goal state (given) actions??: continuous motions of robot joints path cost?? goal test??: complete assembly with no robot included! path cost??: time to execute Chapter 3 21 Chapter 3 23 Example: The 8-puzzle Tree search algorithms 7 2 4 1 5 2 3 Basic idea: offline, simulated exploration of state space 5 6 4 5 6 by generating successors of already-explored states (a.k.a. expanding states) 8 3 1 7 8 function Tree-Search ( problem, strategy ) returns a solution, or failure initialize the frontier using the initial state of problem Start State Goal State loop do if the frontier is empty then return failure states??: integer locations of tiles (ignore intermediate positions) choose a leaf node and remove it from the frontier based on strategy actions??: move blank left, right, up, down (ignore unjamming etc.) if the node contains a goal state then return the corresponding solution goal test??: = goal state (given) else expand the chosen node and add the resulting nodes to the frontier path cost??: 1 per move end [Note: optimal solution of n -Puzzle family is NP-hard] Chapter 3 22 Chapter 3 24
Tree search example Tree search example Arad Arad Sibiu Timisoara Zerind Sibiu Timisoara Zerind Arad Fagaras Oradea Arad Lugoj Arad Oradea Rimnicu Vilcea Arad Fagaras Oradea Rimnicu Vilcea Arad Lugoj Arad Oradea Chapter 3 25 Chapter 3 27 Tree search example Implementation: states vs. nodes A state is a (representation of) a physical configuration Arad A node is a data structure constituting part of a search tree includes parent, children, depth, path cost g ( x ) Sibiu Timisoara Zerind States do not have parents, children, depth, or path cost! parent, action Arad Fagaras Oradea Rimnicu Vilcea Arad Lugoj Arad Oradea depth = 6 State Node 5 4 5 4 g = 6 6 1 8 6 1 8 state 7 7 3 3 2 2 The Expand function creates new nodes, filling in the various fields and using the SuccessorFn of the problem to create the corresponding states. Chapter 3 26 Chapter 3 28
Recommend
More recommend