The
FordFulkerson algorithm (named for
L. R. Ford, Jr. and
D. R. Fulkerson) computes the
maximum flow in a
flow network. It was published in 1956. The name "FordFulkerson" is often also used for the
EdmondsKarp algorithm, which is a specialization of FordFulkerson.
The idea behind the algorithm is very simple: 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 these paths. Then we find another path, and so on. A path with available capacity is called an augmenting path.
Algorithm
Given is a graph
$G(V,E)$, with capacity
$c(u,v)$ and flow
$f(u,v)=0$ for the edge from
$u$ to
$v$. 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:
 $f(u,v)\; leq\; c(u,v)$. The flow from $u$ to $v$ does not exceed the capacity.
 $f(u,v)\; =\; \; f(v,u)$. Maintain the net flow between $u$ and $v$. If in reality $a$ units are going from $u$ to $v$, and $b$ units from $v$ to $u$, maintain $f(u,v)=ab$ and $f(v,u)=ba$.
 $sum\_v\; f(u,v)\; =\; 0\; Longleftrightarrow\; f\_\{in\}(u)\; =\; f\_\{out\}(u)$ for all nodes $u$, except $s$ and $t$. The amount of flow into a node equals the flow out of the node.
This means that the flow through the network is a legal flow after each round in the algorithm. We define the residual network $G\_f(V,E\_f)$ to be the network with capacity $c\_f(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
$c\_f(v,u)>0$.
Algorithm FordFulkerson
 Inputs Graph $,G$ with flow capacity $,c$, a source node $,s$, and a sink node $,t$
 Output A flow $,f$ from $,s$ to $,t$ which is a maximum
 # $f(u,v)\; leftarrow\; 0$ for all edges $,(u,v)$
 # While there is a path $,p$ from $,s$ to $,t$ in $,G\_f$, such that $,c\_f(u,v)\; >\; 0$ for all edges $(u,v)\; in\; p$:
 ## Find $,c\_f(p)\; =\; min\{c\_f(u,v)\; ;;\; (u,v)\; in\; p\}$
 ## For each edge $(u,v)\; in\; p$
 ### $f(u,v)\; leftarrow\; f(u,v)\; +\; c\_f(p)$ (Send flow along the path)
 ### $f(v,u)\; leftarrow\; f(v,u)\; \; c\_f(p)$ (The flow might be "returned" later)
The path in step 2 can be found with for example a breadthfirst search or a depthfirst search in $G\_f(V,E\_f)$. If you use the former, the algorithm is called EdmondsKarp.
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 Maxflow Mincut theorem.
Complexity
By adding the flow augmenting path to the flow already established in the graph, the maximum flow will be reached when no more flow augmenting paths can be found in the graph. However, there is no certainty that this situation will ever be reached, so the best that can be guaranteed is that the answer will be correct if the algorithm terminates. In the case that the algorithm runs forever, the flow might not even converge towards the maximum flow. However, this situation only occurs with irrational flow values. When the capacities are integers, the runtime of FordFulkerson is bounded by
O(
E*f), where
E is the number of edges in the graph and
f is the maximum flow in the graph. This is because each augmenting path can be found in
O(
E) time and increases the flow by an integer amount which is at least 1.
A variation of the FordFulkerson algorithm with guaranteed termination and a runtime independent of the maximum flow value is the EdmondsKarp algorithm, which runs in O(VE^{2}) time.
Example
The following example shows the first steps of FordFulkerson in a flow network with 4 nodes, source A and sink D. This example shows the worstcase behaviour of the algorithm. In each step, only a flow of 1 is sent across the network. If you used breadthfirstsearch instead, you would only need two steps.
Path 
Capacity 
Resulting flow network 

Initial flow network 

$A,B,C,D$ 
$min(c\_f(A,B),\; c\_f(B,C),\; c\_f(C,D))=$
$min(c(A,B)f(A,B)\; ,c(B,C)f(B,C),\; c(C,D)f(C,D))=$
$min(10000,\; 10,\; 10000)=1$


$A,C,B,D$ 
$min(c\_f(A,C),\; c\_f(C,B),\; c\_f(B,D))=$
$min(c(A,C)f(A,C),\; c(C,B)f(C,B),\; c(B,D)f(B,D))=$
$min(10000,\; 0(1),\; 10000)=1$



After 1998 more steps … 


Final flow network 

Notice how flow is "pushed back" from C to B when finding the path A,C,B,D.
External links
References