LP Modeling I (SS 2022)
Introduction to LP Modeling
Johanna Mlekusch
[Link]@[Link]
What is Linear Programming?
Linear Programming
Problem solving approach for minimizing (or maximizing) a linear objective
function subject to linear equality and inequality constraints
Linear: All mathematical functions in the model are required to be linear
functions
Programming: Not in the sense of computer programming; here rather a
synonym for planning → planning of activities to obtain an optimal result
What is Linear Programming Used For?
Assignment problem
Packing problems
Lot-Sizing
Max flow Transportation problem
Scheduling
Shortest path Traveling salesman problem
and many, many more…
General LPs
The following is a LP problem:
Objective
Inequality
constraints
Equality
constraints
Non-negativity
constraint
Modeling
• Usually the LP is not given and has to be extracted from
information
• Translation from a verbal description of the problem into a
mathematical one
LP Modeling
• Often there are different ways to model a problem
• The mathematical formulation of the problem decides which
solution methods can be applied
Modeling
Practical modeling Mathematical
problem model
compatible? methodologies
Practical implementation Mathematical
solution solution
The Burglar Problem
• Pete, the burglar, sees 10 items of different weight and different
value.
• He can not carry all of the items, only up to a certain total ????
weight.
• Which items should he take?
Model Formulation
• Understand the problem thoroughly
What does the decision maker want to achieve with the
present model?
What instruments does the decision maker have?
What are the objectives?
What are the constraints?
What data is available?
Decision Variables and Parameters
Decision Variables
• Quantities a decision maker would like to determine
• Examples: production quantity, current size of the inventory, starting time of activity, …
• Decision variables might be measured in different units → compatibility?
• Let us assume is a decision variable. can for example be either
• a real number ()
• an integer () : all-integer problems (IP LPs), mixed-integer problems (MIP LPs)
• a binary variable with
• Size of decision variable can be restricted
Parameter
• Exogenously given (e.g. value of an item, capacity of an inventory, …), known and constant
General LPs
Decision variables (unknown)
Parameters (known)
s.t.
0
0
Notation is important,
it can make working with LPs more efficient!
General LPs
s.t.
s.t.
0
0 0
0
Notation is important,
it can make working with LPs more efficient!
The Burglar Problem
• A burglar sees 10 items of different weight and different value.
• He can not carry all of the items, bag holds only up to a certain
total weight.
????
• Which items should he take?
Step 1: Determine the decision variables and parameters
… set of items
… (binary) decision variable (take item?),
… value of item i,
… weight of item i,
… maximum weight that can be transported in bag
The Burglar Problem
• Step 2: Determine the objective
max ∑ 𝑣 𝑖 ∙ 𝑥 𝑖 ????
❑ 𝑖∈𝐼 … maximize the profit
• Step 3: Determine the constraints
∑ 𝑤 𝑖 𝑥 𝑖❑ ≤ 𝑊 … sum of the weight of the stolen items must be
𝑖∈𝐼
lower than maximum capacity W
for all
𝑥𝑖 ∈ { 0 , 1 } , ∀ 𝑖 ∈ 𝐼 … item i is either stolen () or it is not ()
( must be binary)
• Further steps: Implement the model, solve the problem,…
Why are we discussing this?
• Please be careful when you write down a model:
• A good notation saves time, it helps you to read ????
(and implement) the problem more easily
• Be consistent and precise!
• This model is actually relevant in supply chain
management / logistics.
Model Formulation & Interpretation
• The burglar problem is a so-called knapsack (or rucksack)
problem
!!!!!
• Different application: A firm needs to decide which items it
wants to transport in a certain truck.
Mathematical models can often be interpreted in various
manners / are often similar from a formal point of view
Understanding one problem can often help to solve others
Model Formulation
One can also write down the same problem in different manners, e.g.
Maximization problem as minimization problem (and vice versa)
Inequality constraint as equality constraint (and vice versa)
Approximate a non-linear function by linear functions
…
A well-considered model formulation can make solving a problem easier
and/or more efficient!
General LPs
s.t.
s.t.
0
0 0
0
Notation is important,
it can make working with LPs more efficient!
General LPs
( )
𝑥1
′
𝑥 =( 𝑥 1 , … , 𝑥 𝑛 ) ⇔ 𝑥 = ⋮
𝑥𝑛
(e.g. is the set of inequalities with ,
is the set of equality constraints here)
LP in general form…
∀
∀
∀
∀
∀
General LPs
Consider the LP problem from before: LP in general form…
∀
∀
∀
∀
∀
s.t. 𝑥=( 𝑥 1 , 𝑥 2 , 𝑥 3 , 𝑥 4 ) ′ 𝑐= ( 2, −1 , 4 , 0 ) ′
→ ={3}, ={1}, ={2},
0 ={1}, ={3},
0
Constraints
How to express an equality constraint in terms of inequality constraints?
Create two inequalities, which have to hold at the same time:
∙ ( −1)
To only have inequalities, where the l.h.s. is larger than the right hand side,
multiply second constraint by -1:
Matrix notation
Matrix notation of an LP problem, e.g.
Matrix notation
Example: transform the previous LP to a form such that
you only have inequalities with ≥
Matrix notation
Example: transform the previous LP to a form such that
you only have inequalities with ≥
Matrix notation
Example: transform the previous LP to a form such that
you only have inequalities with ≥
min 2 𝑥1 − 𝑥 2+ 4 𝑥 3
− 𝑥 1 − 𝑥 2 − 𝑥4 ≥− 2
3 𝑥 2 − 𝑥 3 ≥5
−3 𝑥 2 + 𝑥3 ≥ −5
𝑥 3+ 𝑥 4 ≥ 3
𝑥1 ≥ 0
− 𝑥3 ≥ 0
Matrix notation
Example: transform the previous LP to a form such that
you only have inequalities with ≥
min 2 𝑥1 − 𝑥 2+ 4 𝑥 3
− 𝑥 1 − 𝑥 2 − 𝑥4 ≥− 2
3 𝑥 2 − 𝑥 3 ≥5
−3 𝑥 2 + 𝑥3 ≥ −5
𝑥 3+ 𝑥 4 ≥ 3
𝑥1 ≥ 0
− 𝑥3 ≥ 0
Matrix notation
Example: transform the previous LP to a form such that
you only have inequalities with ≥
min 2 𝑥1 − 𝑥 2+ 4 𝑥 3 ‘
− 𝑥 1 − 𝑥 2 − 𝑥4 ≥− 2 𝑐= ( 2, −1 , 4 , 0 ) ′
3 𝑥 2 − 𝑥 3 ≥5
𝑏=( −2 , 5 , −5 , 3 , 0 ,0 ) ′
−3 𝑥 2 + 𝑥3 ≥ −5
( )
𝑥 3+ 𝑥 4 ≥ 3 −1 −1 0 −1
𝑥1 ≥ 0 0 3 −1 0
− 𝑥3 ≥ 0 𝐴= 0 −3 1 0
0 0 1 1
1 0 0 0
0 0 −1 0
Standard form of an LP problem (in matrix notation)
Standard form…
• only equality constraints
• only non-negative variables
Reduction to Standard Form
General form: Standard form:
Standard form
Eliminating free variables…
free variables are neither in
N1 nor in N2
Standard form
Eliminating free variables…
Essentially, you redefine the decision variable
Example: Imagine is the balance of your bank account (which can be
negative).
replace by the amount of money you own minus the debt .
Balance
100 100 0
-200 0 200
Standard form
Eliminating inequality constraints…
Introduce slack/surplus variables which tell you how much smaller/larger is the left hand side of the
inequality compared to the right hand side
1. Slack variables
2. Surplus variables
Slack and surplus variables are decision variables!
Standard form
Example: transform the LP
below to standard form
Standard form
Example: transform the LP
below to standard form
−
𝑥 2= 𝑥+2 ¿ − 𝑥 2 ¿
𝑥 =¿
𝑐= ( 2, 4 , − 4 , 0 )
𝐴=
(13 1
2
−1
−2
−1
0 )
𝑏=( 3 , 14 )′
Standard form
Get rid of non-positive decision variables:
𝑥3≤ 0 −
𝑥 3 =− 𝑥3
𝑥−
3 ≥0
Minimization vs. maximization
Any minimization problem can be transformed into a
maximization problem and vice versa.
minimize
maximize -
Absolute values
Absolute values
Can be written as:
Or:
¿
Absolute values
Idea: Find the smallest number z that is larger than x as well as larger than –x
(i.e. z satisfies z ≥ x and z ≥ -x ) . |x| is equal to z.
min z s.t. z ≥ x and z ≥ -x
|x| z
x x
Absolute values
Can be written as:
Absolute values
Core idea:
¿
Redefine decision variables (see bank account example)
Balance
100 100 100 0
-200 200 0 200
=-
=
Absolute values
Example. Reformulate:
−
−𝑥
𝑥1 = 𝑥+¿ 1 ¿
1
min 2 𝑧 + 𝑥 2
−
+ ¿ +2 𝑥 + 𝑥 2 ¿
min 2 𝑥1 1
𝑥1 + 𝑥 2 ≥ 4
𝑥1
−
+ ¿ − 𝑥 1 + 𝑥2 ≥ 4 ¿ 𝑧 ≥ 𝑥1
𝑧 ≥ − 𝑥1
−
¿, 𝑥
𝑥+ 1 ≥0 ¿
1
Example: Production Problem
A firm produces n different goods using m different raw materials
Let bi , i=1…m, be the available amount of the ith raw material
The jth good, j=1...n, requires aij units of the ith raw material
The jth good, j=1...n, results in a revenue of cj per unit produced.
How much of each good to produce to maximize total revenue?
Example: Production Problem
Example: Production Problem
Product A Product B Available
Raw material I 1 3 24
Raw material II 1 1 10
Raw material III 2 1 18
Revenue 100 200
Example: Production Problem – Graphical Solution
How to draw a line / inequalities
The area for which the inequality holds is bounded by
Approach 1:
Find the points where the line intersects with the axes and connect the points. (I.e. set , then you
get ; Point 1: (0, ), set y, then you get Point 2: ( ), connect points 1 and 2.
Now you can draw the line.
()
On which side of the line is the feasible area?? 𝑥
How steep is the line?? (0, )
How to draw a line / inequalities
Approach 2:
(better approach for the graphical solution of LPs)
Rewrite the inequality as or
𝑦
→ Only values of which are greater than are admissible.
The line bounds the feasible area.
𝑥
Slope of the line:
Intersection of the line with y-axis:
Feasibility
Solution
Any specification of values for all decision variables, regardless of whether it is a
desirable or even allowable choice
Feasibility
• Feasible (admissible) solution: all constraints are fulfilled
• Infeasible solution: at least one constraint is violated
Feasible region:
Feasible
region
• Collection of all feasible solutions
Obviously: An optimal solution must be feasible, but a feasible solution does not
have to be optimal
Example: Production Problem – Graphical Solution
= gives a line with profit Z
Consider value of the objective at the
corners of the feasible region
Optimal solution:
,
𝑍 =1600
𝑍 =1700
Feasible
region 𝑍 =1200
𝑍 =0
𝑍 =900
Slope =
()
Example: Production Problem – Graphical Solution
𝑍 =1700
binding at (3,7)
Feasible
region Optimal solution:
,
non-binding at (3,7)
A constraint can be
• binding / active at the optimal solution point
• non-binding / in-active at the optimal solution point
• redundant e.g.
Example: Production Problem – Graphical Solution
Consider value of the objective at the
corners of the feasible region
𝑍 =100 𝑥1 +200 𝑥 2
Slope =
Slope = 𝑍 =1700
𝑍 =1600
Slope =
Feasible 𝑍 =1200
region
𝑍 =0
𝑍 =900
Feasible
region At the optimal solution the line =
𝑍 =0 does not enter the feasible region, it just touches
it
Slope =
Example: Production Problem – Graphical Solution
Consider value of the objective at the
corners of the feasible region
Slope = Corner point can only be optimal if the slope is
between the two slopes of the constraint
Slope = restricting the feasible region of the point
Slope =
E.g. , is optimal, one can observe at this point --
1
If we consider another objective with and , then
Feasible =-1.5, comparing the slopes of the constraints
region we find --2 implying that the intersection point
𝑍 =0 between the yellowish and the black constraint ,
2 is optimal
Slope =
Example: Production Problem – Graphical Solution
Consider a different objective 𝑍 =100 𝑥1 +100 𝑥 2
𝑍 ∗ =1000
Feasible
region
Any point on the red line has the same objective value and is optimal
LP solutions
The following can happen when solving a LP:
(a) Unique optimal solution
(b) Multiple optimal solutions (bounded or unbounded set)
(c) Objective value is ∞ and no feasible solution is optimal
(d) The feasible set is empty (the LP is then infeasible)
Infeasibility
6
6
2
𝑥1 ≥ 4
4 𝑥1 +2 𝑥 2 ≤ 8
2 4 6 8
No point fulfills all of the constraints
No feasible solution
Objective Value is Infinite
s.t. 6
0
4
2
𝑥1 ≤ 4
2 4 6 8
One can always increase the profit by increasing
A Bin Packing Example
We want to find the minimum number of vehicles required to transport all the
parcels demanded by customers.
Set of V parcels
weight of parcel i V
Vehicle capacity Q
Upper bound on number of vehicles M
A Bin Packing Example
Set of V parcels
weight of parcel i W
Vehicle capacity Q
Upper bound on number of vehicles M
Decision variable {0,1} j {1..M} Is vehicle j used or not
Decision variable {0,1} i V, j {1..M} is parcel i in vehicle j
j {1..M}
V, j {1..M}
A Scheduling Example
A hospital wants to make a weekly night shift schedule for its nurses
The demand for nurses for the night shift on day j is an integer dj, j=1…7:
d1 5
Every nurse works 4 days in a row on the night shift
d2 4
(and then off 3 days)
d3 5
What is the minimal number of nurses
d4 3
the hospital needs to hire?
d5 5
d6 7
d7 8
Nurse Scheduling Example
Decision variable: …. Number of nurses starting their shift on day i, i=1,…,7
Outlook
• Homework 1
• Due March 10th 945 (Hard deadline)
• Solution will be uploaded on March 10th at 1300
????
• Install Xpress