Post on 14-Mar-2022
Network Flow
Max-Flow: Edmonds-Karp Algorithm, Dinitzβs AlgorithmMax Bipartite Matching: HopcroftβKarpβKarzanov algorithm
Residual Network πΊπ
Given πΊ = (π, πΈ), π, and a flow π
πΊπ = (π, πΈπ) and the associated capacity ππ: πΈπ β β+ are defined as follows:
βͺ π’, π£ β πΈπ if one of the followings holdsβ π’, π£ β πΈ and π π’, π£ < π(π’, π£): in this case, ππ π’, π£ = π π’, π£ β π(π’, π£)
β π£, π’ β πΈ and π π£, π’ > 0: in this case, ππ π’, π£ = π π£, π’u
ts
v
20/20
20/30
10
20/2010
u
ts
v
10
10
πΊ πΊπ
20
20
20 10
Last Lecture β Ford-Fulkerson Method
βͺ Always terminates for integer/rational capacities
βͺ Not guaranteed to terminate for irrational capacities
βͺ Time complexity for integer capacities: π πΈ β π£(π)max
β not a polynomial time
Edmonds-Karp Algorithm
EdmondsKarp(πΊ = π, πΈ , π , π‘, π):
1. initialize π such that βπ β πΈ: π π = 0; initialize πΊπ β πΊ;
2. while there is an π -π‘ path on πΊπ:
3. find such a path π by BFS;
4. find an edge π β π with minimum capacity π;
5. update π that pushes π units of flow along π;
6. update πΊπ;
7. endwhile
8. return π
Edmonds-Karp Algorithm
Why BFS?
βͺ BFS maintains the distancesβ distance: num of edges, not weighted distance
π π‘
dist = 1 dist = 2 dist = 3 dist = 4dist = 5
dist = 6dist = 0
A path found by an iteration of Edmonds-Karp Algorithm
Why BFS?
βͺ In the residual network πΊπ, a new appeared edge can only goes from a vertex at distance π‘ + 1 to a vertex at distance π‘.
βͺ Addition of such edges does not decrease the distance between π and π’ for every π’ β π.
βͺ [Key Observation in this lecture!] Thus, dist(π’) is non-decreasing throughout the algorithm for every π’ β π.
π π‘
dist β₯ 1 dist β₯ 2 dist β₯ 3 dist β₯ 4dist β₯ 5
dist β₯ 6dist = 0
The updates to the edges in πΊπ
Weak Monotonicity to Strong Monotonicity
βͺ dist(π’) can only be one of 0, 1, 2,β¦ , |π|,ββ It can only be increased for |π| + 1 times!
βͺ Itβs great that BFS buys us distance monotonicity!
βͺ However, weak monotonicity is not enough.
βͺ To make a progress, we need dist(π’) strictly increases for some π’ β π, so that we can upper bound the number of iterations.
Counterexample: dist for all vertices remain unchanged after an iteration.
3
3
4
10
2
1
1
5
1
2
5
s
a
d
c
e
b
t
2
1
4
10
2
1
1
5
1
2
5
s
a
d
c
e
b
t3
Towards Strong Monotonicityβ¦
βͺ Observation: At least one edge (π’, π£) on π is βsaturatedβ, and this edge will be deleted in the next iteration.
βͺ Each iteration will remove an edge from a vertex at distance π to a vertex at distance π + 1.
βͺ Intuitively, we cannot keep removing such edges while keeping the distances of all vertices unchanged.
Towards Strong Monotonicity
βͺ Suppose we are at the π + 1 -th iteration. ππ is the current flow, and π is the path found in πΊππ at the π + 1 -thiteration.
βͺ We say that an edge (π’, π£) is critical if the amount of flow pushed along π is πππ(π’, π£).
βͺ A critical edge disappears in πΊππ+1 , but it may reappear in the futureβ¦
βͺ We will try to bound the number of times (π’, π£) becomes critical.
Between two βcriticalβ
π π‘
π’ π£
π
A flow along π in πΊππ where (π’, π£) becomes critical
π π‘
π’ π£In πΊππ+1, (π’, π£) disappears, and (π£, π’) appears.
Before the next time (π’, π£) becomes critical again, (π’, π£) must first reappear!
π π‘
π’ π£Before (π’, π£) reappears, the algorithm must have found π going through (π£, π’).
Between two βcriticalβ
π π‘
π’ π£
π
π π‘
π’ π£
distπ π£ = distπ π’ + 1
distπ+π π’ = distπ+π π£ + 1
βͺ Distance monotonicity: distπ+π π£ β₯ distπ π£ .
βͺ Thus, distπ+π π’ = distπ+π π£ + 1 β₯ distπ π£ + 1 β₯ distπ π’ + 2.
βͺ The distance of π’ from π increases by 2 between two βcriticalβ.
Putting Together
βͺ The distance of π’ from π increases by 2 between two βcriticalβ.
βͺ Distance takes value from 0, 1,β¦ , π ,β , and never decrease.
βͺ Thus, each edge can only be critical for π( π ) times.
βͺ At least 1 edge become critical in one iteration.
βͺ Total number of iterations is π( π β πΈ ).
βͺ Each iteration takes π πΈ time.
βͺ Overall time complexity for Edmonds-Karp: π π β πΈ 2 .
βͺ It can handle the issue with irrational numbers!
Can we improve?
βͺ Each iteration takes π πΈ time to find a shortest π -π‘ path by BFS.
βͺ However, each shortest π -π‘ path has length at most |π|.
βͺ Idea: push flow from multipleshortest π -π‘ paths in one iteration!
Dinicβs Algorithm (Dinitzβs Algorithm)
βͺ Proposed by Yefim Dinitz
βͺ Updated by Shimon Even and Alon Itai
βͺ Time complexity: π π 2 β πΈ
Dinicβs Algorithm β high-level ideas
βͺ Build a level graph:β Vertices at Level π are at distance π.
β Only edges go from a level to the next level are kept.
β Can be done in π πΈ time using a similar idea to BFS.
3
3
4
10
2
1
1
5
1
2
5
s
a
d
c
e
b
t3
3
4
2
1
1
5
2
5
s
a
d
c
e
b
t
Level 1 Level 2 Level 3
Dinicβs Algorithm β high-level ideas
βͺ Find a blocking flow on the level graph:β Push flow on multiple π -π‘ paths.
β Each π -π‘ path must contain a critical edge!
3
2/3
4/4
2/2
1
1
4/5
2/2
4/5
s
a
d
c
e
b
t
Level 1 Level 2 Level 3
Dinicβs Algorithm β high-level ideas
βͺ Find a blocking flow on the level graph:β Push flow on multiple π -π‘ paths.
β Each π -π‘ path must contain a critical edge!
1/3
1/3
4/4
1/2
1/1
1
4/5
2/2
4/5
s
a
d
c
e
b
t
a blocking flow
1/3
3
4/4
2
1/1
1
4/5
1/2
4/5
s
a
d
c
e
b
t
not a blocking flow: path s-a-b-t contains no critical edge
Dinicβs Algorithm β Overview
βͺ Initialize π to be the empty flow and πΊπ = πΊ.
βͺ Iteratively do the followings until dist π‘ = β:
β Construct the level graph πΊπΏπ for πΊπ.
β Find a blocking flow on πΊπΏπ.
β Update π and πΊπ.
Questions Remain
1. How many iterations do we need before termination?
2. How do we find a blocking flow?
Questions Remain
1. How many iterations do we need before termination?
2. How do we find a blocking flow?
Simple yet important observations
βͺ In the level graph πΊπΏππ at every iteration π, every π -π‘ path has
length distπ π‘ .
βͺ Every shortest π -π‘ path in πΊππ also appears in πΊπΏππ.
ts
πΊπΏππ
Distance Monotonicity
βͺ After one iteration, a new edge (π’, π£) appearing in πΊππ+1
(but not in πΊππ) must be βbackwardβ: distπ π’ = distπ π£ + 1.
ts
Level π Level π + 1
πΊπΏππ
u
vA new edge that will appear in πΊππ+1
Distance Monotonicity
βͺ After one iteration, a new edge (π’, π£) appearing in πΊππ+1
(but not in πΊππ) must satisfy distπ π’ = distπ π£ + 1.
βͺ Such additions of edges cannot reduce the distance for any vertex!
βͺ We again have that dist(π’) is non-decreasing!
βͺ Can we have strong monotonicity?
Taking a closer lookβ¦
βͺ All the paths in πΊπΏππ with length distπ(π‘) are βblockedβ after
the π-th iteration.
βͺ Thus, a path in the (π + 1)-th iteration must use some edges that are not in πΊπΏ
ππ.
Taking a closer lookβ¦
βͺ This new edge may be a βbackwardβ edge whose reverse was a critical edge in the previous iteration.
βͺ In this case, dist(π‘) is increased by at least 2.
ts
πΊπΏππ
Taking a closer lookβ¦
βͺ Or, it may be an edge in πΊππ, but not in πΊπΏππ.
βͺ In this case, dist(π‘) is increased by at least 1.
ts
πΊπΏππ
Taking a closer lookβ¦
βͺ In both cases: distπ+1 π‘ > distπ(π‘)
βͺ Letβs prove it rigorously thenβ¦
Proving distπ+1 π‘ > distπ(π‘)
βͺ Consider an arbitrary π -π‘ path π in πΊπΏππ+1 with length distπ+1(π‘).
βͺ We have distπ+1 π‘ β₯ distπ(π‘) by monotonicity.
βͺ Suppose for the sake of contraction that distπ+1 π‘ = distπ(π‘).
βͺ Case 1: all edges in π also appear in πΊπΏππ
βͺ Then π is a shortest path containing no critical edges in πΊπΏππ
βͺ Contracting to the definition of blocking flow!
Proving distπ+1 π‘ > distπ(π‘)
βͺ Case 2: π contains an edge (π’, π£) that is not in πΊπΏππ
βͺ If (π’, π£) was not in πΊππ, then (π£, π’) was critical in the last iteration. We have distπ π’ = distπ π£ + 1.
βͺ If (π’, π£) was in πΊππ but not πΊπΏππ, by the definition of level
graph, we have distπ π’ β₯ distπ π£ .
βͺ In both cases above, distπ π’ β₯ distπ π£ .
βͺ We have distπ+1 π’ β₯ distπ(π’) by monotonicity,
βͺ and we have distπ+1 π£, π‘ β₯ distπ(π£, π‘). (why?)
Proving distπ+1 π‘ > distπ(π‘)
βͺ Case 2: π contains an edge (π’, π£) that is not in πΊπΏππ
βͺ Fact i: distπ π’ β₯ distπ π£ .
βͺ Fact ii: distπ+1 π’ β₯ distπ π’ .
βͺ Fact iii: distπ+1 π£, π‘ β₯ distπ(π£, π‘).
Putting together:distπ+1 π‘ = distπ+1 π’ + 1 + distπ+1(π£, π‘)
β₯ distπ π’ + 1 + distπ(π£, π‘)
β₯ distπ π£ + 1 + distπ(π£, π‘)
β₯ distπ π‘ + 1
(Fact ii and iii)
(Fact i)
(triangle inequality)
Putting Togetherβ¦
βͺ dist(π‘) is increased by at least 1 after each iteration.
βͺ dist(π‘) takes value from {0, 1, β¦ , π ,β}, so it can be increased for at most π π times.
βͺ Total number of iterations is at most π π .
Questions Remain
1. How many iterations do we need before termination?β π π
2. How do we find a blocking flow?
Finding a blocking flow in a level graphβ¦
Iteratively do the followings, until no path from π to π‘:
βͺ Find an arbitrary maximal path in πΊπΏπ starting from π :
β At every vertex, find an arbitrary edge in πΊπΏπ and append it to the
path.
βͺ Two possibilities:β End up at π‘: in this case, we update π (by pushing flow along the
path) and remove the critical edge
β End up at a dead-end, a vertex π£ with no out-going edges in πΊπΏπ: in
this case, we remove all the incoming edges of π£
Finding a blocking flow in a level graphβ¦
βͺ At least one edge is removed after each search.β Total number of searches: π πΈ
βͺ Each search takes at most |π| steps.
βͺ Time complexity for each iteration of Dinicβs algorithm: π π β πΈ .
Overall Time Complexity for Dinicβs Algorithm
βͺ Each iteration: π π β πΈ .
βͺ We need at most π π iterations.
βͺ Overall time complexity for Dinicβs algorithm: π π 2 β πΈ .
Other Algorithms for Max-Flow
βͺ Improvements to Dinicβs algorithm:β [Malhotra, Kumar & Maheshwari, 1978]: π π 3
β Dynamic tree: π π β πΈ β log π
βͺ Push-relabel algorithm [Goldberg & Tarjan, 1988]
β π π 2 πΈ , later improved to π π 3 , π π 2 πΈ , π π πΈ logπ 2
πΈ
βͺ [King, Rao & Tarjan, 1994] and [Orlin, 2013]: π π β πΈ
βͺ Interior-point-method-based algorithms:
β [Kathuria, Liu & Sidford, 2020] πΈ4
3+π(1)π
1
3
β [BLNPSSSW, 2020] [BLLSSSW, 2021] ΰ·¨π πΈ + π3
2 logπ
β [Gao, Liu & Peng, 2021] ΰ·¨π πΈ3
2β
1
328 logπ
HopcroftβKarpβKarzanov algorithm
βͺ Find a maximum bipartite matching in π πΈ β π time.
βͺ Proposed independently by Hopcroft-Karp and Karzanov.
βͺ Can be viewed as a special case of Dinicβs algorithm.
Conversion to Max-Flow Problem
s
t
1111
1
1111111
1 11
11
11
1 1
1
Set the capacity to 1 for all edges.
Conversion to Max-Flow Problem
s
t
1111
1
1111111
1 11
11
11
1 1
1
Dinicβs algorithm runs in π πΈ β π time for this special case.
Conversion to Max-Flow Problem
βͺ Integrality theorem also holds for Dinicβs algorithm:β The flow output by Dinicβs algorithm in our case is integral.
βͺ We aim to show Dinicβs algorithm runs in π πΈ β π time.
βͺ Step 1: Finding a blocking flow in a level graph takes π πΈtime.
βͺ Step 2: Number of iterations is at most 2 π .
Step 1: Finding a blocking flow in a level graph takes π πΈ time.
Iteratively do the followings, until no path from π to π‘:
βͺ Perform DFS from π
βͺ If we reach π‘, delete all edges on the π -π‘ path (why can we do this?) and start over from π .
βͺ If we ever go backward, delete the edge just travelled. (why can we do this?)
Step 1: Finding a blocking flow in a level graph takes π πΈ time.
s t
An π -π‘ path is found, remove all edges from the path.
Step 1: Finding a blocking flow in a level graph takes π πΈ time.
s t
We have to go backward now; delete the edge just travelled.
Step 1: Finding a blocking flow in a level graph takes π πΈ time.
s t
Again, we have to go backward; delete the edge just travelled.
Step 1: Finding a blocking flow in a level graph takes π πΈ time.
s t
Again, we have to go backward; delete the edge just travelled.
Step 1: Finding a blocking flow in a level graph takes π πΈ time.
s t
Again, we have to go backward; delete the edge just travelled.
Step 1: Finding a blocking flow in a level graph takes π πΈ time.
s t
Find another π -π‘ path; delete all edges on the path
Step 1: Finding a blocking flow in a level graph takes π πΈ time.
s t
We have obtained a blocking flow!
Step 1: Finding a blocking flow in a level graph takes π πΈ time.
Time complexity: π πΈ
βͺ Each edge is visited at most once.
Step 2: Number of iterations is at most 2 π .
βͺ If the algorithm terminates within π iterations, we are already done!
βͺ Otherwise, let π be the flow after π iterations.
βͺ Claim: the maximum flow in πΊπ has value at most π .
Observation on πΊπ
βͺ In each iteration, for each π£ β π β {π , π‘}, either its in-degree is 1, or its out-degree is 1.
βͺ Proof. By Inductionβ¦
βͺ At the beginning, this is clearly true.
t
s
1111
1
111111
1 11
11
11
1
1
in-degree = 1
out-degree = 1
Observation on πΊπ
βͺ In each iteration, for each π£ β π β {π , π‘}, either its in-degree is 1, or its out-degree is 1.
βͺ Proof. At the beginning, this is clearly true.
βͺ For each iteration, the amount of flow going through π£ is either 0 or 1.
βͺ If it is 0, π£βs in-degree and out-degree are unchanged.
βͺ Otherwise, exactly one in-edge and one out-edge are flipped; the property is still maintained.
The maximum flow in πΊπ has value at most π
βͺ Integrality Theorem: there exists a maximum integral flow πβ² in πΊπ.
βͺ πβ² consists of edge-disjoint paths.
βͺ Edge-disjointness implies vertex-disjointness by previous observation on πΊπ.
s t s t
violating flow conservation
The maximum flow in πΊπ has value at most π
βͺ Max-flow on πΊπ, πβ², is integral and consists of edge-disjoint paths.
βͺ By our analysis to Dinicβs algorithm, distπΊππ , π‘ β₯ π .
βͺ Each path in πβ² has length at least π .
βͺ There are at most π
π= π paths in πβ² by vertex-disjointness.
βͺ π£ πβ² β€ π
Step 2: Number of iterations is at most 2 π .
βͺ If the algorithm terminates within π iterations, we are already done!
βͺ Otherwise, let π be the flow after π iterations.
βͺ Claim: the maximum flow in πΊπ has value at most π .
βͺ Each iteration increase the value of flow by at least 1.
βͺ Thus, the algorithm will terminates within at most another π iterations.
βͺ Total number of iterations: 2 π .
Putting Togetherβ¦
βͺ Step 1: Finding a blocking flow in a level graph takes π πΈtime.
βͺ Step 2: Number of iterations is at most 2 π .
βͺ Overall time complexity: π πΈ β π
Todayβs Lecture
Maximum Flow Problem:
βͺ Edmonds-Karp Algorithmβ Implement Ford-Fulkerson method by BFS
β π π β πΈ 2
βͺ Dinicβs Algorithmβ Push flow on multiple paths at one iterationβ Level graph and blocking flow
β π π 2 β |πΈ|
Maximum Bipartite Matching Problem:
βͺ HopcroftβKarpβKarzanov algorithmβ Apply Dinicβs algorithm
β π πΈ β π