Skip navigation links org.jgrapht.alg.shortestpath

## Class BidirectionalAStarShortestPath<V,E>

• Type Parameters:
V - the graph vertex type
E - the graph edge type
All Implemented Interfaces:
ShortestPathAlgorithm<V,E>

public class BidirectionalAStarShortestPath<V,E>
extends BaseBidirectionalShortestPathAlgorithm<V,E>
A bidirectional version of A* algorithm.

See the Wikipedia article for details and references about bidirectional search. This technique does not change the worst-case behavior of the algorithm but reduces, in some cases, the number of visited vertices in practice.

The algorithm was first introduced in Ira Sheldon Pohl. 1969. Bi-Directional and Heuristic Search in Path Problems. Ph.D. Dissertation. Stanford University, Stanford, CA, USA. AAI7001588.

The implementation uses two termination criteria depending on if the provided heuristic is consistent or not. Both criteria are based on the shortest path distance $\mu$ seen thus far in the search. Initially, in both cases the algorithm sets $\mu=\infty$. Whenever the search updates the information about the vertex $v$, it sets $\mu = min\{\mu; g_f(v) + g_b(v)\}$, where $g_f(v)$ is the current best-known path cost from $source$ to $sink$ and $g_b(v)$ is the current best-known path cost from $sink$ to $source$.

Author:
Semen Chudakov, Dimitrios Michail, Joris Kinable, Jon Robison, Thomas Breitbart
See Also:
AStarShortestPath

• ### Nested classes/interfaces inherited from interface org.jgrapht.alg.interfaces.ShortestPathAlgorithm

ShortestPathAlgorithm.SingleSourcePaths<V,E>
• ### Field Summary

Fields
Modifier and Type Field and Description
protected Graph<V,E> graph
The underlying graph.
protected static String GRAPH_CONTAINS_A_NEGATIVE_WEIGHT_CYCLE
Error message for reporting the existence of a negative-weight cycle.
protected static String GRAPH_MUST_CONTAIN_THE_SINK_VERTEX
Error message for reporting that a sink vertex is missing.
protected static String GRAPH_MUST_CONTAIN_THE_SOURCE_VERTEX
Error message for reporting that a source vertex is missing.
• ### Constructor Summary

Constructors
Constructor and Description
BidirectionalAStarShortestPath(Graph<V,E> graph, AStarAdmissibleHeuristic<V> heuristic)
Constructs a new instance of the algorithm for a given graph and heuristic.
BidirectionalAStarShortestPath(Graph<V,E> graph, AStarAdmissibleHeuristic<V> heuristic, Supplier<org.jheaps.AddressableHeap<Double,V>> heapSupplier)
Constructs a new instance of the algorithm for a given graph, heuristic and heap supplier.
• ### Method Summary

All Methods
Modifier and Type Method and Description
protected GraphPath<V,E> createEmptyPath(V source, V sink)
Create an empty path.
GraphPath<V,E> getPath(V source, V sink)
Get a shortest path from a source vertex to a sink vertex.
ShortestPathAlgorithm.SingleSourcePaths<V,E> getPaths(V source)
Compute all shortest paths starting from a single source vertex.
double getPathWeight(V source, V sink)
Get the weight of the shortest path from a source vertex to a sink vertex.
• ### Methods inherited from class org.jgrapht.alg.shortestpath.BaseBidirectionalShortestPathAlgorithm

createPath
• ### Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
• ### Field Detail

• #### GRAPH_CONTAINS_A_NEGATIVE_WEIGHT_CYCLE

protected static final String GRAPH_CONTAINS_A_NEGATIVE_WEIGHT_CYCLE
Error message for reporting the existence of a negative-weight cycle.
See Also:
Constant Field Values
• #### GRAPH_MUST_CONTAIN_THE_SOURCE_VERTEX

protected static final String GRAPH_MUST_CONTAIN_THE_SOURCE_VERTEX
Error message for reporting that a source vertex is missing.
See Also:
Constant Field Values
• #### GRAPH_MUST_CONTAIN_THE_SINK_VERTEX

protected static final String GRAPH_MUST_CONTAIN_THE_SINK_VERTEX
Error message for reporting that a sink vertex is missing.
See Also:
Constant Field Values
• #### graph

protected final Graph<V,E> graph
The underlying graph.
• ### Constructor Detail

• #### BidirectionalAStarShortestPath

public BidirectionalAStarShortestPath(Graph<V,E> graph,
AStarAdmissibleHeuristic<V> heuristic)
Constructs a new instance of the algorithm for a given graph and heuristic.
Parameters:
graph - the graph
heuristic - heuristic that estimates distances between nodes
• #### BidirectionalAStarShortestPath

public BidirectionalAStarShortestPath(Graph<V,E> graph,
AStarAdmissibleHeuristic<V> heuristic,
Supplier<org.jheaps.AddressableHeap<Double,V>> heapSupplier)
Constructs a new instance of the algorithm for a given graph, heuristic and heap supplier.
Parameters:
graph - the graph
heuristic - heuristic that estimates distances between nodes
heapSupplier - supplier of the preferable heap implementation
• ### Method Detail

• #### getPath

public GraphPath<V,E> getPath(V source,
V sink)
Get a shortest path from a source vertex to a sink vertex.
Parameters:
source - the source vertex
sink - the target vertex
Returns:
a shortest path or null if no path exists
• #### getPaths

public ShortestPathAlgorithm.SingleSourcePaths<V,E> getPaths(V source)
Compute all shortest paths starting from a single source vertex.
Specified by:
getPaths in interface ShortestPathAlgorithm<V,E>
Parameters:
source - the source vertex
Returns:
the shortest paths
• #### getPathWeight

public double getPathWeight(V source,
V sink)
Get the weight of the shortest path from a source vertex to a sink vertex. Returns Double.POSITIVE_INFINITY if no path exists.
Specified by:
getPathWeight in interface ShortestPathAlgorithm<V,E>
Parameters:
source - the source vertex
sink - the sink vertex
Returns:
the weight of the shortest path from a source vertex to a sink vertex, or Double.POSITIVE_INFINITY if no path exists
• #### createEmptyPath

protected final GraphPath<V,E> createEmptyPath(V source,
V sink)
Create an empty path. Returns null if the source vertex is different than the target vertex.
Parameters:
source - the source vertex
sink - the sink vertex
Returns:
an empty path or null null if the source vertex is different than the target vertex
Skip navigation links Copyright © 2019. All rights reserved.