Network Flow Problems
Network Flow Problems
Linear Optimization
Based on the book Introduction to Linear Optimization by D. Bertsimas and J.N. Tsitsiklis
Outline
N = {1, 2, 3, 4, 5},
E = {{1, 2}, {1, 3}, {2, 3}, {1, 4}, {3, 4}, {3, 5}}.
Undirected graphs
i1 , i2 , . . . , it
N = {1, 2, 3, 4, 5},
A = {(1, 2), (2, 1), (1, 3), (3, 2), (1, 4), (4, 3), (3, 5)}.
Directed graphs
▶ For any arc (i, j), we say that i is the tail and j is the head.
▶ The arc (i, j) is said to be leaving from node i, entering to
node j, and incident to both i and j.
Directed graphs
i1 , i2 , . . . , it ,
Theorem 7.1
(a) Every tree with more than one node has at least one
leaf.
Proof idea:
▶ Assume by contradiction that there is no leaf. Then every
node has degree at least 2.
1bc
Trees
Theorem 7.1
(a) Every tree with more than one node has at least one
leaf.
Proof idea:
▶ Assume by contradiction that there is no leaf. Then every
node has degree at least 2.
1bc 2bc
Trees
Theorem 7.1
(a) Every tree with more than one node has at least one
leaf.
Proof idea:
▶ Assume by contradiction that there is no leaf. Then every
node has degree at least 2.
Theorem 7.1
(a) Every tree with more than one node has at least one
leaf.
Proof idea:
▶ Assume by contradiction that there is no leaf. Then every
node has degree at least 2.
Theorem 7.1
(a) Every tree with more than one node has at least one
leaf.
Proof idea:
▶ Assume by contradiction that there is no leaf. Then every
node has degree at least 2.
Theorem 7.1
(b) An undirected graph is a tree if and only if it is
connected and has |N | − 1 edges.
Theorem 7.1
(b) An undirected graph is a tree if and only if it is
connected and has |N | − 1 edges.
Theorem 7.1
(b) An undirected graph is a tree if and only if it is
connected and has |N | − 1 edges.
tree jbc
Trees
Theorem 7.1
(b) An undirected graph is a tree if and only if it is
connected and has |N | − 1 edges.
|N | − 2 edges jbc
Trees
Theorem 7.1
(b) An undirected graph is a tree if and only if it is
connected and has |N | − 1 edges.
Theorem 7.1
(b) An undirected graph is a tree if and only if it is
connected and has |N | − 1 edges.
5bc
2bc
8bc
7bc
Trees
Theorem 7.1
(b) An undirected graph is a tree if and only if it is
connected and has |N | − 1 edges.
5bc
2bc
8bc
7bc
Trees
Theorem 7.1
(b) An undirected graph is a tree if and only if it is
connected and has |N | − 1 edges.
5bc
2bc
8bc
7bc
Trees
Theorem 7.1
(b) An undirected graph is a tree if and only if it is
connected and has |N | − 1 edges.
5bc
2bc
8bc
7bc
Trees
Theorem 7.1
(b) An undirected graph is a tree if and only if it is
connected and has |N | − 1 edges.
5bc
2bc
8bc
7bc
Trees
Theorem 7.1
(b) An undirected graph is a tree if and only if it is
connected and has |N | − 1 edges.
5bc
2bc
8bc
7bc
Trees
Theorem 7.1
(b) An undirected graph is a tree if and only if it is
connected and has |N | − 1 edges.
5bc
2bc
8bc
7bc
Trees
Theorem 7.1
(b) An undirected graph is a tree if and only if it is
connected and has |N | − 1 edges.
5bc
2bc
8bc
7bc
Trees
Theorem 7.1
(b) An undirected graph is a tree if and only if it is
connected and has |N | − 1 edges.
5bc
2bc
8bc
7bc
Trees
Theorem 7.1
(b) An undirected graph is a tree if and only if it is
connected and has |N | − 1 edges.
5bc
2bc
8bc
7bc
Trees
Theorem 7.1
(b) An undirected graph is a tree if and only if it is
connected and has |N | − 1 edges.
5bc
2bc
8bc
7bc
Trees
Theorem 7.1
(c) For any two distinct nodes i and j in a tree, there exists
a unique path from i to j.
Proof idea:
▶ By contradiction.
bc bc
ibc bc jbc
Trees
Theorem 7.1
(c) For any two distinct nodes i and j in a tree, there exists
a unique path from i to j.
Proof idea:
▶ By contradiction.
bc bc
ibc bc jbc
bc bc
Trees
Theorem 7.1
(c) For any two distinct nodes i and j in a tree, there exists
a unique path from i to j.
Proof idea:
▶ By contradiction.
bc bc
bc jbc
bc bc
Trees
Theorem 7.1
(d) If we start with a tree and add a new edge, the
resulting graph contains exactly one cycle.
Proof idea:
▶ Add an edge to a tree and use part (c).
1bc 4bc
6bc
3bc
5bc
2bc
8bc
7bc
Trees
Theorem 7.1
(d) If we start with a tree and add a new edge, the
resulting graph contains exactly one cycle.
Proof idea:
▶ Add an edge to a tree and use part (c).
1bc 4bc
6bc
3bc
5bc
2bc
8bc
7bc
7.2 Formulation of the network flow problem
Formulation of the network flow problem
cij ∈ R ∀(i, j) ∈ A.
Formulation of the network flow problem
▶ This means that the total flow from the outside into the
network (at the sources) must be equal to the total flow
from the network to the outside (at the sinks).
Formulation of the network flow problem
▶ We impose the following conditions on the flow variables fij ,
(i, j) ∈ A:
∑ ∑
bi + fji = fij ∀i ∈ N (i)
j∈δ in (i) j∈δ out (i)
▶ Ordering of arcs: (1, 2), (2, 1), (3, 2), (4, 3), (1, 4), (1, 3), (3, 5).
▶ The corresponding node-arc incidence matrix is
Af = 0,
is called a circulation.
▶ Intuitively, we have flow conservation within the network and
zero external supply or demand, which means that the flow
“circulates” inside the network.
Circulations
c′ (f + θhC ) − c′ f = c′ f + c′ (θhC ) − c′ f = θ · c′ hC .
7.3 The network simplex algorithm
The network simplex algorithm
▶ In this section, we develop the details of the simplex method,
as applied to the uncapacitated network flow problem
minimize c′ f
subject to Af = b
f ≥ 0,
minimize c′ f
subject to Af = b
f≥0
Assumption 7.1
∑
(a) We have i∈N bi = 0.
(b) The graph G is connected.
Af = b
by the constraint
Ãf = b̃.
▶ We will see shortly that under Assumption 7.1, the matrix Ã
has linearly independent rows.
Example 7.2
▶ Consider the node-arc incidence matrix A in Example 7.1.
Definition 7.1
A flow vector f is called a tree solution if it can be constructed
by the following procedure.
(a) Pick a set T ⊂ A of n − 1 arcs that form a tree when
their direction is ignored.
(b) Let fij = 0 for every (i, j) ∈
/ T.
(c) Use the flow conservation equation Ãf = b̃ to determine
the flow variables fij , for (i, j) ∈ T.
A tree solution that also satisfies f ≥ 0, is called a feasible tree
solution.
Trees and basic feasible solutions
Step (c) in the above definition can be carried out using the
following systematic procedure.
(a) Call node n the root of the tree.
(b) Use the flow conservation equations to determine the flows on
the arcs incident to the leaves, and continue by proceeding
from the leaves towards the root.
Note that the existence of leaves follows from Theorem 7.1 (a).
Trees and basic feasible solutions
Corollary 7.1
If the graph G is connected, then the matrix à has linearly
independent rows.
Trees and basic feasible solutions
▶ With our construction of a tree solution, the columns of B are
the columns of à corresponding to the variables fij , for
(i, j) ∈ T, and are linearly independent.
▶ In general LP terminology, B is a basis matrix.
▶ Since the remaining variables fij , (i, j) ∈
/ T, are set to zero, the
resulting flow vector f is the basic solution corresponding to
this basis.
▶ Thus, a tree solution is a basic solution.
▶ And a feasible tree solution is a basic feasible solution.
Trees and basic feasible solutions
▶ With our construction of a tree solution, the columns of B are
the columns of à corresponding to the variables fij , for
(i, j) ∈ T, and are linearly independent.
▶ In general LP terminology, B is a basis matrix.
▶ Since the remaining variables fij , (i, j) ∈
/ T, are set to zero, the
resulting flow vector f is the basic solution corresponding to
this basis.
▶ Thus, a tree solution is a basic solution.
▶ And a feasible tree solution is a basic feasible solution.
▶ In fact, the converse is also true.
Theorem 7.4
A flow vector is a basic solution if and only if it is a tree
solution.
Proof idea:
▶ Select a cycle of G and 1bc
remove from it an edge not
in E 0 .
▶ Repeat. 5bc 2bc
6bc
4bc 3bc
Spanning trees
Theorem 7.2
Let G = (N , E) be a connected undirected graph and let E 0
be some subset of the set E of edges. Suppose that the
edges in E 0 do not form any cycles. Then, the set E 0 can
be augmented to a set E1 ⊇ E 0 so that (N , E1 ) is a
spanning tree.
Proof idea:
▶ Select a cycle of G and 1bc
remove from it an edge not
in E 0 .
▶ Repeat. 5bc 2bc
6bc
4bc 3bc
Spanning trees
Theorem 7.2
Let G = (N , E) be a connected undirected graph and let E 0
be some subset of the set E of edges. Suppose that the
edges in E 0 do not form any cycles. Then, the set E 0 can
be augmented to a set E1 ⊇ E 0 so that (N , E1 ) is a
spanning tree.
Proof idea:
▶ Select a cycle of G and 1bc
remove from it an edge not
in E 0 .
▶ Repeat. 5bc 2bc
6bc
4bc 3bc
Spanning trees
Theorem 7.2
Let G = (N , E) be a connected undirected graph and let E 0
be some subset of the set E of edges. Suppose that the
edges in E 0 do not form any cycles. Then, the set E 0 can
be augmented to a set E1 ⊇ E 0 so that (N , E1 ) is a
spanning tree.
Proof idea:
▶ Select a cycle of G and 1bc
remove from it an edge not
in E 0 .
▶ Repeat. 5bc 2bc
6bc
4bc 3bc
Spanning trees
Theorem 7.2
Let G = (N , E) be a connected undirected graph and let E 0
be some subset of the set E of edges. Suppose that the
edges in E 0 do not form any cycles. Then, the set E 0 can
be augmented to a set E1 ⊇ E 0 so that (N , E1 ) is a
spanning tree.
Proof idea:
▶ Select a cycle of G and 1bc
remove from it an edge not
in E 0 .
▶ Repeat. 5bc 2bc
6bc
4bc 3bc
Spanning trees
Theorem 7.2
Let G = (N , E) be a connected undirected graph and let E 0
be some subset of the set E of edges. Suppose that the
edges in E 0 do not form any cycles. Then, the set E 0 can
be augmented to a set E1 ⊇ E 0 so that (N , E1 ) is a
spanning tree.
Proof idea:
▶ Select a cycle of G and 1bc
remove from it an edge not
in E 0 .
▶ Repeat. 5bc 2bc
6bc
4bc 3bc
Spanning trees
Theorem 7.2
Let G = (N , E) be a connected undirected graph and let E 0
be some subset of the set E of edges. Suppose that the
edges in E 0 do not form any cycles. Then, the set E 0 can
be augmented to a set E1 ⊇ E 0 so that (N , E1 ) is a
spanning tree.
Proof idea:
▶ Select a cycle of G and 1bc
remove from it an edge not
in E 0 .
▶ Repeat. 5bc 2bc
6bc
4bc 3bc
Spanning trees
Theorem 7.2
Let G = (N , E) be a connected undirected graph and let E 0
be some subset of the set E of edges. Suppose that the
edges in E 0 do not form any cycles. Then, the set E 0 can
be augmented to a set E1 ⊇ E 0 so that (N , E1 ) is a
spanning tree.
Proof idea:
▶ Select a cycle of G and 1bc
remove from it an edge not
in E 0 .
▶ Repeat. 5bc 2bc
6bc
4bc 3bc
Spanning trees
Theorem 7.2
Let G = (N , E) be a connected undirected graph and let E 0
be some subset of the set E of edges. Suppose that the
edges in E 0 do not form any cycles. Then, the set E 0 can
be augmented to a set E1 ⊇ E 0 so that (N , E1 ) is a
spanning tree.
Proof idea:
▶ Select a cycle of G and 1bc
remove from it an edge not
in E 0 .
▶ Repeat. 5bc 2bc
6bc
4bc 3bc
Spanning trees
Theorem 7.2
Let G = (N , E) be a connected undirected graph and let E 0
be some subset of the set E of edges. Suppose that the
edges in E 0 do not form any cycles. Then, the set E 0 can
be augmented to a set E1 ⊇ E 0 so that (N , E1 ) is a
spanning tree.
Proof idea:
▶ Select a cycle of G and 1bc
remove from it an edge not
in E 0 .
▶ Repeat. 5bc 2bc
6bc
4bc 3bc
Spanning trees
Theorem 7.2
Let G = (N , E) be a connected undirected graph and let E 0
be some subset of the set E of edges. Suppose that the
edges in E 0 do not form any cycles. Then, the set E 0 can
be augmented to a set E1 ⊇ E 0 so that (N , E1 ) is a
spanning tree.
Proof idea:
▶ Select a cycle of G and 1bc
remove from it an edge not
in E 0 .
▶ Repeat. 5bc 2bc
6bc
4bc 3bc
Spanning trees
Theorem 7.2
Let G = (N , E) be a connected undirected graph and let E 0
be some subset of the set E of edges. Suppose that the
edges in E 0 do not form any cycles. Then, the set E 0 can
be augmented to a set E1 ⊇ E 0 so that (N , E1 ) is a
spanning tree.
Proof idea:
▶ Select a cycle of G and 1bc
remove from it an edge not
in E 0 .
▶ Repeat. 5bc 2bc
6bc
4bc 3bc
Now let’s prove Theorem 7.4!
Trees and basic feasible solutions
Example:
▶ The tree in the figure leads to a
degenerate basic feasible solution,
because f67 = 0.
▶ A different tree that would yield
the same basic feasible solution is
obtained by replacing arc (6, 7) by
arc (5, 7).
Change of basis
Change of basis
0 3
ibc
3
Change of basis
3
Change of basis
f̂ = f + θhC .
fkℓ + θ if (k, ℓ) ∈ F
f̂kℓ = fkℓ − θ if (k, ℓ) ∈ B
fkℓ otherwise.
▶ We set θ as large as possible, provided that all arc flows
remain nonnegative.
▶ If B is empty, we let θ∗ = ∞.
▶ Otherwise, the largest possible value of θ is equal to
θ∗ = min fkℓ .
(k,ℓ)∈B
5 2
5−θ
jbc kbc
▶ In this example we set θ = 3.
θ+0 3−θ
ibc
3
Change of basis
5 2
5−3
jbc kbc
▶ In this example we set θ = 3.
3+0 3−3
ibc
3
Change of basis
5 2
2
jbc kbc
▶ In this example we set θ = 3.
▶ The variable fik exits the basis. 3 0
ibc
3
Change of basis
Change of basis
▶ Since we are minimizing the cost of the flow, the variable fij
should enter the basis only if the value of the expression (*)
is negative.
▶ From the development of the simplex method, we know
that if the variable that enters the basis takes the value θ∗ ,
then the cost changes by
p′ = c′B B−1 .
c̄′ = c′ − p′ Ã.
c̄′ = c′ − p′ Ã.
▶ We conclude that
cij − (pi − pj ) if i, j ̸= n
c̄ij = cij − pi if j = n
cij + pj if i = n.
pi − pj = cij ∀(i, j) ∈ T
pn = 0.
Calculation of the cost change
pi − pj = cij ∀(i, j) ∈ T
pn = 0.
▶ This system of equations is easily solved using the following
procedure.
pi − pj = cij ∀(i, j) ∈ T
pn = 0.
▶ This system of equations is easily solved using the following
procedure.
b1 > 0 bc
1
4bc b4 < 0
b2 > 0 bc
2
5bc b5 < 0
b3 > 0 bc
3
b1 > 0 bc
1
4bc b4 < 0
b2 > 0 bc
2
5bc b5 < 0
b3 > 0 bc
3
▶ We set the costs cij of the auxiliary arcs to 1 and the costs
of the original arcs to 0.
▶ Then, the optimal solution of the auxiliary problem yields a
basic feasible solution of the original problem.
Overview of the algorithm
▶ In the case where an initial basic feasible solution is not
available, we need to form and solve an auxiliary problem.
b1 > 0 bc
1
4bc b4 < 0
b2 > 0 bc
2
5bc b5 < 0
b3 > 0 bc
3
Theorem 7.5
Consider an uncapacitated network flow problem and assume
that the underlying graph is connected.
(a) For every basis matrix B, the matrix B−1 has integer
entries.
(b) If the supplies bi are integer, then every basic solution has
integer coordinates.
(c) If the cost coefficients cij are integer, then every dual
basic solution has integer coordinates.
Theorem 7.5
Consider an uncapacitated network flow problem and
assume that the underlying graph is connected.
(a) For every basis matrix B, the matrix B−1 has integer
entries.
Proof:
▶ As shown in the proof of Theorem 7.3, we can reorder the
rows and columns of a basis matrix B so that it becomes
lower triangular and its diagonal entries are either 1 or −1.
▶ Therefore, the determinant of B is equal to 1 or −1.
▶ By Cramer’s rule, B−1 has integer entries.
Integrality of optimal solutions
Theorem 7.5
Consider an uncapacitated network flow problem and
assume that the underlying graph is connected.
(b) If the supplies bi are integer, then every basic solution
has integer coordinates.
Proof:
▶ This follows from the formula fT = B−1 b̃.
Integrality of optimal solutions
Theorem 7.5
Consider an uncapacitated network flow problem and
assume that the underlying graph is connected.
(b) If the supplies bi are integer, then every basic solution
has integer coordinates.
Proof:
▶ This follows from the formula fT = B−1 b̃.
▶ It can also be seen by inspecting the algorithm that
determines the values of the basic variables.
Integrality of optimal solutions
Theorem 7.5
Consider an uncapacitated network flow problem and
assume that the underlying graph is connected.
(c) If the cost coefficients cij are integer, then every dual
basic solution has integer coordinates.
Proof:
▶ This follows from the formula p′ = c′B B−1 .
Integrality of optimal solutions
Theorem 7.5
Consider an uncapacitated network flow problem and
assume that the underlying graph is connected.
(c) If the cost coefficients cij are integer, then every dual
basic solution has integer coordinates.
Proof:
▶ This follows from the formula p′ = c′B B−1 .
▶ It can also be seen by inspecting the algorithm that
determines the values of the dual variables.
Integrality of optimal solutions
Corollary 7.2
Consider an uncapacitated network flow problem, and assume
that the optimal cost is finite.
(a) If all supplies bi are integer, there exists an integer
optimal flow vector.
(b) If all cost coefficients cij are integer, there exists an
integer optimal solution to the dual problem.
Special cases of the network flow problem
The maximum flow problem
▶ In the maximum flow problem, we wish to determine the
largest possible amount of flow that can be sent:
▶ from a given source node s to a given sink node t,
▶ without exceeding the arc capacities uij .
The maximum flow problem
▶ In the maximum flow problem, we wish to determine the
largest possible amount of flow that can be sent:
▶ from a given source node s to a given sink node t,
▶ without exceeding the arc capacities uij .
Idea:
▶ Supply 1 in the origin, -1 in the destination, 0 otherwise.
▶ Costs as given.
▶ Capacities are infinity.
The transportation problem
1bc bc
1 The assignment problem is a special
case of the transportation problem,
where:
2bc bc
2
▶ the number of suppliers is equal to
the number of consumers,
▶ each supplier has unit supply, and
3bc bc
3
▶ each consumer has unit demand.
The assignment problem
2bc bc
2
will be a unique and distinct j for
which fij = 1, and we can say that
the ith supplier is assigned to the
jth consumer.
3bc bc
3 ▶ This justifies the name of this
problem.