Skip to content

[FEATURE REQUEST] Add Dinic's Algorithm to the Graph Algorithms #6731

@ni-ms

Description

@ni-ms

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

  1. 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.
  2. 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.
  3. 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).
  4. 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).
  5. 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions