You are on page 1of 128
Chapter 3 Best First Search i Best First Search « So far, we have assumed that all the edges have the same cost, and that an optimal solution is a shortest path from the initial state to a goal state. » Let’s generalize the model to allow individual edges with arbitrary costs associated with them. » We'll use the following denotations: Jength - number of edges in the path cost - sum of the edge costs on the path Best First Search Best First Search is an entire class of search algorithms, each of which employ a cost function. The cost function : froma NOdE to its COSt. Example: a sum of the edge costs from the root to the node. We assume that a lower cost node is a better node. The different best-first search algorithms differ primarily in their cost function. Best First Search Best-first search employs two lists of nodes: = Open list ¢ contains those nodes that have been generated but not yet expanded. » Closed list contains those nodes that have already been completely expanded Best First Search Initially, just the root node is included on the Open list, and the Closed list is empty. At each cycle of the algorithm, an Open node of lowest cost is expanded, moved to Closed, and its children are inserted back to Open. The Open list is maintained as a priority queue. The algorithm terminates when a goal node is chosen for expansion, or there are no more nodes remaining in Open list. Example of Best First Search » One example of Best First Search is breadth first search. = The cost here is a depth of the node below the root. » depth first search is not considered to be best- first-search, because it does not maintain Open and Closed lists, in order to run in linear space. Uniform Cost Search = Let g(n) be the sum of the edges costs from root to node n. If g(n) is our overall cost function, then the best first search becomes Uniform Cost Search, also known as_ Dijkstra’s_ single-source-shortest-path algorithm . «= Initially the root node is placed in Open with a cost of zero. At each step, the next node n to be expanded is an Open node whose cost g(n) is lowest among all Open nodes. Example of Uniform Cost Search » Assume an example tree with different edge costs, represented by numbers next to the edges. a @® Notations for this example: — generated node — expanded node Example of Uniform Cost Search 2 Os Example of Uniform Cost Search te) re rn Example of Uniform Cost Search “| oo Example of Uniform Cost Search (c) a , ) @ @ Closed list: (Sfelp & Ls e) Open list: Q alo wl | = |ta = Example of Uniform Cost Search 2 Closed list: (Sfelbla & Ls e) Oo ea [o} Open list: Example of Uniform Cost Search wed” 2 - @ @ © Closed list: (Sfelblalet Open list: g EES) [es]=n Example of Uniform Cost Search 2 ce) o : @ Ce) Closed list: falelbla Open list: aq a Example of Uniform Cost Search 2 @ 7m reat Closed list: (4 dleltiaf Open list: Uniform Cost Search » We consider Uniform Cost Search to be brute force search, because it doesn’t use a heuristic function. = Questions to ask: ¢ Whether Uniform cost always terminates? ¢ Whether it is guaranteed to find a goal state? Uniform Cost Search - Termination « The algorithm will find a goal node or report that there is no goal node under following conditions: @ the problem space is finite ¢ there must exist a path to a goal with finite length and finite cost there must not be any infinitely long paths of finite cost » Wewill assume that all the edges have a minimum non-zero edge cost e to a solve a problem of infinite chains of nodes with zero-cost edges. Then, UCS will eventually reach a goal of finite cost If one exists In the graph. Uniform Cost Search - Solution Quality = Theorem 3.1 : Jn a graph where all edges have a minimum positive cost, and in which a finite path exists to a goal node, uniform-cost search will return a lowest-cost path to a goal node. « Steps of proof ¢ show that if Open contains a node on an optimal path to a goal before a node expansion, then it must contain one after the node expansion ¢ show that if there is a path to a goal node, the algorithm will eventually find it ¢ show that the first time a goal node is chosen for expansion, the algorithm terminates and returns the path to that node as the solution Uniform Cost Search - Time Complexity » Inthe worst case every edge has the minimum edge e. ¢ cis the cost of optimal solution, so once all nodes of cost %TSP Gis the optimal solution. Admissible, Consistent and Monotonic Heuristics = Admissible: if we define h*(n) as the exact lowest cost from node nto a goal, a heuristic function h(n) is admissible if and only if Vn h(n) < h(n) = Consistent: this quality is similar to the triangle inequality of all metrics. If c(n,m) is the cost of a shortest path from node n to node m, then a heuristic function h(x) is consistent if ¥n,m h(n) < c(n,m) + h(m) Consistent heuristic h(n) < c(n,m) + h(m) {h(n)-h(m)| c will be expanded. Some nodes n whose cost f(n) = c will be expanded. Thus, f(n) < c is a sufficient condition for A* to expand node n, and f(n) scis a necessary condition. 2 . . * Time optimality of A = Theorem 3.3 : For a given consistent (admissible) heuristic function, every admissible algorithm must expand all nodes surely expanded by A*. » Intuition: If anode m with f(m) bis also a constant ) Thus, the asymptotic time complexity of A* using a heuristic that has constant absolute error is linear in the solution depth. Constant Relative Error » A much more realistic assumption for measurements of heuristic functions, is constant relative error. We assume that the absolute error is a bounded percentage of the quantity being estimated. h(n) =a. h*(n) Let's repeat the above analysis with the new heuristic model g(n)=x+y h*(n)=y+d-x h(n) =o (y +d- x) f(n) = g(n) + h(n) =x+y +a (y+d-x) max (h(n)) , D(x) =1 A way to view D(x) is that it is the probability that a state is chosen randomly and uniformly from all states in the problem space has h(n) h(parent) -1. @ the solid boxes represent “fertile” nodes which will be expanded. @ the dotted boxes represent “sterile” nodes that will not be expanded, because their total cost exceeds the optimal solution cost. @ the thick diagonal! line separates the fertile nodes from the sterile nodes. In this particular example, the maximum value of the heuristic is 4, and the depth of solution d is 8 moves. We chose 3 for the heuristic value of the initial state. Nodes Expanded as a Function of Depth » We will count the number of node expansions, which is the number of fertile nodes in the graph. The number of nodes generated is simply 6 times the number expanded. » There is a single state at depth 0. This root node generates b children, whose heuristic value range from 2 to 4, inclusive. Each of these nodes generate b nodes, whose heuristic value will range from 1 to 4, giving a total of b* nodes at depth 2. Since the goal is assumed to be at depth 8, in the worst case, all nodes n whose total cost f(n) = g(n) + h(n) < 8 will be expanded.Since 4 is a maximum heuristic value, all nodes down to depth 8 - 4 = 4 will be expanded, as in brute force search. Down to this depth, the number of nodes at depth d will be b%. Note that P(4) = 1, and hence b*P(4) = b*. » In general, down to depth d - m, where m is max heuristic value, all nodes are expanded. Nodes Expanded as a Function of Depth « The nodes expanded at depth 5 are fertile nodes, which are those with f(n) = g(n) + h(n) =5+h(n)<8 = h(n) <3. In equilibrium distribution, the fraction of nodes at depth 5 with h(n) < 3 is P(3). Since all nodes at depth 4 are expanded, the total number of nodes at depth 5 is b®°, and the number of fertile nodes at depth 5 is bSP(3). » While there are nodes at depth 6 with all possible heuristic values, their distribution in no longer equal to the equilibrium distribution. The number of nodes at depth 6 with h(n) < 2 is completely unaffected by this pruning and is the same as it would be in a brute force search at depth 6, or b®P(2). Nodes Expanded as a Function of Depth - Due to consistency of the heuristic function, all the possible parents of fertile nodes are themselves fertile. Thus, the number of nodes with each heuristic value to the left of the diagonal line is the same as it would be in a brute force search to the same depth. » If the heuristic were inconsistent, then the distribution of fertile nodes would change at every level where pruning occurred, making analysis much more complex. « Ingeneral, the number of fertile nodes at depth jis b’P(d - I) Q d >" b'P(d—i) The Heuristic Branching Factor » Heuristic branching factor = number of nodes generated in a search to depth d number of nodes generated in a search to depth d - 1 « The heuristic branching factor is the same as the brute-force branching factor b. » This analysis contradicts the abstract model: ¢ abstract model: the effect of the heuristic function is to reduce the heuristic branching factor and the overall complexity from O(b2) to O(a), a

You might also like