chap10_1.7m

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Content of Part 2

Chapter 1. Fundamental concepts


Chapter 2. Graph representation
Chapter 3. Graph Traversal
Discrete Mathematics Chapter 4. Tree and Spanning tree
Course preparation group: Chapter 5. Shortest path problem
Nguyễn Khánh Phương
Đỗ Phan Thuận Chapter 6. Maximum flow problem
Phạm Quang Dũng
Huỳnh Thanh Bình
Trần Vĩnh Đức
Bùi Quốc Trung
Đinh Viết Sang
Ban Hà Bằng
1

Contents
PART 1 1. Problem description and applications
COMBINATORIAL THEORY 2. Cut
3. Residual graph and Augmenting path
(Lý thuyết tổ hợp)
4. Ford-Fulkerson algorithm
5. Edmond-Karp algorithm
PART 2 6. Some applications

GRAPH THEORY
(Lý thuyết đồ thị)
2

1
Network Flow in network
Network is a directed graph G = (V, E): Definition. Flow f in network G=(V,E) is to assign value f(e) on each edge e
• There is only one vertex s without any incoming arcs, called (f(e) is flow on edge e) so that following conditions are satisfied:
source vertex and only vertex t without any outgoing arcs 1) Capacity rule:
called target vertex.
• Each edge e of G is assigned a nonnegative value c(e) which For each edge e, 0  f (e)  c(e)
is called capacity of e. 2) Conservation Rule (Điều kiện cân bằng luồng): Each v  s, t
Example:  f ( e)   f ( e )
eE  ( v ) eE  ( v )
v 3
6
1 Definition. Value of flow f is
7 t
s 3 (*)

1
w
9 5
val ( f )   f ( e)   f (e)
eE  ( s ) eE  ( t )
5
u z Edges going out of s Edges going into t
2
(Equation (*) is obtained by summing up all the conservation rules.)

Flow in network Flow in network: Example


Definition. Flow f in network G=(V,E) is to assign value f(e) on each edge e Example:
(f(e) is flow on edge e) so that following conditions are satisfied: v 1/3
2/6
1) Capacity rule: 1/1
3/7 t
s 3/3
For each edge e, 0  f (e)  c(e) w
2/9 4/5
3/5 1/1
2) Conservation Rule (Điều kiện cân bằng luồng): Each v  s, t u z
2/2
 f ( e)   f ( e )
 
eE ( v ) eE ( v )
• 2 values on each edge: value of flow on edge is in red, the other is
E-(v) and E+(v) are sets of arcs entering and leaving vertex v, respectively. capacity of edge.
• Conditions 1) and 2) are satisfied => f is flow on the network.
• Value of flow:
8 = f(s,v) + f(s,u) + f(s,w) = f(v,t) + f(w,t) + f(z,t)
(*)
val ( f )   
f ( e)   f (e )
eE ( s ) eE  ( t )

2
Maximum Flow problem Contents
A flow in network G is called
maximum flow if among all 2/6
v 1/3 1. Problem description and applications
1/1
flows in G, it is the one having
maximum value. s 3/3
3/7 t
2. Cut
w
3/5 1/1 2/9 4/5
3. Residual graph and Augmenting path
Maximum flow problem is u z
the problem aiming to
2/2
Flow with value 8 = 2 + 3 + 3 = 1 + 3 + 4 4. Ford-Fulkerson algorithm
determine a feasible flow
through the network with 4/6
v 3/3
5. Edmond-Karp algorithm
maximum value 1/1
3/7 t
s 3/3
w
6. Some applications
1/1 2/9 4/5
3/5
u z
2/2
Maximum flow with value 10 = 4 + 3 + 3 = 3 + 3 + 4

Some applications Cut


Cut is a partition vertex set of the network into 2 disjoint sets S and T with s 
S, t  T.
Network Vertex Arc Flow • Capacity cap(S,T) of the cut (S, T) is:

Network
transaction stations,
computers, satellites
cables
voice, video,
packets
cap ( S , T )  
eS T
c(e),

gates, registers, where S  T : {(v, w)  E : v  S , w  T }


Electrical network conductors Power circuit
processors Min cut is the cut having minimum capacity.
S = {s}
Mechanical joints rods, beams, springs heat, energy Example 1 2 9 5
T = {t,2,3,4,5,6,7}
pumping stations,
Irrigation pipelines Liquid, water 10
4 15 15 10 Cap(S, T) = 10+5+15=30
water source
S
Finance bank transitions money
s 5 3 8 6 10 t
Goods,
Traffic airport, station highways, flights
customers 15
4 6 10
15
Chemistry sites bonds energy
4 30 7

3
Flow and cut Max Flow and Min Cut
Lemma 1. Assume f is flow, and (S, T) is a cut. Then Corollary. Assume f is a flow, (S, T) is a cut. If val( f ) = cap(S, T), then
Flow through this cut is equal to the value of flow f: f is maximum flow and (S, T) is minimum cut.

 f (e )   f (e )   f (e )   f (e) val ( f )
eS T eT  S eE  (s ) eE  (t )

Flow and cut Max-Flow Min-Cut Theorem


Lemma 2. Assume f is a flow, (S, T) is a cut. Then Theorem (Ford-Fulkerson, 1956): In a network, value of max flow is equal to
capacity of min cut.
val( f )  cap(S, T).
Proof
9
2 9 5
val ( f )  
eS T
f (e)  
eT  S
f ( e) 10
10
1 9
S T 4 0 15 15 0 10


4
 f ( e) 8
t 4 9
8
eS T s 5 3 8 6 10 t

 
eS T
c ( e)
s
4
15 0
10
7 4 0 6 10
15
 cap(S , T ) 6 14
