Lesson 6 Branch and Bound (or Uniform Cost) Search Branch and Bound – Paths are developed in terms of increasing cost (more accurately, in terms of non-decreasing cost). Once a path to the goal is found, it is likely that this path is optimal. To change “likely” to “guaranteed”, one must continue generating partial paths until each has a cost greater than or equal to the path found to the goal. Branch and Bound Search To conduct a branch-and-bound search, Form a one-element queue consisting of a zero-length path that contains only the root node. Until the first path is the queue terminates at the goal node or the queue is empty, o Remove the first path from the queue; create new paths by extending the first path to all the neighbors of the terminal node. o Reject all new paths with loops. o Add the remaining new paths, if any, to the queue. o Sort the entire queue by path length with least-cost paths in front. If the goal node is found, announce success; otherwise announce failure. 1 of 14 Branch and Bound (Uniform Cost) Search – cont. A A 4 Start with root node A. Note: Heurisitic estimates are not used in this search! 11 B Paths from root are generated. 0 A C 4 15 13 D 12 10 I 18 4 E F 16 6 J G1 B H 3 K L 1 M 7 N Since B has the least cost, we expand it. G2 A 11 C 11 C B 13 D 19 11 4 B 15 15 E 17 4 13 D 19 Of our 3 choices, C has the least cost so we’ll expand it. E 17 H 15 Node H has the least cost thus far, so we expand it. 4 C B C 13 11 4 11 B E 17 14 A 4 D 19 3 F A 15 C 11 4 A 4 11 3 15 3 F 15 We have a goal, G2 but 1 need to expand other branches to see if there is 15 N another goal with less distance. 19 H 13 4 E 17 F 6 7 G2 21 2 of 14 3 L 21 3 1 M N 18 15 Note: Both nodes F and N have a cost of 15, we chose to expand the leftmost node first. We continue expanding until all remaining H paths are greater than 21, 7 the cost of G2 G2 21 Our B & B Example – continued A 4 11 B C 15 19 D 13 4 17 E F 16 6 10 J 29 Step 4 3 H 3 1 7 M N G2 K L 33 21 18 15 21 Step 2 Step 3 Step 1 All partial paths must be extended until their costs ≥ shortest path to goal. Step 1: The path to node N cannot be extended. Step 2: The next shortest path, A -> B -> E is extended Its cost now exceeds 21. Step 3: The path to node M, much like to node N, cannot be extended. Step 4: The last partial path with a cost ≤ 21 is extended. Its cost, 29, now exceeds the start -> goal path. The shortest path to a goal is A -> C -> H -> G2 with a cost of 21. 3 of 14 Branch and Bound with Estimates Now, we will augment Branch and Bound Search with underestimates of remaining distance. A:18 11 4 C:4 B:14 15 13 D:9 12 E:12 10 I:21 4 F:1 18 J:31 3 16 G1:0 6 K:34 H:3 3 L:21 1 M:18 7 N:8 G2:0 Hence, we generate paths in terms of their estimated overall length. A:18 A:18 A:18 11 A is not a goal; we continue 11 C:4 11+4=15 C:4 15 4 Observe, that in this search, we went to C first instead of B as we did in plain B&B. F:1 A:18 11 C:4 4 F:1 15 3 16 4 of 14 H:3 (11+3)+3=17 (11+4)+1=16 Branch and Bound with Estimates A:18 11 4 B:14 C:4 4+14=18 15 3 4 F:1 16 H:3 17 A:18 11 4 18 3 4 15 Step 3 15 C:4 B:14 16 D:9 H:3 F:1 Step 1 1 3 M:18 N:8 7 17 Step 2 G2:0 (11+3+7)+ 0 = 21 Once again, we are not done until all paths with an estimated cost ≤ 21 are extended. Step 1: The path A -> C -> F is exended to M. We are over 21. Step 2: A -> C -> H is extended to N. Over 21. Step 3: A -> B is extended to D. Over 21. 5 of 14 Branch & Bound with Underestimates To conduct a branch-and-bound search with a lower-bound estimate, Form a one-element queue consisting of a zero-length path that contains only the root node. Until the first path in the queue terminates at the goal node or the queue is empty, o Remove the first path from the queue; create new paths by extending the first path to all the neighbors of the terminal node. o Reject all new paths with loops. o Add the remaining new paths, if any, to the queue. o Sort the entire queue by the sum of the path length and a lowerbound estimate of the cost remaining, with least-cost paths in front. If the goal node is found, announce success; otherwise announce failure. 6 of 14 Branch and Bound with Dynamic Programming An Example (Artifical Intelligence by: Patrick Henry Winston, 3rd Edition, AddisonWesley): A B 4 C 4 3 5 5 S G 3 4 D 2 E 4 F A basic search problem. A path is to be found from the start node, S, to the goal node, G. Search procedures explore nets such as these, learning about connections and distance as they go. An illustration of the dynamic-programming S principle. The numbers beside the nodes are accumulated distances. There is no point in A expanding the instance of node D at the end Expanded next -> of S-A-D, because getting to the goal via the instance of D at the end of S-D is obviously B D 7 8 D 4 <- Never expanded more efficient. Assume cost 1 > cost 2 o Why would one wish to get to the goal by first taking a more expensive path to I? 7 of 14 Branch and Bound with Dynamic Programming – continued The Principle of Optimality – optimal paths are constructed from optimal subpaths. i.e. S Cost 1 Cost 2 I I an optimal subpath from S to G that passes through some intermediate node I is composed of an optimal S -> I path, followed by G an optimal I -> G path. To conduct a branch-and-bound search with dynamic programming. Form a one-element queue consisting of a zero-length path that contains only the root node. Until the first path in the queue terminates at the goal node or the queue is empty, o Remove the first path from the queue; create new paths by extending the first path to all the neighbors of the terminal node. o Reject all new paths with loops. o Add the remaining new paths, if any, to the queue. o If two or more paths reach a common node, delete all those paths except the one that reaches the common node with the minimum cost. o Sort the entire queue by path length with least-cost paths in front. If the goal node is found, announce success; otherwise announce failure. 8 of 14 Branch and Bound with Dynamic Programming – continued Branch-and-bound search, augmented by dynamic programming, determines that path S-D-E-F-G is optimal. The numbers beside the nodes are accumulated path distances. Many paths, those shown terminated with underbars, are found to be redundant. Thus, dynamic programming reduces the number of nodes expanded. S S S A A D 3 4 3 D A 4 4 B D 7 8 B D A E 7 8 9 6 S 3 D S A 4 D B D A 7 8 9 E 3 7 6 B F 11 10 A B D A 8 9 7 6 E B F 11 12 11 10 A B E C S 3 4 D 4 D D A 8 9 E C E B 11 12 11 6 F G 9 of 14 10 A* Search A* Search Branch and Bound, with Estimate of remaining distance, and Dynamic Programming principle employed To conduct A* Search Form a one-element queue consisting of a zero-length path that contains only the root node. Until the first path in the queue terminates at the goal node or the queue is empty, o Remove the first path from the queue; create new paths by extending the first path to all the neighbors of the terminal node. o Reject all new paths with loops. o If two or more paths reach a common node, delete all those paths except the one that reaches the common node with the minimum cost. o Sort the entire queue by the sum of the path length and a lowerbound estimate of the cost remaining, with least-cost paths in front. If the goal node is found, announce success; otherwise announce failure. 10 of 14 Branch and Bound (Uniform Cost) Search Complete: If one guarantees that the cost of every step is some small positive constant. Optimal: With above caveat. Time and Space Complexity: Recall b is branching factor and d is the depth of the shallowest goal node. Can be much greater than bd … this is because this search may explore large trees of small steps before exploring paths involving large and perhaps fruitful steps. A* Search is optimal whenever the estimate of remaining distance employed, h(n) is an admissible heuristic, i.e. h(n) never overestimates the remaining distance. A* is also complete. 11 of 14 Traversing a Maze Artificial Intelligence Illuminated by Ben Coppin, Jones & Bartlett F L C B J G D I K E IN A N M OUT A: entrance M: exit C, E, F, G, H, J, I: dead ends B, D, I, K: choices exist Imagine an ant crawling along the left wall…. the path A, B, E, F, C, D, G, H, I, J, K, L, M would be taken. A depth first search would follow this same path A B E C F D G H I J K L M 12 of 14 N Maze Example – A Search Approach Now, imagine that one had a heuristic measure of remaining distance (how was it obtained…??). Ten times straight-line distance to goal … in inches. L H J C G B 19.5 25 D E 30 23.5 17 10 24 N A 21 K 23.5 27.5 11 30 M We employ hillclimbing. 1) We first go to D as it has the lowest estimated remaining distance to the goal. A 30 B 25 C 24 D 2) I is selected next. 3) We proceed to K. I 17 23.5 G H 23.5 4) And finally M is selected. K 10 19.5 J 21 L M 0 11 N Note: Had we arrived at a dead end e.g. C, E, F, G, H, J, L, or N hillclimbing would be stuck. 13 of 14 3 Puzzle Revisited 14 of 14