Transcript dye-lp

Linear Programming & Flows
Instructor: yedeshi
[email protected]
1
Linear Programming
What is it?
Quintessential tool for optimal allocation of scarce resources,
among a number of competing activities. (e.g., see ORF 307)
Powerful and general problem-solving method.
shortest path, max flow, min cost flow, generalized flow,
multicommodity flow, MST, matching, 2-person zero sum games
Why significant?
Fast commercial solvers: CPLEX, OSL, Lindo.
Powerful modeling languages: AMPL, GAMS.
Ranked among most important scientific advances of 20th century.
Also a general tool for attacking NP-hard optimization problems.
Dominates world of industry.
ex: Delta claims saving $100 million per year using LP
2
Example
max x1  x2
Subject to
4 x1  x2  8
2 x1  x2  10
5 x1  2 x2  2
x1 , x2  0
3
Geometry
Observation. Regardless of objective function
(convex) coefficients, an optimal solution
occurs at an extreme point.
4
Standard and slack forms
Standard form
In standard form, we are given n real numbers
c1, c2, ..., cn; m real numbers b1, b2, ..., bm; and
mn real numbers aij for i = 1, 2, ..., m and j = 1,
2, ..., n. We wish to find n real numbers x1, x2,
..., xn that max c x

n
j
j 1
j
s.t.
n
a
j 1
ij
x j  bi
xj  0
for i  1, 2,
,m
5
Standard and slack forms
Standard form
In standard form, we are given n real numbers
c1, c2, ..., cn; m real numbers b1, b2, ..., bm; and
mn real numbers aij for i = 1, 2, ..., m and j = 1,
2, ..., n. We wish to find n real numbers x1, x2,
..., xn that
T
max
C X
s.t.
AX  b
X 0
6
slack form
In standard form,
n
a
j 1
ij
x j  bi
Slack variable s, such that
n
a
j 1
ij
x j  s  bi
7
The simplex algorithm
Simplex algorithm. (George Dantzig, 1947)
Developed shortly after World War II in response to
logistical problems.
Used for 1948 Berlin airlift.
never decrease
objective func
Generic algorithm.
Start at some extreme point.
Pivot from one extreme point to a neighboring one.
Repeat until optimal.
How to implement? Linear algebra.
8
Illustration of Simplex
Step1: Convert the LP problem to a system of linear
equations (slack form).
Step 2: Set up the initial tableau.
Step 3: Find the PIVOT
Step 4: Form RATIOS (quotients) for each row: divide
the right-most number by the number in the pivot
column of that row.
Step 5: The PIVOT ROW is the row with the smallest
NON-NEGATIVE ratio (quotient).
Step 6: If all indicators (in the bottom row) are nonnegative, STOP.
Step 7: Otherwise, goes to Step 3.
9
Step 1
Original problem:
max z  x1  2 x2  x3
s.t.
2 x1  x2  x3  14
4 x1  2 x2  3 x3  28
2 x1  5 x2  5 x3  30
x1  0, x2  0, x3  0
Slack form:
2 x1  x2  x3  s1  14
4 x1  2 x2  3 x3
2 x1  5 x2  5 x3
 s2  28
 s3  30
All variables  0
10
Step 2
2 x1  x2  x3  s1  14
4 x1  2 x2  3 x3
 s2  28
2 x1  5 x2  5 x3
 s3  30
All variables  0
SIMPLEX TABLEAU.
Compare RED symbols
with Z = x1 + 2x2 - x3.
2 1
1 1
0
0
14
4 2
3 0
1
0
28
2 5
5 0
0
1
30
-1 -2 +1 0
0
0
0
11
Step 3: Pivot
2 1
1 1
0
0
14
4 2
3 0
1
0
28
2 5
5 0
0
1
30
-1 -2 +1 0
0
0
0
Indicator row
Pivot column
12
Step 3: Pivot ratios
2 1
1 1
0
0
Ratios:
14 14÷1 =14
4 2
3 0
1
0
28 28÷2 =14
2 5
5 0
0
1
30 30÷5 =6
-1 -2 +1 0
0
0
0
Indicator row
Pivot column
Pivot
13
Step 4: entering variable
r1: 2 1
1 1
0
0
14
r2: 4 2
3 0
1
0
28
r3: 2 5
r4:
5 0
0
1
30
-1 -2 +1 0
0
0
0
R3=(r3 /5)
2
1
1
1
0
0
14
4
2
3
0
1
0
28
2/5 1
1
0
0
1/5 6
-1
+1
0
0
0
-2
0
14
Step 4: leaving variable
R1=r1 - R3
R2=r2-2R3
R4=r4+2R3
r1: 2
1
1
1
0
0
14
r2: 4
2
3
0
1
0
28
R3: 2/5 1
1
0
0
1/5 6
r4: -1
+1
0
0
0
0
R1:
8/5
0
0
1
0
-1/5
8
R2:
16/5
0
1
0
1
-2/5
16
R3:
2/5
1
1
0
0
1/5
6
R4:
-1/5 0
3
0
0
2/5
12
-2
15
Step 3 again
R1:
8/5
0
0
1
0
-1/5
8
R2:
16/5
0
1
0
1
-2/5
16
R3:
2/5
1
1
0
0
1/5
6
R4:
-1/5 0
3
0
0
2/5
12
Indicator row
Pivot column
16
Step 3 again
R1:
8/5
0
0
1
0
-1/5
8
Ratios:
8÷(8/5) =5
R2:
16/5
0
1
0
1
-2/5
16
16÷(16/5) =5
R3:
2/5
1
1
0
0
1/5
6
R4:
-1/5 0
3
0
0
2/5
12
Tie: choose
arbitrary
6÷ (2/5) =15
Indicator row
Pivot column
17
Step 3 again
R1:
8/5
0
0
1
0
-1/5
8
R2:
16/5
0
1
0
1
-2/5
16
R3:
2/5
1
1
0
0
1/5
6
R4:
-1/5 0
3
0
0
2/5
12
R1:
8/5
0
0
1
0
5/16 0
5/16 -1/8 5
2/5
1
1
0
0
1/5 6
-1/5 0
3
0
0
2/5 1218
R2:
R3:
R4:
R2=(R2 /(16/5))
1
0
-1/5 8
Step 3 again
R1:
R2:
R3:
R4:
8/5
0
0
1
0
-1/5 8
1
0
5/16 0
5/16 -1/8 5
2/5
1
1
0
0
1/5 6
-1/5 0
3
0
0
2/5 12
R1:
R2:
R3:
R4:
R1=R1 – (8/5)R2
R3=R3-(2/5)R2
R4=R4+(1/2)R2
0
0
-1/2
1 -1/2 0
0
1
0
5/16 0 5/16 -1/8 5
0
1
7/8
0
0
49/16 0 1/16 3/8 13
19
0 -1/8 1/4 4
STOP
R1:
R2:
R3:
R4:
x1
x2
x3
s1 s2
s3
0
0
-1/2
1
0
5/16 0 5/16 -1/8 5
0
1
7/8
0
0
49/16 0 1/16 3/8 13
1 -1/2 0
0
0 -1/8 1/4 4
Finally, the optimal solution of LP is
x3=s2=s3=0
x1=5, x2=4, s1=0
z =13
20
History of LP
1939. Production, planning. (Kantorovich,
USSR)
Propaganda to make paper more palatable to
communist censors.
Kantorovich awarded 1975 Nobel prize in
Economics for
contributions to the theory of optimum allocation
of resources.
Staple in MBA curriculum.
Used by most large companies and other profit
maximizers.
21
History
1939. Production, planning. (Kantorovich)
1947. Simplex algorithm. (Dantzig)
1950. Applications in many fields.
Military logistics.
Operations research.
Control theory.
Filter design.
Structural optimization.
22
History
1939. Production, planning. (Kantorovich)
1947. Simplex algorithm. (Dantzig)
1950. Applications in many fields.
1979. Ellipsoid algorithm. (Khachian)
Geometric divide-and-conquer.
Solvable in polynomial time: O(n4 L) bit operations.
– n = # variables
– L = # bits in input
Theoretical tour de force, not remotely practical.
23
History
1939. Production, planning. (Kantorovich)
1947. Simplex algorithm. (Dantzig)
1950. Applications in many fields.
1979. Ellipsoid algorithm. (Khachian)
1984. Projective scaling algorithm.
(Karmarkar)
O(n3.5 L).
Efficient implementations possible.
24
History
1939. Production, planning. (Kantorovich)
1947. Simplex algorithm. (Dantzig)
1950. Applications in many fields.
1979. Ellipsoid algorithm. (Khachian)
1984. Projective scaling algorithm. (Karmarkar)
1990. Interior point methods.
O(n3 L) and practical.
Extends to even more general problems.
25
Perspective
LP is near the deep waters of NPcompleteness.
Solvable in polynomial time.
Known for less than 28 years.
Integer linear programming.
LP with integrality requirement.
NP-hard.
26
Formulating problems
as linear programs
Maximum flow:
we are given a directed graph G = (V, E) in which
each edge (u, v) ∈ E has a nonnegative capacity
c(u, v) ≥ 0, and two distinguished vertices, a sink s
and a source t. The goal is to find s-t flow of
maximum value.
max  f ( s, v )
vV
s.t.
f (u , v )  c (u , v )
f (u , v )   f (v, u )
for each u , v  V
for each u , v  V
 f (u, v)  0
for each u  {s, t}
vV
27
China Rail Network
28
Maximum Flow
and Minimum Cut
Max flow and min cut.
Two very rich algorithmic problems.
Cornerstone problems in combinatorial optimization.
Beautiful mathematical duality.
29
Minimum Cut Problem
Flow network.
Abstraction for material flowing through the edges.
G = (V, E) = directed graph, no parallel edges.
Two distinguished nodes: s = source, t = sink.
c(e) = capacity of edge e.




10
source
s
capacity
5
15
2
9
5
4
15
15
10
3
8
6
10
4
6
15
4
30
7
t
sink
10
30
Cuts
Def. An s-t cut is a partition (A, B) of V with s  A and t  B.
Def. The capacity of a cut (A, B) is:
cap( A, B) 
 c(e)
e out of A

10
s
5
2
9
5
4
15
15
10
3
8
6
10
4
6
15
t
A
15
4
30
7
10
Capacity = 10 + 5 + 15
= 30
31
Cuts
Def. An s-t cut is a partition (A, B) of V with s  A and t  B.
Def. The capacity of a cut (A, B) is:
cap( A, B) 
 c(e)
e out of A

10
5
s
A
15
2
9
5
4
15
15
10
3
8
6
10
4
6
15
4
30
7
t
10
Capacity = 9 + 15 + 8 + 30
= 62
32
Minimum Cut Problem
Min s-t cut problem. Find an s-t cut of minimum capacity.
10
5
s
A
15
2
9
5
4
15
15
10
3
8
6
10
4
6
15
4
30
7
t
10
Capacity = 10 + 8 + 10
= 28
33
Flows
Def. An s-t flow is a function that satisfies:
For each e  E:
0  f (e)  c(e)
For each v  V – {s, t}:  f (e)   f (e)
(capacity)
(conservation)


e in to v
e out of v
Def. The value of a 
flow f is: v( f ) 
 f (e) .
e out of s

0
2
4
10

4 4
0
5
s
9
0
15
5
0
15
0
4
4
3
8
6
0
capacity
15
flow
0
4 0
6
15 0
0
4
30
10
7
10
t
0
10
Value = 4
34
Flows
Def. An s-t flow is a function that satisfies:
For each e  E:
0  f (e)  c(e)
For each v  V – {s, t}:  f (e)   f (e)
(capacity)
(conservation)


e in to v
e out of v
Def. The value of a 
flow f is: v( f ) 
 f (e) .
e out of s

6
2
10
10

4 4
3
5
s
9
0
15
5
6
15
0
8
8
3
8
6
1
capacity
15
flow
11
4 0
6
15 0
11
4
30
10
7
10
t
10
10
Value = 24
35
Maximum Flow Problem
Max flow problem. Find s-t flow of maximum value.
9
2
10
10
4 0
4
5
s
9
1
15
5
9
15
0
9
8
3
8
6
4
capacity
15
flow
14
4 0
6
15 0
14
4
30
10
7
10
t
10
10
Value = 28
36
Flows and Cuts
Flow value lemma. Let f be any flow, and let (A, B) be any s-t cut.
Then, the net flow sent across the cut is equal to the amount leaving s.
 f (e)   f (e)  v( f )
e out of A

6
2
10
10
4 4
3
s
e in to A
5
9
0
15
5
6
15
0
8
8
3
A
8
6
1
15
4 0
11
6
15 0
11
4
30
10
7
10
t
10
10
Value = 24
37
Flows and Cuts
Flow value lemma. Let f be any flow, and let (A, B) be any s-t cut.
Then, the net flow sent across the cut is equal to the amount leaving s.
 f (e)   f (e)  v( f )
e out of A

6
2
10
10
4 4
3
s
e in to A
5
9
0
15
5
6
15
0
8
8
3
A
8
6
1
15
4 0
11
6
15 0
11
4
30
10
7
10
t
10
10
Value = 6 + 0 + 8 - 1 + 11
= 24
38
Flows and Cuts
Flow value lemma. Let f be any flow, and let (A, B) be any s-t cut.
Then, the net flow sent across the cut is equal to the amount leaving s.
 f (e)   f (e)  v( f )
e out of A

6
2
10
10
4 4
3
s
e in to A
5
9
0
15
5
6
15
0
8
8
3
A
8
6
1
15
4 0
11
6
15 0
11
4
30
10
7
10
t
10
10
Value = 10 - 4 + 8 - 0 + 10
= 24
39
Flows and Cuts
Flow value lemma. Let f be any flow, and let (A, B) be any s-t cut. Then
 f (e)   f (e)  v( f ) .
e out of A
Pf.
e in to A
v( f ) 

 f (e)
e out of s
by flow conservation, all terms
except v = s are 0




   f (e)   f (e)

v  A e out of v
e in to v
 f (e)   f (e).
e out of A
e in to A

40
Flows and Cuts
Weak duality. Let f be any flow, and let (A, B) be any s-t cut. Then the
value of the flow is at most the capacity of the cut.
Cut capacity = 30 
10
s
5
Flow value  30
2
9
5
4
15
15
10
3
8
6
10
4
6
15
4
30
t
A
15
7
10
Capacity = 30
41
Flows and Cuts
Weak duality. Let f be any flow. Then, for any s-t cut (A, B) we have
v(f)  cap(A, B).
Pf.
v( f ) 
 f (e)   f (e)
e out of A

A
4
8
e in to A
B
t
 f (e)
e out of A

 c(e)
s
e out of A
 cap(A, B)
▪
7
6

42
Certificate of Optimality
Corollary. Let f be any flow, and let (A, B) be any cut.
If v(f) = cap(A, B), then f is a max flow and (A, B) is a min cut.
Value of flow = 28
Cut capacity = 28 
Flow value  28
9
2
9
4
1
15
10
10
0
4
5
s
5
9
15
0
9
8
3
8
6
4
A
15
4 0
14
6
10
15 0
10
t
10
10
14
4
30
7
43
Bipartite Matching
Matching
Matching.
Input: undirected graph G = (V, E).
M  E is a matching if each node appears in at most one edge in M.
Max matching: find a max cardinality matching.



45
Bipartite Matching
Bipartite matching.
Input: undirected, bipartite graph G = (L  R, E).
M  E is a matching if each node appears in at most one edge in M.
Max matching: find a max cardinality matching.



1
1'
2
2'
matching
1-2', 3-1', 4-5'
L
3
3'
4
4'
5
5'
R
46
Bipartite Matching
Bipartite matching.
Input: undirected, bipartite graph G = (L  R, E).
M  E is a matching if each node appears in at most edge in M.
Max matching: find a max cardinality matching.



