0% found this document useful (0 votes)
49 views70 pages

Lec-17-20-Network-Flow

The document outlines the problem of finding maximum flow in a directed graph using the Ford-Fulkerson algorithm, which involves defining flow, capacity, and conservation constraints. It details the steps of the algorithm, including initializing flow, finding augmenting paths, and updating flows and residual graphs. Additionally, it discusses the running time of the algorithm and introduces the concept of s-t cuts and their relation to flow values.

Uploaded by

fakertoolzz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views70 pages

Lec-17-20-Network-Flow

The document outlines the problem of finding maximum flow in a directed graph using the Ford-Fulkerson algorithm, which involves defining flow, capacity, and conservation constraints. It details the steps of the algorithm, including initializing flow, finding augmenting paths, and updating flows and residual graphs. Additionally, it discusses the running time of the algorithm and introduces the concept of s-t cuts and their relation to flow values.

Uploaded by

fakertoolzz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 70

Network Flow

Prepared by Pawan K. Mishra


Problem Definition
Given a directed graph G=(V,E)
A source node s in V and a target node t in V
with a capacity associated with each edge e=(u,v) in E, c(e) // another notation c(u,v)

Definition of a flow: An s-t is a flow that maps each edge e in E to a non-negative real
number.
Value of a flow on edge e =(u,v) in E, f(e) // another notation f(u,v)
A flow must satisfy
Capacity Constraint: For each edge e=(u,v), f(e) ≤ c(e).

Conservation Constraint: For each node v in V other than s and t,


summation of flow into v is equal to summation of flow out of v.
The value of a flow f, v(f) is defined to be the amount of a flow out of s.

Goal: To find a flow of maximum value.

Prepared by Pawan K. Mishra


Problem Definition s = source, t = sink.
c(e) = capacity of edge e
Capacity condition:
0 ≤ f(e) ≤ c(e)
Conservation condition:
for v  V – {s, t}:
∑ f(e) = ∑ f(e)
e into v e out of v
Definition of a flow: An s-t is a flow that maps each edge e in E to
a non-negative real number.
Value of a flow on edge e =(u,v) in E, f(e) // another notation
f(u,v)
A flow must satisfy
Capacity Condition: For each edge e=(u,v), f(e) ≤ c(e).
Conservation Condition: For each node v in V other than s and t,
summation of flow into v is equal to summation of flow out of v. The value of a flow f is:
The value of a flow f, v(f) is defined to be the amount of a flow v(f) =∑ f(e)
out of s. e out of s
Goal: To find a flow of maximum value.
Prepared by Pawan K. Mishra
Max-Flow
Ford-Fulkerson Algorithm
1.Initially f (e) = 0 for all e in G //initial graph G is also a residual
graph with each edge full residual capacity

2.While there is an s-t path in the residual graph Gf


2.1) Let P be a simple s-t path in Gf
2.2) f’ = augment(f , P) // change the previous flow
2.3) Update f to be f’ // update the previous flow
2.4) Update the residual graph Gf to be Gf’// build residual graph
EndWhile
Return f

Prepared by Pawan K. Mishra


Ford-Fulkerson Algorithm
Max-Flow

1.Initially f (e) = 0 for all e in G //initial graph G is also a residual


graph with each edge full residual capacity
2.While there is an s-t path in the residual graph Gf
2.1) Let P be a simple s-t path in Gf
2.2) f’ = augment(f , P) // will change previous flow
2.3) Update f to be f’ // update the previous flow
2.4) Update the residual graph Gf to be Gf’ // build residual graph
3.EndWhile Present in G
4.Return f augment(f , P)
Let b = bottleneck (P, f )
For each edge (u, v) ∈ P
If e = (u, v) is a forward edge in P then
Increase f (e) in G by b
Else ((u, v) is a backward edge in P, and let e = (v, u))
decrease f (e) in G by b
Endif
Endfor
Prepared by Pawan K. Mishra Return(f)
Residual Graph
Original edge: e = (u, v) E. u 17 v
6
Flow f(e), capacity c(e).

Create two residual edges residual


Forward edge capacity

