Presentation on theme: "Intelligence Artificial Intelligence Ian Gent Search: 2."— Presentation transcript:
Intelligence Artificial Intelligence Ian Gent Search: 2
Intelligence Artificial Intelligence Part I :The Eights Puzzle Part II: Search Algorithms via lists Part II: Best First Search Search 2
3 The Eights Puzzle zSliding blocks puzzle, more usually 15 puzzle yshows you the state of AI in the sixties yhow many moves between these states?
4 Search Reminder zSearch states, Search trees zDon’t store whole search trees, just the frontier
5 Frontiers as lists zOne way to implement search algorithms is via lists yLists fundamental in AI programming xmain data structure in Lisp, Prolog xmakes list processing really easy (no pointers) x zLists can easily store frontier of search zEach element in list is search state zDifferent algorithms manipulate list differently
6 A general search algorithm z1. Form a one element list with null state z2. Loop Until (either list empty or we have a solution) yRemove the first state X from the list yChoose the next decision to make e.g. which letter to set in SAT, which city to choose successor in TSP yCreate a new state for each possible choice of decision e.g. upper/lower case, Walla Walla/Oberlin/Ithaca yMERGE the set of new states into the list different algorithms will have different MERGE methods z3. If (solution in list) succeed y else list must be empty, so fail
7 Depth First Search zThe most important AI search algorithm? zMERGE = push ytreat list as a stack ynew search states to explore at front of list, get treated first zWhat about when many new states created? yWe use a heuristic to decide what order to push new states yall new states in front of all old states in the list zWhat about when no new states created? yWe must be at a leaf node in the search tree ywe have to backtrack to higher nodes
8 Breadth First Search zMERGE = add to end ytreat list as a queue ynew search states to explore at end of list, zWhat about when many new states created? yWe use a heuristic to decide what order to add new states zBreadth first considers all states at a given depth in the search tree before going on to the next depth ycompare with depth-first, ydepth-first considers all children of current node before any other nodes in the search tree ylist can be exponential size -- all nodes at given depth
9 Depth-First-Depth-Bounded Search zAs depth-first search zDisallow nodes beyond a certain depth d in tree yto implement, add depth in tree to search state zCompare DFDB with Depth-first yDFDB: always finds solution at depth <= d xDF may find very deep solution before shallow ones yDFDB: never goes down infinite branch xrelevant if search tree contains infinite branches e.g. Eights puzzle yDFDB: we have a resource limit (b^d if b branching rate) yHow do we choose d?
10 Iterative Deepening Search zNo longer a simple instance of general search yd = min-d yLoop Until (solution found) xapply DFDB(d) xd := d + increment zWhy? yGuarantees to find a solution if one exists (cf DFDB) yFinds shallow solutions first (cf DF) yAlways has small frontier (cf Breadth First) ySurprising asymptotic guarantees xsearch time typically no more than d/(d-1) as bad as DF
11 Why is Iterative deepening ok? zSuppose increment = 1, solution at depth d yhow much more work do we expect to do in I.D. vs DF ? zI.d. repeats work from depths 1 to d d i=1 b i = b d+1 / (b - 1) zRatio to b d = b d+1 / b d (b - 1) = b/(b-1) zSo we only do b/(b-1) times as much work as we need to ye.g. even if b=2, only do twice as much work zVery often worth the overhead for the advantages
12 Comparing Search Algorithms
13 Best First Search zAll the algorithms up to now have been hard wired yI.e. they search the tree in a fixed order yuse heuristics only to choose among a small number of choices xe.g. which letter to set in SAT / whether to be A or a zWould it be a good idea to explore the frontier heuristically? zI.e. use the most promising part of the frontier? zThis is Best First Search
14 Best First Search zBest First Search is still an instance of general algorithm zNeed heuristic score for each search state zMERGE: merge new states in sorted order of score yI.e. list always contains most promising state first ycan be efficiently done if use (e.g.) heap for list no, heaps not done for free in Lisp, Prolog. zSearch can be like depth-first, breadth-first, or in- between ylist can become exponentially long
15 Search in the Eights Puzzle zThe Eights puzzle is different to (e.g.) SAT ycan have infinitely long branches if we don’t check for loops xbad news for depth-first, xstill ok for iterative deepening yUsually no need to choose variable (e.g. letter in SAT) xthere is only one piece to move (the blank) xwe have a choice of places to move it to ywe might want to minimise length of path xin SAT just want satisfying assignment
16 Search in the Eights Puzzle zAre the hard wired methods effective? yBreadth-first very poor except for very easy problems yDepth-first useful without loop checking xnot much good with it, either yDepth-bounded -- how do we choose depth bound? yIterative deepening ok xand we can use increment = 2 (why?) xstill need good heuristics for move choice zWill Best-First be ok?
17 Search in the Eights Puzzle zHow can we use Best-First for the Eights puzzle? zWe need good heuristic for rating states zIdeally want to find guaranteed shortest solution yTherefore need to take account of moves so far yAnd some way of guaranteeing no better solution elsewhere
18 Next week in Search for AI zHeuristics for the Eights Puzzle zthe A* algorithm