Optimization and Linear Programming Basics
Optimization and Linear Programming Basics
Linear Programming
Outline
• What is optimization?
• Example formulations
• Solution – the basics
• Types of constrained optimization problems
• Linear Programming
– Formulation
– Simplex
– Interior Point Methods
– Duality
• Preview: other optimization types and solution
methods
Elements of Optimization
• Whenever you see or are setting up an optimization
problem, always ask yourself these questions:
• Who is the decision-maker?
• What is their objective? (Or do they have multiple
objectives?)
• What are their decision variables (the things within
the control of the decision-maker)
• What constraints does the decision-maker face?
Elements not within control of the decision maker are the parameters
Constrained Optimization
Mathematical Formulation:
x can be a scalar or a vector Equality
Objective
Constraints
Function min f ( x) s.t.
x
Decision g ( x) = 0 Inequality
Variables h( x ) ≤ 0 Constraints
Objective functions are either minimizing functions or maximizing functions
Decision variables sometimes might not appear in the objective function
Constraints are rules and limits
Example: Filing Cabinets
You need to buy some filing cabinets. You know that Cabinet X
costs $10 per unit, requires six square feet of floor space, and holds
eight cubic feet of files. Cabinet Y costs $20 per unit, requires eight
square feet of floor space, and holds twelve cubic feet of files. You
have been given $140 for this purchase, though you don't have to
spend that much. The office has room for no more than 72 square
feet of cabinets. How many of which model should you buy, in order
to maximize storage volume?
max 8X + 12 Y
Objective here would be to maximize storage
X, Y
Decision maker can control X and Y
constraints (space) 6X + 8Y <=72
This problem is an example of (budget) 10X + 20Y < 140
linear programming Non negativity
constraints X >= 0
Y >= 0
Example: Filing Cabinets
You need to buy some filing cabinets. You know that Cabinet X
costs $10 per unit, requires six square feet of floor space, and holds
eight cubic feet of files. Cabinet Y costs $20 per unit, requires eight
square feet of floor space, and holds twelve cubic feet of files. You
have been given $140 for this purchase, though you don't have to
spend that much. The office has room for no more than 72 square
feet of cabinets. How many of which model should you buy, in order
to maximize storage volume?
max 8𝑥𝑥 + 12𝑦𝑦
𝑥𝑥,𝑦𝑦
Subject to:
10𝑥𝑥 + 20𝑦𝑦 ≤ 140
6𝑥𝑥 + 8𝑦𝑦 ≤ 72
𝑥𝑥, 𝑦𝑦 ≥ 0
Example: Filing Cabinets
Max Z = 8x + 12y
subject to:
10x + 20y <= 140
7
6x + 8y <= 72
6
5
Budget Constraint:
x,y >=0 4
10x + 20y <= 140
3
2
y
-1
-2
-3
0 2 4 6 8 10 12 14 16 18 20
x
Example: Filing Cabinets
Max Z = 8x + 12y
subject to: 10
5
y
Budget Constraint:
3
2
10x + 20y <= 140
1
0
0 5 10 15 20 25
x
Example: Filing Cabinets
Max Z = 8x + 12y
subject to: 10
5
y
Budget Constraint:
3
Feasible Region 2
10x + 20y <= 140
1
All points in the grey region
are feasible, but we don't know 0
0 5 10 15 20 25
Z=72
y
Z=48 3
Budget Constraint:
10x + 20y <= 140
2
Z=24 1
0
0 5 10 15 20 25
x
Example: Filing Cabinets
Max Z = 8x + 12y
subject to: 10
5
Solution to be in a vertex
y
Solution: (8,3) 1
i plants; j markets
Decision variables: x(i,j)
min 2.5𝑥𝑥 1,1 + 1.7𝑥𝑥 1,2 + 1.8𝑥𝑥 1,3 + 2.5𝑥𝑥 2,1 + 1.8𝑥𝑥 2,2 + 1.4𝑥𝑥(2,3)
Example: Transportation Problem
Subject to: ∑x i, j ≥ Dj ∑x
i
i, j ≤ Si xi , j ≥ 0
j
Demand Supply Non-negativity
Constraint Constraint Constraint
Example: Economic Dispatch
Solution:
𝑥𝑥2 = 1 𝑥𝑥1 = 4 𝜆𝜆 = 2
Meaning of Lagrange Multipliers
100
90
80 90-100
80-90
70
70-80
60 60-70
50-60
50
40-50
40 30-40
30 20-30
12 10-20
20 10 0-10
8
10
6
0
0 4
1 2 3 4 5 6
2 Optimum
7 8 9 10 0
11 12 13
Optimum is always in a corner or an edge
Linear Programming Solution Methods
• Simplex Algorithm
– Linear algebra-based method
– Search along edges (constraints) until solution cannot
be improved
• Interior Point Methods
– Approaches optimum from interior point
– Typically uses Newton-Rhapson (i.e., gradient
approach)
• Tradeoffs
– Simplex: each calculation is easy, could take many
– IPMs: each calculation expensive, converges faster
Idea of Nonlinear Programming (NLP)
450
400
350
400-450
350-400
300
300-350
250 250-300
200-250
200
150-200
150 100-150
50-100
7
100 0-50
5
50 3
1
0
-1
-5 -4 -3 -2 -1 0 -3
1 2 3 4 5 6 -5
7 8
Linear Programming Standard Form
Original Problem:
Minimize: 2 x1 + 4 x2
Subject to: x1 + x2 ≥ 3
3 x1 + 2 x2 = 14
x1 ≥ 0
Becomes Elimination of free variables
+ −
Minimize: 2 x1 + 4 x2 − 4 x2 Slack variable
+ −
Subject to: x1 + x2 − x2 − x3 = 3
+ −
3 x1 + 2 x2 − 2 x2 = 14
+ −
x1 , x2 , x2 , x3 ≥ 0
Linear Programming
min 𝑓𝑓 𝑥𝑥
𝑥𝑥
𝑠𝑠𝑠𝑠. 𝑔𝑔 𝑥𝑥 ≥ 0
𝑥𝑥 ∈ 𝑋𝑋
Linear Programming Framework
Standard Form for n variables and m constraints
min 𝑐𝑐 𝑇𝑇 𝑥𝑥
𝑥𝑥
𝑠𝑠𝑠𝑠. 𝐴𝐴𝐴𝐴 ≥ 𝑏𝑏
𝑥𝑥 ≥ 𝟎𝟎
Linear Programming Framework
Standard Form for n variables and m constraints
min 𝑐𝑐 𝑇𝑇 𝑥𝑥
𝑥𝑥
𝑠𝑠𝑠𝑠. 𝐴𝐴𝐴𝐴 ≥ 𝑏𝑏
𝑥𝑥 ≥ 𝟎𝟎
(n x 1)
Linear Programming Framework
Standard Form for n variables and m constraints
(n x 1)
min 𝑐𝑐 𝑇𝑇 𝑥𝑥
𝑥𝑥
𝑠𝑠𝑠𝑠. 𝐴𝐴𝐴𝐴 ≥ 𝑏𝑏
𝑥𝑥 ≥ 𝟎𝟎
(n x 1)
Linear Programming Framework
Standard Form for n variables and m constraints
(n x 1)
min 𝑐𝑐 𝑇𝑇 𝑥𝑥 (m x n)
𝑥𝑥
𝑠𝑠𝑠𝑠. 𝐴𝐴𝐴𝐴 ≥ 𝑏𝑏 (m x 1)
𝑥𝑥 ≥ 𝟎𝟎
(n x 1)
Example
min 𝑐𝑐 𝑇𝑇 𝑥𝑥 max 8𝑥𝑥 + 12𝑦𝑦
𝑥𝑥,𝑦𝑦
𝑥𝑥 Subject to:
𝑠𝑠𝑠𝑠. 𝐴𝐴𝐴𝐴 ≥ 𝑏𝑏 10𝑥𝑥 + 20𝑦𝑦 ≤ 140
𝑥𝑥 ≥ 𝟎𝟎 6𝑥𝑥 + 8𝑦𝑦 ≤ 72
𝑥𝑥, 𝑦𝑦 ≥ 0
Example
min 𝑐𝑐 𝑇𝑇 𝑥𝑥 max 8𝑥𝑥1 + 12𝑥𝑥2
𝑥𝑥,𝑦𝑦
𝑥𝑥 Subject to:
𝑠𝑠𝑠𝑠. 𝐴𝐴𝐴𝐴 ≥ 𝑏𝑏 10𝑥𝑥1 + 20𝑥𝑥2 ≤ 140
𝑥𝑥 ≥ 𝟎𝟎 6𝑥𝑥1 + 8𝑥𝑥2 ≤ 72
𝑥𝑥1 , 𝑥𝑥2 ≥ 0
𝑥𝑥1
𝑥𝑥 = 𝑥𝑥
2
8
𝑐𝑐 =
12
Example
min 𝑐𝑐 𝑇𝑇 𝑥𝑥 max 8𝑥𝑥1 + 12𝑥𝑥2
𝑥𝑥,𝑦𝑦
𝑥𝑥 Subject to:
𝑠𝑠𝑠𝑠. 𝐴𝐴𝐴𝐴 ≥ 𝑏𝑏 10𝑥𝑥1 + 20𝑥𝑥2 ≤ 140
𝑥𝑥 ≥ 𝟎𝟎 6𝑥𝑥1 + 8𝑥𝑥2 ≤ 72
𝑥𝑥1 , 𝑥𝑥2 ≥ 0
8 𝑇𝑇 𝑥𝑥1 −8 𝑇𝑇 𝑥𝑥1
max 𝑥𝑥2 = min 𝑥𝑥2
12 −12
Linear Programming in MATLAB
In General: In MATLAB only:
min 𝑐𝑐 𝑇𝑇 𝑥𝑥 min 𝑐𝑐 𝑇𝑇 𝑥𝑥
𝑥𝑥 𝑥𝑥
𝑠𝑠𝑠𝑠. 𝐴𝐴𝐴𝐴 ≥ 𝑏𝑏 𝑠𝑠𝑠𝑠. 𝐴𝐴𝐴𝐴 ≤ 𝑏𝑏
𝑥𝑥 ≥ 𝟎𝟎 𝑥𝑥 ≥ 𝟎𝟎
x = linprog(f,A,b)
𝑇𝑇
min 𝑧𝑧 = 𝑐𝑐 𝑥𝑥
𝑥𝑥
𝐴𝐴 𝑥𝑥 ≥ 𝑏𝑏
𝑥𝑥 ≥ 𝟎𝟎
At the optimal solution, if the constraint is non-binding, the shadow price will be 0 because there
is no cost to relaxing the constraint. The solution is already beating the constraint
Advertising Problem LP
𝑥𝑥1
min 𝑧𝑧 = 𝑐𝑐 𝑇𝑇 𝑥𝑥2
𝑥𝑥
𝑥𝑥1
𝐴𝐴 𝑥𝑥2 ≥ 𝑏𝑏
𝑥𝑥1
𝑥𝑥2 ≥ 𝟎𝟎
Advertising Problem LP
𝑥𝑥1
min 𝑧𝑧 = 𝑐𝑐 𝑇𝑇 𝑥𝑥2
𝑥𝑥
7 2 𝑥𝑥1 28
𝑥𝑥2 ≥
2 12 24
𝑥𝑥1
𝑥𝑥2 ≥ 𝟎𝟎
Advertising Problem LP
𝑥𝑥1
min 𝑧𝑧 = 50 100 𝑥𝑥2
𝑥𝑥1,𝑥𝑥2
7 2 𝑥𝑥1 28
𝑥𝑥2 ≥
2 12 24
𝑥𝑥1 0
𝑥𝑥2 ≥
0
Advertising Problem Solution
∗
∗ 𝑥𝑥1 3.6
• 𝑥𝑥 = ∗ = The asterick denotes the optimal solution
𝑥𝑥2 1.4
• 𝑧𝑧 ∗ = 𝑐𝑐 𝑇𝑇 𝑥𝑥 ∗
𝑥𝑥1∗
= 50 100 ∗
𝑥𝑥2
= 320
= 320,000
Q: When will an LP have a solution?
LP Standard Form
𝑇𝑇
min 𝑐𝑐 𝑥𝑥
𝑥𝑥
𝑠𝑠𝑠𝑠. 𝐴𝐴𝐴𝐴 ≥ 𝑏𝑏
𝑥𝑥 ≥ 𝟎𝟎
- Each constraint in 𝐴𝐴𝐴𝐴 ≥ 𝑏𝑏 marks a half-space
- All constraints result in a polyhedron P = 𝑥𝑥 𝐴𝐴𝐴𝐴 ≥ 𝑏𝑏 , 𝑥𝑥 ≥ 𝟎𝟎}
- Every point within P is feasible
- 𝑥𝑥 ∗ is at one of the vertices of P
LP Geometry 101
Exhaustive Search LP Solver