1b. Linear Programming Models
1b. Linear Programming Models
• Some solvers also handle non-linear problems, with fairly good results
on special cases (quadratic models).
Introductory Example
• SilComputers makes quarterly decisions about their
product mix. While their full product line includes hundreds
of products, we will consider a simpler problem with just
two products: notebook computers and desktop
computers.
𝒙𝟏 + 𝒙𝟐 ≤ 𝟏𝟎 CPU availability
𝒙𝟏 + 𝟐𝒙𝟐 ≤ 𝟏𝟓 Memory availability
𝟒𝒙𝟏 + 𝟑𝒙𝟐 ≤ 𝟐𝟓 Production time
Thousands of produced
𝒙𝟏 ≥ 𝟎, 𝒙𝟐 ≥ 𝟎
computers
Linear Programming Models
• Models are useful in their own right: they
allow for a formal definition of a problem and
can be useful in thinking about a problem.
• Linear programming models are particularly
useful because we have efficient solvers able
to handle them for obtaining the optimal
decision values.
• In our example (2 variables), it is possible to
solve the problem graphically.
Constraints and feasible region
Finding the optimal profit
We include the objective function on the diagram
by drawing iso-profit lines: lines along which the
profit is the same.
Since our goal is to maximize the profit, we can
push the line out until moving it any further would
result in no feasible point. This happens at point X.
The optimal solution is found at the intersection of the
two constraints:
𝒙 + 𝟐𝒙𝟐 ≤ 𝟏𝟓
ቊ 𝟏
𝟒𝒙𝟏 + 𝟑𝒙𝟐 ≤ 𝟐𝟓
• The newspaper is printed in three printing houses P1, P2 and P3 that print
daily 125000, 180000 and 70000 copies of the newspaper respectively .
• It is known that the shipping costs are 0.1 EUROS/Km (for a single copy of
the newspaper). The distances between printing houses and distribution
centers are 20, 25, 15 and 5 Km. respectively for
• the first printing houses, 12, 14, 18 and 30 Km. respectively for the
• second printing house and 19, 11, 40 e 12 Km. respectively for the third
printing house.
𝑥𝑖𝑗 ≥ 𝐵𝑗 ∀𝑗 = 1, . . , 𝐷
𝑖=1
𝑛
𝑥𝑖𝑗 ≤ 𝐴𝑖 ∀𝑖 = 1, . . , 𝑆
𝑗=1
Trasportation problem
𝑆 𝐷
In this general form, this is
min 𝑐𝑖𝑗 𝑥𝑖𝑗 called the
𝑖=1 𝑗=1
𝑛
TRANSPORTATION PROBLEM
𝑥𝑖𝑗 ≥ 𝐵𝑗 ∀𝑗 = 1, . . , 𝐷
𝑖=1 Another quite famous
𝑛
problem in the combinatorial
𝑥𝑖𝑗 ≤ 𝐴𝑖 ∀𝑖 = 1, . . , 𝑆
optimization field.
𝑗=1
A motel problem
A motel problem
A multi-period production problem
A firm is planning the production for the next four months.
It is known the there is currently no inventory and it is required to have
no inventory at the end of the four months.
Formulate a Linear Programming model of this problem minimizing the
total production and inventory cost and satisfying sales forecast and
production capacity constraints.
Variables 𝑥𝑖 ∈ 𝑍 +
xi: production quantity - month i
zi: inventory level at the end of month i 𝑧𝑖 ∈ 𝑍 +
z1 = x1 − 20
z 2 = x2 + z1 − 30
z3 = x3 + z 2 − 50
0 = x4 + z3 − 40
x1 40 x2 50 x3 30 x4 50
• Note that the constraints which impose
that the production is enough for the
demand at each months should have been:
x1 20
x2 + z1 30
x3 + z 2 50
x4 + z3 = 40
The available production capacity is now not enough for serving the
demand (previous model would result in an infeasible solution result).
The company has the option to activate overtime work. The cost for the
activation is 500, and in case of activation, 10 additional item are
produced in the month.
Variables 𝑥𝑖 ∈ 𝑍 +
xi: production quantity - month i
yi: overtime production activated (1) or not (0). 𝑧𝑖 ∈ 𝑍 +
zi: inventory level at the end of month i 𝑦𝑖 ∈ {0,1}
subject to
𝑧1 = 𝑥1 + 10𝑦1 − 30
𝑧2 = 𝑥2 + 10𝑦2 + 𝑧1 − 50
𝑧3 = 𝑥3 + 10𝑦3 + 𝑧2 − 60
0 = 𝑥4 + 10𝑦4 + 𝑧3 − 50
x1 40 x2 50 x3 30 x4 50
A multi-period production problem
Consider the following additional constraints to the previous model:
• For each month, the production must be at least the 10% of the total
production over the 4 months.
x1 0.1( x1 + 10 y1 + x2 + 10 y2 + x3 + 10 y3 + x4 + 10 y4 )
x2 0.1( x1 + 10 y1 + x2 + 10 y2 + x3 + 10 y3 + x4 + 10 y4 )
x3 0.1( x1 + 10 y1 + x2 + 10 y2 + x3 + 10 y3 + x4 + 10 y4 )
x4 0.1( x1 + 10 y1 + x2 + 10 y2 + x3 + 10 y3 + x4 + 10 y4 )
A production planning problem
• A given product is composed by three parts that can be processed
on four different production lines. Each production line has a
limited capacity in terms of available production hours.
• The following table indicates the number of parts produced per
hour by each production line with respect to each part together
with the capacity (in hours) of each production line.
• Formulate a Linear Programming model of this problem maximizing
the number of product units.
A production planning problem
10 x11 + 15 x21 + 20 x31 + 10 x41 ,
max min 15 x12 + 10 x 22 + 5 x 32 + 15 x 42
,
5 x + 5 x + 10 x + 20 x
13 23 33 43
max min{𝑒1 , … , 𝑒𝑛 }
max 𝑦
𝑦 ≤ 𝑒1
𝑦 ≤ 𝑒2
…
𝑦 ≤ 𝑒𝑛
Min-Max
• Consider a generic PL model in which the objective function is the
following form (e1,..en are linear expressions of the control
variables):
min max{𝑒1 , … , 𝑒𝑛 }
min 𝑦
𝑦 ≥ 𝑒1
𝑦 ≥ 𝑒2
…
𝑦 ≥ 𝑒𝑛
Min-Abs
• Consider a generic PL model in which the objective function
is the following form (e is a linear expressions of the control
variables):
min |𝑒|
min 𝑦
𝑦≥𝑒
𝑦 ≥ −𝑒
A production planning problem
Actually, the model could have been simpler adding
the following assumption:
𝑆2 ≥ 𝑆1 + 5
𝑆3 ≥ 𝑆2 + 7
𝑆4 ≥ 𝑆3 + 4
𝑆5 ≥ 𝑆4 + 7
𝑆𝑖 ≥ 0 ∀𝑖
In order to linearize the objective function, we can introduce 5 variables, one for each
absolute value, and, accordingly, the additional constraints.
Just in time production
𝑆𝑖 = 𝑠𝑡𝑎𝑟𝑡𝑖𝑛𝑔 𝑡𝑖𝑚𝑒 𝑓𝑜𝑟 𝑙𝑜𝑡 𝑖 (𝑖𝑛 𝑚𝑖𝑛𝑢𝑡𝑒𝑠 𝑎𝑓𝑡𝑒𝑟 0.00. 𝐹𝑜𝑟 𝑒𝑥𝑎𝑚𝑝𝑙𝑒, 10.00 𝑖𝑠 600)
min 𝑦1 + 𝑦2 + 𝑦3 + 𝑦4 + 𝑦5
• Roses, daisies and gerania are available in small, medium and large size, whilst
there are available 250 lilies only all in small size.
• The cost of a rose is 2, 3 and 4 EUROS respectively (small, medium and large size).
• The cost of a daisy is 1.5, 2 and 2.5 EUROS (small, medium, large size).
• The cost of a geranium is 1.5, 2.5 and 3 EUROS (small, medium, large size).
• The cost of a small lily is 2.5 EUROS.
• Costs:
– Rose: 2, 3 and 4 EUROS respectively (small, medium and large size).
– Daisy: 1.5, 2 and 2.5 EUROS (small, medium, large size).
– Geranium: 1.5, 2.5 and 3 EUROS (small, medium, large size).
– Small lily: 2.5 EUROS.
𝑥𝑖𝑗 ∈ 𝑍 +
𝑥𝑖𝑗 = 𝑓𝑙𝑜𝑤𝑒𝑟𝑠 𝑜𝑓 𝑡𝑦𝑝𝑒 𝑖 ∈ 𝑅, 𝐷, 𝐺, 𝐿 𝑜𝑓 𝑠𝑖𝑧𝑒 𝑗 ∈ {𝑆, 𝑀, 𝐿}
min 2𝑥𝑅𝑆 + 3𝑥𝑅𝑀 + 4𝑥𝑅𝐿 + 1.5𝑥𝐷𝑆 + 2𝑥𝐷𝑀 + 2.5𝑥𝐷𝐿 +1.5𝑥𝐺𝑆 + 2.5𝑥𝐺𝑀 + 3𝑥𝐺𝐿 +2.5𝑥𝐿𝑆
𝑥𝐿𝑆 ≤ 250
𝑥𝑅𝑆 + 𝑥𝐷𝑆 + 𝑥𝐺𝑆 + 𝑥𝐿𝑆 = 𝑥𝑅𝑀 + 𝑥𝐷𝑀 + 𝑥𝐺𝑀 = 𝑥𝑅𝐿 + 𝑥𝐷𝐿 + 𝑥𝐺𝐿
𝑦𝐺 + 𝑦𝐷 ≤ 1
«Big M» constraints
• A «Big M» constraint is useful for defining a
relationship between a continuous or integer variable
x and the binary variable y similar to the following:
1 𝑖𝑓 𝑥 > 0
𝑦=ቊ
0 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
• The constraint is:
𝑥 ≤ 𝑀𝑦
where M is a constant with a value large enough to
take any possible value of x.
«Big M» constraints
• Big-M formulations are relatively straightforward,
but the value of the M term needs to be chosen
carefully. If M is smaller than the upper bound of
x, this situation may cut off valid solutions. If M is
too large, the model may become numerically
difficult.
• In the case of the previous exercise, 1300 is a
good value of M, because it’s, for the problem
description, the maximum value the variable x
can take.
«Big M» constraints
X=0 X>0
𝑥 ≤ 𝑀𝑦 Y=0 Feasible NO
Y=1 Feasible Feasible
• Note that above constraint does not work EXACTLY like defined 2 slides back.
• The situation which can cause problems is the one in which y=1 and still x=0.
• Usually, variable y will represent some kind of cost in the objective function.
• In this cases, in the optimal solution, y will be set only if there is the real need of
activating variable x.
• In order to impose a double-side property (x=0 y=0 and x>0 y=1), the
following constraint must be added to the above one, where m is a small number
(in case x is integer, m can be set to 1).
𝑚𝑦 ≤ 𝑥
Small-m constraints
• As an example, consider x as the variable defining how
much we produce of something, and that we have a setup
cost s for activating the production of that product.
y≤x
Logic constraints
• When using binary variables, it is often
possible to write logic operators in form of
a linear inequality:
Another production planning example
• 4 products (A,B,C,D).
• Production can be activated or not. If it is activated, there’s a fixed
activation cost, and the factory must produce a minimum quantity.
• Each product require a certain workforce (total available is 200.000)
and provide a profit.
• In the case the production of A is activated, the factory must
activate at least one between C and D.
It is a valid
mathematical
formulation, but it
is
NON LINEAR (x
and y variables
min 50𝑥𝑎 − 14500 𝑦1 + (… )
cannot be
multiplied
between each
other)!