Linear Programming: Brewer's Problem Simplex Algorithm Implementation Linear Programming
Linear Programming: Brewer's Problem Simplex Algorithm Implementation Linear Programming
brewer’s problem
simplex algorithm
implementation
linear programming
References:
The Allocation of Resources by Linear Programming,
Scientific American, by Bob Bland
Algs in Java, Part 5
1
Overview: introduction to advanced topics
Main topics
• linear programming: the ultimate practical problem-solving model
• reduction: design algorithms, prove limits, classify problems
• NP: the ultimate theoretical problem-solving model
• combinatorial search: coping with intractability
Shifting gears
• from linear/quadratic to polynomial/exponential scale
• from individual problems to problem-solving models
• from details of implementation to conceptual framework
Goals
• place algorithms we’ve studied in a larger context
• introduce you to important and essential ideas
• inspire you to learn more about algorithms!
2
Linear Programming
see ORF 307
What is it?
•Quintessential tool for optimal allocation of scarce resources, among
a number of competing activities.
•Powerful and general problem-solving method that encompasses:
shortest path, network flow, MST, matching, assignment...
Ax = b, 2-person zero sum games
Why significant?
•Widely applicable problem-solving model Ex: Delta claims that LP
3
Applications
5
Toy LP example: Brewer’s problem
all ale
179 136 1190 442
(34 barrels)
34 barrels times 35 lbs malt
all beer
480 128 640 736 per barrel is 1190 lbs
(32 barrels) [ amount of available malt ]
20 barrels ale
400 160 1100 720
20 barrels beer
12 barrels ale
480 160 980 800
28 barrels beer
more profitable
? ? ? >800 ?
product mix?
6
Brewer’s problem: mathematical formulation
Mathematical formulation
• let A be the number of barrels of beer
• and B be the number of barrels of ale
ale beer
maximize 13A + 23B profit
5A + 15B 480 corn
subject
to the 4A + 4B 160 hops
constraints
35A + 20B 1190 malt
A 0
B 0
7
Brewer’s problem: Feasible region
Hops Malt
4A + 4B 160 35A + 20B 1190
(0, 32)
(12, 28)
Corn
5A + 15B 480
(26, 14)
Beer
8
Brewer’s problem: Objective function
Pr
of
it
(0, 32)
(12, 28)
(26, 14)
(0, 32)
(12, 28)
extreme point
(26, 14)
Beer
10
7
Standard form linear program
subject to the
constraints constraints x 0
a21 x1 + a22 x2 + . . . + a2n xn = b2
...
x1 , x2 ,... , xn 0
Original formulation
Standard form
• add variable Z and equation corresponding to objective function
• add slack variable to convert each inequality to an equality.
• now a 5-dimensional problem.
maximize Z
subject 13A + 23B Z = 0
to the
5A + 15B + SC = 480
constraints
4A + 4B + SH = 160
35A + 20B + SM = 1190
A, B, SC, SH, SM 0
12
Geometry
Convex set. If two points a and b are in the set, then so is (a + b).
Extreme point. A point in the set that can't be written as (a + b),
where a and b are two distinct points in the set.
extreme
point
13
Geometry (continued)
14
brewer’s problem
simplex algorithm
implementation
linear programming
15
Simplex Algorithm
Generic algorithm.
•
never decreasing objective function
Start at some extreme point.
• Pivot from one extreme point to a neighboring one.
• Repeat until optimal.
16
Simplex Algorithm: Basis
Basis
{B, SH, SM } {A, B, SM }
(0, 32) (12, 28)
maximize Z Infeasible
{A, B, SH }
subject 13A + 23B Z = 0 (19.41, 25.53)
to the
5A + 15B + SC = 480 Beer {A, B, SC }
constraints
4A + 4B + SH = 160 (26, 14)
A, B, SC, SH, SM 0
{SH, SM, SC } Ale {A, SH, SC }
(0, 0) (34, 0)
17
Simplex Algorithm: Initialization
maximize Z
basis = {SC, SH, SM}
subject 13A + 23B Z = 0
A=B=0
to the
5A + 15B + SC = 480 Z=0
constraints
4A + 4B + SH = 160 SC = 480
SH = 160
35A + 20B + SM = 1190
SM = 1190
A, B, SC, SH, SM 0
18
Simplex Algorithm: Pivot 1
maximize Z
basis = {SC, SH, SM}
subject 13A + 23B Z = 0
A=B=0
to the
5A + 15B + SC = 480 Z=0
constraints
4A + 4B + SH = 160 SC = 480
SH = 160
35A + 20B + SM = 1190
SM = 1190
A, B, SC, SH, SM 0
which variable
Substitution B = (1/15)(480 – 5A – SC ) puts B into the basis does it replace?
( rewrite 2nd equation, eliminate B in 1st, 3rd, and 4th equations)
maximize Z
basis = {B, SH, SM}
subject (16/3)A - (23/15) SC Z = -736
A = SC = 0
to the
(1/3) A + B + (1/15) SC = 32 Z = 736
constraints
(8/3) A - (4/15) SC + SH = 32 B = 32
SH = 32
(85/3) A - (4/3) SC + SM = 550
SM = 550
A, B, SC, SH, SM 0
19
Simplex Algorithm: Pivot 1
maximize Z
basis = {SC, SH, SM}
subject 13A + 23B Z = 0 A=B=0
to the Z=0
5A + 15B + SC = 480
constraints SC = 480
4A + 4B + SH = 160
SH = 160
35A + 20B + SM = 1190
SM = 1190
A, B, SC, SH, SM 0
Why pivot on B?
•Its objective function coefficient is positive
(each unit increase in B from 0 increases objective value by $23)
•Pivoting on column 1 also OK.
maximize Z
basis = {B, SH, SM}
subject (16/3)A - (23/15) SC Z = -736
A = SC = 0
to the
(1/3) A + B + (1/15) SC = 32 Z = 736
constraints
(8/3) A - (4/15) SC + SH = 32 B = 32
SH = 32
(85/3) A - (4/3) SC + SM = 550
SM = 550
A, B, SC, SH, SM 0
maximize Z
basis = {A, B, SM}
subject - SC - 2SH Z = -800
SC = SH = 0
to the
B + (1/10) SC + (1/8) SH = 28 Z = 800
constraints
A - (1/10) SC + (3/8) SH = 12 B = 28
A = 12
- (25/6) SC - (85/8) SH + SM = 110
SM = 110
A, B, SC, SH, SM 0
21
Simplex algorithm: Optimality
maximize Z
basis = {A, B, SM}
subject - SC - 2SH Z = -800
SC = SH = 0
to the
B + (1/10) SC + (1/8) SH = 28 Z = 800
constraints
A - (1/10) SC + (3/8) SH = 12 B = 28
A = 12
- (25/6) SC - (85/8) SH + SM = 110
SM = 110
A, B, SC, SH, SM 0
22
brewer’s problem
simplex algorithm
implementation
linear programming
23
Simplex tableau
maximize Z
subject 13A + 23B Z = 0
to the
5A + 15B + SC = 480
constraints
4A + 4B + SH = 160
A, B, SC, SH, SM 0
5 15 1 0 0 480
4 4 0 1 0 160 m A I b
35 20 0 0 1 1190
1 c 0 0
13 23 0 0 0 0 n m 1
24
Simplex tableau
maximize Z
subject - SC - 2SH Z = -800
to the
B + (1/10) SC + (1/8) SH = 28
constraints
A - (1/10) SC + (3/8) SH = 12
- (25/6) SC - (85/8) SH + SM = 110
A, B, SC, SH, SM 0
0 1 1/10 1/8 0 28
1 0 1/10 3/8 0 12
m A I b
0 0 25/6 85/8 1 110
0 0 -1 -2 0 -800 1 c 0 0
n m 1
m A I b
1 c 0 0
n m 1
26
Simplex algorithm: Bare-bones Implementation
27
Simplex Algorithm: Bare Bones Implementation
q
Simplex algorithm.
p + +
28
Simplex Algorithm: Running Time
29
Simplex algorithm: Degeneracy
30
Simplex Algorithm: Implementation Issues
• Detect infeasiblity
• Detect unboundedness.
• Preprocess to reduce problem size.
31
LP solvers: basic implementations
35
Linear programming
Linear “programming”
• process of formulating an LP model for a problem
• solution to LP for a specific problem gives solution to the problem
1. Identify variables
2. Define constraints (inequalities and equations)
3. Define objective function
• bipartite matching
• .
• .
• .
• [ a very long list ]
36
Single-source shortest-paths problem (revisited)
Goal. Find distance (and shortest path) from s to every other vertex.
2 24 3
9
s
18
14 6
2
6
30 4 19
11
15 5
5
6
20 16
7 44 t
37
LP formulation of single-source shortest-paths problem
minimize xt
subject xs + 9 x2
to the xs + 14 x6 9
2 24 3
constraints xs + 15 x7 s
18
14 6
x2 + 24 x3 6
2
x3 + 2 x5 30
11
4 19
5
x3 + 19 xt 15
5
6
x4 + 6 x3 20 16
x4 + 6 xt 7 44 t
x5 + 11 x4
x5 + 16 xt
x6 + 18 x3
x6 + 30 x5
x6 + 5 x7
x7 + 20 x5
x7 + 44 xt
xs = 0
x2 , ... , xt 0
38
LP formulation of single-source shortest-paths problem
minimize xt
subject xs + 9 x2 9 32
to the xs + 14 x6 0 9
2 24 3
constraints xs + 15 x7 s
18
14 14 6
x2 + 24 x3 6
2
45
x3 + 2 x5 30
11
4 19
5
x3 + 19 xt 15
5
34 6
x4 + 6 x3 20 16
x4 + 6 xt 7 44 t
x5 + 11 x4 15 50
x5 + 16 xt solution
x6 + 18 x3 xs = 0
x6 + 30 x5 x2 = 9
x3 = 32
x6 + 5 x7
x4 = 45
x7 + 20 x5
x5 = 34
x7 + 44 xt
x6 = 14
xs = 0 x7 = 15
x2 , ... , xt 0 xt = 50
39
Maxflow problem
•
2 3
[many other examples] t
at each
[ flow in equals flow out ] 1 2 vertex
0 1
flow capacity 1 1
in every edge
3 2 1 4
flow in to t is 3 40
LP formulation of maxflow problem
1 2
maximize xts 1 1
3 1
subject xs1 2
to the xs2 3 3 4
constraints x13 3 2 3
x14 1 capacity
t
x23 1 constraints
add dummy
x24 1 edge from
x3t 2 t to s
s
x4t 3
xts = xs1 + xs2 1 2
xs1 = x13 + x14
equilibrium xs2 = x23 + x24
constraints x13 + x23 = x3t 3 4
x14 + x24 = x4t
x3t + x4t = xts t
all xij 0
41
LP formulation of maxflow problem
1 2
maximize xts 1 1
3 1
subject xs1 2
to the xs2 3 3 4
constraints x13 3 2 3
x14 1 capacity
t
x23 1 constraints
add dummy
x24 1 edge from
x3t 2 t to s
2 s 2
x4t 3 solution
xts = xs1 + xs2 xs1 = 2 1 2
1 1
xs1 = x13 + x14 xs2 = 2
x13 = 1 1
xs2 = x23 + x24
1
equilibrium x14 = 1
constraints x13 + x23 = x3t x23 = 1 3 2 2 4
x14 + x24 = x4t x24 = 1
x3t = 2
x3t + x4t = xts t
x4t = 2
all xij 0 xts = 4
maxflow value 42
Maximum cardinality bipartite matching problem
•
Adobe, Apple Carol, Eliza
Ex: medical students to residence positions Eliza Sun
•
IBM, Sun, Yahoo Carol, Eliza, Frank
Ex: students to writing seminars Frank Yahoo
A B C D E F
43
LP formulation of maximum cardinality bipartite matching problem
0 1 2 3 4 5
45
Linear programming perspective
46
LP: the ultimate problem-solving model (in practice)
•
other generalized versions
can just add more inequalities to LP
New problem?
•may not be difficult to formulate LP
•may be very difficult to develop specialized algorithm
Today’s problem?
•similar to yesterday’s Ex. Airline scheduling
•
[ similar to vast number of other business processes ]
edit tableau, run solver
Too slow?
•could happen Want to learn more?
• .
• .
• . [see next lecture]
Good news:
• LP has been widely used for large practical problems for 50+ years
• Existence of guaranteed poly-time algorithm known for 25+ years.