You are on page 1of 29

Introduction to Modeling with

Linear Programming
Algorithmic Methods for Mathematical Models
(AMMM)

Enric Rodrı́guez-Carbonell

September 7, 2022
Example 1: Problem
A factory can produce five types of product (PROD1, PROD2, ..., PROD5)
by using two production processes: grinding and drilling.
Each unit of each product yields the following contributions to profit:
PROD1 PROD2 PROD3 PROD4 PROD5
550¿ 600¿ 350¿ 400¿ 200¿
Each unit requires a certain number of hours on each process.
A dash indicates when a process is not needed.
PROD1 PROD2 PROD3 PROD4 PROD5
Grinding 12 20 — 25 15
Drilling 10 8 16 — —
The final assembly of a unit of product uses 20 hours of an employee’s time.
The factory has 3 grinding machines and 2 drilling machines and works a
6-day week with 2 shifts of 8 hours on each day. In total 8 workers are
employed in assembly, each working one shift a day.
The problem is to find how much of each product is to be manufactured so as
to maximize the total profit contribution.
2 / ??
Example 1: Model
■ We introduce (decision) variables x1 , x2 , . . ., x5 representing the amount
of PROD1, PROD2, ..., PROD5 that should be produced in a week.
■ As each unit of PROD 1 yields 550¿ contribution to profit and each unit
of PROD 2 yields 600¿ contribution to profit, etc., our total profit
contribution will be represented by the expression:

550x1 + 600x2 + 350x3 + 400x4 + 200x5


■ The objective of the factory is to choose x1 , x2 , . . ., x5 so as to make the
value of this expression as high as possible, that is, the expression is an
objective function that we wish to maximize

3 / ??
Example 1: Model
■ Our processing and labour capacities limit the values the xj can take.
■ As we have 3 grinding machines working for a total of 2 × 8 × 6 = 96
hours a week each, we have 3 × 96 = 288 hours of grinding capacity.
■ Each unit of PROD1 uses 12 hours grinding.
So x1 units will use 12 x1 hours.
■ Similarly, x2 units of PROD2 will use 20 x2 hours.
■ Similarly for PROD3, PROD4, PROD5.
■ The total amount of grinding capacity that we use in a week is

12x1 + 20x2 + 25x4 + 15x5

■ As we have 288 hours of grinding capacity available, the inequality

12x1 + 20x2 + 25x4 + 15x5 ≤ 288

must hold. This inequality is known as a constraint.


It restricts (or constrains) the values that variables xj can take.
4 / ??
Example 1: Model
■ Since we have 2 drilling machines working for 96 hours a week each,
we have 2 × 96 = 192 hours a week of drilling capacity available.

This gives the following constraint:

10x1 + 8x2 + 16x3 ≤ 192


■ As we have 8 assembly workers each working 6 × 8 = 48 hours a week,
the labour capacity is of 8 × 48 = 384 hours.

■ As each unit of each product uses 20 hours of this capacity, we have the
constraint

20x1 + 20x2 + 20x3 + 20x4 + 20x5 ≤ 384

5 / ??
Example 1: Model
We have now expressed our original problem as a mathematical model and is
now a well-defined mathematical object.

■ Maximize profit: max 550x1 + 600x2 + 350x3 + 400x4 + 200x5


■ Subject To:
◆ Respect grinding capacity : 12x1 + 20x2 + 25x4 + 15x5 ≤ 288
◆ Respect drilling capacity: 10x1 + 8x2 + 16x3 ≤ 192
◆ Respect labour capacity: 20x1 + 20x2 + 20x3 + 20x4 + 20x5 ≤ 384

6 / ??
What is a Model
■ Many applications of science make use of models.
The term model is usually used for a structure built with the purpose of
exhibiting characteristics of some other object.
Generally, only some of these features will be retained in the model.

■ In mathematical programming, a model involves a set of mathematical


relationships (such as equations, inequalities and logical dependencies)
that correspond to down-to-earth relationships in the real world (such as
technological relationships, marketing constraints, etc.).

7 / ??
Why Do We Want Models?
There are a number of reasons for building models:
■ To improve understanding.
The actual exercise of building a model often reveals relationships that
were not apparent. As a result, a greater understanding is achieved of the
object being modelled.

■ To allow mathematical analysis.


Having built a model it is usually possible to analyse it mathematically to
help suggest courses of action that might not otherwise be apparent.

■ To allow computational analysis.


Computational experimentation is possible with a model, whereas it is
often not possible or desirable to experiment with the object being
modelled.

8 / ??
Models and Data
■ A model is defined by its relationships, which are independent of the
actual data.

Different coefficients may be used, for example, for costs, resource


availabilities, etc.. But we will still think of it as the same model.

We will make evident this differentation in the lab lectures.

9 / ??
Mathematical vs. Computer Prog.
■ Mathematical programming is different from computer programming.

■ Mathematical Programming is programming in the sense of planning.

■ As such, it need have nothing to do with computers.

■ Inevitably, mathematical programming becomes involved with computing


as practical problems involve large quantities of data that can only be
tackled with of a computer.

