Maximum Flow
description
Transcript of Maximum Flow
04/22/23 11:18 Maximum Flow 2
Outline and ReadingFlow networks Flow (§8.1.1) Cut (§8.1.2)
Maximum flow Augmenting path (§8.2.1) Maximum flow and minimum cut (§8.2.1) Ford-Fulkerson’s algorithm (§8.2.2-8.2.3) Edmonds-Karp algorithm (§8.2.4)
Maximum Bipartite MatchingMinimum Cost Flow (§8.4)
04/22/23 11:18 Maximum Flow 3
Flow NetworkA flow network (or just network) N consists of
A weighted digraph G with nonnegative integer edge weights, where the weight of an edge e is called the capacity c(e) of e
Two distinguished vertices, s and t of G, called the source and sink, respectively, such that s has no incoming edges and t has no outgoing edges.
Example:
ws
v
u
t
z
3
9
13
76
515
2
04/22/23 11:18 Maximum Flow 4
FlowA flow f for a network N is is an assignment of an integer value f(e) to each edge e that satisfies the following properties:Capacity Rule: For each edge e, 0 f (e) c(e)
Conservation Rule: For each vertex v s,t where E(v) and E(v) are the incoming and outgoing edges of v, resp.
The value of a flow f , denoted |f|, is the total flow from the source, which is the same as the total flow into the sink Example:
)()(
)()(vEevEe
efef
2/2
ws
v
u
t
z
3/3
2/9
1/1
1/3
3/72/6
4/51/13/5
04/22/23 11:18 Maximum Flow 5
Maximum FlowA flow for a network N is said to be maximum if its value is the largest of all flows for NThe maximum flow problem consists of finding a maximum flow for a given network NApplications
Hydraulic systems Electrical circuits Traffic movements Freight transportation
ws
v
u
t
z
3/3
2/9
1/1
1/3
3/72/6
4/51/13/5
2/2
ws
v
u
t
z
3/3
2/9
1/1
3/3
3/74/6
4/51/13/5
2/2
Flow of value 8 = 2 + 3 + 3 = 1 + 3 + 4
Maximum flow of value 10 = 4 + 3 + 3 = 3 + 3 + 4
04/22/23 11:18 Maximum Flow 6
CutA cut of a network N with source s and sink t is a partition (Vs,Vt) of the vertices of N such that s Vs and t Vt
Forward edge of cut : origin in Vs and destination in Vt
Backward edge of cut : origin in Vt and destination in Vs
Flow f() across a cut : total flow of forward edges minus total flow of backward edgesCapacity c() of a cut : total capacity of forward edgesExample:
c() 24 f() 8
t
ws
v
u z
3
9
13
76
515
2
ws
v
u
t
z
3/3
2/9
1/1
1/3
3/72/6
4/51/13/5
2/2
f() = 2 –1 + 3 + 2 + 2 = 8
04/22/23 11:18 Maximum Flow 7
Flow and CutLemma:
The flow f() across any cut is equal to the flow value |f|
Lemma:The flow f() across a cut is less than or equal to the capacity c() of the cut
Theorem:The value of any flow is less than or equal to the capacity of any cut, i.e., for any flow f and any cut , we have|f| c()
ws
v
u
t
z
3/3
2/9
1/1
1/3
3/72/6
4/51/13/5
2/2
1 2
c(1) 6 3 1 2 12 c(2) 3 7 9 2 21
|f| 8
04/22/23 11:18 Maximum Flow 8
Augmenting PathConsider a flow f for a network NLet e be an edge from u to v:
Residual capacity of forward edge e, from u to v: f(u, v) = c(e) f (e)
Residual capacity of backward edge e, from v to u: f(v, u) = f (e)
Let be a path from s to t The residual capacity f() of
is the smallest of the residual capacities of the edges of
A path from s to t is an augmenting path if f() 0
ws
v
u
t
z
3/3
2/9
1/1
1/3
2/72/6
4/50/12/5
2/2
f(s,u) 3f(u,w) 1f(w,v) 1f(v,t) 2
f() 1|f| 7
04/22/23 11:18 Maximum Flow 9
Flow AugmentationLemma:
Let be an augmenting path for flow f in network N. There exists a flow f for N of value| f | = |f | f()
Proof: We compute flow f by modifying the flow on the edges of
Forward edge:f (e) = f(e) f()
Backward edge:f (e) = f(e) f()
ws
v
u
t
z
3/3
2/9
1/1
1/3
2/72/6
4/50/12/5
2/2
f() = 1
ws
v
u
t
z
3/3
2/9
0/1
2/3
2/72/6
4/51/13/5
2/2
| f | = 7
| f | = 8
04/22/23 11:18 Maximum Flow 10
Ford-Fulkerson’s AlgorithmInitially, f(e) 0 for each edge eRepeatedly
Search for an augmenting path
Augment by f() the flow along the edges of
A specialization of DFS (or BFS) searches for an augmenting path
An edge e is traversed from u to v provided f(u, v) 0
Algorithm FordFulkersonMaxFlow(N)for all e G.edges()
setFlow(e, 0)while G has an augmenting path { compute residual capacity of } for all edges e { compute residual capacity of e }
if e is a forward edge of getCapacity(e) getFlow(e)
else { e is a backward edge } getFlow(e)
if <
{ augment flow along }for all edges e
if e is a forward edge of setFlow(e, getFlow(e) )
else { e is a backward edge }setFlow(e, getFlow(e) )
04/22/23 11:18 Maximum Flow 11
Max-Flow and Min-CutTermination of Ford-Fulkerson’s algorithm
There is no augmenting path from s to t with respect to the current flow f
DefineVs set of vertices reachable
from s by augmenting pathsVt set of remaining vertices
Cut (Vs,Vt) has capacityc() = |f|
Forward edge: f(e) = c(e) Backward edge: f(e) = 0
Thus, flow f has maximum value and cut has minimum capacity
ws
v
u
t
z
3/3
1/9
1/1
3/3
4/74/6
3/51/13/5
2/2
Theorem:The value of a maximum flow is equal to the capacity of a minimum cut
c() | f | 10
04/22/23 11:18 Maximum Flow 12
Example (1)
ws
v
u
t
z
0/3
0/9
0/1
0/3
1/70/6
0/51/11/5
0/2
ws
v
u
t
z
1/3
0/9
1/1
0/3
2/71/6
1/50/11/5
1/2
ws
v
u
t
z
2/3
0/9
0/1
1/3
2/71/6
1/50/11/5
1/2
ws
v
u
t
z
1/3
0/9
0/1
0/3
1/70/6
1/50/11/5
1/2
04/22/23 11:18 Maximum Flow 13
Example (2)
ws
v
u
t
z
2/3
0/9
0/1
3/3
2/73/6
1/50/11/5
1/2
ws
v
u
t
z
3/3
1/9
1/1
3/3
3/74/6
2/50/11/5
1/2
ws
v
u
t
z
3/3
1/9
1/1
3/3
4/74/6
3/51/13/5
2/2
two steps
ws
v
u
t
z
3/3
1/9
0/1
3/3
2/73/6
2/50/11/5
1/2
04/22/23 11:18 Maximum Flow 14
AnalysisIn the worst case, Ford-Fulkerson’s algorithm performs |f*| flow augmentations, where f* is a maximum flowExample
The augmenting paths found alternate between 1 and 2
The algorithm performs 100 augmentations
Finding an augmenting path and augmenting the flow takes O(n m) timeThe running time of Ford-Fulkerson’s algorithm is O(|f*|(n m))
ts
v
u
1/1
1/500/50
1/50 0/50
1
ts
v
u
0/1
1/501/50
1/50 1/50
2
04/22/23 11:18 Maximum Flow 15
Edmonds-Karp AlgorithmVariation of Ford-Fulkerson’s algorithmUses a simple technique for finding good augmenting path in faster running time.
It is more greedy in the choice of path Chooses an augmenting path with the smallest
number of edges This can be done in O(m) by a modified BFS
traversalComplexity O(n m2)Lemma: The number of flow augmentations in the Edmonds-Karp algorithm for a network with n vertices and m edges is no more than n m.
04/22/23 11:18 Maximum Flow 16
Maximum Bipartite Matching
Graph G(V,E) is bipartite (denoted G(V1,V2,E) ) if The vertices V of G can be partitioned into two disjoint sets, V1 and V2
Every edge e of G has one endpoint in V1 and the other in V2.A matching in G is a set of edges (subset of E) that have no endpoints in common. A matching in bipartite graph is called bipartite matching.We are often interested in maximum matching, that is, the matching with maximum number of edges.
V1 V2
M=2M=1
04/22/23 11:18 Maximum Flow 17
Maximum Bipartite Matching
Solution is non-uniqueExamples:(all are maximum, M=2)
V1 V2
04/22/23 11:18 Maximum Flow 18
Reduction to Max Flow Problem
Systematic approach to bipartite matching problemCreate a network flow N from graph G(V1,V2,E):
Add a source s and a sink t Connect s withV1 and t with V2, using directed edges Direct edges E from V1 to V2 and assign capacities c(e)=1
Solve a max flow problem on the network flow N max M = max f
V1 V2
s t
04/22/23 11:18 Maximum Flow 19
Reduction to Max Flow Problem
Proof of correctness f(e) = 1 e M Set M is a matching:
The flow through e is 0 or 1 (capacity is 1) Each vertex in V1 has exactly one incoming edge: by flow
conservation rule there is at most one outgoing edge for v V1 Each vertex in V2 has exactly one outgoing edge: there is at
most one incoming edge for v V2 Hence, each vertex in V1 will be paired in M by at most one
vertex in V2 ., hence M is the matching. Finally, size of M = |f|.
V1 V2
s t
04/22/23 11:18 Maximum Flow 20
Minimum Cost Flow Problem
A variant of the max flow problem, applicable to networks where there is a cost w(e) associated with sending a unit flow through an edge.
Associate cost w(e) with each edge e in the network N Compute flow f with minimum total cost:
min w(f) = e E w(e) f(e) That is, find a minimum-cost flow among all the flows
of maximum value f Sometimes, given a fixed flow f, compute minimum-
cost flow with flow value = f.Solving min-cost flow uses augmented cycles concept.
04/22/23 11:18 Maximum Flow 21
Minimum Cost Flow Problem
Augmenting cycle : a cycle that has non-zero residual capacity f()
Residual capacity f() along the cycle : min of
c(e)-f(e) for forward edges f(e)>0 for backward edges
Example: Initially f=2 and w(f)=8 Augmenting cycle {s,v,u,s} has
residual capacity f() = 1. The cost of is w()=-1 Flow f’ obtained by pushing 1 unit
of flow along has cost: w(f’) = w(f) + w() f() = 8 - 1= 7
ts
u
v
0 / 3,1
1 / 2, 11 / 1, 3
1 / 1, 31 / 2, 1
f(e) / c(e),w(e)
ts
u
v
0/1
0 / 1, 3
2 / 2, 1 1/ 1, 3
2
1 / 2, 1