Skip to content

[FEATURE REQUEST] HARD: Contraction Hierarchies Algorithm (Optimized Shortest Path) #6244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
DenizAltunkapan opened this issue May 21, 2025 · 0 comments

Comments

@DenizAltunkapan
Copy link
Collaborator

What would you like to Propose?

implementing the Contraction Hierarchies (CH) algorithm, a powerful preprocessing-based technique for extremely fast shortest path queries in large static graphs (e.g., road networks). It builds a node hierarchy and introduces shortcut edges to reduce query times significantly while maintaining exact path lengths.
CH is an optimization over Dijkstra’s algorithm using preprocessing. It first "contracts" nodes by removing them and adding shortcut edges that preserve shortest paths. Each node is assigned a level based on its contraction order. During queries, only upward edges (edges to higher-level nodes) are traversed, enabling extremely fast bidirectional search.

Issue details

  1. Preprocessing Phase
  • Compute a contraction order of nodes.

  • For each node:
    - Remove it from the graph.
    - Add shortcut edges between its neighbors if needed (to preserve shortest path distances).
    - Assign the node a level: nodes contracted earlier get lower levels.

  1. Query Phase
  • Use bidirectional Dijkstra from source and target.
  • Only traverse upward edges in both directions.
  • Maintain two distance maps (forward and backward).
  • Combine the two searches at meeting nodes to compute the final shortest path.
  1. Data Structures
  • Graph class with support for forward and backward adjacency lists.
  • Node class with ID and level.
  • Edge class with weights, direction, and possibly a "shortcut flag".
  • Use Java’s PriorityQueue for efficient query processing.

Additional Information

This proposal is just one suggested structure. You're welcome to adjust the implementation details, class design, or performance strategies. The core goal is to provide a clean and educational CH implementation in pure Java for the community.

More Details on CH:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant