Contraction hierarchies
In computer science, the method of contraction hierarchies is a speed-up technique for finding the shortest-path in a graph. Contraction hierarchies is a method optimized to exploit properties of graphs similar to those representing road networks.[1] These networks consist of tens of millions of vertices (representing intersections) which renders Dijkstra's algorithm impracticable.[2] The speed-up is archived by creating shortcuts in a preprocessing phase which are then used during a shortest-path query to skip over "unimportant" vertices.[1]
Contraction hierarchies are applied to speed-up algorithms in car-navigation systems, web-based route planners, traffic simulation, and logistics optimization.[3][2][4] Implementations of the algorithm are publicly available as open source software. [5][6][7][8][9]
The Algorithm
The contraction hierarchies (CH) algorithm is a two-phase approach to the shortest path problem consisting of a preprocessing phase and a query phase. As road networks change rather infrequent, more time (seconds to hours) can be used to once precompute some calculations before queries are to be answered. Using this precomputed data, many queries can be answered taking very litte time (microseconds) each.[2][3] CHs rely on shortcuts to archive this speedup. A shortcut connects two vertices and not connected in the original graph. Its edge weight is the sum of the edge weights on the shortest - path.
Preprocessing phase
The CH algorithm relies on shortcuts created in the preprocessing phase to reduce the search space — that is the number of vertices CH has to look at at query time. To archive this, iterative vertex contractions are performed. When contracting a vertex it is temporarily removed from the graph , and a shortcut is created between each pair of neighboring vertices if the shortest path from to contains .[1] The process of determining if the shortest path between and contains is called witness search. It can be performed for example by computing a path from to using a forward search using only not yet contracted nodes.[3]
Node Order
The vertices of the input graph have to be contracted in a way which minimizes the number of edges added to the graph by contractions. As optimal node ordering is NP-complete[10] heuristics are used[1].
Bottom-up and top-down heuristics exist. On one hand, the computationally cheaper bottom-up heuristics decide the order in which to contract the vertices in a greedy fashion. A combination of factors is used to select the next vertex for contraction, including the net number of shortcuts added and the number of nearby vertices already contracted. The net number of shortcuts added is defined as the number of added shortcuts obtained by a simulated contraction minus number of edges incident to the contracted node. Considering the number of nearby vertices which are already contracted a uniform contraction and a flat hierarchy is archived. This can for example be done by maintaining a counter for each node which is incremented each time a neighboring vertex is contracted.[1][3]
Top-down heuristics on the other hand yield better results but need more preprocessing time. They classify vertices which are part of many shortest paths as more important than those which are only needed for a few shortest paths. This can be approximated by computing nested dissections, which can be efficiently computed on road networks because of their small separators.[1][3]
Query phase
In the query phase, a bidirectional search is performed starting from the starting node and the target node on the original graph augmented by the shortcuts created in the preprocessing phase.[1] The most important vertex on the shortest path between and will be either or themselves or upward from both and . Therefore the vertex minimizing is on the shortest s-t path in the original graph and holds.[1]This means that both forward and backward search only need to relax edges leading to nodes higher up in the hierarchy which keeps the search space small.[3]
Path retrieval
A CH query as described above yields the time or distance from to but not the actual path. To obtain the list of edges (streets) on the shortest path the shortcuts taken have to be unpacked. Each shortcut is the concatenation of two other edges of the original graph or further shortcuts. Storing the middle vertex of each shortcut during contractions enables linear-time recursive unpacking of the shortest route.[1][3]
Customized Contraction Hierachies
If the edge weights are changed more often than the network topology, CH can be extended to a three-phase approach by including a customization phase between the preprocessing and query phase. This can be used for example to switch between shortest distance and shortest time or include current traffic information as well as user preferences like avoiding certain types of roads (ferries, highways, ...). In the preprocessing phase, most of the runtime is spent on computing the order in which the nodes are contracted.[3] However, this sequence of contraction operations in the preprocessing phase can be saved for when they are later needed in the customization phase. Each time the metric is customized, the contractions can then be efficiently applied in the stored order using the custom metric.[1] Additionally, depending on the new edge weights it may be necessary to recompute some shortcuts.[3] For this to work, the contraction order has to be computed using metric-independent nested dissections.[2]
Extensions and Applications
CHs as described above search for a shortest path from one starting node to one target node. This is called one-to-one shortest path and is for example for car-navigation systems. Other applications include matching GPS traces to road segments and speeding up traffic simulators which have to consider the likely routes taken by all drivers in a network. Additionally, in route prediction one tries to estimate where a vehicle is likely headed by calculating how well its current and past positions agree with a shortest path from its starting point to any possible target. This can be efficiently done using CHs.[1]
In one-to-many scenarios, a starting node and a set of target nodes are given and the distance for all has to be computed. The most prominent application for one-to-many are point-of-interest queries. Typical examples include finding the closest gas station, restaurant or post office using actual travel time instead of geographical distance as metric.[1]
In the many-to-many shortest path scenario, a set of starting nodes and a set of target nodes are given and the distance for all has to be computed. This is used for example in logistic applications.[1] CHs can be extended to many-to-many queries in the following manner. First, perform a backward upward search from each . For each vertex scanned during this search, one stores in a bucket . Then, one runs a forward upward search from each , checking for each non-empty bucket, whether the route over the corresponding vertex improves any best distance. That is, if for any .[1][3]
Some applications even require one-to-all computations, i. e., finding the distances from a source vertex to all other vertices in the graph. As Dijkstra’s algorithm visits each edge exactly once and therefore runs in linear time it is theoretically optimal. However, Dijkstra’s algorithm is hard to parallelize and is not cache-optimal because of its bad locality. CHs can be used for a more cache-optimal implementation. For this, a forward upward search from followed by a linear scan over the shortcut-enriched graph is performed. In this linear scan, the distance values downward in the contraction hierarchy.[11] This second phase is independent of the source node , it can be therefore engineered to exploit parallelism and locality.[1]
In production, car-navigation systems should be able to compute fastest travel routes using predicted traffic information and display alternative routes. Both can be done using CHs.[1] The former is called routing with time-dependent networks where the travel time of a given edge is no longer constant but rather a function of the time of day when entering the edge. Alternative routes need to be smooth looking, significantly different from the shortest path but not significantly longer.[1]
CHs can be extended to optimize multiple metrics at the same time; this is called multi-criteria route planning. For example one could minimize both travel cost and time. Another example are electric vehicles for which the available battery charge constrains the valid routes as the battery may not run empty.[1]
References
- ^ a b c d e f g h i j k l m n o p q r Bast, Hannah; Delling, Daniel; Goldberg, Andrew V.; Müller-Hannemann, Matthias; Pajor, Thomas; Sanders, Peter; Wagner, Dorothea; Werneck, Renato F. (2016). "Route Planning in Transportation Networks". Algorithm Engineering. doi:10.1007/978-3-319-49487-6_2.
- ^ a b c d Dibbelt, Julian; Strasser, Ben; Wagner, Dorothea (5 April 2016). "Customizable Contraction Hierarchies" (PDF). Journal of Experimental Algorithmics. 21 (1): 1–49. doi:10.1145/2886843.
- ^ a b c d e f g h i j Geisberger, Robert; Sanders, Peter; Schultes, Dominik; Vetter, Christian (2012). "Exact Routing in Large Road Networks Using Contraction Hierarchies". Transportation Science. 46 (3).
- ^ Delling, Daniel; Sanders, Peter; Schultes, Dominik; Wagner, Dorothea (2009). "Engineering Route Planning Algorithms". Algorithmics of Large and Complex Networks. 5515.
- ^ "OSRM – Open Source Routing Machine".
- ^ "Wiki – OpenTripPlanner".
- ^ "Web – GraphHopper".
- ^ "GitHub – Tempus".
- ^ "GitHub – RoutingKit".
- ^ Bauer, Reinhard; Delling, Daniel; Sanders, Peter; Schieferdecker, Dennis; Schultes, Dominik; Wagner, Dorothea (2010-03-01). "Combining hierarchical and goal-directed speed-up techniques for dijkstra's algorithm". Journal of Experimental Algorithmics. 15: 2.1. doi:10.1145/1671970.1671976. ISSN 1084-6654.
- ^ Delling, Daniel; Goldberg, Andrew V.; Nowatzyk, Andreas; Werneck, Renato F. (2011). "PHAST: Hardware-Accelerated Shortest Path Trees". Parallel & Distributed Processing Symposium (IPDPS), 2011 IEEE International. doi:10.1109/ipdps.2011.89.
External links
Open Source Implementations
https://github.com/ifsttar/Tempus