Professional Documents
Culture Documents
Textbooks
Textbooks
Williams, Gueret a. o.
Tony Hürlimann
Department of Informatics
University of Fribourg
CH – 1700 Fribourg (Switzerland)
tony.huerlimann@unifr.ch
February 1, 2021
Copyright © 2021
All rights reserved. Department of Informatics
University of Fribourg
CH-1700 Fribourg Switzerland
Email: tony.huerlimann@unifr.ch
WWW: http://www.virtual-optima.com
i
ii
C ONTENTS
1 Introduction 3
1.1 Model and Related Concepts . . . . . . . . . . . . . . . . . . 4
1.2 The Model Building Process . . . . . . . . . . . . . . . . . . . 6
1.3 The Modeling Language LPL . . . . . . . . . . . . . . . . . . 10
1.4 Mathematical Notation . . . . . . . . . . . . . . . . . . . . . 16
1.4.1 Set-Names versus Index-Names . . . . . . . . . . . . . 16
1.4.2 Logic-mathematical Notation . . . . . . . . . . . . . . 17
1.4.3 Logical Operators . . . . . . . . . . . . . . . . . . . . 18
6 Billonnet 393
6.1 A MIQP problem (Bill018) . . . . . . . . . . . . . . . . . . . 393
6.2 Localisation Optimal (Bill023) . . . . . . . . . . . . . . . . . . 394
6.3 Optimal Portefolio (Bill026) . . . . . . . . . . . . . . . . . . . 396
ix
6.4 Optimal Positioning on the Market (Bill028) . . . . . . . . . . 398
6.5 An iQP Problem: Clustering (Bill035) . . . . . . . . . . . . . . 402
6.6 Fraction Objective (Bill046) . . . . . . . . . . . . . . . . . . . 404
6.7 Optimal Portefolio (Bill053) . . . . . . . . . . . . . . . . . . . 407
6.8 Piecewise Linear Function (Bill227) . . . . . . . . . . . . . . . 409
6.9 A Cost Flow Problem (bill320) . . . . . . . . . . . . . . . . . 412
7 Miscellaneous 419
7.1 A simple blending problem (alloy) . . . . . . . . . . . . . . . 419
7.2 Assign Consulters (assign1) . . . . . . . . . . . . . . . . . . . 420
7.3 Agriculture Production (crop) . . . . . . . . . . . . . . . . . 421
7.4 Import and Export Goods (export) . . . . . . . . . . . . . . . 422
7.5 A Small Portfolio Model (lin193) . . . . . . . . . . . . . . . . 423
7.6 Exposures in Media Vehicles (media) . . . . . . . . . . . . . . 424
7.7 Mexican Steel Industry (mexican) . . . . . . . . . . . . . . . . 425
7.8 A Production Planning Model (omp) . . . . . . . . . . . . . . 427
7.9 One Machine Scheduling (ordon) . . . . . . . . . . . . . . . . 430
7.10 A Transport Model Fragment (pam) . . . . . . . . . . . . . . 431
7.11 The Beer Game (beergame) . . . . . . . . . . . . . . . . . . . 432
7.12 Production Planning (aggrplan) . . . . . . . . . . . . . . . . 436
7.13 Production Planning (planning) . . . . . . . . . . . . . . . . 438
7.14 Multiperiod Production (prod) . . . . . . . . . . . . . . . . . 439
7.15 Production and Planning (prodplan) . . . . . . . . . . . . . . 442
7.16 Production and Shipment Planning (prodship) . . . . . . . . . 444
7.17 A Production Model (produ) . . . . . . . . . . . . . . . . . . 448
7.18 Multiperodic Production Planning (product) . . . . . . . . . . 450
7.19 Multiperiod Production Scheduling (schedule) . . . . . . . . 454
7.20 Multiperiod Production Scheduling (schedule) . . . . . . . . 455
7.21 Tanglewood Chair Manufacturing (tangle) . . . . . . . . . . . 456
7.22 A Travel Optimization Problem (travel) . . . . . . . . . . . . 457
7.23 Multi-period Blending Problem (xpress) . . . . . . . . . . . . 458
x
L IST OF F IGURES
xi
L IST OF TABLES
4.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
4.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
4.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
4.4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
4.5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284
4.6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310
4.7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312
4.8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313
4.9 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316
4.10 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317
4.11 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319
4.12 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325
4.13 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325
4.14 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328
4.15 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 330
4.16 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 332
4.17 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 332
4.18 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334
4.19 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 338
4.20 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 339
4.21 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342
4.22 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344
xiii
P REFACE
Chapter 3 contains all 65 models from the French book of Guéret Christelle,
Prins Christian and Sevaux Marc (see [5]. The book has been translated to
English by Dash Optimization and is available as [28] (it can be downloaded
from the Internet and is free. The last chapter 14 of [5] has not been trans-
lated, so I give the original French version of the models. Some models that
I used in my master courses have additional comments and explanation, but
most of them only contain the bare bone LPL implementation that can also be
executed directly though the Internet.
The reader does not need to install any software to run and solve the models
compiled in this text. Only an Internet browser and an Internet connection is
needed. A link appears in the title of each model. Click on it, and you are on
the Internet site where the model is prompted in a text box. You can modify
it interactively. Clicking the button “Send” on the web page, sends the model
to the LPL-server, runs it and returns the result after it has been solved in a
new browser page. If you know well the syntax of LPL, you can even write an
entirely new model and present it to the LPL-server as well. Just click “Send”
to solve it.
However, the solution time is limited to 60secs, and large ans complex models
cannot be solved this way.
The book was compiled using the typesetting system LATEX. However, the
documentation of all models was written in LPL’s own “literate documenta-
tion system”. LPL contains a documentation tool (similar to javadoc for Java
programs) to automatically translate a documented model into a full LATEX
code. Additional information for this tool can be found in the Reference Man-
ual of LPL [29].
The mathematical modeling and all case studies in this book are based on
the software LPL. It is my own contribution to the field of computer-based
mathematical modeling.
Currently, there is an implementation for Windows. A Linux console version
is available – write me an email.
LPL – the software – together with documentation containing the Reference
Manual, several papers and examples can be downloaded at:
www.virtual-optima.com
The paper’s home page can be found at any of the two locations:
I NTRODUCTION
This chapter introduces briefly the concept of a model and related notions.
Then it gives a rudimentary overview of the model building process in the
way it is used for the examples in the following chapters. Finally, since all
models are formulated in the executable modeling language LPL, the basic
elements of this language are briefly presented.
3
CHAPTER 1. INTRODUCTION 4
further research and queries varying the initial questions and problems.
It is often said that modeling skills can only be acquired in a process of learning-
by-doing; like learning to ride a bike can only be achieved by getting on
the saddle. It is true that the “case study approach” is most helpful, and
many university courses in (mathematical) modeling use this approach. But
it is also true – once some basic skills have been acquired – that theoretical
knowledge about the mechanics of bicycles can deepen our understanding
and enlarge our faculty to ride it. This is even more important for model-
ing industrial processes. It is not enough to exercise these skills, one should
also acquire methodologies and the theoretical background of modeling. In
applied mathematics, more time than it is currently spent, should be given
to the study of discovery, expression and formulation of the problem, initially in
non-mathematical terms. So, the novice first needs to be an observer and then,
very quickly, a doer. Modeling is not learnt only by watching others building
models, but also by being actively and personally involved in the modeling
process.
CHAPTER 1. INTRODUCTION 6
The use of computer modeling tools to simulate, visualize, and analyze math-
ematical structures has spread steadily. In the eighties, the “micro-computer”
– a word which disappeared as quickly as it emerged – was the archetype of a
whole generation of self-made quick and messy models. Everyone produced
their own simulation tool, mathematical toolbox, etc. This phenomenon has
now almost vanished. We have powerful packages such as Mathematica,
Maple, Axiom, the NAG-library, Matlab, R, Python packages, Julia packages,
and powerful MIP solvers to mention just a few, for solving complex prob-
lems. But the modeling process still needs more than easy-to-use solving
tools: It also needs tools to integrate different tasks: such as data manipulation
tools, representation tools for the model structure, viewing tools to represent
the data and structure in different ways, reporting tools, etc. Some tasks can
be done by different software packages: data are preferably manipulated in
databases and spreadsheets, and are best viewed by different graphic tools.
This brings us to the heart of this book: Modeling is still an art with tools
and methods built in an ad-hoc way for a specific context and for a particu-
lar type of model. While I believe that modeling will always be an art in the
sense of a creative process, I also believe that we can build general computer-
based modeling tools that can be used not only to help to find the solution to a
mathematical model, but also to support the modeling process itself. The ex-
traordinary advances in science, on one hand, and in computing performance,
on the other hand, leave a cruel gap that can be bridged by general and effi-
cient modeling management systems and mathematical modeling languages.
As already mentioned, all models presented in this book are formulated with
the modeling language LPL. After the problem is formulated in this language
specification, our task is finished. The rest – solving a model instance – will
be done by the software.
A small example follows to illustrate the main points. Suppose you have to
solve the following problem:
CHAPTER 1. INTRODUCTION 8
“Knowing that the length plus the width of a rectangle is 27, while the area
plus the difference of the length and the width is 183, find the length and
width!”
One of the key steps in mathematical modeling is to find out what we are
looking for. In this example, it can easily be stated: we are looking for the
length and the width of the rectangle. So, we immediately introduce two sym-
bols for them: L and W. Passing from the words to the symbols is a crucial
and necessary step and should not be underestimated when building a math-
ematical model. One of the difficulties in modeling often stems from the fact,
that we cannot easily identify the “objects” in the problem. If we have iden-
tified all essential objects, we have reached an important milestone. The rest
often follows straight away.
Now, having L and W, we can easily derive from the first part of the statement
that their sum is 27. Therefore, we write it down as: L + W = 27. Write it down
on a piece of paper! Do not do it mentally only! The paper is patient, you can throw
it away and begin again from scratch! The second part of the statement says, that
the area plus the difference is 183. The area is L·W and the difference is L−W.
Therefore we have L · W + L − W = 183. Did we use all information? Yes! Is
something missing? No! Well, probably not. Can we now derive, what L and
W are? Yes! So, let’s see. We now have:
L + W = 27
L · W + L − W = 183
The problems here and their well polished models in the next chapters give
the impression that modeling is easy and straightforward. It is not! The main
goal of this text is to give you the complete solution on the modeling process,
indeed. But I also try to give you a possible step by step procedure on how
one could model them. Of course, this itself is an elaborated recipe on how to
proceed. In reality, it was a “painful” process that was anything but a straight
path. This has to be kept in mind, when you are going through these steps
of modeling. Nevertheless, it can be helpful to learn techniques and methods
on how to build models, on how to attack a problem. To stimulate further
your capability of modeling, each “case study” contains a number of ques-
tions that you can solve yourself. The proposed answer, also given in this
text, is not necessarily the “right” approach, but gives you an indication how
9 CHAPTER 1. INTRODUCTION
I did it. Maybe this also has an educational effect. Anyway, the reader can
only learn something from the examples, when he goes through all steps and
questions himself. It is better to find a wrong answer (which can be corrected
afterwards) than to look up the solution right away.
The approach, I propose for the case studies, is as follows: First, the prob-
lem is presented by a short description, this is marked by a title Problem.
The information given in this part should be enough to get started with the
modeling steps.
Next follows a polished procedure of the model building steps in Modeling
Steps. Normally, we begin by identifying the data, that means, the sets and the
numerical data used in the model. The critical step is the introduction of the
variables. The reader should be convinced that he understood this important
part in the model building process. Often the introduction of the variables
determine the rest of the modeling process. In the next step, we develop the
conditions (the constraints) that hold about the variables. Finally, the goal, the
objective function, is put forward.
The presentation of the model building process is normally given by enumer-
ating the steps to suggest to the reader a logical and sequential order he can
follow. Again the reader, nevertheless, should be aware, that this sequential
ordering is only an already polished outline of the real model building pro-
cess. It is itself already an abstraction of the labyrinthine process of modeling.
However, I did not find a better way of presenting this process. I also wanted
to break it down to the main points. To describe the “real process” – of what
is really going on in the brain when modeling – is also not what is actually
needed to reconstruct and comprehend the model building process. It would
be a lengthy explanation of all the intricate and nebulous thoughts that one
goes through while modeling. Modeling can be learnt, but not by following
the connotations and tortuous brainwork that one goes through actually. It
can only be learnt using case studies, if the presentation itself is a clear and
unequivocal synopsis of the main steps. If the classical outline proposed in
this book (data – variables – constraints) is the right one, is an open question.
Surely, other methods exist.
After the presentation of the modeling steps, a short paragraph follows to lay-
out the solution of the problem. This solution is normally found by running
the model on the computer. Sometimes hints are given to check the result and
to verify its correctness.
Finally, each case study ends with some questions. The reader can test his
comprehension and explore model variants. The questions should stimulate
him to investigate various topics.
CHAPTER 1. INTRODUCTION 10
There is one important difference between mathematical sets and sets in LPL:
Sets (also called index-sets) in LPL are always ordered. These sets can then be
used to build vectors, matrices, and higher dimensional tables of parameters
(the data), variables, or constraints. For example, the two-dimensional table
11 CHAPTER 1. INTRODUCTION
can be declared in LPL as follows (the single entries are listed in lexicograph-
ical ordering, row by row from left to right, the commas are optional):
parameter a{i,j} := [1 2 3 , 4 5 6 , 7 8 9];
The main difference between the mathematical notation and LPL’s notation
is that in LPL we do not need to distinguish between the set names and the
index names. Of course, we could also write:
set I; J; -- set name uppercase
parameter a{i in I,j in J}; -- index names lowercase
to make a difference between set name and index name, but this is not nec-
essary in most contexts. A further difference, as already mentioned, between
mathematical sets and sets defined in LPL is that mathematical sets are un-
ordered, while in LPL they are always ordered. However, this difference only
becomes important when we are referencing, for example, the elements by
their relative or absolute position, as in expression i − 1 (an expression that
returns the previous element of element i).
A declaration of a vector of unknown quantities (called variables) is written
in mathematical notation as xj with j ∈ J. In LPL we write it as follows:
variable x{j};
The expression [0..100] means that the integer variables x{j} are bound
to the range [0 . . . 100]. Binary variable can only be zero or one. This means:
yi ∈ {0, 1} with i ∈ I.
Constraints are defined in the same way. A constraint vector:2
2 P
The formula uses a very common mathematical symbol ( ), which is a shortcut for
a summation. Hence,
X
xj with J = {1 . . . n} is the same as x1 + x2 + . . . + xn
j∈J
where n is a positive integer. It is supposed that the reader is familiar with this
notation. In the context of this book and if it is clear to which set the index j is
CHAPTER 1. INTRODUCTION 12
X
xj + yi ≤ 10 for all i ∈ I
j∈J
In LPL, each constraint has a name (here D) and can be indexed like a variable
or a parameter. If the context allows it, the indexes within the expressions
can even be dropped (but this is a matter of style). So the constraint can also
compactly be written as follows:
constraint D{i}: sum{j} x + y <= 10;
The solve statement is identical to the constraint, except that it begins with
the keyword maximize or minimize. If there is no objective function and
we are only looking for a feasible solution then in LPL we can just use the
keyword solve.
maximize obj: sum{j} x;
minimize obj: sum{j} x;
solve;
A Simple Example
Suppose your company produces laptops and printers. A laptop takes 6 hours
of work and generates a revenue of 300= C, while a printer takes 2 hours of
work and generates a revenue of 200= C. Furthermore, the space in our labo-
ratory is limited to 350m2 and each product takes 5m2 of space. We want to
find the “best” production mix, that means, how many of each can be man-
ufactured in a week, if the total hours of work is limited to 300 hours per
week?
referring, we also often use the shorter notation
X X
xj instead of xj with J = {1 . . . n}
j j∈J
In concordance with the LPL syntax, we often do not introduce the symbol for the
set J, we just use a index name j. So we use the notation
j ∈ {1 . . . n} instead of j ∈ J , J = {1 . . . n}
13 CHAPTER 1. INTRODUCTION
6x+
2y=
300
C
5x
+5y
=3
50
A D x
To find the optimal production mix, we introduce two symbols x and y for the
(unknown) quantities for the two products. Then the production is limited to
6x + 2y ≤ 300 hours, and to 5x + 5y ≤ 350 m2 . This is best displayed by
a diagram (see Figure 1.1). The points (x, y) within the quadrangle ABCD
are the only points that do not violate the two requirements. The point C
= (40, 30) is particularly interesting, because it defines the production mix
with the highest revenue, that means, 300x + 200y – the revenue of the mix
– cannot be larger without violating either the time or the space constraint.
Mathematically we say, that point C maximizes the expression 300x + 200y.
We can formulate the problem as a linear system in the following way:
The formulation says to maximize an expression such that the “subject to”
conditions (called constraints) are fulfilled. In LPL the problem can be formu-
CHAPTER 1. INTRODUCTION 14
An even more compact formulation using matrix notation for the model is:
max cx
subject to Ax ≤ b
x≥0
This is very close to the mathematical notation. The model first declares the
two sets i and j. The data matrix and the two vectors are compactly declared
as Ai,j , cj and bi .4 There size will depend of the number of elements of the
two sets. The variable vector xj is also declared in a similar way. (The posi-
tivity of the variable is automatically assumed by LPL, if no range is given.)
3
http://lpl.virtual-optima.com/lpl/Solver.jsp?name=/tutor01
4
Note – as already mentioned – in LPL syntax index names can be the same as set
names if no ambiguity is created.
15 CHAPTER 1. INTRODUCTION
The constraints and the maximizing function are also very close to the math-
ematical notation. The model does not contain data. They can be added by
a separate submodel. For example, to formulate the small example above in
this general form, the data can be added as :
model data;
i := [1..2]; j := [1..2];
A{i,j} := [6 2 , 5 5];
c{j} := [300 200];
b{i} := [300 350];
end
Data – we already gave an example – can be placed within the model code or
it can be read from files using the Read function. The following data matrix:
2 3 −4 1 15
−5 4 8 1 5
ai,j = 2 1 14 1 17 with i ∈ I, j ∈ J
3 4 5 1 7
0 8 −3 10 1
The matrix elements are listed in lexicographical order (other formats exist).
Of course, for large data tables, it is better to read them from files or database
tables. A comma-separated second identifier just introduces another name
for the same set. Hence, i and j represent the same set, but they may be used
as different index names.
Writing the results can be done using the Writep and Write functions. The
simplest way to output the values of the variable vector x{j} is as follows;
Writep(x);
The string in single quotes contains the literal text and formatting instructions
that must be written. %s is a place holder for strings and %6.2f is a place
holder for floating point data (with width 6 and 2 decimals). The values of the
following two parameters ,j,x replace the placeholders in the string. This
expression means to write (for each element in the set j) on a separate line the
following two elements, that is (j,x). More information on this powerful
“reporting instruction” can be found in the reference manual of LPL.
CHAPTER 1. INTRODUCTION 16
Data can also be assigned by the assignment instruction. The table assignment
Another often used instruction in the presented case studies is the for loop.
Suppose, one would like to optimize a model 10 times (with different param-
eters), then one could write:
set loop := [1..10];
for{loop} do
maximize obj: ... ;
....
end
The reader should now be able to read and recognize the most basic state-
ments of LPL in order to work with the case studies in the following chapters.
There is no room here to explain each detail of the language. The interested
user can get a free LPL version together with the definite language reference
guide and tutor examples. It can be downloaded from the LPL-site.
The LPL syntax uses some shortcuts in mathematical notation which is re-
flected also in the notation of mathematical expressions used in this book. As
already mentioned, one can use an set name also as an index name and vice
versa. So we use the following shorter notation in LPL :
set i := 1..10;
set j := 1..5;
parameter b{i,j} := i*j;
parameter a{i} := sum{j} b[i,j];
instead of the longer notation (although this second notation is also perfectly
correct in LPL) :
17 CHAPTER 1. INTRODUCTION
set I := 1..10;
set J := 1..5;
parameter b{i in I,j in J} := i*j;
parameter a{i in I} := sum{j in J} b[i,j];
This is also reflected in the mathematical notation often used in this book as :
i·j
bi,j =X for all i, j
ai = bi,j for all i
j
i ∈ {1, . . . , 10}
j ∈ {1, . . . , 5}
instead of the usual notation :
i·j
bi,j =X for all i ∈ I, j ∈ J
ai = bi,j for all i ∈ I
j∈J
i∈I I = {1, . . . , 10}
j∈J J = {1, . . . , 5}
The difference is that we do not use the set names I or J, if the context is clear,
only index names i or j are written.
LPL does not distinguish between Boolean and mathematical operators. All
Boolean operator return 0 or 1, which might be interpreted as false and true.
Hence, one can mix these operators in an expression. This is also true in
constraints. We may write, for example:
a=0 or b=1
(a=1) + (b=10)
LPL uses various logical and Boolean operators that can also be used in con-
straints, see Table 1.1. Many problems can be formulated using Boolean or
logical constraints.
“Approach your problem from the right end and begin with the
answer. Then one day, perhaps you will find the final ques-
tion.”
— R. van Gulik
“It isn’t that they can’t see the solution. It is that they can’t see
the problem.”
— G. K. Chesterton
This chapter presents all the models exposed in the famous modeling book
of Williams [17]. All models are implemented in LPL and can be executed
straight away.
19
CHAPTER 2. PROBLEMS FROM WILLIAM’S BOOK 20
1. The food may never be made up of more than three different oils.
2. If an oil is used at least 20 tons must be used.
3. If either vegetable oil Veg1 or Veg2 is used, then non-vegetable oil
Oil3 must also be used.
Model: The Model is as follows:The problem is from [17] Chapter 12.2. The
model is the same as will011 , with exception of the additional restrictions. to
impose these conditions we introduce a 0-1 variable d which is 1 only if the
qunatity used (use) of an oil is not zero, that is we must impose:
use > 0 ↔ d = 1
Model: The Model is as follows:The problem is from [17]. For a problem de-
scription see Chapter 13.4. Note that this is the same model as will032 except
that down is now a variable.
Redundant, D{s,y};
ShortTime, S{s,y} [0..MaxShortTimeWorking];
OverManned,O{s,y};
expression
TotalRetrainCost : sum{y,s} RetrainCost*T[s,s+1,y];
TotalRedundantCost : sum{s,y} RedundantCost*D;
TotalShortTimeCost : sum{s,y} ShortTimeCost*S;
TotalOverManningCost: sum{s,y} OverManningCost*O;
TotalManpowerCost:TotalRetrainCost+TotalRedundantCost
+TotalOverManningCost + TotalShortTimeCost;
TotalRedundantMen : sum{s,y} D;
constraint
Continuity{s,y}: L =
ContinueEachYear*if(y=1,CurrentStrength,L[s,y-1])
+ ContinueFirstYear*R + 0.95*T[s-1,s,y]
+ sum{t} ContinueDownGraded*T[s+t,s,y]
- sum{t} T[s,s-t,y] - T[s,s+1,y] - D;
RetainMaxUnskilled{y}:
T['Unskilled','SemiSkilled',y]<=200;
RetrainingSemiSkilled{y}: T['SemiSkilled','Skilled',y]
<= RetrainSemiSkilled*L['Skilled',y];
OverManning{y}: sum{s} O <= MaxOverManning;
Requirements{s,y}: L = Requirement+O+ShortTimeUsage*S;
minimize TotalRedundancy: TotalRedundantMen;
Writep(TotalManpowerCost,TotalRedundantMen,
Recruite,Retrain,ShortTime,OverManned);
end
CHAPTER 2. PROBLEMS FROM WILLIAM’S BOOK 28
MinLubeOil := 500;
MaxLubeOil := 1000;
MinPremiumProdPct := 0.40;
Profit{p} := [7.00 6.00 4.00 3.50 1.50];
variable
FinalProduct{p}; PurchaseCrude{c};
DistillOutput{f}; NaphthaForReformGas{n};
ReformedGasoline; OilForCracking{o};
CrackedOutput{a}; NaphthaForMotorFuel{n,m};
ReformedGasForMotorFuel{m};
CrackedGasForMotorFuel{m};
OilForJetFuel{o}; ResiduumForJetFuel;
CrackOilForJetFuel; ResiduumForLubeOil;
maximize TotalProfit: sum{p} Profit*FinalProduct;
constraint
DistillLimit "At most 45000 barrels of crude can be
distilled per day":
sum{c} PurchaseCrude <= DistillCapacity;
ReformingLimit "At most 10000 barrels of naphtha can
be reformed per day":
sum{n} NaphthaForReformGas <= ReformingCapacity;
CrackingLimit "At most 8000 barrels of oil can be
cracked per day":
sum{o} OilForCracking <= CrackingCapacity;
DistillationBalance{f} "Balance crude inputs to
distillation outputs":
sum{c} DistillYld*PurchaseCrude = DistillOutput;
ReformedGasBalance "Balance naphtha inputs to
reformed gas output":
sum{n} ReformingYield*NaphthaForReformGas =
ReformedGasoline;
CrackBalance{a} "Balance oil inputs to cracked output
":
sum{o} CrackingYield*OilForCracking =
CrackedOutput;
ResiduumLubeOil "Each barrel of residuum yields 0.5
barrels of lube oil":
ResiduumLubeOilYield*ResiduumForLubeOil =
FinalProduct['LubeOil'];
DivideReformGas "Divide reformed gas to motor fuels":
ReformedGasoline = sum{m}ReformedGasForMotorFuel;
DivideNaphtha{n} "Divide naphthas to reformed gas and
motor fuels":
DistillOutput = NaphthaForReformGas + sum{m}
NaphthaForMotorFuel;
DivideOil{o} "Divide light/heavy oils to cracking,
jet fuel, and fuel oil":
DistillOutput = OilForCracking + OilForJetFuel +
FuelOilRatio*FinalProduct['FuelOil'];
DivideCrackGas "Divide cracked gasoline to motor
CHAPTER 2. PROBLEMS FROM WILLIAM’S BOOK 30
fuels":
CrackedOutput['CrackedGasoline'] = sum{m}
CrackedGasForMotorFuel;
DivideCrackedOil "Divide cracked oil to jet fuel and
fuel oil":
CrackedOutput['CrackedOil'] = CrackOilForJetFuel
+ FuelOilRatioCrackedOil*FinalProduct['FuelOil'];
DivideResiduum "Divide Residuum to jet fuel, fuel oil
, and lube oil":
DistillOutput['Residuum'] = ResiduumForJetFuel
+ FuelOilRatioResiduum*FinalProduct['FuelOil'] +
ResiduumForLubeOil;
BlendMotorFuel{m} "Blending motor fuels from naphtha,
reformed gas, and cracked gas":
FinalProduct = sum{n} NaphthaForMotorFuel +
ReformedGasForMotorFuel +
CrackedGasForMotorFuel;
BlendJetFuel "Blending jet fuel from light/heavy oils
, cracked oil and residuum":
FinalProduct['JetFuel'] = sum{o} OilForJetFuel +
CrackOilForJetFuel + ResiduumForJetFuel;
MaxVaporPressure "Jet fuel maximum vapor pressure":
sum{o} VaporPressure*OilForJetFuel +
VaporPressureCrackedOil*CrackOilForJetFuel
+ VaporPressureResiduum*ResiduumForJetFuel <=
FinalProduct['JetFuel'];
MinPremFuel "Premium fuel at least 40% of Regular":
FinalProduct['PremiumFuel'] >= MinPremiumProdPct*
FinalProduct['RegularFuel'];
MinOctFuel{m} "Motor fuels minimum octane levels":
sum{n} OctaneNumberNaphtha*NaphthaForMotorFuel
+ OctaneNumberReformedGas*ReformedGasForMotorFuel
+ OctaneNumberCrackedGas*CrackedGasForMotorFuel
>= MinOctaneLevel*FinalProduct;
C{c}: PurchaseCrude <= CrudeDailyAvail;
D: MinLubeOil<= FinalProduct['LubeOil'] <=MaxLubeOil;
Writep(TotalProfit);
SetFocus(); //write all variables
while NextFocus(3) do
while NextPosition() do
Write('%-47s %d\n', GetName(0), GetValue(0));
end;
end
end
31 CHAPTER 2. PROBLEMS FROM WILLIAM’S BOOK
GR <= GrainYld*GrainArea;
ACREAS{t} "Acreage limitation":
sum{i} 1/GrainYld*GR + 2/3*SB + 2/3*NEWCOW
+ 2/3*COWS[1,t] + sum{j1} COWS[j1,t] <= 200;
LABOUR{t} "Labour in 100 hours":
0.1*NEWCOW + 0.1*COWS[1,t] + sum{j1} 0.42*COWS[j1,t]
+ sum{i} 0.04/GrainYld*GR + 0.14/1.5*SB <= 55+EXLAB;
-- continuity constraints
CTA{t|t<#t}: COWS[1,t+1] = 0.95*NEWCOW[t];
CTB{t|t<#t}: COWS[2,t+1] = 0.95*COWS[1,t];
CT{j1,t|t<#t}:COWS[j1+1,t+1] = 0.98*COWS[j1,t];
CTC{t}: NEWCOW - sum{j1} 0.55*COWS[j1,t] + HFSELL = 0;
ENDT "Cows at the end": 50<= sum{j1} COWS[j1,5] <=175;
PROFIT{t}:
sum{j1} 16.5*COWS[j1,t] + 40*HFSELL + 120*COWS[12,t]
+ sum{j1} 370*COWS[j1,t] + 75*GRSELL + 58*SBSELL
- 90*GRBUY - 70*SBBUY - 120*EXLAB - 50*NEWCOW
- 50*COWS[1,t] - sum{j1} 100*COWS[j1,t]
- sum{i}15/GrainYld*GR - 20/3*SB - sum{t}39.71*EXCAP
- PROF = 4000;
-- initial conditions, fixing number of cows of each
age at first period
BOUNDS1{j}: COWS[j,1] = if(j<3 , 9.5 , 9.8);
-- maximize profit minus discounted capital expenditures
maximize TProf: sum{t} (PROF-158.85*EXCAP-39.71*t*EXCAP);
Writep(TProf,GR,SB,GRBUY,GRSELL,SBBUY,SBSELL,EXLAB,
EXCAP,HFSELL,COWS,NEWCOW,PROF);
end
CHAPTER 2. PROBLEMS FROM WILLIAM’S BOOK 36
Writep(obj,y,x,s);
consum{o}:=0; /*ignore the exogenous demand*/
maximize obj1: sum{o,t|t>=#t-1} x[o,t];
Write('-- (2) maximize the final output\n');
Writep(obj1,y,x,s);
consum{o}:=consum1; /*recopy the original consum*/
maximize obj2: sum{t,o} (Mreq*x[o,t+1] + Mcap*y[o,t+2])
subject_to (Will09, ~Manpower);
Write('-- (3) maximize the manpower requirement\n');
Writep(obj2,y,x,s);
end
CHAPTER 2. PROBLEMS FROM WILLIAM’S BOOK 38
An alternative is the objective in the model code together with the two con-
straints La and Lb .
CHAPTER 2. PROBLEMS FROM WILLIAM’S BOOK 40
1. Find a straight line, such that the sum of absolute deviation of all cor-
responding values are minimized.
2. Find a straight line, such that the maximum deviation is minimized.
(Note that the standard way to model this is by regression and we minimize
the sum of the quadratic deviations. In this approach different measures of
“deviations” are used.)
Modeling Steps
The problem is from [17]. For a problem description see Chapter 13.11.
Define the data: A set I of points (x, y) is given. Model this be two vectors xi
and yi , for each point i ∈ I.
1. The only part in the model that changes is the constraint DEV. It must
be replaced by the following constraint:
DEV{i}: y = A*x^2 + B*x + C + P - N;
3
http://lpl.virtual-optima.com/lpl/Solver.jsp?name=/will11a
43 CHAPTER 2. PROBLEMS FROM WILLIAM’S BOOK
4
http://lpl.virtual-optima.com/lpl/Solver.jsp?name=/will11
CHAPTER 2. PROBLEMS FROM WILLIAM’S BOOK 44
Model: The Model is as follows:The problem is from [17]. For a problem de-
scription see Chapter 13.12. This problem also appeared in Williams H.P., Ex-
periments in the formulation of integer programming problems, Math. Prog.
Study, 2, pp.180-197.
Explanation: The nor-gate is a device that has exactly two entries a and b with
value 0 or 1, and exactly one output c with value 0 or 1. The device simulates
the Boolean nor (not or) function: c = ¬(a ∨ b). We use also the operator | for
the nor operation, hence, it can also be written as c = a|b (Figure 2.3).
a ∧ b ≡ (a|0)|(b|0)
a∨
˙ b ≡ ((a|0)|(b|0)) | (a|b)
Note that the solution of the model exposes exactly the circuit given in Figure
2.4.
CHAPTER 2. PROBLEMS FROM WILLIAM’S BOOK 46
Model: The Model is as follows:The problem is from [17]. For a problem de-
scription see Chapter 13.13. This problem also appeared in Williams H.P., Ex-
periments in the formulation of integer programming problems, Math. Prog.
Study, 2, pp.180-197.
Model: The Model is as follows:The problem is from [17]. For a problem de-
scription see Chapter 12.13. This problem also appeared in WILLIAMS H.P.,
Experiments in the formulation of integer programming problems, Math. Prog.
Study, 2, pp.180-197.
Extra tighter forms of constraints OILA, OILB, OILC have been added. These
have been derived by LP using roofs and ceilings of the original constraints.
LOA{r}:=[2,3,3,4, 4, 4, 5, 5];
UOB{r}:=[. . . . . . . . 8,8,13,14,14,13,17,19,28,34];
LOB{r}:=[. . . . . . . . 8,9,14,15,15,14,18,20,30,36];
UOC{r}:=[. . . . . . . . . . . . . . . . . .
1,2,2,3,4];
LOC{r}:=[. . . . . . . . . . . . . . . . . .
1,2,2,3,5];
variable
P{k}; -- positive deviation
N{k}; -- negative deviation
MAXDEV [0..120];
binary M{r}; -- 1 if retailer is assigned to division
A
constraint
DELIVER: sum{r} T[1,r] *M[r] +P[1]-N[1]=0.4*Total[1];
SPIRITS: sum{r} T[2,r] *M[r] +P[2]-N[2]=0.4*Total[2];
OILA: sum{r1} T[3,r1]*M[r1]+P[3]-N[3]=0.4*Total[3];
OILB: sum{r2} T[3,r2]*M[r2]+P[4]-N[4]=0.4*Total[4];
OILC: sum{r3} T[3,r3]*M[r3]+P[5]-N[5]=0.4*Total[5];
GROWTH: sum{r} T[4,r] *M[r] +P[6]-N[6]=0.4*Total[6];
NUOILA: sum{r1} UOA[r1]*M[r1] <= 33;
NLOILA: sum{r1} LOA[r1]*M[r1] >= 11;
NUOILB: sum{r2} UOB[r2]*M[r2] <= 75;
NLOILB: sum{r2} LOB[r2]*M[r2] >= 63;
NUOILC: sum{r3} UOC[r3]*M[r3] <= 5;
NLOILC: sum{r3} LOC[r3]*M[r3] >= 5;
DEVA{k}: MAXDEV-P >= 0;
DEVB{k}: MAXDEV-N >= 0;
BOUND1{k}: P <= 0.05*Total >= N;
--minimize SUMDEV: sum{k} Total*(P+N) + 8*(P[6]+N[6]);
--Writep(SUMDEV,MAXDEV,P,N,M);
minimize MINMAX: MAXDEV;
Writep(MAXDEV,P,N,M);
end
CHAPTER 2. PROBLEMS FROM WILLIAM’S BOOK 50
| | | | | 16 blocks (B15-B30)
-------------------
| | | | 9 blocks (B6-B14)
-----------------
| | | 4 blocks (B2-B5)
---------------
| | 1 block (B1)
The problem is to opencast mine within a limited area. Ore body and over-
burden are divided into blocks (e.g. 50 foot cubes). Each block has a certain
revenue and a cost of extracting it. There is a permissible angle of slip (45
degree), so that a block can only be extracted if the (four) blocks above it have
also been removed. Net income must be maximized.
Model: The Model is as follows:he problem is from [17]. For a problem de-
scription see Chapter 13.14. This problem appeared also in Williams H.P., Ex-
periments in the formulation of integer programming problems, Math. Prog.
Study, 2, pp.180-197.
We define a binary variable Di for each block i which is 1 if the block is ex-
tracted. The only restriction is that every block i laying on the top of a specific
block j must also be removed. The condition Di = 1 ↔ Dj = 1 where i is
a block above j means, that block i must be removed if and only if block j is
removed. This can be modeled as Di − Dj >= 0.
1.5,1.5,1,0.5,2,2,1.5,1,3,4,3,1.5,3,3,3,1.5];
-- Cost of a block if excavated
Cost{i}:=[10, 8 8 8 8, 6 6 6 6 6 6 6 6 6,
3 3 3 3,3,3, 3,3,3,3,3, 3,3,3,3, 3];
binary variable D{i} "1 if the block is extracted";
constraint CC{LayingOn[i,j]}: D[i]-D[j] <= 0;
maximize pr: sum{i} (Rev-Cost)*D;
Write('Profit=%4.1f\nExcavated blocks:%4s\n',pr,{i|D} i);
end
CHAPTER 2. PROBLEMS FROM WILLIAM’S BOOK 52
Modeling Steps
This is the same problem as defined in will145 . There the problem is formu-
lated as a integer program, that is, as a mathematical model using integer
variables. It has been shown that the problem can be translated into a max
flow problem in a digraph. See [27] p. 731ff, and [6] p. 49, where the prob-
lem is to find the optimal closure in a digraph. The problem is to choose an
optimal subset of “projects” where each project has a (positive or negative)
benefit. There are restrictions of the form: if a certain project is chosen then
some other projects must also be chosen. The problem is to choose the subset
with the maximal total benefit.
The problem of open mining can be formulated by creating the following di-
graph G(V, A). Let the vertices be the set of the blocks (V). Each block has a
benefit (profit) bi with i ∈ V (return-cost). There is an arc (i, j), if choosing
block i implies choosing block j, that is, block j laying on block i. The arc set
is (i, j) ∈ A.
To formulate this problem as an max-flow problem, we build another graph
G 0 (V 0 , A 0 ) as follows: Add two vertices s (source) and t (sink): (V 0 = V ∪ {s, t}).
For each vertex j ∈ V|bj > 0, add an arc (s, j) to G 0 with capacity bj . For each
vertex i ∈ V|bi < 0, add an arc (i, t) to G 0 with capacity −bi . For each arc
(i, j) ∈ E add an arc to G 0 with capacity ∞. Hence:
5
http://lpl.virtual-optima.com/lpl/Solver.jsp?name=/will14
53 CHAPTER 2. PROBLEMS FROM WILLIAM’S BOOK
Solution: The total benefit is 17.5, the same result as in will14. To find the
blocks to excavate, we inspect the dual variables from which we can recon-
struct the set of the blocks.
CHAPTER 2. PROBLEMS FROM WILLIAM’S BOOK 54
| | | | | 16 blocks (B15-B30)
-------------------
| | | | 9 blocks (B6-B14)
-----------------
| | | 4 blocks (B2-B5)
---------------
| | 1 block (B1)
The problem is to opencast mine within a limited area. Ore body and over-
burden are divided into blocks (e.g. 50 foot cubes). Each block has a certain
revenue and a cost of extracting it. There is a permissible angle of slip (45
degree), so that a block can only be extracted if the (four) blocks above it have
also been removed. We define a binary variable D for each block which is 1 if
the block is extracted. The return on investment must be maximized.
This function is not linear. In order to linearize it, we need to transform this
function by the following steps:
Model: The Model is as follows:The problem is from [17]. For a problem de-
scription see Chapter 13.15. The model appeared also in DAY R.E., Williams
H.P., MAGIC: The Design and Use of an Interactive Modelling Language for
Mathematical Programming, IMA Journal of Mathematics in Management
(1986) 1, pp.53-65.
Writep(cost,out,num,nst);
end
CHAPTER 2. PROBLEMS FROM WILLIAM’S BOOK 58
nsth{h,t} [0..numhyd];
constraint
Dem{t}: sum{i} out +sum{h} hydrolevel*numh -pump >=
demand;
Guar{t}: sum{i} maxl*num >= 1.15*demand-sum{h}
hydrolevel;
output{i,t}: minl*num <= out[i,t] <= maxl*num;
St{i,t}: nst >= num - num[i,if(t=1,#t,t-1)];
Sth{h,t}: nsth >= numh - numh[h,if(t=1,#t,t-1)];
High{t}: heit[if(t<#t,t+1,1)] - heit - (nhours/3)*pump
+sum{h} nhours*redheight*numh = 0;
Bounds1: heit[1] = 16;
Bounds2{t|t>1}: 15 <= heit <= 20;
minimize cost: sum{i,t}(excost*nhours*out
+ startcost*nst + (costph-kctminl)*nhours*num)
+ sum{h,t} (costphh*nhours*numh + startcosth*nsth);
Writep(cost,num,nst,out);
end
CHAPTER 2. PROBLEMS FROM WILLIAM’S BOOK 60
/-------/
/ / |
/-------/ |
| 1 2 3 | |
| 4 5 6 | /
| 7 8 9 | /
/-------/
which means: G is 1, if and only if all three cells of the line are black (sum is
3) or all three cells are white (sum is 0).
The problem is from [17]. For a problem description see Chapter 13.17. This
problem appeared first in Williams H.P., Experiments in the formulation of
integer programming problems, Math. Prog. Study, 2, pp.180-197.
Modeling Steps
The problem is from [17]. For a problem description see Chapter 13.18.
London c2 1.5,
London c3 2.0,
London c5 0.5,
London c6 1.5,
Exeter c3 0.2,
Exeter c4 1.5,
Exeter c5 0.5,
Exeter c6 1.5/;
--client preferences to be delivered from
PrefFtoC{f,c} := [0,1,1,1,1,1,
1,1,1,1,1,1];
--preferred depot of a customer
PrefDtoC{d,c} := [1,0,1,1,1,1,
1,1,1,1,0,1,
1,1,1,1,1,0,
1,1,1,1,1,0];
variable
FactoryDepotQty,FD{f,d|FactoryDepotCost};
FactoryCustQty,FC{f,c|FactoryCustCost};
DepotCustQty,DC{d,c|DepotCustCost};
constraint
FactoryCapa{f}: sum{d} FD + sum{c} FC <= FactoryCap;
DepotCapa{d}: sum{f} FD <= DepotCap;
DepotBalance{d}: sum{c} DC = sum{f} FD;
CustRequirement{c}: sum{f} FC + sum{d} DC =
CustomerReq;
minimize cost: sum{f,d} FactoryDepotCost*FD
+ sum{f,c}FactoryCustCost*FC + sum{d,c}DepotCustCost*
DC;
Writep(cost,FD,FC,DC);
minimize Pref: sum{f,c}PrefFtoC*FC + sum{d,c}PrefDtoC*
DC;
Writep(cost,FD,FC,DC);
end
Model: The Model is as follows:The problem is from [17]. For a problem de-
scription see Chapter 13.19. This model is exactly the same as model will198 :
end
CHAPTER 2. PROBLEMS FROM WILLIAM’S BOOK 70
Cheese 1 Cheese 2
Cheese 1 0.1
Cheese 2 0.4
The problem is to fix prices in a way to maximize total revenue of the agricul-
tural sector. For a complete problem and model description see [17], Chapter
13.21.
71 CHAPTER 2. PROBLEMS FROM WILLIAM’S BOOK
Modeling Steps
The products are defined as a set i, j ∈ Products. The data are the percentage
content of fat (fati ), the percentage content of dry matter (dryi ), previous
year comsumption (coni ), previous year price (prii ), the elastisities (Ei ), and
the cross elastisities of cheese (E0i,j ).
3. The price index should not be higher than the previous year:
X X
coni · pi ≤ coni · prii
i i
dz z − z̄
by
z z̄
Hence we have the linear equations:
xi − x̄i pi − p̄i X pj − p̄i
= −Ei + , for all i
x̄i p̄i p̄j
j|E0i,j
X
max pi Qi,j pj + Ai pi
i,j
subject to three linear constraints
linear constraints that make sure that comsumption is positive
9
http://lpl.virtual-optima.com/lpl/Solver.jsp?name=/WILL21a
73 CHAPTER 2. PROBLEMS FROM WILLIAM’S BOOK
10
http://lpl.virtual-optima.com/lpl/Solver.jsp?name=/WILL21
CHAPTER 2. PROBLEMS FROM WILLIAM’S BOOK 74
[2,0.6,1.5, 2.3,0.7,1.6,
0.8,0.25,0.5, 2.6,0.86,1.9,
2.4,1,2, 8,2.6,4.5,
2.5,0.9,1.6, 2.1,0.85,2,
2,0.65,0.9, 2.05,0.75,1.7,
1.9,0.7,0.5, 1.8,0.63,1.4,
1.5,0.45,1.45, 2.2,0.65,2.2,
1.8,0.62,1.6, 0.9,0.35,0.5,
1.2,0.45,1.3, 6,0.25,2.9,
1.5,0.55,1.55, 0.8,0.2,0.45,
7,2.5,8, 6.5,3.5,5.4,
5.5,3.1,4.5, 1.2,0.48,2,
4.5,2,2.3, 1.1,0.48,1.7,
0.4,0.1,0.55, 0.3,0.09,0.4];
J;
variable x{j}; w;
constraint
ilevel{i}: sum{j} Input[j,i]*x[j] <= Input[J,i];
olevel{k}: sum{j} Output[j,k]*x[j] >= Output[J,k]*w;
for{j1} do
J:=j1;
maximize weight: w;
Write('J=%2d 1/w = %5.3f %s \n',
J,1/w,if(w=1,'efficient',''));
end
end
CHAPTER 2. PROBLEMS FROM WILLIAM’S BOOK 76
-- to be transferred to depot j
td{i,j,t}; -- Number of damaged cars
-- to be tranferred to depot j
rp{i,t}; -- Number repaired at depot i during day t
constraint
inudam{i,t|t>1}: sum{j,k|k<t} (0.9*perret[j,i]*hireper
[k]*(tr[j,t-k]))
+sum{j,k|k>=t} (0.9*perret[j,i]*hireper[k]*(tr[j,t-k
+6]))
+sum{j} (tu[j,i,t-1])+rp[i,t-1]+eu[i,t-1] = nu[i,t];
-- Net flow of undamaged cars into each depot on each
day>Monday
inudama{i}: sum{j,k}(0.9*perret[j,i]*hireper[k]*(tr[j
,7-k]))
+sum{j} (tu[j,i,6])+rp[i,6]+eu[i,6] = nu[i,1];
-- Net flow of undamaged cars into each depot on
Monday
indam{i,t|t>1}: sum{j,k|k<t} (0.1*perret[j,i]*hireper[
k]*(tr[j,t-k]))
+sum{j,k|k>=t} (0.1*perret[j,i]*hireper[k]*(tr[j,t-k
+6]))
+sum{j} (td[j,i,t-1])+ed[i,t-1] = nd[i,t];
-- Net flow of damaged cars into each depot on each
day>Monday
indama{i}: sum{j,k}(0.1*perret[j,i]*hireper[k]*(tr[j
,7-k]))
+sum{j} (td[j,i,6]) +ed[i,6] = nd[i,1];
-- Net flow of damaged cars into each depot on Monday
outudam{i,t}: sum{j} (tu[i,j,t]) +tr[i,t]+eu[i,t]=nu[i
,t];
-- Net flow of undamaged cars out of depot i on day t
outdam{i,t|t>1}: sum{j} td[i,j,t] +rp[i,t-1]+ed[i,t] =
nd[i,t];
-- Net flow of damaged cars out of depot i on day t>
Monday
outdama{i}: sum{j} (td[i,j,1]) +rp[i,6]+ed[i,1] = nd[i
,1];
-- Net flow of damaged cars out of depot i on Monday
repc{i,t}: rp[i,t] <= repcap[i]; -- Repair capacity
demd{i,t}: tr[i,t] <= demand[i,t]; -- Renting out
within demand
tot: sum{i} (0.25*tr[i,1]+0.45*tr[i,2]+nu[i,3]+nd[i
,3]) = n;
-- Total number of cars owned equals those rented out
on Monday for 3 days
-- plus those rented out Tuesday more than 1 day
-- plus those in depots at beginning of Wednesday
maximize Profit: sum{i,t,k|t<>6}
-- Hired out,not Saturday, and returned to same
depot
CHAPTER 2. PROBLEMS FROM WILLIAM’S BOOK 82
(perret[i,i]*hireper[k]*(rcosta[k]-rcostcomp[k
]+10)*(tr[i,t]))
-- Hired out,not Saturday, and returned to
another depot
+sum{i,j,t,k|i<>j and t<> 6}
(perret[i,j]*hireper[k]*(rcostb[k]-rcostcomp[k
]+10)*(tr[i,t]))
+sum{i,t,k|t=6 and k=1}
-- Hired out on Saturday for 1 day with return to
same depot
(perret[i,i]*hireper[k]*(rcosta[k]-20-rcostcomp[k
]+10)*(tr[i,t]))
+sum{i,j,t,k|i<>j and t=6 and k=1}
-- Hired out on Saturday for 1 day with return to
another depot
(perret[i,j]*hireper[k]*(rcostb[k]-20-rcostcomp[k
]+10)*(tr[i,t]))
+sum{i,t,k|t=6 and k<>1} -- Hired out on
Saturday for more than 1 day with return to
same depot
(perret[i,i]*hireper[k]*(rcosta[k]-rcostcomp[k
]+10)*(tr[i,t]))
+sum{i,j,k,t|i<>j and t=6}
-- Hired out on Saturday for more than 1 day with
return to another depot
(perret[i,j]*hireper[k]*(rcostb[k]-rcostcomp[k
]+10)*(tr[i,t]))
-sum{i,j,t}
-- Cost of transfer to another depot
(costtran[i,j]*(tu[i,j,t]+td[i,j,t]))
-15*n; --Marginal cost to company of cars
owned
Writep(Profit,n);
end
83 CHAPTER 2. PROBLEMS FROM WILLIAM’S BOOK
Solution:
1 2 3
8 7 6 5 4
9 10 11 12 13 14 15 16 17 18 19 20 21 22
35 34 33 32 31 30 29 28 27 26 25 24 23
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
Model: The Model is as follows:The problem is from [17], page 6 and page
107.
Model: The Model is as follows:The problem is from [17], page 6 and page
107.
max x+y
subject to −2x + 2y ≥ 1
−8x + 10y ≤ 13
x, y ≤ 0
Modeling Steps
The observation is that the integer solution is not just a rounding of the real
solution. On the contrary, the two solutions are far away from each other. It is
difficult to see, how we could derive the integer solution from the lp solution.
Solution: The integer solution for this small model is: (x, y) = (1, 2) and the
optimal value is 3, whereas the relaxed real solution is (x, y) = (4, 4.5) with
an optimal value of 8.5.
Question (Answer see 2.48)
1. What happens if the constraint R2 becomes:
R2: -9*x + 10*y <= 9;
2. Change the right hand side of constraint R1 from 1 to 2, and the right
hand side from 13 to 12. Solve the LP problem and the ILP problem
(once with real variables, once with integer variables. What do you
derive from the modified model?
CHAPTER 2. PROBLEMS FROM WILLIAM’S BOOK 104
max x+y
subject to 5x + 10y ≤ 9
−5x + 10y ≥ 1
0 ≤ x, y ≤ 1 (or x, y ∈ [0, 1])
Modeling Steps
The observation is that there does not exists an integer solution (the prob-
lem is infeasible). However, there exists a solution with continuous variables
[(x, y) = (0.8, 0.5)] bounded by the interval [0 . . . 1]. In particular, one should
observe that the integer solution is not just a rounding of the real (continuous)
solution. It is difficult to see, how one could derive the fact that the integer
solution is infeasible from the continuous LP solution alone.
The only way to solve the 0-1 integer problem is to “enumerate” all possible
solutions somehow. From the first constraint 5x+10y ≤ 9, one can derive that
y never can be 1. From the second constraint −5x + 10y ≥ 1, one can derive
that y never can be 0. Now we have a contradiction: y cannot be 1 neither can
it be 0. Hence, one derives that there is no integer solution for this problem.
C HAPTER 3
This chapter shows an LPL implementation of all models from the book [5],
respectively [28]
107
CHAPTER 3. PROBLEMS FROM THE GUERET BOOK 108
1. What is the total loss if the life span of each wagon is infinite?
2. What is the loss on each wagon (give the expression in LPL).
3. Suppose that it is possible to accelerate the traitment. How long should
the duration be in order to push the overall loss under 1000 kg? How
does the overall loss decrease with the acceleration of the traitment?
4. How does the number of lignes influence the total loss?
5. Create and run a problem with 100 wagons.
CHAPTER 3. PROBLEMS FROM THE GUERET BOOK 112
Modeling Steps
We introduce a set for the tasks i, j ∈ I. All we need is the duration time of a
task pi and the precedence list of task tuples Preci,j . The tuple entry Preci,j
is true if and only if task i must be completed before task j. The variables are
the (earliest) starting time ti of a task i. The objective is to minimize the latest
starting time.
The model is as follows:
Further Comments: A comment on the Read statement: The first read staemetn
reads the data from an Excel sheet (the statement is outcommented). The sec-
ond Read reads the same data from the same format in a tab separated text
file. Note how similar these statements are. In the text-form we use '%1'
to indicate that the first line must be skipped, and '\t\n' indicates that the
only token separators are tabs and line feeds.
1. What is the earliest, what is the latest time that each task can begin?
2. Draw a Gantt diagram to visualiser the solution.
CHAPTER 3. PROBLEMS FROM THE GUERET BOOK 116
3. Suppose that the duration of each task could be reduced by one unit.
What is now the solution?
4. Suppose that the task number 4 can only begin at the 32 week. What
are the implication of the overall plan?
5. Suppose the municipality would like to terminate the construction ear-
lier than projected by the construction company and is ready to pay a
bonus of 30 unit of money for each reduced week. The company has
additional costs for each task ci per reduced week (last column in Table
3.1) and each task can only be reduced a maximal number of weeks,
given by ri (second to the last column in Table 3.1. How would the
construction company proceed?
6. Create and run a project with 100 tasks.
The parameter Earliest gives the eariest possible starting time, and
Lastest gives the latest possible time. The Submodel EarliestLatest
shows the results.
2. See answer 1
3. Repace pi by pi − 1 the run again. The completion time is 55 weeks.
4. Add the constraint constraint C4: t[4]>=32; and run the model
again.
5. Certainly, the company would try to maximize the additional bonuses.
The additional requirements are formulated in the model CostModel.
117 CHAPTER 3. PROBLEMS FROM THE GUERET BOOK
2. How could we force to process job 1 just before job 3 ? Add the condi-
tion for that. What is the total duration now?
3. Suppose that we must execute the job 6 as the first job. How could this
condition be added to the model? What is the consequence on the total
processing time?
4. Create and run a problem with 50 jobs.
1.
119 CHAPTER 3. PROBLEMS FROM THE GUERET BOOK
1. Implement the three objectifs: (1) minimize the makespan, (2) minimize
the average processing time, (3) minimize the total tardiness.
2. Draw a Gantt diagram.
CHAPTER 3. PROBLEMS FROM THE GUERET BOOK 122
Modeling Steps
end
model data1; --- a random data set
n := [1..20];
L := [1..5];
g{n} := Trunc(Rnd(6,10));
d{n,L} := Trunc(Rnd(10,20))/10;
m{L} := Trunc(Rnd(1500,6000));
T{L,L1|L<>L1} := if(Rnd(0,1)<.3,1,0);
tm{L} := Trunc(Rnd(200,900));
end
end
167 CHAPTER 3. PROBLEMS FROM THE GUERET BOOK
Modeling Steps
The problem is from [5] Chap 13.5, and from [28] Chap 15.4.
Modeling Steps
The problem can be formulated as a Min Cost Flow Problem, see mcf-a1 for
the general Min Cost Flow problem. That is, we “simulate” the traversing of
an arc as a “flow”. Flow=1 means that the arc is traversed once, flow=2 means
that the arc is traversed two times, etc. The variables are the number of flows
on each arcs (xi,j i, j ∈ V V is the set of route intersections). The flow on
each arc must be 1 (at least on traversal li,j ≤ xi,j . We do not want to limit
the number of flows on each arc, hence we can set ui,j = ∞, however on can
show that 2 is enough (ui,j = 2). So there is: li,j ≤ xi,j ≤ ui,j .
1
http://lpl.virtual-optima.com/lpl/Solver.jsp?name=/mcf-a
CHAPTER 3. PROBLEMS FROM THE GUERET BOOK 172
X X
xi,j − xj,i = 0 ∀ i∈V
j j
Hence, we have a Min Cost Flow Problem with the following specifications:
(1) All lower bounds are 1 (li,j = 1, to make sure that all streets are traversed
at least once. All upper bound must be at least 2 (ui,j ≥ 2). And for complet-
ing the formulation (of a Min Cost Flow), bi = 0 for all nodes.
Solution: The optimal traveled distance is 5990. There are 7 arcs that must
be traversed two times: the first time serving the street and the second time
without serving. The solution is shown in 3.1
173 CHAPTER 3. PROBLEMS FROM THE GUERET BOOK
VARIOUS T EXTBOOKS
The average daily output is 128 HC for forest A, 192 HC for forest B, and 200
HC for forest C (1 HC = 100 cubic feet = 2.832 cubic meter). The log cuts
are sorted onto logging trucks for transportation to either the sawmill or the
chipboard plant, the two facilities being at different locations. Transportation
costs per HC are given in the following table:
Transportation Sawmill Chipboard
-------------------------------------------
Forest A $4 $7
Forest B $3 $5
Forest C $6 $3
-------------------------------------------
At the sawmill, logs are sawn into three grades of finished products: clear
grade, dressing grade, and construction grade. A substantial fraction of the
incoming volume of wood ends up as scrap and sawdust. The table below
shows the average log conversion factors at the sawmill, as well as the average
processing rates. Excluding breakdowns, the productive capacity at the mill
averages 360 minutes per day.
Sawn Timber Scraps Sawdust Processing
LogCuts MBF/HC HC/HC HC/HC Time per HC
----------------------------------------------------
1-2 0.72 0.26 0.14 1.8
3-4 0.66 0.30 0.15 2.6
5- 0.54 0.39 0.16 3.9
----------------------------------------------------
From sample logs processed at the sawmill, average yields for each grade of
sawn timber were determined. They are summarized in the following table.
Clear Dressing Construction
----------------------------------------
LogCuts A B C A B C A B C
/Forest
--------------------------------------------------
1-2 35% 28% 20% 48% 42% 30% 17% 30% 50%
3-4 10% 3% 25% 18% 9% 30% 72% 88% 45%
5- 0 0 5% 5% 0 30% 95% 100% 65%
--------------------------------------------------
The ex-mill wholesale price per MBF is $150 for clear grades, $110 for dressing
grades and $80 for construction grades. Scraps at the sawmill are transferred
by truck to the chipboard plant for chipping. The transportation cost is $4
per HC. Sawdust is used as fuel in the mill’s drying kiln and saves $12 in
other fuel costs per HC. At the chipboard plants, logs and scraps are chipped.
The chips are then mixed with additive glues, filled into 4’ by 8’ forms and
then compressed into boards of various thicknesses. The whole process is
highly automated. Each HC of wood yields 0.76M3/4 of chipboard (1M3/4
= 1000 square feet of 3.4 thickness = 1.77 cubic meters). The plant can pro-
duce upto 112M3/4 of chipboard per day. Chipboard prices ex-factory are
$105 per M3/4. In light of predicted demand and desired stock levels, cer-
tain minimum daily output rates of finished product are set up by Wood-D
management for given planning period. These are 31 MBF of clear grades, 35
MBF of dressing grade, 48 MBF of construction grade, and 96 M3/4 of chip-
board. Export prices valid during the same planning period are $95 per HC
for first and second cuts, and $88 per HC for third and fourth cuts. Fifth or
185 CHAPTER 4. VARIOUS TEXTBOOKS
higher cuts are not exported. The problem is to determine the optimal daily
operating policy during the planning period in question.
Project Formulate the production planning problem as a linear program using
MPL. Summarize the optimal daily operating policy for the planning prob-
lem.
Reference: Prof. Ariela Sofer, Operations Research Dept., George Mason Uni-
versity Based on a problem from the book ’Introduction to Operations Re-
search Techniques’ by Hans G. Daellenbach, John A. George, and Donald C.
McNickle, 1983
CHAPTER 4. VARIOUS TEXTBOOKS 186
24 33000 1.40
25 6700 1.22
26 5000 1.30
--------------------------------------
Saw Mill has now received an order for 6 different grades of corn totaling
1. bushels which it intends to fill from the grain stored with Midwest. The
Saw Mill must meet the stated demand for each of the 6 grades. Exceed-
ing demand would be ill-advised, since there is no guarantee that the
next order filled will require the same characteristics. The demand for
each type of grade is shown in the table below.
Corn Grade Demand
-------------------------
Gr1 40000
Gr2 32000
Gr3 50000
Gr4 20000
Gr5 30000
Gr6 100000
-------------------------
Midwest’s handling fee will be based on supplying the 272,000 bushels
of corn, regardless of the manner in which the various corns are blended
to meet the specifications. However, in keeping with the policy of pro-
viding quality service to other buyers and sellers, the problem Mid-
west faces is that of determining the least cost blend of available grains
that will satisfy the specified criteria of the current order. Each of the
6 grades of corn demanded must meet specified criteria for moisture
content, minimum weight per bushel, percentage damaged, and per-
centage of foreign material, which are detailed in the table below. Corn
Grade Characteristics:
Grade MaxMoisture MinWeight MaxDamage MaxForeign
---------------------------------------------------------
Gr1 13.0 56.0 2.0 2.0
Gr2 15.5 54.0 5.0 3.0
Gr3 15.0 56.0 2.0 4.0
Gr4 16.0 54.0 9.0 4.0
Gr5 23.0 54.0 10.0 6.0
Gr6 20.0 54.0 9.0 4.0
---------------------------------------------------------
For each of the 6 grades the four quality requirements are as follows:
The weighted average moisture content cannot exceed the maximum
acceptable moisture level for that grade. The weighted average weight
per bushel of the corns used in the blend of the grades must meet or
241 CHAPTER 4. VARIOUS TEXTBOOKS
The objective for this problem is to determine the number of bushels used
in the blending for each of the 26 types of corn so the the total cost of the 6
desired grades of corn is minimized.
Reference: Prof. Ramesh Sharda, Operations Research Dept., Oklahoma State
University
Modeling Steps
CHAPTER 4. VARIOUS TEXTBOOKS 242
model midwest "MidWest Grain Elevator";
set
type := [1..26];
grade := [Gr1, Gr2, Gr3, Gr4, Gr5, Gr6];
parameter
-- Supply characteristics
Supply{type} := [15000, 30000, 45000, 25000, 40000,
20000, 30000, 75000, 15000,
50000, 16000, 20000, 10000, 12000, 6000, 2000,
5000, 4000, 5000, 6000, 1300, 29000, 1900,
33000, 6700, 5000];
Cost{type} := [1.50, 1.45, 1.44, 1.45, 1.42, 1.38,
1.37, 1.37, 1.39
1.39, 1.27, 1.28, 1.17, 1.22, 1.12, 1.18, 1.42, 1.42
1.42, 1.36, 1.29, 1.29, 1.42, 1.40, 1.22, 1.30 ];
Moisture{type} := [11, 12, 15, 12, 13, 15, 15, 18,
14,
15, 17, 15, 22, 18, 17, 13.5, 13.5 13.5,
13.5, 15, 13.5, 13, 13, 13, 14, 15];
Weight{type} := [58.0, 57.0, 57.0, 58.0, 56.0, 54.0,
55.0, 57.0, 58.0,
55.0, 53.0, 55.0, 56.0, 54.0, 55.0, 57.0, 57.0,
57.5,
57.0, 56.5, 58.0, 57.0, 58.0, 56.0, 56.0, 56.5];
Damage{type} := [ 3, 2, 2, 3, 4, 4, 5, 5, 2,
3, 7, 8, 8, 13, 20, 30, 3, 3,
5, 10, 15, 15, 3, 5, 20, 10];
Foreign {type} := [1, 1.5, 1, 3, 2, 2, 3, 1, 4,
2, 5, 3, 5, 5, 8, 2, 2, 2,
3, 4, 4, 5, 2, 3, 5, 4];
-- Demand Characteristics
Demand{grade} := [40000, 32000, 50000, 20000, 30000,
100000];
MaxMoisture{grade} := [13, 115, 15, 16, 23, 20];
MinWeight{grade} := [56, 54, 56, 54, 54, 54];
MaxDamage{grade} := [2, 5, 2, 9, 10, 9];
MaxForeign{grade} := [2, 3, 4, 4, 6, 4];
variable Bushels{type,grade};
constraint
QuantitySupplied{type}: sum{grade} Bushels <= Supply;
QuantityDemanded{grade}: sum{type} Bushels = Demand;
MoistureContent{grade}: sum{type} Moisture*Bushels <=
MaxMoisture*(sum{type} Bushels);
WeightPerBushel{grade}: sum{type} Weight*Bushels >=
MinWeight*(sum{type} Bushels);
DamagePercent{grade}: sum{type} Damage*Bushels <=
MaxDamage*(sum{type} Bushels);
243 CHAPTER 4. VARIOUS TEXTBOOKS
Solution:
opt: 366863;
CHAPTER 4. VARIOUS TEXTBOOKS 244
Writep(TotalCost,P,I,W,H,L,S);
end
257 CHAPTER 4. VARIOUS TEXTBOOKS
Modeling Steps
Modeling Steps
Modeling Steps
Modeling Steps
Modeling Steps
Modeling Steps
Modeling Steps
max z = 2x1 − x2
subject to x1 − x2 ≤ 1
2x1 + x2 ≥ 6
x1 , x2 ≥ 0
Modeling Steps
Modeling Steps
Modeling Steps
Table 4.1:
Modeling Steps
Table 4.2:
Assets Liabilities
Cash $10,000
Accounts receivable* $ 3,000
Inventory outstanding** $ 7,000
Bank loan $ 10,000
Table 4.3:
Modeling Steps
Modeling Steps
Modeling Steps
Modeling Steps
Modeling Steps
Modeling Steps
Modeling Steps
Modeling Steps
Modeling Steps
Modeling Steps
Modeling Steps
Modeling Steps
Modeling Steps
Table 4.4:
Modeling Steps
a) Verify that Peg should purchase 12 units of food 2 each day and thus over-
satisfy the vitamin C requirement by 6 units.
b) Al has put his foot down and demanded that Peg fulfill the family’s daily
nutritional requirement exactly by obtaining precisely 12 units of vitamin A
and 6 units of vitamin C. The optimal solution to the new problem will in-
volve ingesting less vitamin C, but it will be more expensive. Why?”
This problem is from [31] , Problem 3.4-3, Page 69.
Modeling Steps
Modeling Steps
Table 4.5:
Modeling Steps
Modeling Steps
Modeling Steps
a) The amount invested in personal loans cannot ex- ceed the amount invested
in bonds.
b) The amount invested in home loans cannot exceed the amount invested in
auto loans.
The bank’s objective is to maximize the annual return on its investment port-
folio. Formulate an LP that will enable the bank to meet this goal.” This
problem is from [31] , Problem 3.8-3, Page 87.
Modeling Steps
Modeling Steps
Modeling Steps
Modeling Steps
Modeling Steps
Modeling Steps
Modeling Steps
Modeling Steps
- sum{crude} CrudeCost*PurchaseCrude;
Writep(TotalProfit);
end
CHAPTER 4. VARIOUS TEXTBOOKS 298
Modeling Steps
Modeling Steps
Modeling Steps
Modeling Steps
Modeling Steps
Modeling Steps
Modeling Steps
Modeling Steps
Modeling Steps
Modeling Steps
At any time, leftover cash may be invested in T-bills, which pay 10be invested
in each of investments A, B, and C. Formulate an LP that can be used to max-
imize Finco’s cash on hand at time 3.”
Modeling Steps
Alloy 1 Alloy 2
Cost per ton $190 $200
Percent silicon 2% 2.5%
Percent nickel 1% 1.5%
Percent Carbon 3% 4%
Tensile strenght 42,000 psi 50,000 psi
Table 4.6:
Modeling Steps
Steel 1 Steel 2
Time Time
Cost (minutes) Cost (minutes)
Mill 1 $10 20 $11 22
Mill 2 $12 24 $9 18
Mill 3 $14 28 $10 30
Table 4.7:
Modeling Steps
Farm 1 Farm 2
Corn yield/acre 500 bushels 650 bushels
Cost/acre of corn $100 $120
Wheat yield/acre 400 bushels 350 bushels
Cost/acre of wheat $90 $80
Table 4.8:
Modeling Steps
Modeling Steps
Number New
of Ads Customers
Newspaper 1-10 900
11-20 600
21-30 300
Television 1-5 10,000
6-10 5000
11-15 2000
Table 4.9:
Modeling Steps
Profitt Per
Million Barrels
To Houston To New York
From Los Angeles $20,000 $15,000
From Chicago $18,000 $17,000
Table 4.10:
Modeling Steps
expression
TotalProfitPerYear: sum{refinery, distrpoint} Profit*
Refine;
TotalAddCapCost : sum{refinery} AddCapacityCost*
AddCapacity;
constraint
RefineryLimit{refinery}: sum{distrpoint} Refine <=
RefineCap + AddCapacity;
MaxDemand{distrpoint}: sum{refinery} Refine <=
MaxSales;
maximize TotalProfit: PlanningYears*TotalProfitPerYear
- TotalAddCapCost;
Writep(TotalProfit);
end
321 CHAPTER 4. VARIOUS TEXTBOOKS
Percent of Percent of
Person Daytime Evening
Responding Calls Calls
Wife 30 30
Husband 10 30
Single male 10 15
Single female 10 20
None 40 5
Table 4.11:
Modeling Steps
Modeling Steps
Modeling Steps
Modeling Steps
Modeling Steps
Modeling Steps
Minority Nonminority
District Students Students
1 50 200
2 50 250
3 100 150
Table 4.12:
Table 4.13:
Modeling Steps
Modeling Steps
Table 4.14:
Modeling Steps
Modeling Steps
Group 1 Group 2
Customer Customer
Value of A to $10 $12
Value of B to $8 $15
Table 4.15:
Machine 1 Machine 2
Product 1 4 3
Product 2 7 4
Table 4.16:
Demand Prices
Month 1 Month 2 Month 1 Month 2
Product 1 100 190 $55 $12
Product 2 140 130 $65 $32
Table 4.17:
Modeling Steps
Table 4.18:
Modeling Steps
Modeling Steps
Modeling Steps
Revenue Bills
Month 1 $400 $600
Month 2 $800 $500
Month 3 $300 $500
Month 4 $300 $250
Table 4.19:
Modeling Steps
Incinerator 1 Incinerator 2
City 1 30 5
City 2 36 42
Landfill 1 Landfill 2
Incinerator 1 5 8
Incinerator 2 9 6
Table 4.20:
Modeling Steps
DebrisToLandfill,D{incin,landfill};
expression
TotalBurnCost : sum{city,incin} BurnCost*W;
IncinTranspCost : CostPerMile*(sum{city,incin}
DistToIncin*W);
LandfillTranspCost: CostPerMile*(sum{incin,landfill}
DistToLandfill*D);
constraint
BurnWaste{city}: sum{incin} W = WasteProduced;
IncinLimit{incin}: sum{city} W <= BurnCapacity;
IncinBalance{incin}: sum{city} W = 1/ResultingDebris
*(sum{landfill} D);
LandfillLimit{landfill}: sum{incin} D <=
LandfillCapacity;
minimize TotalCost: TotalBurnCost + IncinTranspCost +
LandfillTranspCost;
Writep(TotalCost);
end
343 CHAPTER 4. VARIOUS TEXTBOOKS
Modeling Steps
Sedans Wagons
Month 1 1100 600
Month 2 1500 700
Month 3 1200 500
Table 4.21:
Modeling Steps
Revenues Bills
July $1000 $5000
August $2000 $5000
September $2000 $6000
October $4000 $2000
November $7000 $2000
December $9000 $1000
Table 4.22:
Modeling Steps
BorrowMonth,S{m};
constraint
CashBalance{m|m=1}:
C = CashAvail + Revenues - Bills + S + L;
CashBalance1{m|m>1 and m<#m}:
C = C[m-1] + Revenues - Bills + S - BorrowRate*S[
m-1];
CashBalance2{m|m=#m}:
C = C[m-1] + Revenues - Bills - BorrowRate*S[m-1]
- LoanRate*L;
minimize TotalCost: LoanInterest*L + sum{m}
BorrowInterest*S;
Writep(TotalCost);
end
C HAPTER 5
Modeling Steps
Modeling Steps
crop_30 . . 27 .
crop_33 11 42 . .
crop_36 . 98 6 1 /;
pcost{p} "cropping technology costs (cr per ha)" :=
sum{km} techc;
a{p} "cropping constants" := if (sum{s} yield[p
,'cotton_h',s]=0,1);
variable
xcrop{p,s} "cropping activities (ha)";
xliver{r} "livestock activity defined on feed
techniques (head)";
lswitch{s} "land downgrading (ha)";
sales{c} "crop sales (ton)";
cons{dr} "on-farm consumption (ton)";
flab{tm} [0..famlab]"family labor (man-days)";
tlab{tm} "temporary labor (man-days)";
plab "permanent labor (workers)";
pdev{ty} "positive price deviations (cr)";
ndev{ty} "negative price deviations (cr)";
xlive "livestock production (head)";
xprod{c} "crop production (ton)";
rationr "livestock ration requirements (cr)";
revenue "from crop and livestock sales (cr)";
cropcost "accounting: cropping activities cost (
cr)";
labcost "accounting: labor costs - including
family (cr)";
vetcost "accounting: vetinary services cost (cr)
";
constraint
landb{s}: sum{p|ps and sc} a*xcrop + sum{sp} ldp[sp]*
lswitch[sp] + sum{r} lio*xliver <= landc "land
balance";
lbal : xlive = sum{r} xliver "livestock balance";
rliv : rationr = sum{r} rations*xliver "livestock
ration requirements definition";
mbalc{c}: sum{s,p} yield*xcrop/1000 >= sales + sum{dr
} cbndl*cons "material balance: crops";
dprod{c}: xprod = sum{p,s} yield*xcrop/1000 "crop
production definition";
labc{tm}: sum{p,s|ps} labor*xcrop + sum{r} llab*
xliver <= flab + tlab + dpm*plab "labor supply-
demand relation";
cond : sum{dr} cons = 1 "on farm consumption
definition";
ddev{ty}: sum{c} prdev*sales = pdev-ndev "crop price
deviation definition";
arev : revenue = lprice*xlive + 1000*(sum{c} price
*sales) "accounting: revenue definition";
CHAPTER 5. MODELS FROM THE GAMS LIBRARY 356
Modeling Steps
Modeling Steps
Modeling Steps
Modeling Steps
Modeling Steps
Modeling Steps
Modeling Steps
Modeling Steps
Modeling Steps
Modeling Steps
Solution:
opt: solution reported in OPTIMA
b.fx('6','2') = 1;
b.fx('7','2') = 1;
b.fx('8','2') = 1;
b.fx('7','1') = 1;
b.fx('8','1') = 1;
b.fx('7','6') = 1;
b.fx('8','6') = 1;
b.fx('7','7') = 1;
b.fx('8','7') = 1;
379 CHAPTER 5. MODELS FROM THE GAMS LIBRARY
Modeling Steps
Modeling Steps
This model is from the GAMS model library (GAMS SEQ=42). See also [16]
and te model WILL16.
Modeling Steps
Modeling Steps
Modeling Steps
Modeling Steps
The Model
function Egypt
set Center (Ce) , P (i, j) “Plants”
set Port (Po) , Region (R) , Units (Un) , Process (Pr) , Nutr (N) ,
Commod (C, c) , cRaw (r) , cInter , cShip (s) , cFinal (f)
param exch := 0.4
param utilPct := 0.85
set pExceptP,Pr
param cf75R,cFinal , fncFinal,N , roadR,Ce , railHalfP,P , impdBargP
, impdRoadP , ioC,Pr , utilUn,Pr , pImpC , pRcRaw , pPrP,cRaw ,
dcapP,Un , raili,j := if(railHalfi,j , railHalfi,j , railHalfj,i )
param tranFinalP,R := 0.5 + 0.0144 · roadR,PwithinCe
param tranImportR,Po := 0.5 + 0.0144 · roadR,PowithinCe
param tranInteri,j := 3.5 + 0.03 · raili,j
param tranRawP := if(impdBargP , 1+0.003·impdBargP )+if(impdRoadP , 0.5+
0.144 · impdRoadP )
param pDomP,cRaw := if(pRcRaw , pRcRaw , pPrP,cRaw )
param icapUn,P := 0.33 · dcapP,Un
set mPosP,Un := icapUn,P > 0
set pCapP,Pr := ∀Un|utilUn,Pr >0 mPosP,Un
P P,Pr ∧ ¬pExceptP,Pr
set pPosP,Pr := pCap
set cpPosC,P := io >0
P Pr|pPosP,Pr C,Pr
set ccPosC,P := Pr|pPosP,Pr io C,Pr < 0
set cPosC,P := cpPosC,P ∨ ccPosC,P
var ZP,Pr|pPosP,Pr , XfcFinal,P,R|cpPoscFinalwithinC,P , Xis,i,j|cpPosswithinC,i ∧ccPosswithinC,j
, VfcFinal,R,Po , VrcRaw,P|ccPoscRawwithinC,P , UcRaw,P|ccPoscRawwithinC,P ∧pDomP,cRaw >
, Psip , Psil , Psii
CHAPTER 5. MODELS FROM THE GAMS LIBRARY 390
P P P
s.t.PmbdN,R : cFinal,Po fncFinal,N ·( Po VfcFinal,R,Po + P XfcFinal,P,R ) ≥
cFinal fncFinal,N · cf75 P
R,cFinal P
s.t. mbdbcFinal,R|cf75R,cFinal >0 : Po VfcFinal,R,Po + P XfcFinal,P,R ≥
cf75R,cFinal
P P P
s.t. mbc,i : PrPioc,Pr ·Zi,Pr + j Xicwithins,i,j + j Xicwithins,j,i +if(pImpc , Vrcwithinr,i )+
Ucwithinr,i ≥ R XfP cwithinf,i,R
s.t. ccP,Un|mPosP,Un
P : Pr utilUn,Pr · ZP,Pr ≤ utilPct · icapUn,P
s.t. ap : Psip =P cRaw,P pDomP,cRaw · UcRaw,P P
s.t. al : Psil = cFinal,P,R
P tranFinalP,R ·XfcFinal,P,R
P + cFinal,Po,R tranImportR,Po ·
P tranInteri,j ·Xis,i,j + cRaw,P tranRaw
VfcFinal,R,Po + s,i,j P P ·VrcRaw,P
s.t. ai : Psii/exch = f,R,Po pImpfwithinC · Vff,R,Po + r,P pImprwithinC ·
Vrr,P
minimize Psi := Psip + Psil + Psii
Writep(Psi, Z, Xf, Xi, Vf, Vr, U, Psip, Psil, Psii)
Writep(mPos, pCap, pExcept, pPos, cpPos, ccPos, cPos)
end
391 CHAPTER 5. MODELS FROM THE GAMS LIBRARY
Modeling Steps
Problem: The Tanglewood Chair Manu. Co. has four plants located around
the country. The fabrication data are the following:
The wood required to make each chair is twenty pounds and is obtained from
two suppliers. The company purchase of at least 8 tons of wood per month
from each supplier. The cost of wood is 0.10/lb from supplier 1 and 0.075/lb
from supplier 2. The shipping cost in dollar per pound of wood from each
supplier to each plant is shown below:
P1 P2 P3 P4
sup1 0.01 0.02 0.04 0.04
sup2 0.04 0.03 0.02 0.02
The chairs are sold in New York, Houston, San Francisco and Chicago. The
transportation costs are shown below:
NY H SF C
P1 1 1 2 0
P2 3 6 7 3
P3 3 1 5 3
P4 8 2 1 4
Where should each plant buy its raw materials? How many chairs should be
made at each plant? How many chairs should be sold at each city? Where
should each plant ship its product?
393 CHAPTER 5. MODELS FROM THE GAMS LIBRARY
B ILLONNET
X
min (xi − ai )2
X
i∈I
subject to bi xi ≤ K
i∈I
xi ∈ Z for all i ∈ I = {1 . . . 5}
with K = 50, a = {30, 20, 4, 8, 16}, and b = {3, 2, 5, 7, 1} (see [1] p.18).
Modeling Steps
395
CHAPTER 6. BILLONNET 396
Modeling Steps
1. Now we can express the total costs: (1) the buildung costs are:
X
ck,i xk,i
k∈K,i∈I
(note that xk,i is one if a factory k is built at site i). (2) the transportation
costs are: X
Cdi,j yi,j
i∈I,j∈J
Modeling Steps
1. The sum of all invested parts must be one, this is formulated by the
constraint C1.
2. The yield must be at least ρ, The earning on a title is the expected rate
times the invested part of this title. The sum must be ρ. This is con-
straint C2.
3. The number of titles in the final portfolio is K. This gives constraint C3.
4. The parts must be between the minimal and maximal requirements.
loi yi is the minimal requested amount to be placed in a title i: if yi = 0
(the part of i is zero), then loi yi = 0, if yi = 1 (there is a positive part
of i in the portfolio), then loi yi is loi . upi yi is the maximal requested
amount to be placed in a title i: if yi = 0, then upi yi = 0, if yi = 1 then
upi yi is upi . Hence xi should be between loi yi and upi yi : if yi = 0
then xi = 0 anyway, if yi = 1 then xi is between loi and upi . That is
exactly what is requested. The constraint is C4.
5. Finally, we want to minimize the risk. The total risk is measured by
the sum of the (positive and negative) deviations from the expected
eanrings on each title. The deviation of a single title i can be measured
by vi x2i . The quadratic term makes sure that the risk increased with an
increasing (positive or negative deviation. Hence the sum of these risks
is minimized.
399 CHAPTER 6. BILLONNET
sX
Ri = wi,k (dj,k − zjk )2
k∈K
A company now wants to design a new product with the attributes such that
it maximises the profit by attracting as many customer as possible supposing
that the company gets a revenu ci if the customer is attracted by the new
product.
Furthermore, we suppose that the introduced product with characteristic val-
ues of xk with k ∈ K costs f(x1 , x2 , . . . , xp ). Let this function be given by the
quadratic expression as follows (p = 5):
In addition the characteristcs of the product are only possible under the fol-
lowing linear constraints Φ:
x1 − x2 + x3 + x4 + x5 ≤ 10
0.6x1 − 0.9x2 − 0.5x3 + 0.1x4 + x5 ≤ −0.64
x1 − x2 + x3 − x4 + x5 ≥ 0.69
0.157x1 + 0.05x2 ≤ 1.5
0.25x2 + 1.05x4 − 0.3x5 ≥ 4.5
2 ≤ x1 ≤ 4
0 ≤ x2 ≤ 8
3 ≤ x3 ≤ 9
0 ≤ x4 ≤ 5
4 ≤ x5 ≤ 10
What characteristics should this product contain and which customers will be
attracted by it? (see [1] p.27ff)
401 CHAPTER 6. BILLONNET
Modeling Steps
attribute k";
binary variable y{i} "Customer attracted or not";
constraint
C1{i}: sum{k} w*(x-z)^2 - h*(1-y) <= R;
C2: x[1] - x[2] + x[3] + x[4] + x[5] <= 10;
C3: 0.6*x[1] -0.9*x[2] - 0.5*x[3] + 0.1*x[4] + x[5]
<= -0.64;
C4: x[1] - x[2] + x[3] - x[4] + x[5] >= 0.69;
C5: 0.157*x[1] + 0.05*x[2] <= 1.5;
C6: 0.25*x[2] + 1.05*x[4] - 0.3*x[5] >= 4.5;
expression Fx: 0.6*x[1]^2 - 0.9*x[2] - 0.5*x[3] + 0.1*x
[4]^2 + x[5];
maximize profit: sum{i} c*y - Fx;
Writep(profit,y,x);
end
CHAPTER 6. BILLONNET 404
X
n X
n
min ci,j · xi · xj
i j
subject to Ax = b
xi ∈ {0, 1} forall i ∈ I = {1 . . . n}
X
n X
n X
n X
n X
n
ci,j · xi · xj with ci,j · xi · xj + λ (x2 − x)
i j i j i
Note that the two expressions are identical for x ∈ {0, 1}, since in this case we
have: x2i = xi .
Modeling Steps
0 1 7 3 9 3
1 0 5 2 1 3
7 5 0 1 7 8
ci,j =
3
2 1 0 5 1
9 1 7 5 0 2
3 3 8 1 2 0
Problem: The fractional LP is a model where the constraints are linear and the
objective function consists of a fraction with the nominator and the denomi-
nator are both linear functions. The general model is as follows:
Pn
b0 + bj xj
max Pj=1
n
c0 + j=1 cj xj
X
n
subject to ai,j xj ≤ di forall i ∈ I = {1 . . . m}
j=1
xj ≥ 0 forall j ∈ J = {1 . . . n}
As an example we have:
3 + 2x1 + 5x2 + x3
max
1 + 3x1 + x2 + 4x3
subject to 5x1 + x2 + 6x3 ≤ 10
x1 + 2x2 + x3 ≤ 2
xj ≥ 0 forall j ∈ {1, 2, 3}
Modeling Steps
1
z= Pn
c0 + j=1 cj xi
x
yj = Pnj
c0 + j=1 cj xi
now we substitute them into the model to obtain the following linear model:
407 CHAPTER 6. BILLONNET
X
n
max b0 z + bj y j
j=1
Xn
subject to c0 z + cj yj = 1
j=1
X
n
ai,j yj ≤ di z forall i ∈ I = {1 . . . m}
j=1
yj ≥ 0 forall j ∈ J = {1 . . . n}
z≥0
cT x + d
min
eT x + f
subject to eT x + f > 0
Gx ≤ h
min cT y + dz
subject to Gy − hz ≤ 0
eT y + fz = 1
z≥0
CHAPTER 6. BILLONNET 408
x∗ = y∗ + z∗ , y∗ = x∗ /(eT x∗ + f) , z∗ = 1/(eT x∗ + f)
409 CHAPTER 6. BILLONNET
Modeling Steps
1. The sum of all invested parts must be one, this is formulated by the
constraint C1.
2. The yield must be at least ρ, The earning on a title is the expected rate
times the invested part of this title. The sum must be ρ. This is con-
straint C2.
3. Finally, we want to minimize the risk. The total risk is measured by
the sum of the (positive and negative) deviations from the expected
eanrings on each title. The deviation of a single title i can be measured
by vi x2i . The quadratic term makes sure that the risk increased with an
increasing (positive or negative deviation. Hence the sum of these risks
is minimized.
constraint
C1: sum{i} x = 1;
C2: sum{i} r*x >= rho;
minimize risk: sum{i,j} v[i,j]*x[i]*x[j];
Writep(risk,rho,x);
end
411 CHAPTER 6. BILLONNET
Modeling Steps
To translate the piecewise linear function into a linear model the following
steps have to be processed:
Sos2(< variable − list >) is a special constraint saying that exactly 2 consec-
utive variables in the list are different from zero, all others must be zero. (For
more theoretical background see [16], Chapter 9.3.)
A Sos2(λk , ∀ k = {1 . . . K}) can be transformed into linear constraints as fol-
lows:
CHAPTER 6. BILLONNET 412
xk ≥ 0, k = {1 . . . K − 1} with xk ∈ {0, 1}
λ
X k ≤ xk + xk+1 , ∀ k = {1 . . . K − 1}
xk = 1
k
In LPL, the piecewise linear function is added using the << ... >> notation.
LPL then translates the model autoamtically into an integer linear model:
This notation could also be explicitly added to the model by replacing the
constraint with the following piece of code in LPL:
-- the following is equivalent to the <<piecewise-
linear-code>>
variable la{k};
constraint
C1: e = sum{k} la*b;
C2: y = sum{k} la*a;
C3: sum{k} la = 1;
C4: Sos2({k} la);
The Sos() constraint (C4) can also be replaced by the linear constraints as
follows:
413 CHAPTER 6. BILLONNET
1
http://lpl.virtual-optima.com/lpl/Solver.jsp?name=/Bill320
CHAPTER 6. BILLONNET 414
X
Γ (x) = fi,j (xi,j ) · xi,j
(i,j)∈A
.
Let fi,j (xi,j ) be piecewise linear fonctions (for each (i, j) ∈ A there is one piece-
wise linear function) defined by points as follows:
The p points with k = {1 . . . p} for each piecewise linear function (i, j) ∈ A are
given by the data as follows:
Find a flow of size ω from the source (node 1) to the sink (node n) through
the network such that the total costs are minimal. (This problem instance is
from [1] p.320, Problem 23).
Modeling Steps
X
min fi,j (xi,j ) · xi,j
(i,j)∈A
subject to 0 ≤
X xi,j ≤ ui,j X forall (i, j) ∈ A
xj,i = xi,j forall i ∈ V \ {1, n}
X
j|(i,j)∈A j|(i,j)∈A
x1,j = ω
j|(1,j)∈A
In the objective function we minimize the total flow costs. The flow on each
arc (i, j) should be in the range [0 . . . ui,j ]. For each arc (except the source
and the sink) the sum of the incoming flows must be the sum of the outgoing
flows. And finally, the sum of the flows outcoming from the source is fixed to
be ω.
415 CHAPTER 6. BILLONNET
;
Read{i,j}('%2:Table', i,j, {k}d[i,j,k+1]);
u{i,j}:=sum{k} b;
variable x{i,j|e} [0..u];
variable t{i,j,k};
binary variable y{i,j,k};
constraint
A{i|i>1 and i<#i}: sum{j} x[i,j] = sum{j} x[j,i];
B: sum{j} x[1,j] = flow;
C1{e[i,j]}: x[i,j] = sum{k} t[i,j,k];
C2{e[i,j],k|k<#k}: t[i,j,k] >= b[i,j,k]*y[i,j,k+1];
C3{e[i,j],k}: t[i,j,k] <= b[i,j,k]*y[i,j,k];
minimize cost: sum{e[i,j],k} d[i,j,k]*t[i,j,k];
write cost,x;
end
*/
end
The data and the solution are given in the Table 6.1. Further
Pdata are given as
follows: the flow is ω = 50, the capacity is given as ui,j = k bi,j,k .
As an example, the piece-wise linear function for the arc (7, 8) is given in
Figure 6.2.
could simply be replaced by the following piece of LPL code – it’s exactly the
same:
variable lambda{e[i,j],k};
constraint C1{e[i,j]}: sum{k} lambda = 1;
constraint C2{e[i,j]}: x = sum{k} b*lambda;
constraint C3{e[i,j]}: Sos2({k} lambda);
minimize cost: sum{e[i,j]} (sum{k} d*lambda);
To solve the problem, the Sos2 constraints must be interpreted by the solver.
LPL sends them directly to the solver, if it is capable to interpret them (this
is the case for Gurobi and Cplex). If the solver does not understand these con-
straints then they must be further linearized. In the previous model we must
replace the following constraint:
constraint C3{e[i,j]}: Sos2({k} lambda);
So, basically, we need to specify additional binary variables y that selects the
linear interval within the piecewise linear function and two additional con-
straint types. The complete mixed integer model of the flow model would
then be as follows – a model that is much more involving from the formula-
tion point of view3 :
model p23_2 "A Cost Flow Problem";
set i,j "vertices";
k :=[1..4] "piecewise points";
e{i,j} "Arcs";
parameter flow; u{i,j};
d{i,j,k}; b{i,j,k}; // piecewise points
variable x{i,j|e} [0..u];
variable lambda{e[i,j],k};
3
The mathematical background of these linearization can be found in [1] p. 200ff,
227, and 320ff
CHAPTER 6. BILLONNET 420
M ISCELLANEOUS
421
CHAPTER 7. MISCELLANEOUS 422
Modeling Steps
u{cr,plants};
e{cf,plants};
d{cf,markets};
v{cf,markets};
x{cf,plants,markets};
constraint
r1{cf,markets}: d = DT*(1+rse/100)*dd/100;
mbf{cf,plants}: sum{process} a3*z >= sum{markets} x +e;
mbi{ci,plants}: sum{process} a2*z >= 0;
mbr{cr,plants}: sum{process} a1*z + u >= 0;
cc{produnit,plants}: sum{process} b*z <= k;
mr{cf,markets}: sum{plants} x+v >= d;
me{cf}: sum{plants} e <= eb;
r2: phipsi = sum{cr,plants} pd*u;
r3: philam = sum{cf,plants,markets} if(rd1 , (0.0084*
rd1+2.48)*x)
+ sum{cf,plants} if(rd2,(0.0084*rd2+2.48)*e)
+ sum{cf,markets} if(rd3,(0.0084*rd3+2.48)*v);
r4: phipi = sum{cf,markets} pv*v;
r5: phieps = sum{cf,plants} pe*e;
minimize phi: phipsi + philam + phipi - phieps;
Writep(phi);
end
429 CHAPTER 7. MISCELLANEOUS
Modeling Steps
1. There are three sets: the time periods (t), the products (p), and the ma-
chines (m).
2. The prices for each product is Pricep .
3. Timem,p is the time (in hours) that a machine m takes to manufacture
one unit of product p.
4. Limitt,p is the upper limit of sales of a product p in period t.
5. Capacityt,m is the quantity of any product a machine m can manufac-
ture in period t.
6. We introduce three variables: the quantity of products p that are manu-
factured in period t: Manufp,t ; the quantity sold of product p in period
t: Salesp,t , and the quantity stored of product p at the end of time pe-
riod t: Stockp,t .
7. The inventory at the end of the last period must be 50:
1. Suppose that machine MACHE has broken down at the end of the first
period and cannot be replaced. What is the main consequence for the
production? What is the new contribution?
2. The model did not consider any production costs (only inventory cost
were considered). How could we take into account production cost, say,
to manufacture one unit of a product costs 5 (for all products). Model
it!
1. Product 3 and five are not manufactured anymore after period 1. Why?
The contribution is: 54592.14. To achieve this, the capacities of MACHE
must be set to zero after the first period. Just set:
{t|t>1} (Capacity[t,'MACHE']:=0);
Problem: This is a version of the famous beer game problem: Consider a sim-
plified beer supply chain, consisting of a single retailer, a single wholesaler
which supplies the retailer, a single distributor which supplies the wholesaler,
and a single factory with unlimited raw materials which makes (brews) the
beer and supplies the distributor. Each component in the supply chain has
unlimited storage capacity, and there is a fixed supply lead time and order
delay time between each component.
Each week, each component in the supply chain tries to meet the demand of
the downstream component. Any orders which cannot be met are recorded
as backorders, and are met as soon as possible. No orders will be ignored,
and all orders must eventually be met. At each period, each component in the
435 CHAPTER 7. MISCELLANEOUS
supply chain is charged a (1.00) shortage cost per backordered item. Also, at
each period, each location is charged (0.50) inventory holding cost per inven-
tory item that it owns. Each component owns the inventory at that facility. In
addition, the wholesaler owns inventory in transit to the retailer; the distrib-
utor owns inventory in transit to the wholesaler; the factory owns both items
being manufactured and items in transit to the distributor.
Each supply chain member orders some amount from its upstream supplier.
It takes one week for this order to arrive at the supplier. Once the order ar-
rives, the supplier attempts to fill it with available inventory, and there is an
additional two week transportation delay before the material being shipped
by the supplier arrives at the customer who placed the order.
The goal of the retailer, wholesaler, distributor, and factory, is to minimize to-
tal cost, either individually, or for the system. (see: http://beergame.mit.edu).
Modeling Steps
1. First we identify the players of the system and fix the time horizon:
There are four players: Retailer WholeSaler Distributor Factory, in this
order defining the down- and up-flow stream of placing orders and
delivery of the products. The time horizon defines the length of the
"game".
2. In each period the costumer demand an amount of the product (demand).
3. Then we define a minimal stock at which an order should be placed, if
the Inventory fall beneath that point (s) and an amount of stock that is
desirable (S).
4. Further data are the initial stock at the first period for each player (Init).
5. The main data the be calculated are: the Order issues in each period
from each player the up-stream (O) and the resulting Inventory level in
each period for each player (I).
6. The Orders are decisions to take at each period: How much should I
order to minimize my costs? If each player knows the end demand
from the customer, then he can take the politic to order the average
demand in each period. This would probably minimize the Inventory
overall and for each player.
7. However, normally the players use their own strategies to fill the stock.
One such strategy could be the s-S-rule: "If the stock is below the amount
of s then issue an order that fill it up to S, with s ≤ S.
8. In our case, we also consider back log orders, that is orders that cannot
be fulfilled in a period must be fulfilled at a later time period (at heavy
costs). (we can model this fact as negative Inventories.)
CHAPTER 7. MISCELLANEOUS 436
9. The rule implemented in the model is: use the s-S rule, however look at
the order issues in the previous period and deduce it from the present
order (this avoids to have to much stock after the time lag. That is,
Op,i = ⇐⇒ (Ip,i + Op,i−1 ≤ s, S − Ip,i − Op,i−1 ).
10. The Inventory then is calculated as follows: Ip,i = ⇐⇒ (i = 1, Initp , Ip,i−1 )+
Op,i−3 −demandi for the retailer and Ip,i = ⇐⇒ (i = 1, Initp , Ip,i−1 )+
Op,i−3 + Op−1,i−1 where we think of p − 1 the next player up-stream.
Solution: The solutions to the two order strategies are given in the following
figures.
Further Comments: The beer game show very well that a supply chain is
not inherently stable, as one can see from the results. Demand variability in-
creases as one moves up the supply chain away from the retail customer, and
small changes in consumer demand can result in large variations in orders
placed upstream. Eventually, the network can oscillate in very large swings
as each organization in the supply chain seeks to solve the problem from its
own perspective. This phenomenon is known as the bullwhip effect and has
been observed across most industries, resulting in increased cost and poorer
service.
The following reasons contribute to the bullwhip effect:
1. Overreaction to backlogs
2. No communication nor coordination up and down the supply chain
3. Local decision in ordering in order to reduce inventory
4. Order batching, that is, larger orders in an effort to reduce ordering
costs
5. Demand forecast inaccuracies.
6. Larger delay in delivery down the chain, an delay placing orders up the
chain.
One way to reduce the bullwhip effect is through better information, either in
the form of improved communication along the supply chain or (presumably)
better forecasts. Because managers realize that end-user demand is more pre-
dictable than the demand experienced by factories, they attempt to ignore sig-
nals being sent through the supply chain and instead focus on the end-user
demand. This approach ignores day-to-day fluctuations in favor of running
level. (In the present model, for example, it would substantially reduce the
inventories for all players, if each player only orders up-stream the mean de-
mand from costumers, independently what the successors or follower order.
Try: Op,i = 2.)
Another solution is to reduce or eliminate the delays along the supply chain.
In both real supply chains and simulations of supply chains, cutting order-to-
delivery time by half can cut supply chain fluctuations by 80reduced inven-
tory carry costs, operating costs also decline because less capacity is needed
to handle extreme demand fluctuations.
CHAPTER 7. MISCELLANEOUS 438
Modeling Steps
A small instance with two products and 4 time periods is given in the data
model:
1. Remove the constraints TecCapacity and the costs drop from 1467.50
to 615.
2. Add a new last instruction in the data model:
d{p,t} := 1.1*d[p,t]; (d{p,t} := 0.9*d[p,t];)
Note that at an addition 10% of the demand the problem becomes in-
feasible, because the technical capacity is too small to generate the de-
mand.
CHAPTER 7. MISCELLANEOUS 440
Problem: This model determines a series of workforce levels that will most
economically meet demands and inventory requirements over time, while
minimizing overall costs. There are wage costs (regular and overtime), hiring
costs, layoff costs, demand shortage costs, and inventory costs. How many
workers should be employed, on a regular or overtime basis, hired or fired at
each period?
Modeling Steps
Model from: FOURER R. and GAY D.M. and KERNIGHAN B.W., [1990], A
Modeling Languagef for Mathematical Programming, in: Management Sci-
ence, Vol. 36, p. 519ff.
CHAPTER 7. MISCELLANEOUS 444
Modeling Steps
Modeling Steps
1. ...
end
model data2;
/* data2: OPT= , Var:1613, Const:1521, Ints:181,
NonZeroes: 44071, density: 1.7963% */
f := [1..13];
p := [1..11];
w := [1..10];
c := [1..20];
CAPACITY{f,p} := if(Rnd(0,1)<0.95 , Rnd(500,2200));
PCOST{f,p} := if(CAPACITY , Rnd(200,300));
SCOST{f,w} := if(Rnd(0,1)<0.95 , Rnd(1,20));
TCOST{w,c} := if(Rnd(0,1)<0.90 , Rnd(15,70));
DEMAND{c,p} := Rnd(20,100);
/* different parameters
CAPACITY{f,p} := if(Rnd(0,1)<0.95 , Rnd(500,2200));
PCOST{f,p} := if(CAPACITY , Rnd(200,300));
SCOST{f,w} := if(Rnd(0,1)<0.65 , Rnd(1,20));
TCOST{w,c} := if(Rnd(0,1)<0.75 , Rnd(15,70));
DEMAND{c,p} := Rnd(20,100); */
end
model data3;
f := [1..13];
p := [1..20];
w := [1..10];
c := [1..20];
CAPACITY{f,p} := if(Rnd(0,1)<0.95 , Rnd(500,2200));
PCOST{f,p} := if(CAPACITY , Rnd(200,300));
SCOST{f,w} := if(Rnd(0,1)<0.95 , Rnd(1,20));
TCOST{w,c} := if(Rnd(0,1)<0.90 , Rnd(15,70));
DEMAND{c,p} := Rnd(20,100);
end
model data4;
f := [ topeka ny ];
p := [ chips nachos ];
w := [ topeka ny ];
c := [ east south west ];
CAPACITY{f,p} := /
topeka chips 200
topeka nachos 800
ny chips 600/;
PCOST{f,p}:=/
topeka chips 230
topeka nachos 280
ny chips 255 /;
SCOST{f,w} := /
topeka topeka 1
topeka ny 45
ny ny 2
ny topeka 45 /;
TCOST{w,c} := /
449 CHAPTER 7. MISCELLANEOUS
topeka east 60
topeka south 30
topeka west 40
ny east 10
ny south 30
ny west 80 /;
DEMAND{c,p} := /
east chips 200
east nachos 50
south chips 250
south nachos 80
west chips 150
west nachos 300 /;
end
model data;
f := [1..10];
p := [1..7];
w := [1..20];
c := [1..20];
CAPACITY{f,p} := if(Rnd(0,1)<0.85 , Rnd(200,800));
PCOST{f,p} := if(CAPACITY , Rnd(200,300));
SCOST{f,w} := if(Rnd(0,1)<0.65 , Rnd(1,20));
TCOST{w,c} := if(Rnd(0,1)<0.75 , Rnd(15,70));
DEMAND{c,p} := Rnd(50,250);
end
model output;
Write('Total costs are: %15.2f\n', COST);
Write('Assignment:\n warehouse assigned centers\
n\
-------------------------------------\n');
Write{w}(' %6s %5s\n', w, {c|ASSIGN}c);
Writep(PRODUCE,SHIP,ASSIGN);
end
end
CHAPTER 7. MISCELLANEOUS 450
Modeling Steps
Writep(totalProfit,X,S);
model data "an model instance";
t := [1..5];
p := [nuts bolts washers];
r := [nickel iron];
initStock{r}:=[7.32 35.8];
value{r}:=[-0.01 0.025];
cost{r}:=[0.025 0.03];
maxPrd := 123.7;
profit{p,t} :=[1.73 1.8 1.6 2.2 .
1.82 1.9 1.7 2.5 .
1.05 1.1 0.95 1.33 .];
units{r,p} := [0.21 0.17 0.08
0.79 0.83 0.92];
end
end
CHAPTER 7. MISCELLANEOUS 452
Modeling Steps
There are different ways of attacking the problem. One way is to begin with
the data.
1. Resale value r and storage cost s: they depend on the product types,
hence we have rk and sk for each product type k.
2. Storage capacity u: supposing that each product type has its limits, then
we have uk for each product type k.
3. Demand d and selling price: Suppose we have a different demand and
price for each product type k in each time period i (summer and win-
ter), then this gives two tables di,k and pi,k .
4. The different machines h have different availability time a in the vari-
ous production modes j (normal and overtime) and in the different time
periods i. Hence the data are given in a three-dimensional table ai,j,h .
5. Each unit of product k manufatured at each machine h in each period i
and under the different production modes j has different costs c. This
is specified in a four-dimensional table ci,j,k,h .
6. Finally, each machine h needs a different time t to manufacture a unit of
a product k in each time period i under the different production modes
j. Hence ti,j,k,h . (Of course, we might suppose that this time t does not
depend on production modes j neither on the time period i. In this case
we would have tk,h . The modeller has the liberty here to specify the
data, but it depends on the context. We choose a finer grid in the data.)
7. Now we might ask: what are the variables, the unknown quantities,
to be calculated. Certainly we need to specify the quantity sold Z and
stored Y of each product type k in each time period i. Hence we get Zi,k
and Yi,k .
453 CHAPTER 7. MISCELLANEOUS
Sx{i,k}
p1 p2 p3
summer 45.00 32.17 30.00
winter 51.79 22.83 25.00
Y{i,k}
p1 p2
summer 20.00 2.17
winter 41.79
Z{i,k}
p1 p2 p3
455 CHAPTER 7. MISCELLANEOUS
The result says that 45 and 51.79 units are produced of product p1 in two
periods where 20 are stored after the first period and 41.79 after the second
period. 25 units are sold in the first period and 30 in the second. Hence 41.79
are left to be sold at a discount price at the end. Only 2.16 units are stored of
the product p2 after the first period and nothing after the second period, and
nothing is stored of product p3.
1. Click on the link at the beginning of the model specification. Then send
the model to the Internet solver. It returns 1842.7714.
2. Remove the storage bounding constraint BOUND and solve again. There
is almost no change in the result.
CHAPTER 7. MISCELLANEOUS 456
Problem: The Tanglewood Chair Manu. Co. has four plants located around
the country. The fabrication data are the following:
The wood required to make each chair is twenty pounds and is obtained from
two suppliers. The company purchase of at least 8 tons of wood per month
from each supplier. The cost of wood is 0.10/lb from supplier 1 and 0.075/lb
from supplier 2. The shipping cost in dollar per pound of wood from each
supplier to each plant is shown below:
P1 P2 P3 P4
sup1 0.01 0.02 0.04 0.04
sup2 0.04 0.03 0.02 0.02
The chairs are sold in New York, Houston, San Francisco and Chicago. The
transportation costs are shown below:
NY H SF C
P1 1 1 2 0
P2 3 6 7 3
P3 3 1 5 3
P4 8 2 1 4
Where should each plant buy its raw materials? How many chairs should be
made at each plant? How many chairs should be sold at each city? Where
should each plant ship its product?
459 CHAPTER 7. MISCELLANEOUS
Modeling Steps
. production smoothing
.
smooth(t=1:nweeks): &
metal(t) - sum(|t.ne.1) metal(t-1) + diff(t) &
= D(t)*curmetal
.
. material balance and satisfy demand
.
matbal(t=1:nweeks): &
-stock(t) + metal(t) + sum(|t.ne.1) stock(t-1) &
> demand(t) - D(t)*curstock
.
BOUNDS . simple bounds
.
stock(t=1:nweeks) < maxstock . stock level
diff(t=1:nweeks) < maxdiff . decrease in production
diff(t=1:nweeks) > -maxdiff . increase in production
ore(j=1:nores,t=1:nweeks) < ore purchases
.
GENERATE . generate the matrix
. end of XPRESS-LP formulation
[11] R. Fourer, D.M. Gay, and B.W. Kernighan. AMPL: A Modelling Language
for Mathematical Programming. Duxbury Press/Brooks/Cole Publ. Co.,
second edition, 2003.
[12] Hillier F.S. and Liebermann G.J. Introduction to Operations Research.
McGraw-Hill, 6rd ed., 1999.
[13] Polya G. How To Solve It. Penguin Books 1990, London, 1957.
[14] Dantzig G.B. Linear Programming and Extensions. Princeton University
Press, Princeton, New Jersey, 1963.
[15] H-O. Günther and H. Tempelmeier. Produktion und Logistik. Springer,
Berlin, 2002.
[16] Williams H.P. Model Building in Mathematical Programming. John Wiley,
Third Edition Revisted, 1993.
[17] Williams H.P. Model Building in Mathematical Programming. John Wiley,
Fifth Edition, 2013.
[18] D. Kendrick. Caution and Probing in a Macroeconomic Model. Journal
of Economic Dynamics and Control 4, 2, 1982.
[19] Murty K.G. Operations Research: Deterministic Optimization Models. Pren-
tice Hall, 1994.
[20] G.P. Kutcher, A. Meeraus, and G.T. O’Mara. Agriculture Sector and Pol-
icy Models. The World Bank, 1988.
[21] G.P. Kutcher and P.L. Scandizzo. The Agricultural Economy of North-
east Brazil. The Johns Hopkins University Press, Baltimore and London,
1981.
[22] Cesari L. Optimization – Theory and Applications. Springer Verlag, 1983.
[23] Seiford L.M. and Thall R.M. Recent developments in DEA: the mathe-
matical programming approach to frontier analysis. Journal of Economet-
rics, Vol 46, p. 7–38, 1990.
[24] Bosch R. Mind Sharpener. OPTIMA MPS Newsletter, January 2000.
[25] Shapiro RD. Optimization models for planning and allocation. John Wiley
Sons, 1984.
[26] Rosenthal R.E. Tutorial of GAMS in: GAMS: A User’s Guide. The Scientific
Press, Redwood City, California, 1988.
[27] Ahuja R.K., Magnanti T.L., and Orlin J.B. Network Flows, Theory, Algo-
rithms, and Applications. Prentice Hall, 1993.
[28] Heipcke S. Applications of optimization with Xpress. dash optimization,
2000,
467 Bibliography
www.maths.ed.ac.uk/hall/Xpress/FICO_Docs/
Xpress-booka4.pdf
A translation of [5].
[29] Hürlimann T. Reference Manual for the LPL Modelling Language, most
recent version. lpl.virtual-optima.com/lpl/doc/manual.pdf.
[30] Wiens T.B. The Economics of High-yield Agriculture, in: China: Triple-
Cropping at the Baimano Peoples’ Commune. The World Bank, Wash-
ington DC, 1985.
[31] Winston W.L. Introduction to mathematical programming, applications and
algorithms. Duxbury Press, second edition, 1995.