Introduction LP (Incl Graphical Solution)
Introduction LP (Incl Graphical Solution)
Introduction to LP Modeling
Johanna Mlekusch
[email protected]
What is Linear Programming?
Linear Programming
Assignment problem
Packing problems
Lot-Sizing
Scheduling
Objective
Inequality
constraints
Equality
constraints
Non-negativity
constraint
Modeling
LP Modeling
compatible? methodologies
Decision Variables
Parameter
• Exogenously given (e.g. value of an item, capacity of an inventory, …), known and constant
General LPs
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
… set of items
… value of item i,
… weight of item i,
… maximum weight that can be transported in bag
The Burglar Problem
max ∑ 𝑣 𝑖 ∙ 𝑥 𝑖 ????
❑ 𝑖∈𝐼 … maximize the profit
One can also write down the same problem in different manners, e.g.
…
s.t.
s.t.
0
0 0
0
Notation is important,
it can make working with LPs more efficient!
General LPs
( )
𝑥1
′
𝑥 =( 𝑥 1 , … , 𝑥 𝑛 ) ⇔ 𝑥 = ⋮
𝑥𝑛
LP in general form…
∀
∀
∀
∀
∀
General LPs
∀
∀
∀
∀
∀
s.t. 𝑥=( 𝑥 1 , 𝑥 2 , 𝑥 3 , 𝑥 4 ) ′ 𝑐= ( 2, −1 , 4 , 0 ) ′
→ ={3}, ={1}, ={2},
0 ={1}, ={3},
0
Constraints
∙ ( −1)
To only have inequalities, where the l.h.s. is larger than the right hand side,
multiply second constraint by -1:
Matrix notation
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
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
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
Balance
100 100 0
-200 0 200
Standard form
2. Surplus variables
𝑥 2= 𝑥+2 ¿ − 𝑥 2 ¿
𝑥 =¿
𝑐= ( 2, 4 , − 4 , 0 )
𝐴=
(13 1
2
−1
−2
−1
0 )
𝑏=( 3 , 14 )′
Standard form
𝑥3≤ 0 −
𝑥 3 =− 𝑥3
𝑥−
3 ≥0
Minimization vs. maximization
minimize
maximize -
Absolute values
Absolute values
¿
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.
x x
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
The jth good, j=1...n, requires aij units of the ith raw material
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.
()
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)
Solution
Any specification of values for all decision variables, regardless of whether it is a
desirable or even allowable choice
Feasibility
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
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
𝑍 =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
Slope =
E.g. , is optimal, one can observe at this point --
1
Slope =
Example: Production Problem – Graphical Solution
𝑍 ∗ =1000
Feasible
region
Any point on the red line has the same objective value and is optimal
LP solutions
6
6
2
𝑥1 ≥ 4
4 𝑥1 +2 𝑥 2 ≤ 8
2 4 6 8
s.t. 6
0
4
2
𝑥1 ≤ 4
2 4 6 8
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
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
• Homework 1
• Due March 10th 945 (Hard deadline)
• Solution will be uploaded on March 10th at 1300
????
• Install Xpress