CSC373 Week 6: Linear Programming
373F20 - Nisarg Shah 1
Illustration Courtesy: Kevin Wayne & Denis Pankratov
Linear Programming Illustration Courtesy: Kevin Wayne & Denis - - PowerPoint PPT Presentation
CSC373 Week 6: Linear Programming Illustration Courtesy: Kevin Wayne & Denis Pankratov 373F20 - Nisarg Shah 1 Announcement ACM ICPC Qualification Round Oct 24, 3-8pm EST Sign up at: https://www.teach.cs.toronto.edu/~acm/
373F20 - Nisarg Shah 1
Illustration Courtesy: Kevin Wayne & Denis Pankratov
373F20 - Nisarg Shah 2
regional contest (broken into three teams of 3 each)
373F20 - Nisarg Shah 3
➢ Ford-Fulkerson algorithm
➢ Correctness using max-flow, min-cut ➢ Applications:
373F20 - Nisarg Shah 4
into producing some amount of ale and some amount of beer
➢ Per unit resource requirement and profit of the two items are as
given below
Example Courtesy: Kevin Wayne
373F20 - Nisarg Shah 5
this program:
373F20 - Nisarg Shah 6
➢ Example: 𝑔 𝑦1, 𝑦2 = 3𝑦1 − 5𝑦2 =
3 −5 𝑈 𝑦1 𝑦2
➢ 𝑦 = 𝑑, where : ℝ𝑜 → ℝ is a linear function and 𝑑 ∈ ℝ ➢ Line in the plane (or a hyperplane in ℝ𝑜) ➢ Example: 5𝑦1 + 7𝑦2 = 10
373F20 - Nisarg Shah 7
hyperplane) represented by 𝑏𝑈𝑦 = 𝑑
373F20 - Nisarg Shah 8
373F20 - Nisarg Shah 9
equality/inequality constraints
373F20 - Nisarg Shah 10
373F20 - Nisarg Shah 11
373F20 - Nisarg Shah 12
vertex that is an optimal solution
373F20 - Nisarg Shah 13
373F20 - Nisarg Shah 14
𝑦, 𝑧 ∈ 𝑇, 𝜇 ∈ [0,1] ⇒ 𝜇𝑦 + 1 − 𝜇 𝑧 ∈ 𝑇
combination of any two points in the set
373F20 - Nisarg Shah 15
➢ Start at some point 𝑦 in the feasible region ➢ If 𝑦 is not a vertex:
both 𝑒 and −𝑒 directions are within the feasible region
more constraint is “tight”
➢ Repeat until we are at a vertex
373F20 - Nisarg Shah 16
➢ There are 𝑜 variables and 𝑛 constraints
373F20 - Nisarg Shah 17
➢ There are 𝑜 variables and 𝑛 constraints
373F20 - Nisarg Shah 18
➢ Constraints that use ≥
➢ Constraints that use equality
➢ Objective function is a minimization
➢ Variable is unconstrained
every occurrence of 𝑦 with 𝑦′ − 𝑦′′, and add constraints 𝑦′ ≥ 0, 𝑦′′ ≥ 0
373F20 - Nisarg Shah 19
373F20 - Nisarg Shah 20
large (for maximization) or small (for minimization)
must be a vertex which is optimal
373F20 - Nisarg Shah 21
373F20 - Nisarg Shah 22
373F20 - Nisarg Shah 23
Start at a vertex of feasible polytope Move to a neighbor vertex with better
Terminate, declare the current solution and value as optimal Is there a neighbor vertex with better
373F20 - Nisarg Shah 24
➢ Convenient for implementing simplex operations ➢ We want to maximize 𝑨 in the slack form, but for now, forget about
the maximization objective
373F20 - Nisarg Shah 25
373F20 - Nisarg Shah 26
373F20 - Nisarg Shah 27
➢ How do we find a feasible vertex? ➢ For now, assume 𝑐 ≥ 0 (each 𝑐𝑗 ≥ 0)
➢ We’ll later see what to do in the general case
373F20 - Nisarg Shah 28
➢ Find a nonbasic variable with a positive coefficient
➢ See how much you can increase its value without violating any
constraints
373F20 - Nisarg Shah 29
This is because the current values of 𝑦2 and 𝑦3 are 0, and we need 𝑦4, 𝑦5, 𝑦6 ≥ 0
373F20 - Nisarg Shah 30
Tightest obstacle
➢ Solve the tightest obstacle for the nonbasic variable
𝑦1 = 9 − 𝑦2 4 − 𝑦3 2 − 𝑦6 4
373F20 - Nisarg Shah 31
➢ The basic feasible solution (i.e. substituting 0 for all nonbasic
variables) improves from 𝑨 = 0 to 𝑨 = 27
373F20 - Nisarg Shah 32
373F20 - Nisarg Shah 33
373F20 - Nisarg Shah 34
373F20 - Nisarg Shah 35
Start at a vertex of feasible polytope Move to a neighbor vertex with better
Terminate, declare the current solution and value as optimal Is there a neighbor vertex with better
373F20 - Nisarg Shah 36
Assuming 𝑐 ≥ 0, start with a basic feasible solution
Move to a neighbor vertex with better
Terminate, declare the current solution and value as optimal Is there a neighbor vertex with better
373F20 - Nisarg Shah 37
Assuming 𝑐 ≥ 0, start with a basic feasible solution
Move to a neighbor vertex with better
Terminate, declare the current solution and value as optimal
Is there an entering variable with positive coefficient?
373F20 - Nisarg Shah 38
Assuming 𝑐 ≥ 0, start with a basic feasible solution
Pivot on a leaving variable Terminate, declare the current solution and value as optimal
Is there an entering variable with positive coefficient?
373F20 - Nisarg Shah 39
Assuming 𝑐 ≥ 0, start with a basic feasible solution
Pivot on a leaving variable Terminate, declare
Is there an entering variable with positive coefficient?
373F20 - Nisarg Shah 40
➢ If it doesn’t appear in any constraints, or only appears in constraints
where it can go to ∞
➢ Then 𝑨 can also go to ∞, so declare that LP is unbounded
➢ Known as degeneracy, and can lead to infinite loops ➢ Can be prevented by “perturbing” 𝑐 by a small random amount in
each coordinate
➢ Or by carefully breaking ties among entering and leaving variables,
e.g., by smallest index (known as Bland’s rule)
373F20 - Nisarg Shah 41
𝑀𝑄
1
Max 𝑑𝑈𝑦 s.t. 𝑏1
𝑈𝑦 ≤ 𝑐1
𝑏2
𝑈𝑦 ≤ 𝑐2
⋮ 𝑏𝑛
𝑈 𝑦 ≤ 𝑐𝑛
𝑦 ≥ 0 𝑀𝑄
2
Max 𝑑𝑈𝑦 s.t. 𝑏1
𝑈𝑦 + 𝑡1 = 𝑐1
𝑏2
𝑈𝑦 + 𝑡2 = 𝑐2
⋮ 𝑏𝑛
𝑈 𝑦 + 𝑡𝑛 = 𝑐𝑛
𝑦, 𝑡 ≥ 0 𝑀𝑄
3
Max 𝑑𝑈𝑦 s.t. 𝑏1
𝑈𝑦 + 𝑡1 = 𝑐1
−𝑏2
𝑈𝑦 − 𝑡2 = −𝑐2
⋮ −𝑏𝑛
𝑈 𝑦 − 𝑡𝑛 = −𝑐𝑛
𝑦, 𝑡 ≥ 0
Multiply every constraint with negative 𝑐𝑗 by − 1 so RHS is now positive
373F20 - Nisarg Shah 42
𝑀𝑄
3
Max 𝑑𝑈𝑦 s.t. 𝑏1
𝑈𝑦 + 𝑡1 = 𝑐1
−𝑏2
𝑈𝑦 − 𝑡2 = −𝑐2
⋮ −𝑏𝑛
𝑈 𝑦 − 𝑡𝑛 = −𝑐𝑛
𝑦, 𝑡 ≥ 0
Remember: RHS is now positive
𝑀𝑄
4
Min σ𝑗 𝑨𝑗 s.t. 𝑏1
𝑈𝑦 + 𝑡1 + 𝑨1 = 𝑐1
−𝑏2
𝑈𝑦 − 𝑡2 + 𝑨2 = −𝑐2
⋮ −𝑏𝑛
𝑈 𝑦 − 𝑡𝑛 + 𝑨𝑛 = −𝑐𝑛
𝑦, 𝑡, 𝑨 ≥ 0
Remember: we only want to find a basic feasible solution to 𝑀𝑄
1
373F20 - Nisarg Shah 43
Remember: the RHS is now positive
𝑀𝑄
4
Min σ𝑗 𝑨𝑗 s.t. 𝑏1
𝑈𝑦 + 𝑡1 + 𝑨1 = 𝑐1
−𝑏2
𝑈𝑦 − 𝑡2 + 𝑨2 = −𝑐2
⋮ −𝑏𝑛
𝑈 𝑦 − 𝑡𝑛 + 𝑨𝑛 = −𝑐𝑛
𝑦, 𝑡, 𝑨 ≥ 0
What now?
4 using simplex with
the initial basic solution being 𝑦 = 𝑡 = 0, 𝑨 = 𝑐
extract a basic feasible solution 𝑦∗ from it, use it to solve 𝑀𝑄
1 using simplex
4 is
greater than 0, then 𝑀𝑄
1 is
infeasible
373F20 - Nisarg Shah 44
𝑀𝑄
1
Max 𝑑𝑈𝑦 s.t. 𝑏1
𝑈𝑦 ≤ 𝑐1
𝑏2
𝑈𝑦 ≤ 𝑐2
⋮ 𝑏𝑛
𝑈 𝑦 ≤ 𝑐𝑛
𝑦 ≥ 0 𝑀𝑄
2
Min σ𝑗 𝑨𝑗 s.t. 𝑏1
𝑈𝑦 + 𝑡1 + 𝑨1 = 𝑐1
𝑏2
𝑈𝑦 + 𝑡2 + 𝑨2 = 𝑐2
⋮ 𝑏𝑛
𝑈 𝑦 + 𝑡𝑛 + 𝑨𝑛 = 𝑐𝑛
𝑦, 𝑡 ≥ 0
the initial basic feasible solution 𝑦 = 𝑡 = 0, 𝑨 = 𝑐
extract a basic feasible solution 𝑦∗ from it, use it to solve 𝑀𝑄
1 using simplex
greater than 0, then 𝑀𝑄
1 is
infeasible
373F20 - Nisarg Shah 45
time analysis?
373F20 - Nisarg Shah 46
➢ Number of vertices of a polytope can be exponential in the number
your pivots arbitrarily
➢ There are other algorithms which run in polynomial time
373F20 - Nisarg Shah 47
solve very large problem instances
➢ Idea: They can give you very large LPs and you can quickly return the
➢ Question: But how would they know that your solutions are optimal,
if they don’t have the technology to solve those LPs?
373F20 - Nisarg Shah 48
➢ Note: Can easily substitute (𝑦1, 𝑦2), and verify that it is feasible, and
its objective value is indeed 1900
373F20 - Nisarg Shah 49
their positive combinations
➢ E.g. 2*first_constraint + 5*second_constraint + 3*third_constraint ➢ Try to take combinations which give you 𝑦1 + 6𝑦2 on LHS
373F20 - Nisarg Shah 50
➢ 𝑦1 + 6𝑦2 ≤ 200 + 6 ∗ 300 = 2000 ➢ This shows that no feasible solution can beat 2000
373F20 - Nisarg Shah 51
➢ 5𝑦2 + 𝑦1 + 𝑦2 ≤ 5 ∗ 300 + 400 = 1900 ➢ This shows that no feasible solution can beat 1900
373F20 - Nisarg Shah 52
multiplying the three constraints
➢ Note: These need not be integers. They can be reals.
𝑧1 + 𝑧3 𝑦1 + 𝑧2 + 𝑧3 𝑦2 ≤ 200𝑧1 + 300𝑧2 + 400𝑧3
373F20 - Nisarg Shah 53
➢ We have:
𝑧1 + 𝑧3 𝑦1 + 𝑧2 + 𝑧3 𝑦2 ≤ 200𝑧1 + 300𝑧2 + 400𝑧3
➢ What do we want?
373F20 - Nisarg Shah 54
➢ We have:
𝑧1 + 𝑧3 𝑦1 + 𝑧2 + 𝑧3 𝑦2 ≤ 200𝑧1 + 300𝑧2 + 400𝑧3
➢ What do we want?
300𝑧2 + 400𝑧3
373F20 - Nisarg Shah 55
➢ We have:
𝑧1 + 𝑧3 𝑦1 + 𝑧2 + 𝑧3 𝑦2 ≤ 200𝑧1 + 300𝑧2 + 400𝑧3
➢ What do we want?
373F20 - Nisarg Shah 56
➢ The problem of verifying optimality is another LP
upper bound on the objective value of the primal
equal to the primal objective for the (𝑦1, 𝑦2) given to you, then you would know that the given 𝑦1, 𝑦2 is optimal for primal (and your (𝑧1, 𝑧2, 𝑧3) is optimal for dual)
373F20 - Nisarg Shah 57
➢ The problem of verifying optimality is another LP
verify if optimality of (𝑦1, 𝑦2) given to me?
corresponding 𝑧1, 𝑧2, 𝑧3 for proof of optimality
primal objective under optimal solution (𝑦1, 𝑦2)?
373F20 - Nisarg Shah 58
Primal LP Dual LP
➢ General version, in our standard form for LPs
373F20 - Nisarg Shah 59
Primal LP Dual LP
primal feasible 𝑦 𝑑𝑈𝑦 ≤
min
dual feasible 𝑧 𝑧𝑈𝑐
373F20 - Nisarg Shah 60
➢ For any primal feasible 𝑦 and dual feasible 𝑧, 𝑑𝑈𝑦 ≤ 𝑧𝑈𝑐
𝑑𝑈𝑦 ≤ 𝑧𝑈𝐵 𝑦 = 𝑧𝑈 𝐵𝑦 ≤ 𝑧𝑈𝑐 Primal LP Dual LP
373F20 - Nisarg Shah 61
➢ For any primal optimal 𝑦∗ and dual optimal 𝑧∗, 𝑑𝑈𝑦∗ = 𝑧∗ 𝑈𝑐
Primal LP Dual LP
373F20 - Nisarg Shah 62
➢ Exactly one of the following holds:
1) There exists 𝑦 such that 𝐵𝑦 ≤ 𝑐 2) There exists 𝑧 such that 𝑧𝑈𝐵 = 0, 𝑧 ≥ 0, 𝑧𝑈𝑐 < 0
➢ Define image of 𝐵 = set of all possible values of 𝐵𝑦 ➢ It is known that this is a “linear subspace” (e.g. a line in a plane, a
line or plane in 3D, etc)
This slide is not in the scope of the course
373F20 - Nisarg Shah 63
1) There exists 𝑦 such that 𝐵𝑦 ≤ 𝑐 2) There exists 𝑧 such that 𝑧𝑈𝐵 = 0, 𝑧 ≥ 0, 𝑧𝑈𝑐 < 0 1) Image of 𝐵 contains a point “below” 𝑐 2) The region “below” 𝑐 doesn’t intersect image of 𝐵 this is witnessed by normal vector to the image of 𝐵
This slide is not in the scope of the course
373F20 - Nisarg Shah 64
➢ For any primal optimal 𝑦∗ and dual optimal 𝑧∗, 𝑑𝑈𝑦∗ = 𝑧∗ 𝑈𝑐 ➢ Proof (by contradiction):
Primal LP Dual LP
This slide is not in the scope of the course
373F20 - Nisarg Shah 65
➢ There is no 𝑧 such that ➢ By Farkas’ lemma, there is 𝑦 and 𝜇 such that ➢ Case 1: 𝜇 > 0
𝑦 𝜇 = 𝑐 and 𝑑𝑈 𝑦 𝜇 > 𝑨∗
➢ Case 2: 𝜇 = 0
contradiction This slide is not in the scope of the course
373F20 - Nisarg Shah 66
canning plants (A and B).
from each grower to maximize profit
373F20 - Nisarg Shah 68
➢ A brewery can invest its inventory of corn, hops and malt into
producing three types of beer
➢ Per unit resource requirement and profit are as given below ➢ The brewery cannot produce positive amounts of both A and B ➢ Goal: maximize profit
Beverage Corn (kg) Hops (kg) Malt (kg) Profit ($) A 5 4 35 13 B 15 4 20 23 C 10 7 25 15 Limit 500 300 1000
373F20 - Nisarg Shah 69
➢ A brewery can invest its inventory of corn, hops and malt into
producing three types of beer
➢ Per unit resource requirement and profit are as given below ➢ The brewery can only produce 𝐷 in integral quantities up to 100 ➢ Goal: maximize profit
Beverage Corn (kg) Hops (kg) Malt (kg) Profit ($) A 5 4 35 13 B 15 4 20 23 C 10 7 25 15 Limit 500 300 1000
373F20 - Nisarg Shah 70
➢ A brewery can invest its inventory of corn, hops and malt into
producing three types of beer
➢ Per unit resource requirement and profit are as given below ➢ Goal: maximize profit, but if there are multiple profit-maximizing
solutions, then…
Beverage Corn (kg) Hops (kg) Malt (kg) Profit ($) A 5 4 35 13 B 15 4 20 23 C 10 7 25 15 Limit 500 300 1000
373F20 - Nisarg Shah 71
➢ Replace with constraints 𝑦 ≤ 3 and −𝑦 ≤ 3 ➢ What if the constraint is 𝑦 ≥ 3?
➢ Add a variable 𝑢 ➢ Add the constraints 𝑢 ≥ 𝑦 and 𝑢 ≥ −𝑦 (so 𝑢 ≥ |𝑦|) ➢ Change the objective to minimize 3𝑢 + 𝑧 ➢ What if the objective is to maximize 3 𝑦 + 𝑧?
➢ Hint: minimizing 3 𝑦 + 𝑧 in the earlier bullet was equivalent to
minimizing max(3𝑦 + 𝑧, −3𝑦 + 𝑧)
373F20 - Nisarg Shah 72