Fact-checked by Grok 2 weeks ago

Contraction hierarchies

Contraction hierarchies (CH) is a preprocessing algorithm for accelerating exact shortest path queries in large directed graphs, particularly road networks used for route planning. Developed by researchers at the , it constructs a hierarchy by iteratively contracting vertices in order of increasing importance—measured by heuristics like edge count and connectivity—while adding shortcut edges to preserve shortest path distances between remaining vertices. During queries, bidirectional is employed on the resulting overlaid graph, restricting searches to upward (to higher-level vertices) and downward (from higher-level vertices) edges, which dramatically prunes the search space. This method, introduced in 2008, achieves query times orders of magnitude faster than standard —often under 1 millisecond for continental-scale networks—while using less memory than the original graph due to efficient shortcut selection. The core innovation of contraction hierarchies lies in its simple yet effective preprocessing phase, which eliminates the need for complex or transit node selections common in prior hierarchical techniques. Vertices are assigned levels based on contraction order, with shortcuts ensuring that paths through contracted vertices are replicated exactly. This approach excels in weighted graphs with non-negative weights, such as those modeling travel times or distances, and has been shown to handle networks with millions of vertices and edges, like the entire European road system. Extensions include time-dependent variants for dynamic traffic conditions and customizable versions for multi-modal or profile-based routing, where preprocessing adapts to user-specific costs like types. In practice, contraction hierarchies have become a cornerstone of high-performance systems, powering applications in software, , and geographic systems (GIS). For instance, mobile implementations achieve sub-10-millisecond queries on resource-constrained devices, making routing feasible without server dependency. The algorithm's open-source availability under the AGPL has facilitated widespread adoption and further , including parallel preprocessing for scalability on modern hardware. Despite its strengths, CH assumes static graphs in its basic form, though hybrid methods combine it with other speed-up techniques for evolving networks. Overall, contraction hierarchies exemplify how graph preprocessing can preprocessing time, space efficiency, and query speed for real-world computational challenges.

Introduction

Overview and Motivation

Contraction hierarchies are a preprocessing technique designed to accelerate exact shortest queries in large weighted directed graphs, particularly those modeling real-world like road systems. The method constructs a hierarchical structure by iteratively removing nodes deemed low in importance and inserting shortcut edges to ensure that shortest path distances between remaining nodes are preserved. This preprocessing step enables subsequent queries to traverse the hierarchy efficiently, often achieving sub-millisecond response times for practical applications. The underlying problem addressed is finding the shortest path—the minimum-weight path—from a to a target node in a where edges carry non-negative weights representing costs such as travel times. provides an exact solution by maintaining a priority queue of nodes, expanding them in order of increasing tentative distance from the source until the target is reached. However, in massive graphs typical of road networks, which can contain tens of millions of nodes (e.g., over 20 million for the continental United States) and edges, the algorithm's worst-case time complexity of O((V + E) log V) leads to prohibitive runtimes, as it may explore a large fraction of the graph even for distant source-target pairs. The primary motivation for contraction hierarchies stems from the demands of route planning in navigation systems, where users require instantaneous computation of optimal routes amid dynamic queries. Standard Dijkstra implementations are too slow for such interactive use on continent-scale networks, prompting the need for speed-up techniques that deliver exact results with minimal preprocessing overhead relative to query gains. Contraction hierarchies achieve this by investing moderate preprocessing time to create a static , dramatically reducing online computation—often by orders of magnitude—while maintaining exactness without approximations. At its core, the approach relies on basic : directed graphs with nodes representing junctions and weighted edges denoting traversable segments with associated costs. Shortest paths generalize distance minimization to these weighted settings, solved fundamentally by Dijkstra's priority-queue mechanism, which contraction hierarchies augment through structural simplification rather than altering the core search paradigm.

Historical Development

