Max Flow Lecture Notes
Max Flow Lecture Notes
1.1 Question 1
• Therefore, any unvisited non-adjacent node adjacent to adjacent nodes is on the short-
est path discovered like this.
1
2
• Now, in BSF all we do is, we insert first node in a queue then we keep removing
nodes from rear and keep inserting their adjacent nodes in the same queue if they are
not already visited. This restricts visiting a node adjacent node before all adjacent
ones. So, this is exactly the procedure which uses points 1 and 2 above. Hence, nodes
discovered by BFS are through shortest path only.
2.1 Explanation:
A flow network can model the trucking problem shown in Figure 3. In the given flow
network G(V,E) for the Lucky Puck Company’s trucking problem. The Vancouver factory
is the source s, and the Winnipeg warehouse is the sink t. Company ships pucks through
intermediate cities, but only c(u,v) crates per day can go from city u to city v. Each edge
is labeled with its capacity. A flow f in G with value —f— = 19. Each edge (u,v) is labeled
by f(u,v)/ c(u,v). The slash notation merely separates the flow and capacity; it does not
indicate division. Our goal is to maximize the flow from node s to t. In this case maximize
the flow of crates from Vancouver to Winnipeg.
3
2.3 Solutions
One solution can be find all possible path from s to t and return the one with maximum
flow. But this solution will give us result but it will be in exponential time. The two better
algorithms for finding maximum flow from node s to t are.
• Ford-Fulkerson method
• Edmonds-Karp algorithm
4
3 Ford-Fulkerson method
FORD-FULKERSON-METHOD(G(s,t))
1. initialize flow f to 0
2. while there exists an augmenting path p in the residual network Gf
3. augment flow f along
4. return f
Intuitively, given a flow network G and a flow f , the residual network Gf consists of edges
with capacities that represent how we can change the flow on edges of G.An edge of the flow
network can admit an amount of additional flow equal to the edge’s capacity minus the flow
on that edge. If that value is positive, we place that edge into GF with a “residual capacity”
of cf (u, v) = c(u,v) - f(u,v). The only edges of G that are in Gf are those that can admit
more flow; those edges (u,v) whose flow equals their capacity have cf (u, v) = 0, and they are
not in Gf .
Given a flow network G(V , E) and a flow f , an augmenting path p is a simple path from s
to t in the residual network Gf .
3.3 Explanation
Repeatedly run DFS from source node s to sin t until there’s no path exists in residual
network from sorce s to sink t. The Ford-Fulkerson method iteratively increases the value of
the flow. We start with f(u)u,v) = 0 for all u,v ∈ V , giving an initial flow of value 0. At each
iteration, we increase the flow value in G by finding an “augmenting path” in an associated
“residual network” Gf . Once we know the edges of an augmenting path in Gf , we can
easily identify specific edges in G for which we can change the flow so that we increase the
value of the flow. Although each iteration of the Ford-Fulkerson method increases the value
of the flow, we shall see that the flow on any particular edge of G may increase or decrease;
decreasing the flow on some edges may be necessary in order to enable an algorithm to send
more flow from the source to the sink. We repeatedly augment the flow until the residual
network has no more augmenting paths. The max-flow min-cut theorem will show that upon
termination, this process yields a maximum flow.
5
Figure 5:
Figure 6:
6
Figure 7:
Figure 8:
In practice, the maximum-flow problem often arises with integral capacities. If the capacities
are rational numbers, we can apply an appropriate scaling transformation to make them all
integral. If f ∗ denotes a maximum flow in the transformed network, then a straightforward
implementation of FORD-FULKERSON executes the while loop of lines 3–8 at most —f ∗ —
times, since the flow value increases by at least one unit in each iteration.
Running time of fork-fulkerson algorithm will be O(((V+E).f). where f is the maximum
flow. Example in figure 11. This figure illustrates worst case of fork-fulkerson algorithm.If
the path in odd iterations is chosen as s ->u ->v ->t and in case of even numbers the path
chosen is s ->v ->u ->t. The total running time of the algorithm will be O(total number of
edges * MAXIMUM FLOW), as in each iteration only one unit of flow will pass through.
7
Figure 9:
Figure 10:
4 Edmonds-Karp algorithm
Edmonds-karp algorithm is a modified version of fork-fulkerson algorithm. Instead of it-
erating with DFS Edmonds-karp used BFS. That is, we choose the augmenting path as a
shortest path from s to t in the residual network, where each edge has unit distance (weight).
We call the Ford-Fulkerson method so implemented the Edmonds-Karp algorithm. We now
prove that the Edmonds-Karp algorithm runs in O(V 2 E). As in each augmented path the
distance between nodes is increasing monotonically.
4.1 Explanation
Figures 12-15 show successive stages of the Edmonds-Karp algorithm, including the 4 aug-
menting paths selected, while solving a particular maxflow problem. ”Real” edges in the
graph are shown in black, and dashed if their residual capacity is zero. Green residual edges
are the back edges created to allow ”undo” of flow on a ”real” edge. Each graph containing
8
Figure 11:
an augmenting path is drawn twice– first as a ”plain” graph, then showing the layering in-
duced by breadth-first search, together with an augmenting path chosen at that stage (light
blue). G4 has no remaining augmenting paths (edges from s are saturated); G5 is the re-
sulting max flow, with each edge annotated by ”flow” / ”capacity”. Note how successive
augmentations push nodes steadily farther from s, and especially that (undirected) edge a,f
is the ”critical” edge twice – first in G0, when a is at depth 1 in the BFS tree, and again in
G3 when f (not a) is at depth 3, which allows us to undo the ”mistake” of sending any flow
through this edge. Edge capacities of 10 could be replaced by any value C greater than 1
without fundamentally altering the series of graphs shown. Hence, Ford-Fulkerson (lacking
the E-K-D shortest path innovation) might use C augmentations on G0, instead of 4.
9
Figure 12:
10
Figure 13:
11
Figure 14:
12
Figure 15: