Model Book
Model Book
Basics
Tony Hürlimann
Department of Informatics
University of Fribourg
CH – 1700 Fribourg (Switzerland)
[email protected]
October 9, 2024
First Edition
Copyright © 2024
First Edition
All rights reserved. Department of Informatics
University of Fribourg
CH-1700 Fribourg Switzerland
Email: [email protected]
www: https://matmod.ch
i
This book is dedicated to Giulia born today
ii
iii
C ONTENTS
1 What is modeling? 5
1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.1.1 Models and their Functions . . . . . . . . . . . . . . . 7
1.1.2 The Advent of the Computer . . . . . . . . . . . . . . 9
1.1.3 New Scientific Branches Emerge . . . . . . . . . . . . . 10
1.1.4 The Consequences . . . . . . . . . . . . . . . . . . . . 12
1.2 What is a Model? . . . . . . . . . . . . . . . . . . . . . . . . 13
1.2.1 Modeling – an Informal Definition . . . . . . . . . . . 14
1.2.2 Mathematical Models . . . . . . . . . . . . . . . . . . 18
1.2.3 Related Concepts . . . . . . . . . . . . . . . . . . . . . 23
2 How to model? 27
2.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
2.1.1 Recognition and Specification of the Problem . . . . . . 29
2.1.2 Formulation of the (Mathematical) Model . . . . . . . . 30
2.1.3 Solving the Mathematical Model . . . . . . . . . . . . 31
2.1.4 Validation and Interpretation . . . . . . . . . . . . . . 32
2.1.5 The Modeling Life-Cycle . . . . . . . . . . . . . . . . . 33
2.2 The Problems . . . . . . . . . . . . . . . . . . . . . . . . . . 34
2.2.1 Problem 1: Seven Digits Puzzle . . . . . . . . . . . . . 35
2.2.2 Problem 2: The Clock Puzzle . . . . . . . . . . . . . . 35
2.2.3 Problem 3: The 6-Knights Puzzle . . . . . . . . . . . . 35
2.2.4 Problem 4: The 3-jug Problem . . . . . . . . . . . . . . 36
2.2.5 Problem 5: The Fake Coin Puzzle I . . . . . . . . . . . 36
2.2.6 Problem 6: The Fake Coin Puzzle II . . . . . . . . . . . 36
2.2.7 Problem 7: The Horse Race Puzzle . . . . . . . . . . . 36
2.2.8 Problem 8: Adding Numbers . . . . . . . . . . . . . . 36
2.2.9 Problem 9: 3d-Diagonal . . . . . . . . . . . . . . . . . 37
v
2.2.10 Problem 10: Square Inside a Triangle . . . . . . . . . . 37
2.2.11 Problem 11: Birthday Paradox . . . . . . . . . . . . . . 37
2.2.12 Problem 12: Length of Loch Ness Monster . . . . . . . 37
2.2.13 Problem 13: Price of the Ball . . . . . . . . . . . . . . . 37
2.2.14 Problem 14: Postman Problem . . . . . . . . . . . . . . 37
2.2.15 Problem 15: One Unit Missing . . . . . . . . . . . . . . 38
2.2.16 Problem 16: How old am I? . . . . . . . . . . . . . . . 38
2.2.17 Problem 17: 7-Digits Puzzle (redo) . . . . . . . . . . . 38
2.2.18 Problem 18: The Clock Puzzle (redo) . . . . . . . . . . 38
2.3 The Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . 38
2.3.1 Problem 1: Seven Digits Puzzle . . . . . . . . . . . . . 39
2.3.2 Problem 2: The Clock Puzzle . . . . . . . . . . . . . . 39
2.3.3 Problem 3: The 6-Knights Puzzle . . . . . . . . . . . . 40
2.3.4 Problem 4: The 3-jug Problem . . . . . . . . . . . . . . 41
2.3.5 Problem 5: The Fake Coin Puzzle I . . . . . . . . . . . 43
2.3.6 Problem 6: The Fake Coin Puzzle II . . . . . . . . . . . 44
2.3.7 Problem 7: The Horse Race Puzzle . . . . . . . . . . . 44
2.3.8 Problem 8: Adding Numbers . . . . . . . . . . . . . . 47
2.3.9 Problem 9: 3d-Diagonal . . . . . . . . . . . . . . . . . 48
2.3.10 Problem 10: Square Inside a Triangle . . . . . . . . . . 48
2.3.11 Problem 11: Birthday Paradox . . . . . . . . . . . . . . 49
2.3.12 Problem 12: Length of Loch Ness Monster . . . . . . . 50
2.3.13 Problem 13: Price of the Ball . . . . . . . . . . . . . . . 50
2.3.14 Problem 14: Postman Problem . . . . . . . . . . . . . . 51
2.3.15 Problem 15: One Unit Missing . . . . . . . . . . . . . . 52
2.3.16 Problem 16: How old am I? . . . . . . . . . . . . . . . 53
2.3.17 Problem 17: 7 Digits Puzzle (redo) . . . . . . . . . . . . 54
2.3.18 Problem 18: The Clock Puzzle (redo) . . . . . . . . . . 55
2.4 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
9 My Vision 375
9.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . 376
9.2 Algorithmic Knowledge . . . . . . . . . . . . . . . . . . . . . 377
9.3 Mathematical Knowledge . . . . . . . . . . . . . . . . . . . . 383
9.4 Historical Notes . . . . . . . . . . . . . . . . . . . . . . . . . 385
9.5 Combine mathematical and algorithmic knowledge . . . . . . 388
9.5.1 The Sorting Problem . . . . . . . . . . . . . . . . . . . 388
9.5.2 The 0-1 Knapsack Problem . . . . . . . . . . . . . . . . 389
9.5.3 The Two-Persons Zero-Sum Game . . . . . . . . . . . . 390
9.5.4 The Cutting Stock Problem . . . . . . . . . . . . . . . 390
9.5.5 The Traveling Salesman Problem (TSP) . . . . . . . . . 392
9.6 Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . 393
9.7 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . 396
ix
L IST OF F IGURES
2
L IST OF TABLES
3
P REFACE
The book is for all persons eager to learn mathematical modeling, especially
for students in operations research and management sciences or business an-
alytics, in order to solve all kind of problems. I also have books with a huge
number of various problems with which one may learn modeling with con-
crete applications and puzzles (see https://matmod.ch).
The book is also for the modeling language designer, to illustrate – what I
have found to be – the most important concepts in modeling and their imple-
mentations. I believe that one of the most important aspects of a modeling
language is to be able to create models that are readable and compact and,
of course, models that can be broken into smaller pieces of information that
encapsulate related elements
To use the LPL modeling system, the reader does not need to install any soft-
ware to run and solve models presented in this and other books. Only an
Internet browser and an Internet connection is needed. In the electronic ver-
sion of this book, a link appears in the title of each case-study. 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 problem and present it to the LPL-server as
well. Just click “Send” to solve it.
3
The book was compiled using the typesetting system LATEX. However, the
documentation of all “case studies” was written in LPL’s own “literate doc-
umentation system”. LPL contains a documentation tool (similar to javadoc
for Java programs) to automatically translate a documented model into a full
LATEX or HTML code. Additional information for this tool can be found in the
Reference Manual of LPL.
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.
LPL – the software – together with a documentation containing the Reference
Manual, several papers and examples can be downloaded at:
https://matmod.ch
W HAT IS MODELING ?
5
CHAPTER 1. WHAT IS MODELING? 6
1.1. Introduction
Observation is the ultimate basis for our understanding of the world around
us. But observation alone only gives information about particular events; it
provides little help for dealing with new situations. Our ability and aptitude
to recognize similarities and patterns in different events, to distil the impor-
tant factors for a specific purpose, and to generalize our experience enables
us to operate effectively in new environments. The result of this skill is knowl-
edge, an essential resource for any intelligent agent.
Knowledge varies in sophistication from simple classification to understand-
ing and comes in the form of principles and models. A principle is simply a
general assertion and is expressed in a variety of ways ranging from saws,
slogans, opinions to mathematical equations. They can vary in their validity
and their precision. A model is, roughly speaking, an analogy or a mapping
for a certain object, process, or phenomenon of interest. It is used to explain,
to predict, or to control an event or a process. For example, a miniature replica
of a car, placed in a wind tunnel, allows us to predict the air resistance or air
eddy of a real car; a globe of the world allows us to estimate distances be-
tween locations; a graph consisting of nodes (corresponding to locations) and
edges (corresponding to streets between the locations) enables us to find the
shortest path between any two locations without actually driving between
them; and a differential equation system enables us to balance an inverted
pendulum by calculating at short intervals the speed and direction of the car
on which the pendulum is fixed.
A model is a powerful means of structuring knowledge, of presenting infor-
mation in an easily assimilated and concise form, of providing a convenient
7 CHAPTER 1. WHAT IS MODELING?
they just prove true because many follow them. Many models in social pro-
cesses are of that type. We all follow certain principles, rules, standards, or
maxims which control or influence our behavior.
Still other models constitute the basis for making decisions. The famous water-
fall model in the software development cycle says that the implementation of
a new software has to proceed in stages: analysis, specification, implementa-
tion, installation and maintenance. It gives software developers a general idea
of how to proceed when writing complex software and offers a rudimentary
tool to help them decide in which order the tasks should be done. It does not
say anything about how long the software team have to remain at any given
stage, nor what they should do if earlier tasks have to be revised: It represents
a rule-of-thumb.
An example of a more formal and complex decision-making-model would be
a mathematical production model consisting typically of thousands of con-
straints and variables as used in the petroleum industry to decide how and
in what quantities to transform crude oil into petrol and fuel. The constraints
– written as mathematical equations (or inequalities) – are the capacity limi-
tations, the availability of raw materials, etc. The variables are the unknown
quantities of the various intermediate and end products to be produced. The
goal is to assign numerical values to the variables so that the cost are mini-
mized, profit is maximized or some other goals are attained.
Both models are tools in the hand of an intelligent agent and guide her in her
activities and support him in his decisions. The two models are very differ-
ent in form and expression; the waterfall model contains only an informal list
of actions to be taken, the production model, on the other hand, is a highly
sophisticated mathematical model with thousands of variables which needs
to be solved by a computer. But the degree of formality or complexity is not
necessarily an indication of the “usefulness” of the model, although a more
formal model should normally be more precise, more concise, and more con-
sistent. Verbal and pictorial models, on the other hand, give only a crude view
of the real situation.
Models may or may not be pertinent for some aspects of reality; they may
or may not correspond to reality, which means that models can be misleading.
The medieval model of human reproduction suggesting that babies develop
from homunculi – fully developed bodies within the woman’s womb – leads
to the absurd conclusion that the human race would become extinct after a
finite number of generations (unless there is an infinite number of homunculi
nested within each other). The model of a flat, disk-shaped earth may have
prevented many navigators from exploring the oceans beyond the nearby
coastal regions because they were afraid of “falling off” at the edge of the
earth disk. The model of the falling profit rate in Marx’s economic theory pre-
dicted the self-destruction of capitalism, since the progress of productivity is
reflected in a decreasing number of labor hours relative to the capital. Accord-
ing to this theory, labor is the only factor that adds plus-value to the products.
9 CHAPTER 1. WHAT IS MODELING?
Schumpeter agreed on Marx’s prediction, but based his theory on a very dif-
ferent model: Capitalism will produce less and less innovative entrepreneurs
who create profits! The last two examples show that very different sophisti-
cated models can sometimes lead to the same conclusions.
One can see from these examples that models are ubiquitous and omnipresent
in our lives. “The whole history of man, even in his most non-scientific activi-
ties, shows that he is essentially a model-building animal” [55] (see also [60]).
We live with “good” and “bad”, with “correct” and “incorrect” models. They
govern our behavior, our beliefs, and our understanding of the world around
us. Essentially, we see the world by means of the models we have in mind.
The value of a model can be measured by the degree to which it enables us
to answer questions, to solve problems, and to make correct predictions. Bet-
ter models allow us to make better decisions, and better decisions lead us to
better adaptation and survival – the ultimate “goal” of every being.
This paper is not about models in general, their variety of functions and char-
acteristics. It is about a special class thereof: mathematical models. Mathe-
matics has always played a fundamental role in representing and formulating
our knowledge. As sciences advance they become increasingly mathematical.
This tendency can be observed in all scientific areas irrespective of whether
they are application- or theory-oriented. But it was not until last century that
formal models were used in a systematic way to solve practical problems.
Many problems were formulated mathematically long ago, of course. But of-
ten they failed to be solved because of the amount of calculation involved.
The analysis of the problem – from a practical point of view at least – was
usually limited to considering small and simple instances only.
The computer has radically changed this. Since a computer can calculate ex-
tremely rapidly, we are spurred on to cast problems in a form which they can
manipulate and solve. This has led to a continuous and accelerated pressure
to formalize our problems. The rapid and still ongoing development of com-
puter technologies, the emergence of powerful user environment software for
geometric modeling and other visualizations, and the development of numer-
ical and algebraic manipulation on computers are the main factors in making
CHAPTER 1. WHAT IS MODELING? 10
by the end of the century. Some scientists believe that we are not far from
that point. Even though most problems in AI turned out to be algorithmi-
cally hard, since they are closely related to combinatorial problems. This led
to an intensive research of heuristics and “soft” procedures – methods we hu-
mans use daily to solve complex problems. The combination of these methods
and the computer’s extraordinary speed in symbolic manipulation produces
a powerful means to implement complex problems in AI.
Other scientific communities had already developed highly efficient proce-
dures for solving sophisticated numerical problems before the first computer
was built. This is especially true in physics and engineering. For example,
Eugène Delaunay (1816-1872) made a heroic effort to calculate the moon’s or-
bit. He dedicated 20 years to this pursuit, starting in 1847. During the first ten
years he carried out the hand calculation by expressing the differential sys-
tem as a lengthy algebraic expression in power series, then during the second
ten years he checked the calculations. His work made it possible to predict the
moon’s position at any given time with greater precision than ever before, but
it still failed to match the accuracy of observational data from ancient Greece.
A hundred year later, in 1970, André Deprit, Jacques Henrard and Arnold
Rom revised Delaunay’s calculation using a computer-algebra system. It took
20 hours of computer time to duplicate Delaunay’s effort. Surprisingly, they
found only 3 minor errors in his entire work.
Many numerical algorithms, such as the Runge-Kutta algorithm and the Fast
Fourier Transform (FFT), were already known – the later even by Gauss –
before the invention of the computer and they were much used by human
“computers”. But for many problems these efforts were hopeless, for the sim-
ple reason that the human computer was too slow to execute the simple but
lengthy arithmetics.
An interesting illustration of this point is the origin of numerical meteorol-
ogy. Prior to World War II, weather forecasting was more of an art, depending
on subjective judgement, than a science. Although, in 1904, Vilhelm Bjerknes
had already elaborated a system of 6 nonlinear partial differential equations,
based on hydro- and thermodynamic laws, to describe the behavior of the
atmosphere, he recognized that it would take at least three months to calcu-
late three hours of weather. He hoped that methods would be found to speed
up this calculation. The state of the art did not fundamentally change un-
til 1949 when a team of meteorologists – encouraged by John von Neumann,
who regarded their work as a crucial test of the usefulness of computers –
fed the ENIAC with a model and got a 24-hour “forecast”, after 36 hours of
calculations, which turned out to be surprisingly good. Four years later, the
Joint Numerical Weather Prediction Unit (JNWPU) was officially established;
they bought the most powerful computer available at that time, the IBM 701,
to calculate their weather predictions. Since then, many more complex mod-
els have been introduced. The computer has transformed meteorology into a
mathematical science.
CHAPTER 1. WHAT IS MODELING? 12
But how can modeling be learnt? Problems, in practice, do not come neatly
packaged and expressed in mathematical notation; they turn up in messy,
confused ways, often expressed, if at all, in somebody else’s terminology.
Therefore, a modeler needs to learn a number of skills. She must have a
good grasp of the system or the situation which she is trying to model; she
has to choose the appropriate mathematical methods and tools to represent
the problem formally; she must use software tools to formulate and solve the
models; and finally, she should be able to communicate the solutions and the
results to an audience, who is not necessarily skilled in mathematics.
So, the novice needs first to be an observer and then, very quickly, a do-er.
Modeling is not learnt only by watching others build models, but also by
being actively and personally involved in the modeling process.
The term model has a variety of meanings and is used for many different pur-
poses. We use modeling clay to form small replica of physical objects; children
– and sometimes also adults – play with a model railway or model aeroplane;
architects build (scale) model houses or (real-size) model apartments in order
to show them to new clients; some people work as photo models , others take
someone for a model, many would like to have a model friend. Models can
be much smaller than the original (an orrery, a mechanical model of the solar
system) or much bigger (Rutherford’s model of the atom). A diorama is a
three-dimensional representation showing lifelike models of people, animals,
or plants. A cutaway model shows its prototype as it would appear if part
of the exterior had been sliced away in order to show the inner structure. A
sectional model is made in such a way that it can be taken apart in layers or
sections, each layer or section revealing new features (e.g. the human body).
Working models have moving parts, like their prototypes. Such models are
very useful for teaching human anatomy or mechanics.
The ancient Egyptians put small ships into the graves of the deceased to en-
able them to cross the Nile. In 1679, Colbert ordered the superintendents of
all royal naval yards to build an exact model of each ship. The purpose was
to have a set of models that would serve as precise standards for any ships
built in the future. (Today, the models are exposed in the Musée de la Marine
in Paris.) Until recently, a new aeroplane was first planned on paper. The
next step was to build a small model that was placed in a wind-tunnel to test
its aerodynamics. Nowadays, aeroplanes are designed on computers, and
sophisticated simulation models are used to test different aspects of them.
The various meanings of model in the previous examples all have a common
feature: a model is an imitation, a pattern, a type, a template, or an idealized
object which represents the real physical or virtual object of interest. In the ship
example, both the original and the model are physical objects. The purpose
is always to have a copy of some original object, because it is impossible, or
too costly, to work with the original itself. Of course, the copy is not perfect
in the sense that it reproduces all aspects of the object. Only some of the
particularities are duplicated. So an orrery is useless for the study of life on
Mars. Sectional models of the human body cannot be used to calculate the
body’s heat production. Colbert’s ship models were built so accurately that
they have supplied invaluable data for historical research, this was not their
original purpose. Apparently, the use made of these ship models has changed
over time.
Besides these physical models, there are also mental ones. These are intuitive
models which exist only in our minds. They are usually fuzzy, imprecise, and
often difficult to communicate.
Other models are in the form of drawings or sketches,
15 CHAPTER 1. WHAT IS MODELING?
A A
B C D E B C ?? D E
F F
B D C E
Now the problem is easily solvable. Connect the squares as prescribed. After
this, return the rubber to the initial state again (Figure 1.4).
(A completely different approach to solve this problem can be found in my
My Books – which is a good (advanced) exercise in mathematical modeling,
see also the implemented model at intersec.)
B C D E
Let’s summarize:
• The model is the result of a mapping (or a transformation) of the real or
virtual object to be considered.
• the model is an abstraction, i.e. only some aspects of the objects of inter-
est are mapped, all others are ignored (abstrahere = leaving out).
17 CHAPTER 1. WHAT IS MODELING?
• the aspects that enter the model are of special interest for an intelligent
actor (the model-builder and the model-user): The model is used for a
certain purpose.
• a model has some simple, concise (and aesthetic) structure that captures
the focused aspects of the object.
A good example is modern physics: Neglecting the Planck constant (that is:
ℏ = 0), the gravitational constant (G = 0) and the speed of light (c = ∞),
physics reduces to classical mechanics. Considering the gravitational constant
(G = 6.6741×1011 [m3 /(kg·s)]) in addition, we must use Newtonian mechanics;
Considering the speed of light (c = 2.9979 × 108 [m/s] instead, we must apply
special relativity, and so on (see [35]). It is not true, that the models of classical
mechanics are learnt, because it is necessary for the “more advanced” theory
as Quantum Field Theory. It is useful and applicable for its own, namely when
the speed is small, when quantum effects are negligible, and when gravitation
is not important – that is in our every day life. Classical mechanics has plenty
of applications on its own. Each model in physics has its own eligibility and
purpose, it will do to know its limitation.
Hence, we saw that a problem can be approached with different models. The
contrary is also true: A (formal) model might have various interpretations. The
intersection problem was built of a rectangle with 6 locations in it (A, B, C, D,
E, and F) and connecting lines. So it is basically a geometric interpretation. An-
other interpretation is as following: Replace “rectangle” with “square electric
board”, “locations” with “endpoint of wires”, and “lines” with “wires”. Now
we have the same model for a different problem: connect the endpoints of
the wires on the 2-dimensional board in such a way that they do not cross.
Another interpretation is: a oval closed room (with only one entry-point) has
corresponding (curved) walls (from a point A to F, B to D and C to E, see the
red lines in Figure 1.3) such that the whole room can be visited. Still another
interpretation is: in an area we have six airports arranged in a similar way as
the 6 locations in our original problem. Planify flight paths in such a way that
the aeroplanes never cross each other. (We suppose that only the correspond-
ing airports are linked, of course.)
Y = {x ∈ X | R(x)}
Example 1:
def
x ∈ IN+ , R(x) = (x = 1)
The state space consists of all positive numbers (IN+ ). x is a singleton variable
which must be a positive integer, and its value is 1 by definition of R, that is,
we choose exactly one number which value is true, namely 1. Hence Y = {1},
the model is feasible and has exactly one solution, namely x = 1. (It is as if we
have only one house with at least 5 windows and 2 balconies, that the unique
one we choose!)
Example 2:2
def
x ∈ IN+ , R(x) = (x = 1 ∧ x = 2)
Example 3:
def
x ∈ IR2 , R(x) = (|x1 | ≤ 1 ∧ |x2 | ≤ 1)
The state space is 2-dimensional (every tuple of two real numbers is a possi-
ble choice). x is a 2-dimensional vector variable (x = (x1 , x2 )) with the com-
ponents x1 and x2 , they must be real numbers each, and its absolute values
must be smaller or equal 1 by definition of R. Hence, the model is given by
Y = {(x1 , x2 ) | −1 ≤ x1 , x2 ≤ 1}, the model is feasible, and has an infinity num-
ber of solutions: every point in a 2-dimensional Euclidean space included in
the 2 × 2 unit square is a solution: so: (−0.5, 0.3), (0, 0), (0.1, 0.2), (0.4, 1), etc.
are solutions. (Keeping our analogy with the choosing a house problem: We
choose a house (x1 ) together with a garage (x2 .)
Example 4:
2
Note that the symbol ∧ is the Boolean and operator. This means that both x = 1
and x = 2 must be true to make the whole expression true.
CHAPTER 1. WHAT IS MODELING? 20
def
x ∈ IR2 , R(x) = (x2 = x1 + 2 ∧ x2 = x21 − 1)
The model is feasible, and has exactly two solutions. To find the solutions, we
need to solve a quadratic equation. Geometrically, the problem can be drawn
in a 2-dimensional space (see Figure 1.5), the two solutions are where the line
meets the parable.
Some mathematical models are easy to solve (the examples so far), others are
very difficult. For example the last conjecture of Fermat is a difficult model:
Example 5:
def
x = (a, b, c, n) ∈ IN4 , R(x) = (an + bn = cn ∧ n > 2)
This model is infeasible, that is, it has no solution. However, this 3-hundred
year old conjecture has been proven by the mathematician A. Wiles only at
1997, after 9 years of intensive research.
Interestingly, a generalization by Euler, namely:
def
x = (a, b, c, d, n) ∈ IN5 , R(x) = (an + bn + cn = dn )
21 CHAPTER 1. WHAT IS MODELING?
has solutions. But it was not until 1960 to find one (others were found later
on3 ):
958994 + 275194 + 275194 + 4145604 = 4224814
Even worse, it is easy to formulate models that cannot be solved because the
computer takes far too much time to find a solution, for other models one can
prove that they are unsolvable by any method.
Optimisation Models
A variant of a mathematical model is the optimization problem. In this case,
we are not interested in any or all feasible solution, but only those solutions
that maximize (or minimize) a function f(x) (in analogy of the house choosing
problem: we want the “best” house only):4
def
x ∈ IR , f(x) = −(x − 1)2 , R(x) = (true)
Example 7:
Now let us construct a real but easy problem. Answer the following question
“What is the height and the width of a cylindric aluminium can that contains
3
1966: 275 + 845 + 1105 + 1355 = 1555 or 1988: 26824404 + 153656294 + 187967604 =
206156734
4
A optimization problem is commonly noted as
min f(x)
subject to R(x)
x∈X
a volume of 1 liter (dm3 ), such that the quantity of material to build the can is
as small as possible?”
Supposing that the material has identical thickness on its surface, we may
substitute “quantity of material” by “surface of the cylinder”. Given the
height h and the diameter 2r of a cylinder, its volume is given as follows
(which must be 1):
V = πhr2 = 1
The surface O of the cylinder is then as follows (two circles and a cylinder
coat):
O = 2πr2 + 2πrh
def def
x = (r, h) ∈ IR2+ , min f(x) = 2πr2 + 2πrh , R(x) = (πhr2 = 1)
One can also simplify the model by eliminating the variable h. We then get
the model:
2
O = 2πr2 +
r
This is a minimization problem with one variable and no constraint. The so-
lution is given in Figure 1.6. The minimal usage of material to construct a
cylindric can that contains a volume of 1 liter has a radius of 5.42cm and a
height of 10.9cm, and the surface is 554cm2 . Any other size has a larger sur-
face, check it!
Another way to express the can problem – with two variables – is as follows:
Basically, every mathematical model is like our house choosing problem, only
the size of the state space change and the requirements are expressed in a
mathematical notation. At this point, I could introduce a really powerful
concept to formulate large and complex mathematical models, that is, models
with many variables and constraints. This concept is called indexing. Since it
is a so important and powerful notation, I wrote a separate paper for that (see
[67]). If you want to get a pro in mathematical modeling, these concepts are a
must!
A historical note: The concepts of the mathematical model are historically re-
cent ones. According to Tarski, “the invention of variables constitutes a turn-
ing point in the history of mathematics.” Greek mathematicians used them
rarely and in an ad hoc way. Vieta (1540-1603) was the first who made use
of variables on a systematic way. He introduced vowels to represent vari-
ables and consonants to represent known quantities (parameters). “Only at
the end of the 19th century, however, when the notion of a quantifier had be-
come firmly established, was the role of variables in scientific language and
especially in the formulation of mathematical theorems fully recognized” [1]
p.12.
this case, the different activities such as data collection, setting up the model,
solving the model, and verifying it, etc. can be distributed between the mod-
elers.
Another concept is modeling. The term is difficult to define because it is used
in so many different contexts. In art, it is used to express the process of work-
ing with plastic materials by hand to build up forms. In contrast to sculp-
turing, modeling allows corrections to be made on the forms. They can be
manipulated, built and rebuilt until its creator feels happy with the result. In
sculpturing, the objective cannot be formed, it must be cut out. Once finished,
the form cannot be modified. Scientific activities are more like modeling than
sculpturing, and therefore the common-sense meaning of modeling is used in
various research communities.
In database technology, for instance, data modeling designates the design, val-
idation, and implementation of databases by applying well-known methods
and approaches such as the entity-relationship (ER) approach and the object-
role modeling (ORM) method. From a practical point of view, data modeling
could be considered as part of mathematical modeling. It is a set of tasks
which consists of collecting, verifying, and ordering data.
Hence: Modeling is an iterative process to conceptualize, to build, to validate, and
to solve a model. Often modeling is more important than the end-product,
the model, to understand a problem. The creative process of getting though
the modeling process gives invaluable insights in the structure of a particular
problem.
(The concept of modeling process is so important that I have written a sepa-
rate paper (see [66] (How to model?).)
Two further important notions in mathematical modeling are that of model
structure and model instance. A model structure is a model where all data is
captured by symbolic entities: the parameters.5 In fact, it represents a whole
class of models. A model instance, on the other hand, does not contain any
parameters; these are replaced by concrete data. As an example, take a look
at the following differential equation:
dx rx(1 − x)
=
dt k
The equation contains two parameters r and k (and a variable x). Hence,
5
The symbols with known values are called parameters and the symbols with un-
known values are called variables – as already used above. Since these two terms
clashes with well known concepts in programming languages, the convention is
used to call the parameters in functions and procedures headings formal parame-
ters. Using these parameters in a function or procedure call will be called actual
parameters. The term variable used in programming languages, which is a name
for a memory location, will be called memory variable.
25 CHAPTER 1. WHAT IS MODELING?
H OW TO MODEL ?
27
CHAPTER 2. HOW TO MODEL? 28
This paper has three parts. It gives first a short introduction on the modeling
process, explains very briefly its stages in order to learn how to model. In
a second part a number of small problems with solutions in a third part are
exposed by which the reader can exercise the skills of modeling. To be useful,
the reader should really try hard to solve these problems and look up the
solution only after trying. It is the only way to acquire the skill of modeling.
Three problems are from [43] which is an excellent book with more than 150
puzzles. Many Internet pages and books are available with puzzles, one of the
oldest is [26]. Martin Gardner has also published a number of mathematical
puzzles in book form. The focus here is mainly on mathematical models,
hence the third part of the problems have also mathematical formulations if
appropriate. Many modeling examples of puzzles can also be found in my
puzzle and other book: See My Modeling Books.
2.1. Introduction
Modeling is an art! But modeling is also a skill that can be learnt. Every prob-
lem to be solved is new, therefore, there is no unique recipe to model and
solve it, but there are guidelines. The most important ability, however, is to
practise, to practise and to practise. Looking at the problems, try to solve them,
analyzing and reproducing how other persons solved them. In this way, the
learner gains experience and security. Also you should learn the theoretical
concepts going along the modeling process. For example, if the concept of
“graph” is used, you must learn the basic concepts of graph theory, if model-
ing a “linear mathematical model”, the basic concepts of linear algebra must
be learnt.
Basically, The process of modeling goes in stages:
Recognition is the stage where the problem is identified and the importance of
the issue is perceived; formulation is the most difficult step: the model is set
up and a mathematical structure is established; solution is the stage where an
algorithm is chosen or conceived to find a solution; finally, the model must
be interpreted and validated in the light of the original problem: Is it consis-
tent? Does it correspond to reality? etc. Modeling, however, is essentially
an iterative process where the different stages must be repeated. The reasons
are manifold: A first attempt often does not produce a satisfactory model
to the original problem. It is often too crude or simply inaccurate or even
wrong in representing the original problem. When inaccurate, the model has
to be modified; when too crude, it must be refined; when too inappropriate
the model has to be rejected. This modify-refine-reject process is very impor-
tant and it is the rule and not the exception. Keep this in mind! Every step
29 CHAPTER 2. HOW TO MODEL?
model.
Summary: Repeat the problem in your own words! Make sketches. Are there
data? What is the goal? What are the conditions? Explain the problem to
another person! Do not stop before you understand the problem entirely.
Order the facts! Name the components! Do not hesitate to restart!
Pólya, in his classical work [20] (see also [21]) about problem solving, tried to
give heuristic strategies to attack mathematical problems – an essay that every
person who does serious modeling should read. Pólya has summarized them
as follows:
1. Understanding the problem: What is (are) the unknown(s)? What are
the data? What are the conditions or constraints? Are they contradic-
tory or are some of them redundant?
31 CHAPTER 2. HOW TO MODEL?
3. Carrying out the plan: Solve the related problems. Check each step.
Once the model formulation step has been completed, the mathematical model
has to be solved, i.e. the model must be transformed using calculation in such
a way as to eliminate the unknowns. We say that a model is solved if a nu-
merical or symbolical expression containing only parameters and numbers is
assigned to each variable so that all constraints are fulfilled.
When using a solver, the model must be put into a form that can be read by
the appropriate solver. This is a laborious and error pruned task especially
for large models with lot of data involved. Data must be read and filtered
correctly from databases, the model structure must be reformulated, and the
generated output must be a correct form for input into the solver. For this
task, modeling tools such as (mathematical) modeling languages exist that can
simplify greatly this task. (I have more to say about modeling languages in a
separate paper: [70].)
CHAPTER 2. HOW TO MODEL? 32
research reveal that one of the most frequent errors made by students
when modeling is inconsistency in the units of measurement. In physics
and other scientific applications, as well as technical and commercial
ones, using units of measure in calculating has a long tradition. It in-
creases both the reliability and the readability of calculations.
4. User defined data checking: Do I have the right data? Are the data
correct and consistent? Are the data complete? Often data checking
is a huge task itself. But it is necessary, otherwise we get a garbage-in
garbage-out model, that is, the model is only useful if the data make
sense. The data should also be separated as much as possible from the
model structure (see [75]). In this way, a data set can easily be replaced
by another data set. Applying various data set (smaller data set or ran-
dom sets, etc., in a prototyping preliminary stage) can largely help to
find inconsistencies.
5. Simplicity Considerations: Can the model be simplified or reduced?
The principle of Ockham’s Razor also applies to modeling. To para-
phrase Einstein: The model should be as simple as possible, but not
simpler.
6. Solvability Checking: Formulate model that are difficult to solve is
easy. One can try various solvers, but sometimes one can modify the
model – for instance by adding trivial constraints – to help the solver
to find a solution in shorter time. These techniques need a lot of expe-
riences and cannot be exposed here (without going into the details: an
small and simple example is the Pigeon hole model pihole).
The model creation process is a difficult undertaking. I barely touched a few
highlights. What is important is to practice to gain experience and to study
in parallel the branches in mathematics used in a particular context. What
follows in a second part of this paper is a number of rather easy problems,
that the reader can try to solve. First the problems are formulated, after a
possible solution is presented with some remarks on modeling exposed in the
previous sections.
must be invented in order to capture the problem – Newton invented the in-
finitesimal calculus to explain the motion and dynamic change, such as the
orbits of planets, the motion of fluids, etc.
Once the solution is known, it must be interpreted in the light of our “real”
problem and validated by the data. Does the result make sense? Does it match
the data? If not, we must review and correct our steps. Maybe one needs to
modify the data, the assumptions, or change the whole approach all together.
Sometimes completely new insights in the problem are discovered which can
lead to a complete new “real problem” which appears to be more promising.
An the whole modeling life cycle begins afresh.
F G
8 4
7 5
6
Inscribe a square in a given triangle. Two vertices of the square are on the
base line of the triangle, and the other two vertices touch the two sides of the
triangle. Are they more then one possibilities?
Given a party of n persons, what is the probability P(n) that at least 2 persons
have the same birthday? For instance, if 30 persons are invited to a party, is it
worthwhile to make a bet that two persons have the same birthday?
If the length of the Loch Ness Monster is 20 meters and half of its length, how
long is it?
A golf club together with a ball costs 110 = C. The price difference between a
C. What is the price of a ball?
golf club and a ball is 10 =
This is the same as the Puzzle 1 above: Use each digit from 1 to 7 exactly once,
and place them into the circles of the Figure in such a way that the sum along
each of the five lines is the same. This time, create a mathematical model with
variables and constraints to solve the problem.
This is the same as Problem 2 above: Divide the clock with a straight cut into
two parts such that the sum of the numbers in both parts are equal? This
time, create a mathematical model with variables and constraints to solve the
problem.
12 · 13 y(y + 1) x(x + 1)
− +
2 2 2
12·13
This quantity must be half of all numbers from 1 to 12, that is, it must be 4 .
Simplifying the expression leads to:
(y − x) · (y + x + 1) = 6 · 13
The board and the knights do not matters, what only matters is from which
number (cell) one can jump to another number: link these numbers with a
straight line. The result is a well-known mathematical structure (a graph),
consisting of lines connected to two locations (the numbers), see Figure 2.2 at
the right. Note that from a knight board we have arrived at a very different
structure (namely the numbers linked by straight lines), the problem has been
reduced to the essential elements.
The positions of the numbers do not matter either, so we can “unfold” the
graph and place the number wherever we want. However, the connecting
lines must be preserved. Finally, we get a much simpler graph (see Figure 2.3
at the right), from which the solution can immediately be constructed: First
the two knights in the middle are moved clockwise, till they have exchanged
their places, then the outer knights are moved clockwise in the same way,
each one move after the other.
Finally, the original problem can be reconstructed by executing the knights
jumping in exactly that order. What is interesting about this puzzle – that is
7 below).
41 CHAPTER 2. HOW TO MODEL?
important for most real modeling problems – is the fact that one can ask (and
answer very easily) “what of questions”. In the solution above, for instance,
knight 1 and knight 10 exchange their places. “What if” I want to exchange
knight 1 with knight 13 instead? Is this possible? The reader would easily
find a solution.
the 3-liter jug contains nothing.” Each state can be represented by a triple of
numbers: (x, y, z), where x is the content of the 8-liter jug, y is the content of
the 5-liter jug, and z is the content of the 3-liter jug. So, (8, 0, 0) is the example
just used before. We want to reach the state (4, 4, 0). The capacities of the jug
can also be represented by a triple: (8, 5, 3).
The first step is to enumerated all states. There are 216 potential states, namely,
all states (x, y, z) with 0 ≤ x ≤ 8, 0 ≤ y ≤ 5, and 0 ≤ z ≤ 3, which is
9·6·4 = 216. However, only states with the condition x+y+z = 8 are allowed
(no water should be added or removed). Furthermore, at least one jug must
be full or empty – following the rules of pouring. This condition can be repre-
sented as a Boolean expression. x = 0 ∨ x = 8 ∨ y = 0 ∨ y = 5 ∨ z = 0 ∨ z = 3.4
There are 16 remaining possible states, they are:
{(0, 5, 3), (1, 4, 3), (1, 5, 2), (2, 3, 3), (2, 5, 1), (3, 2, 3), (3, 5, 0), (4, 1, 3),
(4, 4, 0), (5, 0, 3), (5, 3, 0), (6, 0, 2), (6, 2, 0), (7, 0, 1), (7, 1, 0), (8, 0, 0)}
The basic operation is to pour water from one jug A to another jug B in a way
that either A is emptied or B is filled. We are looking for the shortest sequence
of operations that reaches the state (4, 4, 0) starting with state (8, 0, 0). Such
a basic operation is called a transition from one state to another. You noticed?
The “problem of the 3-jugs” has been transformed into a “problem of states
and transitions between the states”. The final step is to position the states
somewhere in the plane and link two states with an arrow, if a transition from
the first to the second state is possible. The result is a (directed) graph, a graph
with directed links. The problem now is reduced to find the shortest (direct)
path5 in this graph from state (8, 0, 0) to the state (4, 4, 0). The resulting graph
and the shortest path in red is given in Figure 2.4.
I guess it is clear how to interpret the solution: In the first step, take the 8-liter
jug and fill the 5-liter jug, the second step is to take the 5-liter jug and to fill
the 3-liter jug, the thrid step is to empty the 3-liter jug and pour it to the 8-liter
jug, and so on, 7 steps are needed to get to the goal (4, 40).
Interestingly, we not only know now how to solve this particular 3-jug prob-
lem but all kind of jug problems with other capacities and with a different
number of jugs. This is a strong indication of a good model: if the model’s vo-
cabulary stimulates others undiscovered aspects of the problem or guides the
research to similar problems, then the model might be reasonably good. If,
however, the vocabulary is “sticky” or “artificial” then the model is probably
not very useful.
4
∨ is the Boolean “or” operator.
5
Finding the shortest path in a graph is a well-known problem in operations re-
search.
43 CHAPTER 2. HOW TO MODEL?
(4,1,3) (4,4,0)
(7,1,0) (1,4,3)
(7,0,1) (1,5,2)
(2,5,1) (6,0,2)
(2,3,3) (6,2,0)
(5,3,0) (3,2,3)
(0,5,3) (3,5,0)
(5,0,3) (8,0,0)
Two weighings are sufficient! That is astonishing. First, the coins are num-
bered from 1 to 8. Of course, the first idea would be to weight all coins: 4 on
one side of the balance and 4 on the other side. The fake coin is then at the
lighter side, this is repeated with the four on the lighter side, etc. This method
would lead to 3 weighings. But what if we only weight 6 coins initially? Coins
1,2,3 on one side of the balance and 4,5,6 on the other side? Because then we
know: if the left side is lighter, the fake coin is there, if the right side is lighter,
then it is on the right side, and if they are equal, then the face coin must be 7
or 8. Bingo! That is the key idea: to separate the coins into three groups. This
key idea is repeated in the second weighing. Suppose the left side with the
coins 1, 2, 3 is lighter, then we know the fake coin is there. Now we weight
only coin 1 against coin 2. If the left is lighter then the fake coin is 1, of the
right is lighter then the fake coin is 2, otherwise the fake coin is 3, which was
CHAPTER 2. HOW TO MODEL? 44
not weighted! The whole weighings process is best shown in a Figure 2.5.
modeling in general. Order, sort, collect, and name the components before do-
ing more creative things in modeling. Often, the elements “fall into the right
place” just by naming them systematically. In mathematical modeling the key
element is often to identify the right variables.
Let’s analyze the horse problem: Only 5 horses can race at the same time, so:
1. Group the 25 horses into 5 groups of 5 horses. The groups are named
a, b, c, d, e. Mark each horse with its group name. Hence, 5 horses are
marked with an “a”, 5 with a “b”, and so on.
2. Let each group race, that is, the five horses in group a do the first race,
then the five horses in group b, etc. This gives 5 races.
3. Mark each horse with its rang. Hence, the fastest horse in each group is
marked with the number 1, the second fastest with number 2, etc. Each
horse is now marked with its group name an its rank after the first five
races.
4. Let the 5 horses with number 1 do another race (race number 6).
5. Order the 5 groups according to the fastest horses in that last race. So,
CHAPTER 2. HOW TO MODEL? 46
for instance, suppose c1 is the fastest horse, second is b1, third is a1,
fourth is d1, and the slowest is e1 in this 6th race, then order the groups
from top to bottom accordingly as shown in Figure 2.7 (first row con-
tains all horses named c; second row all horses named b, etc.).
6. Clearly, the horse c1 is the fastest overall. Why? It is faster than any a
horse (from the first race), and it is faster than any other 1 horse, and
any 1 horse was faster than any 2 horse etc.
7. Who is second and third? In the group of the 1 horses only b1 and c1
can be second or third (but not d1 or e1). In group a only a1 could
be third (all others in group a were slower). In group c and b the two
fastest (beside c1) can be second or third. So let race the horses c2, c3,
b1, b2, and a1 a final time (race number 7). The two fastest horses in
that last race are second and third.
in the same way in each race, that is, the fastest in the first race is also the fastest
in the 6th race, for instance. In all real problems, this is an idealized assump-
tion. We know that this is not true. So, is the model then useless? Well, it
depends on the context. In our horse-race example we may define the horse to
be the fastest if it is the fastest in the 6th race, but it might have been slower
than any other 1 horse in the 5 first races (when measured by a watch). In any
case, it is important to be aware of all hidden assumptions of a model and in
what context it would be inappropriate to apply the model.
Now the problem can be reduced to the question: How many black squares
are there? We have 20×20 total squares in this example, half of them plus half
of 20 are black. Why? Look carefully, there are more black than white cells,
because the diagonal also contains only black cells. If we made half of the
diagonal (that is 10) white, then we would have exactly the same number of
white and black cells. Hence, the number of black cells is: 20 × 20/2 + 20/2 =
210.
The same reasoning holds if there is a 1000 × 1000 square: Half of 10002 plus
1000/2 are black, or in a 3 × 3 square, where 32 /2 + 3/2 are black – but wait
a minute: 3/2 is not an integer number. Well, 32 /2 is not integer either, but
together they are integer (draw it, to verify). In general, for an n × n large
square, the number of black squares – that is the sum from 1 to n) – therefore
is:
n2 n (n + 1)n
+ =
2 2 2
This approach shows two important concepts in modeling: (1) Transform the
problem into a very different (graphical) problem (piles of squares) that is
structurally identical, (2) try first to pile 3, then 4, etc. Can you see the pattern?
Can it be generalized?
A different approach is with arranging numbers. Try this in Figure 2.9. How
many 1001 do we have? The answer is: 1000. Since each number is counted
twice, we get: 1001 · 1000/2, which confirms the formula above.
CHAPTER 2. HOW TO MODEL? 48
A digression: Proof that the formula is true for all n > 0. Proof by induction:
(1) prove that it is true for n = 1. This is the case, since:
X
1
(n + 1)n 2·1
i= = =1
2 2
i=1
• With 2 persons, the probability that they do not have the same birthday
364
is 365 .
• With 3 persons the probability, that 2 persons do not have the same
birthday, is 364 363
365 · 365 .
• With 4 persons the probability, that 2 persons do not have the same
birthday, is 364 363 362
365 · 365 · 365 . Do you see the pattern now?
Within a group of n persons the probability, that 2 persons do not have the
same birthday, is therefore:
1 2 n − 1
P ′ (n) = 1 − · 1− · ... · 1 −
365 365 365
The initial problem that 2 persons out of n persons do have the same birthday
is then P(n) = 1 − P ′ (n). Figure 2.10 is a graph of this function P(n). The
graph shown that the probability that 2 persons in a group of 30 persons have
the same birthday is more than 70%. In a party with 23 persons the probability
is already larger than 50%.
The birthday paradox problem has a very useful application in computer sci-
ence for calculating the probability that 2 entries clashes in a hash table: Given
a hash table of size 365, what is the probability that 2 entries clashes on the
same memory location after n entries. This is a good example for the fact
that the same model can have very different interpretations (or applications) in
completely different domains.
Another aspect makes this problem interesting from a modeling point of view.
The calculation of the expression for P ′ (n) above is laborious. Isn’t there a
simpler model? Indeed we know that:
x2 x3
ex = 1 + x + + + ... ( and for x ≪ 1, ex ≈ 1 + x)
2! 3!
Let x = −1/365, then x = −2/365, ... then P ′ (n) can be expressed as:
2
= e−(1+2+...+(n−1))/365 = e(n −n)/730
x = 20 + x/2 , and x = 40
cost 110, hence x + y = 110. The difference is 10, that means: x − y = 10. Now
C(and not 10
its is easy to see that x = 105 and y = 5. The price of the ball is 5 =
C).
=
Resolving the equation gives x = 36. The assistant alone takes 36 minutes.
Suppose, as an extreme case, together they would take only 1 minute, then the
CHAPTER 2. HOW TO MODEL? 52
assistant alone would take 45/44 minutes (calculate!). This number is slightly
higher than 1, which makes sense, because they together always do it in less
time.
Well! One could argue that together they will chat a lot and wasting time or
stop for a bite. This may happen, but then we have another problem. We made
the silent assumption that their performance do not change when working
together or working alone.
How did we discover these figures? They are “special numbers” 3×8 is almost
5 × 5, and 8 × 21 is almost 13 × 13. Sounds familiar? 1, 1, 2, 3, 5, 8, 13, 21, 34,...
These are consecutive Fibonacci numbers. These numbers are defined by:
4. Connect the data with the unknown. It is clear from the statement that
c = a + 10 and d = b + 10
a = b/3
6. Finally: “In 10 years my father will only be two times as old as I will
be” gives:
d = 2c
x2 + x4 + x6 = x1 + x4 + x7
x3 + x4 + x5 = x1 + x4 + x7
x2 + x5 + x7 = x1 + x4 + x7
x1 + x3 + x6 = x1 + x4 + x7
xi ∈ {1, . . . , 7}, all distinct
The model was implemented in the modeling language LPL and can be exe-
cuted here: Puzzle7.
X X
!
i · xi = i /2
i i
exactly(2)i (xi ̸= xi mod 12+1 )
xi ∈ {0, 1}, forall i ∈ {1, . . . , 12}
The model was implemented in the modeling language LPL and can be exe-
cuted here: DrawClock.
2.4. Conclusion
This paper gives a short introduction to modeling with examples of how to
model. The examples show that modeling is not trivial. Although the prob-
lems presented here are quiet simple, so to say, find a good model formulation
is not always easy. How much more difficult must it be to formulate real-life
problems with a lot of data and constraints. Modeling an art, sure, but a art
CHAPTER 2. HOW TO MODEL? 56
that can be learnt: one must practise. Continue modeling, look up my books
with a lot of examples see My Modeling Books.
C HAPTER 3
T HE M ODELING L ANGUAGE
LPL
57
CHAPTER 3. THE MODELING LANGUAGE LPL 58
This paper gives a first impression of the LPL modeling language. The paper
is by no means complete or systematic. For learning LPL, I suggest to read
through the tutorial [69] and to consult the reference manual [72]. Surely,
after digesting this paper, the reader would be able to read and understand
with ease most LPL models and would be able to write some basic models. A
functionality overview of LPL can be downloaded at [65].
After an introduction to the basics, the paper exposes highlights several unique
features of LPL such as modularity, the drawing library, logical constraint,
and goal programming.
It would be an advantage, if the reader were familiar with the basics of some
programming language to follow smoothly all the small models in this text.
3.1. Introduction
There are virtually hundreds of software and computer tools to implement
various kinds of mathematical models. There exist special software for par-
ticular domains, or there are general tools for symbolic and algebraic ma-
nipulations or for numerical solutions. There are also extensions of modern
established programming languages to formulate and solve models. Finally,
various algebraic languages exist. Several options and tools are presented in
a separate paper (see [74]).
LPL is an advanced modeling language and seems to me an interesting tool
to start learning mathematical modeling. Its syntax is close to the common
mathematical notational and at least its basics are easy and quick to learn.
With LPL one can formulated small and large linear and non-linear models.
It is linked to various free and commercial solvers. And one of its unique
feature is to formulate discrete models using Boolean and logical operators. It
is also ideal in an educational environment. Aside from that, large linear and
integer models are also implemented and used by large companies such as
ABB (see extern/ABB-cpmPlus.pdf) and SwissPort (see extern/IFORS-News-
2019-12-01.pdf).
Furthermore, for testing and run your first models, there is no need to install
any software on your computer, just use your favorite browser to start mod-
eling. Later on, when you need serious error handling and interactivity in
model building, an academic version of the LPL software can be downloaded
for free and is installed in no time. It is shown later on in this paper.
Learning the basics of LPL is no wasted time. The knowledge is also useful to
switch to other, and for your application more appropriate software or tools.
So let’s start!
59 CHAPTER 3. THE MODELING LANGUAGE LPL
3. Two variable declaration with the name x and y begin with keyword
variable. If the same declaration repeats, the keyword can be dropped.
Copy this model and paste it here: empty (A browser opens). Then click
on the button Run and Solve. A moment later, the solution of this model is
displayed: x = 40, y = 30.
1
If the reader is not familiar with indexed notation, study the following paper [67].
CHAPTER 3. THE MODELING LANGUAGE LPL 60
X
max cj x j
X
j∈J
subject to ai,j xj ≤ bi forall i ∈ I
j∈J
xj ≥ 0 forall j ∈ J
with I = {1, . . . , m}, J = {1, . . . , n} m, n ≥ 0
One of the main strength of LPL is to use the index notation. Data can be
declared by parameters :
parameter m := 1000;
n := 2000;
In the parameter declaration, not only singleton data can be defined also vec-
tor data, or matrices, or higher dimensional data. The vectors bi with i ∈ I, cj
with j ∈ J, and the matrix ai,j are declared (without assignment) :
parameter b{i in I};
c{j in J};
a{i in I, j in J};
These parameters can be assigned in the same way. The assignment can take
place directly at the declaration or later on in a proper assignment as in :
a{i in I,j in J} := if(Rnd(0,1)<0.02 , Rnd(0,60));
c{j in J} := if(Rnd(0,1)<0.87 , Rnd(0,9));
b{i in I} := if(Rnd(0,1)<0.87 , Rnd(10,70000));
matrix else 0 is assigned. This operation is repeated for all elements in I com-
bined with all elements in J. The statement is similar to a double loop in a
programming language like C (suppose myrand() returns a double between
0 and 1) :
double a[][]; int i,j;
for (i=0; i<m; i++) {
for (j=0; j<n; j++) {
a[i,j] = myrand() < 0.02 ? 60*myrand() : 0;
}
}
runs through the sets in lexicographical order, that is, right-most index first,
left-most index last, and on each pass it assigns a random value to the matrix
entry.
In other words, the matrix a contains about 2% of data that are different from
zero. The large majority of its elements is zero. Of course, LPL only stored the
non-zeroes (in a sparse way).
A last remark about a simplified notation in LPL is notable: Although the pre-
vious notation as in a{i in I, j in J} is perfectly legal syntax in LPL, a
shorter notation is preferable. In LPL set names are normally in lowercase
letters and can be used as indexes too. There is generally no need to use a
separate symbol for sets. So the previous declarations could also simply be
written as:
set i := 1..m;
j := 1..n;
parameter a{i,j};
c{j};
b{i};
In the same way as parameters, also variables (x{i}) and constraints C{i}
can be indexed to specify a vector or a higher dimensional quantity of single
objects. The same Pindexing mechanism can also be applied to several index
operators, such as i . . . (in LPL sum{i} ...).
Now all elements are ready to formulate the general linear model with 1000
constraints and 2000 variables :
model largerModel;
parameter m := 1000; n := 2000;
set i := 1..m; j := 1..n;
parameter
a{i,j} := if(Rnd(0,1)<0.02 , Rnd(0,60));
c{j} := if(Rnd(0,1)<0.87 , Rnd(0,9));
CHAPTER 3. THE MODELING LANGUAGE LPL 62
Again, copy this model and paste it here: empty (A browser opens). Then
click on the button Run and Solve. A moment later, the solution of this model
is displayed:
About 90 variables out of the 2000 have a value different from zero. Three are
shown in the list above.
Note that the function Write was used to write a formatted output of the
solution. This function is a very powerful method to generate text output, so-
phisticated reports using the library of FastReport, as well as database tables
or even Excel sheets. See the reference manual for more information [72].
Data can also be directly added to the model. As an exercise, the simple
example above is written in an indexed notation:
model secondModel;
set i := [1 2];
j := [a b];
parameter b{i} := [350 300];
c{j} := [300 200];
a{i,j} := [5 5 , 6 2];
variable x{j};
constraint C{i}: sum{j} a[i,j]*x[j] <= b[i];
maximize Obj: sum{j} c[j]*x[j];
Writep(x);
end
(As before, copy this model, paste it here: empty and run it.) Inline data
tables are enclosed in [...] and are evaluated and assigned before any other
assignment. The elements are listed in lexicographical order. Note that set
elements in this case are strings.
63 CHAPTER 3. THE MODELING LANGUAGE LPL
while expr do
...statement list...
end
if expr then
...statement list...
else //optional part
...statement list...
end
The following program implements the greatest common divider of two num-
bers (the algorithm is quite inefficient – there are much better methods2 , but
it shows a loop and a branching statement):
model gcd;
integer a := 1943; b := 2813;
c := if(a<b, a, b);
d := 1;
for{i in 1..c} do
if a%i = 0 and b%i = 0 then d:=i; end
end
Write('The gcd of %d and %d is %d\n', a, b, d);
end
(Copy this model, paste it here: empty and run it.) Note first, that the assign-
ment operator is := (not = like in C, Python, Java etc.) and the Boolean equal
operator is = (not ==). % is the modulo operator. The keyword integer
start a parameter declaration that is integer. It is a shortcut for integer
parameter. if has two different uses: the first was already explained above
and is a function. The second starts a branching statement. Finally, {i in 1..c}
declares an anonymous set with a local index i. (Another implementation of
the Euclid algorithm is given in euclid.)
2
This method loops through ALL integers i from 1 to the smaller number (a or b)
and checks whether a and b is divisible by i, and if it is it retains the last found
number. A better way is the Euclid algorithm.
CHAPTER 3. THE MODELING LANGUAGE LPL 64
language – in its actual version3 . It lacks object oriented concept; its memory
is not stack-based, that is, although one can define user defined functions (see
below), the function cannot be called recursively; it is interpreted and a just-
in-time compiler is missing; so it is not very efficient for most algorithmic
tasks. Nevertheless, LPL does something very well: large models, eventually
with sparse data sets, can be efficient and compactly formulated and ran. It
links well to several commercial and free solver libraries.
3.3. Sub-models
Models can be organized into sub-models each with its own name space, and
they can be distributed into several file. Let’s give a small simple example that
shows also how the data can be separated from a model structure by using the
two linear models above (open subModels to run it, modify it by assigning 2
to the parameter selectData) :
model subModels;
parameter selectData:=1;
if selectData=1 then data1; else data2; end;
set i; j;
parameter a{i,j}; c{j}; b{i};
variable x{j};
constraint C{i}: sum{j} a[i,j]*x[j] <= b[i];
maximize Obj: sum{j} c[j]*x[j];
Write('Objective Value = %7.2f \n', Obj);
Write{j|x}(' x%-4s = %6.2f\n' , j,x);
model data1;
i := [1 2];
j := [a b];
b{i} := [350 300];
c{j} := [300 200];
a{i,j} := [5 5 , 6 2];
end;
model data2;
parameter m := 1000; n := 2000;;
i := 1..m; j := 1..n;
a{i,j} := if(Rnd(0,1)<0.02 , Rnd(0,60));
c{j} := if(Rnd(0,1)<0.87 , Rnd(0,9));
b{i} := if(Rnd(0,1)<0.87 , Rnd(10,70000));
end;
end
The code contains the main model subModels and two sub-models data1
3
My vision of a fully-fledged modeling language are exposed in another paper, see
[70].
65 CHAPTER 3. THE MODELING LANGUAGE LPL
and data2. The main model does not contain data, only the declarations.
One of the sub-model is called and ran from the main model, depending on
the value of the parameter selectData4 . Note the double semicolon in the
sub-model data2. m and n are two local parameters and after their declara-
tion follows a double semicolon. This is important in this context because it
terminates the declaration with an empty statement (a semicolon, because the
next i := ... is not local, it is an assignment to the global set i. The data
model could also be in another file. To simplify the presentation, the data – in
fact two data-sets – are included within the main model.
3.4. Drawings
Specially for the presentation of the results, figures and drawings are very
helpful to understand the solution of a model. Therefore, LPL contains a small
drawing library to generate an vector graph in SVG format. The following
model show the use of this library (open chess5b to run the model and to see
the graphic) :
model chess;
set i,j := [1..8];
integer variable x{i} [1..#i];
constraint
D: Alldiff({i} x[i]);
S: Alldiff({i} (x[i]+i));
T: Alldiff({i} (x[i]-i));
solve;
parameter X{i,j} := if(j=x[i],1);
Draw.Scale(50,50);
{i,j} Draw.Rect(i,j,1,1,if((i+j)%2,0,1),0);
{i,j|X} Draw.Circle(j+.5,i+.5,.3,5);
end
Two variables x and y with lower bounds 0 and upper bound 10 and 20 are
declared. The constraint contains arithmetic and Boolean operators defining a
concave set. Besides and and or, LPL also defines additions Boolean and log-
ical indexed operators, such as not, nand, implication, and indexed and, or
atleast. For more information, see the paper [68], and the reference manual
[72].
3.6. Conclusion
This paper gives a first impression on the modeling language LPL. It is use-
ful in a educational context to model all kinds of models: linear, non-linear,
permutation problems. It is a full-fetched programming language. It can be
used in a commercial context for formulating large linear integer problems
that can be solved by commercial solvers like Gurobi, Cplex, or Xpress. For
more learning the language see the tutorial and the reference manual as al-
ready mentioned.
C HAPTER 4
I NDEX N OTATION IN
M ATHEMATICS
67
CHAPTER 4. INDEX NOTATION IN MATHEMATICS 68
4.1. Introduction
To work with a mass of data, a concise formalism and notation is needed. In
mathematics, the so-called indexed notation is the appropriate notation. This
notation is an integral and fundamental part of every mathematical model-
ing activity – and they are also used in mathematical modeling languages as
in LPL [76] – to group various objects and entities. It is surprising how little
has been published in the community of modeling language design on this
concept. Even in mathematical textbooks, the indexed notation used in for-
mulae is often taken for granted and not much thought is given to it1 . This
fact contrasts with my experience that students often have difficulties with
the indexed notation in mathematics.
To represent single data, called scalars, names and expressions are used, such
as:
x, y or x−y
z=x−y
It seems to be a little bit less familiar that in the same way as using symbols for
scalars, symbols can represent mass of data. Suppose that we want to express
the profit of several profit centers in a company. Then we could write:
z1 = x1 − y1
z2 = x2 − y2
z3 = x3 − y3
... etc. ...
The “etc.” means that we have to continue writing as many lines as we have
profit centers, there may be dozens – a rather boring task!
There is, however, a much more economical way in mathematics to represent
all these expressions in one single statement. It is the indexed notation. To
formulate them, we first introduce a set: the set I of all profit centers:
here again the “. . .” means that we continue writing all centers in a list. Often
a short name form is used as follows:
I = {1 . . . n} where n ∈ IN+
In the previous set definition we just mean that there are n centers, n being a
positive number. We are not concerned right now of how many centers there
CHAPTER 4. INDEX NOTATION IN MATHEMATICS 70
xi , yi , zi where i∈I
Mathematically speaking, three vectors are declared to represent all data. The
list of expression then can be written in a single statement as follows:
zi = xi − yi with i∈I
This notation is in fact nothing else than an economical way of the following
n expressions:
z1 = x1 − y1
z2 = x2 − y2
...
zn = xn − yn
P all profits,
In a similar way, we can concisely build an expression that sums
for instance. For this purpose we use the mathematical operator , the Greek
sigma symbol. The total profit p of all profit centers can be formulated as
follows:
X
p= zi
i∈I
Again, this formmula is nothing else than a shortcut for the long expression:
p = z1 + z2 + · · · + zn
After this introductory example, this paper presents now a more precise way,
on how the indexed notation is defined and how it can be used in modeling.
71 CHAPTER 4. INDEX NOTATION IN MATHEMATICS
a1 + a2 + · · · + an−1 + an (4.1)
X
n
ai (4.2)
i=1
The expression (1) is called three-dots notation and expression (2) is called
sigma-notation. Both expression are equivalent, but (2) is much shorter and
more general. The later was introduced by Joseph Fourier in 1820, according
to [23, p. 22]. There exist different variants of expression (2) :
X X
n X X
ai , ai , ai , ai with I = {1 . . . n} (4.3)
1≤i≤n i=1 i∈{1...n} i∈I
All four expressions in (3) are equivalent and they have all their advantages
and disadvantages. The last notation in (3) is more general, because the index
set I can be an arbitrary set defined outside the summation expression.
X
4
xi = x2 + x3 + x4
i=2
CHAPTER 4. INDEX NOTATION IN MATHEMATICS 72
and
X
5
xi = x2 + x3 + x4 + x5
i=2
Pn
Hence, the notation i=1 tells us:
X
5
xi = x1 + x2 + x3 + x4 + x5 = 10 + 8 + 2 + 15 + 22 = 57
i=1
The name i is a dummy variable, any other name could be used. We could
have used j, the expression would have be exactly the same, hence:
X
5 X
5
xi = xj
i=1 j=1
P4
Now let us find i=1 3xi based on the previous values. Again we start with
i = 1 and we replace 3xi with its value:
X
4
3xi = 3x1 + 3x2 + 3x3 + 3x4 = 3 · 10 + 3 · 8 + 3 · 2 + 3 · 15 = 105
i=1
P5
Similarly, let use find i=2 (xi − 8): This is:
X
5
(xi − 8) = (x2 − 8) + (x3 − 8) + (x4 − 8) + (x5 − 8)
i=2
= (8 − 8) + (2 − 8) + (15 − 8) + (22 − 8) = 15
73 CHAPTER 4. INDEX NOTATION IN MATHEMATICS
P5
One should be careful with the parentheses. The expression i=2 (xi − 8) is
P5
not the same as i=2 xi − 8. The later evaluates to (the 8 is not included in
the sum):
X
5
xi − 8 = x2 + x3 + x4 + x5 − 8 = 39
i=2
X
4
j2 = 12 + 22 + 32 + 42 = 30
j=1
X
n X
n
cxi = c xi
i=1 i=1
X
n
c = nc
i=1
X
n X
n X
n
(xi + yi ) = xi + yi
i=1 i=1 i=1
Proof:
X
n
cxi = cx1 + cx2 + . . . + cxn−1 + cxn
i=1
X
n
= c · (x1 + x2 + . . . + xn−1 + xn ) = c · xi
i=1
X
n
c = |c + c +{z. . . + c} = n × c = nc
i=1 n−times
X
n
(xi + yi ) = (x1 + y1 ) + . . . + (xn + yn )
i=1
X
n X
n
= (x1 + . . . + xn ) + (y1 + . . . + yn ) = xi + yi
i=1 i=1
End of proof
75 CHAPTER 4. INDEX NOTATION IN MATHEMATICS
K
Ei (4.4)
i∈I
(1) The index operator: It is clear why the index operator must be commuta-
tive and associative: A mathematical set is unordered
P and its elements can be
“traversed” in any order. As an example, the does not specify in which
order the indexed expressions Ei are added up. Various operators fulfill
P these
requirements. Besides the addition, represented by the operator , the fol-
lowing index operators are commonly used (examples will be given later on):
Q
• The product (multiplication) : The indexed expressions are multi-
plied.
• The Max (Min) operator, written as maxi∈I (mini∈I ): They return the
largest (smallest) indexed expression in the list.
V
• In
W Boolean logical expressions we use the AND- and OR-operators ( ,
): They check whether all indexed expressions are true or at least one
is true.
.
V
• An particular index operator is the list operator . It is used to list in-
dexed expressions (see later on).
(2) The index set: In the simplest case, the elements of the index set are inte-
gers, as in :
However, they can also be identifiers (symbolic names), strings or any other
items and even sets representing elements of a set. In the following index set
I with the four elements are identifiers :
Another example is the (infinite) list of all positive integer grid points in a
Euclidean space, written as :
I = {(x, y) | x, y ∈ IN+ }
= {(0, 0), (1, 0), (1, 1), (0, 1), (0, 2), (1, 2), (2, 2), (2, 1), . . .}
S = {Qi | i ∈ I , Qi ⊆ J}
Q1 = {1, 2, 3}
Q2 = {2, 3}
S = {{1, 2, 3}, {2, 3}, {}, {2}} , hence
Q3 = {}
Q4 = {2}
S = {(i, j)|(i, j) ∈ {(1, 1), (1, 2), (1, 3), (2, 2), (2, 3), (4, 2)}} forall i ∈ I, j ∈ J
(3) The active index: The active index is a (dummy) name (or an identifier)
representing an arbitrary element in the index set. The passive index is also an
identifier used in the indexed expression which must have the same spelling
as the active index. The term i ∈ I, consisting of the active index and the index
set, is called an indexing term. The active index and the passive index are used
as place-holders to define a bijective mapping between the index set and a
set of indexed expressions. Each element i in the index set maps to an indexed
expression by replacing the passive index with the corresponding element i
in the index set. This mapping is called the index mechanism. In fact, it defines
f
the (bijective) function f : i −→ Ei with i ∈ I. This mapping supposes that
CHAPTER 4. INDEX NOTATION IN MATHEMATICS 78
X
3 with I = {1, . . . , n}
i∈I
the indexed expression is just 3. The whole expression then reduces simply
to:
|3 + 3 +{z. . . + 3} = 3 · n
n−times
X
i with I = {1, . . . , n}
i∈I
in which case the indexed expression is just i. The whole expression reduces
to:
1 + 2 + ... + n
The indexed expression can itself contain index operators. For example:
X X
Fi,j forall I = {1, . . . , n}, J = {1, . . . , m}
i∈I j∈J
X
(Fi,1 + Fi,2 + · · · + Fi,m ) forall I = {1, . . . , n}
i∈I
Definition: An indexed notation is a formula expressing the fact that the index
operator is applied to the set of indexed expressions constructed by the
index mechanism., that is, a bijective mapping between the elements of the
index set and the indexed expressions.
4.2.3 Extensions
This is really the most general notation, no further concepts are needed to
write more complex index notations. This will be shown now by studying
several “extensions”, which all can be reduced to this simple form.
zi = xi − yi forall i ∈ I
.
^
(zi = xi − yi )
i∈I
V.
The index operator is the -operator. The meaning of this operator is to list
all indexed expressions. In this case, the indexed expression is normally an
equation or an assignment, hence the “side effect” of this operator is to assign
a list of values. Of course, in a mathematical text the first notation is preferred,
because it is so common. However, this example shows that it can really be
seen as an indexed notation. This fact will be important in the context of
modeling languages later on, because we can use the same syntax to specify a
list of expressions. To express it, we only need to use the list operator instead
of any other index operator, as for instance the sigma operator.
CHAPTER 4. INDEX NOTATION IN MATHEMATICS 80
In many situations, the index set is not simply an explicit list of elements, as
in I = {1, . . . , n}. Of course, any set expression can be used to construct the
index set I. Hence, I could be the union or the intersection of other sets as in
the following expression:
I=J∪K or I=J∩K
This kind of modification does not change anything for the indexed notation.
It is immaterial, how the index set is constructed. Sometimes, however, we
construct I as a subset of another set, say J, such that I ⊆ J, and we use the
notation:
I = {j ∈ J | P(j)}
where P(j) is a property about j ∈ J that is either true or false. The notation
means: “for all j ∈ J such that P(j) is true”. Clearly, if P(j) is true for all
elements in J then the two sets are equal (I = J). However, normally P(j)
expresses a property that is true only for a proper subset of J. Using I in an
indexed notation, we could write:
X
Ei with I = {j ∈ J | P(j)}
i∈I
However, it is more common and much shorter to use the notation which is
as follows:
X
Ej
j∈J|P(j)
Hence, we attach the property P(j) directly to the indexing term starting it
with the symbol |. This is extremely useful and very common in modeling.
Suppose we have a list of products. Then it is very common to sum over
different subsets of products, for instance “all products for which the demand
is larger than x” or “all products that are green” or whatever. It would be
exaggerated to generate an explicit named index set each time.
X
xi = x2 + x3 = 8 + 2 = 10
i∈I|P(i)
X
xi = x4 + x5 = 15 + 22 = 37
i∈I|Q(i)
In the first expression P(i) is true only for x2 and x3 , hence the sum take place
only over these two terms. In the second expression, Q(i) is true only for i = 4
and i = 5.
There is no need to explicitly name the properties; their corresponding expres-
sions could be directly used in the indexing terms. Hence the two previous
expressions could also be written as:
X
xi = x2 + x3 = 8 + 2 = 10
i∈I|xi ≤9
X
xi = x4 + x5 = 15 + 22 = 37
i∈I|i≥4
We can write any Boolean expression after | . . . in the indexing term. This
expression is called indexing condition.
X
k= 1 + 2 + . . . + 10 = 55
k∈K|k2 ≤100
X
k2 = 32 + 42 + 52 = 50
k∈K|3≤k≤5
X
k= 2 + 3 + 5 + 7 + 11 + 17 + ... + 97 = 1060
k∈K|k is prime
In the first expression k2 ≤ 100 is only true for 1 ≤ k ≤ 10. In the second
expression, only 3, 4, 5 are allow for k. In the third, we say to take every k up
to 100, such that k is prime (of course, there is no known expression for all
primes).
We saw, to extend the indexing term from “i ∈ I” to “i ∈ I | P(i)” does not
change the meaning of the indexed notation. The expression i ∈ I | P(i) is
still a set albeit a subset of I that has no explicit name. However, no further
concept has been added to the indexed notation.
CHAPTER 4. INDEX NOTATION IN MATHEMATICS 82
K O
Fi,j (4.5)
i∈I j∈J
J N
where and are two arbitrary index operators. If the two operators are
different then we need to evaluate the inner expression first and the outer
afterwards. A notable example is a system of m linear equations with n vari-
ables that is commonly noted as follows:
X
ai,j xj = bi with i ∈ {1 . . . m}
j∈{1...n}
V.
Using the list operator , these formula can be noted as a nested indexed nota-
tion, that is, a notation where the index expression contains itself an indexed
V. P
notation, with the outer index operator and the inner index operator as .
The nested notation then is noted as follows:
.
^ X
ai,j xj = bi
i∈{1...m}
j∈{1...n}
On the other hand, if both index operators in (5) are identical, then the two
index operators can be merged in the following way:
K K K
Fi,j = Fi,j
i∈I j∈J i∈I, j∈J
83 CHAPTER 4. INDEX NOTATION IN MATHEMATICS
It means that we merge the operator and unify also the indexing terms to be
written as “i ∈ I, j ∈ J”. It signifies that we build every tuple of the Cartesian
Product of the two sets: (i, j) ∈ I × J. As an example, suppose I = {1, 2} and
J = {a, b, c} then the index set is I×J = {(1, a), (1, b), (1, c), ((2, a), (2, b), (2, c)}
– it consists of 6 tuples. There are two active indexes i and j, or a tuple (i, j)
of active indexes. Hence we also may write this expression in the following
way:
K
Fi,j
(i,j)∈I×J
where the index set is I×J and the active index is replaced by the notation (i, j)
which is called an active index tuple. In this case, the names within the active
index tuples are called active indices. The active indices are now place-holders
for the single components of the tuple.
The index set I × J is also a set, the set of all tuples in the Cartesian Product.
Hence if we do not need to access the single components within the product,
we can replace (i, j) by a single active index, say k, and I × J can be replaced
by a set name, say K. Now we see that the previous formula really reduces to
our general indexed notation, which is as follows:
K K
Fi,j = Ek
(i,j)∈I×J k∈K
Since indexed notation with multiple indexing terms really is reducible to in-
dexed notation with one indexing term, we only need to extend the definition
of index sets:
Sometimes access to the tuple itself and to its components is needed. In such
cases, one could use a combined syntax as in:
K
(Ek , Fi,j ) (4.6)
k=(i,j)∈I×J
J = {(i, j)|Pi,j , i, j ∈ I}
Suppose now, that fi,j is the number of vehicles that are driving from i to j
in a hour. Then we can calculate the number of vehicles (xi ) arriving at each
location i per hour, it is:
X
xi = fi,j forall j ∈ I
j∈I|Pi,j
How can this be expressed with the tuple list J without using Pi,j ? One variant
is: X
xi = fi,j forall i ∈ (i, j) ∈ J
j∈(i,j)∈J
This notation is a little bit clumsy. In this context, (i, j) ∈ J is often abbreviated
as J[i, j] and the expression becomes:
X
xi = fi,j forall i ∈ J[i, j]
j∈J[i,j]
each other; however, all names in the other sub-tuples must occur in the last
tuple, because they only define a selection from the last tuple. (Of course, the
same selection may turn up more than once, defining several active indices
for the same sub-tuple.)
The previous considerations can now be generalized to a list of p indexing
terms as follows (where K ⊆ I1 × · · · × Ip ):
K K K K
Ei1 ,...,ip , Ei1 ,...,ip , Ek , Ek
i1 ∈I1 ,...,ip ∈Ip (i1 ,...,ip )∈I1 ×···×Ip k∈I1 ×···×Ip k∈K
All tuples in the indexing terms have arity p. All four indexing expressions
represent a p-dimensional table of expressions. Simple index sets (which con-
tain only atoms) can be interpreted as compound index sets with arity 1. In
this case, the parentheses around the ”tuple“ are not needed.
The use of indexed notation together with compound index sets, that is, sets
which are subsets of some Cartesian Product, might be considered as a purely
theoretical exercise. However, this is not the case. This notation is extremely
useful in practice, and it is worth while to understand the mechanism and the
notation very well. Therefore, let us give an example.
4.2.4 Exercise 1:
Suppose we have a set of 3 products P = {1, 2, 3} and a set of 4 factory loca-
tions F = {1, 2, 3, 4}, where these products are manufactured. The products are
transported from one factory to another at unit cost ci,j with i, j ∈ F. Further-
more, each product has a price vp with p ∈ P. Suppose also, that we transport
xp,i,j unities of product p from factory i to factory j with i, j ∈ F and p ∈ P.
The data are as follows (Since x is 3-dimensional,we use the notation xp=1 to
“slice” (or extract) the matrix xi,j where p = 1):
− 1 5 2 − 48 37 45
2 − 4 2 36 − 43 46
v= 6 2 3 c=
1 2
xp=1 =
− 3 44 36 − 33
1 3 1 − 36 39 34 −
− 46 35 39 − 32 32 40
32 − 47 35 30 − 41 30
xp=2 =
45 49 − 39
xp=3 =
45 43 − 45
47 46 30 − 44 41 34 −
CHAPTER 4. INDEX NOTATION IN MATHEMATICS 86
Using these data, we now can calculate various data using indexed notation
(please verify as an exercise):
(1) The total transportation costs T is calculated as follows:
X
T= ci,j · xp,i,j = 3180
p∈P, i,j∈F
(4) The value Wi,j transported between all factories (i, j) ∈ F × F is:
− 476 388 468
^. X 370 − 475 436
Wi,j = vp · xp,i,j =
489 443 − 411
i,j∈F
p∈P
442 449 366 −
(6) For each product p ∈ P the sum of the maximum quantity Si transported
from a factory i ∈ F is:
130
.
^ X 125
Si = max xp,i,j =
i∈F p∈P 133
j∈F
123
K K K
Ei,j or Ei,j (4.7)
i∈I j∈Ji i∈I, j∈Ji
K
Ei,j with K ⊆ I × (J1 ∪ · · · ∪ J|I| ) (4.8)
(i,j)∈K
This means that the concept of indexed index set can be reduced to compound
index set and does not add any new features. Nevertheless, a notation like (7)
may sometimes be more convenient, because the tuples are presented as a
hierarchical structure instead of a flat list.
4.2.4.2 Ordering
We saw that in various context an index set has a natural order. If the set
is a sequence of time periods or time points, for instance, then we order the
elements within this set according to its natural sequence and we expect that
the index mechanism is applied in this order. We take an example: Suppose P
is a set of time periods or time points. Furthermore, xp is the production level
in period p ∈ P, dp is the demand in period p, and sp is the stock level at the
end of period p. Then we can build a balance equation at each period:
Formally this can be written as follows (strictly speaking p has two different
meaning here: once for a duration (xp , dp ) and once for a time point (sp ), be
careful to model this correctly):
In this example we make a reference to sp−1 , that is, to the time period before
p. This would have no meaning, if the set P were not ordered. However, if
we make reference to a different element then we must be careful to check
CHAPTER 4. INDEX NOTATION IN MATHEMATICS 88
This declaration defines the three sets I = {1 . . . 10}, J = {1 . . . 100} and a set
K = {1 . . . n}. Note that the identifiers can be declared in any order in LPL. n
can or cannot have a value (it must be assigned later on).
This set declarations can be used in expressions. The following expressions:
X X X
A= 1 , B= j , C= x2
i∈I j∈J x∈J|10≤x≤20
P
The index operator is the keyword sum. The indexing term i ∈ I is ap-
pended to the index operator and bracketed with { and }. We also need
to declare new parameters A, B, and C that hold the calculated value. The
indexing condition is a proper Boolean expression in the language. Hence,
10 ≤ x ≤ 20 can be formulated as 10<=x<=20. Note that we use := as an
assignment operator.
89 CHAPTER 4. INDEX NOTATION IN MATHEMATICS
X X X
D= vi , E = max ai,j , Fk∈K = bi,j,k
i∈I
i∈I j∈J i∈I, j∈J
The passive indexes in the indexed expression are enclosed in the brackets [
and ]. So there is a clear syntactical distinction between the passive and the
active indexes in the language.
In LPL there exist a slightly shorter syntax that could also be used for an
indexing term. The examples above could be coded as follows:
set i := 1..10;
set j := 1..100;
parameter n;
set k := 1..n;
parameter A := sum{i} 1;
parameter B := sum{j} j;
parameter C := sum{j|10<=j<=20} j^2;
parameter v{i};
parameter a{i,j};
parameter b{i,j,k};
In this code, the active index has the same name as the corresponding index set.
Hence, {i in I}, an indexing term, can just be written as {i}. This makes
the expressions more readable and – in most context – much shorter. How-
ever, this can lead to difficulties as soon as the same index set is used more
than once in an indexed expression as in the following simple expression:
CHAPTER 4. INDEX NOTATION IN MATHEMATICS 90
X
H= ci,j
i,j∈I
In such a case, LPL allows one to define one or two alias names for the same
index set. We then could code this as following:
set i, j := 1..10;
parameter c{i,j};
parameter H := sum{i,j} c[i,j];
Of course, one always can use the more “traditional” notation as follows:
set I := 1..10;
parameter c{i in I, j in J}
parameter H := sum{i in I,j in I} c[i,j];
The alias names – separated by commas – are just other names for the index
set and can be used as unique active indexes name in indexed notations. LPL
allows at most two aliases for each index sets. If we use more than two, then
we always need to use the longer syntax as in the following example:
X
L= di,j,k,p
i,j,k,p∈I
The two versions of the LPL code can be downloaded or executed directly at:
exercise0a and exercise0b
Let us now code the Exercise 1 given in section 4.2.4 as an LPL model. First
we implement the declarations: The set of products and factories which are
P = {1, 2, 3} and F = {1, 2, 3, 4} the cost table ci,j , the value table vp and the
quantity table xp,i,j with i, j ∈ F and p ∈ P. In LPL these data tables can be
implemented as follows:
set p := 1..3;
set i, j := 1..4;
parameter c{i,j|i<>j} := [. 1 5 2 , 2 . 4 2 , 1 2 . 3 ,
1 3 1 .];
parameter v{p} := [6 2 3];
parameter x{p,i,j|i<>j} := [
. 48 37 45 36 . 43 46 44 36 . 33 36 39 34 . ,
. 46 35 39 32 . 47 35 45 49 . 39 47 46 30 . ,
. 32 32 40 30 . 41 30 45 43 . 45 44 41 34 . ];
91 CHAPTER 4. INDEX NOTATION IN MATHEMATICS
In table c and x we use the indexing condition i<>j because there is no cost
or quantity defined form a factory to itself. The data itself are listed in a lexico-
graphical order. The expressions given in section 4.2.4 are then formulated as
follows in LPL:
parameter T := sum{p,i,j} c[i,j]*x[p,i,j];
parameter V := sum{p,i,j} v[p]*x[p,i,j];
parameter C{p} := sum{i,j} c[i,j]*x[p,i,j];
parameter W{i,j}:= sum{p} v[p]*x[p,i,j];
parameter M{i} := max{p,j} x[p,i,j];
parameter S{i} := max{p} (sum{j} x[p,i,j]);
Exercise 1 (continued):
Let us now add a requirement that the transportation can only take place
between a small subset of all (i, j) links between the factories i, j ∈ F. Hence,
we need to introduce a property K(i, j) which is true if the transportation can
take place between factory i and factory j. We define it as:
Ki,j∈F = (1, 2) (1, 4) (2, 3) (3, 2) (4, 3)
The tuple list means that the transportation can only occur from factory 1 to
2, from 1 to 4, from 2 to 3, from 3 to 2 and from 4 to 3. Only 5 transportation
links are allowed. The corresponding expressions are then as follows:
(1) The total transportation costs T is calculated as follows:
X
T= ci,j · xp,i,j = 1524
p∈P, i,j∈F|K(i,j)
(4) The value Wi,j transported between all factories (i, j) ∈ F × F is:
− 476 388 −
X − − 475 −
Wi,j∈F|K(i,j) = vp · xp,i,j =
− 443 − −
p∈P
− − 366 −
CHAPTER 4. INDEX NOTATION IN MATHEMATICS 92
(6) For each product p ∈ P the sum of the maximum quantity Si transported
from a factory i ∈ F is:
85
X 47
Si∈F = max xp,i,j =
49
p∈P
j∈F|K(i,j)
34
The property K(i, j) is simply declared as a set. In fact, in LPL k{i,j} defines
a tuple list which is a subset of the Cartesian Product of (i, j) ∈ I × I. In LPL,
we can code the expressions as follows:
parameter T := sum{p,i,j|k[i,j]} c[i,j]*x[p,i,j];
parameter V := sum{p,i,j|k[i,j]} v[p]*x[p,i,j];
parameter C{p} := sum{i,j|k[i,j]} c[i,j]*x[p,i,j];
parameter W{i,j|k[i,j]} := sum{p} v[p]*x[p,i,j];
parameter M{i} := max{p,j|k[i,j]} x[p,i,j];
parameter S{i} := max{p} (sum{j|k[i,j]} x[p,i,j]);
Since in LPL k{i,j} is itself a set, it can be used as an index set. Hence, the
previous code could be written also as:
parameter T := sum{p,k[i,j]} c[i,j]*x[p,i,j];
parameter V := sum{p,k[i,j]} v[p]*x[p,i,j];
parameter C{p} := sum{k[i,j]} c[i,j]*x[p,i,j];
parameter W{k[i,j]} := sum{p} v[p]*x[p,i,j];
parameter M{i} := max{p,j|k[i,j]} x[p,i,j];
parameter S{i} := max{p} (sum{j|k[i,j]} x[p,i,j]);
TP = TS − RC − MC = 52882
CHAPTER 4. INDEX NOTATION IN MATHEMATICS 94
(5) The total quantity TQp produced for each product p is:
X
TQp = Qf,p,m = 188 228 175 135 89 261 391
f∈F, m∈M|qp,m
(6a) How long (in hours) does the production take on each machine m ∈ M
and in each factory f ∈ F?
515 312 542 290 330
X 548 224 554 324 273
Tif∈F,m∈M = Hp,m · Qf,p,m =
416
392 309 154 246
p∈P|q(p,m)
472 216 695 154 452
(6b) How long (in hours) does the production take maximally until the last
product leaves a factory f ∈ F?
X
TIf∈F = max Hp,m · Qf,p,m = 542 554 416 695
m∈M
p∈P|q(p,m)
X X X
!
Lop∈P = Sp · Qf,p,m − Rr,p · Rcr + Hp,m · Mcm · Qf,p,m
f,m f,m r
= 55792 33450 −6320 −19305 10769 −3046 −18458
X X X
!
LOp∈P = Sp · Qf,p,m − Rr,p · Rcr + Hp,m · Mcm · Qf,p,m < 0
f,m f,m r
= C D F G
(8) Which machines in which factories work more than 500 hours (set MOf∈F, m∈M )?
X
MOf,m = Hp,m · Qf,p,m > 500
p
= (F1, M1) (F1, M3) (F2, M1) (F2, M3) (F4, M3)
95 CHAPTER 4. INDEX NOTATION IN MATHEMATICS
(9) Which machine and in which factory works more than any other machine
(set MAf∈F, m∈M )? 2
MAf,m =
X X
! !
f = argmax Hp,m · Qf,p,m ∧ m = argmax Hp,m · Qf,p,m
f p m p
= (F4, M3)
(10) Which machine and in which factory has the least work to do (in hours)
(set MIf∈F, m∈M )?
MIf,m =
X X
! !
f = argmin Hp,m · Qf,p,m ∧ m = argmin Hp,m · Qf,p,m
f p m p
= (F3, M4)
Based on these given data, we can then calculate the various expressions as
follows3 :
parameter
TS := sum{f,q[p,m]} Q*S;
RC := sum{f,p,m,r} R*Rc * Q;
MC := sum{f,p,m} H*Mc * Q;
TP := TS - RC - MC;
2
The operators argmax and argmin are two other index operators returning the ele-
ment for which the indexed expression has the largest and the smallest value.
3
In LPL, it is quite common to leave out the passive indexes: this is very practical and
shortens the expressions. However, this practice should only be used by advanced
users.
CHAPTER 4. INDEX NOTATION IN MATHEMATICS 96
− − 1 − 1 − − 8 − 8 491
1 − 1 − − 4 − 7 − − 391
1 − − 1 − 7 − − 2 − 156
4
−
q = − − − 1 − − − − 3
H= 120
S=
1 − − − − 5 − − − − 221
− 1 1 − − − 8 2 − − 257
1 − 1 1 − 3 − 2 2 − 184
4
“1” in the matrix means that the combination is possible. For example qB,M1 = 1
means that product B can be manufactured on machine M1.
97 CHAPTER 4. INDEX NOTATION IN MATHEMATICS
− − − − − − 1 5
− − − − − − − 6
− 8 7 6 − − − 7
− 6 − − 5 − − 3
7 8 − − − − 5 7
− 4 − 6 − − − 7
7 − − 3 4 − 4 3
5 − − 8 − 7 − 5
−
2
− − − − 8 2
8
3
− − 3 − − − − 4
R= Rc = 5
Mc =
− − − − − − 4 4
2
5 − 6 4 − 7 6 8
−
4
2 5 − − − 8
4
− − 4 − − − 5 2
− − 5 3 − − − 3
− 1 − − − − − 8
− 5 − 1 − 6 6 5
− − 5 4 8 6 − 6
− 4 − − 3 − − 5
4 − − 8 − 5 3 6
− − 15 − 27 − − 15 − 18
21 − 40 − − 11 − 48 − −
19 − − 16 − 41 − − 18 −
Qf=F1 − − − − 38
= Qf=F2 − − − − 43
=
38 − − − − 17 − − − −
− 39 40 − − − 28 32 − −
36 − 31 43 − 44 − 17 48 −
− − 10 − 24 − − 36 − 43
16 − 15 − − 34 − 43 − −
24 − − 20 − 23 − − 14 −
Qf=F3 − − − − 18
= Qf=F4 − − − − 36
=
11 − − − − 23 − − − −
− 49 31 − − − 27 15 − −
43 − 31 19 − 20 − 38 21 −
CHAPTER 4. INDEX NOTATION IN MATHEMATICS 98
Especially, the last table Q is a given table that specifies the production plan.
It is a given arbitrary plan without asking the question whether this plan is
optimal in any sense. Let us now ask the question whether this plan could be
changed without changing the manufactured quantity of each product, just
by switching the production quantity from one machine to another.
X
MC = Hp,m · Mcr · Qf,p,m = 23802
f∈F, p∈P, m∈M|q(p,m)
99 CHAPTER 4. INDEX NOTATION IN MATHEMATICS
instead of 24882, which is a cost reduction of 1080 units. We could use proba-
bly other reassignment of the production plan in order to reduce the cost even
further. However, we would like to do this not on an experimental level, but
on a systematic way. Hence, the question is: How should the production plan
be, in order to minimize the total machine costs? (Note that the raw material
costs do not change, supposing that the quantities of products manufactured
do not change.) Expressed in another way: how should the production plan,
that is the matrix Qf,p,m , be assigned in order to make the machine costs as
small as possible.
At this point, thing become interesting: From the mathematical point of view,
we now have a model in which some data are unknown, that is the matrix
Qf,p,m becomes an unknown, because we want to know how this matrix has
to be filled to attain our goal (the minimizing of costs). Our model is as fol-
lows:
X
min Hp,m · Mcr · QQf,p,m
f∈F, p∈P, m∈M|q(p,m)
subject to
X
QQf,p,m = TQp , forall p ∈ P
f∈F, m∈M|qp,m
− − − − 188
228 − − − −
− − − 175 −
QQf=F1 −
= − − − 135
QQf=F2 = QQf=F3 = QQf=F4 = 0
89 − − − −
− − 261 − −
391 − − − −
This is a substantial machine cost reduction of more than 35% compared to the
initial (somewhat arbitrary) production plan of Exercise 2 (from 24882 units
to 16006 units).
However, there is no need to use the mathematical models approach to find
this trivial result! We could have found it by a simple thought: “One should
assign as much work as possible to the cheapest machine!” For example, ma-
chine M4 only costs 4 to manufacture one unit of product C, while machine
M1 costs 14, the only alternative to produce C. Furthermore it is not impor-
tant in which factory the product is manufactured, since they are all identical.
Hence, the total quantity 175 of product C should be manufactured by the
means of machine M4. The idea is similar for the other products.
To find the cheapest unit cost for each product and the machine that generates
this, we can use two indexed expressions as follows:
(2) What is the machine m that manufactures the cheapest product p (Table
CWp,m ) ?
2530 0 522 350 1909
X 0 0 0 0 0
Tif∈F,m∈M = Hp,m · QQf,p,m =
0
0 0 0 0
p∈P|q(p,m)
0 0 0 0 0
....
integer variable QQ{f,q};
constraint CA{p}: sum{f,m} QQ = sum{f,m} Q;
CB{m,f}: sum{p} H*QQ <= 500;
minimize obj1: sum{f,p,m} H*Mc * QQ;
....
− − − − 62 − − − − 62
124 − − − − 89 − − − −
− − − − − − − − 175 −
QQf=F1 −
= − − − − QQf=F2 − − −
= − 1
− − − − − − − − − −
− − − − − − − 250 − −
1 − − − − 48 − − − −
− − − − 12 − − − − 52
1 − − − − 14 − − − −
− − − − − − − − − −
QQf=F3 −
= − − − 134
QQf=F4 − − −
= − −
1 − − − − 88 − − − −
− − 11 − − − − − − −
163 − − − − − − 179 − −
The following table give the occupation of each machine with this production
plan:
499 0 0 0 496
X 500 0 500 350 499
Tif∈F,m∈M = Hp,m · QQf,p,m =
498
0 22 0 498
p∈P|q(p,m)
496 0 358 0 416
We see that no machine exceeds the occupation time of 500 hours. All prod-
ucts will be manufactured within 10 weeks.
Still some machine are not at their capacity limit and some are still idle. Could
we reduce the overall production time and to what extend? The most sim-
ple way to do this is to experiment with the maximal occupation time. Very
quickly we find that we can reduce that time up to 330 hours, which means
that the production can be terminated within less than 7 weeks. The corre-
sponding production plan now is as follows:
− − 33 − 41 − − 41 − −
3 − − − − 80 − − − −
− − − − − − − − 9 −
QQf=F1 − − −
= − − QQf=F2 − − −
= − 110
63 − − − − 2 − − − −
− 41 − − − − 38 − − −
1 − 32 55 − − − 1 50 −
103 CHAPTER 4. INDEX NOTATION IN MATHEMATICS
− − − − 38 − − − − 34
80 − 10 − − 54 − − − −
− − − − − − − 165 − −
QQf=F3 − − − − 6
= QQf=F4 − − −
= − 18
2 − − − − 22 − − − −
− 41 99 − − − 41 − − −
− − 30 55 − − − 165 − −
The following table give the occupation of each machine with this production
plan:
330 328 330 330 328
X 330 304 330 326 330
Tif∈F,m∈M = Hp,m · QQf,p,m =
330
328 330 330 330
p∈P|q(p,m)
330 328 330 330 329
As we can see, all machine work almost at 100% of 330 hours. However, the
total machine costs are now 21004, 4998 units over the minimal costs of 16006,
found in the previous model. This is the price we have to pay for a more
balanced machine occupation.
QQf,p,m ≤ U · yf,p,m
forall f ∈ F, p ∈ P, m ∈ M with (p, m) ∈ qp,m
To see that these two constraints express the same condition, we only need to
check that y is one if QQ is strictly positive. However, this is always the case,
hence the two expressions express the same constraint.
We now have to add all setup costs to the objective function. This function
now changed to:
X
min (Hp,m · Mcr · QQf,p,m + Setupp · yf,p,m )
f∈F, p∈P, m∈M|q(p,m)
The formulation of this model in LPL is as following (The value of U has been
fixed to 400 and the total machine occupation has slightly been increased to
337):
....
integer variable QQ{f,q};
binary variable y{f,q};
constraint CA{p}: sum{f,m} QQ = sum{f,m} Q;
CB{m,f}: sum{p} H*QQ <= 337;
CC{f,q}: QQ <= 400*y;
minimize obj1: sum{f,p,m} H*Mc * QQ + Setup*y;
....
4.7. Conclusion
This paper gave a comprehensive overview of the indexed notation in math-
ematical modeling. The general notation is defined and several “extensions”
have been explained. It is fundamental to understand, read and write mathe-
matical models. We then gave some examples and how they are implemented
in the modeling language LPL. Finally, a complete production model with
several variants have been given in order to exercise the mathematical nota-
tion on a concrete example.
C HAPTER 5
105
CHAPTER 5. VARIOUS MODELING TOOLS 106
Virtually hundreds of tools and applications exist to help user to build and to
solve mathematical model. Lists of software and applications can be found in
the Internet. In this paper, some links are given where to look for an appro-
priate tool. It is unrealistic to give an exhaustive overview, also because the
situation is changing rapidly and new approaches emerge all the time.
The focus in this paper is mathematical modeling (not solving) in the realm
of numerical linear and non-linear optimization and combinatorial models –
which are typically used in operations research. The goal of this paper is to
give a first impression of various modeling tools –free and commercial– that
could be used to build mathematical models. The presentation for each tool
is done by a small problem example which is implemented. In this way, the
reader gets a first and better idea of the tool. The selection of the tools do not
follow a systematical method, it is rather a subjective choice of systems that I
came across in the last years.
The toolboxes and software presented here are grouped into three categories:
(algebraic) modeling languages, programming languages, and further tools
in the proximity of mathematical modeling.
A ZIP file of all models and the data displayed in this paper can be found at
this link: modeling4.7z.
5.1. Introduction
107 CHAPTER 5. VARIOUS MODELING TOOLS
The list of mathematical modeling software is huge. One can find free and
commercial software for all kind of problems. Searching the Internet un-
der “mathematical modeling”, “mathematical software”, “optimization soft-
ware”, “mathematics learning”, “mathematical tools” exposes many links.
Wikipedia and other sites list various categories, many other links exist, the
field is very dynamic and new approaches appear all the time:
However, the modeling language that I have in mind (which has not been
found by now in my opinion) is also a complete programming language with
all its interfaces to libraries, other software and own extensions with pack-
ages. Another paper that compares five languages (AMPL, AIMMS, GAMS,
Pyomo, and JuMP) is [81].
One of the first algebraic modeling language was GAMS, developed in the
1980’s, and is still a major and prominent player on the market. Shortly after,
a first version of AMPL, a powerful tool, came out and is one of the most
widespread language.
5.2.1 GAMS
GAMS is a general algebraic modeling system, based on its high level mod-
eling language. It declares a model by specifying a number of Sets, Param-
eters, Tables, Scalars, Variables, Equations, Model. It contains a Solve statement
to call a solver and various Display functions to output the results. GAMS
has probably the largest number of interfaces to all kinds of solvers. Very
large models can be processed efficiently using GAMS and it has a powerful
sparse-indexing mechanism. A large number of model examples is available
on the site of GAMS. GAMS is probably the oldest algebraic modeling lan-
guage, its first version has been published in 1982. It is a commercial software,
but a free demo version is available. As a small example, the following model
implements the problem of maximally coexisting queens on a chessboard.
CHAPTER 5. VARIOUS MODELING TOOLS 110
Modeling Steps: The model is a tighter formulation of the model coex. The
chessboard is a 8 × 8 grid, defining i ∈ I = {1, . . . , 8} rows and j ∈ I columns.
It contains s ∈ S = {1, . . . , 2|I| − 3} diagonals. Let shs be the shift value of a
(forward) diagonal relative to the main diagonal, and let rvs,i be the reverse
shift order value.
We introduce various binary variables: xwi,j = 1 if cell (i, j) has a white
queen; xbi,j = 1 if cell (i, j) has a black queen; wai = 1 if row i contains a
white queen; wbj = 1 if column j contains a white queen; wcs = 1 if (for-
ward) diagonal s contains a white queen; wds = 1 if (backward) diagonal
s contains a white queen. Furthermore, let us introduce the total number of
white (black) queens as an integer variable tot.
Constraints (1-6) are formulated in a logical way. Basically, these constraints
say the following: if a cell occupies a white queen then in the same row, col-
umn and the two diagonals only white queens are allowed, and if a cell occu-
pies a black queen then no white queen is allowed in the same row, column
and the two diagonals. Constraint (1), for instance, formulates the following
fact: “if cell (i, j) is occupied by a white queen (xwi,j is true) then row i and
column j must contain a white queen”, that is, wai and wbj both must be
true. The other logical constraints can be interpreted in a similar way (try to
verbalize them yourself!).
Contraints (7-8) define the total number of white and black queens and the
objective function maximized that number. (In addition, we fix the position
of one queen in the LPL code, since this does not change the optimal value.)
max tot
xwi,j → wai ∧ wbj forall i, j ∈ I (1)
xwi,i+sh → wcs forall s ∈ S, i ∈ I (2)
xwi,i+rvs,i → wds forall s ∈ S, i ∈ I (3)
xbi,j → ¬wai ∧ ¬wbj forall i, j ∈ I (4)
xbi,i+shs → ¬wcs forall s ∈ S, i ∈ I (5)
xbi,i+rv
X s,i
→ ¬wds forall s ∈ S, i ∈ I (6)
tot = xbi,j (7)
X
i,j
tot = xwi,j (8)
i,j
111 CHAPTER 5. VARIOUS MODELING TOOLS
Binary Variable
xw(i,j) has a white queen
xb(i,j) has a black queen
wa(i) white in row i
wb(i) white in column j
wc(s) white in diagonal s
wd(s) white in backward diagonal s;
Variable tot;
eb total black;
aw(i,j).. wa(i) =g= xw(i,j);
bw(j,i).. wb(j) =g= xw(i,j);
cw(s,i).. wc(s) =g= xw(i,i+sh(s));
dw(s,i).. wd(s) =g= xw(i,i+rev(s,i));
5.2.2 AMPL
AMPL is one of the most powerful algebraic modeling language available to-
day. It also supports dozens of solvers. It is similar to GAMS but has a more
straightforward and more concise syntax. It can formulate large linear, integer
and non-linear models and contains automatic differentiation for non-linear
models. It also can add logical constraints that are treated by constraint pro-
gramming solvers. AMPL generates the nl-file, which has become a standard
input format for many solvers. Model data are strictly separated from the
model structure which is purely declarative. In a small, separated script lan-
guage one can read/write the data and call a solver or do some other model
manipulation interactively. In the following, two small models show the syn-
tax of AMPL.
X X
min vci,j,p · Ti,j,p + fci,j · Ui,j
X j∈D, p∈P
i∈O, i∈O, j∈D
s.t Ti,j,p = si,p forall i ∈ O, p ∈ P
X
j∈D
Ti,j,p = dj,p forall j ∈ D, p ∈ P
X
i∈O
Ti,j,p <= ui,j Ui,j forall i ∈ O, j ∈ D
p∈P
Further Comments: This model showns how close the AMPL (and LPL) no-
tation is to the mathematical notation. To run the model, AMPL uses a sepa-
rated script language :
115 CHAPTER 5. VARIOUS MODELING TOOLS
model multmip1.mod;
data multmip1.dat;
solve;
option display_1col 5;
display Trans;
In LPL, one can also separate data and output instructions from the model
structure and then run the following instruction from the command line :
parameter supply{ORIG,PROD};
parameter demand{DEST,PROD};
parameter limit{ORIG,DEST};
parameter vcost{ORIG,DEST,PROD};
variable Trans{ORIG,DEST,PROD};
parameter fcost{ORIG,DEST};
binary variable Use{ORIG,DEST};
minimize TotalCost:
sum{i in ORIG, j in DEST, p in PROD} vcost[i,j,p] *
Trans[i,j,p]
+ sum{i in ORIG, j in DEST} fcost[i,j]*Use[i,j];
constraint
Supply{i in ORIG, p in PROD}: sum{j in DEST} Trans[i,
j,p] = supply[i,p];
Demand{j in DEST, p in PROD}: sum{i in ORIG} Trans[i,
j,p] = demand[j,p];
Multi{i in ORIG, j in DEST} : sum{p in PROD} Trans[i,
j,p] <= limit[i,j] * Use[i,j];
end
check {p in PROD}:
sum {i in ORIG} supply[i,p] = sum {j in DEST}
demand[j,p];
minimize Total_Cost:
sum {i in ORIG, j in DEST, p in PROD} vcost[i,j,p] *
Trans[i,j,p]
+ sum {i in ORIG, j in DEST} fcost[i,j] * Use[i,j];
[*,*,coils]:
FRA DET LAN WIN STL FRE LAF :=
GARY 39 14 11 14 16 82 8
CLEV 27 9 12 9 26 95 17
PITT 24 14 17 13 28 99 20
CHAPTER 5. VARIOUS MODELING TOOLS 118
[*,*,plate]:
FRA DET LAN WIN STL FRE LAF :=
GARY 41 15 12 16 17 86 8
CLEV 29 9 13 9 28 99 18
PITT 26 14 17 13 31 104 20 ;
param fcost:
FRA DET LAN WIN STL FRE LAF :=
GARY 3000 1200 1200 1200 2500 3500 2500
CLEV 2000 1000 1500 1200 2500 3000 2200
PITT 2000 1200 1500 1500 2500 3500 2200 ;
Problem: Assign people into groups in a way that the groups are as hetero-
geneous as possible. Each person is identified by four characteristics (depart-
ment, location, rating, and title). Build 7 groups such that these characteris-
tics are distributed between the groups as much as possible. Let typi,k be the
characteristic (as string) of person i in category k, and let wk be the weight in
the objective function for category k. Finally, the relation TYPESk,t is true if
characteristic t is in category k. This problem is from AMPL/Logic
X
min MaxInGrp − MinInGrp + wk (maxTk,t − minTk,t )
X (k,t)∈TYPES
subject to Xi,j = 1 forall i ∈ I
j X
MinInGrp ≤ Xi,j ≤ MaxInGrp forall j ∈ J
X
i
minTk,t ≤ Xi,j ≤ maxTk,t forall j ∈ J, (k, t) ∈ TYPES
i|typi,k =t
The objective function minimizes the deviations: Basically, we want the same
number of persons in the 7 groups (MaxInGrp − MinInGrp), but also the
119 CHAPTER 5. VARIOUS MODELING TOOLS
same number of all characteristics in each category in the same group. The
first constraint then states that each person must be in one single group. The
other two constraints limit the deviations. To make this problem harder, de-
crease sample and/or increase the number of groups.
set CATEG;
param type {ALL_PEOPLE,CATEG} symbolic;
param typeWt {CATEG} >= 0;
param numberGrps integer > 0;
set TYPES{k in CATEG}:=setof{i in PEOPLE} type[i,k];
var Assign {i in PEOPLE, j in 1..numberGrps} binary;
var MinInGrp <= floor (card(PEOPLE)/numberGrps);
var MaxInGrp >= ceil (card(PEOPLE)/numberGrps);
var MinType {k in CATEG, t in TYPES[k]}
<= floor (card {i in PEOPLE: type[i,k] = t} /
numberGrps);
var MaxType {k in CATEG, t in TYPES[k]}
>= ceil (card {i in PEOPLE: type[i,k] = t} /
numberGrps);
minimize Variation: (MaxInGrp - MinInGrp) +
sum {k in CATEG, t in TYPES[k]}
typeWt[k] * (MaxType[k,t] - MinType[k,t]);
subj to AssignAll {i in PEOPLE}:
sum {j in 1..numberGrps} Assign[i,j] = 1;
subj to MinInGrpDefn {j in 1..numberGrps}:
MinInGrp <= sum {i in PEOPLE} Assign[i,j];
subj to MaxInGrpDefn {j in 1..numberGrps}:
MaxInGrp >= sum {i in PEOPLE} Assign[i,j];
subj to MinTypeDefn {j in 1..numberGrps, k in CATEG, t in
TYPES[k]}:
MinType[k,t] <= sum {i in PEOPLE: type[i,k] = t}
Assign[i,j];
subj to MaxTypeDefn {j in 1..numberGrps, k in CATEG, t in
TYPES[k]}:
MaxType[k,t] >= sum {i in PEOPLE: type[i,k] = t}
Assign[i,j];
5.2.3 LINDO/LINGO
LINDO Systems is a software for integer programming, linear programming,
nonlinear programming, stochastic programming, global optimization. It con-
tains a modeling language (LINGO) as well as solvers integrated. The What’s
CHAPTER 5. VARIOUS MODELING TOOLS 122
Best library – based on this system – is a well known addon for Excel. It con-
tains a fully featured environment for building and editing problems with
LINGO language. A package to Python exists: the pyLingo package. The
LINGO language contains also the different parts: SETS:...ENDSETS for
defining sets, DATA:...ENDDATA for defining data tables, and For-loops
for defining sets of constraints. However, the LINGO language is not as pow-
erful as GAMS or AMPL. Also its syntax is a bit clumsy. It uses sets, but then
needs for-loops. Some keywords are old style (@FOR).
In the following, a model for the “Data Envelopment Analysis” field is used
to show the syntax of LINGO.
4. The output divided by the input on each DMU against each other must
be smaller than 1:
X X
Fk,j Wi,j ≤ Fk,j Wi,j forall i, k ∈ I
j∈J2 j∈J1
Score of BL : 1.000
Score of HW : 0.910
Score of NT : 0.962
Score of OP : 0.912
Score of YK : 1.000
Score of EL : 1.000
Hence, the most efficient schools are Bloom, Yorktown, and Elgin.
Further Comments: In LINGO, the syntax begins with MODEL and ends with
END but they seemed to have no special functions besides to indicate the be-
ginning or ending of the code. In LPL, by contrast, they are important be-
cause in this way one can modularize the code into multiple “sub-models”.
LINGO’s syntax clear departs from the usual mathematical notation: Instead
of SUM(J IN FACTOR)... it is @SUM(FACTOR(J)...) Equality and as-
signment operators are the same. Furthermore, it does not distinguish syn-
tactically between active and passive indices (see my Indexing Paper for more
information) – this is also the case, by the way, for GAMS. I find it essential to
distinguish them syntactically, it sharpens the preciseness when creating and
building models.
LPL code (run deamod)
model deamod "Data Envelopement Analysis";
set DMU,i,k := [BL HW NT OP YK EL] "Six schools";
FACTOR,j := [COST RICH WRIT SCIN] "input/output
factors";
parameter
// Inputs are "spending/pupil" and "not low income"
// Outputs are "Writing score" and "Science score"
NINPUTS := 2 "The first NINPUTS factors are inputs";
F{i,j} := [89.39 64.3 25.2 223
86.25 99 28.2 287
108.13 99.6 29.4 317
106.38 96 26.4 291
62.40 96.2 27.2 295
47.19 79.9 25.5 222];
WGTMIN := .0005 "Min weight applied to every factor";
variable W{i,j} [WGTMIN..9999999] "weight";
SCORE{i};
CHAPTER 5. VARIOUS MODELING TOOLS 124
defines a partitioning between the 3 trucks. It means, for example, that truck 1
starts at the depot visiting customers 2, 3, 4 in this order and returns to the de-
pot. In LPL, we can declare these partitioned permutation with a permutation
variable xk,i ∈ [1 . . . n − 1]. For example: x1,1 = 2 means that the customer
number 2 is visited by the truck 1 right after the depot, x1,2 = 3 means that
the next customer (after 2) is 3, etc.
The unique constraint is the load of the truck that these subsets must fullfill
(each subset sequence must be chosen in such a way that the capacity of the
truck is larger than the cumulated demand of the customers that it visits):
X
demxk,i ≤ CA forall k ∈ K
i|xk,i
We want to minimize the total travel distance of the trucks. Let cck be the size
of the subset k (the numbers of customers that the truck k visits). Of course
that number is variable and cannot be given in advance! Let routeDistancesk
be the (unknown) travel distance of truck k, then we want to minimize the to-
tal distances (and in a first round the number of trucks):
X
min routeDistk
k
where2
X
routeDistk = dxk,i−1 ,xk,i +if(cck > 0, dwxk,1 +dwxk,cck ) forall k ∈ K
i∈2..cck
The term dwxk,1 denotes the distance of the truck k from the depot to the
first customer, and dwxk,cck is the distance of the truck tour k from the last
customer to the depot, dxk,i−1 ,xk,i is the distance fromP
a customer to the next
– namely from customer xk,i−1 to customer xk,i – and i∈2..cck . . . sums that
distances of a tour k.
Further Comments: One of the most distiguished feature of LPL and the LSP
(Hexaly language) is the use of variables within passive indices. This allows
one to formulate an entire and practical important class of problems (the per-
mutation problems, see my Permutation Paper). No other modeling system,
to my knowledge, has this feature.
2
The expression if(boolExpr, Expr) returns Expr if boolExpr is true else it returns 0
(zero).
127 CHAPTER 5. VARIOUS MODELING TOOLS
function model() {
customersSequences[k in 1..nbTrucks] <- list(
nbCustomers);
constraint partition[k in 1..nbTrucks](
customersSequences[k]);
for [k in 1..nbTrucks] {
local sequence <- customersSequences[k];
CHAPTER 5. VARIOUS MODELING TOOLS 128
function readInputCvrp() {
local inFile = io.openRead(inFileName);
local nbNodes = 0;
while (true) {
local str = inFile.readString();
if(str.startsWith("DIMENSION")) {
if (!str.endsWith(":")) str=inFile.readString();
nbNodes = inFile.readInt();
nbCustomers = nbNodes - 1;
} else if ((str.startsWith("CAPACITY"))) {
if(!str.endsWith(":")) str=inFile.readString();
truckCapacity = inFile.readInt();
} else if((str.startsWith("EDGE_WEIGHT_TYPE"))) {
if(!str.endsWith(":")) str=inFile.readString();
local weightType = inFile.readString();
if (weightType != "EUC_2D") throw ("Edge Weight
Type " + weightType + " is not supported (
only EUC_2D)");
} else if(str.startsWith("NODE_COORD_SECTION")) {
break;
} else { local dump = inFile.readln(); }
}
//nodeX and nodeY are indexed by original data indices
(1 for depot)
for[n in 1..nbNodes] {
if (n != inFile.readInt()) throw "Unexpected index";
1820
3 32
5 4
12 24
29 22
9 14
7
19
10 8
23
2
17 13
27
15 31
25
16
30 28
11
6
21
26
5.2.5 MiniZinc
MiniZinc is an open-source, solver-independent constraint modeling language.
The MiniZinc Software includes also the solvers Gecode, Chuffed, COIN-OR
CBC, and a Gurobi interface (see [45]). One can also model linear or non-linear
optimization problems. Like other algebraic modeling languages, MiniZinc
contains sets (defined as arrays), parameter, variables, constraints and solve
instructions to formulate a model in a purely declarative way. As a language
for constraint programming, constraints can contain Boolean operators, such
as and (/\), or (\/), imply (->), or not equal (!=) operators, etc. One of the most
interesting and prominent feature of MiniZinc (and of other constraint pro-
gramming systems) is its library of global constraints (see for example Global
Constraint Catalog). Without going into the details here, two examples are
given: (1) The alldifferent function constrains a set of (integer) variables to be
all different from each other. (2) The at_most function requires at most n vari-
ables in a set of variables to take the given value v. Some of these global
constraints could be expressed in a common mathematical notation, but – de-
pending on the solver used – this would be inefficient. Given a set of integer
variables xi with i, j ∈ I, the alldifferent constraint, for example, could be ex-
pressed as
xi ̸= xj forall i, j ∈ I, j > i
The atmost constraint3 could be expressed as:
X
(xi = v) = n
i∈I
Expressing these constraints using a function name has the advantage that the
constraint programming system recognizes them and can apply special and
more efficient algorithms. MiniZinc contains many global constraints (see the
Reference Manual of MiniZinc and it is the real strength of this language.
Two models are given to show Boolean modeling and the use of alldifferent con-
straint in MiniZinc.
3
Note that LPL’s atmost keyword does not correspond to this global constraint
CHAPTER 5. VARIOUS MODELING TOOLS 132
Further Comments: MiniZinc contains and uses the global constraint alldif-
ferent (LPL uses the Alldiff function) to specify the constraints on the integer
variables. MiniZinc uses ranges and array to specify multi-dimensional data
sets or variables.
LPL code (run sudokuM)
model Sudoku "Sudoku Puzzle";
parameter n:=3;
set i,j := 1..n^2;
set g,h:=1..n; u,v:=1..n;
integer parameter start{i,j} := [
5, 3, 1, 0, 0, 9, 6, 2, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 6, 0, 9, 4,
0, 9, 6, 0, 3, 8, 1, 0, 0,
0, 0, 0, 0, 0, 0, 3, 0, 0,
7, 0, 0, 6, 0, 1, 0, 4, 0,
0, 6, 0, 8, 0, 0, 4, 0, 0,
1, 0, 5, 0, 2, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0];
integer variable X{i,j} [1..n^2];
constraint
A{i}: Alldiff({j} X[i,j]);
B{j}: Alldiff({i} X[i,j]);
C{g,h}: Alldiff({u,v} X[(g-1)*n+u,(h-1)*n+v]);
D{i,j|start}: X[i,j] = start[i,j];
solve;
Write{i}('%3d\n',{j} X);
end
| 0, 0, 0, 0, 0, 6, 0, 9, 4,
| 0, 9, 6, 0, 3, 8, 1, 0, 0,
| 0, 0, 0, 0, 0, 0, 3, 0, 0,
| 7, 0, 0, 6, 0, 1, 0, 4, 0,
| 0, 6, 0, 8, 0, 0, 4, 0, 0,
| 1, 0, 5, 0, 2, 0, 0, 0, 0,
| 0, 0, 0, 0, 0, 0, 0, 0, 0 |];
include "alldifferent.mzn";
constraint forall(i in RANGE)(alldifferent([X[i,j] | j in
RANGE]));
constraint forall(j in RANGE)(alldifferent([X[i,j] | i in
RANGE]));
constraint forall(k in RANGE)(alldifferent([X[i,j] | i in
first_i[k]..first_i[k]+2, j in first_j[k]..first_j[k
]+2]));
constraint forall(i,j in RANGE where start[i,j]!=0) (X[i,
j] = start[i,j]);
solve satisfy;
1. Each white square is illuminated, that is, it can see a light through an
uninterrupted horizontal or vertical line of white squares.
2. No two lights can see each other.
3. The number of lights adjacent to a numbered filled square is exactly the
number in the filled square.
Modeling Steps: For the size w×h (width/height) of the grid, we define a set
j, j1 ∈ W = {1, . . . , w} and i, i1 ∈ H = {1, . . . , h}. A parameter bi,j ∈ [−1, . . . , 5]
is declared for every square (i, j) in the grid: bi,j = −1 means the square is
white, bi,j = 5 means the black square is empty, otherwise (bi,j ∈ [0, . . . , 4])
the square is black and contains the digit bi,j .
CHAPTER 5. VARIOUS MODELING TOOLS 134
0 3
2 4
1 2
(2) For a black numbered square (i, j), the number of lights in the four neigh-
bours (left/right, top/down) must correspond to the number in the square:
X
xi1,j1 = bi,j forall i ∈ H, j ∈ W, bi,j ∈ [0, . . . , 4]
i1,j1|R(i,j,i1,j1)
(3) For all white squares (i, j) that are visible from (i, j1) or from (i1, j), either
(i, j1) or (i1, j) (or both) must have a light:
_ _
xi,j1 ∨ xi1,j forall i ∈ H, j ∈ W, bi,j = −1
j1|Vi,j,i,j1 i1|Vi,j,i1,j
(4) For two different squares (i, j) and (i1, j1) that are visible from each other,
only one can have a light:
xi,j nand xi1,j1 forall (i, j, i1, j1) ∈ V, i ̸= i1, j ̸= j1, bi,j = bi1,j1 = −1
4
Note: “x nand y” and “x nor y” mean x ∧ y and x ∨ y
135 CHAPTER 5. VARIOUS MODELING TOOLS
Solution: The data file for LPL can be downloaded from lightup1.txt. The
solution for this data is given in Figure 5.4, generated by the output model of
LPL (see below).
Further Comments: LPL and MiniZinc are similar in the notation of a logical
constraint (both use exist (exists), and ( /\ ), or ( \/ ) to express the
constraint. In contrast to MiniZinc and depending on the the solver used, LPL
translates the logical constraints into purely mathematical statements if using
a MIP solver.
LPL code (run lightup)
model lightup1 "Light Up Puzzle";
set i,i1,H; // board height
set j,j1,W; // board width
parameter b{i,j} [-1..5]; // board
E := -1; // empty square
F := 5; // empty black square
set visible{i,j,i1,j1};
binary variable x{i,j}; // is there a light
constraint C1{i,j|b<>E}: x=0;
constraint C2{i,j|b=E nor b=F}:
sum{i1,j1|i-1<=i1<=i+1 and j-1<=j1<=j+1 and
Abs(i1-i)+Abs(j1-j)=1} x[i1,j1] = b[i,j];
constraint C3{i,j|b=E}:
exist{j1|visible[i,j,i,j1]} x[i,j1] or
exist{i1|visible[i,j,i1,j]} x[i1,j];
constraint C4{visible[i,j,i1,j1]|i<>i1 or j<>j1}:
x[i,j] nand x[i1,j1];
solve;
end
model output;
Write{i}('%2s \n',{j} if(b<>E,b&'',x=1,'L','.'));
Draw.Scale(40,40);
Draw.DefFont('verdana',18,1,1,1);
--{i,j} Draw.Rect(if(b=E or b=F,'',''&b),j,i,1,1,if(b
=-1,1,0),0);
{i,j} Draw.Rect(if(b=E or b=F,'',''&b),j,i,1,1,if(b
=-1,6,0),0);
{i,j|x} Draw.Circle(j+.5,i+.5,0.4,1,0);
end
0 3
2 4
1 2
5.2.6 AIMMS
AIMMS is a modeling software that features a mixture of declarative and im-
perative programming styles. Optimization models can be formulated in the
style of algebraic modeling languages, with sets and indices, as well as mul-
tidimensional parameters, variables and constraints. Units of measurement
are natively supported in the language. AIMMS has a interface to many lin-
ear and non-linear solvers and is designed for large-scale optimization and
CHAPTER 5. VARIOUS MODELING TOOLS 138
scheduling-type problems. The syntax is very verbose and each element con-
sists of a number of attributes, it is like an entry in a database table with the
attributes as fields.
Problem: In the dice problem a set of three dice has to be designed by as-
signing an integer number to each face such that on average dice 1 beats
dice 2, dice 2 beats dice 3 and dice 3 beats dice 1. The goal is to maximize
the number of total wins on average. The dice problem has many solutions.
The problem is from Robert A Bosch, Monochromatic Squares, Optima, MP
Society Newsletter, Vol 71, March 2004, page 6-7. A related problem is also
implemented in monochrom.
Modeling Steps: Let f, fp ∈ Faces = {1, . . . , 6} be the faces on a dices and let
d ∈ Dices = {1, . . . , 3} be the set of dices. The lowest face value is flo = 1, and
the highest is fup = |Dice| · |Faces|. The variable Obj is the number of wins.
yi,f,fp is defined as follows: if face f of dice i wins (value 1) or loses (value 0)
against face fp of dice i + 1 (circular).
2. The second constraint is the definition of yi,f,fp , that is, face f of dice i
wins (value 1) or loses (value 0) against face fp of dice i + 1:
variable
Obj "Number of wins";
x{i,f} [flo..fup] "Face value of dice";
binary y{i,f,fp} "=1, if f beats fp (MatchOutcome)";
constraint
Wins{i}: sum{f,fp} y[i,f,fp] = Obj "Count the wins";
Fval{i,f,fp}: x[i,f] + (fup-flo)*(1-y[i,f,fp])
>= x[if(i<#i,i+1,1),fp] + 1 "non-trans.
relation";
Fa{i,f|f>1}: x[i,f-1]+1 <= x[i,f] "diff face values";
Fix: x['dice1','face1'] = flo "fix one value";
maximize N: Obj;
end
IndexDomain: (i,f);
Range: binary;
Comment: "Face value of dice.";
}
Variable MatchOutcome {
IndexDomain: (i,f,fp);
Range: binary;
Comment: {
"Binary variable indicating ..."
}
}
Constraint WinsConstraint {
IndexDomain: i;
Definition: Obj = sum( (f,fp), MatchOutcome(i
,f,fp) );
Comment: "Count the wins of all dice.";
}
Constraint MatchOutcomeConstraint {
IndexDomain: (i,f,fp);
Definition: FaceValue(i,f) + (
HighestFaceValue-LowestFaceValue)*(1-
MatchOutcome(i,f,fp)) >= FaceValue(i++1,
fp) + 1;
Comment: {
"Constraint that determines ..."
}
}
Constraint FaceValuesConstraint {
IndexDomain: (i,f) | (f-1) in faces;
Definition: FaceValue(i,f-1) + 1 <= FaceValue
(i,f);
Comment: "Constraint to enforce ...";
}
MathematicalProgram DiceMP {
Objective: Obj;
Direction: maximize;
Constraints: AllConstraints;
Variables: AllVariables;
Type: MIP;
}
}
Procedure MainInitialization {
Body: {
HighestFaceValue := card(Dice) * card(faces);
FaceValue.lower(i,f) := LowestFaceValue;
141 CHAPTER 5. VARIOUS MODELING TOOLS
FaceValue.upper(i,f) := HighestFaceValue;
FaceValue.lower('dice1','face1') :=
LowestFaceValue;
FaceValue.upper('dice1','face1') :=
LowestFaceValue;
FaceValue.level('dice1','face1') :=
LowestFaceValue;
SolutionMethod := 'normal';
}
}
Procedure MainExecution {
Body: {
empty Objs, FaceValues;
Objs(1) := Obj;
FaceValues(i,f,1) := FaceValue(i,f);
}
Comment: {
"Normal solve; returns one solution."
}
}
Procedure MainTermination {
Body: {
return 1;
}
}
}
5.2.7 MOSEL
Mosel Language can be thought of as both a modeling language and a pro-
gramming language. Like other modeling languages it offers the required
facilities to declare and manipulate problems, decision variables, constraints
and various data types and structures like sets and arrays. On the other hand,
it also provides a complete set of functionalities proper to programming lan-
guages: it is compiled and optimized, all usual control flow constructs are
supported and can be extended by means of modules. Although a general
modeling system, it is closely interfaced with its own XPress optimizer. A
link to a separate constraint programming solver Kalis is offered too. Many
modeling examples in Mosel are available from the Fico Site.
I use a small production planning model to illustrate the syntax of Mosel.
CHAPTER 5. VARIOUS MODELING TOOLS 142
X X X
min pxt + hst + qyt
t t t
s.t. st−1 + xt = dt + st forall t ∈ T
xt ≤ Myt forall t ∈ T
s0 = s0, s|T | = 0
xt ≥ 0, st ≥ 0, yt ∈ {0, 1} Sucht ∈ T
Costs are to be minimized. They are composed by production costs the stor-
age costs, and the set-up costs. The first constraint defines the balance from
period to period: stock at the beginning of t plus production equal demand
plus stock at the end of t. The second constraint defines the connection be-
ween production and batch opening: if no batch is opened (yt = 0), then no
bike is produced (xt = 0).
constraint
dem_sat{t}: if(t=1,s0,s[t-1]) + x[t] = d[t] + s[t];
vub{t}: x[t] <= (sum{k} d[k])*y[t];
endStock: s[#t]=0;
minimize cost:
sum{t} (p*x[t]+q*y[t]+if(t<#t,h,h/2)*s[t]);
model data;
q:=5000; p:=100; s0:=200; h:=5;
d{t} := /Jan 400 Feb 400 Mar 800 Apr 800
May 1200 Jun 1200 Jul 1200 Aug 1200/;
end
model output;
Write(' %7s \nDemand %7d \nProduc %7d\
\nInvent %7d \n\n P cost %7d \nI cost %7d\
\nSet-up %7d \n\n Total costs: %7d',
{t}t, {t}d, {t}x, {t}s, {t}p*x, {t}h*s, {t}q*y,cost
);
end
end
declarations
EPS=1e-6 ! Zero t o l e r a n c e
T=8 ! Number o f time p e r i o d s
RT=1..T ! Range o f time
end-declarations
DEMAND:= [400,400,800,800,1200,1200,1200,1200]
! O b j e c t i v e : minimize t o t a l c o s t
mincost:=
sum(t in RT ) (if(t<T,INVCOST,INVCOST/2))*s(t) +
sum(t in RT) (SETUPCOST*y(t) + PRODCOST*x(t))
setparam("XPRS_VERBOSE", 1) !
setparam("XPRS_MIPLOG", 3) !
setparam("XPRS_PRESOLVE", 1) ! D i s a b l e PRESOLVE
setparam("XPRS_CUTSTRATEGY", 0) ! D i s a b l e autom . c u t s
minimize(mincost)
! minimize ( XPRS_LIN , mincost )
writeln
forall(t in RT)
writeln("Period ", t,": prod ", getsol(x(t))," (demand:
", DEMAND(t),
", unit cost: ", PRODCOST, "), setup ", getsol(
y(t)),
" (cost: ", SETUPCOST, ", stock: ", getsol(s(t)
), ")")
end-model
145 CHAPTER 5. VARIOUS MODELING TOOLS
5.2.8 OPL
Optimization Programming Language (OPL) is an algebraic modeling lan-
guage for mathematical optimization models, which makes the coding easier
and shorter than with a general-purpose programming language. It is part of
the CPLEX software package and therefore tailored for the IBM ILOG CPLEX
and IBM ILOG CPLEX CP (constraint programming) optimizers. The sepa-
rate IBM ILOG Script for OPL is an embedded JavaScript implementation that
provides the “non-modeling” expressiveness of OPL.
To display some aspects of the OPL language, a multi-commodity transporta-
tion is used.
X
min cp,i,j · Transp,i,j
X
(p,i,j)∈R
subject to Transp,i,j = sp,i forall p ∈ P, i ∈ Orig
X
j∈R
Transp,i,j = dp,j forall p ∈ P, j ∈ Dest
X
i∈R
Transp,i,j ≤ Capacity forall (i, j) ∈ CO
p∈R
Transp,i,j ≥ 0 forall (p, i, j) ∈ R
Further Comments: OPL uses the ellipsis ... to specify the missing data in an
otherwise structural model code. They are given in an separate data file. The
CHAPTER 5. VARIOUS MODELING TOOLS 146
concept of tuple is used to related data, like the concept of “record” or “struct”
in programming languages. This is definitely a concept that is missing in
the LPL language. Due to this feature it is also possible to create compound
(sparse) sets. However, I find LPL’s compound sets syntax more straightfor-
ward and shorter.
LPL model code (run transp3)
model transp3 "Multi-commodity Transportation";
set i,j,Cities;
set p,Products;
parameter Capacity;
set connection{i,j};
set route{p,i,j};
parameter Supply{p,i};
parameter Demand{p,j};
parameter Cost{p,i,j};
set Orig{i}; Dest{j};
variable Trans{p,i,j|route};
minimize obj:sum{route[p,i,j]} Cost*Trans;
constraint ctSupply{p,Orig[i]}:
sum{j in route} Trans = Supply;
constraint ctDemand{p,Dest[j]}:
sum{i in route} Trans = Demand;
constraint ctCapacity{connection[i,j]}:
sum{p in route} Trans <= Capacity;
end
string p;
connection e;
}
{route} Routes = ...;
{connection} Connections = { c | <p,c> in Routes };
tuple supply {
string p;
string o;
}
{supply} Supplies = { <p,c.o> | <p,c> in Routes };
float Supply[Supplies] = ...;
tuple customer {
string p;
string d;
}
{customer} Customers = {<p,c.d> | <p,c> in Routes};
float Demand[Customers] = ...;
float Cost[Routes] = ...;
{string} Orig[p in Products] = { c.o | <p,c> in Routes };
{string} Dest[p in Products] = { c.d | <p,c> in Routes };
constraint ctSupply[Products][Cities];
constraint ctDemand[Products][Cities];
minimize
sum(l in Routes) Cost[l] * Trans[l];
subject to {
forall( p in Products , o in Orig[p] )
ctSupply[p][o]:
sum( <o,d> in CPs[p] )
Trans[< p,<o,d> >] == Supply[<p,o>];
forall( p in Products , d in Dest[p] )
ctDemand[p][d]:
sum( <o,d> in CPs[p] )
Trans[< p,<o,d> >] == Demand[<p,d>];
forall(c in Connections)
ctCapacity:
sum( <p,c> in Routes )
Trans[<p,c>] <= Capacity;
}
CHAPTER 5. VARIOUS MODELING TOOLS 148
5.2.9 MATLAB
Problem: The problem is “to blend steels with various chemical compositions
to obtain 25 tons of steel with a specific chemical composition. The result
should have 5% carbon and 5% molybdenum by weight. The objective is to
minimize the cost for blending the steel”. The problem is from MatLab Doc.
Modeling Steps: A set i ∈ I of different ingots of steel are available for pur-
chase. Only one of each ingot type is available. Their weight is wi , the carbon
and molybdenum contents in percentage is given by ri and mi , and the cost
per ton is ci .
Furthermore, a set j ∈ J of grades of alloy steel and one grade of scrap steel are
available for purchase. Alloy and scrap steels can be purchased in fractional
amounts. the carbon and molybdenum contents in percentage of each alloy
is given by rai and mai , and the cost per ton is cai . The scrap content of the
carbon and molybdenum in percentage is rs and ms and its cost per ton is cs.
Let Ii be the number of ingots, Aj the fractional weight of each alloy, and S the
weight of scrap. So, how many ingots and how much alloy and scrap must be
used to produce W tons of steel with a p% of carbon and molybdenum while
minimizing the total costs. The model can be formulated as follows:
149 CHAPTER 5. VARIOUS MODELING TOOLS
X X
min ci Ii + caj Aj + cs · S
X
i X
j
subject to wi Ii + Aj + S = W
X
i jX
w i ri I i + raj Aj + rs · S = pW
X
i Xj
mi Ii + maj Aj + ms · S = pW
i j
Ii ∈ [0, 1], Aj ≥ 0, S ≥ 0, forall i ∈ I, j ∈ J
prob.Objective = cost;
totalWeight = weightIngots*ingots + sum(alloys) + scrap;
carbonIngots = [5,4,5,3]/100;
carbonAlloys = [8,7,6]/100;
carbonScrap = 3/100;
totalCarbon = (weightIngots.*carbonIngots)*ingots +
carbonAlloys*alloys + carbonScrap*scrap;
molybIngots = [3,3,4,4]/100;
molybAlloys = [6,7,8]/100;
molybScrap = 9/100;
totalMolyb = (weightIngots.*molybIngots)*ingots +
molybAlloys*alloys + molybScrap*scrap;
sol.ingots
sol.alloys
sol.scrap
fval
A = [];
b = [];
Aeq = [5,3,4,6,1,1,1,1;
5*0.05,3*0.04,4*0.05,6*0.03,0.08,0.07,0.06,0.03;
5*0.03,3*0.03,4*0.04,6*0.04,0.06,0.07,0.08,0.09];
beq = [25;1.25;1.25];
lb = zeros(8,1);
ub = ones(8,1);
ub(5:end) = Inf; % No upper bound on n o n i n t e g e r v a r i a b l e s
[x,fval] = intlinprog(f,intcon,A,b,Aeq,beq,lb,ub);
For the purpose of this paper the free solver glpk (linear models), ipopt (non-
linear models) and the commercial solver cplex and gurobi are used. Note that
a licence is needed for the commercial solvers and separate installation of the
solvers is needed too. To install the packages, which installs an interface to
the solvers, one need the type on the command line (or the Python command
line) :
Problem: Two products (’Pencils’ and ’Pens’) are to be transported from the
factories in (’Detroit’ and ’Denver’) to the warehouses in (’Boston’, ’New York’,
and ’Seattle’) to satisfy the demand (’inflow[h,i]’). The flows on the trans-
portation network must respect arc capacity constraints (’capacity[i,j]’). The
objective is to minimize the sum of the arc transportation costs (’cost[i,j]’). The
Python version is from the Gurobi examples.
The formulation in LPL is straightforward. Note that the flow condition ex-
ploits the sparcity of the network. This is not trivial, but necessary for larger
problems.
This code is compared to the Python formulation using Gurobi package. Note
that the Gurobi package also contains a quicksum function for faster summa-
tion then the ordinary Python sum operator.
LPL code (run netflow)
CHAPTER 5. VARIOUS MODELING TOOLS 154
if GetSolverStatus()=7 then
Write('Optimal objective %d\n', Cost);
{h} (Write('\nOptimal flows for %s:' , h),
Write{arcs[i,j]}('\n %s -> %s: %d', i,j, flow))
;
end
end
m = gp.Model('netflow')
flow = m.addVars(commodities, arcs, obj=cost, name="flow"
)
m.addConstrs(
(flow.sum('*', i, j) <= capacity[i, j] for i, j in
arcs), "cap")
m.addConstrs(
(flow.sum(h, '*', j) + inflow[h, j] == flow.sum(h, j,
'*')
for h in commodities for j in nodes), "node")
m.optimize()
if m.Status == GRB.OPTIMAL:
solution = m.getAttr('X', flow)
for h in commodities:
print('\nOptimal flows for %s:' % h)
for i, j in arcs:
155 CHAPTER 5. VARIOUS MODELING TOOLS
if solution[h, i, j] > 0:
print('%s -> %s: %g' % (i, j, solution[h,
i, j]))
Problem: This model is the same as model 2d-tic-tac-toe, except for the di-
mension: it models a 3-dimensional tik-tak-toe problem.
The question here is the same as for the 2D-tik-tak-toe game: Is it possible to
occupy all 27 fields without any row, column or diagonal of only X’s or O’s?
(If this were not the case, then we have proven that the game cannot end in a
tie.) Interestingly we can prove here that the 3 × 3 × 3 tik-tak-toe cannot end
in a tie (there must be one winner). This model is also interesting for learning
some trick in MIP and logical modeling and some indexing structures.
The second constraint links the Dc and the Gp variables in a logical way: for
each line p, if it does not contain only X or only O then at least one point on
CHAPTER 5. VARIOUS MODELING TOOLS 156
Solution: The objective is 4, which means that it is not possible to end the
game in a tie. (Compare this result with the result in the 2D-tik-tak-toe model
in 2d-tic-tac-toe.)
Questions
Answers
for i in range(size):
for j in range(size):
for k in range(size):
if i == 0:
lines.append(((0,j,k), (1,j,k), (2,j,k)))
if j == 0:
lines.append(((i,0,k), (i,1,k), (i,2,k)))
if k == 0:
lines.append(((i,j,0), (i,j,1), (i,j,2)))
if i == 0 and j == 0:
lines.append(((0,0,k), (1,1,k), (2,2,k)))
if i == 0 and j == 2:
lines.append(((0,2,k), (1,1,k), (2,0,k)))
if i == 0 and k == 0:
lines.append(((0,j,0), (1,j,1), (2,j,2)))
if i == 0 and k == 2:
lines.append(((0,j,2), (1,j,1), (2,j,0)))
if j == 0 and k == 0:
lines.append(((i,0,0), (i,1,1), (i,2,2)))
if j == 0 and k == 2:
lines.append(((i,0,2), (i,1,1), (i,2,0)))
lines.append(((0,0,0), (1,1,1), (2,2,2)))
CHAPTER 5. VARIOUS MODELING TOOLS 158
model = gp.Model('Tic_Tac_Toe')
isX = model.addVars(size, size, size, vtype=GRB.BINARY,
name="isX")
model.setObjective(isLine.sum())
model.optimize()
min ∥b − Ax∥22
x≥0
Modeling Steps: The optimization problem can be formulated (in matrix form)
as follows:
min rT r
x,r
s.t. r = b − Ax
x≥0
x ∈ Rn (regression weights)
r ∈ Rm (residual)
b ∈ Rm (data)
159 CHAPTER 5. VARIOUS MODELING TOOLS
Further Comments: In the newest version of gurobipy (10.0 – 2022) one can
use MVar, MLinExpr, MQuadExpr to model variables and constraints that
are naturally expressed in “vertorized” form. This often allow to write com-
pact, loopless code and most arithmetic operations allow for ndarray (numpy
package) and scipy.sparse operands.
Frankly, I do not find that this more compact form is a big deal. First of all,
sparse datacubes – which is the rule and not the exception – must still be
generated using loops, and only simple model can use this vectorized form.
Second, one must be careful in using nested @ operators: depending on the
nesting the generation of the model can be more or less efficient.
Despite of Python’s vectorized form, the LPL code is still more concise. Note
that in LPL the passive can be omitted, this make the syntax even more “vector-
like”. If one likes to generate exactly the same model instance in LPL then the
data can be read from the data file regressionAb.txt (regressionAb.txt).
LPL code (run regression1)
model regression "Non-negative Regression";
parameter n:=10; m:=100;
set i:=1..m;
j:=1..n;
parameter A{i,j}:=Rnd(0,1);
b{i}:=Rnd(0,1);
variable x{j};
r{i} [-1..1];
constraint C0{i}: r = b - sum{j} A*x;
minimize Dev: sum{i} r*r;
Write('x = %9.6f\n', {j} x);
end
# Example data
A = np.random.rand(100, 10)
b = A \verb? np.random.rand(10) + 0.01 * np.random.rand
(100)
model = gp.Model()
x = model.addMVar(10, name="x")
r = model.addMVar(100, lb=-np.inf, name="r")
model.setObjective(r ? r)
model.addConstr(r == b - A \verb? x)
CHAPTER 5. VARIOUS MODELING TOOLS 160
model.optimize()
print(f"Regression values: {x.X}")
print(f"Fit error: {math.sqrt(r.X ? r.X):.2e}")
Modeling Steps: Let’s introduce three sets: (1) for the nurses: n ∈ N =
{1, . . . , N}, (2) for the periods (days): d ∈ D = {1, . . . , D}, and for the shifts
(tasks): s ∈ S = {1, . . . , S}. A Boolean relationsship for the shift requests is in-
troduced as reqn,d,s which is true if nurse n made a request to be assigned to
shift s in day d. A binary variable xn,d,s (“shifts” in the code) defines whether
nurse n works on shift s in day d (=1) or not (=0). The parameter minS is a
minimal number of shifts that a nurse must work at least to fullfill all assign-
ments. maxS is just at most one bigger than minS.
X
max xn,d,s
X
n,d,s|reqn,d,s
s.t xn,d,s = 1 forall d ∈ D, s ∈ S (1)
X
n
xn,d,s ≤ 1 forall n ∈ N, d ∈ D (2)
s X
minS ≤ xn,d,s ≤ maxS forall n ∈ N (3)
d,s
Constraint (1) specifies that for each shift in all days exactly one nurse is as-
signed. Constraint (2) determines that each nurse works at most one shift per
day. Constraint (3) distribute evenly the amount of work (all shifts: D · S) to
every nurse. On average each nurse must work D · S/N. If this is not an inte-
ger then some nurses must work ⌊D·S/N⌋ and some must work an additional
shift. Hence, every nurse must work in at least minS shifts and at most maxS
shifts.
LPL code (run nurses)
model nurses "A Simple Nurse Scheduling";
parameter N,num_nurses := 5;
D,num_days := 7;
S,num_shifts := 3;
set n,all_nurses := 1..N;
set d,all_days := 1..D;
set s,all_shifts := 1..S;
set req{n,d,s} "shift requests";
Read{n,d,s}('nurses.txt,;1',n,d,s,req);
parameter minS := Trunc((S*D)/N);
maxS := minS + if(S*D%N,1);
binary variable shifts{n,d,s};
constraint C1{d,s}: sum{n} shifts = 1;
C2{n,d}: sum{s} shifts <= 1;
C3{n}: minS <= sum{d,s} shifts <= maxS;
maximize Req: sum{req[n,d,s]} shifts;
Write{d}('Day %d\n%s%s', d,
Format{n,s|shifts}(' Nurse %d works in shift %s %s\
n', n,
s, if(req,'(requested)','')),
Format{n,s|~shifts and req}(' Nurse %d requested
shift %s but does not work\n', n,
s);
Write('The number of requests fulfilled: %d out of %d\n
',Req,sum{req}1);
end
5 7 3 //number nurses/days/shifts
// the request list is:
1 1 3 //nurse 1 requests in day 1 shift 3
1 5 3
....
if __name__ == '__main__':
main()
Modeling Steps: The set of customers is m ∈ M and the potential set of ware-
houses is n ∈ N. The number of warehouses to open is P and the delivery
costs from a warehouse n to a costumer location m is dn,m . Let xn,m be the
unknown quantity send from warehouse n to customer m and let yn be a
binary variable which is 1 if the warehouse location is open.
The mathematical model can be formulated as follows:
165 CHAPTER 5. VARIOUS MODELING TOOLS
X
min cn,m xn,m
X
n,m
subject to xn,m = 1 forall m ∈ M
n
x
X n,m ≤ yn forall n ∈ N, m ∈ M
yn = P forall n ∈ N
n
0 ≤ xn,m ≤ 1 forall n ∈ N, m ∈ M
yn ∈ {0, 1} forall n ∈ N
This model is used to compare LPL with Pyomo. See for an implementation
of an abstract model here: wl2.
Further Comments: The model in LPL includes all data directly into the model.
The Pyomo Python script formulation below uses plain Python code for the
data implementation. The model specification begins by creating a concrete
model with:
model = pyo.ConcreteModel(name="(WL)")
solver = pyo.SolverFactory('gurobi')
Then the solver is called, and finally the output is generated with the print
and with Pyomo’s pprint function.
LPL code (run wl1)
model wl1 "Warehouse Location";
set n := [Harlingen Memphis Ashland] "a set of
warehouses";
m := [NYC LA Chicago Houton] "a set of customer
locations";
parameter P := 2 "number of open warehouses";
d{n,m} "delivery costs"
:= [1956 1606 1410 330
1096 1792 531 567
485 2322 324 1236];
variable x{n,m} [0..1] "fraction of demand";
binary y{n} "warehouse open?";
constraint A{m}: sum{n} x[n,m] = 1;
B{n,m}: x[n,m] <= y[n];
C: sum{n} y[n] = P;
minimize obj: sum{n,m} d[n,m]*x[n,m];
CHAPTER 5. VARIOUS MODELING TOOLS 166
Write('OBJ=%5.2f\n',obj);
Write('Open: %9s\n', {n|y} n);
end
# the data
N = ['Harlingen', 'Memphis', 'Ashland']
M = ['NYC', 'LA', 'Chicago', 'Houston']
d = {('Harlingen', 'NYC'): 1956, \
('Harlingen', 'LA'): 1606, \
('Harlingen', 'Chicago'): 1410, \
('Harlingen', 'Houston'): 330, \
('Memphis', 'NYC'): 1096, \
('Memphis', 'LA'): 1792, \
('Memphis', 'Chicago'): 531, \
('Memphis', 'Houston'): 567, \
('Ashland', 'NYC'): 485, \
('Ashland', 'LA'): 2322, \
('Ashland', 'Chicago'): 324, \
('Ashland', 'Houston'): 1236 }
P = 2
# the model
model = pyo.ConcreteModel(name="(WL)")
model.x = pyo.Var(N, M, bounds=(0,1))
model.y = pyo.Var(N, within=pyo.Binary)
def obj_rule(mdl):
return sum(d[n,m]*mdl.x[n,m] for n in N for m in M)
model.obj = pyo.Objective(rule=obj_rule)
def num_warehouses_rule(mdl):
return sum(mdl.y[n] for n in N) <= P
167 CHAPTER 5. VARIOUS MODELING TOOLS
model.num_warehouses = pyo.Constraint(rule=
num_warehouses_rule)
print("OBJ=",pyo.value(model.obj))
model.y.pprint()
model.x.pprint()
Problem: This model wl2 is the same model as model wl1, with the exception
that the data set is separated from the model structure.
To solve the problem, call the LPL model in the command line as follows:
The file wl2-data.dat contains two data sets. If you want to run the second
set data1 then call it as follows:
Further Comments: The model in LPL contains only the model structure with-
out any data. The data are defined in an external file (see code).
model = pyo.AbstractModel(name="(WL)")
Like the concrete model, it defines the data parameters, the variables, the con-
straints, and the objective function. It can be executed but it does nothing,
since the data are missing and solver link is not established.
The Pyomo abstract model is as follows:
While installing Pyomo with the pip command, an executable pyomo.exe is
also installed. To run and solve the model, use this executable and run the
script on the command line as follows:
CHAPTER 5. VARIOUS MODELING TOOLS 168
The data are defined in an external file wl2-data.dat that must be linked when
called LPL (see above) :
model data;
n:= [Harlingen Memphis Ashland];
m:= [NYC LA Chicago Houton];
P:=2;
d{n,m} := [1956 1606 1410 330
1096 1792 531 567
485 2322 324 1236];
end
model = pyo.AbstractModel(name="(WL)")
model.N = pyo.Set()
model.M = pyo.Set()
model.d = pyo.Param(model.N,model.M)
model.P = pyo.Param()
model.x = pyo.Var(model.N, model.M, bounds=(0,1))
model.y = pyo.Var(model.N, within=pyo.Binary)
def obj_rule(model):
169 CHAPTER 5. VARIOUS MODELING TOOLS
def num_warehouses_rule(model):
return sum(model.y[n] for n in model.N) <= model.P
model.num_warehouses = pyo.Constraint(rule=
num_warehouses_rule)
An external file wl2-pydata.dat holds the data (the format is similar to the
AMPL data format):
# wl2_data.dat: Pyomo format data file for the warehouse
location problem
set N := Harlingen Memphis Ashland ;
set M := NYC LA Chicago Houston;
param d :=
Harlingen NYC 1956
Harlingen LA 1606
Harlingen Chicago 1410
Harlingen Houston 330
Memphis NYC 1096
Memphis LA 1792
Memphis Chicago 531
Memphis Houston 567
Ashland NYC 485
Ashland LA 2322
Ashland Chicago 324
Ashland Houston 1236
;
param P := 2 ;
Modeling Steps: The model in LPL is straightforward (the solver used is Kni-
tro as defined in the lplcfg.lpl file). It is compared to the Pyomo Python script
formulation of a concrete model (note that the free source ipopt is used to
solve the model).
LPL code (run rosenbrock)
model wl1 "Rosenbrock Function";
variable x:=1.5; y:=1.5;
minimize obj: (1-x)^2 + 100*(y-x^2)^2;
Write('OBJ=%5.5f\n',obj);
Write('x=%5.5f , y=%5.5f\n', x,y);
end
Pyomo can also represent hierarchically structured problems using the com-
ponent Block to manage model scope. Various extensions for disjunctive
programming (component Disjunction), differential algebraic equations
(DAE) (components ContinuousSet, DerivativeVar), models with equi-
librium constraints (component Complementarity) exist. These extensions
can be automatically transformed into an appropriate form to be solved. For
example, DAEs can be transformed into a general nonlinear model using, p.e.
the Euler forward method.
m = GEKKO()
m.Var(...)
m.Equation(...)
m.solve(...)
Problem: A non-linear benchmark model (NLP) from the Hock & Schittkowski
model library with 4 variables and 2 constraints.
min x1 x4 (x1 + x2 + x3 ) + x3
s.t x1 x2 x3 x4 ≥ 25
x21 + x22 + x23 + x24 = 40
1 ≤ x1 , x2 , x3 , x4 ≤ 5
x0 = (1, 5, 5, 1) initialization
The AMP model (right side) can be solved online or using the following
Python script:
Python script (run hs71-main.py)
import sys
sys.path.append("../")
from apm import *
minimize x1*x4*(x1+x2+x3) + x3
End Equations
End Model
print('Results')
print('x1: ' + str(x1.value))
print('x2: ' + str(x2.value))
print('x3: ' + str(x3.value))
print('x4: ' + str(x4.value))
print('Objective: ' + str(m.options.objfcnval))
dy
K = −ty (1)
dt
where K = 10. The solution should be reported from initial time 0 to final
time 20 (model is from: GEKKO.
CHAPTER 5. VARIOUS MODELING TOOLS 174
yi+1 − yi −ti yi
=− forall i ∈ I − {n}
∆t K
or
δt
yi+1 = yi + · −ti yi forall i ∈ I − {n} with y0 = 5
K
k1 = ∆t · (−ti yi )/K
k2 = ∆t · ((−ti yi ) + k1 /2)/K
yi+1 = yi + k 2
In LPL, these methods can be implemented using a loop and the graph can be
generated by the Draw instruction.
Further Comments: The dollar sign $ in the APMonitor code indicates a deriva-
tive. The model is transformed using orthogonal collocation into a NLP (non-
linear) model and solved by the open source APopt or IPopt solvers. In LPL,
this transformation must be done manually.
LPL code (run prob8)
model prob8 "Problem 8 from APMonitor";
set i:=0..80;
parameter D:=0.25 "step size";
5
Warning: This approach is only for educational demonstration. It should not be
used in a professional context, because the errors can grow rapidly. Most software
solving such problem use orthogonal collocation and other methods, see [17].
175 CHAPTER 5. VARIOUS MODELING TOOLS
parameter t{i}:=i*D;
parameter y{i};;
y[0]:=5;
-- Euler's forward method
{i|i<#i} (y[i+1] := (y[i] + D*(-t*y)/10));
--Runde-Kutta second order method:
//parameter k1; k2;
//{i|i<#i} (k1:=D*(-t*y)/10,
// k2:=D*((-t*y)+k1/2)/10,
// y[i+1]:=y + k2);
Draw.Scale(1,1);
Draw.XY(t,y,1);
end
m = GEKKO()
m.time = np.linspace(0,20,100)
k = 10
y = m.Var(value=5.0)
t = m.Param(value=m.time)
m.Equation(k*y.dt()==-t*y)
m.options.IMODE = 4
m.solve(disp=False)
plt.plot(m.time,y.value)
plt.xlabel('time')
plt.ylabel('y')
plt.savefig('prob8.png') ## save t o a f i l e
Pulp is an open source package that can formulate linear MIP models. It can
be linked to a numbers of linear solvers (CBC, GLPK, CLPEX, Gurobi, etc.).
To install the PuLP use pip:
prob = LpProblem(...)
x = LpVariable(...)
choices = LpVariable.dicts(...) ## an indexed variable
5 3 7
6 1 9 5
9 8 6
8 6 3
4 8 3 1
7 2 6
6 2 8
4 1 9 5
8 7 9
Problem: The Sudoko is a well known game. Its rules are simple: “Fill in the
grid (see, for example, Figure 5.5) so that every row, every column, and every
3 × 3 subblock contains the digits 1 to 9.”. The modeling has been explain in
my Puzzlebook. An implementation can be found at sudoku.
X
xi,j,k = 1 forall i, j ∈ I
X
k
xi,j,k = 1 forall i, k ∈ I
X
j
xi,j,k = 1 forall j, k ∈ I
X
i
xi ′ ,j ′ ,k = 1 forall i, k ∈ I
j
′
with i = i − (i − 1) mod 3 + ⌈(j − 1)/3⌉
′
and j = 3(i − 1) mod 3 + (j − 1) mod 3 + 1
xi,j,k = 1 forall i, j, k ∈ I, Pi,j = k
xi,j,k ∈ {0, 1} forall i, j, k ∈ I
I = {1, . . . , 9}
CHAPTER 5. VARIOUS MODELING TOOLS 178
The first constraint make sure that in every cell exactlyone digit is placed. The
second and thrid constraints garantuees that on each row and column every
digit occurs exactly once, and the fourth constraint requires that in each 3 × 3
sub-block every digit occurs. Finally, the given entries must be set.
Further Comments: The script uses a default solver, if we want to use a dif-
ferent solver, we can modify the script as follows:
import pulp as pl
path_to_cplex = r'c:\....\cplex.exe'
solver = pl.CPLEX_CMD(path=path_to_cplex)
...
result = model.solve(solver)
# the model
prob = LpProblem("Sudoku Problem",LpMinimize)
choices = LpVariable.dicts("Choice",(Vals,Rows,Cols),0,1,
LpInteger)
prob += 0, "Arbitrary Objective Function"
for r in Rows:
for c in Cols:
prob += lpSum([choices[v][r][c] for v in Vals]) == 1,
""
for v in Vals:
for r in Rows:
prob += lpSum([choices[v][r][c] for c in Cols]) == 1,
""
for c in Cols:
prob += lpSum([choices[v][r][c] for r in Rows]) == 1,
""
for b in Boxes:
prob += lpSum([choices[v][r][c] for (r,c) in b]) ==
1,""
prob += choices["5"]["1"]["1"] == 1,""
prob += choices["6"]["2"]["1"] == 1,""
prob += choices["8"]["4"]["1"] == 1,""
+-------+-------+-------+
| 5 3 4 | 6 7 8 | 9 1 2 |
| 6 7 2 | 1 9 5 | 3 4 8 |
| 1 9 8 | 3 4 2 | 5 6 7 |
+-------+-------+-------+
| 8 5 9 | 7 6 1 | 4 2 3 |
| 4 2 6 | 8 5 3 | 7 9 1 |
| 7 1 3 | 9 2 4 | 8 5 6 |
+-------+-------+-------+
CHAPTER 5. VARIOUS MODELING TOOLS 180
| 9 6 1 | 5 3 7 | 2 8 4 |
| 2 8 7 | 4 1 9 | 6 3 5 |
| 3 4 5 | 2 8 6 | 1 7 9 |
+-------+-------+-------+
# the output
sudokuout = open('sudokuout.txt','w')
for r in Rows:
if r == "1" or r == "4" or r == "7":
sudokuout.write("+-------+-------+-------+\n")
for c in Cols:
for v in Vals:
if value(choices[v][r][c])==1:
if c == "1" or c == "4" or c =="7":
sudokuout.write("| ")
sudokuout.write(v + " ")
if c == "9":
sudokuout.write("|\n")
sudokuout.write("+-------+-------+-------+")
sudokuout.close()
print ("Status:", LpStatus[prob.status])
print ("Solution Written to sudokuout.txt")
Pk = min(k + 1 , 2n − k − 1) , forall k ∈ K
We also define
′ ′
i = max(0 , k − n + 1) + j , j = max(0 , n − k − 1) + j
′′ ′′
i = min(n + 1 , k + 2) − j , j = max(0 , k − n + 1) + j forall j ∈ I, k ∈ K
X
max xi,j
X
i,j
s.t xi,j = 1 forall i ∈ I (1)
X
j
xi,j = 1 forall j ∈ I (2)
X
i
xi ′ ,j ′ ≤ 1 forall k ∈ K (3)
X
j|j≤Pk
xi ′′ ,j ′′ ≤ 1 forall k ∈ K (4)
j|j≤Pk
xi,j ∈ [0, 1] forall i ∈ I, j ∈ I
Note that there are several other implementations in LPL explained in chess5.
Further Comments: The Python code needs the mip package. The model
is initialized by the function Model(). Like in PuLP, the constraints are
CHAPTER 5. VARIOUS MODELING TOOLS 182
“added” to the model using the += operator. Note also the graphical output
of LPL.
queens.optimize()
if queens.num_solutions:
stdout.write('\n')
for i, v in enumerate(queens.vars):
stdout.write('O ' if v.x >= 0.99 else '. ')
if i % n == n-1:
stdout.write('\n')
To install JuMP and solver packages, the package manager Pkg of Julia must
be used:
using Pkg
Pkg.add("JUMP")
Pkg.add("GLPK")
Pkg.add("HIGHS")
Pkg.add("IPOPT")
To install commercial solvers, first install the solver libraries, then add a path
and install a package as follows (sometimes the package has to be built). For
example, to install the commercial solver CPLEX or Gurobi follow the instruc-
tions at CPLEX package and Gurobi package.
ENV["CPLEX_STUDIO_BINARIES"] = "<pathToCplexBin>"
using Pkg
Pkg.add("CPLEX")
Pkg.build("CPLEX")
X X
min ci,j xi,j + fj yj
X
i,j j
s.t. xi,j = 1 forall i ∈ I
j
xi,j ≤ yj forall i ∈ I, j ∈ J
xi,j ∈ [0, 1], yj ∈ [0, 1] forall i ∈ I, j ∈ J
Solution: With the random data of the Julia/JuMP code the graphical output
of the LPL program is given in Figure 5.6.
Obj=5.22642
Further Comments: The LPL code uses the same random data as the Juli-
a/JuMP code to compare the output graph. The plotting code of Julia was
omitted, because it was too long.
The model in Julia is initialized by Model() creating an empty model object.
In contrast to most Python implementations, JuMP uses the powerful marco-
programming of Julia: Variables are declared by a macro @variable(model,...),
constraints are declared by a macro @constraint(model,...), etc. For
the data, Julia’s efficient data structure are used. LPL imports the data from
the file facilityLoc.txt in order to generate the same result as Julia/JuMP.
LPL code (run facilityLoc)
model facilityLoc "Facility Location";
parameter m; n;
parameter x_c{i}; y_c{i}; x_f{j}; y_f{j};
Read('@facitityLoc.txt', m,n);
set i:=1..m; j:=1..n;
Read{i}('@%1',x_c=2,y_c=3);
Read{j}('@%1',x_f=2,y_f=3);
Draw.Scale(300,-300);
{i,j|x} Draw.Line(x_c,y_c,x_f,y_f);
{i} Draw.Circle(x_c,y_c,.02,5);
{j} Draw.Rect(x_f-.02,y_f-.02,.04,.04,if(y,3,1),3);
Draw.Text('Obj='&Round(Obj,-5),0,0);
end
LPL’s own random data: Replace the 6 first lines by the this code, if using LPL
random data:
parameter m:=12; n:=5;
set i:=1..m; j:=1..n;
parameter x_c{i}:=Rnd(0,1); y_c{i}:=Rnd(0,1);
x_f{j}:=Rnd(0,1); y_f{j}:=Rnd(0,1);
Random.seed!(314)
m = 12
n = 5
x_c, y_c = rand(m), rand(m)
x_f, y_f = rand(n), rand(n)
f = ones(n);
c = zeros(m, n)
for i in 1:m
for j in 1:n
c[i, j] = LinearAlgebra.norm([x_c[i] - x_f[j], y_c[i]
- y_f[j]], 2)
end
end
model = Model(HiGHS.Optimizer)
set_silent(model)
@variable(model, y[1:n], Bin);
@variable(model, x[1:m, 1:n], Bin);
@constraint(model, client_service[i in 1:m], sum(x[i, j]
for j in 1:n) == 1);
@constraint(model, open_facility[i in 1:m, j in 1:n], x[i
, j] <= y[j]);
@objective(model, Min, f' * y + sum(c .* x));
optimize!(model)
println("Optimal value: ", objective_value(model))
# p l o t t i n g code was omitted
Modeling Steps: Let’s introduce a set of rows and columns in the grid: i, j ∈
I = {1, . . . , 5}. The set of awarded points is: s ∈ S = {1, . . . , 6}. Furthermore,
we need a set to distingish rows and columns: t ∈ T = {’r’ , ’c’}. Let’s also
introduce a data vector as for the award points.
The binary variable xi,j is 1 if a cell (i, j) is occupied by a residential lot, oth-
erwise it is occupied by a commercial lot. We need another binary variable
yi,s,t which is 1, if and only if the row(column) i has exactly s − 1 residential
lots. So, for example, y1,1,r = 1 means: the row 1 has zero (0) residential lots.
The first constraint says that the number of residential lots is 12:
X
xi,j = 12
i,j
The second and third constraints are nothing else than defintions of the yi,s,t,r
variables. The second constraint is for the rows and models the following: if
and only if the number of residential lots in row i is s − 1 then yi,s,r = 1 The
third constraint is for the columns and models the following: if and only if the
number of residential lots in column i is s − 1 then yi,s,r = 1. This condition
can be formulated as a logical equivalence :
X
yi,s,’r’ ↔ xi,j = s − 1 forall i ∈ I, s ∈ S, t ∈ T
j
X
yj,s,’c’ ↔ xi,j = s − 1 forall j ∈ I, s ∈ S, t ∈ T
i
CHAPTER 5. VARIOUS MODELING TOOLS 188
Solution: The total awards that can be reached is 14. Three residential lots are
on rows 2 − 5 and columns 1, 2, 4, 5.
obj
14.00
x{i,j}
1 2 4 5
-------------------------------
2 | 1 1 1
3 | 1 1 1
4 | 1 1 1
5 | 1 1 1
Further Comments: The Julia/JuMP code is from the JuMP tutorial at JuMP.dev
Tutorial). In Julia/JuMP the problem is formulated explicitly as a linear MIP
problem. LPL uses logical constraints that are translated automatically to lin-
ear constraints.
The model cannot be found anymore in the JuMP web-site. I guess it is erro-
neous, although it produces a correct result (but I did not find out its logic!).
LPL code (run uplanning)
model uplanning "Urban Planning: A Puzzle";
set i,j := 1..5 "rows/cols";
s := 1..6 "point set";
t := /r,c/ "row/col";
parameter a{s} := [-5,-4,-3,3,4,5] "awards";
binary variable x{i,j}; y{i,s,t};
constraint A: sum{i,j} x = 12;
R{i,s}: y[i,s,'r'] <-> sum{j} x = s-1;
C{j,s}: y[j,s,'c'] <-> sum{i} x = s-1;
maximize obj: sum{i,s,t} a*y;
Writep(obj,x);
end
model = Model(GLPK.Optimizer)
@variable(model, 0 <= x[1:5, 1:5] <= 1, Int)
rowcol = ["R", "C"]
points = [5, 4, 3, -3, -4, -5]
@variable(model, 0 <= y[rowcol,points,1:5] <= 1, Int)
@objective(
model,
Max,
sum(
3 * (y["R", 3, i] + y["C", 3, i]) +
1 * (y["R", 4, i] + y["C", 4, i]) +
1 * (y["R", 5, i] + y["C", 5, i]) -
3 * (y["R", -3, i] + y["C", -3, i]) -
1 * (y["R", -4, i] + y["C", -4, i]) -
1 * (y["R",-5,i] + y["C",-5,i]) for i in 1:5
)
)
@constraint(model, sum(x) == 12)
for i in 1:5
@constraints(model, begin
y["R",5,i] <= 1 / 5 * sum(x[i,:]) # sum=5
y["R",4,i] <= 1 / 4 * sum(x[i,:]) # sum=4
y["R",3,i] <= 1 / 3 * sum(x[i,:]) # sum=3
y["R",-3,i] >= 1 - 1 / 3 * sum(x[i,:]) # sum=2
y["R",-4,i] >= 1 - 1 / 2 * sum(x[i,:]) # sum=1
y["R",-5,i] >= 1 - 1 / 1 * sum(x[i,:]) # sum=0
y["C",5,i] <= 1 / 5 * sum(x[:,i]) # sum=5
y["C",4,i] <= 1 / 4 * sum(x[:,i]) # sum=4
example_urban_plan()
CHAPTER 5. VARIOUS MODELING TOOLS 190
Problem: What is the number of passports a person would need to visit all
199 countries without a visa? (The problem is from JuMP.dev example).
Modeling Steps: Let c, d ∈ C = {1, . . . , 199} be a set of all 199 countries. And
let pc,d be the matrix of passport-index with the following values (jan 2022):
• 3 = visa-free travel
• 2 = eTA is required
• 1 = visa can be obtained on arrival
• 0 = visa is required
• -1 is for all instances where passport and destination are the same
Solution: The result is that one needs 23 passports, with the data pc,d stored
in file passport1.csv. They are (Jan 2022) :
Further Comments: Julia uses the package DataFrames and CSV to read
data from Excel. It also uses the package GLPK to link the solver. In Ju-
lia/JuMP a mathematical model is declared using the macros @variable,
@constraint, and @objective.
LPL code (run passport)
model passport;
set c,d "countries";
parameter p{c,d} "passport-index"; dummy;
Read('passport1.csv,,\t,',dummy,{c} c);
Read{c}('passport1.csv,;1,\t,',c,{d} p);
// alternatively read from a text file:
//Read{c}('passport.txt,,\t',c=2);
//Read{c}('passport.txt,,\t',c=2,{d} p);
parameter P{c,d}:=if(p=-1 or p=3,1);
binary variable x{c};
constraint A{d}: sum{c} P[c,d]*x[c] >= 1;
minimize nr: sum{c} x;
Write('Min number of passports: %d\n',nr);
Write{c|x}('* %s\n',c);
end
function modifier(x)
if x == -1 || x == 3
return 1
else
return 0
end
end
using JuMP
import GLPK
model = Model(GLPK.Optimizer)
@variable(model, x[C], Bin)
@objective(model, Min, sum(x))
CHAPTER 5. VARIOUS MODELING TOOLS 192
max x + y + 2z
s.t x + 2y + 3z ≤ 4
x+y≥1
x, y, z ∈ [0, 1]
193 CHAPTER 5. VARIOUS MODELING TOOLS
The optimal solution is (x, y, z) = (1, 0, 1). The example is from Gurobi Exam-
ples.
Further Comments: LPL calls Gurobi’s library to solve the model. Internally,
it is basically the same code as the C code below, but all those implemen-
tation details are hidden from the modeler. The C code first declares the
data needed. Then the model is initialized, license is checked, some param-
eters are set using the library functions GRBemptyenv, GRBsetstrparam,
GRBstartenv, GRBnewmodel. After the initialization, variables and con-
straints are added with GRBaddvars and GRBaddconstr, the optimizer is
called (GRBoptimize) and finally various output functions extract the solu-
tion.
That is basically the same as LPL does when calling the Gurobi solver.
LPL code (run mip1-c)
model mip1c "A small MIP model";
binary variable x; y; z;
maximize O: x + y + 2*z;
constraint C1: x + 2*y + 3*z <= 4;
C2: x + y >= 1;
Writep(O,x,y,z);
end
// Add variables
obj[0] = 1; obj[1] = 1; obj[2] = 2;
vtype[0] = GRB_BINARY; vtype[1] = GRB_BINARY; vtype[2]
= GRB_BINARY;
error = GRBaddvars(model, 3, 0, NULL, NULL, NULL, obj,
NULL, NULL, vtype, NULL);
if (error) goto QUIT;
// Optimize model
error = GRBoptimize(model);
if (error) goto QUIT;
printf("\nOptimization complete\n");
if (optimstatus == GRB_OPTIMAL) {
printf("Optimal objective: %.4e\n", objval);
printf(" x=%.0f, y=%.0f, z=%.0f\n", sol[0], sol[1],
sol[2]);
} else if (optimstatus == GRB_INF_OR_UNBD) {
printf("Model is infeasible or unbounded\n");
} else {
printf("Optimization was stopped early\n");
}
QUIT:
if (error) {
printf("ERROR: %s\n", GRBgeterrormsg(env)); exit(1);
}
// Free model
GRBfreemodel(model);
// Free environment
GRBfreeenv(env);
return 0;
}
tool. If you like to model with JuMP/Julia, for instance, you only need
to install the IJulia package:
using Pkg
Pkg.add("IJulia")
using IJulia
notebook()
Now you are ready to use the Notebook to interactively enter the model
code.
• The R-Project is a open-source tool containing a programming language
basically for statistical applications. But it has also interface to opti-
mization tools.
• The NEOS Server is an Internet-based client-server application that pro-
vides free access to more than 60 libraries of optimization solvers. A
model can be submitted in various formats (GAMS, AMPL, and oth-
ers).
• Mathcad Prime was the first to introduce 1986 live editing (WYSIWYG)
of typeset mathematical notation in an interactive notebook, combined
with automatic computations. A idea copied by many other systems.
The current commercial version contains many features in numerical
and symbolic mathematics, visualization, etc. It is not as powerful as
Maple or Mathematica.
• Besides of the already mentioned solver libraries (Gurobi, Cplex, XPress),
HiGHS is one of the most advanced open-source linear optimization
solver. MOSEK is a commercial solver library and solves LPs, QPs,
SOCPs, SDPs and MIPs. It includes interfaces to C, C++, Java, MAT-
LAB, .NET, Python and R. Knitro is one of the most advanced solver
for nonlinear optimization.
• If you just need a powerful mathematical library containing high per-
formance algorithms and you program everything else yourself, con-
sider the Nag Library.
5.5. Conclusion
The list of mathematical tools in this paper is uncomplete and it is based on
my personal and subjective experiences. I hope that I mentioned the most
important once. Furthermore, there is no rating here, just a simple example is
given that should give a first glimpse on the tools.
C HAPTER 6
197
CHAPTER 6. VARIOUS MODEL TYPES 198
Mathematical models can be classified into groups using various criteria: dis-
crete, continuous, linear, non-linear, etc. Different model types also dominate
in different research domains. Linear and non-linear optimization models
prevail the realm of operations research. Dynamical models such as differ-
ential equations, appear more in physics and engineering. Statistical models
and models treating uncertainty (p.e. stochastic models, fuzzy models) oc-
cur in social sciences. This is not to say that physicists do not use statistics.
However, the various research domain use a slightly different vocabulary in
building their models.
Coming from the operations research, a lot of attention is given to the classifi-
cation in this research field. Several model types are formulated in mathemat-
ical notation and in the modeling system LPL (see [72]). They are compared
with each other from various point of views. Concrete model application ex-
amples are given for most model type.
6.1. Introduction
Models can be classified into different groups using various criteria:
Zero- versus One- versus Multi-objective: We may looking for all, for an
arbitrary or for a particular solution. For zero-objective problems, we are in-
terested only in an arbitrary solution, it may be unique or not. For example,
in model example3a any solution would be fine (it is unique in this case). In
many situations, we are interested in the “best” solution, with regards to one
or many objectives. These problems are called optimization problems. We may
minimize cost, resources, redundancy, etc. or we may maximize revenue, util-
ity, turnover, customer satisfaction, robustness, etc. Normally, we are looking
for one objective. In same cases, however, several – maybe conflicting – ob-
jectives have to be considered. These problems are called multi-objective op-
timization problems. Such problems can be handled by various methods, for
example, with goal programming (see below).
Unconstraint versus constrained: Within the class of optimization problems
there are unconstraint or constraint problems. Unconstraint problems only
contain an objective function and no constraint, example: find the minimum
of a parable : min f(x) = x2 . Constraint problems consist of an objective and
one or several constraints.
Deterministic versus stochastic: If the data in a resultant model is not known
with certainty, we have stochastic models. In many situation, the data are un-
certain or unknown, for example, future demand on a market are not known
or uncertain, but even data from the past are often not known or only a
small sample is known. Statistical methods to estimate them are then needed.
Mostly, however, we pretend that data are deterministic in order to avoid
complicated models. In many cases, this may be realistic, but the modeler
should be aware of that fact. There is a broad theory of stochastic models, but
in this paper only deterministic once are treated.
Static versus dynamical: In many situation we are looking for an (optimal)
state: finding an optimal production plan, a tournament schedule of a sport
league, the shortest round trip, etc. Normally, optimization models result
from these problems. These models are static. When change has to be mod-
eled, like motion over time in physics, evolution in animal population in bi-
ology, fluctuation in monetary quantities in economy, or development of a
virus in a pandemic, dynamical models are commonly use, such as discrete
dynamical systems or a system of differential equations.
Linear versus non-linear: Linear models only contain linear terms with re-
gards to the variables. Completely different methods are used to solve linear
and non-linear problems. Linear, continuous problems are solved mainly by
the simplex method, a modification of this method solves also certain prob-
lems containing quadratic terms (QP, QPC, etc.) – if they are convex. Lin-
ear, discrete (combinatorial) problems use branch-and-bound, cutting plane
or other reduction algorithms. Non-linear problems are in general much more
difficult to solve, and a large number of algorithms have been developed. The
distinction between linear and non-linear models may be arbitrary. We also
may partition the models into convex and concave, or into “easy” and “difficult”
CHAPTER 6. VARIOUS MODEL TYPES 200
min f(x)
subject to gi (x) ≤ 0 forall i ∈ {1, . . . , m}
x∈X
If the first line is missing, we have a zero-objective model, if the second line is
missing, we have an unconstraint model. The f and gi are functions defined in
Rn .2 X is a subset of Rn (or Nn ), and x is a vector of n components x1 , . . . , xn .
The above problem has to be solved for the values of the variables x1 , . . . , xn
that satisfy the restrictions gi while minimizing the function f. The function
f is called the objective function, gi are the constraints. A vector x ∈ X that
satisfies all constraints gi (x) ≤ 0 is called feasible solution. The collection of all
such points is the feasible region. The problem then of the mathematical model
above is to find a xo such that f(x) ≥ f(xo ) for each feasible point x. Such a
point xo is called an optimal solution.
A small example is the following model (see [4], page 3):
Figure 6.1 illustrates the model geometrically in the two-dimensional real Eu-
clidean space.
6.2. Variations
There are useful practical variations in notation that can be reduced to a stan-
dard model type.
f(x) ≥ 0
f(x) = 0 =⇒
f(x) ≤ 0
CHAPTER 6. VARIOUS MODEL TYPES 202
min z
min max f(xi ) =⇒ s.t. f(xi ) ≥ z forall i ∈ I
i∈I
z≥0
min z
subject to gi (x) ≤ 0 forall i = 1, . . . , m
x∈X
f(x) ≤ z
In the following sections various model types are presented and most of them
implemented:
1. Linear programs (LP) consist of linear constraints and a linear objective
function and real variables.
2. Integer (linear) programs (IP) consist of linear constraints and a linear
objective function and integer variables.
3. 0-1 (linear) programs consist of linear constraints and a linear objective
function and binary variables (integer variables with only values of 0
and 1). This type is a special case of the previous one, where vari-
ables are integer but can only take the values 0 or 1. From the for-
mulation point of view, the difference between the three types is very
small. However – as we shall see – the difficulty to solve integer prob-
lems is much higher. Linear programs (LP) can be solved in polynomial
time, while IP and 0-1 IP problems are mostly NP-complete. The appli-
cation field of these three model types is very large. We shall point to
examples.
4. Quadratic problems (QP) which consist of linear constraints and a quadratic
convex objective function.
5. 0-1 quadratic problems (0-1-QP) which consist of linear constraints and
a quadratic convex objective function and contain 0-1 variables. Both
types have interesting applications in portfolio theory.
6. Quadratic constraint problems (QCP) which consist of linear and quadratic
convex constraints and a quadratic convex objective function.
7. Second order cone problems (SOCP), which have many applications in
physics. All of these previous model classes are convex problems – and
much easier to solve.
8. Non-convex quadratic problems (NCQP), an interesting application is given
below. All of these previous model classes can today be solved by com-
mercial solvers like Gurobi or Cplex.
9. A large class of models is the non-linear optimization model class (NLP).
Many solver exist for specific subclasses of this class. Also some general
205 CHAPTER 6. VARIOUS MODEL TYPES
X
min cj xj
X
j∈J
subject to ai,j xj ≥ bi forall i ∈ I
j∈J
xj ≥ 0 forall j ∈ J
I = {1 . . . m}, J = {1 . . . n}, m, n ≥ 0
An more compact formulation using matrix notation for the model is as fol-
lows:
min c·x
subject to A · x ≥ b
x≥0
The objective function f the constraints gi , and X (in the general format) are
as follows:
f(x1 , . . . , xn ) = c1 x1 + . . . + cn xn
gi (x1 , . . . , xn ) = bi − (ai,1 x1 + . . . + ai,n xn ) ≤ 0 forall i = 1, . . . , m
x ∈ Rn
In the following, a concrete problem with random data for the matrix A, and
the two vectors b and c is specified (with n = 15 and m = 15):
c = 16 73 39 81 68 60 90 11 33 89 71 12 24 23 47
207 CHAPTER 6. VARIOUS MODEL TYPES
87 34 0 0 43 0 52 85 36 0 0 0 0 0 0 0
0 0 39 0 84 0 0 88 0 0 0 0 0 0 22 0
55 63 79 0 0 0 0 71 0 0 0 0 70 0 79 0
0 0 0 0 0 0 0 73 0 0 0 22 0 0 0 0
0 0 0 66 0 0 34 0 0 24 0 61 0 0 64 0
0 0 16 19 0 0 0 0 0 0 0 0 0 0 18 0
15 70 61 0 0 0 0 0 0 0 0 0 0 0 0 0
A=
0 0 0 0 0 0 0 0 52 0 14 0 0 92 0 b=
58
0 0 0 0 0 0 0 30 0 0 98 0 19 0 0 44
0 70 37 0 0 0 0 0 0 0 0 86 0 93 0 0
90 0 82 0 66 0 0 0 0 26 0 0 0 0 0 0
77 30 0 0 0 0 13 10 0 0 0 50 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 72 0 0 0 79 0 0 0 0 0 11 90 0 0 0
0 0 0 0 0 32 55 0 23 0 0 0 0 0 36 119
With these data, the model is specified by the following explicit linear pro-
gram:
min 16x1 + 73x2 + 39x3 + 81x4 + 68x5 + 60x6 + 90x7 + 11x8 + 33x9
+89x10 + 71x11 + 12x12 + 24x13 + 23x14 + 47x15
subject to 87x1 + 34x2 + 43x5 + 52x7 + 85x8 + 36x9 ≥ 0
39x3 + 84x5 + 88x8 + 22x15 ≥ 0
55x1 + 63x2 + 79x3 + 71x8 + 70x13 + 79x15 ≥ 0
73x8 + 22x12 ≥ 0
66x4 + 34x7 + 24x10 + 61x12 + 64x15 ≥ 0
16x3 + 19x4 + 18x15 ≥ 0
15x1 + 70x2 + 61x3 ≥ 0
52x9 + 14x11 + 92x14 ≥ 58
30x8 + 98x11 + 19x13 ≥ 44
70x2 + 37x3 + 86x12 + 93x14 ≥ 0
90x1 + 82x3 + 66x5 + 26x10 ≥ 0
77x1 + 30x2 + 13x7 + 10x8 + 50x12 ≥ 0
72x2 + 79x6 + 11x12 + 90x13 ≥ 0
32x6 + 55x7 + 23x9 + 36x15 ≥ 119
xj ≥ 0 forall j ∈ {1 . . . 15}
Modeling Steps: The formulation of the model in the LPL modeling language
is straightforward and the notation is close to the mathematical notation using
indices: First, define the two sets i and j. Then declare and assign the data
as parameters A, c, and b. The variable vector x is declared, and finally the
constraints R and the minimizing objective function obj are written.
CHAPTER 6. VARIOUS MODEL TYPES 208
Note that the data matrices A, b, and c are generated using LPL’s own random
generator. (To generate each time the same data, the code can also use the
function SetRandomSeed(a) where a is an integer.)
Today, models with n, m > 10000 and much larger are solved on a regular
base. LP models with millions of variables can be solved today. A linear
programming model with 2000 variables and 1000 linear constraints can be
downloaded and solved at: lp2000.
Solution: The small model defined above has the following solution:
x= 0 0 0 0 0 0 0 1.4667 1.1154 0 0 0 0 0 2.5929
obj = 174.8096
Further Comments: The linear programming (LP) model has many applica-
tions in quantitative decision making. LP is used for capacity planning, re-
source (raw material) allocation, manpower planning, blending, transporta-
tion, network flow, network design, portfolio selection, optimal marketing
mix, multiperiod product mix, and many others.
A small example in multi period production planning is given in the model:
product. A historical example of a the so-calledmin-cut problem is modeled
by Tolstoi1930. An application example for transportation is trans or ship3.
A linear model implementing three common regression methods is given in
regression.
Further Notes: As already seen in the model regression certain non-linear func-
tions can be transformed in a way that the model becomes an linear one. We
mention three of them (see [9], Chap. 13):
209 CHAPTER 6. VARIOUS MODEL TYPES
2. The maximal value. Suppose the objective function has the form:
f(x) = max c · x
One can add a single variable y and modify the LP as follows:
min y
subject to A · x ≥b
c·x ≤y
x ≥0
y ≥0
One can convert this into a LP model. If the feasible set {x|A · x ≤ b, x ≤
0} is nonempty and bounded and if q · x + β > 0, using the following
transformations:
1
z= , y = zx
q·x+β
min p·x+α
subject to A · y − bz ≤0
q · y + βz =1
y ≥0
z ≥0
X
min cj xj
X
j∈J
subject to ai,j xj ≥ bi forall i ∈ I
j∈J
x j ∈ N+ forall j ∈ J
I = {1 . . . m}, J = {1 . . . n}, m, n ≥ 0
min c·x
subject to A · x ≥ b
x ∈ N+
The objective function f, the constraints gi , and x (in the general model for-
mat) are as follows:
f(x1 , . . . , xn ) = c1 x1 + . . . + cn xn
gi (x1 , . . . , xn ) = bi − (ai,1 x1 + . . . + ai,n xn ) ≤ 0 forall i = 1, . . . , m
x ∈ Nn
The IP model has the same notation as the LP model, the only difference is that
the variables are integer values. However, IP model are much more difficult
to solve in general. (To get an idea solve the following model: lp2000. Then
try to solve ip2000.)
c = 16 73 39 81 68 60 90 11 33 89 71 12 24 23 47
CHAPTER 6. VARIOUS MODEL TYPES 212
87 34 0 0 43 0 52 85 36 0 0 0 0 0 0 0
0 0 39 0 84 0 0 88 0 0 0 0 0 0 22 0
55 63 79 0 0 0 0 71 0 0 0 0 70 0 79 0
0 0 0 0 0 0 0 73 0 0 0 22 0 0 0 0
0 0 0 66 0 0 34 0 0 24 0 61 0 0 64 0
0 0 16 19 0 0 0 0 0 0 0 0 0 0 18 0
15 70 61 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0
A= 0 0 0 0 0 52 0 14 0 0 92 0 58
b=
0 0 0 0 0 0 0 30 0 0 98 0 19 0 0 44
0 70 37 0 0 0 0 0 0 0 0 86 0 93 0 0
90 0 82 0 66 0 0 0 0 26 0 0 0 0 0 0
77 30 0 0 0 0 13 10 0 0 0 50 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 72 0 0 0 79 0 0 0 0 0 11 90 0 0 0
0 0 0 0 0 32 55 0 23 0 0 0 0 0 36 119
The data given above specify the following explicit linear program:
min 16x1 + 73x2 + 39x3 + 81x4 + 68x5 + 60x6 + 90x7 + 11x8 + 33x9
+89x10 + 71x11 + 12x12 + 24x13 + 23x14 + 47x15
subject to 87x1 + 34x2 + 43x5 + 52x7 + 85x8 + 36x9 ≥ 0
39x3 + 84x5 + 88x8 + 22x15 ≥ 0
55x1 + 63x2 + 79x3 + 71x8 + 70x13 + 79x15 ≥ 0
73x8 + 22x12 ≥ 0
66x4 + 34x7 + 24x10 + 61x12 + 64x15 ≥ 0
16x3 + 19x4 + 18x15 ≥ 0
15x1 + 70x2 + 61x3 ≥ 0
52x9 + 14x11 + 92x14 ≥ 58
30x8 + 98x11 + 19x13 ≥ 44
70x2 + 37x3 + 86x12 + 93x14 ≥ 0
90x1 + 82x3 + 66x5 + 26x10 ≥ 0
77x1 + 30x2 + 13x7 + 10x8 + 50x12 ≥ 0
72x2 + 79x6 + 11x12 + 90x13 ≥ 0
32x6 + 55x7 + 23x9 + 36x15 ≥ 119
xj ∈ N+ forall j ∈ {1 . . . 15}
Note that the data matrices A, b, and c are generated using LPL’s own random
generator. (To generate the same data each time, the code can also use the
function SetRandomSeed(a) where a is an integer.)
Solution: The small model defined above has the following solution :
x= 0 0 0 0 0 0 0 2 4 0 0 0 0 0 1
obj = 201
Various linear problems with a special structure (the matrix A must be uni-
modular) such as the transportation problem have integer solutions without
explicitly formulating them as integer programs. They can be solved as LP
progams.
Models with general integer variables with an upper bound can also be trans-
formed into models that only contain 0 − 1 integer variables. The transfor-
mation is as follows. Let x ∈ {0, 1, . . . , u} be an general upper (and lower)
bounded integer variable. Then substitute the variable 0 ≤ x ≤ u by the
expression:
δ0 + 2δ1 + 4δ2 + . . . + 2r δr
Problem: The general linear 0-1 integer programming model – called 0-1-IP
– consists of a linear objective function f(x), m linear constraints gi (x), and n
0 − 1 integer variables. It can be compactly formulated as follows (see [83]):
X
min cj xj
X
j∈J
subject to ai,j xj ≥ bi forall i ∈ I
j∈J
xj ∈ {0, 1} forall j ∈ J
I = {1 . . . m}, J = {1 . . . n}, m, n ≥ 0
A more compact formulation using matrix notation for the model is:
min c·x
subject to A · x ≥ b
x ∈ {0, 1}
The objective function f the constraints gi , and X (in the general model for-
mat) are as follows:
f(x1 , . . . , xn ) = c1 x1 + . . . + cn xn
gi (x1 , . . . , xn ) = bi − (ai,1 x1 + . . . + ai,n xn ) ≤ 0 forall i = 1, . . . , m
x ∈ {0, 1}
The 0-1-IP model has the same notation as the LP (and the IP) model, the only
difference is that the variables are 0 − 1 integer values. The 0-1-IP model is
also difficult to solve in general. (To get an idea solve the following model:
lp2000. Then try to solve ip01-2000.)
c = 16 73 39 81 68 60 90 11 33 89 71 12 24 23 47
CHAPTER 6. VARIOUS MODEL TYPES 216
87 34 0 0 43 0 52 85 36 0 0 0 0 0 0 0
0 0 39 0 84 0 0 88 0 0 0 0 0 0 22 0
55 63 79 0 0 0 0 71 0 0 0 0 70 0 79 0
0 0 0 0 0 0 0 73 0 0 0 22 0 0 0 0
0 0 0 66 0 0 34 0 0 24 0 61 0 0 64 0
0 0 16 19 0 0 0 0 0 0 0 0 0 0 18 0
15 70 61 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0
A= 0 0 0 0 0 52 0 14 0 0 92 0 58
b=
0 0 0 0 0 0 0 30 0 0 98 0 19 0 0 44
0 70 37 0 0 0 0 0 0 0 0 86 0 93 0 0
90 0 82 0 66 0 0 0 0 26 0 0 0 0 0 0
77 30 0 0 0 0 13 10 0 0 0 50 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 72 0 0 0 79 0 0 0 0 0 11 90 0 0 0
0 0 0 0 0 32 55 0 23 0 0 0 0 0 36 119
The data given above specify the following explicit linear program:
min 16x1 + 73x2 + 39x3 + 81x4 + 68x5 + 60x6 + 90x7 + 11x8 + 33x9
+89x10 + 71x11 + 12x12 + 24x13 + 23x14 + 47x15
subject to 87x1 + 34x2 + 43x5 + 52x7 + 85x8 + 36x9 ≥ 0
39x3 + 84x5 + 88x8 + 22x15 ≥ 0
55x1 + 63x2 + 79x3 + 71x8 + 70x13 + 79x15 ≥ 0
73x8 + 22x12 ≥ 0
66x4 + 34x7 + 24x10 + 61x12 + 64x15 ≥ 0
16x3 + 19x4 + 18x15 ≥ 0
15x1 + 70x2 + 61x3 ≥ 0
52x9 + 14x11 + 92x14 ≥ 58
30x8 + 98x11 + 19x13 ≥ 44
70x2 + 37x3 + 86x12 + 93x14 ≥ 0
90x1 + 82x3 + 66x5 + 26x10 ≥ 0
77x1 + 30x2 + 13x7 + 10x8 + 50x12 ≥ 0
72x2 + 79x6 + 11x12 + 90x13 ≥ 0
32x6 + 55x7 + 23x9 + 36x15 ≥ 119
xj ∈ [0, 1] forall j ∈ {1 . . . 15}
Note that the data matrices A, b, and c are generated using LPL’s own random
generator. (To generate each time the same data, the code can also use the
function SetRandomSeed(a) where a is an integer.) Note also that only
difference in the LPL formulation compared with the LP model is the word
binary added to the variable declaration.
Solution: The small model defined above has the following solution :
x= 0 0 0 0 0 1 1 1 0 0 0 0 1 1 1
obj = 255
Comparing the optimal solution of the three problems (1) examp-lp, (2) examp-
ip, and (3) this one, we have the following optimal values: 174.8096 for the LP,
201 for the IP and 255 for the 0-1-IP model.
Do the increasing optimal values for LP, IP and 0-1-IP make sense? Of course,
the IP model is “more” restricted, it only can have integer values, hence the
IP optimal value can never be smaller than the LP optimal value. The same is
true for the 0-1-IP optimum compared with the IP optimum.
One may take the bait to solve the 0-1-IP problem using the following proce-
dure :
Voilà! We can show with a tiny example (see willi155z), that this apparently
reasonable approach is completely erroneous: while the LP relaxation of this
tiny example has a feasible solution, the corresponding 0-1 problem is infea-
sible.
It seems difficult to derive the integer solution from the continuous LP prob-
lem. For a systematic procedure – called cutting plane method – that starts
with the continuous LP problem to find an integer solution of the 0-1-IP prob-
lem, see some explanation in the model example examp-ip01r.
For a short guide to 0-1 integer model formulation and how logical conditions
can be integrated into a mathematical model see the paper [68].
219 CHAPTER 6. VARIOUS MODEL TYPES
Problem: This model is the same as the model examp-ip01 with the important
difference that the variables are continuous and bounded by the interval [0..1].
Hence, this model is a LP program with continuous variable. It is called the
LP relaxation of the corresponding 0-1 integer program.
A compact formulation using matrix notation for the model is:
min c·x
subject to A · x ≥ b
0≤x≤1
With the same data as in model examp-ip01, we get the following model:
min 16x1 + 73x2 + 39x3 + 81x4 + 68x5 + 60x6 + 90x7 + 11x8 + 33x9
+89x10 + 71x11 + 12x12 + 24x13 + 23x14 + 47x15
subject to 87x1 + 34x2 + 43x5 + 52x7 + 85x8 + 36x9 ≥ 0
39x3 + 84x5 + 88x8 + 22x15 ≥ 0
55x1 + 63x2 + 79x3 + 71x8 + 70x13 + 79x15 ≥ 0
73x8 + 22x12 ≥ 0
66x4 + 34x7 + 24x10 + 61x12 + 64x15 ≥ 0
16x3 + 19x4 + 18x15 ≥ 0
15x1 + 70x2 + 61x3 ≥ 0
52x9 + 14x11 + 92x14 ≥ 58
30x8 + 98x11 + 19x13 ≥ 44
70x2 + 37x3 + 86x12 + 93x14 ≥ 0
90x1 + 82x3 + 66x5 + 26x10 ≥ 0
77x1 + 30x2 + 13x7 + 10x8 + 50x12 ≥ 0
72x2 + 79x6 + 11x12 + 90x13 ≥ 0
32x6 + 55x7 + 23x9 + 36x15 ≥ 119
0 ≤ xj ≤ 1 forall j ∈ {1 . . . 15}
Note that the data matrices A, b, and c are generated using LPL’s own random
generator. (To generate each time the same data, the code can also use the
function SetRandomSeed(a) where a is an integer.)
In the following listing, we compare the three solutions: (1) the LP relaxation,
(2) the rounded solution of the LP relaxation, and (3) the 0-1-IP solution. The
LP relaxation has the optimal solution of 201.5179, the rounded problem has
a solution of 181, which is far away from the true 0-1 solution which is 255.
The rounded solution has no merit for the true integer solution.
221 CHAPTER 6. VARIOUS MODEL TYPES
What can we say about that particular inequality? If x14 is zero then both x9
and x11 must be one. Why? Because if x14 = 0, then the inequality reduces to:
52x9 + 14x11 ≥ 58
However, this can only be the case if – in the 0-1 integer problem – both x9
and x11 are 1. Hence, we can add the two following inequalities to the LP
relaxation model:
Why? These two additional constraints do not violate the 0-1-IP solution: if
x14 = 1 then both inequalities are fulfilled, if x14 = 0 then both x9 and x11
CHAPTER 6. VARIOUS MODEL TYPES 222
must be 1. That is exactly what the initial inequality claims if the values must
be 0 or 1.
Now we solve the problem again without excluding a feasible solution of
the 0-1 IP problem. What is interesting now: After having added these two
constraints to the LP relaxation and solving it again, the optimal solution will
be 220.2321. It has increased considerably, and again we can say that this is a
lower bound for the 0-1 integer problem.
and we can repeat the same idea: If x11 = 0 then both x8 and x13 must be 1 in
the integer program. This gives rise to the additional inequalities:
Adding them too to the LP relaxation and solving the problem in R15 , gives a
optimal solution of 237.3750. That again rises the lower bound for the integer
program considerably.
Looking at the solution, the unique value that is not integer is x6 = 0.1563. In
the integer problem, x6 must be 0 or 1. So let try to set x6 = 0 and add this to
the previous problem. Solving the problem results in an infeasible problem.
Hence, there is no integer solution where x6 = 0. So let’s try x6 = 1 instead.
We add this inequality to the previous problem. The new optimal solution is
243.8182.
Again, in the new solution we see that x7 = 0.5091, the unique value that is
not integer. Hence, we try the same procedure again: setting first x7 = 0 and
solving produces also an infeasible solution, setting x7 = 1, gives an optimal
solution of 249.7778.
There is still one variable that is not integer: x15 = 0.8889. Adding x15 = 0
gives an infeasible solution, but setting x15 = 1 produces an integer solu-
tion with the optimum of 255. This is identical to the 0-1-IP problem and we
have found the optimal solution to the 0-1-IP problem by adding appropri-
ate inequalities (and equalities) to the LP relaxation. In our case, we added 4
inequalities and three equalities (by setting three variables to 1) (see the com-
mented lines --ADDED... in the LPL code).
the integer problem, until eventually we reach the optimal point of the integer
problem. (Unfortunately, it is normally not so easy to add valid inequalities.)
At least we have sketched an interesting idea on how to attack the solution of
integer problems, that has great practical importance. For a more systematic
approach to integer programming, see the interesting book [42]. See also two
other small example in this context: alterna and unimodular.
CHAPTER 6. VARIOUS MODEL TYPES 224
X X
min xj Qj,k xk + cj xj
X
j∈J,k∈J j∈J
subject to ai,j xj ≥ bi forall i ∈ I
j∈J
xj ≥ 0 forall j ∈ J
J = {1 . . . m}, I = {1 . . . n}, m, n ≥ 0
An more compact formulation using matrix notation for the model is as fol-
lows:
min xQx ′ + c · x
subject to A · x ≥ b
x≥0
The objective function f the constraints gi , and X (in the general format) are
as follows:
Note that the matrix Q must be semi-definite positive (SDP), (that is: there exist
a vector x such that xQx ′ ≥ 0). In many applications the matrix Q is also
symmetric (Q = QT ).
If the matrix Q is not semi-definite positive then it cannot be solved as a con-
vex problem and it must be considered as an non-linear problem.
In the following, a concrete problem with random data for the two matrices
A, Q and the two vectors b and c is specified (with n = 15 and m = 15):
c = 16 73 39 81 68 60 90 11 33 89 71 12 24 23 47
225 CHAPTER 6. VARIOUS MODEL TYPES
87 34 0 0 43 0 52 85 36 0 0 0 0 0 0 0
0 0 39 0 84 0 0 88 0 0 0 0 0 0 22 0
55 63 79 0 0 0 0 71 0 0 0 0 70 0 79 0
0 0 0 0 0 0 0 73 0 0 0 22 0 0 0 0
0 0 0 66 0 0 34 0 0 24 0 61 0 0 64 0
0 0 16 19 0 0 0 0 0 0 0 0 0 0 18 0
15 70 61 0 0 0 0 0 0 0 0 0 0 0 0 0
0
A= 0 0 0 0 0 0 0 52 0 14 0 0 92 0 58
b=
0 0 0 0 0 0 0 30 0 0 98 0 19 0 0 44
0 70 37 0 0 0 0 0 0 0 0 86 0 93 0 0
90 0 82 0 66 0 0 0 0 26 0 0 0 0 0 0
77 30 0 0 0 0 13 10 0 0 0 50 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 72 0 0 0 79 0 0 0 0 0 11 90 0 0 0
0 0 0 0 0 32 55 0 23 0 0 0 0 0 36 119
diag(Q) = 7 5 5 6 17 19 6 8 16 19 12 5 13 17 18
Note that this matrix Q consisting of positive diagonal entries and zero oth-
erwise is semidefinite positive.
The data given above specify the following explicit linear program:
Note that the data matrices A, b, c, and Q are generated using LPL’s own
random generator. (To generate each time the same data, the code can also
use the function SetRandomSeed(a) where a is an integer.)
Solution: The small model defined above has the following optimal solution:
x= 0 0 0 0 0 0.051 1.37 0.7 0.839 0 0.23 0 0 0.121 0.63
obj = 245.4168
Note that the constraints can also be quadratic, we then have a QPC model
where the Q matrix must be semi-definite positive:
227 CHAPTER 6. VARIOUS MODEL TYPES
X
min cj xj
X
j∈J X
subject to xj Qj,k xk + ai,j xj ≥ bi forall i ∈ I
j∈J,k∈J j∈J
xj ≥ 0 forall j ∈ J
J = {1 . . . m}, I = {1 . . . n}, m, n ≥ 0
CHAPTER 6. VARIOUS MODEL TYPES 228
X X
min xj Qj,k xk + cj xj
X
j∈J,k∈J j∈J
subject to Ai,j · xj ≥ bi forall i ∈ I
j∈J
xj ∈ {0, 1} forall j ∈ J
J = {1 . . . m}, I = {1 . . . n}, m, n ≥ 0
An even more compact formulation using matrix notation for the model is :
min x · Q · x′ + c · x
subject to A · x ≥ b
x ∈ {0, 1}
Solve this problem – x are unknowns, A, b, and c are given – with n = 15 and
m = 15 with the following data:
c = 16 73 39 81 68 60 90 11 33 89 71 12 24 23 47
87 34 0 0 43 0 52 85 36 0 0 0 0 0 0 0
0 0 39 0 84 0 0 88 0 0 0 0 0 0 22 0
55 63 79 0 0 0 0 71 0 0 0 0 70 0 79 0
0 0 0 0 0 0 0 73 0 0 0 22 0 0 0 0
0 0 0 66 0 0 34 0 0 24 0 61 0 0 64 0
0 0 16 19 0 0 0 0 0 0 0 0 0 0 18 0
15 70 61 0 0 0 0 0 0 0 0 0 0 0 0 0
A=
0 0 0 0 0 0 0 0 52 0 14 0 0 92 0 b=
58
0 0 0 0 0 0 0 30 0 0 98 0 19 0 0 44
0 70 37 0 0 0 0 0 0 0 0 86 0 93 0 0
90 0 82 0 66 0 0 0 0 26 0 0 0 0 0 0
77 30 0 0 0 0 13 10 0 0 0 50 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 72 0 0 0 79 0 0 0 0 0 11 90 0 0 0
0 0 0 0 0 32 55 0 23 0 0 0 0 0 36 119
229 CHAPTER 6. VARIOUS MODEL TYPES
diag(Q) = 7 5 5 6 17 19 6 8 16 19 12 5 13 17 18
The data given above specify the following explicit linear program:
obj = 336
Further Comments: Interesting applications for the iQP model come from
portfolio theory. Especially, if we want to limit the number of assets in a
portfolio we must use 0-1 variables. An applications come from clustering
problems. An example is bill035.
231 CHAPTER 6. VARIOUS MODEL TYPES
where xi and w are variables. These constraints are convex and they are au-
tomatically recognized and solved by Gurobi and Cplex, for example.
A small model example is given here.
where xi , v, and w are variables. These constraints are convex and they are
automatically recognized and solved by Gurobi and Cplex, for example.
A small model example is given here.
Problem: All models with quadratic constraints seen so far are convex: QP,
QPC, SOCP.
Models with only linear and quadratic terms which are non-convex are called
NQCP models in LPL. They are much harder to solve, but Gurobi has a way
to solve them (the parameter “nonconvex” must be set to 2).
A small example is this model from the Gurobi model library
Problem: Find the largest empty rectangle in a unit square filled with random
points, see Figure 6.2. This problem is from Erwin Kalvelagen, see also the
Blog of Hexaly.
Modeling Steps: Let us generate n points (xi , yi ) with i ∈ {1, . . . , n}, that are
uniformly distributed in a unit square. The unknown empty rectangle within
the unit square can be defined by two corner points (top/left – bottom/right)
(xa , ya ) and (xb , yb ). These are the variables of our problem.
3
Note that the two operators ∧ and ∨ are the Boolean operators “and” and “or”
235 CHAPTER 6. VARIOUS MODEL TYPES
The objective function defines the size of the empty rectangle (width × height)
and is a non-convex quadratic function. The first constraint requires that the
point (xa , ya ) is smaller than point (xb , yb ). The second constraint requires
that at least one of the four disjunctive terms must be true for each i. Note,
this model is a non-convex quadratic model. Recent versions of Gurobi and
Cplex allow to solve such problems.
Further Comments: If the problem is solved with Gurobi or Cplex, LPL trans-
lates the problem automatically to the following model :
CHAPTER 6. VARIOUS MODEL TYPES 236
Further Notes: In LPL, the second constraint could also be replaced by:
binary variable d1{i}; d2{i}; d3{i}; d4{i};
constraint
B1{i}: d1 -> x <= xa;
B2{i}: d2 -> y <= ya;
B3{i}: d3 -> x >= xb;
B4{i}: d4 -> y >= yb;
B5{i}: d1+d2+d3+d4 >= 1;
Still another formulation is the linearization as given above (this is also the
version to which LPL translates the model in order to solve it with Gurobi) :
binary variable d1{i}; d2{i}; d3{i}; d4{i};
constraint
D1{i}: xa >= x*d1;
D2{i}: ya >= y*d2;
237 CHAPTER 6. VARIOUS MODEL TYPES
Questions
Answers
Problem: Find the function y = f(x) of a hanging chain (of uniform density)
of length L suspended between the two points (xa , ya ) and (xb , yb ) where
(xa < xb and L > xb − xa ) with minimal potential energy. See [16] and [40].
In physics and geometry, the curve of an idealized hanging chain or cable
under its own weight when supported only at its ends is called a catenary.
Galileo mistakenly conjectured that the curve was a parabola. Later Bernoulli
and others proved that it is a hyperbolic cosine. Catenaries are used in a
variety of application: An inverse catenary is the ideal shape of a freestanding
arch of constant thickness. (See also in Wikipedia under “Catenary”.)
Z xb p
min y· 1 + y ′ 2 dx
Z
xa
xb p
subject to 1 + y ′ 2 dx = L
xa
Note that the mass m is proportionl to the arc length (since the chain has
uniform density), and the gravitational constant does not influence the form
of the function. So, it can be dropped. With this hints the model can be easily
constructed as follows:
-0.5
-1
-1.5
-2
-2.5
-3
-3.5
-4
-4.5
-5
Problem: “Consider a forest containing foxes and rabbits where the foxes eat
the rabbits for food. We want to examine whether the two species can survive
in the long-term. A forest is a very complex ecosystem. So to simplify the
model, we will use the following assumptions:
1. The only source of food for the foxes is rabbits and the only predator of
the rabbits is foxes.
2. Without rabbits present, foxes would die out.
3. Without foxes present, the population of rabbits would grow.
4. The presence of rabbits increases the rate at which the population of
foxes grows.
5. The presence of foxes decreases the rate at which the population of rab-
bits grows.”
(This problem is from [2] p. 132ff).
Now, The presence of the other specie either increases (the foxes) its popu-
lation by a rate of β, or decreases (the rabbits) its population by a rate of γ.
Therefore we have:
Given an initial population of F0 = 110 and R0 = 900, and the rates α = 0.12,
β = 0.0001, γ = −0.0003, and δ = 0.039, it is easy to calculate the population
at each time point using the simple LPL model :
Solution: With the rates given, the populations ocillate as can be seen in Fig-
ure 6.4 (Black the population of foxes, red the population of rabbits.)
2389
2150
1910
1671
1432
1193
953
714
475
236
-3
or
X
n−1
cπi ,πi+1 + cπn ,π1
i=1
(j is the next element of i in the permutation π, and the next to the last
is the first element in π). That is:
i+1 : i<n
j=
1 : i=n
X
n
min cπi−1 ,πi + cπn ,π1
i=2
subject to π ∈ Π
Note the syntax characteristic for this kind of models is, that (integer)
variable are used as indexes: πi is a variable. For example, π2 = 7
means that 7 is at the second position (from left to right) in the permu-
tation. And cπi ,πj is the distance value of ch,k where h = πi and k = πj .
This notation extension allows the modeler to formulated the problem
directly in the modeling language LPL:
This is a very compact formulation, but how is the problem solved? A model
in LPL consisting of only a permutation variable and an objective function is
identified by LPL as a special model type, called here as Simple Permutation
Problem (PERM). These problems are sent to an special solver integrated in
LPL which is based on an Tabu-Search metaheuristic method4 . A much more
powerful solver is the commercial Hexaly.
With the problem size n = 30, the Tabu-Search method normally finds the
optimal solution in a few seconds, which is 51.8052 in this case (see Figure
6.5).
4
The solver is quite primitive an its neighborhood structure is based on a 2-opt ex-
change. It was implemented only to demonstrate the feasibility of connecting LPL
to that kind of solver – also heuristics. For a deeper insight into Metaheuristics etc.
consult the Internet.
CHAPTER 6. VARIOUS MODEL TYPES 246
Length=51.8052
1
3
2
6 4
5
9
7
10 8
11
13
12
15
14
16
17
21 18
19
20
22
23
27 24
25
26 29
30
28
The first subsequence is {2, 3, 4}, the second is {1, 9, 8, 5}, etc. this is exactly
what is needed for the capacitated vehicle routing problem.
2 3 4 − − − − − − −
x = 1 9 8 5 − − − − − −
6 7 10 − − − − − − −
X
demxk,i ≤ CA forall k ∈ K
i|xk,i
We want to minimize the total travel distance of the trucks. Let cck be the
size of the subset k (the numbers of customers that the truck k visits). (In
the example above ck = {3, 4, 3}.) Of course, these numbers is variable and
cannot be given in advance! Let routeDistk be the (unknown) travel distance
of truck k, then we want to minimize the total distances:
X
min routeDistk
k
where5
X
routeDistk = dxk,i−1 ,xk,i +if(cck > 0, dwxk,1 +dwxk,cck forall k ∈ K
i∈2..cck
The term dwxk,1 denotes the distance of the truck k from the depot to the
first customer, and dwxk,cck is the distance of the truck tour k from the last
customer
P to the depot, dxk,i−1 ,xk,i is the distance from a customer to the next,
and i∈2..cck . . . sums that distances of a tour k.
As a variant we may also minimize, in a first round, the number of trucks
used – this is added as a comment in the code:
Further Comments: The question is now what solver can solve this kind of
model! I developed a simple Tabu-search solver that can deliver near optimal
solution for small simple permutation problems, but not for partitioned per-
mutation problems. However, there is a powerful commercial solver called
Hexaly that can find near optimal solutions to large problems. LPL contains
an (experimental) interface to that solver.
Solution: The LPL data code reads the “A-n32-k5.vrp” file from the Augerat
et al. Set A instances.
dem{i}:=de[i+1];
dw{i}:=Round(Sqrt((X[i+1]-X[1])^2+(Y[i+1]-Y[1])^2));
end
The Hexaly finds the optimal solution (see 6.6) after 25secs6
1820
3 32
5 4
12 24
29 22
9 14
7
19
10 8
23
2
17 13
27
15 31
25
16
30 28
11
6
21
26
6
Note that Hexaly is not simply a heuristic solver that finds hopefully near optimal
solution. It integrates apparently many lower-bound checks that can guarantee the
quality of the solution.
251 CHAPTER 6. VARIOUS MODEL TYPES
Modeling Steps: Given a set of items i ∈ I with a weight wi and a set of bins
k ∈ K with capacity CA (we suppose that wi ≤ CA for all i ∈ I), that is all
items can be packed in a bin. We need at most maxBins bins :
X
maxBins = min(|I|, wi /CA)
i
X
let bWk = wxk,i forall k ∈ K
i|xk,i ̸=0
let bUk = count xk,i > 0 forall k ∈ K
i
s.t. bW
X k <= CA forall k ∈ K
min bUk
k
set partition xk,i ∈ [1 . . . |I|] forall k ∈ K, i ∈ I
bWk is the (unknown) weight of a bin k. bUk is true (1) if the bin k is not
empty (it counts the items in a bin k and if there is at least 1 then it is true).
The unique constraint makes sure that the capacity of a bin is not exceeded,
and the objective function minimizes the number of bins used.
CHAPTER 6. VARIOUS MODEL TYPES 252
Example problems are TSP, LOP (linear ordering problem), QAP, etc.
If a single objective function is requested – without constraints (as in
253 CHAPTER 6. VARIOUS MODEL TYPES
the TSP) then the small problems can be solved with the internal Tabu-
Search solver of LPL.
2. A variant of the one-dimensional permutation is the subset variant:
alldiff variable x{i} 'notall';
This is the case for the exam-cvrp model: the set of locations defines a
permutation, which is partitioned into subtours. Note that the order in
the subsets (subtours) matters.
5. The variable is 2-dimensional with the additional attribute 'set patition'
means that the unique permutation is partitioned over the set k, but the
order of the items in the subsets does not matter.
alldiff x{k,i} 'set partition';
An example ist the bin-packing problem: the items to place into the bins
define a permutation, which is partitioned into the bins, but the order
within the bins does not matter.
6. The variable is 2-dimensional with the additional attribute 'cover'
means that the unique permutation is distributed over the set k, the
items in the permutation can be repeated in the different subsets.
alldiff x{k,i} 'cover';
CHAPTER 6. VARIOUS MODEL TYPES 254
lo · z ≤ x ≤ up · z
This model will be translated into the following model by LPL (the names
may be different):
model semi1 "Semi-continuous variable";
parameter lo:=5; up:=7;
CHAPTER 6. VARIOUS MODEL TYPES 256
variable x;
binary variable z;
constraint A: 5*z <= x <= 7*z;
solve;
end
This model will be translated into the following model in LPL (the names may
be different):
model semi1 "Semi-integer variable";
parameter lo:=5; up:=7;
integer variable x;
binary variable z;
constraint A: 5*z <= x <= 7*z;
solve;
end
257 CHAPTER 6. VARIOUS MODEL TYPES
x ∈ {2, 4, 6 . . . 8, 11}
zi ∈ {0, 1} i∈I
This model will be translated into the following model by LPL (the names
may be different):
CHAPTER 6. VARIOUS MODEL TYPES 258
7
Since a constraint expression can include Boolean operand and Boolean operator,
constraints with logical connectors are included in this definition
259 CHAPTER 6. VARIOUS MODEL TYPES
If the variables are real (or integer) then an additional binary variable yi has
to be introduced together with the constraints (where upi is an upper bound
on the variable xi ) :
X
yi ≤ 1
i
xi ≤ upi · yi forall i ∈ I
In LPL, we can use the function Sos1 to specify a SOS1 constraint. For exam-
ple, to specify that v = 0 or w = 0 (at most one can be non-zero) we write:
constraint C: Sos1(v,w)
To specify that only in a indexed list of variable must be non-zero, one speci-
fies:
constraint D: Sos1( {i} x[i] );
Note only Gurobi understands this syntax, otherwise the explicit formulation
must be used as follows:
model sos1;
set i:=1..10;
parameter up:=10.2;
variable x{i} [0..up];
binary variable y{i};
constraint A: sum{i} y <= 1;
constraint B{i}: x <= up*y;
maximize obj: sum{i} i*x;
Writep(obj,x);
end
In LPL, we can use the function Sos2 to specify a SOS2 constraint. For ex-
ample, to specify that only in a indexed list of variable must be non-zero, one
specifies:
constraint D: Sos2( {i} x[i] );
Note only Gurobi (and Cplex) understand this syntax from LPL, otherwise
the explicit formulation must be used as follows:
model sos2;
set i,j:=1..10;
parameter up:=10.2;
variable x{i} [0..up];
binary y{i};
constraint B: sum{i} y <= 2;
constraint C{i}: x <= up*y;
constraint D{i,j| j>=i+2}: y[i] + y[j] <= 1;
maximize obj: sum{i} i*x;
Writep(obj,x);
end
A more general version can also be implemented in LPL, where the two scalar
variables can be replaced by arbitrary expressions. LPL reformualtes this ver-
sion. Hence, for example, the constraint
constraint A1: Complements(2*x-1,4*y-1);
Note that Gurobi can solve these constraints if the expressions within the com-
plementarity are linear or quadratic, otherwise a non-linear solver (such as
Knitro) will do the job.
languages, and also to improve the constraint resolution. Many of the global
constraints are referenced into an The Online Catalog, a catalog that presents
a list of 423 global constraints.
Actually, LPL implements only a few to illustrate the use and the power in
modeling. Depending on the solver used, these constraint must be trans-
formed.
When using a MIP solver, LPL transforms both versions into linear constraints.
There are several methods:
The first method (used by LPL) is as follows :
1. Add the binary variables: yi,j with i, j ∈ I.
2. Add the constraints:
Note the second method can be extended. The case xi ∈ {1, . . . , n} where
i ∈ {1, . . . , n} is a very special case of the more general problem where xi ∈
{a1 , . . . , an } with ai+1 > ai . This problem can be handled by the constraints:
X
yi,j = 1 forall i ∈ I
X
j
yi,j = 1 forall j ∈ I
i X
xi = aj yi,j forall i ∈ I
j
X
yi,j ≤ 1 forall i ∈ I
X
j
yi,j = 1 forall j ∈ I
i X
xi = aj yi,j forall i ∈ I
j
6.20.2 Element
The element constraint requires that the (unknown) x-th entry of a data vector
ci with i ∈ {1, . . . , k} is exactly v.
Element(x, ci|i∈{1,...,k} , v)
CHAPTER 6. VARIOUS MODEL TYPES 264
v = cx
X
v= ci yi
i
yi ↔ (xi = i) forall i ∈ I
yi ∈ {0, 1} forall i ∈ I
6.20.3 Occurrence
Occurrence(xi|i∈{1,...,k} , v, m, n)
X
m≤ (xi = v) ≤ n
i
Note that the term (xi = v) is a Boolean expression that returns 0 or 1, and
hence, the sum counts the number of occurrences that xi is exactly v. This
number must be between m and n.
For example, let x be a variable vector of 10 elements (xi with i ∈ {1, . . . , 10}),
and let v = 30 and m = 3, n = 5. Then the constraint is fulfilled if x =
(1, 2, 5, 4, 30, 7, 30, 6, 30, 8) because the value 30 occurs 3 times.
In LPL, the constraint is not yet explicitly implemented. It can be formulated
in the mathematical way as follows:
constraint A: m <= sum{i} (x[i] = v) <= n ;
265 CHAPTER 6. VARIOUS MODEL TYPES
When calling a MIP solver, then LPL automatically translates this into linear
constraints. In the following real models this constraint is used: model Kalis
and model car2. In both models, the special case where m = n is used, which
reduces the formulation into
6.20.4 Sequence_total
Sequence_total(xi|i∈{1,...,k} , v, m, n, s)
X
m≤ (xi = v) ≤ n forall i ∈ {1, . . . , k − s + 1}
h|i≤h≤i+s−1
Note that the term (xi = v) is a Boolean expression that returns 0 or 1, and
hence, the sum counts the number of occurrences that xi is exactly v. This
number must be between m and n.
For example, let x be a variable vector of 10 elements (xi with i ∈ {1, . . . , 10}),
and let v = 30 and m = 1, n = 2, s = 4. Then the constraint is fulfilled
if x = (1, 30, 5, 4, 30, 7, 30, 6, 30, 8) because the value 30 occurs in each sub-
sequence of 4 elements 1 or 2 times.
When calling a MIP solver, then LPL automatically translates this into linear
constraints. The constraint is used in the following real model of “car assem-
bly line sequence”, see car2.
CHAPTER 6. VARIOUS MODEL TYPES 266
6.21. Conclusion
This paper gave a limited overview of some model classes. It shows a uni-
fied implementation into the LPL modeling language. LPL can analyze the
model and selects automatically the right solver, based on a classification, to
solve it. The actual LPL language is far from complete, it is thought as a re-
search vision to formulate all kind of models in a unified modeling language.
That language should also contain most concepts of a modern programming
language – which LPL doesn’t right now.
As said, LPL is a small subset of that unified modeling language, but a special
model class, namely large linear MIP models, are efficiently formulated and
are used in a commercial context.
C HAPTER 7
D ATACUBES AND
P IVOT-TABLES
267
CHAPTER 7. DATACUBES AND PIVOT-TABLES 268
Spreadsheet Poem:
You may spreadsheet in columns
You may spreadsheet in rows
But the more you spreadsheet
The faster it grows.
7.1. Introduction
Data is an increasing value resource in many contexts, for example, in a com-
pany to schedule and monitor effectively the company’s activities. Hence, a
data manipulation system must collect and classify the data, by means of in-
tegrated and suitable procedures, in order to produce in time and at the right
levels the synthesis to be used to support the decisional process, as well as
to administrate and globally control the company’s activity. While databases
269 CHAPTER 7. DATACUBES AND PIVOT-TABLES
are the place where data are collected, data warehouses are systems that clas-
sify the data. According to William Inmon, widely considered the father of
the modern data warehouse, a Data Warehouse is a “ Subject-Oriented, In-
tegrated, Time-Variant, Non-volatile collection of data in support of decision
makin”. Data Warehouses tend to have these distinguishing features: (1) Use
a subject oriented dimensional data model; (2) Contain publishable data from
potentially multiple sources and; (3) Contain integrated reporting tools.
OLAP (On-Line Analytical Processing) is a key component of data warehous-
ing, and OLAP Services provides essential functionality for a wide array of
applications ranging from reporting to advanced decision support. Accord-
ing to [www.olapcouncil.org] OLAP “... is a category of software technol-
ogy that enables analysts, managers and executives to gain insight into data
through fast, consistent, interactive access to a wide variety of possible views
of information that has been transformed from raw data to reflect the real
dimensionality of the enterprise as understood by the user. OLAP function-
ality is characterized by dynamic multidimensional analysis of consolidated
enterprise data supporting end user analytical and navigational activities in-
cluding calculations and modeling applied across dimensions, through hier-
archies and/or across members, trend analysis over sequential time periods,
slicing subsets for on-screen viewing, drilldown to deeper levels of consolida-
tion, rotation to new dimensional comparisons in the viewing area etc.”. The
focus of OLAP tools is to provide multidimensional analysis to the underly-
ing information. To achieve this goal, these tools employ multidimensional
models for the storage and presentation of data. Data are organized in cubes
(or hypercubes), which are defined over a multidimensional space, consist-
ing of several dimensions. Each dimension comprises of a set of aggregation
levels. Typical OLAP operations include the aggregation or deaggregation
of information (roll-up and drill-down) along a dimension, the selection of
specific parts of a cube (dicing) and the reorientation of the multidimensional
view of the data on the screen (pivoting).
OLAP functionality is characterized by dynamic multi-dimensional analysis
of consolidated enterprise data supporting end user analytical and naviga-
tional activities including:
Two main approaches to support OLAP are (1) ROLAP architecture (Rela-
CHAPTER 7. DATACUBES AND PIVOT-TABLES 270
The MOLAP architecture is basically cube-oriented. This does not mean that
they are far from the relational paradigm in fact all of them have mappings
to it but rather that their main entities are cubes and dimensions. In prac-
tice, the cube’s data are extracted from databases using standard SQL queries
and stored in “cubes”, which beside the data extracted contain pre-calculated
data in order to speed up the viewing. One of the big advantage of the cube-
oriented approach is its intuitive use of generating a multitude of various
“views” of the data; another advantage is speed: Having the data in a cube, it
easier to reorganize the data than in ROLAP.
A dimension is a structural attribute of the cube, that is, a list of members all
of which are of a similar type in the user’s perception of the data. For exam-
ple, all months, quarters, years, etc., make up a time dimension; likewise all
cities, regions, countries, etc., make up a geography dimension. A dimension
acts as an index for identifying values within a multi-dimensional array. If
one member of the dimension is selected, then the remaining dimensions in
which a range of members (or all members) are selected define a sub-cube.
If all but two dimensions have a single member selected, the remaining two
dimensions define a spreadsheet (or a "slice" or a "page"). If all dimensions
have a single member selected, then a single cell is defined. A cell can also be
identified as a single tuple of the datacube. Dimensions offer a very concise,
intuitive way of organizing and selecting data for retrieval, exploration and
analysis. A member is a discrete name or identifier used to identify a data
item’s position and description within a dimension. For example, January,
1989 or 1Qtr93 are typical examples of members of a time dimension. Whole-
sale, Retail, etc., are typical examples of members of a distribution channel
dimension.
As an example see the Figure 7.1.
It represents a 3-dimensional cube
with three dimensions time, region,
and product. The measurement
is Sale. The members of time
are {1996, 1997, 1998}, the members
of region are {CEE, USA}, and the
members of product are {P1, P2, P3}.
The cell (1997, CEE, P2) contains the Figure 7.1: A 3-dimensional cube
value 500. The interpretation is that
500 units of the product P2 has been sold in 1997 in CEE. The cube contains
3 × 3 × 2 = 18 cells.
A member combination is an exact description of a unique cell in the datacube
which contains a single value (the measurement). A datacube can also be seen
as a multi-dimensional array. A cell – a unique tuple – can be seen as a sin-
gle data point that occurs at the intersection defined by selecting one member
from each dimension in a multi-dimensional array. The maximal number of
cells is given by the cardinalities of the dimensions as: |D1 | · |D2 | · . . . · |Dn |.
The tuple-set is also called the Cartesian Product of the dimensions. A dat-
acube can be dense or sparse. It is called dense if a relatively high percentage
of the possible combinations of its dimension members contain data values,
otherwise it is called sparse. It is important to see, that very sparse datacubes
are very common in practice.
From a database point of view, an n-dimensional datacube is typically stored
as a database table containing n+1 fields, the first n fields representing the di-
mensions and the (n+1)-th field represents the measurement (the data value).
The first n fields are typically (but not necessary) foreign keys pointing to a
CHAPTER 7. DATACUBES AND PIVOT-TABLES 272
table filled with basis “identifier” lists. It is important to note that a table is
a more general concept than a datacube: (1) The same tuple of members in a
datacube – defining a cell – can occur only once in a datacube, while it can oc-
cur several times in a database table, except when a primary key is defined on
the “dimensional” fields. In praxis, however, this is not a limitation, because
we mostly analyze data which can be classified according some dimensions
and hence have distinct tuples. (2) A database table – besides the "dimen-
sional" fields – can contain several “measurements” fields. If this is the case,
then several datacubes with the same dimensions can be built, or a datacube
with an additional dimension, which contains a “measurement” field name
as members, if the measurements are all of the same data type (numeric, al-
phanumeric, etc.). If this is not the case the db table can be mapped to a set of
datacubes.
We call the list of tuples defining a datacube – normally printed in a vertical
way – on a piece of paper, the standard view or the db-view of the datacube. As
we shall see, this is nothing else than a particular pivot table view.
In a mathematical notation, a cube can be represented as follows:
i1 , i2 , . . . , in are called indexes, and the notation is called the indexed nota-
tion (see [67]).
7.3.1 Slicing
right part selects a slice of 1-dimensional cube by fixing the member 3 of di-
mension 1 and the member 1 of dimension 3. In both cases, the dimension is
reduced and the result is another datacube of lower dimension.
In fact, the operation “slicing on
more than one dimensions” can be
reduced to a sequence of “slicing on
a single dimension”. The operation
is commutative and associative on
the dimensions, meaning that the or-
der which it is applied to the “fixed”
dimensions does not matter. “Slic-
ing on a single dimension” reduced
the dimension by one. Hence, ap-
Figure 7.2: Slicing a Cube
plying this sliding operation to an n-
dimensional cube, generates a (n −
1)-dimensional cube. One can apply this operation at most n times succes-
sively to get a 0-dimensional cube, say a single cell of the original datacube.
In the mathematical notation, slicing is to generate a sub-cube as follows. As
an example, let’s start with a 3-dimensional cube ai,j,k with i ∈ I, j ∈ J, k ∈ K
and I = {i1 , i2 , . . . , im }, J = {j1 , j2 , . . . , jn }, and K = {k1 , k2 , . . . , kp }. Let’s fix
the member k2 ∈ K. The result is a cube of dimension 2, say bi,j .
bi,j ← ai,j,k2
means that for each (i, j) ∈ I × J tuple in the cube ai,j,k , the value of the cell
is copied (or mapped) to the corresponding cell in bi,j . It is in fact a matrix-
assignment. Fixing two members in the different dimensions I and K generates
a 1-dimensional cube, say cj :
The operation ← means that for each (i, j)-combination in the cube a, the
value of the cell is copied to the corresponding cell in b. It is in fact matrix-
assignment.
7.3.2 Dicing
A shorter notation is :
di,j,k|P ← ai,j,k
7.3.3 Sizing
Sizing (it may be called also up-sizing) a n-dimensional datacube means to add
tuples which contains members in a particular dimension that were not part
of that dimension. The dimensions are extended: elements are added to one
or more dimensions.
The consequence is an extension of the datacube in one or several dimensions.
This operation does not change the dimension of the resulting cube – just
its size in one or several dimension is changed (see Figure 7.4. A particular
operation is when only one dimension is extended. Then this operation can
also be seen as “merging” a n-dimensional datacube with a (n − 1)-datacube
in which the n − 1 dimensions occur in both cubes. It is “adding a slice” to
the cube.
275 CHAPTER 7. DATACUBES AND PIVOT-TABLES
ai,j,k if j ∈ J
fi,j,k ←
bi,k if j = ′ jn+1 ′
X
bi,k ← ai,j,k forall i ∈ I, k ∈ K
j∈J
′ X ′′ X
bi,j ← ai,j,k forall i ∈ I, j ∈ J bj,k ← ai,j,k forall j ∈ J, k ∈ K
k∈K i∈I
′ X ′′ X ′′′ X
ci ← ai,j,k cj ← ai,j,k ck ← ai,j,k
j,k i,k i,j
X
d← ai,j,k
i,j,k
CHAPTER 7. DATACUBES AND PIVOT-TABLES 276
7.3.4 Rising
datacubes having the same number of dimensions and having the same di-
mensions can be merged together. Figure 7.8 displays an example.
This case is especially interesting for com-
parative studies of two or several datacubes,
comparing scenarios and outcoming of the
same datacube. In LPL this is implemented
as Multiple Snapshot Analysis. Rising im-
plies to introduce an additional dimension
into the resulting datacube. LPL automati-
cally adds a set called _SNAP_. Hence the Figure 7.8: Rising Identical
resulting datacube has then n + 1. dimen- Cubes
sions.
(2) The second important application arises when the actual cube has to be
partitioned into several groups, for example, along a time dimension, the
months, one has to group the dimension along quarters; or along a product
dimension, one has to group them into various product categories, etc (see
Figure 7.9).
The original cube is partitioned into the de-
sired parts and build from each part a com-
plete datacube of the original size – by get-
ting eventually a very sparse cube. Then
these cubes are risen by “merging” them
along a new dimension, which implements
the partition, see Figure 7.10.
Figure 7.9: Rising Cubes
The idea behind this partition of a cube is
by Extending
that certain dimensions can be structured
into hierarchies (Year – Month – Week – Day,
and Merging
Continent – Country – Region – State). The Dimensions
partition can be arbitrarily however, it can
be even on several dimensions, that is, cer-
tain tuples of the cube may belong to one part and other tuples to another
part. The two most important applications of this operation are grouping and
hierarchy building in OLAP tool and grouping and subgrouping in reports.
sort it along one dimension (dimensional sorting), to get the 5 closest neigh-
bors of each location. This may be interesting in a heuristic to find a good TSP
tour.
DRILL DOWN/UP
“Drilling down or
up is a specific an-
alytical technique whereby
the user navigates
among levels of data
ranging from the most
summarized (up) to
the most detailed (down).
The drilling paths
may be defined by Figure 7.11: Roll-Op/Drill-Down Operations
the hierarchies within
dimensions or other
relationships that may be dynamic within or between dimensions. For ex-
ample, when viewing sales data for North America, a drill-down operation in
the Region dimension would then display Canada, the eastern United States
and the Western United States. A further drill- down on Canada might dis-
play Toronto, Vancouver, Montreal, etc.”
The Drill-Down means slicing a cube along the hierarchies defined before by
a rolling-up process.
MULTI-DIMENSIONAL ANALYSIS
“The objective of multi-dimensional analysis is for end users to gain insight
into the meaning contained in databases. The multi-dimensional approach
to analysis aligns the data content with the analyst’s mental model, hence re-
ducing confusion and lowering the incidence of erroneous interpretations. It
also eases navigating the database, screening for a particular subset of data,
asking for the data in a particular orientation and defining analytical calcula-
tions. Furthermore, because the data is physically stored in a multi- dimen-
sional structure, the speed of these operations is many times faster and more
consistent than is possible in other database structures. This combination of
simplicity and speed is one of the key benefits of multi-dimensional analysis.”
Multi-dimensional analysis is nothing else than cube manipulation!
CALCULATED MEMBER
“A calculated member is a member of a dimension whose value is determined
from other members’ values (e.g., by application of a mathematical or logical
operation). Calculated members may be part of the OLAP server database or
may have been specified by the user during an interactive session. A calcu-
lated member is any member that is not an input member.”
CHAPTER 7. DATACUBES AND PIVOT-TABLES 280
By rising a cube, one can add member to a dimensions the cells of which are
calculated. The aggregates are typical such calculated cells.
NAVIGATION
“Navigation is a term used to describe the processes employed by users to
explore a cube interactively by drilling, rotating and screening, usually using
a graphical OLAP client connected to an OLAP server.”
See implementation of pivot-tables in LPL.
The column/row labels will display the extra dimensionality of the output by
nesting the labels describing the members of each dimension. For example,
the display’s columns may be as seen in Figure 7.12. These columns contain
three dimensions, nested in the user’s preferred arrangement.”
“Likewise, a report’s rows may contain nested dimensions”, see Figure 7.13.
This was consistently implemented into the modeling environment of LPL
(lplw.exe).
Product across and Time down. An example of the second case would be
to change a report which has Measures and Products down and Time across
into a report with Measures down and Time over Products across. An exam-
ple of the third case would be taking a report that has Time across and Prod-
uct down and changing it into a report that has Time across and Geography
down.”
PAGE DIMENSION
“A page dimension is generally used to describe a dimension which is not
one of the two dimensions of the page being displayed, but for which a mem-
ber has been selected to define the specific page requested for display. All
page dimensions must have a specific member chosen in order to define the
appropriate page for display.”
See: “take out/in” operator in the next section.
SELECTION
“A selection is a process whereby a criterion is evaluated against the data or
members of a dimension in order to restrict the set of data retrieved. Exam-
ples of selections include the top ten salespersons by revenue, data from the
east region only and all products with margins greater than 20 percent.” See:
dicing
The aggregated cubes can be viewed by “taking out” one or several dimen-
sions from
P the original cube.
P So Figure 7.16 represents the aggregated cubes
bj,k = i ai,j,k and ci,k = j ai,j,k . The aggregate operator was SUM.
Furthermore, ordering can be taken into account. Each cell in the datacube is
determined by the tuple of its members. Hence, the order in which the tu-
ples are given does not matter. However, one could exploit this freedom to
impose a specified order on each dimension’s member list. The order than
imposed the sequence in which the cells are listed in a particular pivot-table.
Any permutation order on the members on each dimension gives a particu-
lar pivot-table. The ordering is easy to specify: Given an initial order of the
members, one only need to attach a permutation vector to each dimension.
Another operation in showing a cube as a particular pivot-table is selection.
One can dice a cube first and then display the diced cube as a pivot-table.
Another way to view this is to attach a Boolean on each member, and set its
value to TRUE if the particular member should be displayed in the pivot-table
and FALSE else wise. Hence, each dimension needs a boolean vector of the
size of the dimension to specify a selection.
The augmented cube can also be integrated easily into the pivot-table pre-
sentations. In the terminology we used earlier, we first size the cube with its
aggregates and then show the sized cube as a pivot-table. Another way again
is to integrate this information into the displaying operations: given a cube,
we add (1) a permutation, (2) define a h and k and an (3) an aggregate-op.
Normally however, there is no need to compute all aggregated cubes in order
to display them in a particular pivot-table. Let’s explain this in the example
of a 2-dimensional and then of a 3-dimensional cube.
Figure 7.17 shows a cube of dimension 2 on the left side a pivot-table with
h = 1. All three aggregated cubes (a*, *b, **) are visible and attached as last
row and last column. All aggregated cubes are needed (ab, a*, *b, and **), see
Figure 7.18. The middle pivot-table with h = 0 displays also all aggregates.
However, one could argue that in the last four rows only the last is needed
(the total of all totals), hence, the aggregated cube *b is not needed. A more
“natural way” to display the pivot-table would be the picture on the right.
For a 3-dimensional cube with h=0 only the aggregates abc, ab*, a**, *** (see
Figure 7.18) are needed, with h = 1, we need abc, ab*, a**, ***, and a*b, **c.
The rule is the following: We need all aggregates along maximally two paths
from abc to *** in the lattice. It is easy to find them. If we have a 5-dimensional
cube, for example, with the dimensions abcde (the top node of the lattice) then
the dimensions are partitioned into the vertically and horizontally displayed
dimensions for a particular pivot-table (say h = 2, then we have abc|de). The
two aggregates needed – following the paths in the lattice – are : ab*|de and
abc|d*. Hence, following the path in which the stars (*) are filled from right
CHAPTER 7. DATACUBES AND PIVOT-TABLES 286
to left beginning with the very last entry and beginning with the entry left
to |. Following the path down to ***** this way, generates to paths and the
corresponding aggregates to calculate and integrate into the pivot-table are
given by collecting them in the two paths. Now we also see, why in the cases
of h = 0 (all vertically) and h = n − k (all horizontally displayed) a single
path is needed only. It is easy to see, why this works in general.
Formatting: A pivot-table is – first of all – a 2-dimensional representation of a
datacube. The parts of the tables can be thought to be “printed” in rows and
columns, in vertically/horizontally arranged cells as shown in Figure 7.19
287 CHAPTER 7. DATACUBES AND PIVOT-TABLES
where the parts are just displayed in the grid without formatting.
However, not all cells in the grid have the same meaning. While some “cells”
in the pivot-table display the name of the dimensions, others display the
data. Basically, a pivot-table can be partitioned into 4 sections: (1) a header,
where the dimensions are displayed, (2) the member names of the dimen-
sions to identify a row and a column (3) the aggregates which are "SUM"
rows/columns, and (4) the data part. The formatting of these sections is in-
dependent from the layout and we are free to enforce visually by colors and
other attributes the different sections. An example is shown in Figure 7.20.
Different formatting could be chosen.
Another kind of formatting is data formatting: (1) the data can be formatted
CHAPTER 7. DATACUBES AND PIVOT-TABLES 288
along a mask like ##.### (with three decimals, if they are numbers), (2) cer-
tain data can be shown in a different color (for example if they are negative),
(3) The data can be shown as percent of a total, or as difference from a given
value, etc.
The spreadsheet software Excel offers the functionality of pivot-tables. But it
is a somewhat neglected tool and have serious disadvantages: : (1) The table is
a one-way construct, one cannot change any data, (2) certain formats get lost
if the table is manipulated by pivoting, (3) it takes quite a time to understand,
what you can do, many operations can be done by mans different ways
In the LPL modeling system pivot table manipulation are fully integrated and
easy to handle (see user manual of LPL). The LPL modeling system is de-
signed to define and manipulate datacubes. The dimensions must be modeled
as SETs and a datacube then is a multi-indexed entity in LPL. For example, to
define a 3-dimensional cube one needs the declaration of four entities: 3 SETs,
representing the dimensions and a parameter (or a variable, or whatever
is indexed).
set i:=[i1 i2]; j:=[j1 j2 j3]; k:=[k1 k2 k3 k4];
parameter a{i,j,k} := i*j*k;
Dicing:
parameter c{i,j,k|a>=10} := a[i,j,k];
Sizing:
set h:=[1 i2 i3];
parameter d{h,j,k|a>=10} := if(h in i, a[h,j,k], sum{i}
a[h,j,k];
Rising:
set i:=[1..3]; j:=[a b c]; k:=[1 2 3 a b c]; m:=[1..2];
parameter a{i}:=i; b{j}:=10*j;
c{k}:=if(k<=#i,a[k],b[k-#i]);
d{m,i}:=if(m=1,a[i],b[i]);
1. a datacube
2. a permutation of the dimensions , h , k, aggregate operator
3. a order for the members of each dimensions
4. a Boolean for each member indicating of selecting it or not
5. Formatting: (1) of the cell: mask, alignment, font, border, pattern, (2)
of the value: as percent, as difference etc., (3) depend on an expression
(p.e., negative number with another color).
7.6. Spreadsheets
Spreadsheet modeling represents one of the most successful and widespread
applications of present desktop computers. Since their introduction in the late
1970s, spreadsheet programs transformed the way of end-user computing. It
created a new paradigm that offers a unique combination of ease of use and
unprecedented modeling and calculation power, accessible to every user. As a
result, spreadsheet programs became the most widely used decision support
tool in modern business. Today’s spreadsheet programs are very powerful,
versatile, and user friendly. Yet in spite of this technological progress, the
basic ideas for building a spreadsheet model remained the same in the last
25 years. Let us briefly explain what these basic ideas are and where they
came from. “Spread sheets” have been used by accountants for hundreds of
years [12], [58]. The history of accounting and bookkeeping is intrinsically
linked to the history of calculation. It is, therefore, not surprising that the first
published book on double-entry-accounting (Luca Pacioli’s famous Summa de
Arithmetica, geometria, proportioni et proportionalita, at 1494) appeared in a
book of mathematics. In the realm of accounting, a “spread sheet” was and
is a large sheet of paper with columns and rows that organizes data about
transactions for a business person to examine. It spreads all of the costs, in-
come, taxes, and other related data on a single sheet of paper for a manager
to examine when making a decision. However, according to [58], until the
19-th century accounting was pure “arithmetics”. Only at that time “alge-
braic” considerations entered the picture in accounting in the form of simple
equations such as “Assets = Liabilities + Owner’s Equity”, compound interest
rate calculations or present value considerations. The present value approach
in accounting, for instance, played an important role in the German Railway
Statutes of 1863 and subsequent legislations.
Spreadsheets are great for small models, although they are used frequently
today for complex models with dubious success. The number of papers re-
porting and analyzing “errors” in spreadsheets is large. As soon as the model
becomes complex the disadvantages of using traditional spreadsheets become
evident. Since all calculation is cell-oriented, formulas must be copied again
and again, revising and rearranging the layout turn out to be a nightmare,
CHAPTER 7. DATACUBES AND PIVOT-TABLES 290
adding a new “item” having the same pattern as the already entered once is
error-prune. The logic and structure behind the model get lost or invisible. It
became evident already at the beginning of the 1990’s that tools are needed
to separate the different concepts: structure and logic, data and presentation.
“In many ways, the present state of spreadsheet modeling is reminiscent of
the state of data management prior to the ’database era.’ Before data defi-
nition was elevated to the DBMS level, file structures were a fixed part of a
program’s code. In a similar vein, the logic and documentation of spreadsheet
models are often ’buried in the formulae,’ and are largely inaccessible to peo-
ple other than the spreadsheets’ creators. In both cases, the implications are
similar: redundant and inconsistent file and model structures, respectively.
To complete the analogy, these problems arise because spreadsheet programs
lack a high-leuel means to support the design and maintenance of spreadsheet
models.” [34].
In 1991, Lotus – then the leader of spreadsheet technology with its Lotus 1-
2-3 – shipped a new product: Improv. Its inventor was Pito Salas, who can
be called the father of pivot-table. The concepts of Lotus Improv revolved
around the concept of separating the three parts: data, views, and formulas.
The data are described in terms of categories such as “Territory”, “Month”,
or “Product” and items of those categories such as “Europe”, “January” or
“Leather Gloves”. The data can easily be reorganized. Categories are listed
on tiles that you simply drag and drop to rearrange your data. Just pick up
a category tile and move it to another axis, or rearrange it with respect to
the tiles currently on its axis. Because data is associated with categories and
items, rearranging the data has no effect on the validity of formulas. Multi-
dimensional data – not just 2-dimensional once – can easily be set up. For-
mulas are written and stored in a separate formula area, which can be viewed
simultaneously with the spreadsheet itself. Formulas are written in plain En-
glish, making it easier to read and write them. Improv was shipped in 1991
with the new NeXT computer, it was very popular and was one of the killer
application on that computer. Unfortunately, Lotus did not port Improv to
Windows until 1993. The main reason was that they did not want it to com-
pete directly with their cash-cow: 1-2-3. In the meantime, however, the users
already turned away from Lotus 1-2-3 to buy the product Excel. One reason
between others was that Lotus put all its effort to the newest version of 1-2-
3, which was delayed by more than one year and they did only half-hearted
develop Improv. Lotus took Improv from the market. As the inventor of Im-
prov sees it in retro-perspective, is “...that the key strategy mistake was to try
to market Improv to the existing spreadsheet market. Instead, if the product
were marketed to a segment where the more structured model was a ’feature’
not a ’bug’ would have given Lotus the time to learn and improve and refine
the model to a point where it would have satisfied the larger market as well.”
[Pito Salas at November 28, 2004]. Improv was more a product in the realm of
OLAP, a market that just had emerged at that time. It seems “that the OLAP
vendors of the time, the likes of Comshare, Holos and IRI were worried about
291 CHAPTER 7. DATACUBES AND PIVOT-TABLES
Improv as it had much the same functionality as product such as Holos and
Express but with the backing of Lotus, who at the time were number one in
the spreadsheet market with 1-2-3. In the end though, Lotus marketed Improv
more as ’spreadsheets done right’ (referring to the separation of data and for-
mulas, and the more rigid structure of an Improv model) rather than its OLAP
capabilities, which unfortunately had the effect of confusing those customers
who now had to choose between 1-2-3 and Improv, and chose Microsoft Ex-
cel instead.” [Rittman Mark, March 3, 2006]. So, it seems that Improv has
failed due to its marketing debacle and less due to its “complexity”. It is un-
deniable that creating a model with Improv requires some preparation and a
structured and conceptual approach. However, it is also true that this greatly
outweights the chaotic and “any-thing-goes” of today’s spreadsheet building
by producing a cleaner and more error-free model.
In any case, the story does not end here. Various attempts have been made to
reanimate the ideas of Improv. FlexSheet, for instance, is a free software that
implements a subset of Improv. In 2004, a company called Quantrix, has mar-
keted its flagship software Quantrix Modeler, a real superset of Improv and
more. Interestingly enough, the inventors of Quantrix Modeler, Peter Murray
and Chris Houle, do not see their product as a direct competitor of traditional
spreadsheet programs. Quantrix Modeler has even an export function to Ex-
cel! However, they analyzed very carefully the deficiencies of the traditional
spreadsheet technology [50]:
The results are flawed models. This is alarming especially in financial con-
text where a lot of money may be involved.1 It also results in lack of au-
ditability, in dependencies from its author, in lack of portability and extensi-
bility. One of the main functions of modeling is insight. This is largely absent.
Since the logic and structure is mixed with the data and the formatted lay-
out, the structure of the model cannot be separated and inspected on its own.
Precisely what is the power of mathematics – insight – is made hidden and
intransparent in the spreadsheet, because basically spreadsheets are “arith-
metic” not “algebraic”. So many scenarios are not calculated because it is too
time-consuming to do it! However, the reality is that business professionals
must create increasingly complex models for their decision making processes
and their software is based on 25 year old innovations which mapped the
paper-ledger into software! There exists an increasing need for better tools.
1
“A slip of the hand in a computer spreadsheet for bidding on electricity transmis-
sion contracts in New York will cost TransAlta Corp. $24-million (U.S.), wiping
out 10 per cent of the company’s profit this year.” ... “A spreadsheet created in 3-
months, full-time work by a highly-paid professional has a cost-accounting value
in excess of $25,000.” [?].
293 CHAPTER 7. DATACUBES AND PIVOT-TABLES
Still!
7.7. Conclusion
Data Viewing is an important subject whenever mass of data is involved in
modeling. For this we use reporting, data browsing tools and data editing tools.
When uniformed data are stored along several dimensions, then we may pack
them into datacubes. These data are best viewed and edited through pivot-
tables, the 2-dimensional representation of any datacubes.
This paper tries to give a unified theory on datacube and pivoting. It was
shown that all data operations in OLAP can by reduced to slicing, dicing,
sizing, and rising operations in a multidimensional datacube. The goal is
to reduce all kind of proposed operations in OLAP to a few operations in
manipulating datacubes. This gives also a new view in implementing OLAP
tools. It is, furthermore, important to note that all aspects of data viewing
of unified mass of data stored as datacubes can be accessed through pivot-
tables. Pivot-tables are easy to understand (if implemented correctly) and
easy to manipulate – at least from the point of view of the user. This paper
shows that – given a datacube – a few operations and options determine a
particular pivot-table. If the user understands these few operations, it is easy
to use them. Unfortunately, Excel pivot-tables do not have these properties.
C HAPTER 8
L OGICAL M ODELING
295
CHAPTER 8. LOGICAL MODELING 296
Logical and Boolean conditions are often used in real-live problem solving.
However, its importance in practical modeling contrasts sharply with its treat-
ment in modeling books and courses. Many modeling techniques and appli-
cations to formulate logical conditions are exposed in this paper.
It presents various methods of logical modeling, that is, mathematical mod-
eling containing logical propositions and Boolean mixed with mathematical
expressions within the constraints. Several modeling techniques are formu-
lated in mathematical notation and in the modeling system LPL (see [72]).
Concrete and executable model application examples are given for the differ-
ent techniques.
A word of caution: It is not trivial in a practical context to use Boolean op-
erators. One needs to analyze carefully the context to use the right opera-
tors. “and”, “or”, and other words in a a spoken text cannot be translated
one-to-one to Boolean “and”, “or”, for instance. Check multiple times before
proceeding!
A second word of caution: The modeling formulation may be correct, the
implementation of the translation to a mathematical linear model might not
always correspond to this logical modeling. This is due to the fact that in most
cases, the automatically introduction of a new binary variable is realized in
LPL as an implication instead of an equivalence. In most cases, this is justifies
but not always. Hence, the resulting linear model in LPL should be checked
anyway.
8.1. Introduction
Mathematical modeling using integer variables is a surprisingly powerful
way to formulate and handle real problems. This is not obvious at a first
glance. Clearly, if there are objects that cannot be divided into parts, then
integer quantities are needed. The number of aeroplanes, for example, must
be integer, 1.5 aeroplanes does not make sense in most context. On the other
hand, if there are 3’345’678 or 3’345’678.5 hens in a country, the difference
may not be important probably, one just can round the number up or down.
More important from a modeling point of view, however, are yes/no deci-
sions where integer programming is used, which is the main focus of this
paper.
Of course, we know that models containing integer variables are much harder
to solve. However, this paper focuses on the various operations which allow
the modeler to express the model in a straightforward way and not on how to
solve it basically. The focus is on modeling and formulation and less on how
to solve these models.
297 CHAPTER 8. LOGICAL MODELING
portation problem, the assignment problem, critical path problems, and other
flow problems. They all contains a special structure and can be solved
without explicitly fix the variables to be integer. Other problems (most
of them) are difficult problems, such as graph vertex coloring, quadratic
assignment problem, finding a maximal clique in a graph and others.
5. Finally, we have problems were one must impose integer values, as
already mentioned, such as number of aeroplanes, etc. This is the most
evident kind of problems where integer quantities are used, they are
also the least important problems from a practical point of view.
Using mathematical notation only, one can formulate all these variants, al-
though one also can use Boolean propositions and predicate logic to express
some of these problems. Whether the problem is formulated in a purely math-
ematical notational framework or partially in logic is basically the same, be-
cause one can translate logical expressions into mathematical once, and vice
versa. We will see how this can be done in one direction: translating logical
expressions into mathematical linear constraints. Advantages of translating
logical into mathematical constraints are as follows:
1. Powerful IP- and MIP-solvers can be applied to solve complex prob-
lems or at least to find good lower and upper bound for a solution.
2. In the case where the Boolean constraints can be expressed as Horn
clauses (Prolog clauses are all Horn-clauses), the model can be solved
using LP without branching. Instead of using inference and resolution
techniques to solve such problems, one may translate the problem into
a LP problem and solve the transformed problem efficiently.
3. Logical and mathematical constraints can be mixed in a single defined
modeling language to augment the readability of a model and to pro-
duce more compact models.
4. As mentioned, MIP-modeling is extremely rich, but also often tricky
and not at all trivial. Often a more natural formulation and representa-
tion for many problems is (a subset of) predicate logic.
This paper contains two parts. The first part lists and explains all mathemat-
ical and logical operators that can be used in constraints. Model examples
are given to understand the semantic of the different operations. The second
part presents a translation procedure that translates all logical operators into
mathematical linear constraints. This is also basically the procedure that is
implemented in the LPL interpreter software. Model examples in LPL are
also given.
min f(x)
subject to gi (x) ≤ 0 forall i ∈ {1, . . . , m}
x∈X
min F(x)
subject to Gi (x) forall i ∈ {1, . . . , m}
x ∈ Nn (or Rn )
where F(x) and Gi (x) are expressions containing mathematical and logical op-
erators. This is a powerful way to compactly specify a large variations of con-
straints in a uniformed syntax. Before using them in concrete model, these
operators and their precedence within an expression is now defined. All the
operators and operands that are allowed in a constraint are listed in Table 8.1,
x and y are arbitrary (sub)-expressions. The precedence is in decreasing or-
der within the table. Indexed operators are listed in Table 8.2. The indexed
operators all have the same precedence.
1
When using integer numbers there is no ambiguity in the concept of “non-zero”,
however if floating point numbers are involved, there must carefully be defined
what is meant by “non-zero”: how far away from zero must a number be to be
defined as non-zero? A (small) interval must be defined, which results from the
context.
CHAPTER 8. LOGICAL MODELING 300
The third expression above may occur in a production planning context. Let
Pi be the proposition that “product i is manufactured” and let N be the propo-
CHAPTER 8. LOGICAL MODELING 302
sition that “most machines (say at least 80%) are maintained”. Then the con-
straint may be interpreted as: “At most 3 different products can be manufac-
tured or exactly one product must be manufactured when most machines are
maintained (N)”.
The definition of the various Boolean operations is given in Table 8.3.
x y x∧y x∨y x∨
˙ y x→y x↔y x←y x nand y x nor y
1 1 1 1 0 1 1 1 0 0
1 0 0 1 1 0 0 1 1 0
0 1 0 1 1 1 0 0 1 0
0 0 0 0 0 1 1 1 1 1
x∨y∨z∨w∨v
x∨y∨z∨w∨v
A Horn-clause is a clause with at most one un-negated literal. Above, the first
clause is a Horn-clause while the second is not2 . A conjunctive normal form
(CNF) is a formula which is a conjunction of a set of clauses. A disjunctive
normal form (DNF) is just a CNF where the two operators ∧ (and) and ∨ (or)
are exchanged. In the following formula the first is a CNF, while the second
is a DNF :
(x ∨ y) ∧ (y ∨ z ∨ w) ∧ v
(y ∧ x) ∨ z ∨ (w ∧ v)
2
Horn clauses play a basic role in logic programming, such as in the Prolog language.
303 CHAPTER 8. LOGICAL MODELING
Various Boolean operators can be transformed into each other (where the
symbol ⇐⇒ is used in the sense “is equivalent to”). 9 identities are listed
below.
(1) It is possible to eliminate one of the three operators (negation, and, or) using
the following identities (Morgan’s law):
x ∧ y ⇐⇒ x ∨ y , x ∧ y ⇐⇒ x ∨ y
x ∨ y ⇐⇒ x ∧ y , x ∨ y ⇐⇒ x ∧ y
(2) The implication and the reverse implication can be replaced using:
x → y ⇐⇒ x ∨ y
x ← y ⇐⇒ x ∨ y
x↔y ⇐⇒ (x → y) ∧ (x ← y) ⇐⇒
(x ∨ y) ∧ (x ∨ y) ⇐⇒ (x ∧ y) ∨ (x ∧ y)
x∨˙ y ⇐⇒ ¬(x ↔ y) ⇐⇒
(x ∨ y) ∧ (x ∨ y) ⇐⇒ (x ∧ y) ∨ (x ∧ y)
(5) The operators nand and nor are given by a negation in Table 8.1:
x nand y ⇐⇒ x ∧ y ⇐⇒ x ∨ y
x nor y ⇐⇒ x ∨ y ⇐⇒ x ∧ y
(6) The indexed operators have the following meanings (where all xi are Boolean
propositions and i ∈ I = {1, . . . , n}, n > 0):
CHAPTER 8. LOGICAL MODELING 304
^
xi ⇐⇒ (x1 ∧ x2 ∧ . . . ∧ xn )
i∈I
_
xi ⇐⇒ (x1 ∨ x2 ∨ . . . ∨ xn )
i∈I
˙
_ X
xi ⇐⇒ exactly(1)i∈I xi ⇐⇒ xi = 1
i∈I
X i∈I
atleast(k)i∈I xi ⇐⇒ xi ≥ k
X
i∈I
atmost(k)i∈I xi ⇐⇒ xi ≤ k
X
i∈I
exactly(k)i∈I xi ⇐⇒ xi = k
i∈I
n
The expression on the right hand side is a conjunction of n−k+1 clauses
consisting of exactly k positive propositions each. The at-least operator can
be interpreted as a compact form of a possibly very large (containing many
clauses) CNF.
(8) The four indexed operators and, or, nand, and nor can be expressed using
the at-least operator using :
^
xi ⇐⇒ atleast(n)i∈I xi ((1))
i∈I
_
xi ⇐⇒ atleast(1)i∈I xi ((2))
i∈I ^ _
nand xi ⇐⇒ ¬ xi ⇐⇒ (¬xi ) ⇐⇒ atleast(1)i∈I (¬xi ) ((3))
i∈I
i∈I
_ i∈I
^
nor xi ⇐⇒ ¬ xi ⇐⇒ (¬xi ) ⇐⇒ atleast(n)i∈I (¬xi ) ((4))
i∈I
i∈I i∈I
Interpretation: (1) If and only if all expressions are true then at least all are
true; (2) if and only if one expression is true then at least one is true; (3) if not
all are true then al least one is false; (4) if none is true then at least all are false.
(9) One may also replace negation of the at-least, at-most, and exactly operators
by each other:
305 CHAPTER 8. LOGICAL MODELING
Note also that atleast(k)... with k > n and atmost(k)... with k < 0 is defined
to be false. Likewise, atmost(k)... with k ≥ n and atleast(k)... with k ≤ 0 is
defined to be true3 .
Using the substitutions (1) to (9) given above one can easy see that all logical
operators can be reduced to a few once, for example, negation (¬), and (∧),
or (∨), and the at-least (atleast() ) operator. The next section shows how these
identities can be used to translate logical expressions into pure mathematical
formulas.
((x ∧ y) ∨ z) ∨
˙ w
((x ∧ y) ∨ z ∨ w) ∧ ((x ∧ y) ∨ z ∨ w)
Step 2: Move the negation inwards (using the Morgan’s law). This gives:
((x ∧ y) ∨ z ∨ w) ∧ (((x ∨ y) ∧ z) ∨ w)
Step 3: Move the or-operators inwards over the and-operators. This gives the
following conjunctive normal form (CNF) :
(x ∨ z ∨ w) ∧ (y ∨ z ∨ w) ∧ (x ∨ y ∨ w) ∧ (z ∨ w)
x+z+w ≥1
y+z+w ≥1
1−x+1−y+1−w ≥1
1−z+1−w ≥1
A1 x ≥ b1 ∨ A2 x ≥ b2 ∨ . . . ∨ An x ≥ bn
CHAPTER 8. LOGICAL MODELING 308
A disadvantage of the big-M method is that it requires lower and upper bounds
on the linear constraints as well as a small number ϵ. In the following, U(y)
is used as “upper bound value for y” and L(y) as “lower bound value for y”.
In the formulas the following shortcuts are used5 :
X X
! !
M=U ai xi − b , m=L ai xi − b
i i
Rule 50a is the same as Rule 50, except that δ has been replaced by δ. Rule 50’
and 50a’ are simplified versions of Rule 50 and 50a, the linear inequality has
been replaced by just a single variable inequality.
Split the vector x into n components (x(i) , i ∈ {1, . . . , n}). Then the disjunction can
be formulated as:
Ai x(i) ≥ bi δi
P (i)
x
P= i x
i δi = 1
δi ∈ {0, 1} , x(i) ≥ 0 , i ∈ {1, . . . , n}
This formulation has been developed in [59]. The test is also a foundation is the
concept of “MIP representability”. An introduction can also be found in [30] and
[29].
5
LPL automatically calculates and uses these bounds provided that the involved
variables are bounded by lower and upper bounds. An error message is generated
if this is not the case.
309 CHAPTER 8. LOGICAL MODELING
Rule 52a is the same as Rule 52, except that δ has been replaced by δ. Rule 52’
and 52a’ are simplified versions of Rule 52 and 52a, the linear inequality has
been replaced by just a single variable inequality.
Basically, the four cases (Case 1 to Case 4) can be reduced to two cases in fact.
Case 4 is the same as case 1 if we replace A < B by A ≤ B − ϵ, or in other
words, in the linear inequalities of Case 4 the right hand side b is replaced by
b − ϵ (hence M also changes). Equally, Case 2 can be reduced to Case 3 by
replacing A > B by A ≥ B + ϵ, or in other words, in the linear inequalities of
Case 2 the right hand side b is replaced by b + ϵ (hence M also changes).
P
Note also that a case with equalities δ → i ai xi = b can be modeled by
applying two rules separately since:
X X X
! !
ai xi − b = 0 ⇐⇒ ai xi − b ≤ 0 ∧ ai xi − b ≥ 0
i i i
z>0→δ=1 is translated to z ≤ Mδ
z ≤ Mδ
z > 0 ↔ δ = 1 is translated to
z ≥ ϵδ;
z>0→δ or δ→z≤0
c1 z + c2 · (z > 0)
Example 3: Two quantities must be link logically. For example: “If product A
is included in the blend then also at least a quantity b of product B must be
included”. That is: zA > 0 → zB ≥ b
To model this situation, an indicator variable δ is introduced with the meaning
“A is included in the blend” that is: zA > 0 → δ. And the requirement
“if product A is included in blend then also at least b of product B must be
included” can be modeled as: δ → zB ≥ b
The two constraints can be translated to mathematical inequalities by apply-
ing the two Rules 51a and 53a, giving:
zA ≤ U(zA ) · δ
zB ≥ L(zB + b) · δ
2v + 3w ≤ 1 → δ δ → 2v + 3w ≤ 1
Applying two rules, one gets (supposing L(v) = L(w) = 0 , U(v) = U(w) = 1
, ϵ = 0.001):
2v + 3w + 4δ ≤ 5 , 2v + 3w + 1.001δ ≥ 1.001
3x + 4y ≤ 5 ∨ 2x + 3y ≥ 4 ↔ x + 2y ≥ 3 ∨ 2x + 4y ≤ 5
The details are given in the text logic0. Note that these examples are from [31]
and [30].
3+4·5 , (3 + 4) · 5 , ¬x ∧ (y ∨ z)
For binary operators like + (addition) or ∨ (or operator), the node (repre-
sented as a ellipse) has a left and a right child connected by an arc, for unary
operators like ¬ there is only a left child (the right is a null pointer, see the
node not.
+ * and
3 * + 5 not or
4 5 3 4 x y z
The concept of “cut-off” is the operation of cutting a subtree off the main
syntax tree. In mathematics, this operation is called “substitution”: a (sub-
)expression is replaced by an additional variable as in the following expres-
sion where yz is substituted by an additional variable w :
x+w = 17
x + yz = 17 becomes
w = yz
Represented as a syntax tree, the original tree is decomposed into two (smaller)
trees as shown in Figure 8.3, the left trees is decomposed into the two expres-
sions on the right.
Boolean expressions can also be cut-off. In this case, the equality sign (=)
must be replaced by equivalence (↔). In most cases, however an implication
(→) is sufficient. An example is given as follows with x and y being Boolean
315 CHAPTER 8. LOGICAL MODELING
sum{i} or{i} if
* and ,
x[i] y x[i] y , y
< x
a b
propositions and p and q are numerical (real) variables (the trees are shown
in Figure 8.4) :
δ∨x∧y
(p + q ≥ 10) ∨ x ∧ y becomes
δ → (p + q ≥ 10)
= = =
+ 17 + 17 w *
x * x w y z
y z
or or -->
+ 10 x y x y + 10
p q p q
Step 1: T0-Rules
Step 2: T1-Rules
Several operators are substituted by other operators defined by the previous
definitions. Table 8.7 give the list of the operators. Step 1 and Step 2 could be
done in a single step.
Step 3: T2-Rules
The NOT-Operator is pushed down the syntax tree and some other reductions
are processed. All rules are listed in Table 8.8.
Step 5: T3-Rules
In this step remaining and-s are pushed upwards in the syntax tree over the
or-s as much as possible. The rules are listed in Table 8.9. Note that n is the
cardinality of the set I and atleast(n)i is the same as the indexed and. This
step can be applied more than once to force a CNF before subtrees are cut.
4. If a parent node in the syntax tree is not a logical operator and the child
node is a logical operator or a relational operator then the subtree is
disconnected. Example:
a · (b > 0) will become a · δ , δ ← b > 0
We suppose that a is a parameter and b is a variable. (a may also be a
variable in this case the model is non-linear.)
CHAPTER 8. LOGICAL MODELING 320
E1 ∨ E2 will become E1 → δ , δ → E2
After this step, the only form with logical operators are x ∨ E1 or x ∨ E1 .
Step 7: T4-Rules
In this step several modifications are done and the final or operator is elimi-
nated.
1. An expression x is transformed to x ≥ 1, and x is transformed into
x ≤ 0, if x is a binary.
2. if x occurs in a nested expression then it is transformed to 1 − x.
3. The two operators < and > are eliminated. If the expressions E1 and E2
are integer expressions then ϵ = 1 else ϵ = 0.00001.
8.7. Conclusion
A procedure was presented to translate mixed constraints, which contain
mathematical and logical operators, into mixed integer constraints – some
details have been left out. Such a procedure can be very useful, especially for
large mathematical models which are enriched and extended by a few logical
constraints. It is also helpful for symbolic manipulation of such constraints.
However, there is certainly no claim here that such a translation procedure is
practical in all circumstances.
min x0
subject to x0 e + Bx ≥ b
Ax ≥ a
x ∈ {0, 1}
min B(k) x
subject to B(i) x ≥ bi ∀i : i ̸= k
Ax ≥ a
x ∈ {0, 1}
Problem: Is the following argument correct? “If fallout shelters are built,
other countries will feel endangered and our people will get a false sense
of security. If other countries will feel endangered they may start a preven-
tive war. If our people will get a false sense of security, they will put less
effort into preserving peace. If fallout shelters are not built, we run the risk of
tremendous losses in the event of war. Hence, either other countries may start
a preventive war and our people will put less effort into preserving peace, or
we run the risk of tremendous losses in the event of war.” (see [28]).
Modeling Steps:
E ⇐⇒ (p → q ∧ r) ∧ (q → s) ∧ (r → t) ∧ (¬p → u) and F ⇐⇒ (s ∧ t ∨ u)
E ⇐⇒ (p ∨ q) ∧ (p ∨ r) ∧ (q ∨ s) ∧ (r ∨ t) ∧ (p ∨ u)
F ⇐⇒ (u ∨ s) ∧ (u ∨ t)
88% of all random generated SAT problems can be solved this way without branch-
ing.
323 CHAPTER 8. LOGICAL MODELING
−p + q ≥ 0, −p + r ≥ 0, −q + s ≥ 0, −r + t ≥ 0, p+u≥1
min u+s
subject to u + t ≥ 1
−p + q ≥ 0
−p + r ≥ 0
−q + s ≥ 0
−r + t ≥ 0
p+u≥1
p, q, r, s, t, u ∈ {0, 1}
p∨q (1a)
p∨r (1b)
q∨s (2)
r∨t (3)
p∨u (4)
s∨u (5a)
t∨u (5b)
Questions
Answers
minimize obj: + u + s;
constraint
s1: + q - p >= 0;
s2: + s - q >= 0;
s3: + t - r >= 0;
s4: + u + p >= 1;
X58X: + r - p >= 0;
X59X: + u + t >= 1;
end
Problem: Is the following set of statements logically consistent? “If the bond
market goes up or if interest rates decrease, either the stock market goes down
or taxes are not raised. The stock market goes down when and only when the
bond market goes up and taxes are raised. If interest rates decrease, then the
stock market does not go down and the bond market does not go up. Either
taxes are raised or the stock market goes down and interest rates decrease.”
(see [28]).
Modeling Steps:
We minimize the last statement s ∨ (r ∧ q). If the minimal value of this ex-
pression is 1, then we know, that the argument holds. Why? Because this
expression must be true under all interpretations. Therefore it follows from
the first three statements.
Further Comments: Note: Williams [28] gives the following formula (22): p +
q + r <= 1 for s3 which is not correct (a correct formula is produced by LPL)
also formula (20) in Williams is not correct.
Questions
1. Verify that LPL’s translation is correct, by generating the CNF using the
method given in model sat1
2. Verify that the argument cannot be proven with the LP relaxation.
Answers
1. Go to model sat1
2. Build the LP relaxation of the problem and solve it. The optimum is −1.
This is smaller than the value of B( k) which is 0. Therefore we have no
proof.
CHAPTER 8. LOGICAL MODELING 328
Problem: Is the following set of statements correct? “If Superman were able
and willing to prevent evil, he would do so. If Superman were unable to
prevent evil, he would be impotent and if he were unwilling to prevent evil,
he would be malevolent. Superman does not prevent evil. If Superman exists,
he is neither impotent nor malevolent. Therefore, Superman does not exist.”
(see [24]).
Modeling Steps:
s3: ~p;
s4: e -> i nor m;
minimize ne: ~e "Superman does not exist";
Write('%s', if (e,'Superman exists.','Superman does not
exist'));
end
Solution: The Boolean statement is correct, that is, the argumentation is cor-
rect and unfortunately, Superman does not exist.
Questions
1. Verify that LPL’s translation is correct, by generating the CNF using the
method given in model sat1
2. Verify that the argument cannot be proven with the LP relaxation.
Answers
2. Build the LP relaxation of the problem and solve it. The optimum is −1.
This is smaller than the value of B( k) which is 0. Therefore we have no
proof.
CHAPTER 8. LOGICAL MODELING 330
Modeling Steps:
Solution: Since the optimal value for this model is x2 = 1, we conclude that
x2 follows from the five clauses.
Further Comments: LPL translates this Boolean model into a pure 0-1 linear
program as follows:
model SAT4;
binary variable x1; x2; x3; x4;
331 CHAPTER 8. LOGICAL MODELING
constraint
R1: x1+x2+x3 >= 1;
R2: -x1+x2-x4 >= 1-2;
R3: -x1+x3 >= 1-1;
R4: -x1-x3+x4 >= 1-2;
R5: x1-x3 >= 1-1;
minimize obj: x2;
end
CHAPTER 8. LOGICAL MODELING 332
x ∧ y → z, w ∧ z ∧ y → x, x→y
If a model consists of Horn clauses then one can solve the LP relaxation of the
corresponding 0-1-ILP to solve the problem, although the solution may not be
necessarily have an integer solution. We can nevertheless deduce the result
from the optimal value. Hence, no branching is needed.
(x,y,z,w) =
(1,1,1,1)
(1,1,1,0)
(0,1,1,0)
(0,1,0,1)
(0,1,0,0)
(0,0,1,1)
(0,0,1,0)
(0,0,0,1)
(0,0,0,0)
z :- x, y // three rules
x :- w, z, y
y :- x
?- x // the goal to prove
Questions
1. Translate the following Prolog program into LPL and solve it. What is
the optimum of the 0-1-ILP, what is the optimum of the LP relaxation?
x, y, z
x :- y, z
?- y, z
Answers
1. The model in LPL is as follows and gives the optimal value solution of
-1
model Horn1;
binary variable x; y; z;
constraint
c1: ~x or ~y or ~z;
c2: x or ~y or ~z;
minimize obj: ~y or ~z;
end
The LP relaxation is as follows and give an optimum of -1.5:
model Horn1;
variable x[0..1];y[0..1];z[0..1];
minimize obj: -z-y;
constraint c1: -z - y - x >= -2;
c2: -z - y + x >= -1;
end
(The expression ~y or ~z is a separating cut.)
CHAPTER 8. LOGICAL MODELING 334
Show that from a blend of MgO, H2, O2, and C, the molecule H2CO3 will be
produced.
Modeling Steps: To be able to model this with Boolean logic, some supposi-
tions and simplifications are needed:
E→F
with E= (MgO ∧ H2 → Mg ∧ H2 O) ∧ (C ∧ O2 → CO2 )∧
(CO2 ∧ H2 O → H2 CO3 ) ∧ MgO ∧ H2 ∧ O2 ∧ C
F= H2 CO3
The constraints A1 to A3 form the reaction. A4 means that these four molecules
are present. In the implementation, E is the set of constraints (which must
hold). The objective function represents F. It is minimized, if the objective
function F is zero (false) then F does not follow from E, that is E → F is false.
On the other side, if F is one (true), then F is the consequence of E and E → F
is true.
Solution: In this model, H2 CO3 can be (logically) produced from the reaction.
CHAPTER 8. LOGICAL MODELING 336
Problem: Study how the five following modeling situation can be handled
and translated into a mathematical 0-1-ILP formulation (these examples are
all from [31] and [30]).
Modeling Steps: [Run the model and generate the EQU-file to see how LPL
translates the logical statements into Math.]
z ≤ Mδ
z>0↔δ=1
This can be modeled by the following two linear inequalities (supposing the
lower bound for z is 0 and the minimal strictly positive quantity is ϵ):
z ≤ Mδ , z ≥ ϵδ
z>0→δ or δ→z≤0
This is modeled by the linear constraint (M being an upper bound for z):
z ≤ Mδ and the cost function is formulated as: cost = 5z + 8δ
To verify the resulting model, we check for the values of δ:
(1) if δ = 1 (true) then we have: z ≤ U(z) , cost = 5z + 8
(2) If δ = 0 (false) then we have: z≤0 , cost = 0
In LPL one may formulated the cost function directly – without needing to
introduce explicitly a binary variable (although this is possible too) – as fol-
lows:
constraint C2: cost = 5*z + 8*(z>0);
It generates automatically the two linear constraints (where X13X is the addi-
tional binary variable):
C2: - 8 X13X - 5 z + cost = 0;
X14X: + z - 10 X13X <= 0;
zA ≤ U(zA ) · δ
zB ≥ L(zB + b) · δ
2v + 3w ≤ 1 → δ , δ → 2v + 3w ≤ 1
2v + 3w + 4δ ≤ 5 , 2v + 3w + 1.001δ ≥ 1.001
X X X X
a1,j xj ≤ b1 ∨ a2,j xj ≥ b2 ↔ a3,j xj ≥ b3 ∨ a4,j xj ≤ b4
j j j j
Let the four top inequalities be Pi with i ∈ {1, . . . , 4}, as well as their lower
and upper bound mi , Mi with i ∈ {1, . . . , 4}. Then we have:
P1 ∨ P2 ↔ P3 ∨ P4 which gives
((P1 ∨ P2 ) ∨ (P3 ∨ P4 )) ∧ ((P1 ∨ P2 ) ∨ (P3 ∨ P4 )) which gives
(P1 ∨ P2 ∨ (P3 ∧ P4 )) ∧ ((P1 ∧ P2 ) ∨ P3 ∨ P4 )
δi = 1 → Pi forall i ∈ {1, . . . , 4}
δ5 = 1 → P1
δ5 = 1 → P2
δ6 = 1 → P3
δ6 = 1 → P4
(δ1 ∨ δ2 ∨ δ6 ) ∧ (δ3 ∨ δ4 ∨ δ5 )
CHAPTER 8. LOGICAL MODELING 340
The 8 indicator variable definitions together with the Boolean constraint gen-
erated the following 10 linear inequalities:
X
a1,j xj + (M1 − b1 )δ1 ≤ M1
X
j
a2,j xj + (m2 − b2 )δ2 ≤ m2
X
j
a3,j xj + (m3 − b3 )δ3 ≤ m3
X
j
a4,j xj + (M4 − b4 )δ4 ≤ M4
X
j
a1,j xj − (m1 − b1 + ϵ)(1 − δ5 ) ≥ b1 + ϵ
X
j
a2,j xj − (M2 − b2 + ϵ)(1 − δ5 ) ≥ b2 − ϵ
X
j
a3,j xj − (M3 − b3 + ϵ)(1 − δ6 ) ≥ b3 − ϵ
X
j
a4,j xj − (m4 − b4 + ϵ)(1 − δ6 ) ≥ b4 + ϵ
j
δ1 + δ2 + δ6 ≥ 1
δ3 + δ4 + δ5 ≥ 1
δi = 1 → Pi , forall i ∈ {1, . . . , 4}
δ1 ∨ δ2 ↔ δ3 ∨ δ4 which gives
((δ1 ∨ δ2 ) ∨ (δ3 ∨ δ4 )) ∧ ((δ1 ∨ δ2 ) ∨ (δ3 ∨ δ4 )) which gives
(δ1 ∨ δ2 ∨ (δ3 ∧ δ4 )) ∧ ((δ1 ∧ δ2 ) ∨ δ3 ∨ δ4 ) which gives
(δ1 ∨ δ2 ∨ δ3 ) ∧ (δ1 ∨ δ2 ∨ δ4 ) ∧ (δ1 ∨ δ3 ∨ δ4 ) ∧ (δ2 ∨ δ3 ∨ δ4 )
The last line is an expression of four clauses, for which one can directly derive
the four linear inequalities. Finaly, this translation generates only 4 additional
binaries and totally 8 linear constraints, in contrast with the translation given
in [30] which generates 6 binaries and 10 linear constraints.
The code of LPL is as follows:
variable x[0..4]; y [0..5];
constraint C5: 3*x+4*y<=5 or 2*x+3*y>=4 <-> x+2*y>=3 or
2*x+4*y<=5;
341 CHAPTER 8. LOGICAL MODELING
LPL generates the following 8 inequalities (together with the 4 binary vari-
ables X50X, X52X, X54X, X56X :
C5: + X56X + X54X - X50X >= 0;
X51X: + 4 y + 3 x + 27 X50X <= 32;
X53X: + 3 y + 2 x - 4 X52X >= 0;
X55X: + 2 y + x - 3 X54X >= 0;
X57X: + 4 y + 2 x + 23 X56X <= 28;
X58X: + X52X + X50X - X54X >= 0;
X59X: + X56X + X54X - X52X >= 0;
X60X: + X52X + X50X - X56X >= 0;
Questions
Answers
3x + 4y + (M1 − b1 )δ1 ≤ M1
3x + 4y + 27δ1 ≤ 32
A: x∧y∨z ∨ ˙ w
_∧ y ∨ z) ∨ w
B: (x ˙
C: (qi ∧ pi )
i∈I
^
D: (qi ∨ pi )
i∈I
I = {1, . . . , n} , n > 0
Modeling Steps:
Expression A: ((x ∧ y) ∨ z) ∨
˙ w
(x ∨
˙ y) ≡ ((x ∨ y) ∧ (¬x ∨ ¬y))
this gives:
(x ∨ z ∨ w) ∧ (y ∨ z ∨ w)
343 CHAPTER 8. LOGICAL MODELING
x+z+w ≥1
y+z+w ≥1
1−x+1−y+1−w ≥1
1−z+1−w ≥1
Expression B: ((x ∧ y) ∨
˙ z) ∨ w
(x ∨ z ∨ w) ∧ (y ∨ z ∨ w) ∧ (¬x ∨ ¬y ∨ ¬z ∨ w)
x+z+w ≥1
y+z+w ≥1
1−x+1−y+1−z+w ≥1
i∈I (pi ∧ qi )
W
Expression C:
W
The operator is the indexed operator for “or”. The constraint is in fact (note
that we have I = {1, . . . , n} , n > 0):
(p ∧ q1 ) ∨ (p2 ∧ q2 ) ∨ . . . ∨ (pn ∧ qn )
| 1 {z }
n times
CHAPTER 8. LOGICAL MODELING 344
i∈I (pi ∨ qi )
V
Expression D:
V
The operator is the indexed operator for “and”. The constraint is in fact
(note that we have I = {1, . . . , n} , n > 0):
(p ∨ q1 ) ∧ (p2 ∨ q2 ) ∧ . . . ∧ (pn ∨ qn )
| 1 {z }
n times
This constraint is already in the conjunctive normal form. Hence, the transla-
tion into linear inequalities is straightforward as:
pi + q i ≥ 1 , forall i ∈ I
Questions
7
Note that in many cases an implication is all what is needed, however there are
situations where an equivalence is imperatively required. LPL used implication
whenever possible. If equivalence is needed the modeler must manually impose
it.
345 CHAPTER 8. LOGICAL MODELING
1. Start LPL and look what it generates by looking at the EQU-file and the
LPY-file.
Answers
C1 : d↔ V ∧ y)
(x
C2 : d↔ i∈I zi
D1 : d↔ W ∨ y)
(x
D2 : d↔ i∈I zi
E1 : d↔ (x ∨
˙ y)
F1 : d↔ (x ↔ y)
Modeling Steps:
0 ≤ x + y − 2d ≤ 1 (C1a)
CHAPTER 8. LOGICAL MODELING 348
For a different formulation, consider the three planes defined by three points
each as follows: {(010), (111), (001)}, {(111), (101), (000)}, and {(110), (000), (001)}
(see Figure 8.5, right side). These three planes are formulated mathematically
as: x + y − d = 1 , x = d , y = d Hence, the constraint C1 could also be ex-
pressed mathematically by the intersection of the three half-spaces as follows
:
x+y−d≤1
x≥d (C1b) (8.1)
y≥d
Both mathematical formulations are correct. However, the second one with
three linear inequalities is “better” because its LP-relaxation is tighter.8 LPL
automatically generates the tighter formulation:
C1: + x - d >= 0;
X43X: - y - x + d >= -1;
X44X: + y - d >= 0;
d ↔ (x ∧ y) ≡ (d ∨ (x ∧ y)) ∧ (d ∨ (x ∧ y)) ≡
(d ∨ x ∨ y) ∧ (d ∨ x) ∧ (d ∨ y)
Constraint C2: In the same way as C1, this constraint C2 can be formulated
by two parallel planes as follows (n is the cardinality of the set i):
8
The LP-relaxation is obtained by replacing x, y, d ∈ {0, 1} with 0 ≤ x, y, d ≤ 1.
“tighter” means that C1b ⊂ C1a and this is “better” because most solver start
with a LP-relaxation as initial solution. For a more profound theory see [42] or
[51].
349 CHAPTER 8. LOGICAL MODELING
X
n
0≤ zi − nd ≤ n − 1
i=1
X
n
− xi + d ≥ 1 − n
i=1
xi ≥d forall i ∈ {1, . . . , n}
Constraint D1: Graphically, the constraint is true for the black points in the
unit cube and false otherwise (see in Figure 8.6). These black points can
be separated from the others by two parallel planes containing the points
{(1, 1, 0), (0, 0, 0.5), (1, 0, 1)} and {(1, 1, 1), (0.5, 0, 1), (0, 0, 0)}. The two planes
are: x + y − 2d = 0 and x + y − 2d = −1. The intersection of the two half-
spaces represents D1, it is:
−1 ≤ x + y − 2d ≤ 0
x+y ≥d
x ≤d
y ≤d
X
n
−(n − 1) ≤ zi ≤ nd
i=1
X
n
zi ≥d
i=1
−zi + d ≥ 0 forall i ∈ {1, . . . , n}
x+y−d ≥0
x+y+d ≤2
x−y+d ≥0
−x + y + d ≥0
Graphically the solution is given by the four corner points in Figure 8.7 (left
side). Each half-space excludes a single corner of the unit cube.
The four corresponding planes are defined by three points each as: {(000), (011), (110)}
, {(110), (011), (101)} , {(000), (011), (101)} , and {(000), (101), (110)}.
Constraint F1: This constraint can be formulated in the thight form as:
−x + y − d ≥ −1
x−y−d ≤ −1
x+y+d ≥1
−x − y + d ≥ −1
Graphically the solution is given by the four corner points in Figure 8.7 (right
side).
351 CHAPTER 8. LOGICAL MODELING
The four planes can be constructed in the same way as in the previous exam-
ple.
CHAPTER 8. LOGICAL MODELING 352
or:
X X ^ X
Pi ≤ 2 ∧ Pi ≥ 4 ∨ ¬Pi ∨
Pi ≥ 2
i∈I1 i∈I2 i∈I3 i∈I4
X
δ1 = 1 → Pi ≤ 2
X1
i∈I
δ1 = 1 → Pi ≥ 4
i∈I
^2
δ2 = 1 → ¬Pi
X3
i∈I
δ3 = 1 → Pi ≥ 2
i∈I4
X
Pi + 3δ1 ≤ 5
X1
i∈I
Pi − 4δ1 ≥ 0
i∈I2
i + δ2 ≤ 1
PX forall fi ∈ I3
Pi − 2δ3 ≥ 0
i∈I4
δ1 + δ2 + δ3 ≥ 1
Questions
1. For some reasons, the company wants only produce two products. Which
product is certainly not in that list.
Answers
1. If only two product are produced then certainly product 5 and 6 cannot
be part of them. Why? Because this makes the premise of the implica-
tion true and the consequence false, since then less than two of set I4
are part and not none of set I3 are in the part. One can check this by
adding the two constraints (the model becomes infeasible – saying that
there is no way to make this true):
constraint D: sum{i} P <= 2;
constraint E: P[5] or P[6];
355 CHAPTER 8. LOGICAL MODELING
Problem: Model the disjunctive grey space defined in the Figure 8.8
(0,0) (6,0)
R: x≤6 ∧ y≤2
T : y≤x ∧ y≤6−x
(x ≤ 6 ∧ y ≤ 2) ∨ (y ≤ x ∧ y ≤ 6 − x)
CHAPTER 8. LOGICAL MODELING 356
LPL transforms the disjunctive constraint into the following 5 linear con-
straints, adding two binary variables X40 and X43:
max: + y + x;
Grey: + X43X + X40X >= 1;
X41X: + x + 5 X40X <= 10;
X42X: + y + 18 X40X <= 20;
X44X: - x + y + 20 X43X <= 20;
X45X: + x + y + 24 X43X <= 30;
357 CHAPTER 8. LOGICAL MODELING
1. We introduce two variables for the quantities of the the two liquids: x
and y.
2. Three cases can be distinguished: Either we produce only the first liq-
uid A and store it in both containers, or we produce only the second
liquid B and store it also in both containers or we produce both then
we have to store the first in one and the second in the second container
separately. The feasible space is shown in Figure 8.9.
CHAPTER 8. LOGICAL MODELING 358
(y = 0 ∧ x ≤ a + b) ∨ (x = 0 ∧ y ≤ a + b) ∨ (x ≤ a ∧ y ≤ b)
(x > a → y ≤ 0) ∧ (y > b → x ≤ 0)
Solution: The logical capacity constraint can be translated into the following
linear constraints by adding two binary variables p and q:
x−a ≤ b·p
y−b ≤ a·q
x ≤ (a + b) · (1 − q)
y ≤ (a + b) · (1 − p)
p, q ∈ {0, 1} , 0 ≤ x, y ≤ a + b
Further Comments: To translate the logical constraint into the linear inequal-
ities, do the following:
(x > a → y ≤ 0) ∧ (y > b → x ≤ 0)
(x ≤ a ∨ y ≤ 0) ∧ (y ≤ b ∨ x ≤ 0)
359 CHAPTER 8. LOGICAL MODELING
p1 = 1 → x≤a
p2 = 1 → y≤0
q1 = 1 → y≤b
q2 = 1 → x≤0
p1 , p2 , q1 , q2 ∈ {0, 1}
(p1 ∨ p2 ) ∧ (q1 ∨ q2 )
5. which is :
p1 + p2 ≥ 1 , q1 + q2 ≥ 1
6. Translating the four definitions into linear constraints gives (where U(α)
is an upper bound for α):
x−a ≤ U(x − a) · (1 − p1 )
y ≤ U(y) · (1 − p2 )
y−b ≤ U(y − b) · (1 − q1 )
x ≤ U(x) · (1 − q2 )
p1 + p2 ≥ 1
q1 + q2 ≥ 1
x−a ≤ b · (1 − p1 )
y ≤ (a + b) · (1 − p2 )
y−b ≤ a · (1 − q1 )
x ≤ (a + b) · (1 − q2 )
This is exactly what we have obtained above. Note, however, that the linear
inequalities are logically not equivalent with the logical constraint, but they
are implied.
Questions
Answers
1. In the expression
(x > a → y ≤ 0) ∧ (y > b → x ≤ 0)
replacing a → b by ā ∨ b gives:
(x ≤ a ∨ y ≤ 0) ∧ (y ≤ b ∨ x ≤ 0)
Redistributing ∨ gives:
(x ≤ a ∧ y ≤ b) ∨ (x ≤ a ∧ y ≤ 0) ∨ (y ≤ b ∧ x ≤ 0) ∨ (y ≤ 0 ∧ x ≤ 0)
Now the last term is contained in all the previous ones, so it can be
removed and the formula follows.
2. Suppose p = 0 and q = 0, then x ≤ 10, y ≤ 12, that is, the two contain-
ers are used separatedly to store the two liquids.
Suppose p = 1 and q = 0, then x ≤ 22, y ≤ 0, that is, both containers
are used to store the first liquid and the second liquid is not produced.
Suppose p = 0 and q = 1, then x ≤ 0, y ≤ 22, that is, both containers
are used to store the second liquid and the first liquid is not produced.
Suppose p = 1 and q = 1 then x ≤ 0, y ≤ 0. This case will not be
realised since at least one (x or y) is maximized. Hence, the model
correctly reflects the three cases discussed above.
361 CHAPTER 8. LOGICAL MODELING
1. The food may never be made up of more than three oils (ingredients).
2. If an oil is used at least 20 tons and at most 200 tons must be used.
3. If either Veg1 or Veg2 is used (two vegetal oils) then Oil3 (a non-
vegetal oil) must also be used in the blend.
Modeling Steps:
end
Note that the lower and upper bounds of xi is not the same as the minimal
and maximal quantity used in the blend. Therefore, the second condition is
translated into:
xi ≤ 20δi forall i ∈ I
xi + 100δi ≤ 300 forall fi ∈ I
Further Comments: In LPL the second condition can also be integrated in the
decraation of the binary variable as follows;
binary variable d{i}: Lo <= x <= Up
a≤2∨b≤3 ↔ e≤8∨f≥7
One can apply exactly the same procedure as in model logic0, Example 5.
Questions
1. Change e<=8 to e>=8 and compare the two objective values, What do
you notice?
Answers
1. The solution to the first model is 6 while to the second it is 10. Mini-
mizing the sum of the four variables will set them to their lower bound,
365 CHAPTER 8. LOGICAL MODELING
that is: a = 1, b = 0, e = 2, and f = 3, since the left side and the right
side of the equivalence are both true, the constraint is fulfiled.
In the second case, the right side is true only if f ≥ 7, hence the solution
is a + b + c + d = 10. If, on the other hand, the left would be false then
a ≥ 3 and b ≥ 4 must hold and f and g would be at there lower bound,
hence a + b + c + d ≥ 12 which is larger than 10.
CHAPTER 8. LOGICAL MODELING 366
Rule29a : 0=y;
Rule30 : y = z;
Rule31 : y <-> z;
Rule32 : y <> z;
Rule33 : y xor z;
Rule34 : exactly(2){i} x;
Rule35 : atmost(2){i} x;
Rule33a : atmost(0){i} x;
Rule36 : atleast(2){i} x;
-- T3 rules
Rule40 : z or (v and y);
Rule40a : (v and y) or z;
Rule41 : y or atleast(0){i} x;
Rule41a : atleast(0){i} x or y;
solve;
end
CHAPTER 8. LOGICAL MODELING 368
Problem: Coal, gas and nuclear fuel can be imported in order to satisfy the
energy demands of a country. Three grades of gas and coal (low, medium,
high) and one grade of nuclear fuel may be imported. The costs are known.
Furthermore, there are upper and lower limits in the imported quantities from
a country. What quantities should be imported if the import cost have to be
minimized? (The model is from [49]). In addition, three additional conditions
must be fulfilled:
1. The data are defined and explained in the model code (see parameter
section).
3. The sum of all imports must be the desired energy amount e. Hence we
have
X X
xi,j,k + yk = e
i,j,k k
6. In condition 3, two other predicates are needed: “If the total amount of
non-nuclear imported fuel, lays between 40-50% for gas and 20-30% for
coal of the total imported non-nuclear fuel then Qj ”, and “if imported
gas is between 50-60% of the total imported non-nuclear fuel then R”.
Hence: P
Qj ← (eLj ≤ P i,k xi,j,k ≤ eUj ) forall j
R ← (eA ≤ i,k xi, ′ gas ′ ,k ≤ eB)
1. The first condition has the form: “for each k, either A or B”. Normally,
“either ... or” is translated as exclusive or, but sometimes we just mean
or (non-exclusive). It depends on the context. Here we want to say
that A and B cannot both be true at the same time. Therefore we have:
A∨ ˙ B.
Modeling Steps: This model shows how mathematical and logical constraints
can be used side by side.
1. There are 7 possible components that are used to build a radio. For each
component a binary variable is introduces, that says whether to use it
or not to build our radio.
2. The constraints easy to derive. The objective function is the selling
prices minus the costs of all components. Since the radio is either of
wood or plastic only one of the variable W or P is differnt from zero.
Solution: The profit for one radio made of wood is 12. It uses tube III and a
special power supply.
Questions
Answers
1. The profit is 8. It uses tube II and also a special power supply. This can
be found by adding the constraint:
constraint R7: ~W; //do not use a wooden box !
373 CHAPTER 8. LOGICAL MODELING
n
_
xi,j , forall i = 1, . . . , n + 1
j
¬xi,j ∨ ¬xk,j , forall i, k = 1, . . . , n + 1 , i ̸= k , j = 1, . . . , n
Modeling Steps:
1. We introduce a binary variable for each (i, j)-combination, that is, xi,j =
1 if pigeon i is in hole j, otherwise xi,j = 0.
2. The first constraint states that each pigeon is placed in exactly one hole.
X
n
xi,j = 1 , forall i = 1, . . . , n + 1
j=1
3. The second constraint states that for each pair of pigeons (i, k), i ̸= k,
both do not occupy the same hole j (constraint S0):
4. There is another way to formulated this last constraint: For each hole j
there can be at most one pigeon (constraint S1):
X
n+1
xi,j ≤ 1 , forall j = 1, . . . , n
i
--SetSolver(glpkSol);
parameter n:=10 "number of holes";
set i,k:=1..n+1 "n+1 Pigeons";
set j :=1..n "n Holes";
binary variable x{i,j};
constraint
R{i}: sum{j} x = 1 "Each pigeon i must be in exactly
one hole";
--S0{i,k,j|i<>k}: x[i,j] + x[k,j] <= 1;
S1{j}: sum{i} x <= 1;
solve;
end
Note that the first formulation (with constraint S0) has n(n + 1)2 constraint,
while the second formulation (with constraint S1 instead) is much smaller
and contains only 2n + 1 constraint. Furthermore, the LP relaxation of the
first formulation is feasible with xi,j = 1/n, while the LP relaxation of the
second formulation is infeasible. Thus, IP solvers – based on LP relaxations–
will immediately discover the infeasibility of the pigeon hole problem in the
second formulation, while in the first formulation the infeasibility could be
very difficult to be proven. Therefore, the free solver glpk found the feasibility
of the second formulation immediately, while it was not possible to prove
infeasibility for the first formulation in reasonable time.
Questions
1. Try to solve both model versions – once with S0 and without S1 and
once with S1 and without S0, with the two solvers glpk and lp_solve.
2. Try a problem with n = 100 and solve it with a commercial solver – like
Gurobi. Try both formulations.
Answers
1. Prove infeasibility with S1 is easy and the solver takes no time. With S1
the solvers take a long time to prove infeasibility.
2. Depending on commercial solvers, it is easy or difficult to solve with
S0. For Gurobi it was easy to solve it.
C HAPTER 9
M Y V ISION
375
CHAPTER 9. MY VISION 376
I have contributed with my own modeling language, namely LPL. At the be-
ginning of my career as a researcher, I implemented LPL (Linear Program-
ming Language) as a tool to formulate several larger LPs (Linear Programs),
which we used at the Department of Informatics at the University of Fribourg
for various real-life projects. Soon I discovered that this kind of language
notation could be used for many different other applications. I added and
removed many features to the language, always on the quest to find out what
is the “best” (simplest, shortest, most readable, efficient) way to formulate
and to model a concrete problem as a mathematical model. It has become
a main playground and research object for many serious and not so serious
applications and models.
The quest to find the modeling language that I have in mind did not end till
now. This paper collects some ideas and requirements that I came around on
my career as a teacher, researcher and consulter for real problems and that
I consider to be fundamental. It might stimulate persons with more compe-
tence in formal language design than I have to pick these ideas and to do a
better job than I did till now. Although this paper is rather descriptive than
formal, I am convinced that these ideas are worthwhile to be written down.
Future will show of whether they are falling on fruitful soil.
9.1. Introduction
We use programming languages to formulate problems in order to deal with
them by computers. At the same time, we want these languages to be read-
able for human beings. In fact, the emergence of computers has created a
systematic way in which problems are formulated as computations. We now
frequently make use of this mould even if computers are not involved. Prob-
lem formulation as a computation has a long tradition. The ancient Babylonians
(19th–6th century B.C.), who had the most advanced mathematics in the Mid-
dle East, formulated all their mathematical problems as computations. They
easily handled quadratic and even some cubic equations. They knew many
primitive Pythagorean triples. They mastered the calculation of the volume
of the truncated pyramid and many more impressive computations [25, 33].
Arithmetics was highly developed to ensure their calculations for architec-
377 CHAPTER 9. MY VISION
tural and astronomical purposes. On the other hand, we cannot find a single
instance of what we nowadays call a proof using symbolic variables and con-
straints. Only the process of the calculation – today we may say the procedure or
the algorithm – was described. In this sense, the Babylonian mathematicians
were in fact computer scientists. To illustrate how they did mathematics, one
can consult the examples in [14]. This is in contrast with the Greek mathe-
maticians who were interested in why things are true and less how things are
calculated. The Babylonian and Greek approaches of acquiring and writing
down knowledge are two fundamental different paradigms of knowledge:
algorithmic knowledge and mathematical knowledge1 . This is the subject of
this paper and how to represent the knowledge in programming or modeling
languages.
input, O being the domain of output, and f being the computation. A distinc-
tion is made between function definition, which describes how a function is to
be computed, and function application, which is a call to a defined function.
Since every value can be expressed as a function, there is no need to use ex-
plicitly variables, i.e. symbolic names for memory locations, nor do we need
the assignment operation. Loops in the imperative programming languages
are replaced by (tail) recursion. Furthermore, functions are first-class values,
that is, they must be viewed as values themselves, which can be computed
by other functions. The computational model of functional programming is
based on the λ–calculus invented by Church A. (1936) as a mathematical for-
malism for expressing the concept of a computation; this was at the same
time as Turing invented the Turing machine for the same purpose. One can
show that the two formalism are equivalent in the strict sense that both can
compute the same set of functions – called the computable functions. We call a
programming language Turing complete, if it can compute all computable func-
tions. With respect to functional programming we have the important result
that: “A programming language is Turing complete if it has integer values,
arithmetic functions on these values, and if it has a mechanism for defining
new functions using existing functions, selection, and recursion.” [39, p. 12].
Logic programming emerged in the 1960s, when programs were written that
construct proofs of mathematical theorems using the axioms of logic. This led
to the insight that a proof can be seen as a kind of computation. But it was
realised soon that also the reverse is true: computation can also be viewed as
a kind of proof. This inspired the development of the programming language
Prolog. In Prolog, a program consists of a set of (Horn)-rules together with at
least one goal. Using the backtracking algorithm which consists of resolution
and unification, the goal is derived from the rules. A logic programming lan-
guage can be defined as a “notational system for writing logical statements
together with specified algorithms for implementing inference rules.” [39,
p. 426]. The unification-resolution algorithm is quite limited and has been
replaced by various constraint solving mechanisms in the constraint logic pro-
gramming, a modern extension of the logic programming class [36].
The functional and logic programming classes are sometimes called declara-
tive in computer science. There are problem classes for which a declarative
representation can be used directly to compute a solution, if interpreted in a
certain way. A famous example is the algorithm of Euclid to find the greatest
common divisor (gcd) of two integers. One can easily show that :
This is clearly a declarative way, since it defines the gcd. However, the for-
mulation can directly be used to implement a functional (recursive) program
CHAPTER 9. MY VISION 380
(define (gcd a b)
(if (= b 0) a
(gcd b (remainder a b))))
def
SQR(x, y) = x = y2
Sqr(X,Y) :- Y = X*X.
The query
? :- Sqr(X,7).
? :- Sqr(49,Y).
381 CHAPTER 9. MY VISION
is made then the interpreter may not return a result, because it does not know
what the inverse operation of squaring is. In a constraint logic language, the
interpreter may or may not return a result, depending on whether the square
root is implemented as an inverse of the square operation. This is but a simple
example, but it shows an essential point: the logic program is declarative only
in one direction, but not in the other, except when implementing explicitly the
inverse into the system. This situation is similar in functional programming.
The function (in Scheme)
(define (Sqr y)
(* y y))
solves the problem: “given y find (Sqry)”. The inverse problem, however,
which is implicitly also part of the mathematical definition, would be: “given
the body (∗yy), which evaluates to a single value, find the value of y”. This
second problem cannot be solved using the functional definition. To find the
square root, one needs an entirely different algorithm, e.g. Newton’s approx-
imation formula:
a
xn−1 + xn−1
xn =
2
In an algebraic modeling language (see below), such as LPL one can write:
variable x; y; constraint R: y*y = x; y=7;
or
variable x; y; constraint R: y*y = x; x=49;
The problem specification is valid in both directions and does not change,
regardless of what are known and what are unknown quantities. By the way,
a clever modeling language (which is not the case for LPL ) would reduce the
first model immediately to {y = 7, x = 49} using only local propagation; the
second model would be fed to a non-linear solver which eventually applies a
gradient search method, for which Newton’s approximation is a special case.
The main point here is, that an algorithmic formulation of a problem assumes
an (explicit or implicit) underlying mechanism (algorithm) for solving the
problem, while a mathematical formulation (see below) does not assumes
such a mechanism. In this sense, problems formulated in either a functional or
a logic programming language represent the problem in an algorithmic way,
while algebraic modeling language only formulate the problem in a mathe-
matical way, without indicating how to solve it.
This last example discloses a whole other class of problems that can also be
formulated in a declarative way: the mathematical models. A more complete
CHAPTER 9. MY VISION 382
{min cx | Ax ≥ b}
2
In the research community of operations research, a linear system with inequali-
ties is called linear program. Dantzig wrote in his Linear Programming book [22]:
“When I first analyzed the Air Force planning problem and saw that it could be
formulated as a system of linear inequalities, I called my paper Programming in a
Linear Structure. Note that the term ’program’ was used for linear programs long
before it was used as the set of instructions used by a computer. In the early days,
these instructions were called codes.”
383 CHAPTER 9. MY VISION
z X zn
= Bn
ez − 1 n!
n≥0
Nevertheless, a mathematical model has a big downside: it does not give any
indication on how to solve3 it with the exception of fully enumerate the whole
space and checking for each x whether R(x) is true or false, but enumerating
the space X is out of question for any realistic problem. There does not exist
a unique method (algorithm) to solve all mathematical models. Even worse:
Seemingly harmless problem can be arbitrarily difficult to solve. The problem
of finding the smallest x and y such that {x, y ∈ IN | x2 = 991y2 + 1}, is a hard
problem, because the smallest numbers contain 30 and 29 digits and appar-
ently no other procedure than enumeration is known to find them. There are
even problems that can be represented in a mathematical way, but cannot be
computed. The problem of enumerate all even integers {x ∈ IN | 2x ∈ IN},
for example, cannot be computed, because the computation would take an
infinite time. The problem of printing all real number within a unit circle
{x, y ∈ IR | x2 + y2 ≤ 1} is even not enumerable. It is well-known, to give
a nontrivial example, that the set of theorems in first-order logic, a restricted
subset of classical logic, is undecidable (not computable). This can be shown
by reducing the halting problem to the problem of deciding which logical
statements are theorems [18, p. 520]. These examples simply have the shatter-
ing consequence: Given an arbitrary mathematical formulation of a problem,
we can even not say in the general case whether the problem has a solution
or not. The algorithmic way, on contrast, is a precise sequence of instructions
(a recipe) of finding the solution to a given problem. For well designed algo-
rithms, the sequence will terminate and we can even – for most algorithms –
calculate an upper bound of its execution time – which is called its complexity.
In practice, however, we are not so badly off. There exists problem classes,
even with an infinite state space, which can be solved using general methods.
An example is linear programming (as seen) and other classes of non-linear
models. Great progress has been made in the last decades of discrete prob-
lems, more about them later on.
besides of other limitations, the order in which the rules are written is essen-
tial for their processing, showing that Prolog is not a mathematical language
either. But Prolog had an invaluable influence on the recent development of
constraint logic programming (CLP). Unfortunately, a constraint language nor-
mally come with its own solution methods based on constraint propagation
and various consistency techniques and the modeling part and solution pro-
cess are so closely intermingled that it is difficult to “plug in” different solvers
into a CLP language. However, this is exactly what is needed. Since a gen-
eral and efficient algorithm for all mathematical problems is unlikely, it is ex-
tremely important of being able to link a given mathematically stated problem
to different solver procedure. The solution and formulation process should be
separated as much as possible.
In logic programming, the underlying search mechanism (its computation) is
behind the scene and the computation is intrinsically coupled with the lan-
guage. This could be a strength because the programmer does not have to
be aware of how the computation is taking place, one only writes the rules
in a descriptive way and triggers the computation by a request. In reality,
however, it is an important drawback, because, for most nontrivial problem,
the programmer must be aware on how the computation is taking place. To
guide the computation, the program is interspersed with additional rules (cut
a.o.) which have nothing to do with the description of the original problem.
This leads to programs that are difficult to survey and hard to debug and to
maintain. This problem is somewhat relieved by the constraint logic program-
ming paradigm, where specialized algorithms for different problem classes
are directly implemented in the underlying search mechanism. However, this
makes the language dependent of the implemented algorithms and problems
that are not solvable by one of these algorithm cannot easily be stated in the
language.
In the 80’s and 90’s of the last century, a new kind of mathematical languages,
namely algebraic modeling languages, emerged in the community of operations
research. The fact that a single method (for instance the Simplex method)
can solve almost all linear programs, led to the development of these alge-
braic languages (such as GAMS, AMPL, LINGO, LPL a.o.), which have been
becoming increasingly popular in the community of operations research. Al-
gebraic modeling languages represent the problem in a purely mathematical
way, although the different languages include also some computational facil-
ities to manipulate the data. The mathematical notation itself of a model give
no hint on how to solve the problem, it is stated in purely declarative way.
Therefore, all algebraic modeling language must be linked to “solvers”, that
is, mathematical libraries or programs that can solve the problem, for exam-
ple, Gurobi, Cplex, XPress, HIGHS, etc. Many of these algebraic languages
can also formulate non-linear problems, or some elements of constraint pro-
gramming. They also include some methods to generate derivatives in order
to link the model to non-linear solvers, like Knitro, IPOPT, etc. Typically,
387 CHAPTER 9. MY VISION
spaghetti coding
structured & procedural programming imperative
algorithmic object oriented programming
functional programming
logic programming
declarative
constraint programming
mathematical
algebraic programming
X
n
min iaπi
π∈Π
i
389 CHAPTER 9. MY VISION
This is a very elegant and short way to formulate the sorting problem, but is it
a useful or efficient way? Not really, this formulation is in the same category
as the TSP (traveling salesman problem) which can also be formulated as a
permutation problem and which is NP-complete (find a round trip of minimal
distances defined in a distance matrix ci,j ) :
X
n
min cπi ,πj where j = i mod n + 1
π∈Π
i
The question then is, how to find such a permutation. This is not an easy
task. One could apply a general meta-heuristic, such as Tabu-search with a 2-
or 3-opt neighbourhood to find nearly optimal permutations. However, this
technique is only applicable for small instances and does not necessarily de-
liver an optimal solution. But why using this approach for sorting? We know
that sorting is an “easy” problem: There exists efficient algorithms (Heapsort,
Mergesort) that have a complexity of O(n log n). Even simple approaches
such as Bubblesort can be implemented in a few lines of code in any pro-
gramming language. So, while the mathematical approach seems elegant, it
is neither practical nor efficient. The sorting problem is definitely better for-
mulated as an algorithm.
true if n = 0, K = 0
P(n, K) = false if n = 0, K > 0
P(n − 1, K) ∨ P(n − 1, K − wn ) otherwise
X
min xi
X
i∈I
subject to wi x i = K
i∈I
xi ∈ {0, 1} forall i ∈ I
X
max min pi,j xi
j
X i
subject to xi = 1
i
xi ≥ 0 i ∈ I = {1, . . . , m} , j ∈ J = {1, . . . , n}
such as paper rolls or sheet metal, into smaller pieces of specified sizes while
minimizing material wasted. The problem is explained in cutstock. The col-
umn generation version implemented in LPL is found in cutstock2. Technical
details and a theory for these kind of problems can be found in the text book
[80, Chap. 13]. To understand the main points that I want to make here, the
technical details of the problem are not important.
My main point is the following: The cutting stock problem is preferably for-
mulated partly in a mathematical way, partly in an algorithmic way:
For the mathematical part, three models must be implemented:
(1) A small instance of the cutting stock problem with only a few patterns as a
relaxed linear model (we call it rCS) (details and the notation is found in the
link above) :
X
min zj
X
j
subject to patti,j zj ≥ di forall i ∈ I (A)
j
zj ≥ 0 forall j ∈ J
X
min zj
X
j
subject to patti,j zj ≥ di forall i ∈ I (A)
j
zj ∈ Z+ forall j ∈ J
(3) Finally, a Knapsack problem (fP) to find new improving pattern is also
used :
X
min dui yi
X
i
subject to w i yi ≥ W
i
yi ∈ Z+ forall i ∈ I
function ColumnGenertion() {
InitializePatterns() //add some p a t t e r n s t o Cutstock
solve Cutstock // r e t u r n s duals
CHAPTER 9. MY VISION 392
Inject_duals_into_Knapsack()
solve Knapsack // t o f i n d a new improving p a t t e r n
while (found_an_improved_pattern) do {
Add_the_pattern_to Cutstock()
solve Cutstock // r e t u r n s duals
Inject_duals_into_Knapsack()
solve Knapsack // t o f i n d a new improving p a t t e r n
}
solve IntegerCutstock
}
X
min ci,j xi,j
X
i,j∈V
subject to xi,j = 1 forall i ∈ V (A)
X
j∈V
xi,j = 1 forall j ∈ V (B)
XX
i∈V
xi,j ≤ |S| − 1 forall S ⊂ V, |S| ≥ 2 (G)
i∈S j∈S
xi,j ∈ {0, 1} forall i, j ∈ V, i ̸= j
i, j ∈ V = {1 . . . n} , n > 0
The binary variables xi,j is 1 if the circuit contains the arc (i, j) in the graph,
otherwise it is 0. The constraints A and B make sure that a location is visited
only once, and the constraint G excludes all subtours (further explications
is given in tsp-5. Unfortunately, G contains an exponential number of con-
straints, for each sub-tour one. Hence, it is not possible to generate all if them
at once. What is possible, however, is to solve an problem only with the con-
straints A and B then check which subtours constraints are violated and add
then to the model, and proceed this way until no subtours is violated. The
(algorithmic) procedure is then to begin with an empty list S and repeatedly
add subtours to S :
function AddSubtours() {
S = {}
cNr1 = 2 // i n i t i a l i z e cNr1 ( number o f components )
393 CHAPTER 9. MY VISION
9.6. Requirements
Combining mathematical and algorithmic knowledge in a single language is
a great advantage for formulating such problems and the combination should
be in a way that the different components can be clearly separated from each
other. We shall call a modular language that combines mathematical and al-
gorithmic knowledge, modeling language.
concrete context, this approach may be the appropriate way, but in general, I
think, this is a short-term thinking.
It is said that this approach has some advantages: One must learn only one
language; a language like Python contains thousands of packages for all kinds
of tasks: manipulating, reading/writing data, generating graphics and others;
implementing efficient algorithms. So then, if one wants to use a “master
language” like Python for modeling, why not using an algebraic language as
an additional package (library), instead of using complicated syntax to define
mathematical variables and constraints within the programming language?6
As a small example, let’s look at the following simple non-linear model (see
gurobiNLP) :
Why should one use the following GurobiPy (Python) code to implement this
model
import gurobipy as gp
from gurobipy import GRB
m = gp.Model()
x = m.addVar(lb=-1, ub=4, vtype=GRB.INTEGER, name="x")
twox = m.addVar(lb=-2, ub=8, name="2x")
sinx = m.addVar(lb=-1, ub=1, name="sinx")
cos2x = m.addVar(lb=-1, ub=1, name="cos2x")
expx = m.addVar(name="expx")
m.setObjective(sinx + cos2x + 1, GRB.MINIMIZE)
lc1 = m.addConstr(0.25 * expx - x <= 0)
lc2 = m.addConstr(2.0 * x - twox == 0)
gc1 = m.addGenConstrSin(x, sinx, "gc1")
gc2 = m.addGenConstrCos(twox, cos2x, "gc2")
gc3 = m.addGenConstrExp(x, expx, "gc3")
m.params.FuncNonlinear = 0 ## using P i e c e w i s e l i n e a r
approx
# m. params . FuncNonlinear = 1 ## using MINLP s o l v e r
# m_presolve = m. p r e s o l v e ( )
m.optimize()
model gurobiNLP;
SetSolver(gurobiLSol);
variable x [-1..4];
constraint A: 0.25*Exp(x) - x <= 0;
minimize M: Sin(x) + Cos(2*x) + 1;
end
In this case, LPL does not need to decompose the non-linear expressions, but
it eventually generate derivatives instead.
9.7. Conclusion
In this paper, a new type of modeling language has been presented which is a
superset of a programming language, since it can not only represent algorith-
mic, but also mathematical knowledge. It was shown by examples that some
problems are best formulated in a mathematical way, others in an algorithmic
way, still others in a combination of both. Consequently, we need languages
which can code both kinds of knowledge in a unified framework.
397 CHAPTER 9. MY VISION
[1] Tarski A. Introduction to Logic and to the Methodology of the Deductive Sci-
ences. Oxford University Press, 1994, 4th edition.
[2] Fox W.P. Albright B. Mathematical Modeling with Excel. CRC Press,
NewYork, 2020, second edition.
[3] MEYER B. Object–Oriented Software Construction. Prentice Hall, London,
1997.
[4] Shetty C.M. Bazaraa M.S., Sherali H.D. Nonlinear Programming, Theory
and Algorithms. Wiley, 2006, third edition.
[5] Pogh J. Bell D., Morrey I. The Essence of Program Design. Prentice Hall,
London, 1997.
[6] Weismantel R. Bertsimas D. Optimization over Integers. Dynamic Ideas,
Belmont, 2005.
[7] Hart W. E. Laird C. D. Nicholson B. L. Siirola J. D. Watson J-P Woodruff
D. L. Bynum M. L., Hackebeil G. A. Pyomo–optimization modeling in
python, volume 67. Springer Science & Business Media, third edition,
2021.
[8] Mancas C. On Modelware as the 5th Generation of Programming Lan-
guages. Acta Scientific Computer Sciences, Vol 2 Issue 9, 2020.
[9] Pedregal P. García R. Alguacil N. Castillo E., Conejo A.J. Building and
Solving Mathematical Programming Models in Engineering and Science. Wi-
ley, 2002.
[10] Kwon Ch. julia – programming for operations research.
http://www.chkwon.net/julia, second edition, 2019.
399
Bibliography 400
[28] Williams H.P. Logical problems and integer programming. Bull. Inst.
Math. Appl., 13:18–20, 1977.
[29] Williams H.P. An alternative explanation of disjunctive formulations.
European Journal of Operations Research, 72:200–203, 1994.
[30] Williams H.P. Logic and Integer Programming. Springer, 2009.
[31] Williams H.P. Model Building in Mathematical Programming. John Wiley,
Fifth Edition, 2013.
[32] IBM. Mathematical Programming System Extended/370 (MPSX/370), Ver-
sion 2, Program Reference Manual. IBM, 1988.
[33] Yaglom I.M. Mathematical Structures and Mathematical Modelling. Gor-
don and Breach Science Publ., New York, (transl. from the Russian by D.
Hance, original ed. 1980), 1986.
[34] Lucas H.C.JR. Isakowitz T., Schocken S.
[35] Schwichtenberg J. Teach Yourself Physics, a travel companion. No-Nonsense
Books, 2020.
[36] Maher M.J. Jaffar J. Constraint logic programming: a survey. The Journal
of Logic Programming, Volumes 19–20, Supplement 1, May–July 1994,
Pages 503-581, 1996.
[37] Hooker J.N. A Quantitative Approach to Logical Inference. Workshop
"Mathematics and AI", Vol II, FAW Ulm, 19th-22nd December 1988, pages
289–314, 1988.
[38] Malliaris M. Jukic N., Jukic B. Processing (OLAP) for Decision Support.
Handbook on Decision Support Systems 1, eds. Burstein F., Holsapple C.W.,
Springer, pp. 259ff, 2008.
[39] Louden K.C. Programming Languages – Principles and Practice. PWS–
KENT Publ. Comp., 1993.
[40] Cesari L. Optimization – Theory and Applications. Springer Verlag, 1983.
[41] Schrage L. Optimization modeling with LINGO. http://www.lindo.
com, 1999.
[42] Wolsey L.A. Integer Programming. Wiley, 1998.
[43] Levitin Maria Levitin A. Algorithmic Puzzles. Oxford University Press,
2011.
[44] Biegler L.T. Nonlinear Programming, Concepts, Algorithms, and Applications
to Chemical Processes. MOS-SIAM Series on Optimization, 2010.
[45] Wallace M. Building Decision Support Systems, using MiniZinc. Springer,
2020.
Bibliography 402
[62] Winston W.L. Seref M.H., Ahuja R.K. Developing Spreadsheet-Based De-
cision Support Systems (Using Excel and VBA for Excel). 2007, Belmont,
MA: Dynamic Ideas.
[63] Hürlimann T. An Introduction to the Modeling Language LPL. https:
//matmod.ch/lpl/doc/modeling3.pdf.
[64] Hürlimann T. Computer-Based Mathematical Modeling (Ha-
bilitation Thesis). https://matmod.ch/lpl/doc/WP-old/
1997-Habil-new.pdf.
[65] Hürlimann T. Functionality Sheet of LPL. https://matmod.ch/lpl/
doc/lpl.pdf.
[66] Hürlimann T. How to model ? https://matmod.ch/lpl/doc/
modeling2.pdf.
[67] Hürlimann T. Index Notation in Mathematics and Modeling Lan-
guage LPL: Theory and Exercises. https://matmod.ch/lpl/doc/
indexing.pdf.
[68] Hürlimann T. Logical modeling. https://matmod.ch/lpl/doc/
logical.pdf.
[69] Hürlimann T. LPL Tutorial, Models. https://matmod.ch/lpl/doc/
tutorial.pdf.
[70] Hürlimann T. My Vision of a Modeling Language. https://matmod.
ch/lpl/doc/modeling5.pdf.
[71] Hürlimann T. Permutation Problems. https://matmod.ch/lpl/
doc/permutation.pdf.
[72] Hürlimann T. Reference Manual for the LPL Modeling Language, most
recent version. https://matmod.ch/lpl/doc/manual.pdf.
[73] Hürlimann T. Various Model Types. https://matmod.ch/lpl/doc/
variants.pdf.
[74] Hürlimann T. Various Modeling Tools. https://matmod.ch/lpl/
doc/modeling4.pdf.
[75] Hürlimann T. What is modeling ? https://matmod.ch/lpl/doc/
modeling1.pdf.
[76] Hürlimann T. Mathematical Modeling and Optimization – An Essay for the
Design of Computer-Based Modeling Tools. Kluwer Academic Publ., Dor-
drecht, habilitation at the university of fribourg edition, 1999.
[77] Hürlimann T. Modeling Languages in Optimization: a New Paradigm.
in : Encyclopedia of Optimization, eds. Floudas A., Pardalos P.M., Springer,
2001.
Bibliography 404