## Class ContractionHierarchyBidirectionalDijkstra<V,​E>

• java.lang.Object
• org.jgrapht.alg.shortestpath.ContractionHierarchyBidirectionalDijkstra<V,​E>
• Type Parameters:
V - the graph vertex type
E - the graph edge type
All Implemented Interfaces:
ShortestPathAlgorithm<V,​E>

public class ContractionHierarchyBidirectionalDijkstra<V,​E>
extends Object
Implementation of the hierarchical query algorithm based on the bidirectional Dijkstra search. This algorithm is designed to contracted graphs. The best speedup is achieved on sparse graphs with low average outdegree.

The query algorithm is originally described the article: Robert Geisberger, Peter Sanders, Dominik Schultes, and Daniel Delling. 2008. Contraction hierarchies: faster and simpler hierarchical routing in road networks. In Proceedings of the 7th international conference on Experimental algorithms (WEA'08), Catherine C. McGeoch (Ed.). Springer-Verlag, Berlin, Heidelberg, 319-333.

During contraction graph is divided into 2 parts which are called upward and downward graphs. Both parts have all vertices of the original graph. The upward graph ($G_{\uparrow}$) contains only those edges which source has lower level than the target and vice versa for the downward graph ($G_{\downarrow}$).

For the shortest path query from $s$ to $t$, a modified bidirectional Dijkstra shortest path search is performed. The forward search from $s$ operates on $G_{\uparrow}$ and the backward search from $t$ - on the $G_{\downarrow}$. In each direction only the edges of the corresponding part of the graph are considered. Both searches eventually meet at the vertex $v$, which has the highest level in the shortest path from $s$ to $t$. Whenever a search in one direction reaches a vertex that has already been processed in other direction, a new candidate for a shortest path is found. Search is aborted in one direction if the smallest element in the corresponding priority queue is at least as large as the best candidate path found so far.

After computing a contracted path, the algorithm unpacks it recursively into the actual shortest path using the bypassed edges stored in the contraction hierarchy graph.

There is a possibility to provide an already computed contraction for the graph. For now there is no means to ensure that the specified contraction is correct, nor to fail-fast. If algorithm uses an incorrect contraction, the results of the search are unpredictable.

Since:
July 2019
Author:
Semen Chudakov
ContractionHierarchyPrecomputation
• ### 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.
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.
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.
Constant Field Values
• #### graph

protected final Graph<V,​E> graph
The underlying graph.
• ### 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
• #### 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