This directory collects algorithms for the maximum-flow problem: given a
directed graph whose edges have capacities, a source, and a sink, how
much flow can be pushed from source to sink without exceeding any edge's
capacity?
Maximum flow turns up all over the place — routing traffic through a network, matching people to jobs, scheduling, image segmentation, and any problem that can be phrased as "move as much as possible from here to there through a shared network." Its close relative, the minimum cut, finds the cheapest set of edges whose removal disconnects the sink from the source, and the max-flow min-cut theorem says the two always have the same value.
New to the topic? These are good starting points:
- https://en.wikipedia.org/wiki/Maximum_flow_problem
- https://en.wikipedia.org/wiki/Flow_network
- https://en.wikipedia.org/wiki/Max-flow_min-cut_theorem
All four compute the same maximum-flow value; they differ in speed and in how the graph is represented.
- Just learning the idea? Start with
ford_fulkerson.pyandminimum_cut.py— the augmenting-path picture is the most intuitive. - Sparse graph, or parallel edges? Reach for
dinic.py; the adjacency-list representation and level-graph batching make it fast in practice. - Dense graph?
push_relabel.pytends to win, because it avoids re-scanning long augmenting paths.
Each file is self-contained, fully type-hinted, and verified with doctests — run
any of them directly (for example python networking_flow/dinic.py) to execute
the tests.
