Chapter 4-Problems of flows (1)
Chapter 4-Problems of flows (1)
– Course 4 –
Chapter 4 : Problems of Flows (1/1)
Summary
Goals of course
• Define the concepts of cycle /Co cycle, elementary (Cycle/ Co cycle)
, Cocircuit, cyclomatic number.
• Define the concept of flow In a graph.
• Apply an algorithm of research of a maximum flow.
2
Section 1 :Definitions
3
Cycle
G1=({V1,V2,V3,V4,V5,V6},{e1,e2,e3,e4,e5,e6,e7, e8, e9})
Cycle
A cycle of length h is a e1 V2 e2
succession of h edges, all V1 V3
differents, each intermediate e5
edge having an end in e3 e6 e7
e4
common with the following
edge. V4 V6
The initial and the final e8 V5 e9
edges also having their free
end in common. C1=(e1, e5, e4 ) is a cycle
4
Cycle
G1=({V1,V2,V3,V4,V5,V6},{e1,e2,e3,e4,e5,e6,e7, e8, e9})
e1 V2 e2 e1 V2 e2
V1 V3 V1 V3
e5 e5
e3 e6 e7 e3 e6 e7
e4 e4
V4 V6 V4 V6
e8 V5 e9 e8 V5 e9
5
Cycle
G1=({V1,V2,V3,V4,V5,V6},{e1,e2,e3,e4,e5,e6,e7, e8, e9})
e1 V2 e2 e1 V2 e2
V1 V3 V1 V3
e5 e5
e3 e6 e7 e3 e6 e7
e4 e4
V4 V6 V4 V6
V5 e9 e8 V5
e8 e9
6
Cycle
G1=({V1,V2,V3,V4,V5,V6},{e1,e2,e3,e4,e5,e6,e7, e8, e9})
e1 V2 e2 e1 V2 e2
V1 V3 V1 V3
e5 e5
e3 e6 e7 e3 e6 e7
e4 e4
V4 V6 V4 V6
e9 V5
V5 e8 e9
e8
C5=(e1, e2, e7, e9, e8, e3 ) C6=(e3, e4, e9, e7, e6,e8)
is a cycle of length 6 is a cycle of length 6
7
Cycle
G1=({V1,V2,V3,V4,V5,V6},{e1,e2,e3,e4,e5,e6,e7, e8, e9})
e1 V2 e2 e1 V2 e2
V1 V3 V1 V3
e5 e5
e3 e6 e7 e3 e6 e7
e4 e4
V4 V6 V4 V6
V5 V5
e8 e9 e8 e9
C7=(e3, e1, e5, e9, e7, e6, e8 ) C8=(e3, e4, e9, e7, e2, e5, e8)
is a cycle of length 7 is a cycle of length 7
8
Cycle
G1=({V1,V2,V3,V4,V5,V6},{e1,e2,e3,e4,e5,e6,e7, e8, e9})
e1 e2 e1 e2
V2 V2
V1 V3 V1 V3
e5 e5
e3 e6 e7 e3 e6 e7
e4 e4
V59
V4 V6 V4 V6
,
e9 V5
e8 e8, e8 e9
e3
C7=(e1, e5, e6, e2, e5, e4 ) C8=(e3, e1, e5, e9, e7, e2, e5,e8)
is not not a cycle is not not a cycle
9
Elementary cycle
G1=({V1,V2,V3,V4,V5,V6},{e1,e2,e3,e4,e5,e6,e7, e8, e9})
Elementary
cycle
e1 V2 e2
V1 V3
e5
A cycle is said to be "elementary" e3 e6 e7
e4
if, while going through it, we do
not encounter the same vertex
several times. V4 V6
e8 V5 e9
10
Elementary cycle
G1=({V1,V2,V3,V4,V5,V6},{e1,e2,e3,e4,e5,e6,e7, e8, e9})
e1 V2 e2 e1 V2 e2
V1 V3 V1 V3
e5 e5
e3 e6 e7 e3 e6 e7
e4 e4
V4 V6 V4 V6
e8 V5 e9 e8 V5 e9
11
Elementary cycle
G1=({V1,V2,V3,V4,V5,V6},{e1,e2,e3,e4,e5,e6,e7, e8, e9})
e1 V2 e2 e1 V2 e2
V1 V3 V1 V3
e5 e5
e3 e6 e7 e3 e6 e7
e4 e4
V4 V6 V4 V6
V5 e9 e8 V5
e8 e9
12
Elementary cycle
G1=({V1,V2,V3,V4,V5,V6},{e1,e2,e3,e4,e5,e6,e7, e8, e9})
e1 V2 e2 e1 V2 e2
V1 V3 V1 V3
e5 e5
e3 e6 e7 e3 e6 e7
e4 e4
V4 V6 V4 V6
V5 V5
e8 e9 e8 e9
C7=(e3, e1, e5, e9, e7, e6, e8 ) C8=(e3, e4, e9, e7, e2, e5, e8)
is not an elementary cycle is not an elementary cycle
13
Representative vector of a cycle (Vector notation)
Vector notation
1 V2 2
V1 V3
The edges are numbered from 1 to
m 5
A cycle is represented by an m-tuple 3 6 7
4
vector composed of -1, 1 and 0 in
the following way :
We consider all the edges in their V4 V6
order 8 V5 9
If the edge does not belong to the
cycle, we put a "0"
If the edge belongs to the cycle
and is traveled in the right direction The vector notation of the cycle C1=(1, 5, 4
(we then call it "direct"), we put a )
+1 is (+1,0,0,-1,+1,0,0,0,0)
If the edge belongs to the cycle but
traveled in the wrong direction (we
then call it "reverse"), we put a -1
14
Cyclomatic Number
G1=({V1,V2,V3,V4,V5,V6},{e1,e2,e3,e4,e5,e6,e7, e8, e9})
e1 V2 e2
V1 V3
15
CoCycle
G1=({V1,V2,V3,V4,V5,V6},{e1,e2,e3,e4,e5,e6,e7, e8, e9})
CoCycle
1 V2 2
V1 V3
16
Elementary CoCycle
Elementary CoCycle
e1 V2 e2
A CoCycle associated with a set V1 V3
of vertices A is elementary if the
deletion of (A) generates a e5
e3 e6 e7
connected component e4
A CoCycle is said to be V4 V6
e8 V5 e9
elementary if it is minimal.
17
Elementary CoCycle
e1 V2 e2
A cocycle is elementary V1 V3
when it is composed of edges
e5
connecting two subsets of e3 e6 e7
e4
connected vertices that
partition a connected V4 V6
component of the graph e8 V5 e9
18
Elementary CoCycle (example 1)
1 V2 2
The cocycle associated to (V2,V5) V1 V3
is not elementary because it is
composed of edges connecting 5
3 6 7
{V2,V5} to 4
{V1, V4, V3, V6} and if {V2,V5} is
deleted, this is not the case for V4 V6
{V1, V4, V3, V6}. 8
V5
9
V2 1 V2 2
V1 V3 V1 V3
5 5
3 7 3 6 7
4
V4 V6 V4 V6
V5 V5
8 9
19
Elementary CoCycle (example 2)
1 V2 2
V1 V3
The cocycle associated to {V1,
V2, V4} of which its notation 5
3 6 7
vector is (0,1,0,1,1,0,0,-1,0) is 4
elementary.
V4 V6
V5
8 9
1 1 V2 2
V2 V1
V1 V3 V3
5
3 6 7 3 6 7
4
V4 V6 V4 V6
V5
V5 8 9
20
CoCircuit
CoCircuit CoCircuit
e1 V2 e2
V1 V3
e5
In a cocycle associated with e3
e4
e6 e7
a set of vertices A
, if one of the sets V4 V6
or is empty, V5
e8 e9
the cocycle is called cocircuit
Let A be the set of vertices A=(V1, V2,
V3,V4,V5,V6)
The CoCycle assotiaed to A is (A) =(+,
-) =()
Its vector notation is (0,0,0,0,0,0)
21
22
Flows and tensions
Basic Concepts
Flow Networks (Networks of transportation)
Capacity
a 4 b
4
3
2
6
S p
8 9
Source c 3 d
Well
No incoming edges No outgoing edges
23
Flows and tensions
Basic Concepts
Flow Networks (Networks of transportation)
2 Flow
=2
a 4 b
2 2
4
2
2
6
S p
8 9 3
3 c 3 d
3 Flow = 3
Basic Concepts
Flow Networks (Networks of transportation) Flow
2
=2
a 4 b
2 4 2
The edge (s a) is 2
2
0 6
saturated
S p
The edge (c d) is 0
8 9 3
saturated
3 c 3 d
3 Flow = 3
• Saturated direct edge: if the flow circulating there = the capacity of the edge
• Saturated reverse edge : if the flow circulating there = 0
• Saturated Path/Chain : if it contains at least one saturated edge
25
Flows And tensions
Basic Concepts
Flow Networks (Networks of transportation)
Kirchhoff’s law
2 Flow =2
a 4 b
2 4 2
2
Law of 2
6
conservation of the S
flow (fluxes) : p
The sum of the flows
arriving at a
8 c d 3
vertex is equal to 3
3 3
the sum of the
Flow = 3
flows leaving it
26
Section 3:
Problematic of Maximum Flow
Ford-Fulkerson Algorithm
27
Problematic of Maximum Flow
28
Problematic of Maximum Flow
29
Ford-Fulkerson Algorithm
30
Ford-Fulkerson Algorithm
• In pseudo-computer code, the algorithm can be presented as follows:
• Initialization (Start from an initial flow compatible with the capacities);
• End := False
• While (End = False)
• Perform the marking procedure from the current flow
• If (P is unmarked) Then
set end:= True {the flow is maximal}
• Else
Modify the flow from an improving chain
• Endwhile
• End
From an initial flow compatible with the capacities, the algo improves the flow as
long as the marking procedure applied to the current flow allows to mark P.
31
Ford-Fulkerson Algorithm
0
a 4 b 0
0
4
3
2
6
0 0
S p
8 9
0 c d 0
3
0
32
Ford-Fulkerson Algorithm
Flow + (Maximum Flow) =0
The research of an improving chain
Mark S, mark the adjacent vertex if (it is not marked and the flux is strictly less
than the capacity), choose the largest flux
0
a 4 b 0
0 4
3
2
+ 6
0 0
S p
8 9
0 c d 0
3
0
S is marked +
a is not marked and 0˂3
c is not marked and 0˂8
We choose to mark C
because 8-0 ˃3-0
33
Ford-Fulkerson Algorithm
Flow + (Maximum Flow) =0
The research of an improving chain
Mark S, mark the adjacent vertex if (it is not marked and the flux is strictly
less than the capacity), choose the largest flux
0 +
has 4 b 0
0 4
3
2
+ 6
0 0
S p
8 9
0 c d 0
3
C is marked 0
b is not not marked and +
0˂6
d is not marked and 0˂3
We choose to mark b
because 6-0 ˃3-0
34
Ford-Fulkerson Algorithm
Flow + (Maximum Flow) =0
The research of an improving chain
Mark S, mark the adjacent vertex if (it is not marked and the flux is strictly
less than the capacity), choose the largest flux
0 +
has 4 b 0
0 4
3
2
+ 6
S
0 0 p +
0 8 9
c d 0
3
0
b is marked +
P is not marked and 0˂4
We choose to mark P
because 0˂4
35
Ford-Fulkerson Algorithm
Flow + (Maximum Flow) =0
The research of an improving chain
Mark S, mark the adjacent vertex if (it is not marked and the flux is strictly
less than the capacity), choose the largest flux
0 +
ha 4 b 0
0 4
3
2
+ 6 +
0 0
S p
0 8 9
c d 0
3
0
+
S c b P is an improving chain
The flow can be increase
by (min(8-0,6-0, 4-0) = +4
36
Ford-Fulkerson Algorithm
Flow + (Maximum Flow) =0+4
The research of an improving chain
Mark S, mark the adjacent vertex if (it is not marked and the flux is strictly
less than the capacity), choose the largest flux
0 +
a 4 b 0+4
0 4
3
2
+ 6
0 0+4
S p
8 9
0+4 c d 0
3
0
+
S c b p is an improving chain
The flow can be increased by
(min(8-0,6-0, 4-0) = +4
37
Ford-Fulkerson Algorithm
Flow + (Maximum Flow)=0+4
Erasing the marking
The research of an other improving chain
Mark S, mark the adjacent vertex if (it is not marked and the flux is strictly less than
the capacity), choose the largest flux
0
a 4 b 0+4
0 4
3
2
6
0
S 0+4 p
8 9
0+4 c d 0
3
0
38
Ford-Fulkerson Algorithm
Flow + (Maximum Flow)=0+4
Mark the source S
The research of an improving chain
Mark S, mark the adjacent vertex if (it is not marked and the flux is strictly less
than the capacity), choose the largest flux
0
a 4 b 0+4
0 4
3
2
+ 6
0
S 0+4 p
8 9
0+4 c d 0
3
a is not marked and 0˂3 + 0
c is not marked and 0+4˂8
We choose to mark c because 8-4˃3-0
39
Ford-Fulkerson Algorithm
Flow+ (Maximum Flow) =0 +4
C is marked
The research of an improving chain
Mark S, mark the adjacent vertex if (it is not marked and the flux is strictly less
than the capacity), choose the largest flux
0
a 4 b 0+4
0 4
3
2
+ 6
0
S 0+4 p
8 9
0+4 c d 0
3
b is not marked and 0+4˂6 + 0 +
d is not not marked and 0˂3
We choose to mark d because 3-0 ˃6-4
40
Ford-Fulkerson Algorithm
Flow+ (Maximum Flow) =0 +4
d is marked
The research of an improving chain
Mark S, mark the adjacent vertex if (it is not marked and the flux is strictly less
than the capacity), choose the largest flux
0
a 4 b 0+4
0 4
3
2
+ 6
0 0+4
S p
8 9
+
0+4 c d 0
3
P is not marked and 0˂9 + 0 +
We mark p
41
Ford-Fulkerson Algorithm
Flow+ (Maximum Flow) =0 +4
P is marked and the improving chain is S c d P
We can increase the flow of min(8-4, 3-0, 9-0) =+3
Flow+ =0+4+3
0
a 4 b 0+4
0 4
3
2
+ 6
0
S 0+4 p
8 9
+
0+4+3 0+3
c 3 d
0+3
+ +
42
Ford-Fulkerson Algorithm
Flow+ =0+4+3
Delete the marking and research for an other improving chain
0
a 4 b 0+4
0 4
3
2
6
0 0+4
S p
8 9
0+4+3 c d
3 0+3
0+3
43
Ford-Fulkerson Algorithm
Flow+ =0+4+3
Mark S
We can mark either c or a but we choose because max (3-0, 8-7)=3
+ 0
a 4 b 0+4
0 4
3
2
+ 6
0 0+4
S p
8 9
0+4+3 c 0+3
3 d
0+3
44
Ford-Fulkerson Algorithm
Flow+ =0+4+3
S is marked
a is marked
We choose to mark b because 2-0 ˂ 4-0
+ 0
a 4 b 0+4
0 4
3
2
+ 6
0
S 0+4 p
8 9
0+4+3 c 3 d 0+3
0+3
45
Ford-Fulkerson Algorithm
Flow+ =0+4+3
S is marked
a is marked
b is marked
+ 0 +
a 4 b 0+4
0 4
3
2
+ 6
0
S 0+4 p
8 9
0+4+3 c d
3 0+3
0+3
46
Ford-Fulkerson Algorithm
Flow+ =0+4+3
S is marked
a is marked
b is marked
We cannot mark P because the edge (b p) is saturated
+ 0 +
a 4 b 0+4
0 4
3
2
+ 6
0 0+4
S p
8 9
0+4+3 c 0+3
3 d
0+3
47
Ford-Fulkerson Algorithm
Flow+ =0+4+3
S is marked
a is marked
b is marked
We mark c by – because it is an inverse edge and the flux can decrease (c is the
origin of an edge whose end is marked and the flux which is greater than 0 can
decrease)
+ 0 +
h 4 b 0+4
0 a 4
3
s 2
+ 6
0 0+4
S p
8 9
0+4+3 c 0+3
3 d
0+3
-
48
Ford-Fulkerson Algorithm
Flow+ =0+4+3
S is marked
a is marked
b is marked
c is marked by –
We cannot mark d because the arc (c d) is saturated (flux=capacity)
+ 0 +
a 4 b 0+4
0 4
3
2
+ 6
0
S 0+4 p
8 9
0+4+3 c 0+3
3 d
0+3
-
49
Ford-Fulkerson Algorithm
Flow+ =0+4+3
S is marked
a is marked
b is marked
c is marked by –
We go back
+ 0 +
a 4 b 0+4
0 4
3
2
+ 6
0
S 0+4 p
8 9
0+4+3 c d 0+3
3
0+3
-
50
Ford-Fulkerson Algorithm
Flow+ =0+4+3
S is marked
a is marked
We mark d from a because 0 ˂ 2
+ 0
a 4 b 0+4
0 4
3
2
+ 6
0 0+4
S p
8 9
0+4+3 c 0+3
3 d
0+3
- +
51
Ford-Fulkerson Algorithm
Flow+ =0+4+3
S is marked
a is marked
d is marked
We mark P from d because 0+3 ˂ 9
+ 0
a 4 b 0+4
0 4
3
2
+ 6
0
S 0+4 p
8 9
+
0+4+3 c 0+3
3 d
0+3
- +
52
Ford-Fulkerson Algorithm
Flow+ =0+4+3
S is marked
a is marked
d is marked
P is marked
The improving chain is with an increase in flux = min (3-0.2-0.9-3)=2
+ 0
a 4 b 0+4
0 4
3
2
+ 6
0
S 0+4 p
8 9
+
0+4+3 c 3 d 0+3
0+3
- +
53
Ford-Fulkerson Algorithm
Flow+ =0+4+3+2
S is marked
a is marked
d is marked
P is marked
The improving chain is with an increase in flux = min (3-0.2-0.9-3)=2
+ 0
a 4 b 0+4
0 4
3
2
+ 6
0
S 0+4 p
8 9
+
0+4+3 c d 0+3
3
0+3
- +
54
Ford-Fulkerson Algorithm
Flow+ =0+4+3+2
S is marked
a is marked d is
marked
P is marked
The improving chain is S a d P with an increase in flux = min (3-0.2-0.9-3)=2
+ 0
a 4 b 0+4
0+2 4
3
2
+ 6
0+2 0+4
S p
8 9
+
0+4+3 c d 0+3+2
3
0+3
- +
55
Ford-Fulkerson Algorithm
Flow+ =0+4+3+2
If we no longer find an improving chain (this is the case for this network
because (b p) (a d) and (c d) are saturated
0
a 4 b 0+4
0+2 4
3
2
6
0+2 0+4
S p
8 9
0+4+3 0+3+2
c 3 d
0+3
56