0% found this document useful (0 votes)
20 views46 pages

2 - 6 MaxFlow EN V2

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)
20 views46 pages

2 - 6 MaxFlow EN V2

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/ 46

Discrete

Mathematics
PART 1
COMBINATORIAL THEORY
(Lý thuyết tổ hợp)

PART 2
GRAPH THEORY
(Lý thuyết đồ thị)
3
Content of Part 2

Chapter 1. Fundamental concepts


Chapter 2. Graph representation
Chapter 3. Graph Traversal
Chapter 4. Tree and Spanning tree
Chapter 5. Shortest path problem
Chapter 6. Maximum flow problem
Contents

1. Problem description and applications


2. Cut
3. Residual graph and Augmenting path
4. Ford-Fulkerson algorithm
5. Edmond-Karp algorithm
6. Some applications
Network
Network is a directed graph G = (V, E):
• There is only one vertex s without any incoming arcs,
called source vertex and only vertex t without any
outgoing arcs called target vertex.
• Each edge e of G is assigned a nonnegative value c(e)
which is called capacity of e.
Example:
v 3
6
1
7 t
s 3
w
1 9 5
5
u z
2
Flow in network
Definition. Flow f in network G=(V,E) is to assign value f(e) on each edge
e
(f(e) is flow on edge e) so that following conditions are satisfied:
1) Capacity rule:
For each edge e, 0 ≤ f (e) ≤ c(e)
2) Conservation Rule (Điều kiện cân bằng luồng): Each v ≠ s, t

E-(v) and E+(v) are sets of arcs entering and leaving vertex v, respectively.
v 1/ 3
Conditions 1) and 2) are satisfied => 2/ 6
1/ 1
??/ t
f is flow in network 3/ 7
s 3/ 3
e.g. oil flowing through w
4/ 5
1/1 2/ 9
??/ ??/
pipes, internet routing 3/5
2/ 2
??/
u z
Flow in network
Definition. Flow f in network G=(V,E) is to assign value f(e) on each edge e
(f(e) is flow on edge e) so that following conditions are satisfied:
1) Capacity rule:
For each edge e, 0 ≤ f (e) ≤ c(e)
2) Conservation Rule (Điều kiện cân bằng luồng): Each v ≠ s, t

Definition. Value of flow f is

Edges going out of s Edges going into t


(Equation (*) is obtained by summing up all the conservation rules.)
Example:
• 2 values on each edge: value of flow on edge is in red, the other is
capacity of edge.
• Conditions 1) and 2) are satisfied => f is flow on the network.
Flow in network: Example
• Value of flow:
8 = f(s,v) + f(s,u) + f(s,w) = f(v,t) + f(w,t) + f(z,t)
v 1/3
2/6
1/1 t
3/7
s 3/3
w
1/1 2/9 4/5
3/5
u z
2/2
Maximum Flow problem
A flow in network G is called maximum flow if among all flows in G, it is
the one having maximum value.

Maximum flow problem is the problem aiming to determine a feasible


flow through the network with maximum value

Flow with value 8 = 2 + 3 + 3 = 1 + 3 + 4

v v 3/3
1/3 4/6
2/6 1/1
1/1 t 3/7 t
3/7 s 3/3
s 3/3
w w
2/9 4/5 1/1 2/9 4/5
3/5 1/1 3/5
u z u z
2/2 2/2
Maximum flow with value 10 = 4 + 3 + 3 = 3 + 3 + 4
Some applications

Network Vertex Arc Flow

transaction stations, voice, video,


Network cables
computers, satellites packets
Electrical gates, registers, Power
conductors
network processors circuit
Mechanical joints rods, beams, springs heat, energy
pumping stations,
Irrigation pipelines Liquid, water
water source
Finance bank transitions money

Goods,
Traffic airport, station highways, flights
customers

Chemistry sites bonds energy


Contents

1. Problem description and applications


2. Cut
3. Residual graph and Augmenting path
4. Ford-Fulkerson algorithm
5. Edmond-Karp algorithm
6. Some applications
Cut
Cut is a partition vertex set of the network into 2 disjoint sets S and T with
s ∈ S, t ∈ T.
• Capacity cap(S,T) of the cut (S, T) is:

Min cut is the cut having minimum capacity.


2 5
S = {s}
Example 1 9
T = {t,2,3,4,5,6,7}
10 15 15 10 Cap(S, T) = 10+5+15=30
4
S
s 5 3 8 6 10 t

4 6 15 10
15

4 30 7
Flow through the cut
Definition. Assume f is a flow in network and (S,T) is a cut. We call value of flow
through the cut (S,T) is the value
6+0+8+10 0

