Presentation is loading. Please wait.

Presentation is loading. Please wait.

COMP261 Lecture 7 A* Search. A* search Can we do better than Dijkstra's algorithm? Yes! –want to explore more promising paths, not just shortest so far.

Similar presentations


Presentation on theme: "COMP261 Lecture 7 A* Search. A* search Can we do better than Dijkstra's algorithm? Yes! –want to explore more promising paths, not just shortest so far."— Presentation transcript:

1 COMP261 Lecture 7 A* Search

2 A* search Can we do better than Dijkstra's algorithm? Yes! –want to explore more promising paths, not just shortest so far. – ⇒ need to change the priority on the fringe: choose node on the fringe that is the most promising: Total path length will be cost from start to this node (we know this cost) +cost from this node to goal (we can only estimate this cost) A* uses a heuristic estimate of total path length: costSoFar + heuristic estimate heuristic estimate must be guaranteed to be no more than the real cost.

3 A* algorithm (fast version) Minor change on Dijkstra's algorithm: Initialise: for all nodes visited ← false, pathFrom ← null enqueue(  start, null, 0, estimate(start, goal ) , fringe), Repeat until fringe is empty:  node, from, costToHere, totalCostToGoal  ← dequeue(fringe) If not node.visited then node.visited ←true, node.pathFrom←from, node.cost←costToHere If node = goal then exit for each edge to neigh out of node if not neigh.visited then costToNeigh ← costToHere + edge.weight estTotal ← costToNeigh + estimate(neighbour, goal ) fringe.enqueue(  neighbour, node, costToNeigh, estTotal  ) fringe = priority queue, ordered by total cost to Goal estimate(node, goal) must be admissible and consistent.

4 A* example. 15 25 26 20 22 17 20 5 13 11 6 17 15 11 6 G 8 12 8 14 35 6 7 12 9 8 9 10 7 6 9 8 13 10 18 10 12 8 31 5 8 Number in node is estimate of remaining path length

5 An example. 34 28 29 25 34 31 21 30 15 25 26 33 25 34 20 22 9 17 20 5 13 9 11 15 6 22 17 15 11 6 I 8 6 915 7 12 8 6 5 10 8 14 35 6 7 12 9 88 9 25 10 17 7 10 8 5 12 7 48 9 6 6 5 9 10 7 12 9 8 13 10 18 10 12 25 14 9 13 8 4 5

6 A* heuristic A heuristic estimate of the remaining path is admissible if it always underestimates the remaining cost If it is not admissible, it may not find the shortest path: C /40 B /25 S /30 T /25 G G /7 10 E /15 10 estimate

7 A* heuristic: monotonic/consistent Admissible is not enough for the fast version of A*: When visit a node, must be the best path to a node To be able to commit to visited nodes: heuristic must get more accurate as you go along a path d x + h(X) ≤ d x + W xy + h(Y) Consistent heuristic: h(X) - h(Y) ≤ W xy C /100 B /10 S /20 G 10 55 E /20 200 X /h(X) W xy Y /h(Y) dxdx

8 A* heuristic Consistent heuristics can be hard to find (Euclidean distance to goal is consistent) If the estimate is admissible, but is not consistent, then: ⇒ cannot commit to a node when we take it off the queue ⇒ may need to revisit nodes ⇒ no point in the visited set Do we have to keep searching all possible paths? When is it not worth putting a neighbour on the fringe? If this path to the neighbour is worse than the best to neighbour so far. If this path to the neighbour is worse than the best path to the goal so far

9 A* algorithm (slow version) No visited set! But must store length of best path to each node Initialise: bestToGoal ← , for all nodes node.pathLength ←  fringe.enqueue(  start, null, 0, estimate(start, goal )  ) Repeat until fringe is empty:  node, from, costToHere, totalCostToGoal   ← fringe.dequeue If costToHere < node.cost then // shorter route to node node.pathFrom← from, node.cost ← costToHere If node = goal then exit// found shortest route to goal for each edge from node to neighbour toNeigh ← costToHere + edge.weight if toNeigh < neigh.cost then estTotal ← toNeigh + estimate(neighbour, goal ) if estTotal < bestToGoal then fringe.enqueue(  neighbour, node, toNeigh, estTotal  ) if neighbour = goal then bestToGoal ← toNeigh

10 More on A* Very general search strategy –not just paths: eg: search for optimal loading of a truck –any optimisation problem where build up a solution as a series of steps. –Works with implicit graphs (AI search problems) (but need to store nodes you have seen) –need a lower bound estimate of full cost [admissible] –need a consistent estimate to use the fast version. –If cannot guarantee consistency, may be exponential Heuristics –Issue: how to find a good, admissible, consistent heuristic


Download ppt "COMP261 Lecture 7 A* Search. A* search Can we do better than Dijkstra's algorithm? Yes! –want to explore more promising paths, not just shortest so far."

Similar presentations


Ads by Google