Refactor: Optimize Dijkstra's algorithm and fix Yen's algorithm call#12
Open
Refactor: Optimize Dijkstra's algorithm and fix Yen's algorithm call#12
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Dijkstra's Algorithm Optimization:
std::multisetwithstd::priority_queuefor the candidate vertices inDijkstraShortestPathAlg.WeightLesscomparator inGraphElements.hto ensurestd::priority_queuefunctions as a min-priority queue.Yen's Algorithm Fix:
YenTopKShortestPathsAlg::next()method.reverse_tree.get_shortest_path_flower(m_pTargetVertex)toreverse_tree.determine_shortest_paths(NULL, m_pTargetVertex, false).These changes aim to improve the performance of shortest path calculations and ensure the correctness of Yen's K-shortest paths algorithm.