where: S → T = {(v,w)∈E: v∈S, w∈T} S = {s,2,3,4}


T = {5,6,7,t}
T→ S = {(v,w)∈E: v∈T, w ∈S} Flow through the cut (S,T) = ???
6
Example 1 2 9 5
24
10 6
0
10 15 15 0 10
S 4 4

4 8 8
s 5 3 8 6 10 t

0 10
4 0 6 15 0 10
15
10 10
4 30 7
Flow and cut
Lemma 1. Assume f is flow, and (S, T) is a cut. Then
Flow through this cut is equal to the value of flow f:
Flow and cut
Lemma 2. Assume f is a flow, (S, T) is a cut. Then
val( f ) ≤ cap(S, T).
Proof

S 4 T
8
t

s
7
6
Max Flow and Min Cut
Corollary. Assume f is a flow, (S, T) is a cut. If val( f ) = cap(S, T), then
f is maximum flow and (S, T) is minimum cut.

The flow in network G is called maximum flow if among all Minimum cut: the cut of minimum capacity
flows in G, its value is maximum

Proof: Consider f ’ is arbitrary flow and (S’,T’) is arbitrary cut.


Using Lemma 2, we have: Assumption Lemma 2
val( f ’) ≤ cap(S,T) = val( f ) ≤ cap(S’,T’)

f ’ is arbitrary
Lemma flowf is a flow, and (S, T) is a cut. Then
2. Assume f is max flow
val( f’ ) ≤ val (f ) val( f ) ≤ cap(S, T)

(S’, T’) is arbitrary cut


(S,T) is min cut
cap( S,T ) ≤ cap( S’,T’ )
Max-Flow Min-Cut Theorem
Theorem (Ford-Fulkerson, 1956): In a network, value of max flow is equal
to capacity of min cut.

9
2 9 5

10 9
1
10 15 15 0 10
4 0

4 8 9
s 5 3 8 6 10 t

4 10
4 0 6 15 0 10
15
14
4 30 7
14 Flow value = 28
Cut capacity = 28
Contents

1. Problem description and applications


2. Cut
3. Residual graph and Augmenting path
4. Ford-Fulkerson algorithm
5. Edmond-Karp algorithm
6. Some applications
Greedy algorithm
Greedy algorithm:
• Starting with flow 0 (value of flow = 0).
• Find path P from s to t such that each edge e satisfies f (e)<c(e).
• Augument flow along P.
• Repeat until can not find P
s->4->3->t ???
s->2->5->t ???

4 5
0
0 4 0
4
0 4
0 10 4
0 10 0 10
s 10 2 13 3 10 t

Value
Valueof
offlow
flow==10
0
Greedy algorithm
Greedy algorithm does not provide optimal solution.
4 5
0 Greedy algorithm:
0 4 0
4
Value of flow = 10
0 4
10 4
10 10
s 10 2 13 3 10 t

Optimal:
4 5 Value of flow = 14
4
4 4 4
4
4 4
10 4
6 10
s 10 2 13 3 10 t
Residual graph

Network G = (V, E). capacity


• Arc e = (v, w) ∈ E
v 17 w
• Flow f (e)
6
• Capacity c(e) flow

e = (u,v) ⇒ eR = (v,u)
Residual graph: Gf = (V, Ef ).
• Ef = {e: f(e) < c(e) } ∪ {eR : f(e) > 0 }
• Capacity of each arc e
v 11 w
6
Residual graph - Example
Residual graph: Gf = (V, Ef ).
– Ef = {e : f(e) < c(e)} ∪ {eR : f(e) > 0}.
– cf(e) indicates the maximum amount that can increase flow on arc e.
– cf(eR) indicates the maximum amount that can decrease flow on arc e.
(s,4)
4 5 (s,2)
0
0 4 (2,3)
0
G 4
4
(4,3)
0
4
(2,5)
10 10 10
(3,t)
s 10 2 13 3 10 t
4 5
(5,t)

4
Gf 4
4
4
s 10 2 10 3 10 t

3
Residual graph - Example
Residual graph: Gf = (V, Ef ).
– Ef = {e : f(e) < c(e)} ∪ {eR : f(e) > 0}.
– cf(e) indicates the maximum amount that can increase flow on arc e.
– cf(eR) indicates the maximum amount that can decrease flow on arc e.
(s,4)
Augmenting path = path from s to t on the residual graph Gf.
(s,2)
Capacity of the path: cf (P) = min {cf (e): e ∈ P }.
(2,3)
Build new Gf 4 5
Find augmenting path
4 X
0 (4,3)
4 X
0 4 (2,5)
On new Gf 0 4
X
4
G 4 X
0 4 (3,t)
10 4 (5,t)
X 6
10 10
s 10 2 13 3 10 t
Example: Augmenting path P: 4 5
cf (P) = 4
s, 4, 3, 2, 5, t 4
Gf 4
4
4
s 10 2 10 3 10 t