e = (u, v) with capacity c(e) - f(e) u 11 v

Backward/reverse edge 6

e’ = (v, u) with capacity f(e)

Residual graph: G f = (V, E f ).


Ef = edges with positive residual
capacity Ef = {e : f(e) <c(e)} ∪ {e’ : f(e) >0}

Prepared by Pawan K. Mishra


Augmenting Path
Definition: an s-t path P in residual graph G f is an
augmenting path
Idea: use an augmenting path in Gf to augment
flow in G.

Increase flow on forward edges


Decrease flow on backward edges

Definition: let bottleneck(P, f) be the minimum


residual capacity (i.e., capacity in Gf) of any edge in
P

Prepared by Pawan K. Mishra


Observations
f ‘ is a flow in G.

At every intermediate stage of the Ford-Fulkerson Algorithm, the flow values {f (e)} and the
residual capacities in Gf are integers.

Let f be a flow in G, and let P be a simple s-t path in Gf. Then ν(f ‘) = ν(f ) + bottleneck(P, f );
and since bottleneck(P, f) > 0, we have ν(f ‘) > ν(f ).

Suppose, as above, that all capacities in the flow network G are integers.
Then the Ford-Fulkerson Algorithm terminates in at most C iterations of the While loop.

Suppose, as above, that all capacities in the flow network G are integers.
Then the Ford-Fulkerson Algorithm can be implemented to run in O(mC) time

Prepared by Pawan K. Mishra


Running Time?

There are at most C augment operations.


How long does it take for each?
Find a residual path O(m+n)
Compute bottleneck O(m)
capacity Update flow O(m)
Update residual graph O(m)

Total running time: O(C(m+n))


Prepared by Pawan K. Mishra
Example
0
2 4 4

G: 0 0 0
10 2 0 8 6 0 10

0 0 0
s 10 3 9 5 10 t

Flow value = 0
Example
0
2 4 4

G 8×
0 ×
0 8 0
10 2 0 8 6 0 10

0 0 ×
0 8
s 10 3 9 5 10 t

Flow value =×
0

Gf
2 4 4 8
10 2 8 6 10

s 10 3 9 5 10 t
Example
0
2 4 4

G 10 ×
8 8 0
10 2 0 × 8 6 0 10
2
0 ×
0 2 ×
8 10
s 10 3 9 5 10 t

Flow value =×
8
2 4 4 10
Gf 8

2 2 8 6 10

s 10 3 9 5 2 t

8
Example
0
2 4 4

G 10 8 ×
0 6
10 2 2 8 6 0 × 10
6
×
0 6 ×
2 8 10
s 10 3 9 5 10 t

Flow value = ×
10
2 4 4 16
Gf 10

2 8 6 10

s 10 3 7 5 t

2 10
Example
×
0 2
2 4 4

G 10 8 ×
6 8
10 2 2 × 8 6 6 10

×
6 8 0
8 10
s 10 3 9 5 10 t

Flow value = ×
16
2 4 4 18
Gf 10 6

2 8 6 4

s 4 3 1 5 t

6 8 10
Example
×
2 3
2 4 4

G 10 ×
8
7 ×
8 9
10 2 0 8 6 6 10

×
8 9 ×
8 9 10
s 10 3 9 5 10 t

2 Flow value = ×
18
2 2 4 19
Gf 10 8

2 8 6 2

s 2 3 1 5 t

8 8 10
Example
3
2 4 4

G 10 7 9
10 2 0 8 6 6 10

9 9 10
s 10 3 9 5 10 t

max flow = 19 3

2 1 4
Gf 10 9

2 7 6 1

1
s 1 3 5 t

9 9 10
Optimality of the
algorithm
Cuts

An s-t cut is a part it ion (A, B) of V wit h s  A and t  B.

t
A s B
Capacity of an s-t cut

An s-t cut is a part it ion (A, B) of V wit h s  A and t  B.

t
A s B
The capacity of a cut (A, B) is c(A,B)=Σc (e)
e out of A
Capacity of an s-t cut
An s-t cut is a part it ion (A, B) of V wit h s  A and t 
B.
The capacity of a cut (A, B) is c(A,B) = Σ c (e)
e out of A

B
2 9 5

A 10 4 15 15 10

source s 5 3 8 6 10 t sink

4 6 15 10
15
capacity of
cut = 30 4 30 7
Capacity of an s-t cut
capacit y of cut = 9 + 15 + 8 + 30 = 62 (Capacity is
sum of weights on edges leaving A.)

A 5
B
2 9

10 4 15 15 10
source
s 5 3 8 6 10 t sink

4 6 15 10
15

4 30 7
Flow of an s-t cut
An s-t cut is a part it ion (A, B) of V wit h s  A and t  B.

t
A s B
Let f be any flow, and let (A, B) be any s-t cut.
Then, the net flow sent across the cut is
∑ f(e) - ∑ f(e)
e out of A e into A
Flow of an s-t cut
An s-t cut is a part it ion (A, B) of V wit h s  A and t  B.

t Flow value lemma.


Let f be any f low, and

s
let (A, B) be any s-t

A B cut. Then, the net flow


sent across the cut is
equal to the amount of
Let f be any flow, and let (A, B) be any s-t cut. flow leaving s.

Then, the net flow sent across the cut is


∑ f(e) - ∑ f(e) = v(f )
e out of A e into A
Flow of an s-t cut
Flow value lemma. Let f be any flow, and let (A, B)
be any s-t cut. Then, the net flow sent across the
cut is equal to the amount leaving s.
∑ f (e) - ∑ f (e) = v(f )
e out of a e into a

value = 24 2
9
9 5 B
A 10 10 4
1
15
0
1
0 9
10
5
4 6 6
source s 5 3 8 6 10 t sink
0
10 4 1 6 1 9
15 10
50
4 7
10 30
Flow of an s-t cut
Flow value lemma. Let f be any flow, and let (A, B)
be any s-t cut. Then, the net flow sent across the
cut is equal to the amount leaving s.
∑ f (e) - ∑ f (e) = v(f )
e out of a e into a
Flow of an s-t cut
Flow value lemma. Let f be any flow, and let (A, B)
be any s-t cut. Then, the net flow sent across the
cut is equal to the amount leaving s.
∑ f (e) - ∑ f (e) = v(f )
e out of a e into a
9
value = 24 2 9 5
A 1 0 9
10 10 0
4 15 1 10
5
4 6 6
t sink
B
source s 5 3 8 6 10
0
10 4 1 6 15 9
15 10
0
4 7
10 30
Flow of an s-t cut
Flow value lemma. Let f be any flow, and let (A, B)
be any s- t cut. Then ∑ f(e) - ∑ f(e) = v(f ).
e out of A e into A
Proof: ∑ f(e) - ∑ f(e)
e out of A e into A

= ∑ f(e) – ∑ f(e) + ∑ f(e) - ∑ f(e)


e out of s e in s e out of e in of
A \ {s} A \ {s}
= ∑ f(e)
e out of s by flow conservation, all
terms except v = s are 0
if both endpoints of e are in
A, there will be canceling
terms for that edge
by definition = 0
Corollary: Let f be any flow, and let ( A,
B) be any s-t cut. Then v(f ) ≤ c( A, B).

Proof. v(f) = ∑ f(e) - ∑ f(e) By previous lemma

e out of A e into A

≤ ∑ f(e)
e out of A

≤ ∑ c(e) = c(A,B)
e out of A
Corollary: Let f be any flow, and let ( A, B)
be any s-t cut. Then v(f ) ≤ c( A, B).
Interpretation: every cut gives an upper bound
on the value of every flow, and hence the value
of the maximum flow.

What is the best (i.e. smallest)


upper bound?
Max-Flow Min-Cut theorem
Corollary: Let f be any flow, and let ( A, B)
be any s-t cut. Then v(f ) ≤ c( A, B).
Interpretation: every cut gives an upper bound
on the value of every flow, and hence the value
of the maximum flow.

What is the best (i.e. smallest)


upper bound?
Max-flow min-cut theorem. Value of a max flow = capacity of a min cut
Minimum Cut Problem
Find an s-t cut of minimum capacity.
here capacit y = 10 + 8 + 10 = 28
B

