Ch. 3 – Search Supplemental slides for CSE 327 Prof. Jeff Heflin
8-puzzle Successor Function blank-rightblank-downblank-leftblank-up
8-puzzle Search Tree initial state
function TREE-SEARCH(problem,fringe) returns a solution, or failure fringe INSERT(MAKE-NODE(INITIAL-STATE[problem],fringe) loop do if EMPTY?(fringe) then return failure node REMOVE-FIRST(fringe) if GOAL-TEST[problem] applied to STATE[node] succeeds then return SOLUTION(node) fringe INSERT-ALL(EXPAND(node,problem),fringe) Tree Search Algorithm 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 Java or C++) From Figure 3.9, p. 72
Problem Solving Agent Algorithm 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 do goal FORMULATE-GOAL(state) problem FORMULATE-PROBLEM(state,goal) seq SEARCH(problem) action FIRST(seq) seq REST(seq) return action From Figure 3.1, p. 61
Water Jug Problem state: initial state: goal test: –x and y can be any value path cost: –1 per solution step? –1 per gallon of water moved? actions/successor function –let C 12 =12, C 8 =8, C 3 =3 fill-jug-i –if J i < C i then J i =C i empty-jug-i-into-jug-j –if J i <= C j – J j then J j ’ = J j + J i, J i ’=0 fill-jug-i-from-jug-j –if J j >= C i – J i then J j ’ = J j – (C i – J i ), J i ’=C i
Depth-first Search A CB DEF H G I not generated on fringe in memory deleted
Breadth-first Search A CB DEF H G I not generated on fringe in memory deleted
Uniform Cost Search I GB G I B G State space Search tree g(n)=0 g(n)=4 g(n)=10 g(n)=9 C 3 C g(n)=7 3 not generated on fringe in memory deleted
Repeated States A CB C A State space Search tree B GC A BGCBA GBA initial state goal test
Uninformed Search Summary depth-firstbreadth-firstuniform cost queuingadd to front (LIFO) add to back (FIFO)by path cost complete?noyesyes, if all step costs are greater than 0 optimal?noyes, if identical step costs yes, if all step costs are greater than 0 timeexpensive spacemodestexpensive