3
Augmenting path
Augmenting path = path from s to t on the residual graph.
• Max flow ⇔ could not find any augmenting path??? (s,4)
(s,2)
(2,3)
Value of flow = 14 4 5 (4,3)
4
4 (2,5)
4 4
G 4 (3,t)
4 4
4 (5,t)
10 6 10
s 10 2 13 3 10 t

Find augmenting path P???


4 5

4
Gf 4
4
4
s 10 2 6 3 10 t
7
Theorem about maximum flow and minimum cut

Augmenting path Theorem (Ford-Fulkerson, 1956): Flow is maximum if


and only if there does not exist augmenting path on network.

Max flow and min cut Theorem (Ford-Fulkerson, 1956): the maximum
possible flow in a network (from source to sink) is exactly equal to the
minimum capacity of all possible cuts.

We will prove the following Theorem:


Theorem. Assume f is a flow in network. The following three statements
are equivalent
(i)Can find the cut (S, T) such that val( f ) = cap(S, T).
(ii) f is maximum flow.
(iii) Could not find augmenting path to augment value flow f.
Contents

1. Problem description and applications


2. Cut
3. Residual graph and Augmenting path
4. Ford-Fulkerson algorithm
5. Edmond-Karp algorithm
6. Some applications
Ford – Fulkerson algorithm
Augmenting flow f along path P
float Augment(f,P)
{
b ← cf(P)
FOR e ∈ P
IF (e ∈ E)
f(e) ← f(e) + b
ELSE
f(eR) ← f(e) – b Ford-Fulkerson algorithm
float Ford_Fulkerson(G,c,s,t)
RETURN f
{
}
FOR e ∈ E // initialize flow f to 0
f(e) ← 0
Gf ← residual graph for f

WHILE (there exists an augmenting path P)


{
f ← augment(f, P)
Update residual graph Gf
}
RETURN f
}
Computation time
Question: Is the Ford-Fulkerson algorithm a polynomial algorithm?
(algorithm with computation time is bounded by a fixed degree
polynomial of the input length)
• Answer: Not at all. If the maximum capacity is C then the
algorithm may have to do C iterations.

The following example shows how the algorithm can take a lot of
iteration
Ford – Fulkerson algorithm is not polynomial algoirthm

Augmenting path P: s, 4, 2, t

G 4 Gf 4
10X 0 1
X
10 10 10 10
9 9 9 9
s XX
10 10 t s 1 t

10 10 10 10
09
1X X9 1
0 9 9
2 2
Algorithm executes alternating Gf 4
1
augmenting flow along two paths P and P’ 109-1 109
(s, 4) 9
(s, 2) 2×10 iterations s 1 t
(4, 2)
(2, t ) 109 109 -1
(4, t ) 1
2

Augmenting path P’: s, 2, 4, t


Computation time
Question: Is the Ford-Fulkerson algorithm a polynomial algorithm?
(algorithm with computation time is bounded by a fixed degree
polynomial of the input length)
• Answer: Not at all. If the maximum capacity is C then the
algorithm may have to do C iterations.
If the capacities of arcs on network is real, there is an example that
the Ford-Fulkerson algorithm does not stop.
Zwick constructs examples showing that the algorithm may not stop,
if the capacity of arcs is irrational
Example: Ford – Fulkerson algorithm does not terminate

Zwick constructs examples showing that the algorithm may not stop,
if the capacity of arcs is irrational

s
X X
X
1 1 φ

X
X X
t
Ford – Fulkerson algorithm
Assumption: All capacities on arcs are integers in the range [0, C].
Immutability: Each value of flow value f(e) and capacity cf (e) are
always integer during algorithm execution.
Theorem: F-F algorithm stops after not more than val( f *) ≤ nC
iterations.
Proof.
After each augmenting flow, value of flow is augmented by at least 1

Corollary. Computation time of Ford-Fulkerson algorithm is


O(m.n.C)
Corollary. If C = 1, then the computation time of algorithm is
O(mn).
Contents

1. Problem description and applications


2. Cut
3. Residual graph and Augmenting path
4. Ford-Fulkerson algorithm
5. Edmond-Karp algorithm
6. Some applications
How to select the augmenting path?
Be careful when select augmenting path, because
• Several options may lead to an exponential algorithm.
• Smart choice leads to polynomial algorithm.
• If capacity is irrational number, the algorithm may not stop

