0% found this document useful (0 votes)
52 views32 pages

Foundations of Operations Research: Master of Science in Computer Engineering

The document describes several examples of maximum flow problems that can be modeled as flow networks. It provides the following definitions: - A flow network is represented by a directed graph where nodes represent locations and arcs represent paths between locations with capacities. - The maximum flow problem aims to find the maximum amount of flow that can be pushed from a source node to a sink node respecting the capacities of each arc. - Cut capacity is the sum of capacities of arcs flowing out of a cut set, while flow is the difference between outgoing and incoming flows across a cut. The maximum flow is always less than or equal to the minimum cut capacity.

Uploaded by

Heisenberg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views32 pages

Foundations of Operations Research: Master of Science in Computer Engineering

The document describes several examples of maximum flow problems that can be modeled as flow networks. It provides the following definitions: - A flow network is represented by a directed graph where nodes represent locations and arcs represent paths between locations with capacities. - The maximum flow problem aims to find the maximum amount of flow that can be pushed from a source node to a sink node respecting the capacities of each arc. - Cut capacity is the sum of capacities of arcs flowing out of a cut set, while flow is the difference between outgoing and incoming flows across a cut. The maximum flow is always less than or equal to the minimum cut capacity.

Uploaded by

Heisenberg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

Foundations of Operations Research

Master of Science in Computer Engineering

Roberto Cordone
[email protected]
Tuesday 13.15 - 15.15
Thursday 10.15 - 13.15
http://homes.di.unimi.it/~cordone/courses/2013-for/2013-for.html

Lesson 8: Maximum flow

Como, Fall 2012


1 / 32

A flow model
A company manages a hydraulic network to supply water to a big consumer.
The network is known: in particular, each link has a maximum flow capacity,
the position of the water sources and of the consumer are given.
The aim is to estimate the maximum amount of water which is possible to
supply to the consumer through the network.
The network can be modelled by an arc-weighted directed graph G = (N, A)
the nodes stand for water sources and pipeline crossings, while
a fictitious node s (source) represents the overall origin of water,
and node t (sink) represents the consumer
the arcs stand for pipelines (two opposite arcs each),
including fictitious arcs from s to each water source node
the weight kij stands for the capacity of arc (i, j), i. e. the maximum
feasible water flow in the pipeline (possibly different in the two directions)

2 / 32

A human flow model


An event will draw a large crowd in a square of the town centre.
The Civil Protection must define the maximum amount of people who can be
admitted to the event, while guaranteeing that they will all be able to leave the
town centre within a specified time.
The street network is known: in particular, the width of the streets and the
relation between the width and the number of individuals per unit time who
can move along each street are known.
We aim to estimate the maximum amount of people who can attend the event.
The network can be modelled by an arc-weighted directed graph G = (N, A)
the nodes stand for crossings and squares:
a source node s represents the square (origin of the crowd),
a sink node t represents the external world (destination of the crowd)
the arcs stand for streets (two opposite arcs for each street),
plus fictitious arcs from each node on the border of the town centre to t
the weight kij stands for the arc capacity (maximum number of individuals
who can walk along the arc in a time unit)
3 / 32

The maximum flow problem


Given
a directed graph G = (N, A) with n = |N| nodes and m = |A| arcs
+
a source node s with
s = , and a sink node t with t =
(the other nodes are denoted as transhipment nodes)

a capacity function defined on the arcs: k : A R+


find a flow function defined on the arcs (x : A R+ ) such that
1

balance: in transhipment nodes the outgoing flow equals the ingoing flow
X
X
xjk =
xij
j N \ {s, t}
(j,k)+
j

(i,j)
j

capacity: the flow on each arc respects the capacity


0 xij kij

(i, j) A

the ingoing flow of the sink t is maximum:


X
f (x ) =
xjt f (x)
(j,t)
t

for all x enjoying properties 1 and 2


4 / 32

Examples

. . . nonbalanced

. . . violating a capacity

. . . nonminimal (f (x) = 2)

x is optimal (f (x ) = 6)

x is not an optimal
solution because it is. . .

. . . nonbalanced

5 / 32

A production planning model