1
1'
2
2'
max matching
1-1', 2-2', 3-3' 4-4'
L
3
3'
4
4'
5
5'
R
47
Bipartite Matching
Max flow formulation.
Create digraph G' = (L  R  {s, t}, E' ).
Direct all edges from L to R, and assign infinite (or unit) capacity.
Add source s, and unit capacity edges from s to each node in L.
Add sink t, and unit capacity edges from each node in R to t.




G'
1
1
s
L

1'
2
2'
3
3'
4
4'
5
5'
1
t
R
48
Bipartite Matching: Proof of Correctness
Theorem. Max cardinality matching in G = value of max flow in G'.
Pf. 
Given max matching M of cardinality k.
Consider flow f that sends 1 unit along each of k paths.
f is a flow, and has cardinality k. ▪



G
1
1'
2
2'
3
3'
4
5
1
1

1'
2
2'
3
3'
4'
4
4'
5'
5
5'
s
1
t
G'
49
Bipartite Matching: Proof of Correctness
Theorem. Max cardinality matching in G = value of max flow in G'.
Pf. 
Let f be a max flow in G' of value k.
Integrality theorem  k is integral and can assume f is 0-1.
Consider M = set of edges from L to R with f(e) = 1.
– each node in L and R participates in at most one edge in M
– |M| = k: consider cut (L  s, R  t) ▪



1
1
s
G'

1'
1
1
1'
2
2'
3
3'
2
2'
3
3'
4
4'
4
4'
5
5'
5
5'
t
G
50
Disjoint Paths
Edge Disjoint Paths
Disjoint path problem. Given a digraph G = (V, E) and two nodes s and t,
find the max number of edge-disjoint s-t paths.
Def. Two paths are edge-disjoint if they have no edge in common.
Ex: communication networks.
s
2
5
3
6
4
7
t
52
Edge Disjoint Paths
Disjoint path problem. Given a digraph G = (V, E) and two nodes s and t,
find the max number of edge-disjoint s-t paths.
Def. Two paths are edge-disjoint if they have no edge in common.
Ex: communication networks.
s
2
5
3
6
4
7
t
53
Edge Disjoint Paths
Max flow formulation: assign unit capacity to every edge.
1
s
1
1
1
1
1
1
1
1
1
1
1
t
1
1
Theorem. Max number edge-disjoint s-t paths equals max flow value.
Pf. 
Suppose there are k edge-disjoint paths P1, . . . , Pk.
Set f(e) = 1 if e participates in some path Pi ; else set f(e) = 0.
Since paths are edge-disjoint, f is a flow of value k. ▪



54
Edge Disjoint Paths
Max flow formulation: assign unit capacity to every edge.
1
s
1
1
1
1
1
1
1
1
1
1
1
t
1
1
Theorem. Max number edge-disjoint s-t paths equals max flow value.
Pf. 
Suppose max flow value is k.
Integrality theorem  there exists 0-1 flow f of value k.
Consider edge (s, u) with f(s, u) = 1.
– by conservation, there exists an edge (u, v) with f(u, v) = 1
– continue until reach t, always choosing a new edge
Produces k (not necessarily simple) edge-disjoint paths. ▪




can eliminate cycles to get simple paths if desired
55
Network Connectivity
Network connectivity. Given a digraph G = (V, E) and two nodes s and t,
find min number of edges whose removal disconnects t from s.
Def. A set of edges F  E disconnects t from s if all s-t paths uses at
least on edge in F.
s
2
5
3
6
4
7
t
56
Edge Disjoint Paths and Network Connectivity
Theorem. [Menger 1927] The max number of edge-disjoint s-t paths is
equal to the min number of edges whose removal disconnects t from s.
Pf. 
Suppose the removal of F  E disconnects t from s, and |F| = k.
All s-t paths use at least one edge of F. Hence, the number of edgedisjoint paths is at most k. ▪


