Ch. 3 – Search Supplemental slides for CSE 327 Prof. Jeff Heflin
8-Puzzle Transition Model blank-rightblank-downblank-leftblank-up state s actions a RESULT(s,a)
8-puzzle Search Tree initial state
function T REE -S EARCH (problem) returns a solution, or failure initialize the frontier using the initial state of problem loop do if the frontier is empty then return failure choose a leaf node and remove it from the frontier if the node contains a goal state then return the corresponding solution expand the chosen node, adding the resulting nodes to the frontier Tree Search Algorithm From Figure 3.7, p. 77
Problem Solving Agent Algorithm function S IMPLE -P ROBLEM -S OLVING -A GENT (percept) returns an action persistent: seq, an action sequence, initially empty state, some description of the current world state goal, a goal, initially null problem, a problem formulation state U PDATE -S TATE (state,percept) if seq is empty then goal F ORMULATE -G OAL (state) problem F ORMULATE -P ROBLEM (state,goal) seq S EARCH (problem) if seq = failure then return a null action action F IRST (seq) seq R EST (seq) return action From Figure 3.1, p. 67
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 frontier in memory deleted
Breadth-first Search A CB DEF H G I not generated on frontier 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 frontier in memory deleted
Repeated States A CB C A State space Search tree B GC A BGCBA GBA initial state goal state
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
A* Example Use A* to solve the 8-puzzle: initial state: goal state: Consider these heuristics –H 1 : The number of tiles out of place –H 2 : Sum of distances of tiles from goal positions Ignore moves that return you to the previous state path cost is the total number of moves made
A* on 8-puzzle f=0+3=3 f=1+3=4 f=2+4=6 f=2+2=4 f=2+3=5f=2+4=6 f=3+3=6 f=3+1=4 f=4+2=6f=4+0= Heuristic = H 1 Whether or not this node is expanded depends on how you break ties. It could be expanded at any time or not at all.
A* on 8-puzzle f=0+4=4 f=1+3=4 f=1+5=6 f=2+4=6f=2+2=4 f=3+3=6 f=3+1=4 f=4+2=6f=4+0= Heuristic = H 2
Summary of Search Algorithms typeorderingoptimal?complete?efficient? depth-firstuninformedLIFOno if lucky breadth-firstuninformedFIFOyes a yesno uniform costuninformedg(n)yes b no greedyinformedh(n)no usually A*informedg(n)+h(n)yes c yes b yes a – if step costs are identical b – if step costs > 0 c – if heuristic is admissible and consistent