During a planning horizon of various months T = {1, . . . , n}, a factory
produces an item, respecting a variable known production capacity.
The item is sold in batches at the end of each month, so as to satisfy (as much
as possible) a known demand.
The unsold items are stored in a depot whose capacity is known.
Determine the maximum number of items which remain in the depot at the
end of the planning horizon.
The problem can be modelled by an arc-weighted directed graph G = (N, A):
nodes: a factory node fi , a storage node si and a demand node di for each
month i = 1, . . . , n, a final storage node sn+1 , a source s and a sink t
arcs and arc capacities:
from s to all factory nodes: ks,fi = +
from each factory node to the corresponding storage node:
kfi ,si = production capacity in month i
from each storage node to the following one: ksi ,si+1 = depot capacity
from each storage node to the corresponding demand node:
ksi ,di = demand in month i
from each demand node and from the last storage node to t:
kdi ,t = + and ksn ,t = depot capacity
6 / 32

Capacity and flow associated to a cut


An (s, t)-cut is a cut induced by a subset of nodes including s and not t
A graph with n nodes admits 2n2 (s, t)-cuts

S = {1, 2} +
S = {(1, 3) , (2, 3) , (2, 4)} and S = {(3, 2)}

Capacity of a cut is the sum of the capacities on the arcs of the outgoing cut
X
kS =
kij
(i,j)+
S

For example, kS = k13 + k23 + k24 = 7


Flow across a cut is the difference of the outgoing and ingoing flow on the cut
X
X
xS =
xij
xij
(i,j)+
S

(i,j)
S

For example, xS = x13 + x23 + x24 x32 = 4


7 / 32

Property 1: Uniformity of the flow


Given a feasible flow x : A R+ , every (s, t)-cut is crossed by the same flow
Proof: Given the outgoing flow of s, notice that no arc enters s
X
X
X
xis
x{s} =
xsk =
xsk
(s,k)+
s

(s,k)+
s

(i,s)
s

Given any subset S including s and not t (s S N \ {t}), sum the balance
constraints over all nodes in S \ {s} and move both terms on the left side
X
X
X
X
xjk
xij = 0
jS\{s} (j,k)+
j

jS\{s} (i,j)
j

Sum the expression of x{s} obtained above


X X
X X
x{s} =
xjk
xij
jS (j,k)+
j

jS (i,j)
j

Split each sum, separating the arcs with both or only one extreme in S
X
X
X
X
x{s} =
xjk +
xjk
xij
xij = xS
(j,k)A:j,kS

(j,k)+
S

(i,j)A:i,jS

(i,j)
S

The flow across any cut equals that going out of s; in particular, f (x) = x{s}
8 / 32

Property 2: Relation between flow and capacity


Given any feasible flow x : A R+ and any (s, t)-cut, the capacity of the cut
exceeds the flow across the cut
Proof: Let S be any subset including s and not t: s S N \ {t}.
By definition
xS =

xij

(i,j)+
S

xij

(i,j)
S

Since xij 0 for all (i, j) A


xS

xij

(i,j)+
S

Since xij kij for all (i, j) A


xS

kij = kS

(i,j)+
S

which is the thesis

9 / 32

Duality between maximum flow and minimum cut


The relation between flow and capacity is an example of duality, that is a
general relation between a maximization and a minimization problem:
weak duality when each solution of the minimization problem costs no less
than each solution of the maximization problem; as a consequence, the
minimum of the former is not smaller than the maximum of the latter
strong duality when the two optima coincide
A weak duality relates two problems defined on graph G = (N, A), on nodes s
and t and on capacity function k : A R+ :
the minimum cut problem: find an (s, t)-cut of minimum capacity
the maximum flow problem: find a flow of maximum size from s to t
The capacity of any (s, t)-cut is not smaller than any feasible flow from s to t:
hence, the minimum cut capacity is not smaller than the maximum flow
If the capacity of an (s, t)-cut equals a feasible flow x, both are optimal
(the flow is maximum and the cut is minimum)
We will prove prove that also strong duality holds: the minimum capacity of an
(s, t)-cut is always equal to the maximum flow from s to t
There is a subtle theoretical reason for that
10 / 32

A minimum cut model


What is the practical meaning of the minimum cut problem?

Find the bottleneck: links to destroy in order to reduce the flow


Conversely, select the links to improve in order to increase the flow
11 / 32

A load balancing model (1)


A set M of program modules must be distributed between two processors.
The cost of executing module i M on the first processor is i .
The cost of executing module i M on the second processor is i .
A communication cost cij must be paid if modules i and j are assigned to
different processors.
Distribute the modules minimizing the execution and communication cost.
Model the problem with an auxiliary arc-weighted directed graph:
a node s for the first processor, a node t for the second processor, a node
i for each module
an arc from s to each module node, two opposite arcs between each pair
of module nodes, an arc from each module node to t
the weight function k : A R+ provides
the execution cost i for the arcs (s, i) with i M
the communication cost cij for the arcs (i, j) M M
the execution cost i for the arcs (i, t) with i M

