-
Notifications
You must be signed in to change notification settings - Fork 20.5k
Closed
Labels
Description
What would you like to Propose?
I would like to propose adding an implementation of Dinic's Algorithm to the graph module. It is an efficient technique for solving maximum flow problems in directed graphs using a layered BFS along with a DFS blocking flow. It performs better than Ford-Fulkerson and Edmonds-Karp in many cases.
Issue details
Dinic’s Algorithm
-
Start with a directed graph
- Each edge has a capacity (how much flow it can carry).
- Given a source node s and a sink node t.
-
Build a level graph using BFS
- This graph only keeps edges that go from one layer to the next (level i to level i+1).
- It focuses only on the shortest paths from s to t, skipping the inefficient ones.
-
Find a blocking flow using DFS
- Try to push flow from s to t through the level graph.
- Stop when every path hits a full edge (no more flow can be pushed).
-
Repeat the process
- Rebuild the level graph and find another blocking flow.
- Keep doing this until the BFS can’t reach the sink anymore (no more flow is possible).
-
Return the total flow
- Add up all the flow pushed from s to t across all iterations.
- That is maximum flow
References:
https://cp-algorithms.com/graph/dinic.html
https://en.wikipedia.org/wiki/Dinic%27s_algorithm
Additional Information
No response