The goal: select augmenting path such that:


• Can find the augmenting path effectively.
• The algorithm requires as few iterations as possible..

Select augmenting path with


• Maximum capacity. (fat path)
• Capacity is large enough. (capacity scaling)
• The number of edges along the way is the least. (shortest path)
Edmond-Karp algorithm Applying BFS
5. Edmonds – Karp Algorithm
Edmonds and Karp, JACM 1972
• If the augmenting path is the shortest path from s to t,
then the computation time of the algorithm is O(|E|2 |V|).
Ford-Fulkerson algorithm
float Ford_Fulkerson(G,c,s,t)
{
FOR augmenting
Find e ∈ E // initialize
path by BFS: flow to 0
f(e) ← 0
• GEasy to implement
f ← residual graph for flow f

• WHILE
Augmenting
(therepath has the
exists anleast edges
augmenting path P)
{ f ← augment(f, P)
update Gf
}
RETURN f
}

Edmonds – Karp algorithm


FOR e ∈ E
f(e) ← 0
Gf ← residual graph for flow f

WHILE (there exists an augmenting path)


{
find augmenting P by BFS
f ← augment(f, P)
O(|E|2 |V|) update Gf
}
RETURN f
Edmonds-Karp Algorithm

0
Flow
2 4 5
Capacity
G: 0 0 0
10 2 0 8 60 10

0 0 0
s 10 3 9 4 10 t

Value of flow = 0
Build the residual graph Gf

38
Edmonds-Karp Algorithm

0
flow
2 4 5
capacity
G: 8 X
0 0 8
X 0
10 2 0 8 60 10

0 0 8 X
0
s 10 3 9 4 10 t

Value of flow
flow==80
Augmenting path P: s, 2, 4, t
Augment flow along P 2 4 5
capacity
Gf:
10 2 8 6 10

s 10 3 9 4 10 t
Edmonds-Karp Algorithm
X 2
0
2 4 5

G: 10 8
X X
0 2
8
10 2 0 8 60 10

0 0 8
s 10 3 9 4 10 t

Build residual graph Gf


Valueof
Value offlow
flow==10
8
Augmenting path P: s, 2, 5, t Augment flow along P
(s, 2)
(s, 3) 2 4 5
(2, 3) Gf: 8
(2, 5) 2 8 6 10
2
(2, 4)
(3, 4)
(5, t) s 10 3 9 4 2 t
(4, 5) 8
(4, t)
Edmonds-Karp Algorithm

2
2 4 5

G: 10 8 2
10 2 0 8 60 10

0
X 2 0 2
X 10 8
X
s 10 3 9 4 10 t

Build residual graph Gf


Value
Value of
of flow
flow =
= 10
12
Augmenting path P: s, 3, 4, t 2
Augment flow along P
2 2 5

Gf: 2
10 2 8 6 8

s 10 3 9 4 2 t

8
Edmonds-Karp Algorithm

2
2 4 5

G: 10 8 2 8
X
10 2 0 8 6X
0 10
6
2 8
X X 8
2 10
s 10 3 9 4 10 t

Build residual graph Gf


Augmenting path P: s, 3, 4, 5, t Value of flow = 12
18
2
Augment flow along P
2 2 5

Gf: 2
10 2 8 6 8

s 8 3 7 4 10 t

2 2
Edmonds-Karp Algorithm

X
2 3
2 4 5

G: 10 X 7
8 X
8 9
10 2 0 8 66 10

X
8 9 8 9
X 10
s 10 3 9 4 10 t

Build residual graph Gf


Value
Value of
of flow
flow =
= 18
19
Augmenting path P: s, 3, 4, 2, 5, t 2
Augment flow along P
2 2 5

Gf: 8
10 2 8 6 2

s 2 3 1 4 10 t

8 8
Conclusion: In graph Gf, S = set of vertices reached from s by BFS(s)
- Min cut (S, T): S = {s, 3}; T = {2,4,5,t}
- Max flow: val ( f ) = 10 + 9 = 19
3
2 4 5

G: 10 7 9
10 2 0 8 66 10

9 9 10
s 10 3 9 4 10 t

Build residual graph Gf


Value of flow = 19
Augmenting path P: 3
Not exist 2 1 5

Gf: 9
1
10 2 7 6 1

s 1 3 9 4 10 t
9
Applications

• Some general flow problems:


• The problem with multiple sources and sinks
• The problem with limited capacities at nodes
• Airline scheduling
• Image segmentation
• Bipartite matching
• Data mining
• Project selection
• Network connectivity
• …
THANK YOU !

46

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