You are on page 1of 13

Week 6: Maximum Flows and Min Cost Flows

October 12, 2022

1 Introduction to Network Flows


A network N is a pair (G, u) where G is a directed graph (V, A) and u : A → R+ is a capacity
function on the arcs. In the network two special vertices, a source s and a sink t are identified.
A flow from s to t in (G, u) is a function x : A → R+ on the arcs, that satisfies the capacity
constraints on the arcs and maintains the flow balance (inflow equals outflow) in all nodes,
except possibly the source s and the sink t.
For example, consider the network depicted in Figure 1.

4, 4
1 5

4, 6 0, 4 1, 4 3, 6
4, 8
4, 8 2 6 6, 7
1, 5
s 0, 2 t

2, 5 2, 2 1, 4
3 7
1, 3
2, 2 1, 5 2, 5 2, 2

0, 4
4 8

Figure 1: A flow in a network

The figures at the arcs denote respectively the flow xa (a ∈ A) and the capacity ua (a ∈ A).
One can check that in the example above the flow indeed satisfies the capacity constraints and
maintains the flow balance on all nodes except s and t. The net outflow of s equals the net
inflow of t, and this is named the flow value. In Figure 1 we can see that the flow value is 12.
Often we are interested in finding a flow of maximum value: the max flow problem.

1
Graph Theory 2

Max Flow Problem


Input: A network (G, u) with source s and sink t.
Task: Find a flow of maximum value from s to t.

One could easily denote this problem as a linear program. The decisions to be made in this
problem are how much flow to put through each arc.
Variables: ∀a∈A xa = the amount of flow through arc a.
This gives the following LP-formulation, in which the objective is to maximize the net outflow
from the source s.
X X
maximize xs,j − xi,s
j:(s,j)∈A i:(i,s)∈A
X X
subject to xi,j = xj,i ∀i∈V \{s,t}
j:(i,j)∈A j:(j,i)∈A
0 ≤ xa ≤ ua ∀a∈A
For convenience, we sometimes add an arc (t, s) to the network to redirect the flow from t back
to s, so that the flow balance in these two nodes is also maintained. The flow is then called a
circulation.
There are numerous extensions of the maximum flow problem. In one of these we add costs on
units of flows through the arcs and try to minimize find a flow that minimizes the total cost
for a given flow value. This min-cost flow problem will be the subject of a later section. Many
problems can be modelled as a maximum flow problem or as one of its extensions. Among them
are the shortest path problem and the bipartite matching problem (also called the assignment
problem).

2 Augmenting Path Algorithm


An intuitive and very simple idea for solving a maximum flow problem is to search for paths
from the source s to the sink t over which flow can be augmented. This algorithm is known as
the augmenting path algorithm.

Input: Network N = (G, u), with source s and sink t.


Output: a flow of maximum value
Initialize xa = 0 for all a ∈ A
while there exists an augmenting path P from s to t do
Augment the flow over P with the minimum residual capacity
end
return d(v) for all v ∈ V
Algorithm Augmenting Path Algorithm:

Consider Example 4. The capacities are attached to the arcs.


Graph Theory 3

1 1
1 2
+2
s 3 t s +2 t
+2
2 1
2 2

Figure 2: Example: Numbers at arcs are capacities.

The leftover capacities of the example network are given in the following picture.

1
1 0
s 1 t

0 1
2

Figure 3: Leftover capacities

It looks like the augmenting path algorithm can not find a better flow, although there is
one. What is wrong? The mistake is found in the interpretation of augmenting paths. An
augmenting path may consist of arcs which have the ”wrong” direction. The ”path” s−1−2−t
consists of the non-existent arc (1, 2). However, we CAN increase the flow along this path by
increasing the flow on the arcs (s, 1) and (2, t), and DECREASING the flow on the arc (2, 1),
by one unit. Note that this DOES maintain the flow conservation constraints at the nodes 1
and 2.

1 1
+1 1 2
s −1 t s 1 t

+1 2 1
2 2

Figure 4: Augmenting path and flow.

A path from s to t that contains arcs in the ”right” direction and arcs in the ”wrong” direction
is an augmenting path if the flow along ”right” arcs can be increased and the flow along ”wrong”
arcs can be decreased. This idea is implemented such that the ordinary reaching algorithm
can find augmenting paths by introducing the so-called residual network G(x) which depends
on the flow x. For each arc (i, j) with capacity uij and flow xij , in the original network, we
introduce at most two new arcs in G(x). If xij < uij then the arc (i, j) is defined with capacity
Graph Theory 4

