Searching large spaces

Finding Paths
Efficiently with A*
presented by
Nicolas Bettenburg




                         1
2
3
What is the fastest way to
       get to TD?




                             4
B
A




        5
A student’s mental model of Kingston...

       Domino's Pizza

                         350
                             ...
Describe the Problem as a State Space


                                                   Gordon Hall




               ...
Uninformed Search
Breadth-First Search will find the path through
 the search tree to the shallowest solution.

           ...
Breadth-First Search will need to keep
O(bd+1 ) nodes in memory!

b is the branching factor
d is the depth of the solution...
Uninformed Search
Depth-First Search will always expand
  the deepest unexplored node.
                         Gordon Hal...
Uninformed Search

                   Depth-First   Breadth-First
                   Search        Search

Space complexit...
Can you compute
   a solution?
       Yes.
                     Can you compute
                       a best solution?
  ...
Idea: Add problem
specific information
using some heuristic.




                        13
For each node, measure the distance from that node
to the goal “as the bird flies”.
       Domino's Pizza

                ...
Greedy Best-First
               Search


                               Domino's Pizza
                                  ...
Greedy Best-First
                   Search
                                                      Gordon Hall
            ...
Domino's Pizza

                  350
                                          Grizzly Grill             500             ...
Problems

• follows single path all the way to goal
• will back up when hitting dead end
• not better than Depth-First Sea...
A* Search
Define an evaluation function as:
f(n) = g(n) + h(n)
          g(n) = cost(start, n)
          h(n) = distance(n,...
Input:
1    OPEN = {n0}
2    CLOSED = {}                                        G, n0, t
3    while (OPEN is not empty)
4 ...
Gordon Hall

                                                                                                   900 = 0 + ...
Properties of A*
           A* is optimal if h(n) is consistent


h(n)is consistent, if it never over-estimates the true c...
Properties of A*
Suppose an sub-optimal goal node n’ appears on the fringe.
Let the cost of the optimal solution be C*.
Si...
Properties of A*
                     A* is complete


The f-costs along any path are non-decreasing.

Since A* always exp...
Properties of A*
              A* is optimally efficient



For any heuristic function h(n),
no other algorithm can expand ...
A* can be used for many other problems:


    8-Puzzle              Rubik’s Cube




                                     ...
Start State                   Goal State


average solution cost:      22 steps
average branching factor:   3
complete sta...
Good heuristics to use with
A* and the 8-Puzzle:

h1 : number of misplaced tiles

h2: sum of manhattan distances from
curr...
There are much harder
            Problems

15-Puzzle:
1013 distinct states

Rubik’s Cube:
8! x 37 x 12! x 210 ≈ 4.3 x 101...
Image from http://todaysinsidescoop.blogspot.com/2008/04/snowball-effect.html
                                            ...
Divide into Subproblems!


 * 2 4                      1 2
 *   *                    3 4 *
 * 3 1                    * * *...
Calculate costs for every possible
       subproblem instance

     Store these in a database

 Use the recorded values as...
Pattern databases allowed to find the first
optimal solutions to Rubik’s cube in 1997!
                 (18 moves)




     ...
Computing a pattern
database is expensive!
Usually BFS backwards
from goal to start.




                         34
Compute needed pattern
  database entries on
       demand!

  5 2 4                              * 2 4
                tr...
Hierarchical A*

              *   *   4

state Øi(s)   *       *   h(Øi(s))
              *   *   *


     .            ....
Conclusions




              37
Upcoming SlideShare
Loading in …5
×

Finding Paths in Large Spaces - A* and Hierarchical A*

1,897 views

Published on

A presentation on A* and Hierarchical A* I gave for a theoretical algorithms course.

0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,897
On SlideShare
0
From Embeds
0
Number of Embeds
20
Actions
Shares
0
Downloads
0
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Finding Paths in Large Spaces - A* and Hierarchical A*

  1. 1. Searching large spaces Finding Paths Efficiently with A* presented by Nicolas Bettenburg 1
  2. 2. 2
  3. 3. 3
  4. 4. What is the fastest way to get to TD? 4
  5. 5. B A 5
  6. 6. A student’s mental model of Kingston... Domino's Pizza 350 Grizzly Grill 500 TD 50 Pizza Pizza 60 140 A&P 700 100 Hospital Starbucks 900 400 750 1000 Goodwin Hall 100 400 Gordon Hall Biosciences 6
  7. 7. Describe the Problem as a State Space Gordon Hall Goodwin Domino's Hall Pizza Gordon Hall Biociences Hospital Starbucks Gordon Hall Grizzly Grill Goodwin Goodwin Goodwin Hospital TD Canada A&P Pizza PIzza TD Canada Hall Hall Hall Starbucks Grizzly Grill Starbucks Grizzly Grill 7
  8. 8. Uninformed Search Breadth-First Search will find the path through the search tree to the shallowest solution. Gordon Hall Domino's Pizza Goodwin Hall Grizzly Grill Biociences Starbucks Hospital TD Pizza TD Hospital A&P Canada PIzza Canada 1,75 km 1,55 km TD Grizzly Grizzly Canada Grill Grill 8
  9. 9. Breadth-First Search will need to keep O(bd+1 ) nodes in memory! b is the branching factor d is the depth of the solution b=10 Depth Nodes Time Memory 2 1100 1/10 s 1 MB 4 111,100 11 s 106 MB 6 10^7 19 m 10 GB 8 10^9 31 h 1 TB 10 10^11 129 d 101 TB 12 10^13 35 y 10 PB 14 10^15 3,523 y 1 EB 9
  10. 10. Uninformed Search Depth-First Search will always expand the deepest unexplored node. Gordon Hall Domino's Pizza Goodwin Hall Grizzly Grill Biociences Starbucks Hospital TD Pizza TD Hospital A&P Canada PIzza Canada TD Grizzly Grizzly Canada Grill Grill TD TD Canada Canada 10
  11. 11. Uninformed Search Depth-First Breadth-First Search Search Space complexity O(b · m) O(bd+1 ) Time complexity O(bm ) O(bd+1 ) Complete? No Yes 11
  12. 12. Can you compute a solution? Yes. Can you compute a best solution? Yes. With enough time and memory Can you compute a best solution more efficiently? This rest of this presentation. 12
  13. 13. Idea: Add problem specific information using some heuristic. 13
  14. 14. For each node, measure the distance from that node to the goal “as the bird flies”. Domino's Pizza 350 Grizzly Grill 500 TD 50 Pizza Pizza 60 140 A&P 700 100 Starbucks Hospital 900 400 750 1000 Goodwin Hall 100 400 Gordon Hall Biosciences 14
  15. 15. Greedy Best-First Search Domino's Pizza 350 Grizzly Grill 500 TD 50 Always to expand the node Pizza Pizza 140 60 A&P 700 that is closest to the goal. 100 Starbucks Hospital 900 400 750 1000 Goodwin Hall 100 400 Gordon Hall Biosciences 15
  16. 16. Greedy Best-First Search Gordon Hall 900 Goodwin Domino's Hall Pizza 780 1000 Gordon Hall Biociences Hospital Starbucks Gordon Hall Grizzly Grill 900 820 300 Goodwin Goodwin Goodwin Hospital TD Canada A&P Pizza PIzza TD Canada Hall Hall Hall 780 0 Starbucks Grizzly Grill Starbucks Grizzly Grill 16
  17. 17. Domino's Pizza 350 Grizzly Grill 500 TD 50 Pizza Pizza 60 140 A&P 700 100 Starbucks Hospital 900 400 750 1000 100 Goodwin Hall 1,55km! Not the best solution 400 Gordon Hall Biosciences but much faster with less memory consumption! 17
  18. 18. Problems • follows single path all the way to goal • will back up when hitting dead end • not better than Depth-First Search 18
  19. 19. A* Search Define an evaluation function as: f(n) = g(n) + h(n) g(n) = cost(start, n) h(n) = distance(n, end) Thus f(n) describes the estimated cost of the cheapest solution through n. Expand the node with the smallest f(n) 19
  20. 20. Input: 1 OPEN = {n0} 2 CLOSED = {} G, n0, t 3 while (OPEN is not empty) 4 n = pop(OPEN) 5 6 if (n = t) terminate Output: 7 else Best path from n0 to t 8 M = Expand(n) 9 for each m in M do 10 if (exists m’ in OPEN with m’ = m) 11 if (f(m’) smaller or equal f(n) + f(m)) 12 continue 13 else if (exists m’ in CLOSED with m’ = m) 14 if (f(m’) smaller or equal f(n) + f(m)) 15 continue 16 else 17 OPEN = OPEN {m} 18 CLOSED = CLOSED {m} 19 parent (m) = n and OPEN = OPEN + {m} 20 end for 21 CLOSED = CLOSED + {n} 22 end if 23 end while 20
  21. 21. Gordon Hall 900 = 0 + 900 Domino's Pizza Goodwin Hall 1680 = 900 + 780 880 = 100 + 780 Biociences Starbucks Hospital Domino's Pizza 1320 = 500 + 820 1100 = 500+600 1150 = 850 + 300 350 Grizzly Grill 500 TD 50 Pizza Pizza 60 Pizza A&P PIzza 140 A&P 700 1170 = 640+530 1110 = 600+510 100 Starbucks Hospital Grizzly 900 1110 = 660+450 Grill 400 750 TD 1160 = 1160 + 0 Canada 1000 Goodwin Hall 100 400 Gordon Hall Biosciences 21
  22. 22. Properties of A* A* is optimal if h(n) is consistent h(n)is consistent, if it never over-estimates the true cost and it fullfils the triangle inequality. f(n) = g(n) + h(n) with g(n) is the true cost from start to n. Hence f(n) never over-estimates the true cost of a solution through n. 22
  23. 23. Properties of A* Suppose an sub-optimal goal node n’ appears on the fringe. Let the cost of the optimal solution be C*. Since n’ is sub-optimal and h(n’) = 0 f(n’) = g(n’) + h(n’) = g(n’) + 0 = g(n’) > C* (a) For a fringe node n on the optimal path f(n) = g(n) + h(n) ≤C* (b) Combining (a) and (b) shows f(n) ≤ C* < f(g’) So n’ will not be expanded and A* will return an optimal solution. 23
  24. 24. Properties of A* A* is complete The f-costs along any path are non-decreasing. Since A* always expands the the fringe node with lowest f-cost, we will eventually find a path where the f-cost equals the cost of an optimal solution C*, if such a path exists. 24
  25. 25. Properties of A* A* is optimally efficient For any heuristic function h(n), no other algorithm can expand fewer nodes with f(n) < C* without running the risk of missing the optimal solution. 25
  26. 26. A* can be used for many other problems: 8-Puzzle Rubik’s Cube 26
  27. 27. Start State Goal State average solution cost: 22 steps average branching factor: 3 complete state space: 322 ≈ 3.1 x 1010 distinct state space: 181,440 27
  28. 28. Good heuristics to use with A* and the 8-Puzzle: h1 : number of misplaced tiles h2: sum of manhattan distances from current positions to goal positions Depth Cost h1 Cost h2 4 13 12 22 18,094 1,219 28
  29. 29. There are much harder Problems 15-Puzzle: 1013 distinct states Rubik’s Cube: 8! x 37 x 12! x 210 ≈ 4.3 x 1019 states branching factor: 13 8! ways to arrange corner cubes seven indenpendent, eighth dependent on previous choices 12! ways to arrange edges eleven can be flipped independently, twelfth depending on previous choices 29
  30. 30. Image from http://todaysinsidescoop.blogspot.com/2008/04/snowball-effect.html 30
  31. 31. Divide into Subproblems! * 2 4 1 2 * * 3 4 * * 3 1 * * * Start Goal Cost of C* for this subproblem forms lower bound on the cost of complete problem 31
  32. 32. Calculate costs for every possible subproblem instance Store these in a database Use the recorded values as h(n) Can solve 15-puzzles in a few milliseconds! 32
  33. 33. Pattern databases allowed to find the first optimal solutions to Rubik’s cube in 1997! (18 moves) 33
  34. 34. Computing a pattern database is expensive! Usually BFS backwards from goal to start. 34
  35. 35. Compute needed pattern database entries on demand! 5 2 4 * 2 4 transformation 8 7 * * 9 3 1 * 3 1 real state s abstract state Φ(s) Search on abstraction levels 35
  36. 36. Hierarchical A* * * 4 state Øi(s) * * h(Øi(s)) * * * . . . . . . . . . * 2 4 state Ø(s) * * h(Ø(s)) * 3 1 5 2 4 state s 8 7 h(s) 9 3 1 36
  37. 37. Conclusions 37

×