■ But the correct relationship between computers and mathematical


programming should be understood.

10 / ??
Components of a Model
■ Mathematical programming models are built on top of symbolic numerical
values called (decision) variables.

■ The mathematical relationships in the model between variables are called


constraints.

■ Usually models involve optimization: we wish to maximize something


(e.g., benefits) or minimize something (e.g., costs).

■ The quantity that we wish to maximize or minimize is known as the


objective function.

11 / ??
Types of Models
■ In this course we will confine our attention to some special types of
mathematical programming models:
◆ linear programming (LP) models

◆ non-linear programming (NLP) models, and

◆ integer linear programming (ILP) models.


■ E.g., in LP the objective function and the left-hand sides of constraints
are all linear expressions (= polynomial of degree 1), as in the example.

■ The linearity assumption of LP is not always warranted in a practical


problem, although it makes any model computationally much easier to
solve.

■ When we have to incorporate non-linear terms in a model (either in the


objective function or the constraints) we obtain a non-linear programming
(NLP) model.
12 / ??
Example 1: Model (II)
Let us consider again the example of the factory. Recall the model:
■ Maximize profit: max 550x1 + 600x2 + 350x3 + 400x4 + 200x5
■ Subject To:
◆ Respect grinding capacity : 12x1 + 20x2 + 25x4 + 15x5 ≤ 288
◆ Respect drilling capacity: 10x1 + 8x2 + 16x3 ≤ 192
◆ Respect labour capacity: 20x1 + 20x2 + 20x3 + 20x4 + 20x5 ≤ 384
■ There are a number of implicit assumptions in this model:
1. We must enforce that the variables x1 , x2 , . . . , x5 are not allowed to
be negative, i.e., we do not make negative quantities of any product.
We could explicitly state these conditions with the extra constraints
x1 , x2 , ..., x5 ≥ 0.
However, in general, in LP models the non-negativity constraints are
implicitly assumed unless stated otherwise.

13 / ??
Example 1: Model (II)
Let us consider again the example of the factory. Recall the model:
■ Maximize profit: max 550x1 + 600x2 + 350x3 + 400x4 + 200x5
■ Subject To:
◆ Respect grinding capacity : 12x1 + 20x2 + 25x4 + 15x5 ≤ 288
◆ Respect drilling capacity: 10x1 + 8x2 + 16x3 ≤ 192
◆ Respect labour capacity: 20x1 + 20x2 + 20x3 + 20x4 + 20x5 ≤ 384
■ There are a number of implicit assumptions in this model:
2. We have assumed that the variables x1 , x2 , . . . , x5 can take fractional
values. This assumption may be appropriate or not. If, for example,
PROD1 represented litres of beer, fractional quantities would be OK.
But if it represented numbers of motor cars, it may not be.
In practice, the assumption that variables can be fractional is
acceptable if the errors involved in rounding to the nearest integer, if
needed, can be afforded. If this is not the case, we must resort to ILP.
But ILP models may be much harder to solve.
13 / ??
Example 2: Problem
A food is manufactured by refining raw oils and blending them together. The
raw oils come in two categories: vegetable oils (VEG1, VEG2) and
non-vegetable oils (OIL1, OIL2, OIL3).
Vegetable oils and non-vegetable oils require different production lines for
refining. It is not possible to refine more than 200 tons of vegetable oil and
more than 250 tons of non-vegetable oils. There is no loss of weight in the
refining process and the cost of refining may be ignored.
There is a technological restriction of hardness in the final product. In the
units in which hardness is measured, this must lie between 3 and 6. We
assume the hardness of final product is the weighted average of hardness of
the raw oils. The hardness of the raw oils and the costs (per ton) and are
VEG1 VEG2 OIL1 OIL2 OIL3
8.8 6.1 2.0 4.2 5.0
110 e 120 e 130 e 110 e 115 e
The final product sells for 150 e per ton.
How should we make the product in order to maximize net profit?
14 / ??
Example 2: Model
■ Variables are introduced to represent the unknown quantities:
◆ x1 , x2 , ..., x5 represent the quantities (tons) of VEG 1, VEG 2, OIL 1,
OIL 2 and OIL 3 that should be bought, refined and blended.
◆ y represents the quantity of the product that should be made.

■ Our objective is to maximize the net profit:

15 / ??
Example 2: Model
■ Variables are introduced to represent the unknown quantities:
◆ x1 , x2 , ..., x5 represent the quantities (tons) of VEG 1, VEG 2, OIL 1,
OIL 2 and OIL 3 that should be bought, refined and blended.
◆ y represents the quantity of the product that should be made.

■ Our objective is to maximize the net profit:


−110x1 − 120x2 − 130x3 − 110x4 − 115x5 + 150y

15 / ??
Example 2: Model
■ Variables are introduced to represent the unknown quantities:
◆ x1 , x2 , ..., x5 represent the quantities (tons) of VEG 1, VEG 2, OIL 1,
OIL 2 and OIL 3 that should be bought, refined and blended.
◆ y represents the quantity of the product that should be made.

■ Our objective is to maximize the net profit:


