CPSC 322 - Lecture 21 - October 27, 2004

CPSC 322 - Lecture 21

The A* Algorithm


I.  The best of both worlds

If we think about the search strategies we've studied
so far, there are a couple of desirable attributes that
stand out.  There are some strategies, such as 
breadth-first and lowest-cost-first, that guarantee
an optimal path will be found, but they're blind search
strategies and tend to be computationally expensive both
in terms of space and time.  Then there are strategies that 
can be much less expensive to perform, like best-first,  
because they're aided by heuristics, but those strategies won't 
necessarily find an optimal path to the goal.

What we'd really like, of course, is a heuristic search
strategy that guarantees optimality.  We noticed that the
blind-search strategies that find optimal paths take into
account the g(n) function -- the actual cost of the path
from the start node to the frontier node n.  Then we
incorporated the g(n) function into the heuristic best-first
search algorithm to see if we did, in fact, get a heuristic
search strategy with a guarantee of finding the optimal path.

The resulting algorithm has a name -- it's called Algorithm A,
and it looks like this:

  Given a set of start nodes, a set of goal nodes,
  and a graph (i.e., the nodes and the arcs):

  apply heuristic g(n)+h(n) to start nodes
  make a "list" of the start nodes - let's call it the "frontier"
  sort the frontier by g(n)+h(n) values

  repeat
    if no nodes on the frontier then terminate with failure
    choose one node from the front of the frontier and remove it
    if the chosen node matches the goal node
      then terminate with success
      else put next nodes (neighbors) and g(n)+h(n) values on frontier
        and sort frontier by g(n)+h(n) values
  end repeat

Algorithm A is nice and all that, but without some 
extra tweaks, it's not guaranteed to find the optimal path.
But, as is proven in your textbook, if Algorithm A also
adheres to the following constraints:

  The branching factor in the state space is finite

  The arc costs are bounded above 0 (i.e., there is 
  some e > 0 such that all arc costs are greater than e)

  h(n) is a lower bound on the actual minimum cost of the 
  shortest path from node n to a goal node

then, and only then, is it guaranteed that Algorithm A finds
the optimal path AND the first path to goal that it finds 
will be optimal.  In that case, we call this Algorithm A*.

The property that an algorithm will find an optimal
path, if one exists, from the start to the goal, and that 
the first path found from the start to the goal will be 
optimal, even if the search space is infinite, is called
"admissibility".  So Algorithm A* is admissible.  But,
as we discussed in class, admissibility doesn't mean that
the optimal path will be found quickly.  A* may do lots
of searching in places that won't lead to an optimal path
before it finds the optimal path.  And as a side note, we
talked about the fact that both the tiles-out-of-place and
the Manhattan distance heuristics, when applied to the
8-tile puzzle, were admissible.  In other words, either
of those heuristics, when plugged into Algorithm A, turn
it into the A* algorithm.


II.  Refinements to search strategies

Your book talks about several refinements, and you should
take the time to familiarize yourself with all of them.
In class we mentioned three -- cycle checking, iterative 
deepening, and direction of search -- and you'll find
slides about them in the daily slide show.

Last revised: October 30, 2004