2 9 5
A
10 4 15 1 10
5
source s 5 3 8 6 10 t sink

4 6 1 10
15
5
4 30 7
Augmenting path theorem.

A flow f is a max flow iff no augmenting paths.

Pf. The following three conditions are equivalent for any flow f :

i. There exists a cut (A, B) such that c(A, B) = v( f ).


ii. f is a max flow.
iii. There is no augmenting path with respect to f.

[ i ⇒ ii ] This is straight forward.


Augmenting path theorem.

A flow f is a max flow iff no augmenting paths.

Pf. The following three conditions are equivalent for any flow f :

i. There exists a cut (A, B) such that c(A, B) = v( f ).


ii. f is a max flow.
iii. There is no augmenting path with respect to f.

[ ii ⇒ iii ] We prove contrapositive: ¬ iii ⇒ ¬ ii.

Suppose that there is an augmenting path with respect to f.


Can improve flow f by sending flow along this path.
Thus, f is not a max flow.
i There exists a cut (A, B) such that c(A, B) = v( f ).
ii f is a max flow.
iii There is no augmenting path with respect to f.

[ iii ⇒ i ]
Let f be a flow with no augmenting paths.
Let A = set of nodes reachable from s in residual network Gf.
By definition of A: s ∈ A.
By definition of flow f: t ∉ A.

t
A s B
i There exists a cut (A, B) such that c(A, B) = v( f ).
ii f is a max flow.
iii There is no augmenting path with respect to f.

[ iii ⇒ i ]
Let f be a flow with no augmenting paths.
Let A = set of nodes reachable from s in residual network Gf.
By definition of A: s ∈ A.
By definition of flow f: t ∉ A.

t
s B
val(f ) = ∑ f(e) - ∑ f(e)
e out of A e into A
A
flow
value
lemma
i There exists a cut (A, B) such that c(A, B) = v( f ).
ii f is a max flow.
iii There is no augmenting path with respect to f.

[ iii ⇒ i ]
Let f be a flow with no augmenting paths.
Let A = set of nodes reachable from s in residual network Gf.
By definition of A: s ∈ A.
By definition of flow f: t ∉ A.

t
s B
val(f ) = ∑ f(e) - ∑ f(e)
v w
e out of A e into A
A
flow
value
= ∑ c (e) - edge e = (v, w) in G with v  A, w  B must have
e out of A
lemma f(e)= c(e)
otherwise there exist a residual capacity on e in Gf,
and v is reachable form s, which is a contradiction
i There exists a cut (A, B) such that c(A, B) = v( f ).
ii f is a max flow.
iii There is no augmenting path with respect to f.
edge e = (x, y) in G with x  B, y  A
[ iii ⇒ i ] must have f (e) = 0, if not then
・Let f be a flow with no augmenting paths. There exist residual capacity on edge (y,x) in Gf
which means x reachable from y in Gf, but it is
・ Let A = set of nodes reachable from s in residual network Gf. not possible

・By definition of A: s ∈ A.
x
・By definition of flow f: t ∉ A. y
t
s B
val(f ) = ∑ f(e) - ∑ f(e)
v w
e out of A e into A
A
flow
value
= ∑ c (e) - 0 edge e = (v, w) in G with v  A, w  B must have
e out of A f(e)= c(e)
lemma
= c(A , B ) otherwise there exist a residual capacity on e in Gf,
and v is reachable form s, which is a contradiction
Network Flow
APPLICATIONS of FF

Prepared by Pawan K. Mishra


1. Suppose, we are given integral capacity for
each edge, then via FF algorithm we can
generate max flow where all the flows are
integral

2. How to argue max flow is less than some integer K ?

FIND any s-t cut with cut capacity less


than K

Prepared by Pawan K. Mishra


Edge Disjoint Paths
Given d i r e c t e d g r a p h G = (V,E) and two nodes s and t
■Directed graph (V, E), source s, sink t.
■Two paths are edge-disjoint if they have no arc in common.
Disjoint path problem: find max number of edge-disjoint s-t paths.

