Beruflich Dokumente
Kultur Dokumente
Reference: The Allocation of Resources by Linear Programming, Plasma physics. Optimal stellarator design.
Scientific American, by Bob Bland
Telecommunication. Network design, Internet routing.
Sports. Scheduling ACC basketball, handicapping horse races.
Copyright © 2007 by Robert Sedgewick and Kevin Wayne. 3
Linear Programming
see ORF 307
What is it?
Quintessential tool for optimal allocation of scarce resources,
!
2 4
Toy LP example: Brewer’s problem Brewer’s problem: Feasible region
(0, 32)
Brewer’s problem: choose product mix to maximize profits.
(12, 28)
all ale
179 136 1190 442
(34 barrels)
Corn
all beer 5A + 15B ! 480
480 128 640 736
(32 barrels) (26, 14)
20 barrels ale
400 160 1100 720
20 barrels beer Beer
12 barrels ale 480 160 980 800
28 barrels beer
(0, 0) Ale (34, 0)
more profitable
>800 ?
product mix?
5 7
Mathematical formulation:
(0, 32)
ale beer
(12, 28)
maximize 13A + 23B profit
13A + 23B = $1600
5A + 15B ! 480 corn
subject
to the 4A + 4B ! 160 hops
(26, 14)
constraints 35A 20B 1190 malt
+ !
A " 0 Beer 13A + 23B = $800
B " 0
Standard form.
(0, 32)
Add slack variable to convert each inequality to an equality.
!
9 11
Input: real numbers aij, cj, bi. A few principles from geometry:
Output: real numbers xj.
!
inequality: halfplane (2D), hyperplane (kD).
!
bounded feasible region: convex polygon (2D), convex polytope (kD).
n = # nonnegative variables, m = # constraints.
Maximize linear objective function subject to linear equations.
Convex set. If two points a and b are in the set, then so is !(a + b).
n variables matrix version Extreme point. A point in the set that can't be written as !(a + b),
maximize c1 x1 + c2 x2 + . . . + cn xn maximize cT x where a and b are two distinct points in the set.
subject to the a11 x1 + a12 x2 + . . . + a1n xn = b1 subject to the Ax = b
m equations
Extreme point property. If there exists an optimal solution to (P), Simplex algorithm. [George Dantzig, 1947]
then there exists one that is an extreme point. !
Developed shortly after WWII in response to logistical problems,
including Berlin airlift.
Good news. Only need to consider finitely many possible solutions. !
One of greatest and most successful algorithms of all time.
13 15
maximize Z maximize Z
subject 13A + 23B # Z = 0 Basis = {SC, SH, SM} subject 13A + 23B # Z = 0 Basis = {SC, SH, SM}
to the A=B=0 to the A=B=0
5A + 15B + SC = 480 5A + 15B + SC = 480
constraints Z=0 constraints Z=0
4A + 4B + SH = 160 SC = 480 4A + 4B + SH = 160 SC = 480
35A + 20B + SM = 1190 SH = 160 35A + 20B + SM = 1190 SH = 160
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.
17 19
maximize Z maximize Z
subject 13A 23B # Z = 0 Basis = {SC, SH, SM} subject (16/3)A - (23/15) SC # Z = -736 Basis = {B, SH, SM}
+
to the A=B=0 to the A = SC = 0
5A + 15B + SC = 480 (1/3) A + B + (1/15) SC = 32
constraints Z=0 constraints Z = 736
4A + 4B + SH = 160 SC = 480 (8/3) A - (4/15) SC + SH = 32 B = 32
35A + 20B + SM = 1190 SH = 160 (85/3) A - (4/3) SC + SM = 550 SH = 32
SM = 1190 A, B, SC, SH, SM 0 SM = 550
A, B, SC, SH, SM " 0 "
maximize Z maximize Z
subject (16/3)A + 23B - (23/15) SC # Z = -736 Basis = {B, SH, SM} subject - SC - 2SH # Z = #800 Basis = {B, SH, SM}
to the A = SC = 0 to the S C = SH = 0
(1/3) A + B + (1/15) SC = 32 B + (1/10) SC + (1/8) SH = 28
constraints Z = 736 constraints Z = 800
(8/3) A - (4/15) SC + SH = 32 B = 32 A - (1/10) SC + (3/8) SH = 12 B = 28
(85/3) A - (4/3) SC + SM = 550 SH = 32 - (25/6) SC - (85/8) SH + SM = 110 A = 12
SM = 550 SM = 110
A, B, SC, SH, SM " 0 A, B, SC, SH, SM " 0
18 20
Simplex algorithm: Optimality Simplex tableau
5 15 1 0 0 480
maximize Z
Basis = {A, B, SM} 4 4 0 1 0 160 m A I b
subject - SC - 2SH # Z = #800
to the S C = SH = 0 35 20 0 0 1 1190
B + (1/10) SC + (1/8) SH = 28
constraints Z = 800 1 c 0 0
A - (1/10) SC + (3/8) SH = 12 B = 28 13 23 0 0 0 0 n m 1
21 23
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
brewer’s problem - (25/6) SC - (85/8) SH + SM = 110
simplex algorithm A, B, SC, SH, SM " 0
implementation
solving LPs 0 1 1/10 1/8 0 28
linear programming 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
Pivot on element (p, q). q Degeneracy. New basis, same extreme point.
p
"stalling" is common in practice
26 28
LP Duality: Economic Interpretation LP Duality: Sensitivity Analysis
0 1 1/10 1/8 0 28
Entrepreneur's problem. Buy resources from brewer at min cost.
!
C, H, M = unit price for corn, hops, malt. 1 0 1/10 3/8 0 12
!
Brewer won't agree to sell resources if 5C + 4H + 35M < 13 0 0 25/6 85/8 1 110
or 15C + 4H + 20M < 23 0 0 -1 -2 0 #800
objective row of final simplex tableaux
provides optimal dual solution!
29 31
30 32
LP solvers: toy problems
import drasys.or.mp.*;
import drasys.or.mp.lp.*;
brewer’s problem
Problem prob = new Problem(3, 2);
simplex algorithm prob.getMetadata().put("lp.isMaximize", "true");
prob.newVariable("x1").setObjectiveCoefficient(13.0);
implementation prob.newVariable("x2").setObjectiveCoefficient(23.0);
prob.newConstraint("corn").setRightHandSide( 480.0);
solving LPs
prob.newConstraint("hops").setRightHandSide( 160.0);
prob.newConstraint("malt").setRightHandSide(1190.0);
33 35
To improve the bare-bones implementation AMPL. [Fourer, Gay, Kernighan] An algebraic modeling language.
!
Avoid stalling. CPLEX solver. Industrial strength solver.
!
Choose the pivot wisely. separate data from model
!
Watch for numerical stability.
!
Maintain sparsity. requires fancy data structures
set INGR;
set PROD := beer ale; beer.mod
!
Detect infeasiblity set INGR := corn hops malt; set PROD;
param profit {PROD};
!
Detect unboundedness. param: profit :=
ale 13
param supply {INGR};
param amt {INGR, PROD};
!
Preprocess to reduce problem size. beer 23; var x {PROD} >= 0;
param: supply := maximize total_profit:
corn 480 sum {j in PROD} x[j] * profit[j];
hops 160
malt 1190; subject to constraints {i in INGR}:
Commercial solvers routinely solve LPs with millions of variables and param amt: ale beer :=
sum {j in PROD} amt[i,j] * x[j] <= supply[i];
corn 5 15
tens of thousands of constraints. hops 4 4
malt 35 20; [cos226:tucson] ~> ampl
beer.dat
AMPL Version 20010215 (SunOS 5.7)
ampl: model beer.mod;
ampl: data beer.dat;
ampl: solve;
CPLEX 7.1.0: optimal solution; objective 800
ampl: display x;
x [*] := ale 12 beer 28;
34 36
History Linear programming
1939. Production, planning. [Kantorovich] Linear “programming” is the process of developing a model to solve
1947. Simplex algorithm. [Dantzig] the problem at hand.
1950. Applications in many fields.
1979. Ellipsoid algorithm. [Khachian] Identify variables
1984. Projective scaling algorithm. [Karmarkar] Define inequalities and equations
1990. Interior point methods.
!
Interior point faster when polyhedron smooth like disco ball. Easy part: convert to standard form
!
Simplex faster when polyhedron spiky like quartz crystal.
Examples:
!
max flow
!
assignment
!
scheduling
!
shortest paths
!
...
200x. Approximation algorithms, large scale optimization.
37 39
Max flow
brewer’s problem
simplex algorithm
implementation
solving LPs
Problem: compute flow through edges
linear programming !
flow less than capacity in each edge
!
inflow equals outflow at each vertex (except source and sink)
!
maximize flow from source to sink
Applications:
!
distribution of oil through network of pipes
!
distribution of goods in trucks through highways
38 40
Linear programming formulation of maxflow Assignment Problem: Applications
Got an LP solver?
Maybe easier to use it than to implement specialized algorithm
41 43
Assign N jobs to N machines to minimize total cost maximize c11 x11 + c12 x12 + c13 x13 + c14 x14 + c15 x15 +
where cij = cost of assignment job j to machine i. N2 variables c21 x21 + c22 x22 + c23 x23 + c24x24 + c25 x25 +
one corresponding c31 x31 + c32 x32 + c33 x33 + c34 x34 + c35 x35 +
to each cell c41 x41 + c42 x42 + c43 x43 + c44 x44 + c45 x45 +
c51 x51 + c52 x52 + c53 x53 + c54 x54 + c55 x55
1' 2' 3' 4' 5' 1' 2' 3' 4' 5'
2N equations subject x11 + x12 + x13 + x14 + x15 = 1
1 3 8 9 15 10 1 3 8 9 15 10 to the constraints
one per row ...
2 4 10 7 16 14 2 4 10 7 16 14 one per column x51 + x52 + x53 + x54 + x55 = 1
Today’s problem?
!
similar to yesterday’s
!
edit tableau, run solver
intractable (conjectured)
46