Lably
Skip to content

Ford–Fulkerson algorithm

Algorithm to compute the maximum flow in a network

  • 10 min read
  • 5 chapters

Related on Lably

Through Assignment (computer science) and Big O notation

The idea behind the algorithm is as follows: as long as there is a path from the source (start node) to the sink (end node), with available capacity on all edges in the path, we send flow along one of the paths. Then we find another path, and so on. A path with available capacity is called an augmenting path.

Algorithm

Let G(V,E) be a graph, and for each edge from u to v, let c(u,v) be the capacity and f(u,v) be the flow. We want to find the maximum flow from the source s to the sink t. After every step in the algorithm the following is maintained:

This means that the flow through the network is a legal flow after each round in the algorithm. We define the residual network Gf(V,Ef) to be the network with capacity cf(u,v)=c(u,v)−f(u,v) and no flow. Notice that it can happen that a flow from v to u is allowed in the residual network, though disallowed in the original network: if f(u,v)>0 and c(v,u)=0 then cf(v,u)=c(v,u)−f(v,u)=f(u,v)>0.

<b>Algorithm</b> Ford<span typeof="mw:Entity">–</span>Fulkerson
Inputs Given a Network G=(V,E) with flow capacity c, a source node s, and a sink node t
Output Compute a flow f from s to t of maximum value
  1. f(u,v)←0 for all edges (u,v)
  2. While there is a path p from s to t in Gf, such that cf(u,v)>0 for all edges (u,v)∈p:
    1. Find cf(p)=min{cf(u,v):(u,v)∈p}
    2. For each edge (u,v)∈p
      1. f(u,v)←f(u,v)+cf(p) (Send flow along the path)
      2. f(v,u)←f(v,u)−cf(p) (The flow might be "returned" later)
  • "←" denotes assignment. For instance, "largest ← item" means that the value of largest changes to the value of item.
  • "return" terminates the algorithm and outputs the following value.

The path in step 2 can be found with, for example, breadth-first search (BFS) or depth-first search in Gf(V,Ef). The former is known as the Edmonds–Karp algorithm.

When no more paths in step 2 can be found, s will not be able to reach t in the residual network. If S is the set of nodes reachable by s in the residual network, then the total capacity in the original network of edges from S to the remainder of V is on the one hand equal to the total flow we found from s to t, and on the other hand serves as an upper bound for all such flows. This proves that the flow we found is maximal. See also Max-flow Min-cut theorem.

If the graph G(V,E) has multiple sources and sinks, we act as follows: Suppose that T={t∣t is a sink} and S={s∣s is a source}. Add a new source s∗ with an edge (s∗,s) from s∗ to every node s∈S, with capacity c(s∗,s)=ds=∑(s,u)∈Ec(s,u). And add a new sink t∗ with an edge (t,t∗) from every node t∈T to t∗, with capacity c(t,t∗)=dt=∑(v,t)∈Ec(v,t). Then apply the Ford–Fulkerson algorithm.


Also, if a node u has capacity constraint du, we replace this node with two nodes uin,uout, and an edge (uin,uout), with capacity c(uin,uout)=du. We can then apply the Ford–Fulkerson algorithm.

Sign in to keep reading

4 more chapters are free with a Lably account.

More in Discrete mathematics