1 / 8

Backtracking

Backtracking. Introduction. Systematic way to do an exhaustive search Take advantage of pruning when possible. Turnpike Reconstruction Problem. Given |D| distances, determine x coordinates for points lying on x-axis |D|=N(N-1)/2

sandra_john
Download Presentation

Backtracking

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Backtracking

  2. Introduction • Systematic way to do an exhaustive search • Take advantage of pruning when possible

  3. Turnpike Reconstruction Problem • Given |D| distances, determine x coordinates for points lying on x-axis • |D|=N(N-1)/2 • Easy to go from points to distances in O(N2) – distances to points is worst-case exponential

  4. Turnpike Reconstruction Problem • N = 6 • Should largest distance be placed on left or right side? • if 1 only, place • if both, choose 1 – if it does not lead to a solution, try the other • if neither, no solution to current configuration – backtrack x1 = 0 x6 = 10 D = {1, 2, 2, 2, 3, 3, 3, 4, 5, 5, 5, 6, 7, 8, 10}

  5. Turnpike Reconstruction Problem x1 = 0 x6 = 10 D = {1, 2, 2, 2, 3, 3, 3, 4, 5, 5, 5, 6, 7, 8, 10} x1=0 x6=10 x5=8 x4=7 x2=3 x3=6 x2=4 x3=4 x4=6 x3=5

  6. TicTacToe • Idea: for each possible move, determine outcome assuming player and computer will choose optimal subsequent moves • http://www.ocf.berkeley.edu/~yosenl/extras/alphabeta/alphabeta.html • Minimax strategy – human win = -1 and computer win = 1 – human tries to minimize value of play while computer tries to maximize value of play

  7. findCompMove if(full) value = DRAW else if comp wins value = COMP_WIN else value = COMP_LOSS bestMove = 1 for (i 1->n) if empty place rval= findHumanMove unplace if rval > value value = rval bestMove = i findHumanMove if(full) value = DRAW else if comp wins value = COMP_LOSS else value = COMP_WIN bestMove = 1 for (i 1->n) if empty place rval= findCompMove unplace if rval < value value = rval bestMove = i TicTacToe

  8. Game Tree • Levels alternate min/max • If solution is obvious – prune • Example • 44 (max) • 44 (min) • 44 (max) • 27 • 44 • 68 • 68 • C • 40

More Related