Notice that the arcs express separation, and the associated cost
12 / 32

A load balancing model (2)

Any (s, t)-cut describes a partition of the modules between the two processors:
S includes s and the modules assigned to the first processor
N \ S includes t and the modules assigned to the second processor
the weights of the arcs in +
S represent:
the execution costs j for the second processor
the communication costs cij between the two processors
the execution costs i for the first processor

Overall, the weight of any (s, t)-cut equals the cost of the assignment, and the
minimum cut identifies the solution of minimum cost
13 / 32

Saturated and empty arcs


Given a feasible flow x : A R+ , an arc (i, j) is
saturated when its flow equals its capacity: xij = kij
on a saturated arc the flow cannot increase
empty when its flow is null: xij = 0
on an empty arc the flow cannot decrease

Saturated arcs:
(2, 4) and (3, 2)

Saturated arcs:
(1, 3), (2, 3) and (3, 2)

Empty arcs: (2, 3)

Empty arcs: (3, 2)

14 / 32

An optimality condition
The capacity of a cut and the flow across it are equal if and only if
all outgoing arcs are saturated: xij = kij for all (i, j) +
S
all ingoing arcs are empty: xij = 0 for all (i, j)
S
Proof: The if part is trivial. As for the only if part:
X
X
X
xij
kS = xS
kij =
xij
(i,j)+
S

(i,j)+
S

Since xij kij for all (i, j) A


X
X
kij
kij
(i,j)+
S

(i,j)+
S

(i,j)
S

xij

(i,j)
S

xij 0

(i,j)
S

But since xij 0 for all (i, j) A, this implies xij = 0 for all (i, j)
S
Consequently,
X
(i,j)+
S

kij =

xij

(i,j)+
S

But since xij kij for all (i, j) A, this implies xij = kij for all (i, j) +
S
15 / 32

An algorithmic idea
Start with a trivial feasible flow: xij = 0 for all (i, j) A
Increase the current flow while keeping it feasible
If there is an (s, t)-cut whose capacity equals the flow, terminate;

otherwise, go to step 2
How to increase the flow while keeping it feasible?
If the flow on arc (i, j) increases, one of the following effects must occur
an increase in the flow on a subset of ingoing arcs of i
a decrease in the flow on a subset of outgoing arcs of i
a combination of the two modifications on a subset of incident arcs

A similar effect must occur in j (just revert outgoing and ingoing)


To keep it simple, modify the flow on a single arc for each extreme node:
the arcs with modified flow form a path between s and t,
because in s and t it is feasible to change the flow on a single arc

16 / 32

Augmenting path
An augmenting path with respect to a feasible flow x : A R+ is an
undirected path P from s to t, such that the flow value f (x) can be increased
modifying the flow on its arcs
In general the augmenting path is not directed; it consists of
a set P + of forward arcs, directed from s to t, which must be nonsaturated
a set P of backard arcs, directed from t to s, which must be nonempty
The flow value f (x) increases by if
the flow function xij increases by on all forward arcs (i, j) P +
the flow function xij decreases by on all backward arcs (i, j) P
The increase and decrease must respect the capacity along the whole path
xij + kij

(i, j) P +

and

xij 0

(i, j) P

Therefore, the largest feasible flow modification is




f (x, P) = min min (kij xij ) , min xij
(i,j)P +

(i,j)P

f (x, P) > 0 if and only if all arcs are nonsaturated in P + , nonempty in P


17 / 32

Example

Augmenting path: P = (1, 3, 4)

Augmenting path: P = (1, 2, 3, 4)

Forward arcs: P + = {(1, 3) , (3, 4)}

Forward arcs: P + = {(1, 2) , (3, 4)}

Backward arcs: P =

Backward arcs: P = {(3, 2)}

f (x) = min (k13 x13 , k34 x34 ) = 1

f (x) = min (k12 x12 , x32 , k34 x34 )


=1

18 / 32

Ford-Fulkersons algorithm (1956)


1 start from zero flow
2 if no augmenting path exists, terminate;
3 otherwise, add to the current flow the maximum feasible flow for the path found

FordFulkerson(N, A, k)
f := 0; xij := 0 for each (i, j) A;

{ trivial feasible flow }

Stop := False;
Repeat
P := FindAugmentingPath(s, t, N, A, k, x);
If @P
then Stop := True;
else
"
#