uij − xij . If xij > 0 then the arc (j, i) is defined with capacity xij .

uij − xij
0 < xij < uij
i j i j

xij

Figure 5:

The residual network of the example after one flow augmentation is depicted in Figure 6 below.

1
1 2
s 1 2 t

2 1
2

Figure 6: Example: residual network.

Finding an augmenting path in the residual network can be done by any variant of the reaching
algorithm. Note that the amount with which we can increase the flow depends on the capacities
of the arcs on the augmenting path. It equals the minimum capacity of an arc on the path.

Theorem 2.1. (Optimality Condition) A flow in a network is maximum if and only if there
is no augmenting path with respect to that flow in the corresponding residual graph.

Proof. If a flow x is maximum, then certainly there is no augmenting path. Otherwise, the
flow could have been augmented to a better one.
If a flow x is not maximum, then let xmax be a better flow. Observe that xmax − x is a feasible
flow in the residual network G(x). Moreover, the net outflow from s of xmax − x is positive.
Since all vertices except s and t satisfy the flow balance constraints with respect to xmax − x,
it follows that t must be reachable by a path P from s on which each arc carries positive flow.
Clearly P is a flow augmenting path in G(x).
This theorem does not imply that the augmenting path algorithm finishes, or even converges
to the right value. However, with integral capacities, or with special choices of augmenting
paths, we are able to prove that the problem is solvable, even in polynomial time. A final, but
very important, property of flows in case the capacities are integral, is the following:

Theorem 2.2. Consider a network (G, u) with integral capacity function u : A → N+ with
Graph Theory 5

source s and sink t. There is a maximum flow x : A → N+ from s to t in (G, u), i.e., there is
an integral maximum flow.

This theorem is an immediate consequence of the application of the augmenting path algorithm.
All residual capacities are integral at the start, and remain integral during the updates with
an integral number of units of flow on augmenting paths.

3 Maximum Flow and Minimum Cut


The correctness of the augmenting path algorithm follows straightforwardly from the finiteness
of the augmenting path algorithm. However, the finiteness is not trivial to prove. In fact,
we cannot guarantee this with the generic algorithm, and even worse, there are examples for
which the generic augmenting flow algorithm converges to the wrong value. In the following
chapter we will specialize this algorithm to find a maximum flow with certainty. For now we
will derive a tight upper bound for the maximum flow value with s − t cuts.

Some definitions. A cut [S, S] is a partition of the vertex set V into two subsets S and S.
A cut [S, S] is an s − t cut if s ∈ S and t ∈
/ S. We define the forward arcs of [S, S] as the set of
arcs with their tail in S and their head in S. These arcs are denoted by (S, S). The arcs with
their tail in S and their head in S are called backward arcs. These arcs are denoted by (S, S).
The capacity of a cut, i.e., u(S, S) is the cumulative capacity of the forward arcs, i.e.,
X
u[S, S] = ua .
a∈(S,S)

Theorem 3.1. (Weak Duality) The value of a feasible flow v is less than or equal to the
capacity of any s − t cut.
Graph Theory 6

Proof.
X X
v = xs,j − xj,s (1)
j:(s,j)∈A j:(j,s)∈A
 
X X X  X X 
= xs,j − xj,s + xi,j − xj,i (2)
 
j:(s,j)∈A j:(j,s)∈A i∈S−s j:(i,j)∈A j:(j,i)∈A
 
X X X 
= xi,j − xj,i (3)
 
i∈S j:(i,j)∈A j:(j,i)∈A
X X
= xi,j − xj,i (4)
(i,j)∈(S,S) (j,i)∈(S,S)
X
≤ xi,j (5)
(i,j)∈(S,S)
X
≤ ui,j (6)
(i,j)∈(S,S)

= u[S, S] (7)

Theorem 3.2. (Strong Duality) The maximum value of a feasible flow equals the minimum
capacity among all s − t cuts.