2 5

s 3 6 t

4 7

Prepared by Pawan K. Mishra


Edge Disjoint Paths
Given d i r e c t e d g r a p h G = (V,E) and two nodes s and t
■Directed graph (V, E), source s, sink t.
■Two paths are edge-disjoint if they have no arc in common.
Disjoint path problem: find max number of edge-disjoint s-t paths.

2 5

s 3 6 t

4 7

Prepared by Pawan K. Mishra


Network connectivity problem.

Given a digraph G = (V, E) and two nodes s and t, find


min number of edges whose removal disconnects t from
s.
i.e., A set of edges F  E disconnects t from s if each
s-t paths uses at least one edge in F.
2 5

s 3 6 t

4 7

Prepared by Pawan K. Mishra


Edge Disjoint Paths
Max flow formulation: assign unit capacity to every
edge.

1
1 1
1 1
1
s 1 1 t
1
1 1 1 1

Theorem. There are k edge-disjoint paths


from s to t iff the max flow value is k.
Prepared by Pawan K. Mishra
Edge Disjoint Paths
Max flow formulation: assign unit capacity to every
edge.

1
1 1
1 1
1
s 1 1 t
1
1 1 1 1

Theorem. There are k edge-disjoint paths


from s to t iff the max flow value is k.
Prepared by Pawan K. Mishra
Edge Disjoint Paths
Max flow formulation: assign unit capacity to every edge.

1
1 1
1 1
1
s 1 1 t
1
1 1 1 1

Theorem. There are k edge-disjoint paths from s to t iff the max flow value is k.
Proof. (  )
Suppose there are k edge-disjoint paths P1, . . . , Pk.
Set f(e) = 1 if e participates in some path Pi ; otherwise, set f(e) = 0.
Since paths are edge-disjoint, f is a flow of value k.

Prepared by Pawan K. Mishra


Edge Disjoint Paths
Max flow formulation: assign unit capacity to every edge.

1
1 1
1 1
1
s 1 1 t
1
1 1 1 1

Theorem. There are k edge-disjoint paths from s to t iff the max flow value is k.
Proof. (  )
Suppose max flow value is k. By integrality theorem, there exists {0, 1} flow f of value k.
Consider edge (s,v) with f(s,v) = 1.
–by conservation, there exists an arc (v,w) with f(v,w) = 1
–continue until reach t, always choosing a new edge
Produces k edge-disjoint paths.

Prepared by Pawan K. Mishra


Menger’s Theorem (1927)
The max number of edge-
disjoint s-t paths is equal
to the min number of arcs
whose removal disconnects t
from s. Proof using Max Flow-Min Cut Theorem (H/W) …

Prepared by Pawan K. Mishra


MATCHING
Input: undirected graph G = (V, E).
M  E is a matching if each node appears in at most
edge in M.
Max matching: find a max cardinality matching.

12

Prepared by Pawan K. Mishra


Bipartite Matching
Input: undirected, bipartite graph G = (L R, E).
M  E is a matching if each node appears in at most edge in M.
Maximum matching: find a matching with as many edges as
possible.

1 1'

2 2' matching
1-2', 3-1', 4-5'

3 3'

4 4'

L 5 5' R

Prepared by Pawan K. Mishra 4


Bipartite Matching
Bipartite matching.
◼ Input: undirected, bipartite graph G = (L  R, E).
◼ M  E is a matching if each node appears in at most edge in M.
◼ Maximum matching: find a matching with as many edges as possible.

1 1'

2 2' matching
1-1, 2-2, 3-3,5-5

3 3'

4 4'

L 5 5' R

Prepared by Pawan K. Mishra 4


Reducing Bipartite Matching toCould
Maximum
also make
Flow
Reduction to Max flow. capacities in the
middle ∞
◼ Create digraph G' = (𝐿 𝖴 𝑅 𝖴 {s, t}, E' ).
◼ Direct all edges from L to R, and assign capacity 1.
◼ Add source s, and capacity 1 edges from s to each node in L.
◼ Add sink t, and capacity 1 edges from each node in R to t.
Run FF and return the edges between 𝐋 𝖴 𝑹 carrying flow.

