★ Maximum flow algorithms in practice [00SL]
Ford-Fulkerson is actually a kind of meta-algorithm: it specifies the method of repeatedly augmenting along s-t paths in the residual network (augmenting paths) but it doesn’t actually specify how to find augmenting paths. Without specifying how to find augmenting paths at all, we proved that Ford-Fulkerson will run in O(EC) time, where E is the number of edges and C is the total capacity leaving the source (or the total capacity entering the sink, whichever is smaller). But if we are more careful about how we find augmenting paths we can do better.
- The most straightforward way is to simply use a DFS from s to t in the residual network. This works fine but not particularly well; depending on the graph it can exhibit the worst case O(EC) behavior.
- We can use BFS in the residual network to find the shortest augmenting path on each iteration. This is called the Edmonds-Karp algorithm, and it can be shown (though the proof is outside the scope of this course) that it runs in O(VE^2)—in particular, the running time does not depend on the capacities. This algorithm works very well in practice, and often runs much faster than the worst case, behaving more like \Theta (E^{3/2}).
- We could use a variant of Dijkstra’s algorithm to find the maximum capacity augmenting path on each iteration. This seems like it would be a good idea, but in practice it is usually slower than Edmonds-Karp.
- Finally, there is a clever method, Dinitz’s Algorithm, which instead of finding just a single augmenting path each iteration, sends flow along multiple augmenting paths at once. (Note: it is often known as Dinic’s Algorithm, but this is due to a misspelling of the name of its inventor, Yefim Dinitz.) It works as follows:
- Do a BFS from s in the residual network and label every vertex with its level in the BFS tree.
- Now do a DFS from s in the residual network, only taking edges which go from level i to i+1; as we recurse through the graph, keep track of the available flow and the minimum residual capacity along the path to each point. Once we reach s we can unroll the recursion and update flow values with the minimum capacity seen along the path, and subtract the augmenting flow from the available flow. Instead of stopping, however, we keep going to try to augment along as many paths as we can. If we encounter a vertex from which it’s impossible to reach t, we mark it so we know not to visit it if we ever encounter it again.
There are many other approaches to finding maximum flows as well (preflow-push/push-relabel, simplex…), which can have even better asymptotic running times, work better on certain types of graph, or solve more complex max flow variants (max circulation, min-cost max flow, …), but for most practical max flow problems you will encounter, Edmonds-Karp or Dinitz should work just fine!