Contraction hierarchies were invented in 2008 by Robert Geisberger, Peter Sanders, Dominik Schultes, and Daniel Delling at the University of , as detailed in their seminal paper presented at the 7th International Workshop on Experimental and Efficient Algorithms. This work introduced a hierarchical routing technique based on iterative node contraction to accelerate shortest-path computations in road networks, building on prior hierarchical methods but simplifying the preprocessing and query phases for greater efficiency. The approach quickly gained traction for its balance of preprocessing effort and query speed, enabling exact routing on large-scale graphs. Early adoption focused on ensuring exactness and . In 2012, Geisberger, Sanders, Schultes, and Christian Vetter extended the to handle exact shortest paths across entire continental road networks, such as and , demonstrating practical viability for real-world systems. Initial benchmarks from the foundational work reported preprocessing times ranging from tens of seconds to several hours on graphs with tens of millions of nodes and edges, such as the European road with over 18 million nodes, while achieving average query times below 200 microseconds on modern hardware. Further refinements in 2012 integrated contraction hierarchies with A* search using geometric potentials to improve query performance without sacrificing exactness. Key contributors to the evolution of contraction hierarchies include Hannah Bast, Daniel Delling, and Peter Sanders, whose collaborative efforts advanced its theoretical and practical foundations. Their 2016 survey paper provided a comprehensive overview of the technique's integration into broader route planning frameworks, underscoring its role in achieving sub-millisecond query times for transportation networks. Early extensions, such as customizable variants for dynamic edge weights, emerged around this period to address real-time updates like traffic variations.

Core Algorithm

Preprocessing

The preprocessing phase of contraction hierarchies constructs an augmented that preserves all shortest paths from the original while enabling efficient queries. This offline process begins with computing a node ordering that determines the sequence in which vertices are contracted, prioritizing the removal of less important to minimize the introduction of shortcuts and maintain structure. Node ordering is computed using a priority function h(v) for each vertex v, where nodes with smaller h(v) values are processed first to ensure that more central or important nodes are contracted later, forming the hierarchy's upper levels. Common heuristics for h(v) include the edge difference (number of shortcuts added minus the node's incident edges), vertex degree, and the size of Voronoi regions associated with the node, often combined in a weighted sum for balanced performance. Greedy bottom-up strategies, such as those based on edge difference or vertex degree, iteratively select the node with the lowest , while randomized variants introduce perturbations to explore better orderings and reduce preprocessing time. Nested dissection heuristics can also be applied to approximate balanced separators, further optimizing the order for large graphs. Once the ordering is established, the contraction process proceeds sequentially: for each v in the computed order, v is removed from the , and shortcuts are added between its neighbors to preserve shortest paths passing through v. Specifically, for every pair of neighbors u (with an incoming edge to v) and w (with an outgoing edge from v), a shortcut edge \langle u, w \rangle with weight c(u, v) + c(v, w) is added if \langle u, v, w \rangle constitutes the only shortest path from u to w in the current ; this condition is verified using limited bidirectional Dijkstra searches (with hop limits of 1 to 5) to compute distances without full . The searches ensure that shortcuts are added only when necessary, avoiding redundancy while maintaining exact distances. The output of preprocessing is an augmented split into upward (G^\uparrow) and downward (G^\downarrow) components, containing the original edges plus the added shortcuts, along with assigned levels (or ranks) to each node—lower ranks for contracted nodes and higher ranks for those remaining at the top of the . These ranks, assigned based on the order, serve as a byproduct to guide query processing by restricting searches to non-decreasing or non-increasing rank paths. The space overhead from shortcuts typically results in 2 to 10 times the number of original edges, though for road networks like the or benchmarks, it often stays around 2-3 times, with preprocessing times scaling to minutes for graphs with tens of millions of edges.

Query Processing

Query processing in contraction hierarchies leverages the preprocessed graph structure, where each is assigned a during preprocessing to establish a of importance, with higher-ranked nodes representing more central or "highway-like" parts of the network. To compute the shortest path from a source s to a target t, a bidirectional variant of Dijkstra's algorithm is employed. The forward search starts from s and proceeds upward, traversing only edges to nodes with higher ranks (ascending the hierarchy), while the backward search starts from t and proceeds downward, traversing only edges to nodes with lower ranks (descending the hierarchy). This restricted search prunes the exploration space by ignoring downward edges in the upward search and upward edges in the downward search, significantly reducing the number of nodes settled compared to standard Dijkstra. The two searches continue alternately until they meet at a common node v, which is guaranteed to lie on the shortest path due to the hierarchy's properties preserving distances. At this point, the tentative shortest path is formed by combining the path from s to v in the forward search and from v to t in the backward search. To retrieve the actual path, predecessors are traced back from v to s and from v to t, accounting for shortcuts introduced during preprocessing; each shortcut is unpacked by recursively applying the same procedure on the bypassed nodes, though in practice, a single level of unpacking often suffices for road networks. If cycles are detected during combination, they are removed to ensure a simple path. For more complex scenarios involving non-simple paths, nesting allows recursive application of the hierarchy on subgraphs, but this is rarely needed as the core method handles most queries efficiently. In a road network example, querying the shortest path from city A to city B might involve the forward search quickly ascending to major highways (high-rank nodes) and the backward search descending from B to connect via interchanges, exploring far fewer local streets than an unrestricted search would require. This approach achieves query times in the microseconds range on large graphs, such as the 18 million node road network.