4 30 7
14 Flow value = 28
Cut capacity = 28

4
Contents Greedy algorithm
1. Problem description and applications Greedy algorithm does not provide optimal solution.
4 5
2. Cut 0
0
4 0
Greedy algorithm:
4
Value of flow = 10
3. Residual graph and Augmenting path 10
0
4
4

10 10

4. Ford-Fulkerson algorithm s 10 2 13 3 10 t

5. Edmond-Karp algorithm
Optimal:
6. Some applications 4
4
5 Value of flow = 14
4 4 4
4
4 4
4
10 6 10
s 10 2 13 3 10 t

Greedy algorithm Residual graph


Greedy algorithm:
Network G = (V, E). capacity
• 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). • Arc e = (v, w)  E
v 17 w
• Augument flow along P. • Flow f (e)
6
• Repeat until can not find P • Capacity c(e) flow

s->4->3->t ???
s->2->5->t ??? e = (u,v)  eR = (v,u)
Residual graph: Gf = (V, Ef ).
4 5 • Ef = {e: f(e) < c(e) }  {eR : f(e) > 0 }
0 • Capacity of each arc e
0 4 0 v 11 w
4
0 4 c(e)  f (e) if e  E 6
4 c f ( e)  
0 10 0 10 0 10
 f (e) if e R  E
s 10 2 13 3 10 t

Value
Valueof
offlow
flow==10
0

5
Theorem about maximum flow and minimum cut Ford – Fulkerson algorithm
Augmenting path Theorem (Ford-Fulkerson, 1956): Flow is maximum if and Augmenting flow f along path P
only if there does not exist augmenting path on network. float Augment(f,P)
{
b  cf(P)
Max flow and min cut Theorem (Ford-Fulkerson, 1956): the maximum FOR e  P
possible flow in a network (from source to sink) is exactly equal to the IF (e  E)
minimum capacity of all possible cuts. f(e)  f(e) + b
ELSE
Ford-Fulkerson algorithm
f(eR)  f(e) – b
float Ford_Fulkerson(G,c,s,t)
RETURN f
We will prove the following Theorem: }
{
FOR e  E // initialize flow f to 0
Theorem. Assume f is a flow in network. The following three statements are f(e)  0
equivalent Gf  residual graph for f
(i) Can find the cut (S, T) such that val( f ) = cap(S, T).
WHILE (there exists an augmenting path P)
(ii) f is maximum flow. {
(iii) Could not find augmenting path to augment value flow f. f  augment(f, P)
Update residual graph Gf
}
RETURN f
}

Contents Computation time


1. Problem description and applications Question: Is the Ford-Fulkerson algorithm a polynomial algorithm?
(algorithm with computation time is bounded by a fixed degree
2. Cut polynomial of the input length)
• Answer: Not at all. If the maximum capacity is C then the algorithm
3. Residual graph and Augmenting path may have to do C iterations.
4. Ford-Fulkerson algorithm
The following example shows how the algorithm can take a lot of
5. Edmond-Karp algorithm iteration
6. Some applications

6
Ford – Fulkerson algorithm is not polynomial algoirthm
Augmenting path P: s, 4, 2, t Augmenting path P’: s, 2, 4, t
Contents
Augment flow along P Augment flow along P’ 1. Problem description and applications
G 4 Gf 4
10 X
10
X
0 1
10
2. Cut
10 10

s
9
1X
0X10
9

t s
9
1
9

t
3. Residual graph and Augmenting path
10 10 10 10
4. Ford-Fulkerson algorithm
1X
09 X9 1
0 9 9
2
Gf 4
2 5. Edmond-Karp algorithm
Algorithm executes alternating 1
augmenting flow along two paths P and P’ 109-1 109 6. Some applications
(s, 4) 9
(s, 2) 210 iterations s 1 t
(4, 2)
(2, t ) 109 109 -1
(4, t ) 1
2

Computation time How to select the augmenting path?


Question: Is the Ford-Fulkerson algorithm a polynomial algorithm? Be careful when select augmenting path, because
(algorithm with computation time is bounded by a fixed degree • Several options may lead to an exponential algorithm.
polynomial of the input length) • Smart choice leads to polynomial algorithm.
• Answer: Not at all. If the maximum capacity is C then the algorithm • If capacity is irrational number, the algorithm may not stop
may have to do C iterations.
If the capacities of arcs on network is real, there is an example that the The goal: select augmenting path such that:
Ford-Fulkerson algorithm does not stop. • Can find the augmenting path effectively.
Zwick constructs examples showing that the algorithm may not stop, if • The algorithm requires as few iterations as possible..
the capacity of arcs is irrational
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

7
5. Edmonds – Karp Algorithm Applications
Edmonds and Karp, JACM 1972 • Some general flow problems:
• If the augmenting path is the shortest path from s to t, then • The problem with multiple sources and sinks
the computation time of the algorithm is O(|E|2 |V|). • The problem with limited capacities at nodes
• Airline scheduling
• Image segmentation
• Bipartite matching
• Data mining
• Project selection
• Network connectivity
• …

Ford-Fulkerson algorithm
float Ford_Fulkerson(G,c,s,t)
{
FOR e  E // initialize flow to 0
f(e)  0
Gf  residual graph for flow f

WHILE (there exists an augmenting path P)


{ f  augment(f, P)
update Gf
}
RETURN f
}

Edmonds – Karp algorithm


FOR e  E
f(e)  0
Find augmenting path by BFS: Gf  residual graph for flow f
• Easy to implement WHILE (there exists an augmenting path)
• Augmenting path has the least edges {
find augmenting P by BFS

O(|E|2 |V|) f  augment(f, P)


update Gf
}
RETURN f

You might also like