G' 1 1 1'

1 1
2 2'

s 3 3' t

4 4'

L 5 5' R

Prepared by Pawan K. Mishra 14


Bipartite Matching: Proof of Correctness

Theorem. Max matching M is of size k iff max flow has value k

Prepared by Pawan K. Mishra


Bipartite Matching: Proof of Correctness

Theorem. Max matching M is of size k iff max flow has value k

Prepared by Pawan K. Mishra


Bipartite Matching: Proof of Correctness
Theorem. Max matching M is of size k iff max flow has value k
Proof. 
Given max matching M of cardinality k.
Consider f sending 1 unit along path (s,u,v,t) for each (u,v)∈ 𝑀.
f is a flow, and has value k. ▪

1 1' 1 1 1'

1 1
2 2' 2 2'

3 3' s 3 3' t

4 4' 4 4'

G G'
5 5' 5 5'

Prepared by Pawan K. Mishra 17


Bipartite Matching: Proof of Correctness
Theorem. Max matching M is of size k iff max flow has value k
Proof. 
Let f be a max flow in G' of value k.
Integrality theorem  we can find a max flow f that is integral;
all capacities are 1  can find f that takes values only in {0,1}
Consider M = set of edges from L to R with f(e) = 1.
– Each node in L and R participates in at most one edge in M
Because all capacities are 1 and flow must be conserved
– |M| = k: consider flow across cut (L 𝖴 {𝑠}, R𝖴 {𝑡})
1 1 1' 1 1'

1 1
2 2' 2 2'

s 3 3' t 3 3'

4 4' 4 4'

G'
5 5' 5 5'
Prepared by Pawan K. Mishra 18
Perfect Matching
Def. A matching M  E is perfect if each node appears in
exactly one edge in M.

Q. When does a bipartite graph have a perfect matching?

Structure of bipartite graphs with perfect matchings.


◼Clearly we must have |L| = |R|.
◼What other conditions are necessary?
◼What conditions are sufficient?

Prepared by Pawan K. Mishra 19


Perfect Matching
Notation. Let S be a subset of nodes, and let N(S) be the set of nodes
adjacent to nodes in S.

Observation. If a bipartite graph G = (L  R, E), has a perfect


matching, then |N(X)|  |X| for all subsets X  L.

1 1'

2 2' No perfect matching:


S = { 2, 4, 5 }
3 3' N(S) = { 2', 5' }.

4 4'

L 5 5' R
Prepared by Pawan K. Mishra 20
Marriage Theorem (HALLS THEOREM)
Marriage Theorem.[Frobenius 1917, Hall 1935]
Let G = (L  R, E) be a bipartite graph with |L| = |R|.
Then, G has a perfect matching iff

|N(X)|  |X| for all subsets X  L.

Prepared by Pawan K. Mishra


Marriage Theorem (HALLS THEOREM)
Marriage Theorem.[Frobenius 1917, Hall 1935]
Let G = (L  R, E) be a bipartite graph with |L| = |R|.
Then, G has a perfect matching iff

|N(X)|  |X| for all subsets X  L.

If G has a perfect matching, then |N(X)|  |X| for all subsets X  L.


Proof. ()This is straight forward.

Prepared by Pawan K. Mishra


Proof. ( ) If |N(X)|  |X| for all subsets X  L, then G has a perfect matching

Contrapositive: Suppose G does not have perfect matching. Then, there


exists a subset X  L such that |N(X)| < |X|.

Prepared by Pawan K. Mishra


Proof. ( ) If |N(X)|  |X| for all subsets X  L, then G has a perfect matching

Contrapositive: Suppose G does not have perfect matching. Then, there


exists a subset X  L such that |N(X)| < |X|.

Prepared by Pawan K. Mishra


Proof. ( ) If |N(X)|  |X| for all subsets X  L, then G has a perfect matching

Contrapositive: Suppose G does not have perfect matching. Then, there


exists a subset X  L such that |N(X)| < |X|.

Prepared by Pawan K. Mishra

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy