Linear Programming
Linear Programming
CSE 421
Introduction to Algorithms
Autumn 2010
Linear Programming
Linear Programming
Linear Programming
Linear Programming
Feasible Set
Linear Programming
Visually
x= peanut butter, y = steak
x=0
Opt:
x=0,
y=2
feasible set
feasible set
2x+3y=0
y=0
y=0
x+2y=4
Linear Programming
Minimal price of
one protein unit
= 6/4=1.5
x+2y=4
Linear Programming
2x+3y=6
x=0
An Example
with 6
constraints.
feasible set
Maximize c T x
subject to Ax b and x 0
y=0
Linear Programming
10
Min to Max
Change cjxj to (-cj)xj
Linear Programming
Linear Programming
11
12
Solving LP
There are several polynomial-time algorithms
that solve any linear program optimally.
The Simplex method (later) (not polynomial time)
The Ellipsoid method (polynomial time)
More
13
Bagels Muffins
5
4
2
4
1
2
Revenue 10
Avail.
50
30
20
2 4
1 2
12
b = 10 12
Maximize 10x1+12x2
s.t. 5x1+4x2 50
2x1+4x2 30
x1+2x2 20
x1 0, x2 0
50
c = 30
20
Maximize bx
s.t. Ax c
x 0.
Linear Programming
Linear Programming
14
5 4
A=
15
16
Objective function:
Constraints:
17
a x
i =1
ij
= bj 1 j m
Linear Programming
Example:
2x + 3y = 6
3x - 5y = 2
4x + 5y = 7
minimize
e
j=1
j
n
subject to b j aij x i e j
i=1
a x b
a x b
j=1 i=1
ij
18
L1 norm
i=1
ij
ej
ej 0
for 1 j m
Linear Programming
19
Linear Programming
20
Linear Programming
maximize 2x + 3y
s.t x+2y < 4,
2x + 5y < 1,
x - 3y < 2,
x 0, y 0
21
j=1
i=1
Linear Programming
c jx j
j=1
c j x j bi y i
m
aij y i x j
j=1 i=1
m n
= aij x j y i
i=1 j=1
b y
i=1
Linear Programming
22
minimize 4p +q + 2r
s.t p+2q + r > 2,
23
Linear Programming
24
j=1
i=1
c j x *j = bi yi*
Linear Programming
25
26
Simple Example
The druggist wants to maximize the price p,
subject to constraints:
synthetic protein must not cost more than protein
available in foods.
price must be non-negative or he wont sell any
revenue to druggist will be 4p
Linear Programming
Linear Programming
27
28
Duality Theorem
29
30
LP-based approximations
We dont know any polynomial-time algorithm
for any NP-complete problem
We know how to solve LP in polynomial time
We will see that LP can be used to get
approximate solutions to some NP-complete
problems.
Linear Programming
31
32
The LP Relaxation
Min vV w(v)x(v)
s.t.
x(v) + x(u) 1, (u,v)E
x(v) {0,1} vV
33
Linear Programming
Min vV w(v)x(v)
s.t.
x(v) + x(u) 1, (u,v)E
x(v) 0, vV
x(v) 1, vV
Linear Programming
34
35
36
Approximation of
Vertex Cover Using LP-Rounding
37
Linear Programming
Phase II
38
39
x=0
Constraint
Current
feasible
maximum
Objective
function
Feasible
region
y=0
Linear Programming
40
10
Phase II
Phase II
Objective
function
x=0
Constraint
Objective
function
x=0
Constraint
Current
feasible
maximum
Feasible
region
Current
feasible
maximum
Feasible
region
y=0
Linear Programming
y=0
41
Phase II
Objective
function
x=0
42
Current
feasible
maximum
Feasible
region
y=0
Linear Programming
Linear Programming
43
Maximize 5x + 4y + 3z
subject to 2x+ 3y + z 5
4x + y + 2z 11
3x + 4y + 2z 8
x,y,z 0.
Convert inequalities into equalities by introducing slack
variables a,b,c.
Define: a = 5-2x-3y-z
a0
b = 11-4x-y-2z
b0
c = 8-3x-4y-2z
c0
F = 5x+4y+3z, objective function
Linear Programming
44
11
Nonbasic
Objective
Objective
Basic
Nonbasic
x=y=z = 0, a = 5, b = 11, c = 8, F = 0
x=y=z = 0, a = 5, b = 11, c = 8, F = 0
a = 5-2x-3y-z
b = 11-4x-y-2z
c = 8-3x-4y-2z
a = 5-2x-3y-z
b = 11-4x-y-2z
c = 8-3x-4y-2z
F = 5x+4y+3z
F = 5x+4y+3z
Pivot is x
Linear Programming
45
Basic
Linear Programming
46
Objective
Nonbasic
Basic
Objective
F = 5x+4y+3z
z<5
z<
z < 1 most stringent!
Pivot is z
Linear Programming
47
Linear Programming
48
12
Final Solution
Objective
Basic
Original Problem
Maximize 5x + 4y + 3z
subject to 2x+ 3y + z 5 tight
4x + y + 2z 11 not tight
3x + 4y + 2z 8 tight
x,y,z 0.
a=y=c = 0, x = 2, b = 1, z = 1, F = 13
x = 5/2 -3/2 y -1/2 z - 1/2 a x = 2 - 2y - 2a + c
b = 1 + 5y
+2a b = 1 + 5y +2a
c = 1/2 +1/2 y -1/2 z + 3/2 a z = 1 + y + 3a - 2c
Solution: x = 2, y = 0, z = 1, F = 13
49
50
Example
Maximize 2x - y
subject to 2x - y 2
x - 5y -4
x,y 0.
x = y = 0 is not a feasible solution
Linear Programming
i=1..m
j=0..n
51
Linear Programming
52
13
Auxiliary LP
Maximize -z
subject to 2x - y - z 2
x - 5y - z -4
x,y,z 0.
a = 2 - 2x + y + z
z > -2
b = -4 - x + 5y + z
F = -z
We do a pivot step with z.
Linear Programming
53
Basic
Linear Programming
Objective
Nonbasic
Basic
Objective
x=y=b=0, a = 6, z = 4, F = -4
x=y=b=0, a = 6, z = 4, F = -4
a = 2 - 2x + y + z a = 6 - x - 4y + b
a = 6 - x - 4y + b
y < 6/4
b = -4 - x + 5y + z z = 4 + x - 5y + b
z = 4 + x - 5y + b
F = -4 - x + 5y - b
F = -4 - x + 5y - b
F = -z
54
Pivot is y
Linear Programming
55
Linear Programming
56
14
Objective
Basic
Nonbasic
Basic
a = 6 - x - 4y + b
z = 4 + x - 5y + b
F = -4 - x + 5y - b F = 0 - z
Objective
57
Class Exercise
Original objective
function
Linear Programming
58
Choosing a Pivot
Largest increase in F
Largest positive coefficient
First positive coefficient
Maximize 2x - y
subject to 2x - y 2
x - 5y -4
x,y 0.
Linear Programming
59
Linear Programming
60
15
Termination
LP Summary
Linear Programming
Linear Programming
62
16