Variants

Customized Contraction Hierarchies

Customizable Contraction Hierarchies (CCH) extend the standard Contraction Hierarchies approach by decoupling the topology-based preprocessing from weight-dependent computations, enabling efficient adaptation to multiple edge weight configurations without rebuilding the entire hierarchy. This separation allows the core hierarchy to be constructed once using the unweighted graph structure, while subsequent customizations handle scenario-specific weights, such as travel time versus distance or adjustments for costs. The concept of this three-phase —preprocessing, customization, and querying—was introduced by Delling et al. to support route planning under varying metrics in road networks. In the contraction phase, a metric-independent ordering, often derived from nested dissection, is computed on the undirected, unweighted to establish the and initial shortcuts. The customization phase then adapts this to a specific weight function by propagating distances in along the elimination tree, updating shortcut weights to preserve shortest paths for the given ; this involves lower triangles of the to set each shortcut's weight to the minimum over possible intermediate paths. For example, in scenarios with dynamic traffic conditions, can incorporate real-time edge weight updates, such as increased travel times on congested roads, without altering the underlying . This approach offers significant benefits for applications requiring frequent weight changes, as the customization phase is substantially faster than a full contraction rebuild—often taking seconds rather than minutes on large graphs like continental road networks with millions of vertices. Query processing remains bidirectional Dijkstra on the customized hierarchy, achieving sub-millisecond response times comparable to or better than standard Contraction Hierarchies for non-standard metrics like distance, while supporting multiple scenarios from a single preprocessing.

Advanced Variants

One significant extension to contraction hierarchies addresses the preprocessing bottleneck through parallelization, enabling efficient construction on massive graphs. The Scalable Parallelization of Contraction Hierarchies (SPoCH) algorithm, developed in 2025, parallelizes the node contraction phase by distributing computations across threads using advanced data structures and careful to minimize overhead. This results in near-linear speedups on multi-core processors, with reported improvements of 11–68× over sequential baselines and 3.8–41× over prior parallel methods, scaling effectively to road networks with billions of edges while maintaining comparable query times and hierarchy sizes. To support dynamic environments like road networks with frequent updates such as closures or weight changes, incremental update mechanisms allow local modifications to the hierarchy without rebuilding from scratch. The 2023 fully dynamic contraction hierarchies with label restrictions algorithm by Li et al. employs an propagation chain to identify and recompute only affected shortcuts, incorporating optimizations based on weight counts for bounded complexity O(|ΔE| log |ΔE| + |ΔE| d_max), where ΔE denotes changed edges and d_max the maximum degree. This approach handles edge insertions, deletions, and label/weight adjustments efficiently, as demonstrated on real-world graphs, making it suitable for time-sensitive applications like systems. A batch variant further enhances performance through bottom-up layer processing and parallelism. Further innovations include hybrids of contraction hierarchies with A* search algorithms tailored for ultra-large graphs, where the hierarchy guides bidirectional searches augmented by admissible potentials to prune exploration more aggressively. These advanced variants address key limitations of the original contraction hierarchies, particularly in and adaptability. Parallel methods reduce preprocessing times from hours to minutes for continental-scale datasets, facilitating frequent rebuilds in production systems. Incremental techniques enable real-time responses to graph changes in apps, ensuring up-to-date without prohibitive costs.

Applications

In Road Networks

Contraction hierarchies find their primary application in vehicular on networks, where they enable fast computation of exact shortest paths for car navigation systems in commercial services since the late 2000s. These systems model networks as directed graphs to account for one-way streets and complex turn restrictions, preserving path optimality during preprocessing by adding shortcuts that bypass contracted nodes. This approach ensures efficient handling of large-scale, real-world topologies while supporting dynamic queries essential for on-the-go route guidance. In benchmarks on the road network, comprising approximately 18 million nodes and 42 million edges, contraction hierarchies achieve bidirectional query times of 10-50 microseconds on standard hardware, enabling sub-millisecond responses suitable for interactive applications. Commercial routing software, such as PTV VISUM, incorporates contraction hierarchies to optimize traffic assignment and network loading in , leveraging their speed for large-scale simulations and analyses. Extensions of contraction hierarchies for road networks often combine them with landmark-based techniques, such as , to provide tighter initial distance bounds and further accelerate queries in dynamic scenarios like varying traffic conditions. In traffic simulation tools like , contraction hierarchies support efficient routing for microscopic models, computing shortest paths across urban and intercity networks to simulate vehicle flows accurately. A notable involves across the continental road network, with over 24 million nodes, where contraction hierarchies reduce query times by 100 to 1000 times compared to plain , shifting performance from seconds to microseconds and making continent-wide navigation feasible in .

Other Domains

Contraction hierarchies have been adapted for public transit , particularly in timetable-based networks where transfers between vehicles must be modeled. In 2010, Geisberger introduced a contraction approach for timetable networks using a graph model that incorporates realistic times, avoiding the need for fully expanded time-dependent graphs while enabling efficient shortest-path queries for journey planning. This method has been extended to scenarios, combining public transit with walking or other modes, as surveyed in Bast et al. (2016), where contraction hierarchies facilitate fast queries on integrated graphs representing time-dependent connections and transfers. In and , contraction hierarchies support efficient path computation on facility graphs, such as those modeling warehouse-to-warehouse routes or last-mile delivery networks. For instance, open-source engines like GraphHopper, which implement contraction hierarchies, are integrated into logistics platforms to optimize vehicle problems by accelerating shortest- calculations on non-spatial or hybrid graphs of distribution centers and depots. A 2024 study on AI-driven fleet optimization in last-mile logistics demonstrates the use of contraction hierarchies within GraphHopper to compute precise routes, reducing computational overhead in dynamic supply chain scenarios. Beyond transportation, contraction hierarchies find application in non-spatial domains for shortest-path problems on abstract graphs. In social networks, contraction hierarchies compute influence paths—shortest sequences of connections propagating information—outperforming standard Dijkstra on large-scale graphs. Post-2020 experiments in game AI have applied contraction hierarchies to pathfinding on grid-based maps, enabling real-time navigation for non-player characters in complex environments; a 2023 study on alternative paths in game maps reports query speeds 10-100 times faster than baseline A* on weighted grids simulating urban or fantasy terrains. Adapting contraction hierarchies to dense graphs poses challenges due to increased shortcut creation during preprocessing, leading to higher space and time costs. To address this, techniques combining contraction with —such as in PReaCH (Pruned Reachability Contraction Hierarchies)—remove redundant edges early, maintaining efficiency on dense structures like citation or biological networks while preserving query correctness. In mobility data analysis, these adaptations support GPS trace matching, where contraction hierarchies prune candidate paths on road graphs to align noisy trajectories with maps, as demonstrated in a 2011 algorithm that reduces matching time by orders of magnitude on real-world GPS datasets. Such combinations leverage preprocessing shortcuts to handle the irregularity of abstract or time-varying graphs without full recomputation. Recent advances as of 2025 include parallel implementations of contraction hierarchies for faster preprocessing on large-scale networks.

Theoretical Foundations

Complexity and Performance Bounds

