80 likes | 179 Views
Ch. 3 – Search. Supplemental slides for CSE 327 Prof. Jeff Heflin. function SIMPLE-PROBLEM-SOLVING-AGENT( percept ) returns an action
E N D
Ch. 3 – Search Supplemental slides for CSE 327 Prof. Jeff Heflin
function SIMPLE-PROBLEM-SOLVING-AGENT(percept)returns an action static: seq, an action sequence, initially emptystate, some description of the current world stategoal, a goal initially nullproblem, a problem formulation state UPDATE-STATE(state,percept)ifseq is empty then dogoal FORMULATE-GOAL(state)problem FORMULATE-PROBLEM(state,goal)seq SEARCH(problem) action FIRST(seq)seq REST(seq)returnaction From Figure 3.1, p. 61 Problem Solving Agent Algorithm
8-puzzle Successor Function blank-right blank-left blank-up blank-down
state: <J12, J8, J3> initial state: <0, 0, 0> goal test: <1, x, y> x and y can be any value path cost: 1 per solution step? 1 per gallon of water moved? actions/successor function let C12=12, C8=8, C3=3 fill-jug-i if Ji < Ci then Ji=Ci empty-jug-i-into-jug-j if Ji <= Cj – Jj thenJj’ = Jj + Ji, Ji’=0 fill-jug-i-from-jug-j if Jj >= Ci – Ji thenJj’ = Jj – (Ci – Ji), Ji’=Ci Water Jug Problem
8-puzzle Search Tree initial state
Tree Search Algorithm function TREE-SEARCH(problem,fringe)returns a solution, or failure fringe INSERT(MAKE-NODE(INITIAL-STATE[problem],fringe)loopdoif EMPTY?(fringe) then return failurenode REMOVE-FIRST(fringe)if GOAL-TEST[problem] applied to STATE[node] succeedsthen return SOLUTION(node)fringe INSERT-ALL(EXPAND(node,problem),fringe) Notes: 1. fringe argument should be an empty queue. The type of the queue (e.g., LIFO, FIFO, etc.) will affect the order of the search 2. INITIAL-STATE[problem] is just syntax for accessing an object’s data (think problem.initialState in C++) From Figure 3.9, p. 72
Depth-first Search 1 A not generated on fringe 2 7 B C in memory deleted 3 8 6 9 D E F G 4 5 H I
Breadth-first Search 1 A not generated on fringe 2 3 B C in memory deleted 4 5 6 7 D E F G 8 9 H I