You are on page 1of 26

NETWORK AND FLOW

Discrete Math 2

htthua@ptithcm.edu.vn
Content
• Definitions
• Maximum flow problem
• Ford-Fulkerson algorithm to find the maximum
flow

2
Definitions
Network
• Definition 1: The network is a directed graph G = (X,U) with no rings, where:
(1) There is only one vertex with no input arc, called the transmitting vertex, denoted x 0 .
(2) There is only one vertex with no outgoing arc, called the receiver vertex, denoted z.
(3) Each arc u  U, is assigned a non-negative weight, denoted c(u)≥0, called the
throughability (bandwidth) of that arc.
Symbol: U– (x) = The set of arcs entering the vertex x; U+ (x) = Set of arcs
coming out from vertex x.
– We have: U– ( x 0 ) = ; U+ ( z ) = 

4
Stream
• Definition 2: Given a network G = (X,U) with emitter vertex x0 , receiver z,
and throughput c(u), u U:
– (1) A flow on a network G is a non-negative function defined on U into R+, i.e. :U→R+,
u → (u)
Φ(u) is called the stream value Φ on arc u , satisfying the following conditions:
• Condition on arc : The flow per arc does not exceed the pass capacity on arc: 0≤ Φ(u) c(u ), uU
• Equilibrium condition on each vertex : Total value of flow on arcs entering each vertex (minus x 0 and z)
= Sum value of flow on arcs leaving that vertex:

– (2) The value of flow Φ on G , denoted Val (Φ), is determined:

5
Slice
• Definition 3: A slice (A, A') is a way of partitioning the vertex set X=A A' such
that A A'= and A contains x0 , A' contains z
– Passability of the slice (A, A') , denoted c(A, A') :

– The slice with the smallest passability is called the narrowest slice.
• Theorem 1 : The value of every stream Φ in the network is always less than or
equal to the pass capacity of any slice (A, A') in the network: 𝑣𝑎𝑙 () 𝑐 (A, A')
– Corollary : The value of the maximum flow in the network is equal to the throughput of the
narrowest slice in the network.

6
Maximum flow problem
Maximum flow problem
• Problem: Let the network G=(X,U). Find the flow Φ* on the network G such
that the value Val(Φ*) is maximum .
Note:
To find the maximum flow value:
1) Method 1: List all the slices on the G network and calculate the passability of these slices
to find the narrowest slice (which is the maximum flow value).
2) Method 2: If we know the maximum flow on G, we can determine the narrowest slice
from the Ford–Fulkerson Algorithm.
• Practical application:
– Consider the directed graph corresponding to the oil pipeline system
– The oil pipes correspond to the arcs of the graph
– The sending point is an oil tanker , the receiving point is an oil tank
– The junction between the pipes corresponds to the vertices of the graph
– The throughput of the arcs corresponding to the cross-section of the tubes
– Need to find the largest flow of oil that can be pumped from the tanker to the storage tank?
8
Example of Massive Flow Problem

9
Ford-Fulkerson algorithm to find
the maximum flow
flow increasing Graph, flow increasing Path
• Suppose f is a flow in the network G=(V,E). Construct the weight
graph G f = (V,E f ) with arc set E f is determined by the following
rule: Consider e =(u,v) E
– If f(u,v)<c(u,v), then (u,v ) E f with weight c(u,v) - f(u,v)
•  can increase the flow f on arc (u,v) with a maximum value of c(u,v) - f (u,v);
• The arc (u,v) is called the forward arc on Gf
– If f(u,v) >0, then (v ,u) E f with weight f(u,v)
•  can reduce the flow f on arc (u,v) with a maximum value of f (u,v);
• The arc (v,u) is called the inverse arc on Gf .
• G f is called a flow increasing graph and any path from s to t on a
flow increasing graph G f is called a flow increasing graph f .

11
Example: Flow increasing graph

12
Increase flow along the PATH

• Consider 𝑃 = (𝑠 = 𝑣 0 , 𝑣 1 , 𝑣 2 , … , 𝑣 = 𝑡) is a path from 𝑠 to 𝑡 on the


flow increasing graph 𝐺𝑓
• Let be the minimum value of the weights of the arcs on the path.
• Build a flow on the network 𝐺 according to the following rules:

• The flow transformation procedure as above is to increase flow along


the path 𝑃.

13
Example: Increase flow
by path

14
Flow Increase Path

• Definition 4: Given network G and flow Φ on network G.