The preprocessing phase of contraction hierarchies involves computing a ordering and constructing shortcut edges, with a theoretical of O(n^2 \log n + n m) for randomized contraction strategies, where n is the number of and m is the number of edges. This bound accounts for the expected cost of shortcut computations and operations during contractions. In practice, preprocessing times scale with graph size; for instance, on a North American network with approximately 24 million and 58 million edges, it requires about 10 to 28 minutes on standard hardware using economical to aggressive settings. Space requirements for the resulting hierarchy exhibit a worst-case bound of O(m + n^2), arising from the potential addition of up to quadratically many shortcuts in dense graphs during contractions. However, for road networks, the practical space usage remains linear in the input size, with shortcuts typically adding 2 to 5 times the original number of edges, leading to total memory footprints of 100 to 500 MB for continental-scale graphs with tens of millions of edges. This efficiency stems from storing upward and downward graphs separately with direction flags, often resulting in net space savings relative to the input graph plus auxiliary structures. Query processing employs bidirectional Dijkstra searches pruned by the , with a theoretical complexity of O(n \log n) per Dijkstra run in the absence of pruning, but hierarchy constraints reduce the expected number of explored nodes to O(\sqrt{n}) on road under randomized preprocessing. Empirically, queries complete in microseconds on large networks; for example, on a 34-million-node with 75 million edges, average query times range from 1.9 to 2.3 milliseconds, exploring only a few hundred nodes per query. On graphs with around 100 million edges, such as extended continental road networks, early benchmarks from to report preprocessing times of approximately 1 hour on single-threaded standard hardware, though parallel implementations have since reduced this to minutes while maintaining query performance in the range. These bounds highlight contraction hierarchies' suitability for large-scale applications, balancing preprocessing investment with rapid queries. Contraction hierarchies (CH) draw on several graph-theoretic concepts to explain their empirical efficiency, particularly in transportation networks. A key foundation is the highway dimension, a parameter h that captures the sparsity of "highways" in a —sets of vertices that cover all shortest paths longer than a radius r, with the size of such sets bounded by h. Low highway dimension ensures that CH preprocessing adds few shortcuts and limits search spaces during queries, as the hierarchy aligns with these sparse covers. For real-world road networks, empirical evidence indicates low values of h, explaining the small query sizes (often under 500 vertices) observed in practice. CH also benefits from analysis in bounded growth graphs, a class where the number of vertices within distance r grows at most polynomially in r, encompassing planar graphs and road networks. In such graphs, CH queries run in O(\sqrt{n} \log n) time, as the hierarchy prunes exploration exponentially with depth, avoiding full graph traversal. This relates closely to planar embeddings, where bounded growth ensures the shortcuts added during contraction remain sparse. Fundamentally, CH provides exact shortest paths in any undirected with non-negative edge weights, with no involved—the hierarchy preserves all distances via shortcuts. Efficiency in practice stems from low doubling , where the requires few balls to cover doubled-radius neighborhoods; small doubling (implied by low ) bounds the branching in CH searches. These concepts address performance gaps: CH vastly outperforms A* on low-h road networks due to reduced search spaces, but degrades on high-diameter graphs with large h, where shortcuts proliferate without distant pairs effectively.

References

  1. [1]
    Contraction hierarchies: faster and simpler hierarchical routing in ...
    Our algorithm calculates exact shortest paths and handles road networks of whole continents.<|control11|><|separator|>
  2. [2]
    Faster and Simpler Hierarchical Routing in Road Networks
    Authors and Affiliations · Robert Geisberger · Peter Sanders · Dominik Schultes · Daniel Delling.Missing: original | Show results with:original
  3. [3]
    [PDF] Exact Routing in Large Road Networks Using Contraction Hierarchies
    Contraction hierarchies use node contraction and shortcut edges to remove unimportant nodes, preserving shortest path distances in road networks.
  4. [4]
    KIT – ITI Algorithm Engineering – Forschung - Routeplanning
    ### Contraction Hierarchies: Definition, History, Key Papers, Applications
  5. [5]
    Exact Routing in Large Road Networks Using Contraction Hierarchies
    Apr 5, 2012 · Contraction hierarchies are a simple approach for fast routing in road networks. Our algorithm calculates exact shortest paths and handles ...
  6. [6]
    [PDF] Contraction Hierarchies: Faster and Simpler Hierarchical Routing in ...
    Jul 1, 2008 · Abstract. We present a route planning technique solely based on the concept of node contraction. We contract or remove one node at a time ...
  7. [7]
    Contraction Hierarchies with A* for digital road maps - SpringerLink
    Apr 14, 2012 · Conference paper. Contraction Hierarchies with A* for digital road maps. Conference paper; First Online: 01 January 2012. pp 311–316; Cite this ...
  8. [8]
    [1504.05140] Route Planning in Transportation Networks - arXiv
    Apr 20, 2015 · We survey recent advances in algorithms for route planning in transportation networks. For road networks, we show that one can compute driving directions in ...
  9. [9]
    [PDF] Contraction Hierarchies: Faster and Simpler Hierarchical Routing in ...
    Contraction hierarchies (CHs) are created by iteratively contracting nodes, replacing paths through them with shortcuts, preserving shortest paths. This is ...
  10. [10]
    [1402.0402] Customizable Contraction Hierarchies - arXiv
    Feb 3, 2014 · Access Paper: View a PDF of the paper titled Customizable Contraction Hierarchies, by Julian Dibbelt and 2 other authors. View PDF · TeX Source.Missing: original | Show results with:original
  11. [11]
    Parallel Contraction Hierarchies Can Be Efficient and Scalable - arXiv
    Dec 23, 2024 · SPoCH is a new parallel algorithm for Contraction Hierarchies, achieving speedups of 11 to 68 times over sequential and 3.8 to 41 times over ...
  12. [12]
  13. [13]
    PTV Visum - Transportation Planning Software
    The PTV Visum algorithms are therefore continuously optimized with new methods and techniques, such as contraction hierarchies and parallel processing.PTV Visum Publisher Data... · Start free trial · Public Transportation Planning
  14. [14]
    Routing - Eclipse SUMO - Simulation of Urban MObility
    Sep 18, 2025 · CH (Contraction Hierarchies)#. Contraction Hierarchies is a preprocessing-based routing algorithm. This is very efficient when a large number of ...
  15. [15]
    Contraction of timetable networks with realistic transfers
    We contribute a fast routing algorithm for timetable networks with realistic transfer times. In this setting, our algorithm is the first one that ...
  16. [16]
    Enhancing Last-Mile Logistics: AI-Driven Fleet Optimization, Mixed ...
    To minimize the first component, GraphHopper is configured to use Contraction Hierarchies [55], a technique that introduces precomputed “shortcuts” in the ...<|control11|><|separator|>
  17. [17]
  18. [18]
    [PDF] Approximation Algorithm for Shortest Path in Large Social Networks
    Feb 6, 2020 · Contraction Hierarchies: Faster and Simpler Hierarchical. Routing in Road Networks. In International Workshop on Experimental and Efficient ...
  19. [19]
    Efficiently computing alternative paths in game maps
    Jul 19, 2023 · Below, we discuss two of the most popular shortest path algorithms for road networks namely contraction hierarchies and hub labeling.
  20. [20]
    [PDF] PReaCH: A Fast Lightweight Reachability Index using Pruning and ...
    Apr 17, 2014 · We demonstrate how the successful speedup technique Contraction Hierarchies (CH) [12] can be adapted to the reachability problem. To demonstrate ...
  21. [21]
    [PDF] Algorithms for Matching and Predicting Trajectories
    As can be seen from this table, the use of contraction hierarchies drastically reduces the number of Dijkstra operations and, for GPS-sized measurement.
  22. [22]
    [PDF] Provable Efficiency of Contraction Hierarchies with Randomized ...
    We introduce a method to construct randomized Contraction. Hierarchies on road networks as well as a probabilistic query routine. Our analysis reveals that ...
  23. [23]
    [PDF] Contraction Hierarchies on Grid Graphs - Uni Freiburg
    In this paper, we describe an offline, optimal and unspecific technique to efficiently retrieve shortest paths in grid graphs. We will come back to similarities ...
  24. [24]
    [PDF] Highway Dimension, Shortest Paths, and Provably Efficient Algorithms
    We now return to the contraction hierarchies al- gorithm (CH), described in Section 4.1. Recall that its query is essentially bidirectional Dijkstra with ad-.
  25. [25]
    Sublinear Search Spaces for Shortest Path Planning in Grid and ...
    Apr 26, 2018 · In this paper, we use the very intuitive notion of bounded growth graphs to describe road networks and also grid graphs. We show that this model ...
  26. [26]
    [PDF] Contraction Hierarchies: Faster and Simpler Hierarchical Routing in ...
    Abstract. We present a route planning technique solely based on the concept of node contraction. The nodes are first ordered by 'importance'.