Abstract: The following questions and exercises are from chapter 3, Informed Search. This chapter covers the use of heuristics in search and how to evaluate the effectiveness of heuristics and search algorithms. Various algorithms are covered as well. It starts with hill climbing, best first search, and beam search. These algorithms are all similar in that they are forward looking, determining the best path based only on an estimation of the distance remaining to their goal. Branch and bound algorithms are covered next as well as the A* algorithms which are backward looking in that they keep track of and make use of the distance traveled to determine the best path to their goal. Finally constraint satisfaction search, using constraints to break a problem into multiple smaller problems, and bidirectional search, searching from both ends until you meet in the middle, are covered. uestions: 2. Explain why hill climbing would be classified as a greedy algorithm. Hill climbing is a greedy algorithm because the next move is governed by a single measurement. It also does not track past moves or have an ability to recover from bad moves. 4. Why is it that the best first search is more effective than hill climbing? It is more effective because it keeps a list of open nodes that are on the fringe of the search and that can be later explored if needed. So if the search heads down a path that ends up being bad then the algorithm can backtrack to previous nodes in order to find an alternate path. 5. Explain how beam search works. Beam search is a modification to breadth first search. It works the same way as breadth first search but adds some heuristics in order to limit the breadth of the search to a specific width for each level of the search. For example, if the beam width is 2 then the search will only follow the 2 best options at each level of the search. An infinite beam width would be the same as a breadth first search.
7. What does it mean for a heuristic to be more informed than another heuristic? When one heuristic is more informed than another it means that that heuristic saves us more effort in finding our goal than the other heuristic. For example it could allow us to solve a puzzle in fewer moves than another heuristic. 8. What is the idea behind branch and bound search? The idea behind branch and bound search is that the distance traveled is tracked and the shortest complete path so far is the one taken. As the search progresses if the current path becomes longer than a previous path, it can be abandoned while a previous and now shorter path is followed. It continues to expand only what is needed to know that it is currently still on the most optimal path. Exercises: 2. Explain why hill climbing is called a greedy algorithm. Hill climbing, at every step that it needs to make a choice will take the first path that is better than the current path. It also does not track past moves or have an ability to recover from bad moves. a. Describe some other algorithms that you know that are greedy. Dijkstra s shortest path algorithm is an example of a greedy algorithm. It always takes the shortest path found between two nodes until it reaches its destination. b. Explain how steepest ascent hill climbing is an improvement over simple hill climbing. Steepest ascent hill climbing is an improvement because it allows all successor nodes to be evaluated to see which is best rather than just taking the first one that is better. c. How does the best first search improve over hill climbing? Best first search maintains a list of open nodes that it can use to backtrack to a previous path that may be better than the current path. This allows it to recover from bad choices that end up not being fruitful.
3. Suggest an admissible heuristic, not mentioned in the text, for solving the 3 puzzle. An admissible heuristic would be to average the tiles out of place heuristic with the total manhattan distance heuristic. a. Employ your heuristic to conduct an A* search to solve the instance of the puzzle presented in this chapter. b. Is your heuristic more of less informed than the two heuristics that are presented?
Given that it is the average of the 2 heuristics and given that the manhattan distance is more informed than the number of tiles out of place, this heuristic is in general more informed than the number of tiles out of place and less informed than the total manhattan distance. 6. Consider the following variation of the n ueens Problem: If some of the squares that would be attacked by the placement are obstructed by the placement of pawns on an n x n chessboard, can more than n ueens be placed on the partial board that remains? For example, if file pawns are added to a 3 x 3 chessboard, then four nonattacking ueens may be placed on the board (Figure 3.30). P P P P P For ueens on a 3 x 3 Chessboard with five Pawns strategically placed. How many nonattacking ueens may be placed on a 5 x 5 chessboard if one has 3 Pawns at one s disposal? There are a couple of different ways in which to look at this problem. If we are allowed to flood the board with Pawns similar to the 3 x 3 example then we can always fit ceil(n/2) 2 ueens on the board using the same pattern. If we must take a valid solution and try and add more queens to it then we can do so if the solution has 4 squares open in a corner. This will not be possible for all solutions but it is possible for some. For example,
P P P 7. Use both the plain vanilla branch and bound, and branch and bound with dynamic programming, to get from the start node (S) to the goal node (G) in parts (a) and (b) of Figure 3.31. When all else is equal, explore nodes in alphabetical order. Note: The graph for part a in the book lacks a value for the path between E and F, so a value of 1 was assumed. Note: The boxes illustrating the steps in the traversal diagram highlight the nodes revealed in that step, the common parent of those nodes is the node that was opened in that step. a) Plain Vanilla Branch and Bound
Step 1: We expand our start node S to find nodes B and C. Step 2: Node B is at the top of our list since it has the lowest cost, we expand it to find nodes A and D. Step 3: Node A has the lowest overall cost of 2 so we expand it to find node D. Step 4: Node D has an overall cost of 3 which is more than the previously seen node C, so we expand node C to find nodes E and F. Step 5: Nodes E and F both have an overall cost of 6 which is more than the 3 we hav previously seen with node D. We expand node D to find node C. Step 6: C, with a cost of 4, is still our lowest costing path. We expand C to find nodes E and F. Step 7: Node D with a cost of 5 is now our lowest costing path so we expand it to reveal node C. Step 8: The just revealed node C is tied for lowest costing path with E and F at 6. C is taken first and expanded to reveal nodes E and F. Step 9: E at a cost of 6 is now our best path, we expand it to reveal node F. Step 10: F at a cost of 6 is now our best path, we expand it to reveal node G. This is our goal node but there still exists paths that have a cost that is less than that if G at 11 so they must be expanded until we can see that they cost more or that they yield a better result. Step 11: F at 7 is expanded to reveal G with a cost of 12. This is more than our curren best goal of G with a cost of 12 so we can abandon this path. Step 12: E with a cost of 8 is now expanded to reveal F with a cost of 9. Step 13: F with a cost of 8 is now expanded to reveal G with a cost of 13. This is more than our current best cost of 11 so this branch can be abandoned. Step 14: F with a cost of 9 is now expanded to reveal G with a cost of 14. This is more than our current best cost of 11 so this branch can be abandoned. Step 15: E with a cost of 10 is now expanded to reveal F with a cost of 11. Step 16: F with a cost of 10 is now expanded to reveal G with a cost of 12. This is more than our current best cost of 11 so this branch can be abandoned. Step 17: F with a cost of 11 is the same as our best path of G at 11 but since F needs to be evaluated before G we expand it to reveal G with a cost of 16. This branch can
now be abandoned. All paths have now been evaluated to a point where they either terminate or cost more than our best path to G with a cost of 11. The goal node was found in step 10 with an optimal cost of 11. a) Branch and Bound with Dynamic Programming Step 1: We expand our start node S to find nodes B and C.
Step 2: Node B is at the top of our list since it has the lowest cost, we expand it to find nodes A and D. Step 3: Node A has the lowest overall cost of 2 so we expand it to find node D again. This path to D has an overall cost of 3 versus the previous path to D which had an overall cost of 5 so we abandon the previous path to D. Step 4: Node D has an overall cost of 3 which is more than the previously seen node C, so we expand node C to find nodes E and F. Step 5: Nodes E and F both have an overall cost of 6 which is more than the 3 we hav previously seen with node D. We expand node D to find node C again and reach the end of this subtree since we already have a shorter path to C. Step 6: Nodes E and F have the same overall cost and so we break the tie using alphabetical order. We expand node E to find node F again. Step 7: We continue back from our previous F since it was the shorter path and expand it to find node G. Node G is our goal with an overall cost of 11. The goal node was found in step 7 with an optimal cost of 11. b) Plain Vanilla Branch and Bound
Step 1: We expand node S to reveal nodes A and C.
Step 2: A and C have the same cost so we expand A to reveal B and C. Step 3: C has the lowest cost so we it to reveal B and D. Step 4: B is opened to reveal E. Step 5: B is opened again to reveal E. Step 6: C is opened again to reveal B and D. Step 7: B is opened again to reveal E. Step 8: D is opened to reveal E again and our goal node G. Step 9: E is opened to reveal C again. Step 10: E is opened again to reveal C again. Step 11: C is opened again to reveal B and D again. The cost to D is higher than the cost to our goal node so D will not be followed any further. Step 12: C is opened again to reveal B and D again. Step 13: D is opened to reveal E again and our goal node G. The cost of this path to G is higher than the previous path to G. Step 14: E is opened again to reveal C again. Step 15: E is opened again to reveal C again. Step 16: B is opened again to reveal E again. The cost to E is higher than the cost to our goal node so E will not be followed any further. Step 17: B is opened again to reveal E again. The cost to E is higher than the cost to our goal node so E will not be followed any further. Step 18: C is opened again to reveal B and D again. The cost to D is higher than the cost to our goal node so D will not be followed any further. Step 19: C is opened again to reveal B and D again. The cost to D is higher than the cost to our goal node so D will not be followed any further. Step 20: E is opened to reveal C again. Step 21: B is opened again to reveal E again. The cost to E is higher than the cost to our goal node so E will not be followed any further.
Step 22: B is opened again to reveal E again. The cost to E is higher than the cost to our goal node so E will not be followed any further. Step 23: C is opened again to reveal B and D again. The cost to both B and D is highe than the cost to our goal node so neither node will not be followed any further. The goal node was found in step 8 with a optimal cost of 9. b) Branch and Bound with Dynamic Programming Step 1: We expand node S to reveal nodes A and C.
Step 2: A and C have the same cost so we expand A to reveal B and C. C has already been seen at a lower cost so we will not be following it again. Step 3: C has the lowest cost so we it to reveal B and D. B has already been seen at an equal value so we will not be following it again. Step 4: B has the lowest cost so we expand it to reveal 3. Step 5: D is tied with E but is opened first because ties are broken alphabetically. E and G are revealed. E has already been encountered at a lower cost. G is our goal node and was found with a cost of 9. Step 6: E is next to be evaluated since it still has a lower cost than our goal. C is revealed, since we have seen it before at a lower cost it ends our traversal. The goal node was found in step 5 with a optimal cost of 9. 9. Suggest an admissible heuristic for the Water Jug Problem. If the cost is equal to the amount of water moved then an admissible heuristic could be the absolute value of the goal subtracted from the value of the jug that can hold the goal. This is admissible because it is always less than or equal to the cost to the solution. a. Employ your heuristic to conduct an A* search to solve the instance of this problem presented in Chapter 1. h(n) = x 12 where x is the number of quarts of water in the 18 qt jug. f(n) = the number of quarts of water that have been moved. The possible moves at each step are filling the large container from the well (WA), filling the small container from the well (WB), pouring the large container into the small container (AB), pouring the small container into the large container (BA), dumping the large container into the well (AW), dumping the small container into the well (BW). The solution is found on step 17 and there are no competing paths that need to be evaluated.