Skip to content

Refactor: Optimize Dijkstra's algorithm and fix Yen's algorithm call#12

Open
yan-qi wants to merge 1 commit intomasterfrom
optimize-dijkstra-yens-fix
Open

Refactor: Optimize Dijkstra's algorithm and fix Yen's algorithm call#12
yan-qi wants to merge 1 commit intomasterfrom
optimize-dijkstra-yens-fix

Conversation

@yan-qi
Copy link
Copy Markdown
Owner

@yan-qi yan-qi commented May 24, 2025

Dijkstra's Algorithm Optimization:

  • I replaced std::multiset with std::priority_queue for the candidate vertices in DijkstraShortestPathAlg.
  • This changes the complexity of the decrease-key operation from O(N) to an effective O(log V) by re-pushing updated vertices.
  • I modified the WeightLess comparator in GraphElements.h to ensure std::priority_queue functions as a min-priority queue.

Yen's Algorithm Fix:

  • I corrected a call in YenTopKShortestPathsAlg::next() method.
  • I changed the call from the non-existent reverse_tree.get_shortest_path_flower(m_pTargetVertex) to reverse_tree.determine_shortest_paths(NULL, m_pTargetVertex, false).
  • This ensures Yen's algorithm correctly uses Dijkstra's functionality for its reverse path computation phase.

These changes aim to improve the performance of shortest path calculations and ensure the correctness of Yen's K-shortest paths algorithm.

Dijkstra's Algorithm Optimization:
- I replaced `std::multiset` with `std::priority_queue` for the candidate vertices in `DijkstraShortestPathAlg`.
- This changes the complexity of the decrease-key operation from O(N) to an effective O(log V) by re-pushing updated vertices.
- I modified the `WeightLess` comparator in `GraphElements.h` to ensure `std::priority_queue` functions as a min-priority queue.

Yen's Algorithm Fix:
- I corrected a call in `YenTopKShortestPathsAlg::next()` method.
- I changed the call from the non-existent `reverse_tree.get_shortest_path_flower(m_pTargetVertex)` to `reverse_tree.determine_shortest_paths(NULL, m_pTargetVertex, false)`.
- This ensures Yen's algorithm correctly uses Dijkstra's functionality for its reverse path computation phase.

These changes aim to improve the performance of shortest path calculations and ensure the correctness of Yen's K-shortest paths algorithm.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant