Ford-Fulkerson algorithm

From Wikipedia, the free encyclopedia

The Ford-Fulkerson algorithm (named for L. R. Ford, Jr. and D. R. Fulkerson) computes the maximum flow in a flow network. The name Ford-Fulkerson is often also used for the Edmonds-Karp algorithm, which is a specialisation of Ford-Fulkerson.

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.

Contents

[edit] 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 the following is maintained:

  • \ f(u,v) \leq c(u,v). The flow between u and v does not exceed the capacity.
  • \ f(u,v) = - f(v,u). We maintain the net flow.
  • \ \sum_v f(u,v) = 0 for all nodes 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 Gf(V,Ef) to be the network with capacity cf(u,v) = c(u,v) − f(u,v) and no flow. Notice that it is not certain that E = Ef, as sending flow on u,v might close u,v (it is saturated), but open a new edge v,u in the residual network.

Inputs Graph G with flow capacity c, a source node s, and a sink node t
Output Flow f such that f is maximal from s to t
  1. f(u,v) \leftarrow 0 for all edges u,v
  2. While there is a path from s to t in Gf:
    1. Find a path u_1, u_2, \dots, u_k where u1 = s and uk = t, such that cf(ui,ui + 1) > 0
    2. Find m = min(cf(ui,ui + 1))
    3. f(u_i,u_{i+1}) \leftarrow f(u_i,u_{i+1}) + m (send flow along the path)
    4. f(u_{i+1},u_i) \leftarrow f(u_{i+1},u_i) - m (the flow might be "returned" later)

The path can be found with for example a breadth-first search or a depth-first search in Gf(V,Ef). If you use the former, the algorithm is called Edmonds-Karp.

[edit] 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 Ford-Fulkerson 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 Ford-Fulkerson algorithm with guaranteed termination and a runtime independent of the maximum flow value is the Edmonds-Karp algorithm, which runs in O(VE2) time.

[edit] Example

The following example show the first steps of Ford-Fulkerson in a flow network with 4 nodes, source A and sink D. The augmenting paths are found with a depth-first-search, where neighbours are visited in alphabetical order. This example shows the worst-case behaviour of the algorithm. In each step, only a flow of 1 is sent across the network. See that if you used a breadth-first-search instead, you would only need two steps.

Path Capacity Resulting flow network
Initial flow network
A,B,C,D

min(cf(A,B),cf(B,C),cf(C,D)) =
min(c(A,B) − f(A,B),c(B,C) − f(B,C),c(C,D) − f(C,D)) =
min(1000 − 0,1 − 0,1000 − 0) = 1

A,C,B,D

min(cf(A,C),cf(C,B),cf(B,D)) =
min(c(A,C) − f(A,C),c(C,B) − f(C,B),c(B,D) − f(B,D)) =
min(1000 − 0,0 − ( − 1),1000 − 0) = 1

\dots
Final flow network

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

[edit] External links

[edit] References