Ford Fulkerson Method
1.About the Ford Fulkerson Method:
The Ford - Fulkerson method or the Ford - Fulkerson algorithm (FFA) is a greedy
algorithm that computes the maximum flow in a threaded network. It is sometimes
called a "method" instead of an "algorithm" because the approach to finding an
ascending path in a residual graph is not fully specified or it is specified in some
implementations with time run difference.
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 capacity available on all edges in
the path, flowing along one of the paths. Find another path, etc. The path with
available capacity is called an ascending path.
The intuition behind this method is simple: Find a pathway of unused capacity and
increase the flow along that pathway. Call this pathway an augmenting path.
Repeat until no such pathways are found.
What makes this nontrivial is an apparent paradox: overall flow can sometimes be
increased by decreasing flow along certain edges (because they flow in the "wrong"
direction or move capacity to a part of the network that can't handle it as well). See
whether you can find an example in the graph shown.
Residual Network
Given a flow f in a network G = (V, E), consider a pair of vertices u, v ∈ V. How
much additional flow can we push directly from u to v? This is the residual
capacity cf (u,v):
The first case says that if we have not used the full capacity c(u, v) of an edge (u, v)
in E then we can increase it by the difference.
The second case says that if we are using f(v, u) of the capacity of (v, u) in E then
we have the residual "capacity" of reversing (cancelling) that much flow in the
reverse direction (u, v) (notice that the letters are swapped).
Otherwise there is no residual capacity between u and v.
2. Analyze the asymptotic complexity of Ford–Fulkerson algorithm:
Time Complexity: Time complexity of the above algorithm is O(max_flow * E).
Running a loop while there is an augmenting path. In worst case, adding 1 unit flow
in every iteration. Therefore the time complexity becomes O(max_flow * E).
3. Implement the above simple algorithm:
Residual Graph of a flow network is a graph which indicates additional possible
flow. If there is a path from source to sink in residual graph, then it is possible to
add flow. Every edge of a residual graph has a value called residual capacity which
is equal to original capacity of the edge minus current flow. Residual capacity is
basically the current capacity of the edge.
Residual capacity is 0 if there is no edge between two vertices of residual graph.
Initialize the residual graph as original graph as there is no initial flow and initially
residual capacity is equal to original capacity. To find an augmenting path, do a
BFS or DFS of the residual graph. Using BFS in below implementation. Using
BFS, that can find out if there is a path from source to sink. BFS also builds parent[
] array. Using the parent[ ] array, traverse through the found path and find possible
flow through this path by finding minimum residual capacity along the path. We
later add the found path flow to overall flow.
Need to update residual capacities in the residual graph. Subtract path flow from all
edges along the path and we add path flow along the reverse edges Adding path
flow along reverse edges because may later need to send flow in reverse direction
Augmentation and Augmenting Paths:
Given flows f in G and f ' in Gf, define the augmentation of f by f ', f ↑ f ', to be a
function V x V → ℜ:
To "add" the flow f ' of the residual network Gf to the current flow f in G, for each
edge (u, v) in E, increase the flow on (u, v) by f ' (u, v), but decrease it by f ' (v, u)
because pushing flow on the reverse edge in the residual network decreases the
flow in the original network.
Code:
The above implementation of Ford Fulkerson Algorithm is called Edmonds-Karp
Algorithm. The idea of Edmonds-Karp is to use BFS in Ford Fulkerson
implementation as BFS always picks a path with minimum number of edges. When
BFS is used, the worst case time complexity can be reduced to O(VE2). The above
implementation uses adjacency matrix representation though where BFS takes
O(V2) time, the time complexity of the above implementation is O(EV3) (Refer
CLRS book for proof of time complexity)
Or
5. Draw the theoretical complexity function and the actual running time as
the function of input size.
F
Push-Relabel Algorithm
Push-Relabel approach is the more efficient than Ford-Fulkerson algorithm. In this
post, Goldberg’s “generic” maximum-flow algorithm is discussed that runs in
O(V2E) time. This time complexity is better than O(E2V) which is time complexity
of Edmond-Karp algorithm (a BFS based implementation of Ford-Fulkerson).
There exist a push-relabel approach based algorithm that works in O(V3) which is
even better than the one discussed here. Similarities with Ford Fulkerson
Like Ford-Fulkerson, Push-Relabel also works on Residual Graph (Residual Graph
of a flow network is a graph which indicates additional possible flow. If there is a
path from source to sink in residual graph, then it is possible to add flow).
Differences with Ford Fulkerson:
Push-relabel algorithm works in a more localized. Rather than examining the entire
residual network to find an augmenting path, push-relabel algorithms work on one
vertex at a time (Source : CLRS Book).
In Ford-Fulkerson, net difference between total outflow and total inflow for every
vertex (Except source and sink) is maintained 0. Push-Relabel algorithm allows
inflow to exceed the outflow before reaching the final flow. In final flow, the net
difference is 0 for all except source and sink.
Time complexity wise more efficient.
The intuition behind the push-relabel algorithm (considering a fluid flow problem)
is that we consider edges as water pipes and nodes are joints. The source is
considered to be at the highest level and it sends water to all adjacent nodes. Once a
node has excess water, it pushes water to a smaller height node. If water gets
locally trapped at a vertex, the vertex is Relabeled which means its height is
increased. Following are some useful facts to consider before we proceed to
algorithm.
Each vertex has associated to it a height variable and a Excess Flow. Height is used
to determine whether a vertex can push flow to an adjacent or not (A vertex can
push flow only to a smaller height vertex). Excess flow is the difference of total
flow coming into the vertex minus the total flow going out of the vertex.
5. Draw the theoretical complexity function
h and e values denote the label 𝓁 and excess xf , respectively, of the node during
the execution of the algorithm. Each residual graph in the example only contains
the residual arcs with a capacity larger than zero. Each residual graph may contain
multiple iterations of the perform operation loop.