search in ai. towers of hanoi solve the problem by finding the appropriate state transitions from a...
TRANSCRIPT
![Page 1: Search in AI. Towers of Hanoi Solve the problem by finding the appropriate state transitions from a start state to a goal state. A state is a configuration](https://reader030.vdocuments.mx/reader030/viewer/2022032702/56649ccf5503460f9499b72a/html5/thumbnails/1.jpg)
Search in AI
![Page 2: Search in AI. Towers of Hanoi Solve the problem by finding the appropriate state transitions from a start state to a goal state. A state is a configuration](https://reader030.vdocuments.mx/reader030/viewer/2022032702/56649ccf5503460f9499b72a/html5/thumbnails/2.jpg)
Towers of Hanoi Solve the problem by finding the appropriate
state transitions from a start state to a goal state. A state is a configuration of discs A transition takes us from one state to another via a
legal move
![Page 3: Search in AI. Towers of Hanoi Solve the problem by finding the appropriate state transitions from a start state to a goal state. A state is a configuration](https://reader030.vdocuments.mx/reader030/viewer/2022032702/56649ccf5503460f9499b72a/html5/thumbnails/3.jpg)
![Page 4: Search in AI. Towers of Hanoi Solve the problem by finding the appropriate state transitions from a start state to a goal state. A state is a configuration](https://reader030.vdocuments.mx/reader030/viewer/2022032702/56649ccf5503460f9499b72a/html5/thumbnails/4.jpg)
Towers of Hanoi Observations
Moving the smallest disc The smallest disc can always be moved to two
other poles If the smallest disc was moved on the previous
move, it does not make sense to move it again because One choice is to move back to where it just was. The other choice was available on the previous
move Conclusion: There is never a reason to
move the smallest disc twice in a row.
![Page 5: Search in AI. Towers of Hanoi Solve the problem by finding the appropriate state transitions from a start state to a goal state. A state is a configuration](https://reader030.vdocuments.mx/reader030/viewer/2022032702/56649ccf5503460f9499b72a/html5/thumbnails/5.jpg)
Towers of Hanoi Observations (continued)
Moving a disc other than the smallest The disc holding the smallest disc is not a
legal destination for a larger disc The largest top-level disc can not be
moved, as both possible destinations contain smaller discs
Conclusion: If we aren’t moving the smallest disc, there is only one move choice.
![Page 6: Search in AI. Towers of Hanoi Solve the problem by finding the appropriate state transitions from a start state to a goal state. A state is a configuration](https://reader030.vdocuments.mx/reader030/viewer/2022032702/56649ccf5503460f9499b72a/html5/thumbnails/6.jpg)
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.
![Page 7: Search in AI. Towers of Hanoi Solve the problem by finding the appropriate state transitions from a start state to a goal state. A state is a configuration](https://reader030.vdocuments.mx/reader030/viewer/2022032702/56649ccf5503460f9499b72a/html5/thumbnails/7.jpg)
![Page 8: Search in AI. Towers of Hanoi Solve the problem by finding the appropriate state transitions from a start state to a goal state. A state is a configuration](https://reader030.vdocuments.mx/reader030/viewer/2022032702/56649ccf5503460f9499b72a/html5/thumbnails/8.jpg)
The Eight Puzzle
Eight puzzle - one start state and one solution state.
![Page 9: Search in AI. Towers of Hanoi Solve the problem by finding the appropriate state transitions from a start state to a goal state. A state is a configuration](https://reader030.vdocuments.mx/reader030/viewer/2022032702/56649ccf5503460f9499b72a/html5/thumbnails/9.jpg)
Eight puzzle can also have state optimizations Change the goal-state:From to this: To this:
1 2 3
4 5 6
7 8
1 2 3
4 5
7 8 6
![Page 10: Search in AI. Towers of Hanoi Solve the problem by finding the appropriate state transitions from a start state to a goal state. A state is a configuration](https://reader030.vdocuments.mx/reader030/viewer/2022032702/56649ccf5503460f9499b72a/html5/thumbnails/10.jpg)
From each state there are 8 possible “corner twists.”
Rotate clockwise Top-left quadrant Top-right quadrant Bottom-left quadrant Bottom-right quadrant
Rotate counter-clockwise Top-left quadrant Top-right quadrant Bottom-left quadrant Bottom-right quadrant
![Page 11: Search in AI. Towers of Hanoi Solve the problem by finding the appropriate state transitions from a start state to a goal state. A state is a configuration](https://reader030.vdocuments.mx/reader030/viewer/2022032702/56649ccf5503460f9499b72a/html5/thumbnails/11.jpg)
Using state-transition graphs, many of these types of problems become be solved using graph search algorithms.
You probably already know some graph-search algorithms Breadth-first search
Look at all the possible solutions one move deep, before looking at any possible solutions two moves deep and so on.
Depth-first search Try a first move, then another move from
that state. When you run out of moves, backtrack to the next available move.
![Page 12: Search in AI. Towers of Hanoi Solve the problem by finding the appropriate state transitions from a start state to a goal state. A state is a configuration](https://reader030.vdocuments.mx/reader030/viewer/2022032702/56649ccf5503460f9499b72a/html5/thumbnails/12.jpg)
Breadth-first Search Place the root node in a queue While a solution has not been found
Remove a state from the queue If that state is not a solution
Place 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.
![Page 13: Search in AI. Towers of Hanoi Solve the problem by finding the appropriate state transitions from a start state to a goal state. A state is a configuration](https://reader030.vdocuments.mx/reader030/viewer/2022032702/56649ccf5503460f9499b72a/html5/thumbnails/13.jpg)
Depth-first Search Depth-first-search(root)
For every transition from the root If the state is not a solution
Depth-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.
![Page 14: Search in AI. Towers of Hanoi Solve the problem by finding the appropriate state transitions from a start state to a goal state. A state is a configuration](https://reader030.vdocuments.mx/reader030/viewer/2022032702/56649ccf5503460f9499b72a/html5/thumbnails/14.jpg)
Depth-First Search with Iterative Deepening Set the depth limit to 0 While a solution is not found
Perform Depth-First Search to the depth limit
Increase the depth limit by 1
This algorithm has positive qualities of breadth-first, without the exponential memory costs.
![Page 15: Search in AI. Towers of Hanoi Solve the problem by finding the appropriate state transitions from a start state to a goal state. A state is a configuration](https://reader030.vdocuments.mx/reader030/viewer/2022032702/56649ccf5503460f9499b72a/html5/thumbnails/15.jpg)
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.
![Page 16: Search in AI. Towers of Hanoi Solve the problem by finding the appropriate state transitions from a start state to a goal state. A state is a configuration](https://reader030.vdocuments.mx/reader030/viewer/2022032702/56649ccf5503460f9499b72a/html5/thumbnails/16.jpg)
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
![Page 17: Search in AI. Towers of Hanoi Solve the problem by finding the appropriate state transitions from a start state to a goal state. A state is a configuration](https://reader030.vdocuments.mx/reader030/viewer/2022032702/56649ccf5503460f9499b72a/html5/thumbnails/17.jpg)
Manhattan Distance – sum of the minimum number of moves each tile must make to get to its destination position
4 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 = 1 + 1 + 1 +1 + 3 + 3 + 3 + 2 = 15
![Page 18: Search in AI. Towers of Hanoi Solve the problem by finding the appropriate state transitions from a start state to a goal state. A state is a configuration](https://reader030.vdocuments.mx/reader030/viewer/2022032702/56649ccf5503460f9499b72a/html5/thumbnails/18.jpg)
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.
![Page 19: Search in AI. Towers of Hanoi Solve the problem by finding the appropriate state transitions from a start state to a goal state. A state is a configuration](https://reader030.vdocuments.mx/reader030/viewer/2022032702/56649ccf5503460f9499b72a/html5/thumbnails/19.jpg)
Hill Climbing Make 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 heuristic
Examples: 8-Puzzle
Make 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.
![Page 20: Search in AI. Towers of Hanoi Solve the problem by finding the appropriate state transitions from a start state to a goal state. A state is a configuration](https://reader030.vdocuments.mx/reader030/viewer/2022032702/56649ccf5503460f9499b72a/html5/thumbnails/20.jpg)
Steepest Ascent Hill Climbing Look at all possible state transitions
before selecting the one with the highest value.
![Page 21: Search in AI. Towers of Hanoi Solve the problem by finding the appropriate state transitions from a start state to a goal state. A state is a configuration](https://reader030.vdocuments.mx/reader030/viewer/2022032702/56649ccf5503460f9499b72a/html5/thumbnails/21.jpg)
Problems with Hill-climbing The heuristic may not be a good measure,
or may not work in this instance It is easy to get to a “local maximum”
You may not be climbing the highest hill in the search space
There is no mechanism for backtracking If you make a wrong turn you may not be
able to recover There is no mechanism for detecting cycles
![Page 22: Search in AI. Towers of Hanoi Solve the problem by finding the appropriate state transitions from a start state to a goal state. A state is a configuration](https://reader030.vdocuments.mx/reader030/viewer/2022032702/56649ccf5503460f9499b72a/html5/thumbnails/22.jpg)
Problems with Hill Climbing (continued) Plateau Problem
All transition states might have the same value as the current state.
![Page 23: Search in AI. Towers of Hanoi Solve the problem by finding the appropriate state transitions from a start state to a goal state. A state is a configuration](https://reader030.vdocuments.mx/reader030/viewer/2022032702/56649ccf5503460f9499b72a/html5/thumbnails/23.jpg)
Best-first Search Maintain a list of nodes (the open list) that
we can return to if we take a wrong path Maintain a list of nodes that we no longer
need to consider (the closed list) Best-first search
While a solution has not been found Remove the node with the best heuristic value
from the open list and place it on the closed list For each child of that node, if the node is not
already on the closed list, place it on the open list.
![Page 24: Search in AI. Towers of Hanoi Solve the problem by finding the appropriate state transitions from a start state to a goal state. A state is a configuration](https://reader030.vdocuments.mx/reader030/viewer/2022032702/56649ccf5503460f9499b72a/html5/thumbnails/24.jpg)
Beam-Search Expand the best k nodes on the open
list Similar to breadth-first, but each level
only has k nodes explored.
![Page 25: Search in AI. Towers of Hanoi Solve the problem by finding the appropriate state transitions from a start state to a goal state. A state is a configuration](https://reader030.vdocuments.mx/reader030/viewer/2022032702/56649ccf5503460f9499b72a/html5/thumbnails/25.jpg)
Completeness A search algorithm is said to be
complete if it is guaranteed to find a solution if a solution exists.
![Page 26: Search in AI. Towers of Hanoi Solve the problem by finding the appropriate state transitions from a start state to a goal state. A state is a configuration](https://reader030.vdocuments.mx/reader030/viewer/2022032702/56649ccf5503460f9499b72a/html5/thumbnails/26.jpg)
Optimal A search algorithm is said to be optimal
if it is guaranteed to find the lowest-cost (best) solution.
![Page 27: Search in AI. Towers of Hanoi Solve the problem by finding the appropriate state transitions from a start state to a goal state. A state is a configuration](https://reader030.vdocuments.mx/reader030/viewer/2022032702/56649ccf5503460f9499b72a/html5/thumbnails/27.jpg)
Admissible Heuristic An 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.
![Page 28: Search in AI. Towers of Hanoi Solve the problem by finding the appropriate state transitions from a start state to a goal state. A state is a configuration](https://reader030.vdocuments.mx/reader030/viewer/2022032702/56649ccf5503460f9499b72a/html5/thumbnails/28.jpg)
Monotonicity A search algorithm is said to be
monotonic if it is guaranteed to produce an optimal path to every intermediate node it generates.
![Page 29: Search in AI. Towers of Hanoi Solve the problem by finding the appropriate state transitions from a start state to a goal state. A state is a configuration](https://reader030.vdocuments.mx/reader030/viewer/2022032702/56649ccf5503460f9499b72a/html5/thumbnails/29.jpg)
Branch and Bound Create a priority queue sorted on lowest cost Insert root node into priority queue While a solution is not found or the queue
contains nodes with a cost less then the solution found Remove a node from the priority queue If it is the best solution found so far, record it Add all the children to the priority queue
Return the solution
![Page 30: Search in AI. Towers of Hanoi Solve the problem by finding the appropriate state transitions from a start state to a goal state. A state is a configuration](https://reader030.vdocuments.mx/reader030/viewer/2022032702/56649ccf5503460f9499b72a/html5/thumbnails/30.jpg)
Principal of Optimality Optimal paths are constructed from
optimal subpaths If we find a shorter alternate path to a
node we can discard the longer path
![Page 31: Search in AI. Towers of Hanoi Solve the problem by finding the appropriate state transitions from a start state to a goal state. A state is a configuration](https://reader030.vdocuments.mx/reader030/viewer/2022032702/56649ccf5503460f9499b72a/html5/thumbnails/31.jpg)
Estimating the cost to a goal Let g(x) be the cost from the start state to
node x Let h(x) be the cost from x to the goal state The 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)
![Page 32: Search in AI. Towers of Hanoi Solve the problem by finding the appropriate state transitions from a start state to a goal state. A state is a configuration](https://reader030.vdocuments.mx/reader030/viewer/2022032702/56649ccf5503460f9499b72a/html5/thumbnails/32.jpg)
A* Algorithm Create a priority queue sorted on f*(x) Add the start node to the queue While a solution has not been found
Remove a node from the queue Compute f*(x) for all the nodes children
(that have not already been encountered) Insert the node’s children into the queue
![Page 33: Search in AI. Towers of Hanoi Solve the problem by finding the appropriate state transitions from a start state to a goal state. A state is a configuration](https://reader030.vdocuments.mx/reader030/viewer/2022032702/56649ccf5503460f9499b72a/html5/thumbnails/33.jpg)
Assignment Use the C++ code posted on the
website to solve the 8-puzzle
![Page 34: Search in AI. Towers of Hanoi Solve the problem by finding the appropriate state transitions from a start state to a goal state. A state is a configuration](https://reader030.vdocuments.mx/reader030/viewer/2022032702/56649ccf5503460f9499b72a/html5/thumbnails/34.jpg)
Two-Player Games Different search techniques are required
to find solutions to two-player, move-based games.
![Page 35: Search in AI. Towers of Hanoi Solve the problem by finding the appropriate state transitions from a start state to a goal state. A state is a configuration](https://reader030.vdocuments.mx/reader030/viewer/2022032702/56649ccf5503460f9499b72a/html5/thumbnails/35.jpg)
Minimax Trees Alternate 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
![Page 36: Search in AI. Towers of Hanoi Solve the problem by finding the appropriate state transitions from a start state to a goal state. A state is a configuration](https://reader030.vdocuments.mx/reader030/viewer/2022032702/56649ccf5503460f9499b72a/html5/thumbnails/36.jpg)
Depth of Game-Trees Ideally, all the way to the bottom
We can “solve” such games Use 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 uniform e.g., search to a quiescent state
![Page 37: Search in AI. Towers of Hanoi Solve the problem by finding the appropriate state transitions from a start state to a goal state. A state is a configuration](https://reader030.vdocuments.mx/reader030/viewer/2022032702/56649ccf5503460f9499b72a/html5/thumbnails/37.jpg)
Minimax with alpha-beta pruning If terminal node, return the value of the
terminal node If non-terminal
For each child Score = alpha-beta(child) If (Score > alpha) alpha
![Page 38: Search in AI. Towers of Hanoi Solve the problem by finding the appropriate state transitions from a start state to a goal state. A state is a configuration](https://reader030.vdocuments.mx/reader030/viewer/2022032702/56649ccf5503460f9499b72a/html5/thumbnails/38.jpg)
Two types of pruning Alpha cut-off
Happens during min-level analysis The max player will not allow this to
happen, so there is no point looking any further
Beta cut-off Happens during max-level analysis The min player will not allow this to happen,
so there is no point looking any further
![Page 39: Search in AI. Towers of Hanoi Solve the problem by finding the appropriate state transitions from a start state to a goal state. A state is a configuration](https://reader030.vdocuments.mx/reader030/viewer/2022032702/56649ccf5503460f9499b72a/html5/thumbnails/39.jpg)
Homework Assignment Use 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
name j o h n q u e s m i t h j o h n
The first player wants to maximize the alphabetic value of the selected letter
The second player wants to minimize the alphabetic value of the selected letter
Draw the minimax tree and annotate each node with the value of the subtree
Show which branches of the tree would be pruned through alpha-beta search Specify whether alpha or beta cutoff was used for each
pruning