A 2-Variable Integer program
Introduction to Integer Programming
Integer programming models
l
maximize
3x + 4y
subject to
5x + 8y £ 24
x, y ≥ 0 and integer
l
What is the optimal solution?
1
MIT and James Orlin © 2003
2
MIT and James Orlin © 2003
A rounding technique that sometimes is
useful, and sometimes not.
The Feasible Region
5
What is the optimal linear
solution?
Round, get x=5, y=0,
infeasible!
Truncate, get x=4, y=0, and z
=12
Same solution value at x=0,
y=3.
Optimal is x=3, y=1, and z
=13
3
2
0
0
1
2
Can one use linear
programming to solve the
integer program?
1
3
4
Solve LP (ignore integrality)
get x=24/5, y=0 and z =14 2/5.
4
5
Question: What is the
optimal integer solution?
0
1
2
3
4
5
0
Why integer programs?
l
Advantages of restricting variables to take on
integer values
Disadvantages
– More difficult to model
– Can be much more difficult to solve
3
4
5
l
Integer programs: linear equalities and
inequalities plus constraints that say a
variable must be integer valued.
l
We also permit “xj Œ{0,1}.” This is equivalent
to
0 £ xj £ 1 and xj integer.
5
MIT and James Orlin © 2003
2
On 0-1 variables
– More realistic
– More flexibility
l
1
6
MIT and James Orlin © 2003
The game of fiver.
The mystery of integer programming
l
l
l
l
Some integer programs are easy (we can
solve problems with millions of variables)
Some integer programs are hard (even 100
variables can be challenging)
It takes expertise and experience to know
which is which
It’s an active area of research at MIT and
elsewhere
Click on a circle,
and flip its color
and that of adjacent
colors.
Can you make all of
the circles red?
7
MIT and James Orlin © 2003
8
MIT and James Orlin © 2003
The game of fiver.
The game of fiver.
9
MIT and James Orlin © 2003
10
MIT and James Orlin © 2003
Optimizing the game of fiver.
The game of fiver.
1
1
Let’s write an
optimization
problem whose
solution solves
the problem in
the fewest
moves.
2
3
4
5
Let x(i,j) = 1 if I click on
the square in row i and
column j.
x(i,j) = 0 otherwise.
4
Focus on the element in
row 3, and column 2. To
turn it red, we require
that
5
x(2,2) + x(3,1) + x(3,2) +
x(3,3) + x(4,2) is odd
3
11
MIT and James Orlin © 2003
2
12
MIT and James Orlin © 2003
Optimizing the game of fiver
Optimizing the game of fiver
(i, j) to be red for i = 1 to 5 and for j = 1 to 5
l We want to minimize the number of moves.
(i, j) to be red for i = 1 to 5 and for j = 1 to 5
l We want to minimize the number of moves.
l
Minimize
S
i,j=1 to 5
l
x(i,j)
Minimize
Subject to
x(i, j) + x(i, j-1) + x(i, j+1)
+ x(i-1, j) + x(i+1, j) is odd
for i = 1 to 5, j = 1 to 5
x(i, j) is 0 or 1 for i = 1 to 5 and j = 1 to 5
x(i, j) = 0 otherwise.
l
S
i,j=1 to 5
x(i,j)
Subject to
x(i, j) + x(i, j-1) + x(i, j+1)
+ x(i-1, j) + x(i+1, j) - 2y(i,j) = 1
for i = 1 to 5, j = 1 to 5
x(i, j) is 0 or 1 for i = 1 to 5 and j = 1 to 5
y(i,j) is integral
x(i, j) = 0 otherwise.
This (with a little modification) is an integer program.
l
This is an integer program.
13
MIT and James Orlin © 2003
14
MIT and James Orlin © 2003
Should I give away the solution?
Types of integer programs
l
All integer programs have linear equalities
and inequalities and some or all of the
variables are required to be integer.
– If all variables are required to be integer, then it is
usually called a pure integer program.
– If all variables are required to be 0 or 1, it is called a
binary integer program, or a 0-1 integer program.
– if some variables can be fractional and others are
required to be integers, it is called a mixed linear
integer program (MILP)
15
MIT and James Orlin © 2003
16
MIT and James Orlin © 2003
Data for the Stockco Problem
Stockco Example
Investment budget = $14,000
Stockco is considering 6 investments. The cash
required from each investment as well as the NPV
of the investment is given next. The cash
available for the investments is $14,000. Stockco
wants to maximize its NPV. What is the optimal
strategy?
An investment can be selected or not. One cannot
select a fraction of an investment.
Investment 1
Cash
Required
(1000s)
NPV
added
(1000s)
17
MIT and James Orlin © 2003
$5
2
3
4
5
6
$7
$4
$3
$4
$6
$16 $22 $12 $8
$11 $19
18
MIT and James Orlin © 2003
Possible constraints in integer programs
Integer Programming Formulation
l
What are the decision variables?
10,if we invest in i1,...,6,,elseix=Ï=ÌÓ
l
Objective and Constraints?
The previous constraints represent
“economic indivisibilities”, either a project is
selected, or it is not. There is no selecting of
a fraction of a project.
Similarly, integer variables can model logical
requirements (e.g., if stock 2 is selected, then
so is stock 1.)
Max 16x1+ 22x2+ 12x3+ 8x4+ 11x5+ 19x6
5x1+ 7x2+ 4x3+ 3x4+ 4x5+ 6x6 £ 14
MIT and James Orlin © 2003
xj e {0,1} for each j = 1 to 6
19
Formulating Constraints
How to model “logical” constraints
l
l
l
l
20
MIT and James Orlin © 2003
Exactly 3 stocks are selected.
If stock 2 is selected, then so is stock 1.
If stock 1 is selected, then stock 3 is not selected.
Either stock 4 is selected or stock 5 is selected,
but not both.
l
Exactly 3 stocks are selected
x1+ x2+ x3+ x4+ x5+ x6=3
21
MIT and James Orlin © 2003
22
MIT and James Orlin © 2003
If stock 2 is selected then so is stock 1
A 2-dimensional
representation
The integer
programming
constraint:
If stock 1 is selected then stock 3 is not
selected
A 2-dimensional
representation
x1 ≥ x2
Stock 2
x1 + x3 £ 1
Stock 3
Stock 1
MIT and James Orlin © 2003
The integer
programming
constraint:
Work with your partner
for 5 minutes trying to
model the other
23
constraints.
Stock 1
24
MIT and James Orlin © 2003
Either stock 4 is selected or stock 5 is
selected, but not both.
Representing Non-linear functions
l
The integer
programming
constraint:
A 2-dimensional
representation
x4 + x5 = 1
stock 5
Suppose that the cost of computers is
as follows:
–
–
–
–
$2,000 each if you buy 1 to 10
$1,800 for each computer from 11 to 25
$1,700 for each computer from 26 to 50
No more than 50 may be purchased.
–
–
–
–
Let x = number of computers bought
x1 = number bought at $2,000
x2 = number bought at $1,800
x3 = number bought at $1,700
s.t.
0 £ x1 £ 10
0 £ x2 £ 15
0 £ x3 £ 25
If x1 < 10,
then x2 = 0.
If x2 < 15,
then x3 = 0.
Minimize 2,000 x1 +1,800 x2 + 1,700 x3
stock 4
25
MIT and James Orlin © 2003
26
MIT and James Orlin © 2003
Representing Non-linear functions
Is this formulation correct?
Minimize 2,000 x1 +1,800 x2 + 1,700 x3
0 £ x1 £ 10
s.t.
0 £ x2 £ 15 w1
Let w 1 = 1 if x 1 = 10
w 1 = 0 if x 1 < 10
0 £ x3 £ 25 w 2
If £x1w< 10,
then x2 = 0.
0
1 £ x1/10
If
0 £x2w< 15,
£ x then
/15 x3 = 0.
2
2
l
l
It models the x’s correctly.
It does not model the w’s perfectly.
– Suppose x1 = 10, x 2 = x3 = 0;
– Then w 1 = 0 or 1
– Cost = 20,000, regardless.
Let w 2 = 1 if x 2 = 15
w 2 = 0 if x 2 < 15
w1, w 2 Œ {0, 1}
If x1 < 10, then x2 = 0.
If w 1 = 0, then x2 = 0.
If x2 < 15, then x3 = 0.
If w 2 = 0, then x3 = 0.
27
MIT and James Orlin © 2003
Fire Station Problem
1
2
5
Representation as Set Covering Problem
Locate fire stations
so that each district
has a fire station in
it, or next to it.
3
6
1
8
11
12
13
MIT and James Orlin © 2003
15
8
11
7
Set
Covers
1
1, 2, 4, 5
2
1, 2, 3, 5, 6
3
2, 3, 6, 7
16
13, 15, 16
9
12
13
10
10
14
3
6
4
Minimize the
number of fire
stations needed.
9
2
5
7
4
28
MIT and James Orlin © 2003
16
14
29
15
16
30
MIT and James Orlin © 2003
Representation as Graph Cover Problem
1
2
5
8
11
10
14
Replace each district with a
node.
3
7
9
12
15
13
16
A node covers itself and its
neighbors. Thus, node 16
covers nodes 13, 15, 16.
6
8
11
11
10
14
77
9
12
s.t. x 1 + x 2 + x 4 + x5 ≥ 1
x1 + x 2 + x 3 + x 5 + x 6 ≥ 1
13
15
15
16
x13 + x 15 + x 16 ≥ 1
xj Œ {0, 1} for each j.
Suppose you knew which warehouses
were open. S = set of open warehouses
xij = demand satisfied for
customer i at warehouse j
l yj = 1 for j in S,
yj = 0 for j not in S.
n warehouses
l
– cost fj of opening warehouse j
m customers
– customer i has a “demand” of di
– unit shipping cost cij of serving customer i via warehouse j.
subject to:
l customers get their
demand satisfied
l no shipments are made
from an empty warehouse
Variables:
– let yj = 1 if warehouse j is opened
– Let xij = amount of demand for customer i satisfied via
warehouse j.
Si,j cijxij
+ SjŒS fj
minimize
Sj xij = di
xij £ di
xij = 0
if yj = 1
if yj = 0
and x ≥ 0
33
MIT and James Orlin © 2003
34
MIT and James Orlin © 2003
More on warehouse location
yj = 1 if warehouse i is
opened
yj = 0 otherwise
l xij = flow from i to j
Two key aspects of using integrality in the
model
l
Si,j cijxij
+ Sj fi yi
minimize
l
Costs: we include the cost of the warehouse
only if it is opened.
Si fi yi
l
Constraints: We do not allow shipping from
warehouse j if it is not opened.
subject to:
customers get their
demand satisfied
l each warehouse is either
opened or it is not (no
partial openings)
l no shipments are made
from an empty warehouse
l
Si
xij = dj
0 £ yj £ 1
yj integral for all j.
– xij £ d j yi for all i, j
xij £ dj yi for all i, j
and x ≥ 0
35
MIT and James Orlin © 2003
32
MIT and James Orlin © 2003
skip
l
xj = 1 if node j is selected
xj = 0 otherwise
3
Minimize x1 + x 2 + … + x 16
5
What is the minimum size of
a subset of nodes that covers
all of the nodes?
31
Warehouse location problem
l
2
4
MIT and James Orlin © 2003
l
11
Two nodes are adjacent if
their districts are adjacent
6
4
Representation as Integer program
36
MIT and James Orlin © 2003
Using Excel Solver to Solve Integer
Programs
More on warehouse location
l
The above is a core subproblem occurring in
supply chain management, and it can be
enriched
–
–
–
–
–
–
–
Add the integrality constraints (or add that a variable is
binary)
l Set the Solver Tolerance. (The tolerance is the percentage
deviation from optimality allowed by solver in solving
Integer Programs.)
– The default is 5%
– The default is way to high
– It often finds the optimum for small problems
l
more complex distribution system
capacity constraints
non-linear transportation costs
delivery times
multiple products
business rules
and more
37
MIT and James Orlin © 2003
Some Comments on IP models
l
l
38
MIT and James Orlin © 2003
Example
There are often multiple ways of modeling the
same integer program.
l
Solvers for integer programs are extremely
sensitive to the formulation. (not true for LPs)
l
l
constraint A: 2x1 + 2x 2 + … + 2x 50 £ 51
constraint B: x1 + x2 + … + x50 £ 25
– assume that x is binary
constraints C: x1 £ y, x2 £ y, …, x50 £ y
(where y is binary)
l constraint D: x1 + … + x 50 £ 50 y
B dominates A, C dominates D
It is not obvious why, until you see the algorithms.
39
MIT and James Orlin © 2003
Summary on Integer Programming
l
Dramatically improves the modeling capability
–
–
–
–
l
l
Economic indivisibilities
Logical constraints
Modeling nonlinearities
classical problems in capital budgeting and in
supply chain management
Not as easy to model
Not as easy to solve.
41
MIT and James Orlin © 2003
40
MIT and James Orlin © 2003
© Copyright 2026 Paperzz