Linear Programming
Linear Programming
Chapter 1
What is modeling?
Why use models?
Rather than starting with a theoretical overview of what modeling is, and why it is useful, we shall look
at a problem facing a very small manufacturer, and how we might go about solving the problem. When
we have gained some practical modeling experience, we shall come back to see what the benets of
modeling have been.
Section 1.1 gives a word description of the problem and its translation into a mathematical form. We then
dene in Section 1.2 the notion of a Linear Program and show how the example problem ts this form. In
Section 1.3 the problem is implemented with Mosel and solved with the Xpress-Optimizer. The discussion
of the results comprises a graphical representation of the solution information that may be obtained from
the solver. Important issues in modeling and solving linear problems are infeasibility and unboundedness
(Section 1.4). The chapter closes with reections on the benets of modeling and optimization (Section
1.5) and the importance of the data (Section 1.6).
1.1
The number of large and small chess sets we should produce to achieve the maximum contribution to
prot is determined by the optimization process. In other words, we look to the optimizer to tell us the
best values of xs, and xl.
The values which xs and xl can take will always be constrained by some physical or technological limits.
One of the main tasks in building a model is to write down in a formal manner the exact constraints that
dene how the system can behave. In our case we note that the joinery has a maximum of 160 hours of
machine time available per week. Three hours are needed to produce each small chess set, and two hours
are needed to produce each large set. So if in the week we are planning to make xs small chess sets and
xl large chess sets, then in total the number of hours of machine time we are planning to use is:
3 xs + 2 xl
where the 3 xs comes from the time making small sets, and the 2 xl from the time machining large sets.
Note that we have already made some assumptions here. Firstly we have assumed that the lathe-hours to
machine xs small sets is exactly xs times the lathe-hours required to machine one small set. This probably
will not be exactly true in practice one tends to get faster at doing something the more one does it, so
it will probably take a slightly smaller amount of time to machine the 2nd and subsequent sets than the
rst set. But it is unlikely that this will be a very important effect in our small joinery.
The second assumption we have made is much more likely to be inaccurate. We have assumed that the
time for making small and large sets is the sum of the times for the sets. We have not allowed for any
changeover time: resetting the lathes, cleaning up, getting different size tools etc. In some situations,
the time that we lose in changeovers can be very large compared with the time we actually spend doing
constructive work and then we have to resort to more complex modeling. But for the moment, we shall
assume that the changeover times are negligible.
Our rst constraint is:
3 xs + 2 xl 160 (lathe-hours)
which says the amount of time we are planning to use must be less than or equal to the amount of time
available, or equivalently we cannot plan to use more of the resource (time) than we have available.
The allowable combinations of small and large chess sets are restricted to those that do not exceed the
lathe-hours available.
In addition, only 200 kg of boxwood is available each week. Since small sets use 1 kg for every set made,
against 3 kg needed to make a large set, a second constraint is:
1 xs + 3 xl 200 (kg of boxwood)
where the left hand side of the inequality is the amount of boxwood we are planning to use and the
right hand side is the amount available.
The joinery cannot produce a negative number of chess sets, so two further non-negativity constraints
are:
xs 0
xl 0
In a similar way, we can write down an expression for the total prot. Recall that for each of the large
chess sets we make and sell we get a prot of $20, and one of the small chess set gives us a prot of $5.
Assuming that we can sell all the chess sets we make (and note that this may not always be a reasonable
assumption) the total prot is the sum of the individual prots from making and selling the xs small sets
and the xl large sets, i.e.
Prot = 5 xs + 20 xl
Prot is the objective function, a linear function which is to be optimized, that is, maximized. In this case
it involves all of the decision variables but sometimes it involves just a subset of the decision variables.
Note that Prot may be looked at as a dependent variable, since it is a function of the decision variables.
In maximization problems the objective function usually represents prot, turnover, output, sales, market share, employment levels or other good things. In minimization problems the objective function
describes things like total costs, disruption to services due to breakdowns, or other less desirable process
outcomes.
Consider some possible values for xs, and xl (see Table 1.1). The aim of the joinery is to maximize prot,
but we cannot select any combination of xs and xl that uses more of any of the resources than we have
available. If we do plan to use more of a resource than is available, we say that the plan violates the
constraint, and the plan is infeasible if one or more constraints is violated. If no constraints are violated,
the plan is feasible. The column labeled OK? in the table tells us if the plan is feasible. Plans C and E are
infeasible.
In terms of prot, plan H looks good. But is it the best plan? Is there a plan that we have not considered that gives us prot greater than 1320? To answer this question we must move to the notion of
optimization.
1.2
xs
xl
Lathe-hours
Boxwood
OK?
Prot
A
B
C
0
10
-10
0
10
10
0
50
-10
0
40
20
Yes
Yes
No
0
250
150
53
159
53
Yes
265
E
F
50
25
20
30
190
135
110
115
No
Yes
650
725
G
H
12
0
62
66
160
130
198
198
Yes
Yes
1300
1320
Notes
Unprotable!
We wont get rich doing this.
Planning to make a negative
number of small sets.
Uses all the lathe-hours. There
is spare boxwood.
Uses too many lathe-hours.
There are spare lathe-hours
and spare boxwood.
Uses all the resources
Looks good. There are spare
resources.
Linear Programming
We have just built a model for the decision process that the joinery owner has to make. We have isolated
the decisions he has to make (how many of each type of chess set to manufacture), and taken his objective
of maximizing prot. The constraints acting on the decision variables have been analyzed. We have given
names to his variables and then written down the constraints and the objective function in terms of these
variable names.
At the same time as doing this we have made, explicitly or implicitly, various assumptions. The explicit
assumptions that we noted were:
For each size of chess set, manufacturing time was proportional to the number of sets made.
There was no down-time because of changeovers between sizes of sets.
We could sell all the chess sets we made.
But we made many implicit assumptions too. For instance, we assumed that no lathe will ever break or
get jammed; that all the lathe operators will turn up for work every day; that we never nd any aws in
the boxwood that lead to some being unusable or a chess set being unacceptable; that we never have to
discount the sale price (and hence the per unit prot) to get an order. And so on. We have even avoided
a discussion of what is the worth of a fraction of a chess set is it a meaningless concept, or can we just
carry the fraction that we have made over into next weeks production?
All mathematical models necessarily contain some degree of simplication of the real world that we are
attempting to describe. Some assumptions and simplications seem eminently reasonable (for instance,
that we can get the total prot by summing the contributions of the individual prots from the two sizes);
others may in some circumstances be very hopeful (no changeover time lost when we swap between
sizes); whilst others may just be cavalier (all the lathe operators will arrive for work the day after the
World Cup nals).
Modeling is an art, not a precise science. Different modelers will make different assumptions, and come
up with different models of more or less precision, and certainly of different sizes, having different numbers of decision variables. And at the same time as doing the modeling, the modeler has to be thinking
about whether he will be able to solve the resulting model, that is nd the maximum or minimum value
of the objective function and the values to be given to the decision variables to achieve that value.
It turns out that many models can be cast in the form of Linear Programming models, and it is fortunate
that Linear Programming (LP) models of very large size can be solved in reasonable time on relatively
inexpensive computers. It is not the purpose of this book to discuss the algorithms that are used to solve
LP problems in any depth, but it is safe to assume that problems with tens of thousands of variables and
constraints can be solved with ease. So if you can produce a model of your real-world situation, without
too many wild assumptions, in the form of an LP then you know you can get a solution.
So we next need to see what a Linear Programming problem consists of. To do so, we rst introduce the
notion of a linear expression. A linear expression is a sum of the following form
A1 x1 + A2 x2 + A3 x3 +. . . +AN xN
Aj xj
j=1
where A1 , . . . , AN are constants and x1 , . . . , xN are decision variables. So for instance, if we have variables
x, makeP and makeQ
2 x 3 makeP + 4 makeQ
is a linear expression, but
2 x makeP 3 makeP + 4 makeQ
is not, as the rst term contains the product of two variables.
Next,
N we introduce the notion of linear inequalities and linear equations. For any linear expression
A xj and any constant B, the inequalities
j=1 j
N
Aj xj B and
N
j=1
Aj xj B
j=1
N
Aj xj = B
j=1
N
i=j
N
Aij xj Bi for i = 1, . . . , M1
j=1
N
Aij xj = Bi for i = M1 + 1, . . . , M2
j=1
N
Aij xj Bi for i = M2 + 1, . . . , M3
j=1
and
5 xs + 20 xl
subject to
10
We have stressed the linearity condition, where the objective function and all of the constraints must be
linear in the decision variables. But there are two further properties that we must have, Divisibility and
Determinism.
Divisibility means that in an acceptable solution any values of the decision variables are allowed within
the restrictions imposed by the linear constraints. In particular, we are not constrained to accept only
whole number (integer) values for some or all of the decision variables. We have already alluded to this,
when we remarked on the debate as to whether a fraction of a chess set is worth something (or, more
precisely, whether a fraction f of a chess set is worth exactly f times the worth of a whole chess set).
The nal requirement we have of an LP problem is that it is deterministic all the coefcients in the
constraints and the objective function are known exactly. Determinism is sometimes a very strong assumption, particularly if we are building planning models which extend some way into the future. Is it
reasonable, for example, to assume that it will always take 7.5 days for the oil tanker to reach our renery
from the Gulf? Or that all of the lathe operators will arrive for work every day next week?
Problems where we must consider the variability in objective function coefcients, right hand sides or
coefcients in the constraints are Stochastic Programming problems. We do not consider them in this
book, because they are difcult to deal with, not because they are of little practical interest. In fact, it
can be argued that all planning models have stochastic elements, and we will later demonstrate some
methods for dealing with uncertainty in an LP framework.
1.3
Chapter 2
2.1
19
One might ask why have sendb5,Paris as a decision variable at all, as it is xed and there is no decision to
make about its value?. If every day we always sent exactly 30 tonnes to Paris then it might be legitimate
to remove this from the decision process, remembering to account for the resources that are used in the
blend, the transport capacity that is used up in moving the blend, etc. But of course there will inevitably
come a day when Paris needs more of Blend 5, and we have to spend time recalculating the resource
availabilities, transport capacity etc., net of the new Parisian demand. We will get things wrong unless
someone remembers to do the recalculation; and of course forgetting to redo the sums is likely when
we are having to rejig our production plan because of the extra demands from other cities in France (it
is Bastille Day tomorrow). What we gain by removing one variable from the model is not worth the risk
arising from later inexibility.
The last case, D, expresses the fact that sometimes a variable is not bound by the normal non-negativity
constraint, and in this situation it is said to be free. Since, as we have mentioned before, all decision
variables are by default assumed to be non-negative, we have to explicitly tell our modeling software
that the decision variable here (which we shall call eow), denoting the ow from Britain to France
where a positive value means that electricity is owing from Britain to France and a negative value
means that it is owing in the reverse direction is not non-negative
eow +
In Mosel, this is indicated by the notation
eflow is_free
2.2
Flow constraints
Flow constraints arise where one has some sort of divisible item like electricity, water, chemical uids,
trafc etc. which can be divided into several different streams, or alternatively streams can come together.
Some word formulations might be
A) I have got a tank with 1000 liters in it and 3 customers C1, C2 and C3 to supply.
B) I buy in disk drives from 3 suppliers, S1, S2 and S3. Next month I want to have at least 5000 disk drives
arriving in total.
C) I have 2 water supplies into my factory, S1 and S2. I get charged by the water supplier for the amount
of water that enters my site. I lose 1% of the water coming in from S1 by leakage and 2% of that from
S2. My factory needs 100,000 gallons of water a day.
Case A is where there is an outow from a single source, whilst case B is where we want to model a total
inow. Case C is a little more complicated, as we have to model losses.
In case A we have ow variables supply1 , supply2 and supply3 , being the amounts we supply to the three
customers. The total amount supplied is the sum of these three decision variables i.e. supply1 + supply2 +
supply3 , and this total must be less than or equal to the 1000 liters we have available. Thus we have
supply1 + supply2 + supply3 1000
(providing we have dened the units of supply to be liters).
Case B is very similar. The obvious decision variables are buy1 , buy2 and buy3 , and the total amount we
buy is buy1 + buy2 + buy3 . Our requirement is for at least 5000 drives in total, so the constraint is
buy1 + buy2 + buy3 5000
If we wanted exactly 5000 drives, then the constraint would be
buy1 + buy2 + buy3 = 5000
20
Case C is more challenging. I have 2 water supplies into my factory, S1 and S2. I get charged by the
water supplier for the amount of water that enters my site. I lose 1% of the water coming in from S1 by
leakage and 2% of that from S2. My factory needs 100,000 gallons of water a day.
There are several different ways we might approach the modeling. One way is to dene decision variables
as follows: buy1 and buy2 are the amounts we buy from supplier 1 and 2 respectively, and get1 and get2
are the amounts that we actually get (after the losses). If we measure the decision variables in thousands
of gallons, then we have the requirement constraint
get1 + get2 = 100
and we can model the losses as follows (loss equations):
get1 = 0. 99 buy1
get2 = 0. 98 buy2
since, for example, we only receive 98% of the water from supplier 2 that we have to pay for. Then the
objective function would, among other entries, have terms PRICE1 buy1 + PRICE2 buy2 , where PRICE1 and
PRICE2 are the prices per thousand gallons of water from the two suppliers.
We have the option of using the loss equations to substitute for buy1 and buy2 (or, alternatively, get1 and
get2 ), and doing so would reduce the number of equations and variables by 2. But as we have discussed
before, it almost certainly is not worth the effort, and the LP solver should be clever enough to do the
work for us automatically anyway if it thinks it will reduce the solution time.
2.3
21
Resource 2
1.28235
0.95474
12.33312
Resource 3
...
Resource R
0.24
1.8361
6.128
0.8528
etc.
11.2322
5.208
8
5
connectors. So in total if we make makeI Industrial computers and makeH Home computers we will use
8 makeI + 5 makeH connectors. This total must not be greater than the number available i.e.
8 makeI + 5 makeH 10000
In case B we said Each tonne of chemical C1 uses 50 grams of a rare catalyst and 1 kg of a certain ne
chemical, whereas each tonne of chemical C2 requires 130 grams of the catalyst and 1.5 kg of the ne
chemical. I can only afford to buy 10 kilograms of catalyst per month and I can only acquire 200 kg of the
ne chemical each month. So we have two products and two resources.
Table 2.3: Resource use
Catalyst
Fine Chemical
50
130
1.0
1.5
C1
C2
We measure the catalyst in grams, and the ne chemical in kg. Dening decision variable make1 and
make2 to be the number of tonnes of the two chemicals (C1 and C2) we plan to make, and using an
argument similar to the one in case A), we get two constraints, one for the catalyst and one for the ne
chemical.
50 make1 + 130 make2 1000 (catalyst)
1. 0 make1 + 1. 5 make2 200 (ne chemical)
We have been careful to keep the units of measurement consistent.
In general, we have one constraint for each resource, relating the amount we are planning to use to the
amount available.
Case C is now hardly challenging. If I do one unit of activity i it takes up COSTi of my disposable income.
My disposable income next week is $150. The decision variables are doacti , the amount of activity i that
I plan to do. Making the linearity assumption
that if I do doacti units of activity i it costs me COSTi
doacti , my total planned expenditure is i COSTi doacti and this can be no more than the money I have
(assuming credit is not an option for me!). Then the constraint is
2.4
22
L
flowin3
flowout1
flowin2
flowout2
flowout3
flowin1
If the ow variables are measured in terms of mass or weight then we will have
L+
MIN
NOUT
owini =
i=1
owoutj
j=1
A particular form of material balance constraint occurs when we are accounting for the ow of materials
between time periods in a multi-time period model, that is, a model where we represent time as a
series of intervals, not concerning ourselves with the details of when during an interval events happen.
Suppose that we have a simple factory that only makes one product and that we are trying to decide the
manufacturing levels (maket ) for the next NT periods, i.e. t ranges from 1 to NT. Another set of decision
variables are sellt , the amount of the product that we decide to sell in time period t. If we have the
possibility of storing product from one time period to the next time period we can introduce a further
set of decision variables storet which are the amounts of product to have in stock (inventory) at the end
of time period t.
Let us consider the material balance in time period t. In words we can say the stock at the end of time
period t is equal to the stock at the beginning of time period t, plus what we make, minus what we sell.
We are faced with a slight problem now we do not know the decision variable for the stock at the
beginning of time period t but we can see that, assuming there is no loss of stock, the stock at the
beginning of time period t is the same at the end of time period t -1. So in different words, the previous
statement can be phrased as the stock at the end of time period t is equal to the stock at the end of time
period t 1, plus what we make in period t, minus what we sell in period t. In algebraic form this can
be written
stockt = stockt1 + maket sellt
This is deceptively simple but it contains one aw: there is no time period preceding time period 1, so
there is no stock0 variable. We need a special constraint that relates to time period 1 only, and says in
words the stock at the end of time period 1 is equal to the opening inventory SINIT, plus what we make
in time period 1, minus what we sell in time period 1, or in algebra
stock1 = SINIT + make1 sell1
Other material balance constraints arise when we are talking about raw materials that we buy in from
an outside supplier and use in our production process. A word description might be, for a particular raw
material, the stock of the raw material at the end of time period t is equal to the stock at the end of
time period t 1, plus the amount of the raw material that we buy in time period t, minus the amount
of raw material that we use in making the products during time period t. Then considering one raw
material we might have decision variables rbuyt , rstockt and ruset , so the constraints for all but the rst
time period are
rstockt = rstockt1 + rbuyt ruset
We have to remember again that there is a special constraint for time period 1 as we already know the
opening stock level in that period: it is what we have in stock right now.
It is also likely that the ruset variables will be related to the decision variables in another part of the model
which represent how much product we are going to make. If we have products indexed by p = 1, . . . , NP
with technological coefcients REQpr , the number of units of raw material r required by 1 unit of product
p, and decision variables makept denoting the amount of product p that we make in time period t, we
can immediately write down an expression for the amount of raw material we use in time period t (ruset )
23
as
ruset =
NP
REQpr makept
p=1
(see Section 2.3 Simple resource constraints above for an explanation of this).
Since we have just written down an equation for ruset we might consider substituting for it in the constraint in which it occurs. This would generally not be a particularly good thing to do, but not particularly
bad either. It would reduce the number of variables a little but we are probably going to have to use
these variables somewhere else in the model anyway and so the substitution would have to take place everywhere the ruset variables appeared in the model. The model would certainly be less comprehensible,
and consequently harder to maintain.
A new form of material balance equations of the multi-period type occurs where we have xed demands
for our product or products in the NT time periods. In other words, the selling decision variables (sellt in
the example above) are xed. We have the choice of expressing this as a set of simple equality constraints
with sellt variables e.g.
sellt = MUSTSELLt
or by substituting the sellt variables by MUSTSELLt everywhere they occur. This time the decision as to
whether to substitute for the sellt variables is probably a matter of choice some modelers will eliminate
variables while others might put in the simple equality constraint arguing that the sellt variables will
probably at some stage in the future be of interest in themselves.
2.5
Quality requirements
Here are some word statements
A) I cannot have more than 0.02% of sulphur in this gasoline.
B) There must be at least 3% of protein in this dried apricot mixture.
C) This foodstuff must have no less than 5% fat but no more than 10%.
These sorts of quality requirements frequently occur when we are blending together various raw materials with differing properties to create a nal product. Typically each of the raw materials will come
with a set of properties, for instance in foodstuffs it might be the fat content or the percentage of carbohydrates; in the petrochemical industry it might be sulphur content or the octane number. For some
characteristics of the nal product we require that quality specications are adhered to. For bad things
these are usually expressed as a maximum percentages; for desirable properties they will be expressed as
a minimum percentage and other properties may have to lie between specied lower and upper bounds
(perhaps so that the product has stability or other characteristics that we desire). An extreme form of
the latter case is where we have to have an exact percentage of a particular characteristic in the nal
product.
Consider a number NR of raw materials and just one characteristic that we are concerned about in the
nal product. Suppose that one unit of raw material r contains CONTr units of the characteristic (for
instance CONT3 might be 0.1 if raw material number 3 is 10% fat and the characteristic we are considering
is fat). As usual with LP we assume that we know the CONT data precisely.
In many manufacturing processes it is reasonable to assume that the characteristic in the resulting end
product comes from blending the raw materials linearly. For example if we blend together one kg of a
gasoline with 0.01% sulphur and 1 kg of gasoline with 0.03% sulphur, then we will get 2 kg of the mixture
with 0.02% sulphur. Whether this assumption of linearity is correct very much depends upon the physics
or chemistry of the blending process and in some industries it certainly does not hold. However, making
the assumption of linearity, we can see that the proportion of the characteristic in the nal product is
given by
total mass of constituents
p = proportion =
total mass of blend
If the decision variables are ruser for the amount of raw material r to use, then we have
NR
p=
Cr ruser
r=1
NR
r=1
ruser
and we can apply the desired inequality (or equality) to this proportion. For instance, p 0. 1 (i.e. 10%)
becomes
NR
C ruser
r=1 r
0. 1
NR
ruser
r=1
24
At rst sight this does not seem like a linear inequality and indeed it is not as it is a constraint applying
to the ratio of two linear expressions. However, by cross multiplying we can get the constraint into the
form
NR
Cr ruser 0. 1
r=1
NR
ruser
r=1
Note: we have to be careful when multiplying inequalities. The direction of the inequality is preserved
if we multiply by a non-negative amount, but is reversed if we multiply by a negative amount. Here, we
are multiplying both sides of the inequality by the sum of a set of non-negative variables, so the direction
of the inequality is maintained.
If we collect together two terms for each decision variable ruser we get the linear inequality
NR
(Cr 0. 1) ruser 0
r=1
2.6
16
rcosti
i=1
2.7
Blending constraints
A very common use of LP modeling is to deal with the situation where we have a set of inputs each with
certain percentages of different characteristics and we want to blend these inputs together to get a nal
25
product with certain desired characteristics. Blending typically falls into one of two major categories:
either we use xed recipes where the proportion of different inputs is determined in advance (rather like
the recipes you see in cookery books which specify the exact weights of the constitutes required to make
a certain weight of cake) or we have variable recipes where it is up to us to decide, perhaps within limits,
the proportions of the inputs that we are going to blend together.
An example of a variable recipe might be in the manufacture of animal feed stuffs which can be made
from a wide variety of different raw materials, not necessarily always mixed in the same proportions. An
interesting example of recipes which pretend to be xed but in fact are variable are those found in books
that tell you how to mix cocktails. They usually pretend that the proportions of gin, tequila, vermouth
etc are xed, but of course anyone who has been in the position of having restricted stocks of any of
these raw materials knows that within limits the recipes are very variable.
Suppose we have 3 raw materials and the constraint in words is the ratios of raw material 1, raw material
2 and raw material 3 are 6:3:1. If we have decision variables raw1 , raw2 and raw3 representing the weight
of the materials in the blend, then the total weight in the blend is raw1 + raw2 + raw3 and we have the
constraints
raw1
6
=
raw1 + raw2 + raw3 10
raw2
3
=
raw1 + raw2 + raw3 10
1
raw3
=
raw1 + raw2 + raw3 10
These are ratio constraints, not linear equations, but as before we can convert them into linear equations
by cross multiplying to get
(1 0. 6) raw1 = 0. 6 raw2 + 0. 6 raw3 , i. e.
0. 4 raw1 = 0. 6 raw2 + 0. 6 raw3
The cross multiplication preserves the direction of the inequality since the denominator is always nonnegative.
Similarly we get
0. 7 raw2 = 0. 3 raw1 + 0. 3 raw3 , and
0. 9 raw3 = 0. 1 raw1 + 0. 1 raw2
One of these equations is redundant as it is implied by the other two but it does no harm to put all three
equations into the model. In fact it is probably a good idea to put all three equations down as inevitably
at some time in the future we will have a fourth raw material and if we try to be too clever in eliminating
redundant constraints we will forget that we have omitted a previously redundant equation, and make
a mistake that will be hard to detect.
2.8
Modes
A generalization of blending constraints is where we have M inputs and N outputs which must be in strict
proportions. As an example, this might be expressed as My 3 inputs have to be used in the ratio of 2 :
1.6 : 2.2 and they produce outputs of 1.6 of output 1 and 1.7 of output 2. So, for example we might put
in 1 kg of input 1, 0.8 kg of input 2, and 1.1 kg of input 3, and get out 0.8 kg of output 1 and 0.85 kg of
output 2.
It is easy to see that if we have just one output then this is a simple xed ratio blending example.
Such M-input/N-output constraints often arise where we have a plant that we can operate in different
ways (modes), and the ratios differ for different modes. At any point in time, the plant can only be in
one mode.
Consider a very simple example, where we have 3 inputs, 2 outputs and 3 possible operating modes. We
present the operating characteristics in the tables below, where we have dened a unit of a mode as 1
hour i.e. we have shown the kg of each input used, and output produced, by the plant.
The decision variables are the number of hours the plant spends in each mode m, say usemodem . Then
the usage of Input 1, for instance, is 20 usemode1 + 22 usemode2 + 24 usemode3 and the production of
output 2 is 17 usemode1 + 20 usemode2 + 24 usemode3 .
26
20
16
22
22
14
21
24
13
18
Output 1
Output 2
16
17
15
20
14
24
In any given planning period we will also have a constraint on the total number of hours the plant spends
in all the modes. For instance, if we are doing a weekly plan (168 hours), then we will have the constraint
that
usemode1 + usemode2 + usemode3 168
We are assuming that we can work at most 168 hours in the week, and that we do not lose any time
changing from one mode to another. The latter assumption may be totally unrealistic for some plants,
and if we cannot assume that change-over times are negligible then we have to use an Integer Programming formulation.
2.9
27
Panic variables do not just apply to resource availability constraints; they can also be added to demand
constraints. For instance, we might have a constraint that a particular customer C has to have a total
supply from our depots of 100 tonnes, modeled as
owdC 100
dDEPOTS
If, however, it is just not possible to supply him then we may undersupply. There may be a contractual
cost to doing this, in which case we know what the direct cost will be, or we might have some measure
of the cost in terms of loss of goodwill (admittedly these costs are hard to estimate, and can be very
subjective).
If a panic variable is non-zero in an optimal solution, then we can infer one of two things: either we have
put in too low a penalty cost, or we are truly being forced to use the panic variable to achieve feasibility.
Rerunning the model with higher penalty costs will enable us to distinguish these cases. But in either case
we have an implementable solution, and we are not left with an end-user staring at a computer screen
wondering what on earth to do.
subject to
s t1
s t2
s t3
...
s tN
You can see that s has to be no less than each of the ts, and the minimization objective will force it down
to take the value of the largest t. Unfortunately, the same trick cannot be applied where we want to
minimize min(t1 , t2 , t3 , . . . , tN ) or maximize max(t1 , t2 , t3 , . . . , tN ).
N xj
j j
Obj =
Dj xj
Aij xj Ri
28
where is one of , or =.
Dene new variables d = 1
j
Dj xj
= d j Nj xj
= j Nj d xj
= j Nj yj
Obj
Dj d x j =
Dj yj
Aij xj Ri
or (multiplied by d)
d
Aij xj d Ri
or
Aij d xj d Ri
i.e. or
Aij yj d Ri
The resulting LP has variables d and yj . When it has been solved, the optimal values of the original xj
variables can be recovered from the denition xj = yj / d.
Note that we are in trouble if variable d can become 0. We also have to taken care if d is always negative,
as the signs of the inequalities must be reversed when we multiply by d above.
29
Chapter 3
3.1
30
Special Ordered Sets of type 2 (SOS2 or S2): an ordered set of non-negative variables, of which at
most two can be non-zero, and if two are non-zero these must be consecutive in their ordering.
Why might some of these variables and sets, which collectively we call global entities, be used? We shall
give a brief overview, and later we shall expand on these examples.
Integer variables occur naturally, being most frequently found where the underlying decision variable
really has to take on a whole number value for the optimal solution to make sense. If we are modeling
the number of trains that leave a railway station in a half-hour interval, then the variable representing
this number must take on an integer value it makes no sense to say that 11.23 trains are to leave.
The idea of partial integers arose from a study where car engines in short supply were being allocated
to different regions. Some of the regions were large, and took many engines, so it was permissible to
round a solution saying the region should take 1654.19 engines to the integer value 1654. But for a
regions taking only a few engines, it was not acceptable to round 6.32 engines to 6 engines. It is up to
the decision maker to decide the limit L below which it is not acceptable to round a fractional answer to
a nearby integer. The modeling system allows the decision maker to specify a different L for each partial
integer variable, if so desired. So partial integers provide some computational advantages in problems
where it is acceptable to round the LP solution to an integer if the optimal value of a decision variable is
quite large, but unacceptable if it is small.
Semi-continuous variables are useful where, if some variable is to be used at all, its value must be no less
than some minimum amount. For example, in a blending problem we might be constrained by practical
reasons either to use none of a component or at least 20 kg of it. This type of constraint occurs very
frequently in practical problems.
Semi-continuous integer variables often arise in shift planning modeling. If we are going to set up a
machine, then we have to run it for a whole number of shifts, and in any case for at least some minimum
number of shifts. For example, it might be possible only to run the machine for 0, or 12, 13, 14, ... shifts,
with the case of running it for 1, 2, ..., 11 shifts making no economic sense.
Special Ordered Sets of type 1 are often used in modeling choice problems, where we have to select at
most one thing from a set of items. The choice may be from such sets as: the time period in which to start
a job; one of a nite set of possible sizes for building a factory; which machine type to process a part on,
etc.
Special Ordered Sets of type 2 are typically used to model non-linear functions of a variable. They are
the natural extension of the concepts of Separable Programming, but when embedded in a Branch and
Bound code (see below Section 3.2) enable truly global optima to be found, and not just local optima.
(A local optimum is a point where all the nearest neighbors are worse than it, but where we have no
guarantee that there is not a better point some way away. A global optimum is a point which we know
to be the best. In the Himalayas the summit of K2 is a local maximum height, whereas the summit of
Everest is the global maximum height.)
Theoretically, models that can be built with any of the entities we have listed above can equally well be
modeled solely with binary variables. The reason why modern IP systems have some or all of the extra
entities is that they often provide signicant computational savings in computer time and storage when
trying to solve the resulting model. Most books and courses on Integer Programming do not emphasize
this point adequately. We have found that careful use of the non-binary global entities often yields very
considerable reductions in solution times over ones that just use binary variables.
3.2
We have seen that a rich modeling environment supplies more than just binary variables, and we shall
later see examples of using these extended entities, but we start the discussion of IP modeling by showing
the use of binary variables.
3.3.1
Do/dont do decisions
The most common use of binary variables is when we are modeling activities that either have to be done
in their entirety or not done at all. For instance, we might want to model whether we drive a particular
truck between city A and city B on a particular day. In this case we either do drive the truck or we do not
drive the truck at all: there are just two options. Typically we model the option of doing something by
having a binary variable being equal to 1, and the option of not doing the thing with the binary variable
being equal to 0. Thus we just have two choices, of which we must select one.
Associated with the activity and with its binary variable, there may be some other properties. Suppose
for instance we are considering what we do with the three trucks that we own. Truck 1 has a capacity of
20 tonnes, truck 2 has a capacity of 25 tonnes and truck 3 has a capacity of 30 tonnes. If on a particular
day we decide to send truck 1 to a customer then we either send the entire truck or we do not send the
entire truck. So we might have a decision variable (a binary variable) send1 taking the value 1 if we send
truck 1 out or 0 if we do not send truck 1. Similarly we will have another binary variable send2 which is
1 if truck 2 goes out and 0 otherwise; and variable send3 taking on the value 1 if truck 3 goes out, and 0
otherwise.
Elsewhere in the model we will probably be interested in the total tonnage that goes out on that particular day and we can see that this is
20 send1 + 25 send2 + 30 send3
because if truck 1 goes out (send1 = 1) it takes 20 tonnes, if truck 2 goes out it independently takes 25
tonnes, and if truck 3 goes out it carries 30 tonnes, so the total is 20 send1 + 25 send2 + 30 send3 .
Suppose that we have a decision variable called out which gives the total tonnage leaving our depot on
that particular day. Then we have the equation
out = 20 send1 + 25 send2 + 30 send3
33
3.3.2.1
The rst constraint that we might impose is we must choose no more than one project to do. We can
easily see that this can be expressed by the constraint
a+b+c+d+e+f +g+h1
Why is this true? Think of selecting one project, for instance project C. If c is 1 then the constraint
immediately says that a, b, d, e, f, g and h must be 0 because there is no other setting for the values of
these variables that will satisfy that constraint. So if c is 1 then all the others are 0 and, as there is nothing
special about C, we can see immediately that the constraint means that we can only do one project.
If the constraint was that we could do no more than three projects then obviously all we have to do in
the constraint above is to replace the 1 by 3 and then we can easily see that in fact we can have no more
than three of the 0-1 variables being equal to 1. It is possible to have just two of them or one of them or
even none of them being equal to 1 but we can certainly not have four or more being 1 and satisfy the
constraint at the same time.
Now suppose that the constraint is that we must choose exactly two of the projects. Then the constraint
we can use to model this is
a+b+c+d+e+f +g+h=2
Since the binary variables can take only the values 0 or 1, we must have exactly two of them being 1 and
all the rest of them being 0, and that is the only way that we can satisfy that constraint.
3.3.2.2
Simple implications
Now consider an entirely different sort of constraint. Suppose that if we do project A then we must do
project B. How do we model this? Like a lot of mathematics, it is a question of learning a trick that has
been discovered. Consider the following constraint
ba
To show that this formulation is correct, we consider all the possible combinations of settings (there are
four of them) of a and b. First, what happens if we do not do project A. If we also do not do project B
then the constraint is satised (0 = b a = 0) and our word constraint is satised. If, on the other hand,
we do do project B, then 1 = b a = 0, and the constraint is again satised. Now consider what happens
if we actually do project A, i.e. a = 1. Then the constraint is violated if b = 0 and is satised (0 is not 1)
if b = 1, in other words we do project B. The last case to consider is if we do not do project A, i.e. a = 0
and we do project B, i.e. b = 1. Then the constraint is satised (1 0) and the word constraint is indeed
satised. We can lay these constraints out in a table. There are only four possible conditions: {do A, do
B}, {do A, do not do B}, {do not do A, do not do B}, {do not do A, do B}, and we can see that the illegal
one is ruled out by the algebraic constraint.
Table 3.1: Evaluation of a binary implication constraint
ba
a=0
a=1
b=0
b=1
Yes
Yes
No
Yes
The next word constraint we consider is if we do project A then we must not do project B. How might
we set about modeling this? The way to think of it is to notice that the property of notdoing B can be
modeled very easily when we already have a binary variable b representing doing B. We invent a new
variable
b=1b
34
where b represents the doing of project B i.e., the project not doing B. If b = 1 then b = 0 (in other
words, if we do project B then we do not do not B) whereas if b = 0 then b = 1 (if we do not do project
B then we do project B). This is very convenient and b is called the complement of b. We can use this trick
frequently. Just above we learned how to model if we do A then we must do B and now we are trying
to model if we do A then we must not do B, i.e. if we do A then we must do B. As if we do A then we
must do B was modeled by b a we can immediately see that the constraint if we do A then we must
do B can be obtained by replacing b by b in the constraint, in other words b a. Replacing b by 1 b
we get
1ba
or
1a+b
or alternatively
a+b1
Now that we have obtained this constraint, it is quite obvious. What it says is that if we do project A (a =
1) then b must be 0. This is exactly what we wanted to model. The point of the somewhat long-winded
argument we showed above, however, is that we have used the result from the rst logical constraint
that we wanted to model, plus the fact that we have now introduced the notion of the complement of
the project, to build up a newer and more complicated constraint from these two primitive concepts. This
is what we will do frequently in what follows.
We see an example of this by trying to model the word constraint if we do not do A then we must do
B, in other word, if not A then B. We can go back immediately to our rst logical constraint if we do A
then we must do B which was modeled as b a. Now we are actually replacing A by not A, so we can
see immediately that our constraint is
b1a
which is
a+b1
Again this constraint is obvious now that we have got to it. If we do not do A then a = 0, so b 1 and
since the maximum value of b is 1 then this immediately means that b = 1. Again we have just taken our
knowledge of how to model if A then B and the notion of the complement of a variable to be able to
build up a more complex constraint.
The next constraint to consider is if we do project A we must do project B, and if we do project B we
must do project A. We have seen that the rst is modeled as b a and the second as a b. Combining
these two constraints we get
a=b
in other words projects A and B are selected or rejected together, which is exactly what we expressed in
our word constraint.
3.3.2.3
The next constraint we consider is if we do project A then we must do project B and project C. The rst
thing to note is that this is in fact two constraints. One, the rst, is if we do A then we must do project
B and the second constraint is if we do A then we must do project C. With this observation we can see
that the word constraint can be modeled by the two inequalities
b a and c a
so that if a = 1, then both b = 1 and c = 1.
Another constraint might be if we do project A then we must do project B or project C. It is like the
previous constraint, except we now have an or in place of the and. The constraint
b+c a
models this correctly. To see this, consider the following situation. If a is 0 then b + c can be anything, and
so b and c are not constrained. If a = 1, then one or both of b and c must be 1.
We may also try to model the inverse situation: if we do Project B or project C then we must do A. This
is again a case that may be formulated as two separate constraints: if we do B then we must do A and
if we do C then we must do A, giving rise to the following two inequalities
a b and a c
35
3.3.2.4
Generalized implications
Generalizing the previous we now might try to model if we do two or more of B, C, D or E then we must
do A, and our rst guess to this might be the constraint
ab+c+d+e1
Certainly if, say, b and c are both equal to 1 then we have a 1 and so a must equal 1, but the problem
comes when three of the variables are equal to 1, say b, c and d. Then the constraint says that a 3 1,
i.e. a 2, which is impossible as a is a binary variable. So we have to modify the constraint as follows
a
1
(b + c + d + e 1)
3
The biggest value that the expression inside the parentheses can take is 3, if b = c = d = e = 1. The 13
in front of the parenthesis means that in the worst case a must be 1 (so a is equal to 1). But we must
verify that the constraint is true if, say, just b = c = 1 (and d and e are equal to 0). In this case we have
that a 13 (1 + 1 + 0 + 0 1) i.e. a 13 . But since a can only take on the values 0 or 1 then the constraint
a 13 means that a must be 1. This is exactly what we want.
We can generalize this to modeling the statement if we do M or more of N projects (B, C, D, ...) then we
must do project A by the constraint
a
b + c + d+. . . M + 1
NM+1
So far we have only given one way of modeling each of these constraints. We return to the constraint if
we do B or C then we must do A which we modeled as two constraints a b and a c. It is possible to
model this with just one constraint if we take this as a special case of the M or more from N constraint
we have just modeled. If we do B or C then we must do A is the same as if we do M or more of N
projects (B, C, D, ...) then we must do project A with M = 1 and N = 2. So the constraint is
b+cM+1
i.e.
NM+1
b+c1+1
i.e.
a
21+1
1
a (b + c)
2
a
So this single constraint is exactly the same in terms of binary variables as the two constraints which we
produced before. Which of these two representations is better? In fact the representation in terms of
two constraints is better. But both of the two are correct and both will give a correct answer if put into
an Integer Programming system. It is just that the rst pair of constraints will in general give a solution
more rapidly.
More and more complicated constraints can be built up from the primitive ideas we have explored so far.
Since these more complicated constraints do not occur very frequently in actual practical modeling we
shall not explore them further. Table 3.2 summarizes the formulations of logical conditions we have seen
in the different paragraphs of Section 3.3.2.
36
b2
b3
b3 = b1 b2 ?
b3 b1 ?
b3 b2 ?
b3 b1 + b2 1?
0
0
0
0
1
1
1
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
Yes
No
Yes
No
Yes
No
No
Yes
Yes
No
Yes
No
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
We can see that the column headed b3 = b1 b2 ? is true if and only if we have a Yes in the three columns
b3 b1 ?, b3 b2 ? and b3 b1 + b2 1?, so the three linear equations do exactly represent and are true
at exactly the same time as the product is true.
This is a particularly long winded way of demonstrating the equivalence of the product term and the
three linear equations and in fact now we have got it it is actually quite easy to see why these three
inequalities are correct. Since b3 is b1 multiplied by something that is less than or equal to 1, b3 will
always be less than or equal to b1 and by a similar argument b3 will always be less than or equal to b2 .
The only further case we have to consider is when both b1 and b2 are equal to 1 and then we have to
force b3 to be equal to 1. This is done by the constraint b3 b1 + b2 1 which is non restrictive if only
one or none of b1 and b2 are 1 but forces b3 to be 1 when b1 = b2 = 1.
Looking at the constraint this way immediately enables us to model for instance
b4 = b1 b2 b3 ,
in other words the product of three variables, as the four constraints
b4 b1
37
b4 b2
b4 b3
b4 b1 + b2 + b3 2
If any of b1 , b2 and b3 are 0 then b4 must be 0 but if b1 , b2 and b3 are 1 then b4 must be greater than or
equal to 3 2, i.e. b4 must be greater than or equal to 1 so b4 must be 1.
Z = x1 + x2
x1 0, x2 0 and
subject to
x2
Z=
c2
Z=
2
3
Z=
Z=
1
G
2
c1
x1
3.4
2 x1 + x2 + x3 0
2 x1 + x2 + x3 6
x 1 + 2 x2 + 3 x3 7
x 1 + 2 x2 + 3 x3 0
Constraint 2 is satised
Constraint 1 is satised
38