:= min
min kij xij , min xij ;
(i,j)P +

(i,j)P

f := f + ;
xij := xij + for each (i, j) P + ;
xij := xij for each (i, j) P ;
until Stop = True;
Return (f , x);
How can one find an augmenting path? Why does it works?
19 / 32

Finding an augmenting path


Given graph G = (N, A), the capacity function k and a feasible flow x, the
auxiliary incremental network is an arc-weighted directed graph G = N, A
with a residual capacity function k : A R+ defined as follows
1
2

the nodes are the same as in the original graph


for each nonsaturated arc (i, j) A, add to A an arc (i, j) of residual
capacity kij = kij xij
for each nonempty arc (i, j) A, add to A an arc (j, i) of residual capacity
kij = xij
resulting parallel arcs can be merged

The augmenting paths in the original network correspond one-to-one to the


paths from s to t in the incremental network
With a bit of intuition, one can work directly on the original graph: simply
see where new flow can be added or existing flow can be reduced

20 / 32

Finding an augmenting path (example)

Two arcs (2, 3) are merged

Two arcs (3, 2) are merged

An augmenting path corresponds to


a path in the incremental network

There is no augmenting path and


no path in the incremental network

No path in the incremental network No augmenting path the original one


The cut induced by the subset S of nodes reachable from s has only
saturated forward arcs and empty backward arcs the current flow is optimal!
21 / 32

Application of Ford-Fulkersons algorithm (1)

FordFulkerson(N, A, k)
f := 0; xij := 0 for each (i, j) A;
Stop := False;
Repeat
P := FindAugmentingPath(s, t, N, A, k, x);
If @P
then Stop := True;
else
"
#
:= min

min

(i,j)P +

(kij xij ) ,

min

(i,j)P

f := f + ;
xij := xij + for each (i, j) P + ;
xij := xij for each (i, j) P ;

xij

xij := 0 for all (i, j) A

until Stop = True;


Return (f , x);

22 / 32

Application of Ford-Fulkersons algorithm (2)

FordFulkerson(N, A, k)
f := 0; xij := 0 for each (i, j) A;
Stop := False;
Repeat
P := FindAugmentingPath(s, t, N, A, k, x);
If @P
then Stop := True;
else
"
#
:= min

min

(i,j)P +

(kij xij ) ,

min

(i,j)P

xij

Augmenting path: P = (1, 2, 3, 7)


f (x, P) = 2
;

f := f + ;
xij := xij + for each (i, j) P + ;
xij := xij for each (i, j) P ;
until Stop = True;
Return (f , x);

23 / 32

Application of Ford-Fulkersons algorithm (3)

FordFulkerson(N, A, k)
f := 0; xij := 0 for each (i, j) A;
Stop := False;
Repeat
P := FindAugmentingPath(s, t, N, A, k, x);
If @P
then Stop := True;
else
"
#
:= min

min

(i,j)P +

(kij xij ) ,

min

(i,j)P

xij

Augmenting path: P = (1, 5, 6, 7)


f (x, P) = 2
;

f := f + ;
xij := xij + for each (i, j) P + ;
xij := xij for each (i, j) P ;
until Stop = True;
Return (f , x);

24 / 32

Application of Ford-Fulkersons algorithm (4)

FordFulkerson(N, A, k)
f := 0; xij := 0 for each (i, j) A;
Stop := False;
Repeat
P := FindAugmentingPath(s, t, N, A, k, x);
If @P
then Stop := True;
else
"
#
:= min

min

(i,j)P +

(kij xij ) ,

min

(i,j)P

xij

Augmenting path:
P = (1, 4, 3, 2, 6, 7)
;

f (x, P) = 1

f := f + ;
xij := xij + for each (i, j) P + ;
xij := xij for each (i, j) P ;
until Stop = True;
Return (f , x);

25 / 32

Application of Ford-Fulkersons algorithm (5)

FordFulkerson(N, A, k)
f := 0; xij := 0 for each (i, j) A;
Stop := False;
Repeat

No augmenting path:
The nodes reachable from s form
+ =
S = {1, 4} with
S

P := FindAugmentingPath(s, t, N, A, k, x);
If @P
then Stop := True;
else
"
#
:= min

min

(i,j)P +

(kij xij ) ,

min

(i,j)P

xij

f := f + ;
xij := xij + for each (i, j) P + ;
xij := xij for each (i, j) P ;
until Stop = True;
Return (f , x);

