org.jgrapht.alg

## Class AStarShortestPath<V,E>

- java.lang.Object
- - org.jgrapht.alg.AStarShortestPath<V,E>

-     public class AStarShortestPath<V,E>
      extends Object

  An implementation of A* shortest path algorithm. A* shortest path algorithm german Wiki . This class works for Directed and Undirected graphs, as well as Multi-Graphs and Mixed-Graphs. It's ok if the graph changes in between invocations of the `getShortestPath(Object, Object, AStarAdmissibleHeuristic)` getShortestPath} method; no new instance of this class has to be created. The heuristic is implemented using a FibonacciHeap data structure to maintain the set of open nodes. However, there still exist several approaches in literature to improve the performance of this heuristic which one could consider to implement. Another issue to take into consideration is the following: given to candidate nodes, i, j to expand, where f(i)=f(j), g(i)>g(j), h(i)<g(j), f(i)=g(i)+h(i), g(i) is the actual distance from the source node to i, h(i) is the estimated distance from i to the target node. Usually a depth-first search is desired, so ideally we would expand node i first. Using the FibonacciHeap, this is not necessarily the case though. This could be improved in a later version.
  Since:
    Aug, 2015
  Author:
    Joris Kinable, Jon Robison, Thomas Breitbart

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected AStarAdmissibleHeuristic<V>` | `admissibleHeuristic`
    `protected Map<V,E>` | `cameFrom`
    `protected Set<V>` | `closedList`
    `protected Map<V,Double>` | `gScoreMap`
    `protected int` | `numberOfExpandedNodes`
    `protected FibonacciHeap<V>` | `openList`
    `protected Map<V,FibonacciHeapNode<V>>` | `vertexToHeapNodeMap`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AStarShortestPath(Graph<V,E> graph)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `getNumberOfExpandedNodes()` Returns how many nodes have been expanded in the A* search procedure in its last invocation.
    `GraphPath<V,E>` | `getShortestPath(V sourceVertex, V targetVertex, AStarAdmissibleHeuristic<V> admissibleHeuristic)` Calculates (and returns) the shortest path from the sourceVertex to the targetVertex.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### openList

          protected FibonacciHeap<V> openList

    - #### vertexToHeapNodeMap

          protected Map<V,FibonacciHeapNode<V>> vertexToHeapNodeMap

    - #### closedList

          protected Set<V> closedList

    - #### gScoreMap

          protected Map<V,Double> gScoreMap

    - #### cameFrom

          protected Map<V,E> cameFrom

    - #### admissibleHeuristic

          protected AStarAdmissibleHeuristic<V> admissibleHeuristic

    - #### numberOfExpandedNodes

          protected int numberOfExpandedNodes

  - ### Constructor Detail

    - #### AStarShortestPath

          public AStarShortestPath(Graph<V,E> graph)

  - ### Method Detail

    - #### getShortestPath

          public GraphPath<V,E> getShortestPath(V sourceVertex,
                                       V targetVertex,
                                       AStarAdmissibleHeuristic<V> admissibleHeuristic)

      Calculates (and returns) the shortest path from the sourceVertex to the targetVertex. Note: each time you invoke this method, the path gets recomputed.
      Parameters:
        `sourceVertex` - source vertex
        `targetVertex` - target vertex
        `admissibleHeuristic` - admissible heuristic which estimates the distance from a node to the target node.
      Returns:
        the shortest path from sourceVertex to targetVertex

    - #### getNumberOfExpandedNodes

          public int getNumberOfExpandedNodes()

      Returns how many nodes have been expanded in the A* search procedure in its last invocation. A node is expanded if it is removed from the open list.
      Returns:
        number of expanded nodes

Copyright © 2016. All rights reserved.