317 Max Flow
317 Max Flow
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
(DAA, Dr. Ashish Gupta) ULC403 : Unit-III 1 / 26
Transportation networks
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
(DAA, Dr. Ashish Gupta) ULC403 : Unit-III 2 / 26
Graphs in modelling of Transportation Networks
■ Network models of this type have several ingredients:
• capacities on the edges, indicating how much they can carry;
• source nodes in the graph, which generate traffic;
• sink nodes in the graph, which can “absorb” traffic as it arrives
and
• the traffic/flow itself, which is transmitted across the edges.
Figure: A flow network, with source s and sink t. The numbers next to the edges
are the capacities.
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
(DAA, Dr. Ashish Gupta) ULC403 : Unit-III 3 / 26
Flow Networks
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
(DAA, Dr. Ashish Gupta) ULC403 : Unit-III 4 / 26
Defining flow
■ The flow into the sink node (t) is same as flow going out from the
source node (s) and thus, the flow is conserved.
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
(DAA, Dr. Ashish Gupta) ULC403 : Unit-III 6 / 26
The Lucky Puck Company’s trucking problem.
+ The Jalandhar factory is the source s, and the Delhi warehouse is the
sink t.
+ Pucks are shipped through intermediate cities, but only c(u, v) crates
per day can go from city u to city v.
■ Given a flow network G(V, E), with a capacity associated with each
edge in E and two distinguished nodes s and t known as source and
sink respectively,
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
(DAA, Dr. Ashish Gupta) ULC403 : Unit-III 9 / 26
Designing the Algorithm
■ Always set the flow as high as the edge capacities would allow while
preserving the conservation conditions.
■ Is this the maximum possible for the graph in the figure?
• no other s − t path on which we can directly push flow without
exceeding some capacity
• yet we do not have a maximum flow. . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
(DAA, Dr. Ashish Gupta) ULC403 : Unit-III 10 / 26
More general way of pushing flow from s → t
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
(DAA, Dr. Ashish Gupta) ULC403 : Unit-III 11 / 26
Systematically pushing flows: Residual graph
■ We can push backward on edges that are already carrying flow, to divert
it in a different direction.
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
(DAA, Dr. Ashish Gupta) ULC403 : Unit-III 12 / 26
Residual Graph
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
(DAA, Dr. Ashish Gupta) ULC403 : Unit-III 13 / 26
Residual Graph Construction
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
(DAA, Dr. Ashish Gupta) ULC403 : Unit-III 14 / 26
Augmenting Paths in a Residual Graph
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
(DAA, Dr. Ashish Gupta) ULC403 : Unit-III 15 / 26
Max-flow: Ford Fulkerson Algorithm
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
(DAA, Dr. Ashish Gupta) ULC403 : Unit-III 16 / 26
Complexity Analysis
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
(DAA, Dr. Ashish Gupta) ULC403 : Unit-III 17 / 26
Edmonds-Karp algorithm
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
(DAA, Dr. Ashish Gupta) ULC403 : Unit-III 18 / 26
Max-flow and Min-cut
Are they related ?
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
(DAA, Dr. Ashish Gupta) ULC403 : Unit-III 19 / 26
The structure of the flow network & Max-flow
■ Note: the structure of the flow network places upper bounds on the
maximum value of an s-t flow.
■ A basic “obstacle” to the existence of large flows:
• Divide the nodes of the graph into two sets, S and T , so that
s ∈ S and t ∈ T .
• Any flow that goes from s to t must cross from S into T at some
point, and thereby use up some of the edge capacity from S to T .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
(DAA, Dr. Ashish Gupta) ULC403 : Unit-III 20 / 26
Cut-sets of Flow Networks
■ A cut in a network is a partition of V into S and T (T = V − S)
such that s (source) is in S and t (target) is in T .
■ Each such “cut” of the graph puts a bound on the maximum possible
flow value.
■ Capacity of a cut(S, T )
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
(DAA, Dr. Ashish Gupta) ULC403 : Unit-III 21 / 26
The upper bound on the flow
■ Let f be any s − t flow, and (S, T ) any s − t cut. Then v(f ) ≤ c(S, T ).
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
(DAA, Dr. Ashish Gupta) ULC403 : Unit-III 22 / 26
Min-cut
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
(DAA, Dr. Ashish Gupta) ULC403 : Unit-III 23 / 26
Max-flow min-cut theorem
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
(DAA, Dr. Ashish Gupta) ULC403 : Unit-III 24 / 26
Applications
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
(DAA, Dr. Ashish Gupta) ULC403 : Unit-III 25 / 26
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
(DAA, Dr. Ashish Gupta) ULC403 : Unit-III 26 / 26