Proof. Consider a maximum flow xmax and its residual network G(xmax ). By theorem 2.1
there is no path in G(xmax ) from s to t. Now label the vertices that are reachable in G(xmax )
from s and define S as the set of labeled vertices. Clearly, S defines an s − t cut. We claim
that the forward arcs (S, S) in the original network contain a flow equal to their capacity, and
the backward arcs (S, S) contain no flow. Otherwise the residual network G(xmax ) would have
contained an arc from a node i in S to a node j in S implying that j should have been labeled.
Thus, the flow through the cut [S, S] is equal to its capacity. With the previous theorem this
implies optimality of both the flow xmax and the cut [S, S].

3.1 Exercises

Exercise 1. (Khan and Lewis [1987]). To provide adequate medical service to its con-
stituents at a reasonable cost, hospital administrators must constantly seek ways to hold staff
levels as low as possible while maintaining sufficient staffing to provide satisfactory levels of
health care. An urban hospital has three departments: the emergency room (department 1),
the neonatal intensive care nursery (department 2), and the orthopaedics (department 3). The
hospital has three work shifts, each with different levels of necessary staffing for nurses. The
hospital would like to identify the minimum number of nurses required to meet the following
Graph Theory 7

three constraints: (1) the hospital must allocate at least 13, 32 and 22 nurses to the three
departments (over all shifts); (2) the hospital must assign at least 26,24 and 19 nurses to the
three shifts (over all departments); and (3) the minimum and maximum number of nurses
allocated to each department in a specific shift must satisfy the following limits:

Department 1 Department 2 Department 3


Shift 1 (6,8) (11,12) (7,12)
Shift 2 (4,6) (11,12) (7,12)
Shift 3 (2,4) (10,12) (5,6)

The problem is to find a feasible schedule that minimizes the total number of shifts. Formulate
this problem as a max flow problem.

Exercise 2. A commander is located at one node p in a communication network G and


his subordinates are located at nodes denoted by the set S. Let uij be the effort required to
eliminate arc (i, j) from the network. The problem is to determine the minimal effort required
to block all communication between the commander and his subordinates. How can you solve
this problem within polynomial time.

Exercise 3. Consider the network and the feasible flow x shown in Figure 7.
a) Specify four s − t cuts in the network, each containing four forward arcs. List the capacity,
residual capacity, and the flow across each cut.
b) Draw the residual network for the network and flow given in Figure 7 and list fours aug-
menting paths from node s to node t.

5, 8
1 4
5, 10 5, 5 0, 10
0, 4

10, 20
s 2 10, 25 0, 5 t
7, 9
2, 4
5, 15 20, 30
3, 6
3 5

Figure 7: Example for Exercise 3.

Exercise 4. Uniform machine scheduling is an optimization problem in computer science


and operations research in which we are given a certain amount of jobs of varying processing
Graph Theory 8

times, which need to be scheduled on identical different machines. In this exercise we aim to
schedule four jobs on two identical machines. The jobs have a processing time, a release time
and a due date all described in Figure 8.

Job 1 Job 2 Job 3 Job 4


Processing time 1.5 2.0 5.0 1.8
Release time 1 5 0 2
Due date 3 7 6 5

Figure 8: Job properties

Jobs can be preempted, which means that one can stop processing a job and resume it on a
later time.
a) Formulate the example in Figure 8 of the scheduling problem on uniform parallel machines
as a max flow algorithm. Hint: you need to create a node for each job and for each possible
time interval {[0, 1], [1, 2], [2, 3], [3, 5], [5, 6], [6, 7]} and a source s and sink t. Carefully think
about the edges and their capacities.
b) Solve the problem from a and give a feasible schedule.
c) What happens with the optimal value of the max flow if there is no feasible schedule?

Exercise 5. An airline has p flight legs that it wishes to service by the fewest possible
planes. To do so, it must determine the most efficient way to combine these legs into flight
schedules. The starting time for flight i is ai and the finishing time is bi . The plane requires rij
hours to return from the point of destination of flight i to the origin point of flight j. Suggest
a method for solving this problem.

Exercise 6. A group of reporters want to cover a set of sporting events in an olympiad.


The sports events are held in several stadiums throughout a city. We know the starting time
of each event, its duration and the stadium where it is held. We are also given the travel times
between the different stadiums. We want to determine the least number of reporters required
to cover the sporting event. How would you solve this problem?

Exercise 7. The 8 teachers A, B, C, D, E, F, G and H need to be assigned to one of the


