-
Notifications
You must be signed in to change notification settings - Fork 313
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
feat: Implement Yen's Algorithm for K-Shortest Paths #625
base: main
Are you sure you want to change the base?
Conversation
- Added Yen's Algorithm implementation to find the K shortest paths between two nodes in a graph. - Supports applications in network routing, transportation planning, and logistics. - Includes test cases to validate the correctness of the implementation. - Optimized for performance and usability within the graph algorithms module.
pydatastructs/graphs/algorithms.py
Outdated
@@ -11,6 +11,8 @@ | |||
from pydatastructs.graphs.graph import Graph | |||
from pydatastructs.linear_data_structures.algorithms import merge_sort_parallel | |||
from pydatastructs import PriorityQueue | |||
from copy import deepcopy | |||
import heapq |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do have heapq
implemented in PyDataStructs? I think PriorityQueue
and heapq
are the same?
from pydatastructs.utils.raises_util import raises | ||
import pytest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to import this.
for i, path in enumerate(k_shortest_paths): | ||
assert path == expected_paths[i], f"Path {i} does not match expected path. Got {path}, expected {expected_paths[i]}" | ||
|
||
_test_yen_algorithm("List") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't we support matrix representation of graphs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't we support matrix representation of graphs?
The AdjacencyMatrix implementation does not support dynamic modifications like removing vertices or edges during runtime. Since Yen's algorithm requires modifying the graph (e.g., removing edges and vertices to find alternative paths), it cannot work with the AdjacencyMatrix implementation in its current form.
✨ Feature: Yen's Algorithm for K-Shortest Paths
FIXES: #622
📌 Description
This PR introduces Yen's Algorithm, which finds the K shortest paths between a source and destination node in a graph. The algorithm efficiently computes multiple alternative paths, making it useful for applications such as:
🛠️ Changes