a star algorithm
play

A-Star Algorithm & Heaps/Priority Queues Mark Redekopp 2 A* - PowerPoint PPT Presentation

1 EE 355 Unit 14 A-Star Algorithm & Heaps/Priority Queues Mark Redekopp 2 A* Search Algorithm ALGORITHM HIGHLIGHT 3 Search Methods Many systems require searching for goal states Path Planning Roomba Vacuum


  1. 1 EE 355 Unit 14 A-Star Algorithm & Heaps/Priority Queues Mark Redekopp

  2. 2 A* Search Algorithm ALGORITHM HIGHLIGHT

  3. 3 Search Methods • Many systems require searching for goal states – Path Planning • Roomba Vacuum • Mapquest/Google Maps • Games!! – Optimization Problems • Find the optimal solution to a problem with many constraints

  4. 4 Search Applied to 8-Tile Game • 8-Tile Puzzle – 3x3 grid with one blank space – With a series of moves, get the tiles in sequential order – Goal state: 1 2 1 2 3 3 4 5 4 5 6 6 7 8 7 8 HW6 Goal State Goal State for these slides

  5. 5 Search Methods • Brute-Force Search : When you don’t know where the answer is, just search all possibilities until you find it. • Heuristic Search : A heuristic is a “rule of thumb”. An example is in a chess game, to decide which move to make, count the values of the pieces left for your opponent. Use that value to “score” the possible moves you can make. – Heuristics are not perfect measures, they are quick computations to give an approximation (e.g. may not take into account “delayed gratification” or “setting up an opponent”)

  6. 6 Brute Force Search • Brute Force Search 1 2 Tree 4 8 3 W 7 6 5 S – Generate all 1 2 1 2 3 4 8 3 4 8 possible moves 7 6 5 7 6 5 W E S – Explore each move 1 2 1 2 3 1 2 3 1 2 1 8 2 1 2 4 8 3 4 8 4 8 5 4 8 3 4 3 4 8 3 despite its 7 6 5 7 6 5 7 6 7 6 5 7 6 5 7 6 5 proximity to the 1 2 3 4 8 5 goal node 7 6 1 2 3 4 5 7 8 6

  7. 7 Heuristics • Heuristics are “scores” of how close a state is to the goal (usually, lower = better) • These scores must be easy to compute 1 8 3 (i.e. simpler than solving the problem) 4 5 6 • Heuristics can usually be developed by simplifying 2 7 the constraints on a problem # of Tiles out of Place = 3 • Heuristics for 8-tile puzzle – # of tiles out of place • Simplified problem: If we could just pick a tile up and put it 1 8 3 in its correct place 4 5 6 – Total x-, y- distance of each tile from its correct location (Manhattan distance) 2 7 • Simplified problem if tiles could stack on top of each other / Total x-/y- distance = 6 hop over each other

  8. 8 Heuristic Search • Heuristic Search Tree 1 2 H=6 – Use total x-/y- 4 8 3 7 6 5 distance (Manhattan H=7 H=5 1 2 1 2 3 4 8 3 4 8 distance) heuristic 7 6 5 7 6 5 – Explore the lowest H=6 H=6 H=4 1 2 1 2 3 1 2 3 4 8 3 4 8 4 8 5 scored states 7 6 5 7 6 5 7 6 H=5 H=3 1 2 3 1 2 3 4 8 4 8 5 7 6 5 7 6 H=2 1 2 3 4 5 7 8 6 H=1 1 2 3 4 5 7 8 6 Goal 1 2 3 4 5 6 7 8

  9. 9 Caution About Heuristics • Heuristics are just estimates and Start thus could be wrong H=2 H=1 • Sometimes pursuing lowest H=1 H=1 heuristic score leads to a less-than optimal solution or even no Goal H=1 solution H=1 • Solution H=1 – Take # of moves from start (depth) H=1 into account …

  10. 10 A-star Algorithm • Use a new metric to decide which state to explore/expand Start • Define g=1,h=2 g=1,h=1 f=3 f=2 – h = heuristic score (same as g=2,h=1 g=2,h=1 always) f=3 f=3 – g = number of moves from start it g=3,h=1 Goal f=4 took to get to current state – f = g + h • As we explore states and their successors, assign each state its f-score and always explore the state with lowest f-score

  11. 11 A-Star Algorithm • Maintain 2 lists – Open list = Nodes to be explored Start (chosen from) g=1,h=2 g=1,h=1 – Closed list = Nodes already explored f=3 f=2 (already chosen) g=2,h=1 g=2,h=1 f=3 f=3 • Pseudocode g=3,h=1 Goal f=4 open_list.push(Start State) while(open_list is not empty) 1. s ← remove min. f-value state from open_list (if tie in f-values, select one w/ larger g-value) 2. Add s to closed list 3a. if s = goal node then trace path back to start; STOP! 3b. Generate successors/neighbors of s, compute their f values, and add them to open_list if they are not in the closed_list (so we don’t re -explore), or if they are already in the open list, update them if they have a smaller f value

  12. 12 Data Structures & Ordering • We’ve seen some abstract data 0 1 2 3 4 structures original heap 46 21 78 35 67 – Queue (first-in, first-out access order) remove_min 46 78 35 67 = 21 • Deque works nicely remove_min 46 78 67 • There are others… = 35 – Stack (last-in, first-out access order) • Vector push_back / pop_back – Trees • A new one…priority queues (heaps) – Order of access depends on value – Items arrive in some arbitrary order – When removing an item, we always want the minimum or maximum valued item – To implement efficiently use heap data structure

  13. 13 Path-Planning w/ A* Algorithm • Find optimal path from S to G using A* – Use heuristic of Manhattan (x-/y-) distance **If implementing this for a programming assignment, please see the slide at the end about alternate closed-list implementation open_list.push(Start State) while(open_list is not empty) 1. s ← remove min. f -value state from Closed List open_list (if tie in f-values, select one w/ larger g-value) 2. Add s to closed list Open List 3a. if s = goal node then S trace path back to start; STOP! 3b. else Generate successors/neighbors of s, compute their f-values, and add them to open_list if they are not in the closed_list (so we don’t re -explore), or if they are already in the open list, update them if G they have a smaller f value

  14. 14 Path-Planning w/ A* Algorithm • Find optimal path from S to G using A* – Use heuristic of Manhattan (x-/y-) distance **If implementing this for a programming assignment, please see the slide at the end about alternate closed-list implementation open_list.push(Start State) while(open_list is not empty) 1. s ← remove min. f -value state from Closed List open_list (if tie in f-values, select one w/ larger g-value) 2. Add s to closed list Open List 3a. if s = goal node then g=0, S trace path back to start; STOP! h=6, f=6 3b. else Generate successors/neighbors of s, compute their f-values, and add them to open_list if they are not in the closed_list (so we don’t re -explore), or if they are already in the open list, update them if G they have a smaller f value

  15. 15 Path-Planning w/ A* Algorithm • Find optimal path from S to G using A* – Use heuristic of Manhattan (x-/y-) distance open_list.push(Start State) while(open_list is not empty) 1. s ← remove min. f -value state from Closed List open_list (if tie in f-values, select one w/ larger g-value) g=1, h=7, 2. Add s to closed list Open List f=8 3a. if s = goal node then g=1, g=1, S trace path back to start; STOP! h=7, h=5, f=8 f=6 3b. else g=1, Generate successors/neighbors of s, h=5, f=6 compute their f-values, and add them to open_list if they are not in the closed_list (so we don’t re -explore), or if they are already in the open list, update them if G they have a smaller f value

  16. 16 Path-Planning w/ A* Algorithm • Find optimal path from S to G using A* – Use heuristic of Manhattan (x-/y-) distance open_list.push(Start State) while(open_list is not empty) 1. s ← remove min. f -value state from Closed List open_list (if tie in f-values, select one w/ larger g-value) g=1, g=2, h=7, h=6, 2. Add s to closed list Open List f=8 f=8 3a. if s = goal node then g=1, g=1, S trace path back to start; STOP! h=7, h=5, f=8 f=6 3b. else g=1, g=2, Generate successors/neighbors of s, h=5, h=4, f=6 f=6 compute their f-values, and add them to open_list if they are not in the closed_list (so we don’t re -explore), or if they are already in the open list, update them if G they have a smaller f value

  17. 17 Path-Planning w/ A* Algorithm • Find optimal path from S to G using A* – Use heuristic of Manhattan (x-/y-) distance open_list.push(Start State) while(open_list is not empty) 1. s ← remove min. f -value state from Closed List open_list (if tie in f-values, select one w/ larger g-value) g=1, g=2, h=7, h=6, 2. Add s to closed list Open List f=8 f=8 3a. if s = goal node then g=1, g=1, S trace path back to start; STOP! h=7, h=5, f=8 f=6 3b. else g=1, g=2, Generate successors/neighbors of s, h=5, h=4, f=6 f=6 compute their f-values, and add them to open_list if they are not in the closed_list (so we don’t re -explore), or if they are already in the open list, update them if G they have a smaller f value

  18. 18 Path-Planning w/ A* Algorithm • Find optimal path from S to G using A* – Use heuristic of Manhattan (x-/y-) distance open_list.push(Start State) while(open_list is not empty) 1. s ← remove min. f -value state from Closed List open_list (if tie in f-values, select one w/ larger g-value) g=1, g=2, h=7, h=6, 2. Add s to closed list Open List f=8 f=8 3a. if s = goal node then g=1, g=1, S trace path back to start; STOP! h=7, h=5, f=8 f=6 3b. else g=2, g=1, g=1, g=2, Generate successors/neighbors of s, h=6, h=5, h=5, h=4, f=8 f=6 f=6 f=6 compute their f-values, and add them to open_list if they are not in the closed_list (so we don’t re -explore), or if they are already in the open list, update them if G they have a smaller f value

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend