Homework 1 Sean Reynolds 3.7 Describe the Initial State (IS), Goal State (GS), Successor Function (SF) and Cost Function (CF) for each of the following problems. Coloring Regions: IS: no region is colored. GS: every region is colored and no adjacent region is the same color as its neighboring region. SF: for each region fill its color with each of the four possible colors and add each state to the Fringe as part of each node respectively. CF: associate a cost of 1 each time a region’s color is changed. Monkey Banana Room: IS: Monkey is in room but does not have any bananas. GS: Monkey has all bananas. SF: Monkey tries all available actions from the collection of actions {move chair, stack chair, climb chair, grab banana, move closer to chair, move chair closer to banana} until the goal state is found. CF: Each step costs 1 so the path cost is the number of in the steps in the path. Record Processing: IS: The Initial state is that no input records are processed. GS: The last input record gave an output of: Illegal Input Record Error. SF: Run each input record in the file and examine the output. CF: Each input record is associated with a cost of 1, but since there is relatively no search involved this is a linear algorithm. Water Jugs: IS: The initial state begins with three jugs which are all empty. GS: 1 jug has exactly 1 gallon of water in it. SF: Generate all the legal states {Fill Jug, Empty Jug Onto Ground, Empty Jug Into Another Jug} keeping track of the amount of water in each jug based on the exact sizes of each jug {12 gallons, 8 gallons, 3 gallons} CF: Every time an action is taken we associate a cost of 1, so the path cost is the number of Nodes in the solution path. Sean Reynolds: Homework 1 Page 1 3.8 Analyze the state space generated by an initial state of 1 and a successor function of n which returns two numbers: 2n and 2n + 1. A) Show the state space for states 1-15. 1 2 3 4 8 5 9 10 6 11 12 7 13 14 15 B) Show the order that nodes will be visited through this state space for the algorithms {Breadth first search, Depth limit search with limit of 3, and Iterative deepening search}. BFS) DLS [3]) IDS) 1 2 3 4 5 6 7 8 9 10 (11) 1 2 4 8 9 5 10 (11) 1 1 2 3 1 2 4 5 3 6 7 1 2 4 8 9 5 10 (11) C) Would Bidirectional search be appropriate for this problem? Describe in detail how it would work. Yes, bidirectional search could yield results much quicker for this type of problem. We would need to find a predicesor function which is the invers of the successor function. Because this is a tre search of integers and every number generated by the SF is an integer we need a predecessor function which also generates integers. The inverse of the results of the SF would be numbers ((n-1)/2) and (n/2). However some of these numbers may be fractions and we will need to discard all fractions because the state space only includes integers. An alternative is to use a Predecessor function which simply gives a value of FLOOR(n/2) where Floor takes the integer part of any fractions generated by the predecessor function when given a node of value n. D) What is the branching factor in each direction of the bidirectional search? Successor Function has a branching factor of 2. Predecessor Function has a branching factor of 1. Successor Function will have a fringe of: {[1], [1, 2, 3], [1, 2, 3, 4, 5, 6, 7]} Predecessor Function will have a fringe of: {[11], [11, 15], [11, 5, 2]} Sean Reynolds: Homework 1 Page 2 E) Does the anser to C) suggest a reformulation of the problem that would allow you to solve the problem of getting from state 1 to a given goal state with almost no search? Yes; by doing just the predecessor function, FLOOR(n/2), we only need to visit nodes which are in the path to the root from the goal state. Make the Initial state the Goal State and the Goal State the Initial State (Swap them). Change the Successor Function to the Predecessor Function Solve the problem in reverse. 3.13 Describe a state space in which Iterative Deepening search performs much worse than depth first search, for example O(n^2) vs. O(n). Goal state of F produces a solution in 3 nodes visited with DFS and the IDS Search produces a result in 12 nodes visited. A B C D E Goal State (F) G H I J K L M N O P Q R S T U Iterative Deepening search Nodes visited: {A, A, B, C, D, E, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U} Depth first search: {A, B, F, G, H, I, C, J, K, L, M, D, N, O, P, Q, E, R, S, T, U} Any state space where the branching factor b > depth of goal state d, and the solution path is on or near the left side of the tree at depth d. It is important to say that even when the Goal State is near the left most path at depth d, if the branching factor b is > d + (the distance to the left side) then the results will still be much better with DFS (around an order O(n) for DFS with an order around O(n^2) for IDS). Define: near as a distance n from the left most node at depth d. If b > n + d then the DFS with still outperform the IDS by roughly O(n) to O(n^2). Sean Reynolds: Homework 1 Page 3 4.6 Define a heuristic function for the 8puzzle that sometimes overestimates and show that it can lead to suboptimal solutions. Heuristic h defined by: add a cost of 2 for horizontal displacement to goal state for each tile out of place. Add a cost of 1 for every vertical displacement to goal state for each tile out of place. h overestimates the cost of moving 1 to the RIGHT so it moves 4 up instead; leading away from the Goal State. However after one iteration the g function adds the heuristic and the actual cost associated with the choice. A* then returns to the correct choice to move 1 into the correct spot. Sean Reynolds: Homework 1 Page 4 Prove that if h never overestimates by more than c, A* using h returns solutions who’s cost never exceeds the optimal solution by more than c. If h overestimates by c then optimality is only compromised by c. g(GS) – g(n) = h(n) – c Rephrase the problem to prove. h*(n) = h(n) – c Substitute for variables. h(n) – h*(n) = c value that h overestimated by When at branch node Nb of the correct path Nc given by huristic h(Nc) overstated by constant c, and the incorrect path Ni given by h(Ni) which is as accurate huristic equal to h*(Ni). When you take branch Ni it costs 1 extra unit of the CF and you will continue down that incorrect branch until the extra units of the CF make g(Ni_) +h(Ni_) > g(Nb) + h(Nc) 4.7 Prove that if a heuristic is constant, it must be admissible. h(n) <= c(n, n’) + h(n’) h(n) <= c(n, n’) + c(n’, n’’) + h(n’’) h(n) <= c(n, n’) + c(n’, n’’) + c(n’’, n’’’) + h(n’’’) … h(n) <= h*(n) definition: of constant heuristic definition: of constant heuristic Keep expanding the heuristic by its definition. Until you get to the goal state h Is admissible by definition: h(n) <= h*(n) Construct an admissible heuristic that is not constant. Admissible means that the heuristic h never tells the function that you are farther from the Goal State than you really are. (really are h*(n)) Constant means that the heuristic h never increases as you approach the Goal State. An example of an admissible heuristic that is not constant would be a heuristic t which gives all initial moves from the IS Node a value of 0; then all other moves a heuristic value of straight line distance to the GS. Sean Reynolds: Homework 1 Page 5