−110x1 − 120x2 − 130x3 − 110x4 − 115x5 + 150y
■ The refining capacities give the constraints:

15 / ??
Example 2: Model
■ Variables are introduced to represent the unknown quantities:
◆ x1 , x2 , ..., x5 represent the quantities (tons) of VEG 1, VEG 2, OIL 1,
OIL 2 and OIL 3 that should be bought, refined and blended.
◆ y represents the quantity of the product that should be made.

■ Our objective is to maximize the net profit:


−110x1 − 120x2 − 130x3 − 110x4 − 115x5 + 150y
■ The refining capacities give the constraints:
x1 + x2 ≤ 200
x3 + x4 + x5 ≤ 250

15 / ??
Example 2: Model
■ Variables are introduced to represent the unknown quantities:
◆ x1 , x2 , ..., x5 represent the quantities (tons) of VEG 1, VEG 2, OIL 1,
OIL 2 and OIL 3 that should be bought, refined and blended.
◆ y represents the quantity of the product that should be made.

■ Our objective is to maximize the net profit:


−110x1 − 120x2 − 130x3 − 110x4 − 115x5 + 150y
■ The refining capacities give the constraints:
x1 + x2 ≤ 200
x3 + x4 + x5 ≤ 250
■ It is necessary to make sure that the weight of the final product is equal
to the weight of the ingredients:

15 / ??
Example 2: Model
■ Variables are introduced to represent the unknown quantities:
◆ x1 , x2 , ..., x5 represent the quantities (tons) of VEG 1, VEG 2, OIL 1,
OIL 2 and OIL 3 that should be bought, refined and blended.
◆ y represents the quantity of the product that should be made.

■ Our objective is to maximize the net profit:


−110x1 − 120x2 − 130x3 − 110x4 − 115x5 + 150y
■ The refining capacities give the constraints:
x1 + x2 ≤ 200
x3 + x4 + x5 ≤ 250
■ It is necessary to make sure that the weight of the final product is equal
to the weight of the ingredients:
x1 + x2 + x3 + x4 + x5 − y = 0

15 / ??
Example 2: Model
■ Hardness limitations on the final product are imposed by the constraints:

16 / ??
Example 2: Model
■ Hardness limitations on the final product are imposed by the constraints:
(8.8 x1 + 6.1 x2 + 2 x3 + 4.2 x4 + 5 x5 )/y ≤ 6 this looks like non-linear!
(8.8 x1 + 6.1 x2 + 2 x3 + 4.2 x4 + 5 x5 )/y ≥ 3

16 / ??
Example 2: Model
■ Hardness limitations on the final product are imposed by the constraints:
(8.8 x1 + 6.1 x2 + 2 x3 + 4.2 x4 + 5 x5 )/y ≤ 6 this looks like non-linear!
(8.8 x1 + 6.1 x2 + 2 x3 + 4.2 x4 + 5 x5 )/y ≥ 3
i.e.
8.8 x1 + 6.1 x2 + 2 x3 + 4.2 x4 + 5 x5 − 6y ≤ 0
8.8 x1 + 6.1 x2 + 2 x3 + 4.2 x4 + 5 x5 − 3y ≥ 0

16 / ??
Solving Models
■ The software for solving mathematical programming problems is often very
sophisticated and represents many person-years of programming effort.
■ When a mathematical programming model is built, it is usually worth
making use of an existing software to solve it rather than getting diverted
onto the task of programming the computer to solve the model oneself.
■ In the lab lectures we will use one of these packages: IBM ILOG CPLEX

17 / ??
Modeling Languages
■ Mathematical programming packages often include software for helping
users to structure and input their model into the package.
■ These programs use a high level programming language (the modelling
language) to express the models.
■ We will use OPL, which is the modelling language of CPLEX.

18 / ??
Modeling Languages
There are several reasons for modelling languages:
■ A more natural input format. The internal input formats required by most
solvers are designed more with the package in mind than the user.
■ Debugging is made easier. Modelling languages are high level
programming languages.
■ Modification is made easier. Models are often used on a regular basis with
minor modifications, or once built may be used experimentally many times
with small changes in data. The separation of the data from the structure
of the model, common in most modelling languages, facilitates this task.
■ Repetition is automated. Large models usually arise from the combination
or repetition of smaller models, for example, multiple periods, plants or
products. In such circumstances, there will be a lot of repetition of
particular items of data and structure. Modelling languages generally take
account of such repetition very easily.

19 / ??
Models in a Modeling Language
Typical parts of a model in a modelling language:

■ SETS. These usually represent indices for vectors, matrices, ... of decision
variables and data.
■ DATA. These are usually coefficients for the model, which may be defined
in arrays or read from external files. The items in the arrays or files are
often indexed by the indices described above.
■ VARIABLES. These are the decision variables that appear in the model,
typically defined in a vector, matrix, ... The sort of variable
(continuous/integer/binary, free/non-negative, etc.), is usually specified in
the variable declaration.
■ OBJECTIVE FUNCTION. Usually uses notation over index sets for
representing summation compactly.
■ CONSTRAINTS.

20 / ??
Models in a Modeling Language

21 / ??

You might also like