s
2
5
3
6
4
7
t
s
2
5
3
6
4
7
t
57
Disjoint Paths and Network Connectivity
Theorem. [Menger 1927] The max number of edge-disjoint s-t paths is
equal to the min number of edges whose removal disconnects t from s.
Pf. 
Suppose max number of edge-disjoint paths is k.
Then max flow value is k.
Max-flow min-cut  cut (A, B) of capacity k.
Let F be set of edges going from A to B.
|F| = k and disconnects t from s. ▪





A
s
2
5
3
6
4
7
t
s
2
5
3
6
4
7
t
58
Extensions to Max Flow
Circulation with Demands
Circulation with demands.
Directed graph G = (V, E).
Edge capacities c(e), e  E.
Node supply and demands d(v), v  V.



demand if d(v) > 0; supply if d(v) < 0; transshipment if d(v) = 0
Def. A circulation is a function that satisfies:
For each e  E:
0  f(e)  c(e)
For each v  V:
 f (e)   f (e)  d (v)


e in to v
(capacity)
(conservation)
e out of v
Circulation problem: given (V, E, c, d), does there exist a circulation?

60
Circulation with Demands
Necessary condition: sum of supplies = sum of demands.
 d(v) 
v : d (v)  0
  d(v) : D
v : d (v)  0
Pf. Sum conservation constraints for every demand node v.

-6
-8
6
7
4
10
-7
6 6
1
7
7
9
4 2
3
3
10
supply
0
11
4
4
capacity
demand
flow
61
Circulation with Demands
Max flow formulation.
-6
-8
supply
G:
7
4
10
6
-7
7
9
4
4
3
10
0
11
demand
62
Circulation with Demands
Max flow formulation.
Add new source s and sink t.
For each v with d(v) < 0, add edge (s, v) with capacity -d(v).
For each v with d(v) > 0, add edge (v, t) with capacity d(v).
Claim: G has circulation iff G' has max flow of value D.




saturates all edges
leaving s and entering t
s
7
6
8
supply
G':
7
10
7
6
9
4
4
3
0
10
11
demand
t
63
Circulation with Demands
Integrality theorem. If all capacities and demands are integers, and
there exists a circulation, then there exists one that is integer-valued.
Pf. Follows from max flow formulation and integrality theorem for max
flow.
Characterization. Given (V, E, c, d), there does not exists a circulation
iff there exists a node partition (A, B) such that vB dv > cap(A, B)
Pf idea. Look at min cut in G'.
demand by nodes in B exceeds supply
of nodes in B plus max capacity of
edges going from A to B
64
Project Selection
Project Selection
can be positive or negative
Projects with prerequisites.
Set P of possible projects. Project v has associated revenue pv.

–
some projects generate money: create interactive e-commerce interface,
redesign web page
–


others cost money: upgrade computers, get site license
Set of prerequisites E. If (v, w)  E, can't do project v and unless
also do project w.
A subset of projects A  P is feasible if the prerequisite of every
project in A also belongs to A.
Project selection. Choose a feasible subset of projects to maximize
revenue.
66
Project Selection: Prerequisite Graph
Prerequisite graph.
Include an edge from v to w if can't do v without also doing w.
{v, w, x} is feasible subset of projects.
{v, x} is infeasible subset of projects.



w
w
v
x
feasible
v
x
infeasible
67
Project Selection: Min Cut Formulation
Min cut formulation.
Assign capacity  to all prerequisite edge.
Add edge (s, v) with capacity -pv if pv > 0.
Add edge (v, t) with capacity -pv if pv < 0.
For notational convenience, define ps = pt = 0.




u
s
pu

py
y


w
-pw

z

pv
v


-pz
t
-px
x
68
Project Selection: Min Cut Formulation
Claim. (A, B) is min cut iff A  { s } is optimal set of projects.
Infinite capacity edges ensure A  { s } is feasible.
Max revenue because:
cap(A, B) 
 p v   ( p v )


v B: pv  0

v A: pv  0
pv  pv
v: pv  0
v A
constant
 w
A
u
pu
-pw
s
y
py
pv
z

v
t
-px


x
69