Lester Randolph Ford, Jr. is an American mathematician specializing in network flow problems. He is the son of mathematician Lester R. Ford, Sr..Ford's paper with D. R...
Delbert Ray Fulkerson was a mathematician who co-developed the Ford-Fulkerson algorithm, one of the most well-known algorithms to solve the maximum flow problem in networks....
In graph theory, a flow network is a directed graph where each edge has a capacity and each edge receives a flow. The amount of flow on an edge cannot exceed the capacity of the edge. Often in Operations Research, a directed graph is called a network, the vertices are called nodes and the edges are...
. It was published in 1956. The name "Ford–Fulkerson" is often also used for the Edmonds–Karp algorithm, which is a specialization of Ford–Fulkerson.
In mathematics and computer science, an algorithm is an effective method expressed as a finite list of well-defined instructions for calculating a function. Algorithms are used for calculation, data processing, and automated reasoning...
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
Let be a graph, and for each edge from to , let be the capacity and be the flow. We want to find the maximum flow from the source to the sink . After every step in the algorithm the following is maintained:
Capacity constraints:
The flow along an edge can not exceed its capacity.
Skew symmetry:
The net flow from to must be the opposite of the net flow from to (see example).
Flow conservation:
That is, unless or . The net flow to a node is zero, except for the source, which "produces" flow, and the sink, which "consumes" flow.
This means that the flow through the network is a legal flow after each round in the algorithm. We define the residual network to be the network with capacity and no flow. Notice that it can happen that a flow from to is allowed in the residual
network, though disallowed in the original network: if and then .
Algorithm Ford–Fulkerson
Inputs Graph with flow capacity , a source node , and a sink node
Output A flow from to which is a maximum
for all edges
While there is a path from to in , such that for all edges :
Depth-first search is an algorithm for traversing or searching a tree, tree structure, or graph. One starts at the root and explores as far as possible along each branch before backtracking....
in . If you use the former, the algorithm is called Edmonds–Karp.
When no more paths in step 2 can be found, will not be able to reach in the residual
network. If is the set of nodes reachable by in the residual network, then the total
capacity in the original network of edges from to the remainder of is on the one hand
equal to the total flow we found from to ,
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
Max-flow min-cut theorem
In optimization theory, the max-flow min-cut theorem states that in a flow network, the maximum amount of flow passing from the source to the sink is equal to the minimum capacity which when removed in a specific way from the network causes the situation that no flow can pass from the source to the...
.
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 (see big O notation
Big O notation
In mathematics, big O notation is used to describe the limiting behavior of a function when the argument tends towards a particular value or infinity, usually in terms of simpler functions. It is a member of a larger family of notations that is called Landau notation, Bachmann-Landau notation, or...
), where is the number of edges in the graph and is the maximum flow in the graph. This is because each augmenting path can be found in time and increases the flow by an integer amount which is at least .
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 time.
Integral example
The following example shows the first steps of Ford–Fulkerson in a flow network with 4 nodes, source and sink . This example shows the worst-case behaviour of the algorithm. In each step, only a flow of is sent across the network. If breadth-first-search were used instead, only two steps would be needed.
Path
Capacity
Resulting flow network
Initial flow network
After 1998 more steps …
Final flow network
Notice how flow is "pushed back" from to when finding the path .
Non-terminating example
Consider the flow network shown on the right, with source , sink , capacities of edges , and respectively , and and the capacity of all other edges some integer . The constant was chosen so, that . We use augmenting paths according to the following table, where , and .
Step
| Augmenting path
| Sent flow
| Residual capacities
0
1
2
3
4
5
Note that after step 1 as well as after step 5, the residual capacities of edges , and are in the form , and , respectively, for some . This means that we can use augmenting paths , , and infinitely many times and residual capacities of these edges will always be in the same form. Total flow in the network after step 5 is . If we continue to use augmenting paths as above, the total flow converges to , while the maximum flow is . In this case, the algorithm never terminates and the flow doesn't even converge to the maximum flow.
Python implementation
class Edge(object):
def __init__(self, u, v, w):
self.source = u
self.sink = v
self.capacity = w
def __repr__(self):
return "%s->%s:%s" % (self.source, self.sink, self.capacity)
class FlowNetwork(object):
def __init__(self):
self.adj = {}
self.flow = {}
def find_path(self, source, sink, path):
if source sink:
return path
for edge in self.get_edges(source):
residual = edge.capacity - self.flow[edge]
if residual > 0 and not (edge,residual) in path:
result = self.find_path( edge.sink, sink, path + [(edge,residual)] )
if result != None:
return result
def max_flow(self, source, sink):
path = self.find_path(source, sink, [])
while path != None:
flow = min(res for edge,res in path)
for edge,res in path:
self.flow[edge] += flow
self.flow[edge.redge] -= flow
path = self.find_path(source, sink, [])
return sum(self.flow[edge] for edge in self.get_edges(source))