2 Towers of HanoiSolve the problem by finding the appropriate state transitions from a start state to a goal state.A state is a configuration of discsA transition takes us from one state to another via a legal move
4 Towers of Hanoi Observations Moving the smallest discThe smallest disc can always be moved to two other polesIf the smallest disc was moved on the previous move, it does not make sense to move it again becauseOne choice is to move back to where it just was.The other choice was available on the previous moveConclusion: There is never a reason to move the smallest disc twice in a row.
5 Towers of Hanoi Observations (continued) Moving a disc other than the smallestThe disc holding the smallest disc is not a legal destination for a larger discThe largest top-level disc can not be moved, as both possible destinations contain smaller discsConclusion: If we aren’t moving the smallest disc, there is only one move choice.
6 Towers of Hanoi Optimization We will always have a choice of two destinations for the smallest disc, followed by a “forced” move of the smaller of the two other top-level discs.We can therefore reduce the possible transitions at any point to two.
8 The Eight PuzzleEight puzzle - one start state and one solution state.
9 Eight puzzle can also have state optimizations Change the goal-state:From to this: To this:1234567812345786
10 From each state there are 8 possible “corner twists.” Rotate clockwiseTop-left quadrantTop-right quadrantBottom-left quadrantBottom-right quadrantRotate counter-clockwise
11 Using state-transition graphs, many of these types of problems become be solved using graph search algorithms.You probably already know some graph-search algorithmsBreadth-first searchLook at all the possible solutions one move deep, before looking at any possible solutions two moves deep and so on.Depth-first searchTry a first move, then another move from that state. When you run out of moves, backtrack to the next available move.
12 Breadth-first Search Place the root node in a queue While a solution has not been foundRemove a state from the queueIf that state is not a solutionPlace all possible transitions from that state into the queue.Positive qualities: With enough resources, the algorithm will find a solution.Negative qualities: Memory requirements and processing times grow exponentially for every move depth where the branching factor is greater than 1.
13 Depth-first Search Depth-first-search(root) For every transition from the rootIf the state is not a solutionDepth-first-search(transition state)Positive qualities: Memory requirements do not grow exponentiallyNegative qualities: There is no guarantee that depth-first will find an answer, even if one exists.
14 Depth-First Search with Iterative Deepening Set the depth limit to 0While a solution is not foundPerform Depth-First Search to the depth limitIncrease the depth limit by 1This algorithm has positive qualities of breadth-first, without the exponential memory costs.
15 Heuristics-based Search Use a set of rules to evaluate the “quality” of a state. The quality of a state is usually an estimate of how close the state is to the solution.
16 Sample Heuristics For the 8-puzzle Compute the sum of the minimum number of moves needed to move each tile from its current position its destination
17 Manhattan Distance – sum of the minimum number of moves each tile must make to get to its destination position4 must move a minimum of 1 space1 must move a minimum of 1 space2 must move a minimum of 1 space8 must move a minimum of 1 space7 must move a minimum of 3 spaces6 must move a minimum of 3 spaces3 must move a minimum of 3 spaces5 must move a minimum of 2 spacesManhattan distance = = 15
18 Possible (naïve) Heuristic for Towers of Hanoi Number of discs in final position (i.e., on the third pole on top of disc that it is on top of in the solution) – the minimum number of moves to reach a complete solution.
19 Hill ClimbingMake any transition that gets you from your current state to a better state. Do not store any state other than your current state.The value of the state is typically created by a heuristicExamples:8-PuzzleMake any move that transitions to a state with a lower Manhattan distance.Lost in Hoan Kiem District:Turn onto a different street if it is larger than the street that you are on until you find something that you recognize.
20 Steepest Ascent Hill Climbing Look at all possible state transitions before selecting the one with the highest value.
21 Problems with Hill-climbing The heuristic may not be a good measure, or may not work in this instanceIt is easy to get to a “local maximum”You may not be climbing the highest hill in the search spaceThere is no mechanism for backtrackingIf you make a wrong turn you may not be able to recoverThere is no mechanism for detecting cycles
22 Problems with Hill Climbing (continued) Plateau ProblemAll transition states might have the same value as the current state.
23 Best-first SearchMaintain a list of nodes (the open list) that we can return to if we take a wrong pathMaintain a list of nodes that we no longer need to consider (the closed list)Best-first searchWhile a solution has not been foundRemove the node with the best heuristic value from the open list and place it on the closed listFor each child of that node, if the node is not already on the closed list, place it on the open list.
24 Beam-Search Expand the best k nodes on the open list Similar to breadth-first, but each level only has k nodes explored.
25 CompletenessA search algorithm is said to be complete if it is guaranteed to find a solution if a solution exists.
26 OptimalA search algorithm is said to be optimal if it is guaranteed to find the lowest-cost (best) solution.
27 Admissible HeuristicAn admissible heuristic is one that provides an estimate that is always less than or equal to the actual cost.Admissible heuristics allow us to know that we have found the best answer when the heuristic estimates from all nodes on the open list exceed the value of the current node.
28 MonotonicityA search algorithm is said to be monotonic if it is guaranteed to produce an optimal path to every intermediate node it generates.
29 Branch and Bound Create a priority queue sorted on lowest cost Insert root node into priority queueWhile a solution is not found or the queue contains nodes with a cost less then the solution foundRemove a node from the priority queueIf it is the best solution found so far, record itAdd all the children to the priority queueReturn the solution
30 Principal of Optimality Optimal paths are constructed from optimal subpathsIf we find a shorter alternate path to a node we can discard the longer path
31 Estimating the cost to a goal Let g(x) be the cost from the start state to node xLet h(x) be the cost from x to the goal stateThe total cost from start to finish, through node x is: f(x) = g(x) + h(x)We do not know h(x). So we create an estimate that we call h*(x)f*(x) = g*(x) + h*(x) is our estimate of f(x)
32 A* Algorithm Create a priority queue sorted on f*(x) Add the start node to the queueWhile a solution has not been foundRemove a node from the queueCompute f*(x) for all the nodes children (that have not already been encountered)Insert the node’s children into the queue
33 AssignmentUse the C++ code posted on the website to solve the 8-puzzle
34 Two-Player GamesDifferent search techniques are required to find solutions to two-player, move-based games.
35 Minimax TreesAlternate between choosing the maximum and minimum values of the child nodes.The “Value of the Game” can be computed using a bottom-up computation of the value of each parent node
36 Depth of Game-Trees Ideally, all the way to the bottom We can “solve” such gamesUse some fixed depth and then apply a “static evaluation function” that estimates the value of the game at that node.Use heuristics to determine a depth that is not necessarily uniforme.g., search to a quiescent state
37 Minimax with alpha-beta pruning If terminal node, return the value of the terminal nodeIf non-terminalFor each childScore = alpha-beta(child)If (Score > alpha) alpha
38 Two types of pruning Alpha cut-off Beta cut-off Happens during min-level analysisThe max player will not allow this to happen, so there is no point looking any furtherBeta cut-offHappens during max-level analysisThe min player will not allow this to happen, so there is no point looking any further
39 Homework AssignmentUse the letters in your full name to assign values for the 16 terminal nodes in a binary game tree (lower-case only).If you don’t have 16 letters in your name, just repeat your namej o h n q u e s m i t h j o h nThe first player wants to maximize the alphabetic value of the selected letterThe second player wants to minimize the alphabetic value of the selected letterDraw the minimax tree and annotate each node with the value of the subtreeShow which branches of the tree would be pruned through alpha-beta searchSpecify whether alpha or beta cutoff was used for each pruning