8 teaching slots, numbered 1 up to 8. Each teacher can be assigned to at most one teaching
slot and each teaching slot can be assigned to at most one teacher. The table below tells you
which teacher is available on which time slots.
a) Formulate this problem as a linear program.
b) Formulate this problem as a max flow problem.
b) Compute the optimal assignment of teachers to time slots.
Graph Theory 9

1 2 3 4 5 6 7 8
A 1 0 1 1 0 0 1 0
B 0 1 0 0 1 1 0 0
C 0 0 1 1 0 0 1 0
D 0 1 0 0 0 1 0 1
E 1 0 1 0 0 0 1 0
F 1 0 0 1 0 0 1 0
G 0 1 0 0 1 1 0 1
H 1 0 1 1 0 0 1 0

d) Give a compact proof on why there is no assignment in which each teacher is matched to
exactly one timeslot.

Exercise 8. Write down the dual program of the LP-formulation of the max flow problem
on page 2 and explain what kind of solution this dual program will return.

4 The Minimum Cost Flow Problem


The minimum cost flow problem (MCF) is a generalization of the maximum flow problem, in
the sense that besides a network N = (G, u), there is also a cost function c : A → IR+ on
the arcs. The minimum cost flow problem considers s − t flows (where s, t ∈ V of a certain
value v (the net outflow from s or the net inflow of t). Among such flows we want to select
the one with minimum cost, where the arc costs ca are incurred for each unit of flow on arc a.
Formally:

Min Cost Flow Problem


Input: A network (G, u, c) with source s and sink t and a value v.
Task: Find a flow of value v from s to t at minimum cost.

The numbers at the arcs denote respectively the arc costs ca (a ∈ A) and the capacity ua (a ∈
A). A LP-formulation of the problem is given below.
X
minimize ci,j xi,j
(i,j)∈A
X X
subject to xi,j = xj,i ∀i∈V \{s,t}
j:(i,j)∈A j:(j,i)∈A
X X
xs,j − xj,s = v
j:(s,j)∈A j:(j,s)∈A
X X
xt,j − xj,s = −v
j:(t,j)∈A j:(j,t)∈A
0 ≤ xa ≤ ua ∀a∈A
We make some assumptions for instances of minimum cost flows: (1) all input (capacities and
costs) are integral; (2) there is a single supply node s and a single demand node t; (3) there
Graph Theory 10

4, 4
1 5

4, 6 0, 4 1, 4 3, 6
4, 8
4, 8 2 6 6, 7
1, 5
s 0, 2 t

2, 5 2, 2 1, 4
3 7
1, 3
2, 2 1, 5 2, 5 2, 2

0, 4
4 8

Figure 9: An instance of the Minimum Cost Flow problem.

exists a path from s to each vertex and from each vertex to t.


Similar to the max flow problem we can construct residual graphs for the min cost flow problem.
It is slightly more complicated compared to the residual graphs encountered in maximum flow
problems due to the presence of arc costs. A backward arc (on which flow augmentation
corresponds to a flow decrease) has cost which is the negative of the cost of the original arc.

(cij , uij − xij )


0 < xij < uij
i j i j
cij

(−cij , xij )

Figure 10:

4.1 Solving MCF Problems

If a given feasible (value v) flow x∗ , has a residual graph G(x∗ ) that contains a negative cost
cycle, then clearly we can improve upon it by augmenting flow over the cycle. The converse is
also true.

Theorem 4.1. A feasible flow x∗ is optimum if and only if there is no cycle of negative costs
in the residual graph G(x∗ ).

Proof. Let x∗ be a given flow. If there is a negative cost cycle in G(x∗ ), then the flow can be
Graph Theory 11

improved as argued above.


Suppose that there is no negative cost cycle in G(x∗ ). Let xopt be an optimal flow. Then
xopt − x∗ satisfies the capacity constraints on the arcs in the residual graph G(x∗ ). Moreover,
the balance constraints on the nodes are satisfied, even for s and t. Therefore xopt − x∗ can be
decomposed in at most m cycles. These cycles have all nonnegative costs. Therefore,

cxopt = c(xopt − x∗ + x∗ ) = c(xopt − x∗ ) + cx∗ ≥ cx∗

Thus, by the optimality of xopt we have optimality of x∗ .


The negative cycle optimality condition suggests an algorithm in which negative cost cycles
are repeatedly searched in the residual graph. Note that we have to start finding a feasible
flow, i.e., one of the right value. This can be done by applying an augmenting path algorithm
a sufficient number of times, if one exists. We simply augment flow until the desired value is
reached.

Input: Network N = (G, u), with source s and sink t.


Output: a flow of value k with minimum cost
First, find a feasible flow x;
while a negative cost cycle C in G(x) do
Augment the flow over C and update G(x);
end
return flow x
Algorithm Cycle Cancelling:

Note that we did not treat the subject of finding negative cost cycles in graphs in this course.
Though, one could easily adapt Dijkstra’s algorithm in order to do so. In the exercises we
consider the examples are small enough to do it by hand.
Graph Theory 12

4.2 Exercises

Exercise 9. Determine in the following network a maximum s − t flow of minimum cost.

 
1 4 -
HH  HH 2,8
 H  HH 1,9
2,3
 HH 
? 1,1 j
H

* 2,1 HH 3,4 HH
   H
 *
 HY
H HH
20,7 3,3 30,1
  H
H
s - 2 - 5 - t
H H  
H H  
HH HH  
j
H H  ? 2,2 
H
6,7 HH 3,2 HH 6,4
jH
H 
*
5,3
HH 
*
 
40,5 H H  
3

-
6

Figure 11: On the edges you find (cost, capacity)

Exercise 10. Determine in the following network a maximum s − t flow of minimum cost.

 
 1 -
4
 HH 5,1  HH
 HH  HH 9,8
8,7  
 7,3 ? H ? 1,3 j
H
*
 2,2   H H
j
H 7,4 HH
  HH HH
 *
 H H
6,3 6,2 2,4
s - 2 - 5 - t
H H  
HH HH  
 
HH HH 
j 1,3 1,1
6 2,1 8,1
H  H *

1,4 HH  H
jH
H 6  8,8
HH *

1,5 HH
 3 -
6

Figure 12: On the edges you find (cost, capacity)

Exercise 11. Entrepreneur’s problem (Prager [1957]). An entrepreneur faces the fol-
lowing problem. In each of T periods, he can buy, sell, or hold for later sale some commodity,
subject to the following constraints. In each period i he can buy at most αi units of the
commodity, an holdover at most βi units of the commodity for the next period, and must
sell at least γi units (perhaps due some prior agreements). The entrepreneur cannot sell the
commodity in the same period in which he buys it. Assuming that pi , wi and si denote the
purchase costs, inventory carrying cost, and the selling price per unit in period i, what buy-sell
Graph Theory 13

policy should the entrepreneur adopt to maximize total profit in the T periods. Formulate this
problem as a minimum cost flow problem for T = 4.

Exercise 12. The Millersburg Supply Company uses a large fleet of vehicles which it
leases from the manufacturers. The company has forecast the following pattern of vehicle
requirements for the next six months:

Month Jan Feb Mar Apr May Jun


Requirements 430 410 440 390 425 450

Millersburg can lease vehicles from several manufacturers at verious costs and for various
lengths of time. Three of the plans appear to be the best available: a 3-month lease for $1700;
a 4-month lease for $2200; and a 5-month lease for $2600. The company can undertake a lease
beginning in any month. On January 1 the company has 200 cars on lease, all of which go
off lease at the end of February. Formulate the problem of determining the most economical
leasing policy as a minimum cost flow problem.

Exercise 13. Terminal assignment problem (Esau and Wiliams [1966]). Centralized
teleprocessing networks often contain many (as many as tens of thousands) relatively unsophis-
ticated geographically dispersed terminals. These terminals need to be connected to a central
processor unit (CPU) either by direct lines or through concentrators. Each concentrator is
connected to the CPU through a high-speed, cost-effective line that is capable of merging data
flow streams from different terminals and sending them to the CPU. Suppose that the con-
centrators are in place and that each concentrator can handle at most K terminals. For each
terminal j, let coj denote the cost of laying down a direct line from the CPU to the terminal
and let cij denote the line construction cost for connecting concentrator i to terminal j. The
decision problem is to construct a minimum cost network for connecting the terminals to the
CPU. Formulate this Problem as a minimum cost flow problem.

Exercise 14. Formulate the following linear program as a min cost flow problem. All
variables are non-negative.
Min 6x1 + 3x2 + 2x3 + 8x4
x1 + x3 − x4 = 0
x2 − x3 + x5 = 0
x4 + x5 ≥ 20
x3 ≤ 5
x5 ≤ 8

You might also like