✓ (1) The arc u  U is called a saturated arc (full arc ) if Φ ( u) = c (u).
✓ (2) Flow Φ is called a full flow if every path from transmitter 0 to receiver z contains at least a
saturation arc (cung bão hòa).
✓ (3) A single path α (x0 , z) from the transmitting vertex x0 to the receiving vertex z is said to be flow
increasing path if above α there is no saturation supply.
• Definition 5 : The flow increasing path is any path from s to t in the flow
increasing graph𝑓

• Theorem 2: The following statements are equivalent:


– 𝑓 is the maximum flow in the network
– Couldn't find a way to increase the flow
– 𝑣𝑎𝑙(𝑓) = 𝑐(𝑋,𝑋*) with some slice (𝑋,𝑋*).

15
The Ford-Fulkerson algorithm
1. Starting from a flow (any)- can be a flow 0
2. Build flow increasing graph Gf
3. From Gf, find a flow increasing path P
a) If there is no flow increasing path, ending .
b) If there is a flow increase path, then build new flow f’
4. Repeat the above process until no new flow increasing path can
be found.

• The narrowest slice is (VT, V\VT) where VT is the vertices


visited in finding the last unsuccessful flow increase path and
then f is the maximum flow.

16
The Ford-Fulkerson algorithm
• Example: Find the maximum flow in the following network G (s=1, t=4):
4,
2 (0) 3
6 3
,(0) 2 ,(0) ,(0)
fir 1 1 ,(0) 4
st ,(0)
5 6
,(0) 6 5 ,(0)
4 ,(0)

17
The Ford-Fulkerson algorithm
• Example: Find the maximum flow in the following network (s=1,t=4): (ct.)

18
The Ford-Fulkerson algorithm
• Example: Find the maximum flow in the following network (s=1,t=4): (ct.)

19
The Ford-Fulkerson algorithm
• Example: Find the maximum flow in the following network (s=1,t=4): (ct.)

20
The Ford-Fulkerson algorithm
• Example: Find the maximum flow in the following network (s=1,t=4): (ct.)

21
The Ford-Fulkerson algorithm
• Example: Find the maximum flow in the following network (s=1,t=4): (ct.)

So Val(f)=9 is the maximum flow.


22
Ford-Fulkerson Algorithm - Implementation
• The algorithm does not need to build an explicit graph Gf and still finds an
increasing flow path, by using the BFS algorithm (or DFS ) and assigning
labels [ p(v), d(v)] to the vertices v respectively, with:
– p(v) is the vertex immediately preceding v on the flow increment from s to v.
• +p(v): need to increase the flow by arc (p(v), v)
• -p(v): need to reduce the flow by arc (v, p(v))
– d(v): maximum value that can increase flow on arc (p(v), v) or decrease flow
on arc (v, p(v)) .

23
Ford-Fulkerson Algorithm - Implementation
Flow-increasing Pathfinding Algorithm Stream increase algorithm
int Find_Path() { void Inc_Flow() {
assign all vertices unvisited; v=p[t]; u=t; tang=d[t];
while (u!=s){
queue= ; queue  s ; p[s]=s ; d[s]=+vc ; parameter[s]=true;
if (v>0) f[v,u] = f[v,u] + tang;
while (queue!=  ){ else{
u  queue; v = -v; f[u,v] = f[u,v] - tang;
for (v sour greed) { }
if ( (c[u,v]>0)&&( f[u,v] <c[u,v]) ){ // G f has an equal arc (u,v) u = v; v = p[u];
}
p[v]=u; d[v]=min {d[u], c[u,v] – f[u,v]};
}
if (v == t) return 1;
queue  ; parameter[v]=true;
Maximum flow finding algorithm
} void Max_Flow()
if ( (c[v,u]>0)&&(f[v,u]>0){ //coordinate (u,v) {//are you in a position?
p[v]=-u; d[v]=min {d[u], f[v,u]} ; for (u V )
If (v == t) return 1; for (v  V) f(u,v)=0;
stop=0;
queue  v; parameter[v]=true;
while (!stop)
} if (Find_Path()) Inc_Flow();
} else stop=1;
} }
return 0;
}
24
Exercise 1

1. Given network G and flow Φ, check the properties of flow Φ:


a) Conditions on each arc
b) Equilibrium condition on each vertex
c) Flow value Φ (Val(Φ)=?).
2. Build a flow increasing graph for the above G network.
25
Exercise 2
• Given a full flow f on network G as follows:

• Let's apply the Ford-Fulkerson Algorithm to find the maximal flow f * from the
flow f on this network. Then determine a narrowest slice of the network G.

26

You might also like