Chapter 4
Chapter 4
Integer programs
Once again, consider the resource constraint problem we modelled in chapter 2. In this problem,
the goal was to determine the optimal number of fractional barrels produced of each type of oil,
given limited quantities of the input crude oils. However, it isn’t practical to produce a fractional
barrel of oil, since customers come to expect full barrels of oil. Integer programming allows us
to incorporate the constraint that any feasible solution can only produce an integer number of
barrels of each oil type. In this section, we will review integer programming formulations and
some modelling tricks that can be achieved with integer programs. Furthermore, we will discuss
solving integer programs and some properties that make the solving process much easier.
An integer program is obtained from a linear program by adding the condition that a nonempty
subset of variables must take on integer values. When all variables are restricted to take integer
values, we call the corresponding program a pure integer program. Otherwise, it is called a mixed
integer program.
IP Formulation
Naturally, this problem can be modelled as an integer program.
39
40 CHAPTER 4. INTEGER PROGRAMS
Variables. As stated in the question, we need to decide the number of employees of each type
to hire. Therefore, for each employee type j 2 J, we need an integer variable xj to denote the
number of employees of type j hired.
Constraints. For each task i 2 I, we need to hire at least bi employees. Thus, we have the
system of constraints X
xj bi 8 i 2 I.
j2J:
i2Sj
Objective. The goal is to minimize the cost of hiring the employees, which is given by
X
c j xj .
j2J
Formulation. With the addition of non-negativity constraints we obtain the following integer
program.
X
min c j xj (4.1)
j2J
X
s.t. xj bi 8i2I
j2J:
i2Sj
xj 0 8j2J
xj 2 Z 8 j 2 J
In an assignment problem, we use binary variables to indicate choices. We will illustrate the
use of binary variables in assigning numbers to empty squares on a Sudoku puzzle. In an n ⇥ n
p p p
Sudoku puzzle, where n must be an integer, the grid is partitioned into n ⇥ n blocks. Given
a set of numbers already placed on the grid, the goal is to fill the remainder of the board with
numbers 1 to n such that each row, column, and block contains each number from 1 to n. For
ease of notation, we introduce [n] to indicate the set {1, 2, ..., n}. See figure 4.1 for an example
of a 4 ⇥ 4 Sudoku puzzle.
1
4
2
3 1
and • indicates that the square ij is currently blank. How can we write an IP to fill in missing
numbers?
Variables. What are we deciding? For each cell ij where i 2 [n] and j 2 [n], we would like
to know which value from 1 to n is chosen for that cell. We will use binary variables xijk for all
i, j, k 2 [n] where xijk = 1 if value k is placed in cell i, j and xijk = 0 otherwise.
Constraints. First, we cannot change the numbers already place on the grid. Thus we have
the constraint
xijk = 1 8 i, j, k 2 [n] : Gij = k.
In row i, we only want one of each value. So, for all i 2 [n] and k 2 [n] , k must occur precisely
once in row i. Let Ri denote all positions in row i. That is, Ri = {(i, j) : j 2 [n]}. Then we have
the set of row constraints,
X
xijk = 1 8 i, k 2 [n].
(i,j)2Ri
Similarly, we want each value to occur precisely once in each column j. Let Cj = {(i, j) : i 2 [n]}.
Then we have the set of column constraints,
X
xijk = 1 8 j, k 2 [n].
(i,j)2Cj
Finally, we need a set of constraints for the blocks. Define S to be a set of blocks, where
each block is represented by the set of cells in that block. i.e. for a 4 ⇥ 4 puzzle, S =
{{(1, 1), (1, 2), (2, 1), (2, 2)}, ...}. Then we have the set of block constraints,
X
xijk = 1 8 S 2 S, 8 k 2 [n].
(i,j)2S
Integer program. Since we desire any feasible solution, we set the objective function to be
max 0, and obtain the following integer program.
max 0 (4.2)
X
s.t. xijk = 1 8 i, k 2 [n]
(i,j)2Ri
X
xijk = 1 8 j, k 2 [n]
(i,j)2Cj
X
xijk = 1 8 S 2 S, k 2 [n]
(i,j)2S
y1 + y2 + . . . + ym = 1, and
yi 2 {0, 1} 8 i 2 {1, 2, . . . , m}
We would like to enforce that if the ith item is chosen, then x is equal to ai . Writing
x = a 1 y1 + a 2 y2 + . . . + a m y m
achieves this result, since precisely one y-variable will be 1, and so all other terms in the sum are
equal to zero.
fi+1 f
fi
a1 ai ai+1 ak
Since the points (ai , fi ) for 1 i k are chosen as the set of breakpoints from a to b, we have
that if (x, f (x)) is a point with x 2 [ai , ai+1 ], then it can be expressed as a convex combination
4.2. MODELLING TRICKS 43
How can we write an integer program that maximizes f (x) given x 2 [a, b], such that the
feasible values of x and y in the program are precisely the set of all points (x, f (x)) where
x 2 [a, b]?
Variables. Notice that between any two breakpoints, the function f is linear and it is not too
hard to express the set of feasible points in the interval. Thus, we would like to have a binary
variable zi for each interval [ai , ai+1 ], where zi = 1 indicates that x is in the ith interval. We also
introduce variables si and ei for each interval i so that x = si ai + ei ai+1 for some si and ei if
and only if x is in [ai , ai+1 ]. We can think of si and ei as measurements of where x lies relative
to the start and end of the interval.
Constraints. Similar to in section 4.2.1, we are choosing one interval out of k 1 options, so
we require the constraints:
z1 + z2 + . . . + zk 1 = 1, and
zi 2 {0, 1} 8 i 2 {1, 2, . . . , k 1}.
Since the function is only linear between breakpoints, we also require that si and ei are positive
only if x is in the ith interval. Furthermore, we need si ai + ei ai+1 to describe precisely the
interval [ai , ai+1 ]. This is accomplished by
s e
i + i = zi 8 i 2 [k 1], and
s e
i, i 0 8 i 2 [k 1].
Finally, we have
k 1
X k 1
X
s e
x= i ai + i ai+1 .
i=1 i=1
Since only one pair of s and e will be positive, x is a point in the interval [ai , ai+1 ].
i i
Objective. The value of f (x) is completely determined by the positive values of s and e,
i i
and therefore we have the objective function
k 1
X k 1
X
s e
i fi + i fi+1 .
i=1 i=1
44 CHAPTER 4. INTEGER PROGRAMS
Integer program.
k 1
X k 1
X
s e
max i fi + i fi+1 (4.4)
i=1 i=1
k 1
X k 1
X
s e
s.t. x = i ai + i ai+1
i=1 i=1
z 1 + z2 + . . . + z k 1 =1
zi 2 {0, 1} 8 i 2 {1, 2, . . . , k 1}
s e
i + i = zi 8 i 2 [k 1]
s e
i, i 0 8 i 2 [k 1]
However, it is possible to express (4.6) as an integer program. We will demonstrate this property
for the case where 0 x u. This process is not quite as straightforward as the intersection
case and we will need to introduce additional variables. In this case, we are choosing from a set
of two items, where the items are P1 and P2 . Let y1 and y2 be binary variables satisfying
y1 + y2 = 1, and
y1 , y2 2 {0, 1}.
Similar to in section 4.2.1, we would like yi = 1 to imply that x 2 Pi . Note that this does not
prevent x from being in both P1 and P2 , but at all times only a single y-variable will be equal to
1. Since x is in at least one of P1 and P2 , it is equal to some vector x1 in P1 or some vector x2
in P2 .
Integer program. Continuing with this logic, we claim that (4.6), with the additional con-
straint that 0 x u is equivalent to the following integer program.
Proof. To prove the two programs are equivalent, it suffices to show that the feasible regions are
the same. Firstly, suppose x̄, x̄1 , x̄2 , ȳ1 , and ȳ2 is a feasible solution to (4.8). We must show that
x̄ is a feasible solution to (4.6). We may assume that ȳ1 = 1 and ȳ2 = 0 due to constraints (4.9)
and (4.10). Since ȳ2 = 0, constraint (4.15) implies that x̄2 = 0, and so x̄ = x̄1 . Since x̄1 satisfies
constraint (4.12), x̄1 = x̄ is in P1 . Therefore x̄ is a solution to (4.6).
Conversely, suppose x̄ 2 P1 [P2 and 0 x̄ u. We would like to construct a solution to (4.8)
with x̄ given. We may assume that x̄ 2 P1 and so we assign ȳ1 = 1 and ȳ2 = 0, which satisfies
constraints (4.9) and (4.10). Letting x̄1 = x̄ and x̄2 = 0 clearly satisfies constraints (4.11), (4.14),
and (4.15). Observe that A2 x̄2 = 0 = 0b2 = y2 b2 , and so (4.13) is satisfied. Finally, (4.12) is
satisfied since A1 x̄1 = A1 x̄ b1 = y1 b1 , where the inequality holds since we assumed that x̄ was
in P1 .
the integrality constraints of (IP), then the optimal value of (IP) and the optimal value of its
linear relaxation are equal.
An integer program admits a perfect formulation if all of the basic feasible solutions to the
linear relaxation satisfy the integrality constraints of the integer program. For an alternative
definition of perfect formulation, see section 5.7. By our previous argument, if an integer program
admits a perfect formulation, then we can solve the linear relaxation to find an optimal solution
to (IP) and bypass the challenge of solving an integer program. In this section, we will look at
how to identify if an integer program admits a perfect formulation, and we will see that various
nice classes of problems have perfect formulations.
A linear program is written in standard equality form (SEF) if it is of the form
max c> x (4.16)
s.t. Ax = b
x 0.
We may assume that the matrix A has full row rank, or equivalently, A has linearly independent
rows. In this section, when we would like to solve an integer program, we will assume the linear
relaxation is expressed in standard equality form. Recall from CO 250 [6] that if (4.16) has
an optimal solution, then it has an optimal basic solution, which we can find by applying the
Simplex method.
First, we introduce some notation. Consider a matrix A 2 Rm⇥n , a vector b 2 Rm , and the
system Ax = b. We define A j b as the matrix obtained by replacing the jth column of A by
the vector b.
Example 4.3
3 4 1 1 4
If A = ,b = , then A 1 b= .
1 1 2 2 1
Proposition 4.1. Let M be a square matrix with all integer entries. If det(M ) 2 {±1} and b is
an integer vector, then any solution x̄ to the system M x = b is integer.
Proof. The proof follows directly from Cramer’s rule since M is non-singular if det(M ) 2 {±1}.
Therefore, if x̄ is a solution to M x = b, then we can find each entry using equation (4.17).
Futhermore, the denominator of (4.17) will be -1 or 1, and the numerator will be an integer since
all entries of M and b are integer. Thus, x̄j is integer for each entry j.
Example 4.5
Which of the following matrices is TU?
2 3
2 3 2 3 2 3 1 0 1 0
1 1 0 1 1 1 0 1 60 1 0 17
A=4 1 0 25 , B = 4 1 1 5 , C = 4 0 1 0 5 , and D = 6
41
7.
1 0 15
1 1 1 0 1 1 0 1
0 0 1 0
2. Matrix B is not TU, because the square submatrix obtained by removing the third row has
determinant equal to 2.
3. Matrix C is not TU, because the square submatrix obtained by removing the second row
and second column has determinant equal to -2.
4. Matrix D is TU. Observe that there is at most one +1 and one -1 in each column. The
significance of this property will be discussed in section 4.3.2.
Proposition 4.2. Consider Ax = b where A is TU and b is integer. Then every basic solution
is integer.
If a linear program in SEF has an optimal solution, then it has an optimal basic solution.
Thus, we obtain the following corollary of proposition 4.2.
48 CHAPTER 4. INTEGER PROGRAMS
max c> x
s.t. Ax = b
x 0.
Suppose A is TU and b is integer. Then if (P) has an optimal feasible solution it has an integer
one.
Thus, if an integer program has a linear relaxation that satisfies Corollary 4.1, then the integer
program can be solved by solving the linear relaxation. One thing to note is that Corollary 4.1
is not an if and only if statement. In fact, we only need that AB has determinant 1 or -1 to get
an integer basic feasible solution.
While Corollary 4.1 is mathematically interesting, it is only useful if we can find optimization
problems that have an associated TU matrix. We will show that there are actually a large number
of problems with this property. But first, we need to be able to recognize TU matrices when we
encounter them out in the wild.
Proposition 4.3. If A is a {±1, 0}-matrix with at most one +1 and at most one -1 in each
column, then it is totally unimodular.
Proof. What do we need to show? We need to show that for any k ⇥k submatrix M of A, det(M )
2 {0, ±1}. We will proceed by induction on k. For k = 1, M is a single entry, which must be 0
or ±1, and so det(M ) 2 {0, ±1}.
Suppose the claim holds for some k 1 and consider k + 1. If there are no (k + 1) ⇥ (k + 1)
square submatrices, then the property trivially holds, so suppose such a submatrix M exists. We
consider three cases:
If M has a column of zeros, then it has determinant zero. Similarly, if M has exactly one
+1 and one -1 in each column, then the sum of the rows is the zero vector, meaning that the
rows are linearly dependent and the determinant is zero. Thus, we may assume that M has a
column with exactly one non-zero entry, Mij . Then by applying cofactor expansion, det(M ) =
Mij ( 1)i+j det(Mij0 ) where Mij0 is the square submatrix of M obtained by deleting row i and
column j. By induction, det(Mij0 ) is 0, +1, or -1, and so det(M ) must also be 0, +1, or -1.
4.3. PERFECT FORMULATIONS 49
There are also a few nice methods to obtain additional TU matrices. Let A1 2 Rm⇥n and
A2 2 Rm⇥s . We define A1 |A2 to be the matrix obtained by concatenating A1 and A2 , i.e. listing
the columns of A1 and then the columns of A2 in one matrix. In the following proposition, I
denotes the identity matrix of the appropriate size.
Proposition 4.4. Let A be a TU matrix. Then the following matrices are also TU:
1. A|I;
2. A> ;
3. any submatrix M of A;
4. A|A.
We leave the proof of Proposition 4.4 as an exercise. Notice that in the proposition A is an
arbitrary TU matrix and we cannot assume it satisfies the properties of proposition 4.3.
Example 4.6
Consider the matrix 2 3
1 1 0
A= 4 1 0 05 .
0 1 1
Since A has at most one +1 and at most one -1 in each column, it is TU by Proposition 4.3. By
proposition 4.4, the following matrices are all TU:
2 3 2 3
1 1 0 1 0 0 1 1 0
4 5 > 4 5 1 1
A|I = 1 0 0 0 1 0 ,A = 1 0 1 , and M = .
0 1
0 1 1 0 0 1 0 0 1
It is useful to consider why we might want matrix types (1) (4) to be TU if A is TU. Suppose
we are given a formulation with a TU matrix, but it is not yet in SEF. Since A|I is also TU, this
implies that even if we add slack variables, the resulting problem in SEF will have a TU matrix.
Proposition 4.5. Consider the following LP:
max c> x (4.18)
s.t. Ax = b
0 x u.
Suppose A is TU, and b and u are integer vectors. If (4.18) has an optimal solution then there
exists an optimal integer solution.
Proof. Notice that Proposition 4.5 is almost identical to Corollary 4.1, except the variables x
have an upper bound given by u. That is, the given LP is not in standard equality form. In
order to apply Corollary 4.1, we add slack variables s and obtain the following LP:
max c> x (4.19)
✓ ◆✓ ◆ ✓ ◆
A 0 x b
s.t. =
I I s u
✓ ◆
x
0.
s
50 CHAPTER 4. INTEGER PROGRAMS
By
✓ ◆applying Proposition 4.4, it is not hard to show that the resulting matrix is TU. The vector
b
is also integer and therefore by Corollary 4.1, if (4.19) has an optimal solution, then it has
u
an optimal solution that is integral.
Example 4.7
For the directed graph given in figure 4.4, M is the following matrix.
v2111111
e1 11 e5 11
e1 e2 e3 e4 e5 e6 11111 11111
0 0 1 e4
v1 1 1 0 0 0 v11111111
e3 11
11
v4
1111111
v B 1 0 1 1 1 0 C
11111
11111
M = 2@ A
v3 0 1 1 1 0 1 e2 11 e6 11
11111 11111
v4 0 0 0 0 1 1
v3
It is important to notice that the matrix M is TU. In fact, it is not hard to see that the vertex-
arc incidence matrix of a digraph is always totally unimodular. This observation motivates the
proof of the min cost flow integrality theorem, which we restate here for convenience.
4.3. PERFECT FORMULATIONS 51
Proof.
P Consider theP net flow condition for a vertex v. The constraint fx (v) = bv can be expressed
as e2 + (v) xe e2 (v) xe = bv . In this expanded form, we see that fx (v) is equal to Mv x,
where Mv is the row vector corresponding to vertex v of vertex-arc incidence matrix. Therefore,
the min-cost flow LP can be rewritten in terms of M as follows:
Suppose u and b are integer and there exists an optimal solution to (4.21). Since M is totally
unimodular and b and u are integer, by proposition 4.5 there is an optimal solution that is
integer.
Example 4.8
From example 4.6, we know that the following matrix A is totally unimodular.
2 3
1 1 0
A = 41 0 15
0 0 1
In fact, it admits an equitable 2-colouring with R1 = {1} and R2 = {2, 3}. Notice that this was
the only possible split (up to relabeling R1 and R2 ). The first column indicates that rows 1 and
2 cannot both be in the same set. Similarly, column 3 indicates that rows 2 and 3 must be in
the same set.
We can now state a characterization of TU matrices. In the following theorem, R is a set of
row indices and rowR (A) denotes the submatrix of A induced by the row indices in R.
Example 4.9
Continuing with the matrix A from example 4.8, we would like to show that A is TU using
Theorem 4.3. That is, for any R ✓ [m], we must be able to find an equitable 2-colouring of
rowR (A).
If |R| = 1, then we trivially have an equitable 2-colouring with R1 = R and R2 = ;, since all
entries are ±1 and 0. If |R| = 2, then we have the following three cases: R = {1, 2}, R = {2, 3},
and R = {1, 3}. An equitable 2-colouring for each case is given below.
1 1 0 1 0 1 1 1 0
row{1,2} (A) = row{2,3} (A) = row{1,3} (A) =
1 0 1 0 0 1 0 0 1
Finally, we need to show that there is an equitable 2-colouring when R = {1, 2, 3}. This case
was completed in example 8. Therefore by Theorem 4.3, A is TU.
In this course, we will prove the “if” direction of the Ghouila-Houri Theorem. That is, we will
prove that given an m ⇥ n matrix A, if rowR (A) admits an equitable 2-colouring for all R ✓ [m],
then A is TU.
Proof. Suppose rowR (A) has an equitable 2-colouring for all R ✓ [m]. Let B be a k ⇥k submatrix
of A and we will prove that det(B) 2 {±1, 0} by induction on k. We may assume that B is non-
singular, as otherwise the determinant is zero and we are done. Suppose k = 1. Since there is an
equitable 2-colouring when |R| = 1, each entry of A must be 0, +1, or -1.
Now consider k > 1 and suppose the hypothesis holds for all k 0 < k. We would like to find
the determinant of B and we currently have some information on the entries of B. Recall that
Cramer’s rule relates solution indices to determinants. If we want to solve for B 1 such that
BB 1 = I, we can solve for a single column of B 1 , say j at a time: BBj 1 = ej . By Cramer’s
rule since B is non-singular,
det (B i ej )
Bij 1 = . (4.22)
det(B)
Let B̄ be the matrix obtained by deleting the ith column and jth row of B i ej . B̄ is a
smaller square submatrix of A, so by induction det(B̄) 2 {±1, 0}. By applying cofactor expansion
along column i we see that det(B i ej ) 2 {±1, 0}.
Let B ⇤ be the matrix obtained by scaling the entries of B 1 by det(B). Recall from intro-
ductory linear algebra that B ⇤ is the adjugate matrix. Since det(B i ej ) 2 {±1, 0}, all entries
of B ⇤ are in {0, ±1}. Let R = {j : B1j
⇤ 6= 0}. Since B is non-singular, it cannot have a row with
˙ 2 = R such that
By the assumption, there exists a partition R1 [R
X X
Bij Bij 2 {±1, 0} 8 j 2 [k].
i2R1 i2R2
P P
For j 2 {2, ..., k} we must have that i2R1 BijP ij = 0 since |{i 2 R : Bij 6= 0}|
i2R2 BP
indicates that the result must be even. Therefore, i2R1 Bi1 i2R2 Bi1 2 ±1 as otherwise the
matrix would be singular.
In summary, y > B 2 {e> >
1 , e1 } where
8
>
<1 i 2 R1
yi = 1 i 2 R2
>
:
0 otherwise.
For a proof of the reverse direction, please refer to [7]. The following demonstrates how to
apply Theorem 4.3 to a combinatorial problem.
Example 4.10
Suppose we are given a set E = {e1 , ..., ek }, an integer parameter B, and for each element ei we
are given a cost cei 0. The goal is to pick a minimum cost subset S ✓ E such that |S| = B.
This is not hard to express as an integer program. For each i 2 [k], we need a decision variable
xi which is 1 when ei is in S, and 0 otherwise. The linear relaxation is
X
min c ei xei
i2[k]
X
s.t. xe i = B
i2[k]
0 x 1.
max c> x
✓ > ◆✓ ◆ ✓ ◆
1 0 x B
s.t. =
I I s 1
✓ ◆
x
0.
s
We >
✓ would
◆ like to prove that A is TU. By proposition 4.4, it is equivalent to show that A =
1 I
is TU. Note that A> is a 2k ⇥ (k + 1) matrix. When |E| = 3,
0 I
0 1
1 1 0 0
B1 0 1 0C
B C
B1 0 0 1C
>
A =B B C.
C
B0 1 0 0C
@0 0 1 0A
0 0 0 1
We will prove that A> is TU by applying the Ghouila-Houri Theorem. Let R be a subset of row
indices. We need to show that rowR (A> ) has an equitable 2-colouring. First, we know that in
the first column, there is a 1 in the first k rows and a 0 in the remaining rows. We now split
the row indices into upper and lower sections. That is, U = [k] and L = [2k]\[k]. Suppose
R = {i1 , ..., iq , ..., it } ordered by increasing row index in R, and iq is the largest index in R that
is in U .
We know that for the upper indices, we need the number of upper indices in R1 and R2 to
di↵er by at most 1. One way to achieve this is to assign the rows in R to R1 and R2 in an
alternating fashion. Our partition of of rows in U \ R is
R1U = {ij : j q and j is even}, and
R2U = {ij : j q and j is odd}.
It is important to notice that this assignment is done based on the index in set R, and not on
the corresponding row index in A> .
We now consider the rows in L \ R. Notice that in column l, for l 2 {2, ..., k + 1}, there are
1s in row l 1 and row l 1 + k. Therefore, if both of these rows appeared in R, then we must
assign one row to R1 and the other to R2 . That is,
R1L = {r = l 1+k 2L\R:l 1 2 R2U }, and
R2L = (L \ R)\R1L .
Finally, R1 = R1U [ R1L and R2 = R2U [ R2L . We have found a method that creates an equitable
2-colouring for any row subset R, and so by the Ghouila-Houri theorem, A> is TU.
For example, if R = {1, 3, 6},
0 1
1 1 0 0
A>R =
@1 0 0 1A .
0 0 0 1
The rows in R are ordered as {i1 , i2 , i3 }. j = 2 is the largest number such that row ij in R is
in the upper portion of A. Therefore row i1 = 1 is assigned to R2 and row i2 = 3 is assigned to
R1 . We see that i3 = 6, and row 6 = l 1 + k = 1 l + 3 implies that l = 4. Row l 1 = 3
was assigned to R1 , so we assign row i3 = 6 to R2 . Therefore we obtain the partition R1 = {3},
R2 = {1, 6}.
The following corollary to the Ghouila-Houri Theorem can be proven by a similar method, and
we leave the proof as an exercise.
4.4. EXERCISES 55
Corollary 4.2. Let A be a {0, 1}-matrix such that in every column, the 1-entries are consecutive.
Then A is TU.
4.4 Exercises
Exercise 4.1. Permutation matrices
A {0, 1} square matrix is a permutation matrix if in each row and each column, there is precisely
one entry that is 1, and all other entries are zero. Without applying Proposition 4.3, prove that
any permutation matrix is totally unimodular.