Problem-solving agents Restricted form of general agent: function SIMPLE-PROBLEM-SOLVING-AGENT()returns an action PROBLEM SOLVING AND SEARCH CHAPTER 3 a seg一REMAINDER(4staO .t) return action Reminders Example:Romania Assignment 0 due 5pm today Assignment 1 posted,due 2/9 Section 105 will move to-10am starting next week Formulate goal: be in Bucharest Formulate problem: states:various cities actions:drive between cities Outline Example:Romania Problem-solving agents ◇Problem types ◇Problem formulation ◇Example problems Basic search algorithms
Problem solving and search Chapter 3 Chapter 3 1 Reminders Assignment 0 due 5pm today Assignment 1 posted, due 2/9 Section 105 will move to 9-10am starting next week Chapter 3 2 Outline ♦ Problem-solving agents ♦ Problem types ♦ Problem formulation ♦ Example problems ♦ Basic search algorithms Chapter 3 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 offline 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 5 Example: Romania Giurgiu Urziceni Hirsova Eforie Neamt Oradea Zerind Arad Timisoara Lugoj Mehadia Dobreta Craiova Sibiu Fagaras Pitesti Vaslui Iasi Rimnicu Vilcea Bucharest 71 75 118 111 70 75 120 151 140 99 80 97 101 211 138 146 85 90 98 142 92 87 86 Chapter 3 6
Problem types Example:va world DaemAtoaaaim is a seq 图 图 Non-ob omcrmn,atih dirty a clea Unknown state space exploration problem ("online") Example:vacuum world Example:vacuum world Single-state. 图 图▣图 ‘☑ Conformant,start in (..4.56.7.8) 图☐·☑ 图 AE 图 ☑ clean carpet Righ,dirt then Suck Example:vacuum world Single-state problem formulation 图 initial statetArad 图□ ☑ successor fune 冠 goal test,can be 4■ ☑ path cost (additive)
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 7 Example: vacuum world Single-state, start in #5. Solution?? 1 2 3 4 5 6 7 8 Chapter 3 8 Example: vacuum world Single-state, start in #5. Solution?? [Right, Suck] Conformant, start in {1, 2, 3, 4, 5, 6, 7, 8} e.g., Right goes to {2, 4, 6, 8}. Solution?? 1 2 3 4 5 6 7 8 Chapter 3 9 Example: vacuum world Single-state, start in #5. Solution?? [Right, Suck] Conformant, start in {1, 2, 3, 4, 5, 6, 7, 8} e.g., Right goes to {2, 4, 6, 8}. Solution?? [Right, Suck,Left, Suck] Contingency, start in #5 Murphy’s Law: Suck can dirty a clean carpet Local sensing: dirt, location only. Solution?? 1 2 3 4 5 6 7 8 Chapter 3 10 Example: vacuum world Single-state, start in #5. Solution?? [Right, Suck] Conformant, start in {1, 2, 3, 4, 5, 6, 7, 8} e.g., Right goes to {2, 4, 6, 8}. Solution?? [Right, Suck,Left, Suck] Contingency, start in #5 Murphy’s Law: Suck can dirty a clean carpet Local sensing: dirt, location only. Solution?? [Right, if dirt then Suck] 1 2 3 4 5 6 7 8 Chapter 3 11 Single-state problem formulation A problem is defined by four items: initial state e.g., “at Arad” successor function S(x) = set of action–state pairs e.g., S(Arad) = {hArad → Zerind,Zerindi, . . .} goal test, can be explicit, e.g., x = “at Bucharest” implicit, e.g., NoDirt(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
Selecting a state space Example:vacuum world state space graph 0图O (Abstract)state set of real states 0号0·0T0 eg.. 00 setofreapat thatareos in thereord Each abstract actionshoud bethan the orignl problem! co? Example:vacuum world state space graph Example:vacuum world state space graph 0。 1 00 00 00 00 Example:vacuum world state space graph Example:vacuum world state space graph 00 0图®0 000g号0 00g华0 号50 50 二h
Selecting a state space Real world is absurdly complex ⇒ state space must be abstracted for problem solving (Abstract) state = set of real states (Abstract) action = complex combination of real actions e.g., “Arad → Zerind” represents a complex set of possible routes, detours, rest stops, etc. For guaranteed realizability, any real state “in Arad” must get to some real state “in Zerind” (Abstract) solution = set of real paths that are solutions in the real world Each abstract action should be “easier” than the original problem! Chapter 3 13 Example: vacuum world state space graph R L S S S S R L R L R L S S S S L L L L R R R R states?? actions?? goal test?? path cost?? Chapter 3 14 Example: vacuum world state space graph R L S S S S R L R L R L S S S S L L L L R R R R states??: integer dirt and robot locations (ignore dirt amounts etc.) actions?? goal test?? path cost?? Chapter 3 15 Example: vacuum world state space graph R L S S S S R L R L R L S S S S L L L L R R R R states??: integer dirt and robot locations (ignore dirt amounts etc.) actions??: Left, Right, Suck, NoOp goal test?? path cost?? Chapter 3 16 Example: vacuum world state space graph R L S S S S R L R L R L S S S S L L L L R R R R states??: integer dirt and robot locations (ignore dirt amounts etc.) actions??: Left, Right, Suck, NoOp goal test??: no dirt path cost?? Chapter 3 17 Example: vacuum world state space graph R L S S S S R L R L R L S S S S L L L L R R R R states??: integer dirt and robot locations (ignore dirt amounts etc.) actions??: Left, Right, Suck, NoOp goal test??: no dirt path cost??: 1 per action (0 for NoOp) Chapter 3 18
ple:The 8-puzzle aple:The 8-puzzle 724 123 724 23 468 831 8 831 可8 ic) oal state (giv Example: The 8-puzzle Example:The 8-puzzle 724 回▣ ⑦24 23 56 456 83可 78 831 78 diate positions) Note:optimal solution of n-Puzzle family is NP.hard Example:The 8-puzzle Example:robotic assembly 724 123 56 456 831 actions??:continuous motions of robot joints no robot included! to execute
Example: The 8-puzzle 2 Start State Goal State 51 3 4 6 7 8 5 1 2 3 4 6 7 8 5 states?? actions?? goal test?? path cost?? Chapter 3 19 Example: The 8-puzzle 2 Start State Goal State 51 3 4 6 7 8 5 1 2 3 4 6 7 8 5 states??: integer locations of tiles (ignore intermediate positions) actions?? goal test?? path cost?? Chapter 3 20 Example: The 8-puzzle 2 Start State Goal State 51 3 4 6 7 8 5 1 2 3 4 6 7 8 5 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 Example: The 8-puzzle 2 Start State Goal State 51 3 4 6 7 8 5 1 2 3 4 6 7 8 5 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 Example: The 8-puzzle 2 Start State Goal State 51 3 4 6 7 8 5 1 2 3 4 6 7 8 5 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 Example: robotic assembly R R R P R R 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
Tree search algorithms ree search example Bat by ge Tree search example Implementation:states vs.nodes ▣回□ 可▣可 ○g 回同 in the Tree search example Implementation:general tree search
Tree search algorithms Basic idea: offline, simulated exploration of state space by generating successors of already-explored states (a.k.a. expanding states) function Tree-Search( problem,strategy) returns a solution, or failure initialize the search tree using the initial state of problem loop do if there are no candidates for expansion then return failure choose a leaf node for expansion according to strategy if the node contains a goal state then return the corresponding solution else expand the node and add the resulting nodes to the search tree end Chapter 3 25 Tree search example Rimnicu Vilcea Lugoj Sibiu Zerind Arad Fagaras Oradea Timisoara Arad Arad Oradea Arad Chapter 3 26 Tree search example Arad Fagaras Oradea Rimnicu Vilcea Arad Lugoj Arad Oradea Zerind Arad Sibiu Timisoara Chapter 3 27 Tree search example Rimnicu Vilcea Arad Lugoj Arad Oradea Zerind Arad Sibiu Arad Fagaras Oradea Timisoara Chapter 3 28 Implementation: states vs. nodes A state is a (representation of) a physical configuration A node is a data structure constituting part of a search tree includes parent, children, depth, path cost g(x) States do not have parents, children, depth, or path cost! 1 3 2 5 4 6 7 1 8 3 2 5 4 6 7 8 State Node depth = 6 g = 6 state parent, action 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 29 Implementation: general tree search function Tree-Search( problem, fringe) returns a solution, or failure 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 fringe ← InsertAll(Expand(node, problem),fringe) function Expand( node, problem) returns a set of nodes successors ← the empty set for each action, result in Successor-Fn(problem,State[node]) do s ← a new Node Parent-Node[s] ← node; Action[s] ← action; State[s] ← result Path-Cost[s] ← Path-Cost[node] + Step-Cost(node, action,s) Depth[s] ← Depth[node] + 1 add s to successors return successors Chapter 3 30