2 Tree Search Implementation Strategies Require data structure to model search treeTree Node:State (e.g. Sibiu)Parent (e.g. Arad)Action (e.g. GoTo(Sibiu))Path cost or depth (e.g. 140)Children (e.g. Faragas, Oradea) (optional, helpful in debugging)
3 Queue Methods: Empty(queue) Pop(queue) Insert(queue, element) Returns true if there are no more elementsPop(queue)Remove and return the first elementInsert(queue, element)Inserts element into the queueInsertFIFO(queue, element) – inserts at the endInsertLIFO(queue, element) – inserts at the frontInsertPriority(queue, element, value) – inserts sorted by value
8 Greedy best-first search Evaluation function f(n) = h(n) (heuristic)e.g., f(n) = hSLD(n) = straight-line distance from n to BucharestGreedy best-first search expands the node that is estimated to be closest to goal
16 A* search Ideas: Avoid expanding paths that are already expensive ConsiderCost to get here (known) – g(n)Cost to get to goal (estimate from the heuristic) – h(n)
17 A * Evaluation functions Evaluation function f(n) = g(n) + h(n)g(n) = cost so far to reach nh(n) = estimated cost from n to goalf(n) = estimated total cost of path through n to goalstartgoalng(n)h(n)f(n)
20 A* Heuristics A heuristic h(n) is admissible if for every node n, h(n) ≤ h*(n), where h*(n) is the true cost to reach the goal state from n.An admissible heuristic never overestimates the cost to reach the goal, i.e., it is optimisticExample: hSLD(n) (never overestimates the actual road distance)
21 What happens if heuristic is not admissible? Will still find solution (complete)But might not find best solution (not optimal)
22 Properties of A* (w/ admissible heuristic) Complete?Yes (unless there are infinitely many nodes with f ≤ f(G) )Optimal?YesTime?Exponential, approximately O(bd) in the worst caseSpace?O(bm) Keeps all nodes in memory
23 The heuristic h(x) guides the performance of A* Let d(x) be the actual distance between S and Gh(x) = 0 :A* is equivalent to Uniform-Cost Searchh(x) <= d (x) :guarantee to compute the shortest path; the lower the value h(x), the more node A* expandsh(x) = d (x) :follow the best path; never expand anything else; difficult to compute h(x) in this way!h(x) > d(x) :not guarantee to compute a best path; but very fasth(x) >> g(x) :h(n) dominates -> A* becomes the best first search
26 Admissible heuristics E.g., for the 8-puzzle:h1(n) = number of misplaced tilesh2(n) = summed Manhattan distance for all tiles (i.e., no. of squares from desired location of each tile)h1(S) = ?h2(S) = ?
27 Admissible heuristics E.g., for the 8-puzzle:h1(n) = number of misplaced tilesh2(n) = total Manhattan distance (i.e., no. of squares from desired location of each tile)h1(S) = ? 8h2(S) = ? = 18Which is better?
28 Dominance If h2(n) ≥ h1(n) for all n (both admissible) then h2 dominates h1 h2 is better for searchWhat does better mean?All searches we’ve discussed are exponential in time
29 Comparison of algorithms (number of nodes expanded) Iterative deepeningA*(teleporting tiles)A* (manhattan distance)21061121312680201836403522773145391131.8 * 1083056363248.6 * 1010391351641
31 Where do heuristics come from? From peopleKnowledge of the problemFrom computersBy considering a simpler version of the problemCalled a relaxation
32 Relaxed problems8-puzzleIf the rules of the 8-puzzle are relaxed so that a tile can move anywhere, then h1(n) gives the shortest solutionIf the rules are relaxed so that a tile can move to any adjacent square, then h2(n) gives the shortest solutionConsider the example of straight line distance (Romania navigation)Is that a relaxation?
33 Iterative-Deepening A* (IDA*) Further reduce memory requirements of A*Regular Iterative-Deepening: regulated by depthIDA*: regulated by f(n)=g(n)+h(n)