Optimal solution: f (x) = xS = kS = 5


all outgoing arcs are saturated
all ingoing arcs are empty
26 / 32

Computational complexity (1)


T = Tin +

imax
X

(i)

Titer

i=1

FordFulkerson(N, A, k)
f := 0; xij := 0 for each (i, j) A;

Tin O (m) (set the flow on the arcs of A)

Stop := False;
How many iterations imax of the loop?

Repeat

O (m) (visit all arcs of A)

P := FindAugmentingPath(s, t, N, A, k, x);
If @P
then Stop := True;
else
"
#
:= min

min

(i,j)P +

(kij xij ) ,

min

(i,j)P

f := f + ;
xij := xij + for each (i, j) P + ;
xij := xij for each (i, j) P ;

xij

O (n) (scan the arcs of the augmented path)


O (1)
O (n) (scan the arcs of the augmented path)
O (n) (scan the arcs of the augmented path)

until Stop = True;


Return (f , x);

The overall complexity is T O (imax m),


where imax is the number of augmenting paths required to reach the optimum
27 / 32

Computational complexity (2)


How many iterations are necessary?
at first, f and all xij are set to 0
at each iteration, f increases by and all xij change by or keep
unchanged
if all capacities and flows are integer, then the flow update is integer, and
the flows remain integer after the update
kij , xij N for all (i, j) A f (x, P) N xij f (x, P) N
since the path are augmenting, > 0 1
the maximum flow equals the minimum cut
the minimum cut is lower than the total capacity of all the arcs,
which is lower than kmax m, where kmax = max kij
(i,j)A

Consequently

f
mkmax
= m kmax

min
1

and the overall complexity is O kmax m2
imax

28 / 32

Pseudopolynomial algorithms
However, a maximum flow instance is given by a list of m arcs, and for each arc
the index of the tail node, an integer coded into log2 n bits
the index of the head node, an integer coded into log2 n bits
the capacity, an integer coded into log2 kmax bits
Thus, the size of the instance is m (2 log2 n + log2 kmax ) bits
Usually, n < kmax and the size is in O (m log kmax )
The problem is that kmax m2 is
polynomial with respect to m
but but exponential with respect to log kmax
Consequently, Ford and Fulkersons algorithm is not polynomial, but at least it
is not exponential with respect to the number of nodes and arcs
A pseudopolynomial algorithm is an algorithm which is
polynomial with respect to the number of elements of the problem
nonpolynomial with respect to the values of the weight functions

29 / 32

An example of inefficient application

Ford and Fulkersons algorithm might choose the following sequence of


augmenting paths:
1

P = (1, 2, 3, 4): f (x, P) = 1 and f (x) = 1

P = (1, 2, 3, 4): f (x, P) = 1 and f (x) = 2

P = (1, 2, 3, 4): f (x, P) = 1 and f (x) = 3

...

thus requiring 2M steps, where M can be set to any value


The maximum flow problem admits polynomial algorithms derived from Ford
and Fulkersons: the breakthrough is to choose a smart augmenting path, such
as that with the minimum number of arcs
30 / 32

A linear programming formulation


The maximum flow problem can be put into linear programming form
with the following decision variables
f : flow value (uniform across every (s, t)-cut)
xij : flow on arc (i, j) A

max f
X
(i,j)
j

xij

xjk

(j,k)+
j

0 xij

(1)

= 0

f
kij

if j = s
if j N \ {s, t}

(2)

if j = t
(i, j) A

(3)

It can be proved that this specific linear programming problem enjoys the
integrality property: if the data are integer, the optimal solution is integer
(if kij N, then xij N)
31 / 32

A project assignment model


A company with m workers has n ongoing projects. Each worker has specific
skills, which can be appropriate or not to perform each project.
It is necessary to assign the projects to the workers so that:
each worker is assigned at most one project
each project is assigned to at most one worker
Assign the projects to the workers so that the maximum number of projects
can be performed.
The problem can be modelled by an arc-weighted directed graph G = (N, A):
the nodes represent the workers and the projects, plus a fictitious source
node s and a fictitious sink node t
the arcs represent the compatibility relation between workers and projects,
fictitious arcs link s to each worker node, and each project node to t
the capacity function k : A R+ is defined as: ksi = 1 for all i, kjt = 1
for all j, kij = + for all i 6= s, j 6= t
An arc with xij = 1 suggests to assign worker i to project j
Notice that the integrality property guarantees that xij {0, 1} for all (i, j) A
32 / 32

You might also like