Introduction to network flows
Overview
> Transport network and flows
> Complete flows.
> Maximum flows.
> Ford-Fulkerson algorithm.
> Multiflows and dynamic flows.
1
Definition of a transport network and an s-t-flow
> A transport Network R=(G,u,s,t) consists in :
• A digraph G=(V,A).
• A capacity function u : A→R+.
• Two particular vertices s and t in V (resp. called source and sink ).
> Let R=(G,u,s,t) be a transport network, we call s-t-flow on R
function f : A→R+ such that :
• f(a) u(a), for all a A.
• ∑a d-(v) f(a) = ∑a d+(v) f(a), for all v V \ {s,t} (Kirchoff constraint).
2
Example
> Three warehouses A, B, C, contain respectively 20, 35 et 10
tons of goods. There are demands of 25, 20 et 20 tons to
destinations D, E and F. The unitary transportation costs are
given in the following matrix. What would be the minimal cost
transport plan ?
D E F
A 15 10 0
B 15 5 5
C 5 0 10
3
The associated transport network
15
A D
10
20 25
15
s 35 B 5 E 20 t
10 5 5 20
C 10 F
For arcs in the middle, unitary cost (in red) and capacity are taken as infinite
For other arcs, costs are taken as zeros.
4
Definition of the complete s-t-flow
> Let R=(G,u,s,t) be a transport network, s-t-flow f on R is called
complete if for any s-t-path P=((s,v1),(v1,v2),…,(vn-1,vn),(vn,t)),
there exists a P such that f(a) = u(a).
• Some complete flow is not necessarily maximum.
> Construction of a complete s-t-flow :
• Set f := 0.
• Repeat
• Choose some s-t-path P such that a P we have f(a)<u(a).
• If such path doesn’t exist, stop.
• Otherwise, for all a P do f(a) := f(a) + mina P u(a)-f(a).
5
Example
A 0/6 D
0/5
0/2 0/2
0/2
s 0/7 B 0/3 E 0/5 t
0/2 0/2 0/7
C 0/8 F
6
Example
A 0/6 D
0/5
0/2 0/2
0/2
s 0/7 B 0/3 E 0/5 t
0/2 0/2 0/7
C 0/8 F
P = ((s,A),(A,D),(D,t)), mina P u(a)-f(a)=2
7
Example
A 2/6 D
0/5
2/2 2/2
0/2
s 0/7 B 0/3 E 0/5 t
0/2 0/2 0/7
C 0/8 F
8
Example
A 2/6 D
0/5
2/2 2/2
0/2
s 0/7 B 0/3 E 0/5 t
0/2 0/2 0/7
C 0/8 F
P = ((s,B),(B,E),(E,t)), mina P u(a)-f(a)=3
9
Example
A 2/6 D
0/5
2/2 2/2
0/2
s 3/7 B 3/3 E 3/5 t
0/2 0/2 0/7
C 0/8 F
10
Example
A 2/6 D
0/5
2/2 2/2
0/2
s 3/7 B 3/3 E 3/5 t
0/2 0/2 0/7
C 0/8 F
P = ((s,C),(C,E),(E,t)), mina P u(a)-f(a)=2
11
Example
A 2/6 D
0/5
2/2 2/2
0/2
s 3/7 B 3/3 E 5/5 t
2/2 2/2 0/7
C 0/8 F
value(f) = 7
12
The maximum s-t-flow problem
> A complete flow is not necessarily a maximum one.
> Let R=(G,u,s,t) be a transport network, the maximum s-t-flow
problem consists in finding some s-t-flow f* such that value(f*)
is maximum.
• I.e., find f* s. t. for all s-t-flow f on R we have value(f) ≤ value(f*).
13
The residual graph
> Given G=(V,A) a digraph, we let G’=(V,AA’) such that if
a=(v,w)A then a’=(w,v)A’.
• Remark : G’ can contain parallel arcs even when G doesn’t have any.
> Given a transport network R=(G,u,s,t) and an s-t-flow f on R,
uf : AA’→R+ is called the residual capacity function s. t.:
• uf(a) = u(a) – f(a), for all aA.
• uf(a’) = f(a), for all a=(v,w)A and a’=(w,v)A’.
> We call residual graph associated to f the graph
Gf = (V,{aAA’ : uf(a) > 0}).
14
Notion of f-augmenting path
> Let R=(G,u,s,t) be a transport network, f an s-t-flow on R, P a
path on Gf and g > 0, augment f with g over P means:
• f(a) := f(a) + g when a A.
• f(a) := f(a) – g when a’ A’.
> We call f-augmenting path, any s-t-path in Gf.
15
Ford-Fulkerson algorithm
> Input: R=(G,u,s,t) a transport network.
> Output: an s-t-flow f of maximum value.
> Description:
• Set f := 0.
• Repeat:
• Choose an f-augmenting path P.
• If such path doesn’t exist, then end (f is maximum).
• Augment f with g=minaP uf(a) over P.
16
Ford-Fulkerson algorithm
> A practical method:
• Step 1. Set f :=0; mark S;
• Step 2. While there is a non examinated marked node i and t is not
marked, do:
Mark all successors with residual capacities of i with i+;
Mark all predecessors with positive incoming flow of i with i-;
End while;
• Step 3. If t is marked, determine the augmenting path P and augment f with g=minaP uf(a)
over P. Mark S and go back to step 2.
Otherwise, the flow is maximal;
17
Example (previous)
A 2/6 D
0/5
2/2 2/2
0/2
s 3/7 B 3/3 E 5/5 t
2/2 2/2 0/7
C 0/8 F
18
Example (previous)
A 2/6 D
0/5
2/2 2/2
0/2
s 3/7 B 3/3 E 5/5 t
2/2 2/2 0/7
C 0/8 F
P = ((s,B),(B,D),(D,A),(A,E),(E,C),(C,F),(F,t)),
mina P uf(a) =2
19
Example (previous)
A 0/6 D
2/5
2/2 2/2
2/2
s 5/7 B 3/3 E 5/5 t
2/2 0/2 2/7
C 2/8 F
value(f) = 9, f is maximum
20
Go on …
A 1
1/ 1/
1/1 B 0/ 2 1/1
1/1 1/ 1/1
s 1/1 C 3/ 3 1/1 t
1/1 1/
0/1
D 0/ 4
0/1 0/ 1/1
E 5
Transform the above complet flow to a maximum one
21
The maximum bipartite matching
> Transform this problem to a maximum flow one.
22
The maximum bipartite matching
1 1
1 1
1 1
s t
1 1
1 1
1
1
23
Lemma on generalized Kirchoff constraints
> Let R=(G,u,s,t) be a transport network and f an s-t-flow in R
then for all X V \ {s,t} we have :
∑a d-(X) f(a) = ∑a d+(X) f(a).
□
24
Lemma
> Let R=(G,u,s,t) be a transport network and f an s-t-flow in R
then for all X V s. t. s X and t X we have :
(a) value(f) = ∑a d+(X) f(a) - ∑a d-(X) f(a).
(b) value(f) ≤ ∑a d+(X) u(a).
> Proof :
(a) : similar to previous lemma.
(b) : trivial implication of (a) and of positivity of flow function (0 ≤ f(a) ≤ u(a)).
□
25
Theorem
> Let R=(G,u,s,t) be a transport network, an s-t-flow f in R is
maximum iff it doesn’t exist an f-augmenting path.
> Proof :
Necessity : if such path exist, it would conduct to larger flow value, hence f
is not maximum.
Sufficiency : if there is no f-augmenting path, t is not reachable (by
definition) from s in Gf. Let Y be the set of reachable vertices from s in Gf.
By definition of Gf we have f(a)=u(a) (because uf(a)=u(a)-f(a)=0) for all a
of d+G(Y) and f(a)=0 (because uf(a’)=f(a)=0) for all a in d-G(Y). The
previous lemma (part (a)) implies
value(f) = ∑a d+ (Y) u(a),
G
and part(b) allows to conclude.
□
26
Connection to the minimum cut problem
> Let G=(V,A) be a digraph, X V is called cut in G if s X
and t X .
• We define capacity(X) = ∑a d+(X) u(a).
> Theorem : Let R=(G,u,s,t) be a transport network, the
maximum value of s-t-flow in R is equal to the minimum
capacity of cuts in G.
> Proof (hint) :
For any cut X, we have capacity(d+(X)) = ∑a d+(X) u(a) ≥ value(f).
On the other hand, for a maximum flow we can build a cut with the same
capacity, which proves the validity of the theorem.
□
27
Remarks on the integrality
> Corollary : let R=(G,u,s,t) be a transport network with u : A →
Z+, then there exists a maximum s-t-flow with integral values
and Ford-Fulkerson algorithm achieves such a flow.
> Proof :
This is because the capacity function has integer values g=minaP uf (a).
□
> Remark : the corresponding LP yields as well integral
values because the associated matrix is TU (i.e., all
their sub-determinants are 0, +1 or -1).
28
Remarks on algorithmic aspects
> To achieve better performances, it is convenient not to choose
f-augmenting paths arbitrarily.
> Par ex. the Edmonds-Karp algorithm suggests to choose the
shortest augmenting path.
• Theorem : The Edmonds-Karp algorithm solve the s-t-flow maximum
problem in O(m2n).
> Other algorithms exist, for instance the Golberg-Tarjan
algorithm, which runs in O(n3).
29
A PROBLEM OF URBAN CIRCULATION
The road network which Fulkerson City must maintain is illustrated below (the
capacities of the arcs represent the maximum flow in cars per hour).
10 I 15
10
A 4 F
15
10
D 5
15 15
J
20 40 10
B 6 6 G
5 10
5 K
10 E 4
7 4
30
C H 7 15
L
1) Let N be the maximum number of cars per hour which can circulate through
this network.
1.1) Calculate N.
1.2) Characterize the routes that can be created in order to increase N. By how much can we
increase N?
2) The local officials want to improve the circulation, increasing the number N by
creating new routes. In urban areas, only the creation of a route HK and the
widening of the street EG previously reserved for pedestrians are feasible. The
choice will therefore have to be made between:
a) creating HK; b) widening EG; c) creating HK and widening EG.
30
END
31
Multicommodity flows
Un multi-commodity flow is composed of several distinct flows d for any
couples (sd,td). Any node in the graph can be source of flow destination.
Similarly to simple flows, a multi-flow defines a function from U to R+
satisfying:
• Capacity constraints(!)
• Flow conservation (!!)
• Flow value to satisfy/maximize(!!!)
32
Dynamic flow
> Until now we have seen static flows, no temporal considerations
have been taken into account;
> Some flows are dynamic in time, ATM, transport…
> Ford-Fulkerson (1958) have shown how we can transform
dynamic flows to static ones.
33
Transformation of a dynamic flow to a static one
an example
34