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
Repeated States A CB C A State space Search tree B GC A BGCBA GBA initial state goal state
function G RAPH -S EARCH (problem) returns a solution, or failure initialize the frontier using the initial state of problem initialize the explored set to be empty 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 add the node to the explored set expand the chosen node, adding the resulting nodes to the frontier, but only if not in the frontier or explored set Graph Search Algorithm From Figure 3.7, p. 77
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
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