6-Graph theory-Flow problems
6-Graph theory-Flow problems
Flow problems
Z.GUELLIL
Flows: definitions and properties 1
• Flow networks are a fundamental concept in graph theory used to model
the movement of resources through interconnected nodes.
• A flow network is a directed graph where a certain homogeneous quantity
can stream between connected vertices through edges.This quantity is
called flow.
• Each edge is characterized by a capacity, a non-negative real number.
• There are also two special vertices:
• s∈V is the source vertex from which the flow originates.
• t∈V is the sink vertex where the flow is collected.
• No arc reaches the source.
• No arc leaves the sink.
Flows: definitions and properties 2
• A flow non-negative real-valued function f defined on the arcs satisfying:
• Capacity constraint : f ( a ) ≤ c ( a );
• Conservation of flow : for any vertex other than s and t , the sum of the
flows on the incoming edges and the sum of the flows on the outgoing
edges are equal.
• f ( x,y )=-f( y,x )
• Examples: electrical or hydraulic circuits, communication networks, transport
modeling
Flows: definitions and properties 3
• the sum of the flows on the arcs leaving the source and the sum of
the flows on the arcs arriving at the sink are equal;
• This value is the value of the flow | f | ;
• if we separate the vertices into two subsets E containing s and F = A −
E, containing t, then the sum of the values of the flow on the arcs
from E to F minus the sum of the values of the flow on the arcs from
F to E is also | f |.
• Such a separation into two subsets of the vertices is called a cut and
this difference in flow sums is called the net flow crossing the cut.
Ford and Fulkerson Algorithm
Max_Flow (G)
{
MF=0; //the value of the max flow
While (there exists an augmenting path in G) Do
{
Find a path increasing P
C f (P) = smallest capacity on P
MF=MF+ C f (P)
For each arc ( u,v ) in P {
c f ( u,v )= c f ( u,v ) - C f (P)
c f ( seen )= c f ( seen ) + C f (P)
}
}
}
Definition: increasing path
• A path C between “s” and “t” is said to be increasing with respect
to a flow f = (f (i , j), (i , j) ∈ E ) feasible between s and t if:
• f (i , j) < c(i , j) if (i , j) ∈ C + ((i , j) ∈ E ) conformal arc)
• f (i , j) > 0 if (i , j) ∈ C - ((j , i) ∈ E ) non-conforming arc)
i I
• Indirect marking: f(i,j) < c(i,j)
• If for an arc (j, i) we have: i marked, j unmarked and f (j, i) >0 Then
we mark j by (i,-) and we set 𝛿 𝑗 = min 𝛿 𝑖 , 𝑓 𝑗, 𝑖
*
i I
f (i, j) > 0
• 𝛿 𝑗 is the maximum flow you can increase from s to j.
• 𝛿 𝑖 is a value associated with vertex i , initialized to infinity for s.
1
0/8
a c
0/10
0/9
0/10
0/1 t
s
0/9 0/7
b d
0/3
1
0/8
a c
0/10
0/9
𝛿 𝑆 =∞
𝑆, +
0/10
0/1 t
s
0/9 0/7
b d
0/3
1
𝛿 𝑎 = 𝑚𝑖𝑛( ∞,9-0)=9
𝑆, +
0/8
a c
0/10
0/9
𝛿 𝑆 =∞
𝑆, +
0/10
0/1 t
s
0/9 0/7
b d
0/3
1
𝛿 𝑎 = 𝑚𝑖𝑛( ∞,9-0)=9
𝑆, +
0/8
a c
0/10
0/9
𝛿 𝑆 =∞
𝑆, +
0/10
0/1 t
s
0/9 0/7
b d
0/3
𝛿 𝑏 =9
𝑆, +
1
𝛿 𝑆 =∞
𝑆, +
0/10
0/1 t
s
0/9 0/7
b d
0/3
𝛿 𝑏 =9
𝑆, +
1
𝛿 𝑆 =∞
𝑆, +
0/10
0/1 t
s
0/9 0/7
b d
0/3
𝛿 𝑏 =9 𝛿 𝑑 =3
𝑆, + 𝑏, +
1
𝛿 𝑆 =∞
𝑆, +
0/10
0/1 t
s
𝛿 𝑡 =3
𝑑, +
0/9 0/7
b d
0/3
𝛿 𝑏 =9 𝛿 𝑑 =3
𝑆, + 𝑏, +
1
𝛿 𝑆 =∞
𝑆, +
0/10
0/1 t
s
𝛿 𝑡 =3
𝑑, +
3/9 3/7
b d
3/3
𝛿 𝑏 =9 𝛿 𝑑 =3
𝑆, + 𝑏, +
2
0/8
a c
0/10
0/9
0/10
0/1 t
s
3/9 3/7
b d
3/3
2
0/8
a c
0/10
0/9
𝛿 𝑆 =∞
𝑆, +
0/10
0/1 t
s
3/9 3/7
b d
3/3
2
0/8
a c
0/10
0/9
𝛿 𝑆 =∞
𝑆, +
0/10
0/1 t
s
3/9 3/7
b d
3/3
𝛿 𝑎 = 𝑚𝑖𝑛( ∞,9-3)=6
𝑆, +
2
𝛿 𝑐 = 𝑚𝑖𝑛(6,1−0)=1
𝑏, +
0/8
a c
0/10
0/9
𝛿 𝑆 =∞
𝑆, +
0/10
0/1 t
s
3/9 3/7
b d
3/3
𝛿 𝑎 = 𝑚𝑖𝑛( ∞,9-3)=6
𝑆, +
2
𝛿 𝑐 = 𝑚𝑖𝑛(6,1−0)=1
𝑏, +
0/8
a c
0/10
0/9
𝛿 𝑆 =∞
𝑆, +
0/10
0/1 t
s
𝛿 𝑡 =1
𝑐, +
3/9 3/7
b d
3/3
𝛿 𝑎 = 𝑚𝑖𝑛( ∞,9-3)=6
𝑆, +
2
𝛿 𝑐 = 𝑚𝑖𝑛(6,1−0)=1
𝑏, +
0/8
a c
1/10
0/9
𝛿 𝑆 =∞
𝑆, +
0/10
1/1 t
s
𝛿 𝑡 =1
𝑐, +
4/9 3/7
b d
3/3
𝛿 𝑎 = 𝑚𝑖𝑛( ∞,9-3)=6
𝑆, +
3
0/8
a c
1/10
0/9
0/10
1/1 t
s
4/9 3/7
b d
3/3
3
0/8
a c
1/10
0/9
𝛿 𝑆 =∞
𝑆, +
0/10
1/1 t
s
4/9 3/7
b d
3/3
3
0/8
a c
1/10
0/9
𝛿 𝑆 =∞
𝑆, +
0/10
1/1 t
s
4/9 3/7
b d
3/3
𝛿 𝑏 = 𝑚𝑖𝑛( ∞,9-4)=5
𝑆, +
3
0/8
a c
1/10
0/9
𝛿 𝑆 =∞
𝑆, +
0/10
1/1 t
s
4/9 3/7
b d
3/3
𝛿 𝑏 = 𝑚𝑖𝑛( ∞,9-4)=5
𝑆, +
3
0/8
a c
1/10
0/9
𝛿 𝑆 =∞
𝑆, +
0/10
1/1 t
s
4/9 3/7
b d
3/3
𝛿 𝑏 = 𝑚𝑖𝑛( ∞,9-4)=5
𝑆, +
3
𝛿 𝑎 =9
𝑠, +
0/8
a c
1/10
0/9
𝛿 𝑆 =∞
𝑆, +
0/10
1/1 t
s
4/9 3/7
b d
3/3
𝛿 𝑏 = 𝑚𝑖𝑛( ∞,9-4)=5
𝑆, +
3
𝛿 𝑎 =9
𝑠, + 𝛿 𝑐 = 𝑚𝑖𝑛(9,8−0)=8
𝑎, +
0/8
a c
1/10
0/9
𝛿 𝑆 =∞
𝑆, +
0/10
1/1 t
s
4/9 3/7
b d
3/3
𝛿 𝑏 = 𝑚𝑖𝑛( ∞,9-4)=5
𝑆, +
3
𝛿 𝑎 =9
𝑠, + 𝛿 𝑐 = 𝑚𝑖𝑛(9,8−0)=8
𝑎, +
0/8
a c
1/10
0/9
𝛿 𝑆 =∞
𝑆, +
0/10
1/1 t
s
𝛿 𝑡 = 𝑚𝑖𝑛(8,10−1)=8
𝑐, +
4/9 3/7
b d
3/3
𝛿 𝑏 = 𝑚𝑖𝑛( ∞,9-4)=5
𝑆, +
3
𝛿 𝑎 =9
𝑠, + 𝛿 𝑐 = 𝑚𝑖𝑛(9,8−0)=8
𝑎, +
8/8
a c
9/10
8/9
𝛿 𝑆 =∞
𝑆, +
0/10
1/1 t
s
𝛿 𝑡 = 𝑚𝑖𝑛(8,10−1)=8
𝑐, +
4/9 3/7
b d
3/3
𝛿 𝑏 = 𝑚𝑖𝑛( ∞,9-4)=5
𝑆, +
C(f) = 9 + 3 = 12
Definitions
• Cut : A cut is a partition of the set of vertex V into two subsets S and S’=V-S.
The cut is denoted [S,S’].
• A cut like the set of arcs whose ends are in the different partitions S and S'.
• A cut is called a st cut if s ∈ S and t ∈ S’.
• An arc ( i,j ) such that i ∈ S and j ∈ S' is a forward arc, and
• An arc ( i,j ) such that i ∈ S' and j ∈ S is a backward arc of the cut [S,S'].
• The capacity of a cut st cut (S,S') is the sum of the capacities of the front arcs
of this cut.
𝐶(𝛿 𝑆 ) = 𝐶(𝑖, 𝑗)
(𝑖,𝑗)∈𝛿 𝑆
Minimal Cut
• A st cut whose capacity is minimum among all st cuts is a minimum cut .
• Any flow from s to t must pass from S to S' at some point, and thus uses the
capacity of the edges from S to S’.
• This means that each cut of the graph puts a bound (limit) on the value of the
maximum possible flow.
8 /8
𝑆 ={s, a, b} , S'={c, d, t} a c
9/10
𝛿(𝑆) ={(a, c), (b, c), (b, d)} 8/9
0/10 1 /1
t
𝐶 𝛿 𝑆 = 𝐶 𝑖, 𝑗 = 8+1+3 = 12 s
𝑖,𝑗 ∈𝛿 𝑆
4/9 3/7
b d
3 /3
Exercises 1 :
Find the maximum flow by completing the Ford-Fulkerson algorithm .
5/8
a c
8 /8
5/9
0/10 3/3
t
s
8/8 5/9
b d
5/10
5/8
a c
8 /8
5/9
𝛿 𝑆 =∞
𝑆, +
0/10 3/3
t
s
8/8 5/9
b d
5/10
𝛿 𝑎 =4
𝑆, +
5/8
a c
8 /8
5/9
𝛿 𝑆 =∞
𝑆, +
0/10 3/3
t
s
8/8 5/9
b d
5/10
𝛿 𝑎 =4
𝑆, +
5/8
a c
8 /8
5/9
𝛿 𝑆 =∞
𝑆, +
0/10 3/3
t
s
8/8 5/9
b d
5/10
𝛿 𝑎 =4 𝛿 𝑐 =3
𝑆, + 𝑎, +
5/8
a c
8 /8
5/9
𝛿 𝑆 =∞
𝑆, +
0/10 3/3
t
s
8/8 5/9
b d
5/10
𝛿 𝑎 =4 𝛿 𝑐 =3
𝑆, + 𝑎, +
5/8
a c
8 /8
5/9
𝛿 𝑆 =∞
𝑆, +
0/10 3/3
t
s
8/8 5/9
b d
5/10
𝛿 𝑎 =4 𝛿 𝑐 =3
𝑆, + 𝑎, +
5/8
a c
8 /8
5/9
𝛿 𝑆 =∞
𝑆, +
0/10 3/3
t
s
8/8 5/9
b d
5/10
𝛿 𝑏 =3
𝑐, −
𝛿 𝑎 =4 𝛿 𝑐 =3
𝑆, + 𝑎, +
5/8
a c
8 /8
5/9
𝛿 𝑆 =∞
𝑆, +
0/10 3/3
t
s
8/8 5/9
b d
5/10
𝛿 𝑏 =3 𝛿 𝑑 =3
𝑐, − 𝑏, +
𝛿 𝑎 =4 𝛿 𝑐 =3
𝑆, + 𝑎, +
5/8
a c
8 /8
5/9
𝛿 𝑆 =∞
𝑆, +
0/10 3/3
t
s
𝛿 𝑡 =3
𝑑, +
8/8 5/9
b d
5/10
𝛿 𝑏 =3 𝛿 𝑑 =3
𝑐, − 𝑏, +
𝛿 𝑎 =4 𝛿 𝑐 =3
𝑆, + 𝑎, +
5/8
a c
8 /8
5/9
𝛿 𝑆 =∞
𝑆, +
0/10 3/3
t
s
𝛿 𝑡 =3
𝑑, +
8/8 5/9
b d
5/10
𝛿 𝑏 =3 𝛿 𝑑 =3
𝑐, − 𝑏, +
𝛿 𝑎 =4 𝛿 𝑐 =3
𝑆, + 𝑎, +
5/8
a c
8 /8
5/9
𝛿 𝑆 =∞
𝑆, +
0/10 3/3
t
s
𝛿 𝑡 =3
𝑑, +
8/8 8/9
b d
5/10
𝛿 𝑏 =3 𝛿 𝑑 =3
𝑐, − 𝑏, +
𝛿 𝑎 =4 𝛿 𝑐 =3
𝑆, + 𝑎, +
5/8
a c
8 /8
5/9
𝛿 𝑆 =∞
𝑆, +
0/10 3/3
t
s
𝛿 𝑡 =3
𝑑, +
8/8 8/9
b d
5/10
𝛿 𝑏 =3 𝛿 𝑑 =3
𝑐, − 𝑏, +
𝛿 𝑎 =4 𝛿 𝑐 =3
𝑆, + 𝑎, +
5/8
a c
8 /8
5/9
𝛿 𝑆 =∞
𝑆, +
0/10 3/3
t
s
𝛿 𝑡 =3
𝑑, +
8/8 8/9
b d
8/10
𝛿 𝑏 =3 𝛿 𝑑 =3
𝑐, − 𝑏, +
𝛿 𝑎 =4 𝛿 𝑐 =3
𝑆, + 𝑎, +
5/8
a c
8 /8
5/9
𝛿 𝑆 =∞
𝑆, +
0/10 3/3
t
s
𝛿 𝑡 =3
𝑑, +
8/8 8/9
b d
8/10
𝛿 𝑏 =3 𝛿 𝑑 =3
𝑐, − 𝑏, +
𝛿 𝑎 =4 𝛿 𝑐 =3
𝑆, + 𝑎, +
5/8
a c
8 /8
5/9
𝛿 𝑆 =∞
𝑆, +
0/10 3/3
t
s
𝛿 𝑡 =3
𝑑, +
8/8 8/9
b d
8/10
𝛿 𝑏 =3 𝛿 𝑑 =3
𝑐, − 𝑏, +
𝛿 𝑎 =4 𝛿 𝑐 =3
𝑆, + 𝑎, +
5/8
a c
8 /8
5/9
𝛿 𝑆 =∞
𝑆, +
0/10 0/3
t
s
𝛿 𝑡 =3
𝑑, +
8/8 8/9
b d
8/10
𝛿 𝑏 =3 𝛿 𝑑 =3
𝑐, − 𝑏, +
𝛿 𝑎 =4 𝛿 𝑐 =3
𝑆, + 𝑎, +
5/8
a c
8 /8
5/9
𝛿 𝑆 =∞
𝑆, +
0/10 0/3
t
s
𝛿 𝑡 =3
𝑑, +
8/8 8/9
b d
8/10
𝛿 𝑏 =3 𝛿 𝑑 =3
𝑐, − 𝑏, +
𝛿 𝑎 =4 𝛿 𝑐 =3
𝑆, + 𝑎, +
8/8
a c
8 /8
5/9
𝛿 𝑆 =∞
𝑆, +
0/10 0/3
t
s
𝛿 𝑡 =3
𝑑, +
8/8 8/9
b d
8/10
𝛿 𝑏 =3 𝛿 𝑑 =3
𝑐, − 𝑏, +
𝛿 𝑎 =4 𝛿 𝑐 =3
𝑆, + 𝑎, +
8/8
a c
8 /8
5/9
𝛿 𝑆 =∞
𝑆, +
0/10 0/3
t
s
𝛿 𝑡 =3
𝑑, +
8/8 8/9
b d
8/10
𝛿 𝑏 =3 𝛿 𝑑 =3
𝑐, − 𝑏, +
𝛿 𝑎 =4 𝛿 𝑐 =3
𝑆, + 𝑎, +
8/8
a c
8 /8
8/9
𝛿 𝑆 =∞
𝑆, +
0/10 0/3
t
s
𝛿 𝑡 =3
𝑑, +
8/8 8/9
b d
8/10
𝛿 𝑏 =3 𝛿 𝑑 =3
𝑐, − 𝑏, +
𝛿 𝑎 =4 𝛿 𝑐 =3
𝑆, + 𝑎, +
8/8
a c
8 /8
8/9
𝛿 𝑆 =∞
𝑆, +
0/10 0/3
t
s
𝛿 𝑡 =3
𝑑, +
8/8 8/9
b d
8/10
𝛿 𝑏 =3 𝛿 𝑑 =3
𝑐, − 𝑏, +
8/8
a c
8 /8
8/9
𝛿 𝑆 =∞
𝑆, +
0/10 0/3
t
s
8/8 8/9
b d
8/10
𝛿 𝑎 =1
𝑆, +
8/8
a c
8 /8
8/9
𝛿 𝑆 =∞
𝑆, +
0/10 0/3
t
s
8/8 8/9
b d
8/10
8/8
a c
8 /8
8/9
0/10 0/3
t
s
8/8 8/9
b d
8/10
C(f) = 8 + 8 = 1 6
8/8
a c
8 /8
8/9
0/10 0/3
t
s
8/8 8/9
b d
8/10
C(f) = 8 + 8 = 1 6
𝑆 ={s, a} , S'={ b, c, d, t}
𝛿(𝑆) ={(a, c), ( S, b)}
𝐶 𝛿 𝑆 =σ 𝑖,𝑗 ∈𝛿 𝑆 𝐶 𝑖, 𝑗 = 8+8 = 16