15-451 Algorithms 11/02/00
* Linear programming
Quiz #2 next Thurs. 1 sheet notes.
============================================================================
In last couple of classes we looked at:
- Bipartite matching: Given a bipartite graph, find the largest set
of edges with no endpoints in common.
- Network flow. (More general than bipartite matching)
- Min-Cost Max-flow (even more general than plain max flow).
Today, we'll look at something even more general: Linear Programming.
Here, "programming" is meant like "program of action" as in DP.
Linear Programming is important because it is very powerful: many many
problems can be coded up as linear programs. Especially problems of
allocating resources and a lot of business applications. In GSIA
there are entire courses devoted to linear programming. We're only
going to have time for 1 lecture. So, will just have time to say what
they are, and give examples of encoding problems as LPs, will only get
a chance to say a little bit about algorithms for solving them.
Before defining, motivate with an example:
There are 168 hours in a week. Say we want to allocate our time
between classes and studying (S), going to parties (P), and everything
else (E) (eating, sleeping, taking showers, etc). To survive need to
spend at least 56 hours on E (8 hrs/day). To pass courses, need S >=
60, but more if don't sleep enough or spend too much time partying:
2S+E-3P >= 150. (e.g., if don't party at all then this isn't a
problem, but if we spend more time on P then need to sleep more or
study more). To maintain sanity need P+E >= 70. Q1: can we do this?
Formally, is there a *feasible* solution?
A: yes. For instance, one feasible solution: S=80, P=20, E = 68
Q2: What is the maximum partying that we can do? Can we do P=30? No:
the 2S+E-3P >=150 constraint becomes 2S+E >= 240. Even if set E=56
(minimum) then need S = 92, which is too many hours. So, somewhere in
between.
Q3: maybe our notion of happiness is expressed by 2P+E. What is a
feasible solution such that this is maximized? The formula "2P+E" is
called an *objective function*.
This is called a *linear program*. What makes it linear is that all
our constraints were linear in our variables. E.g., 2S+E-3P>=150.
And our objective function is also linear. Not allowed things like
requiring S*E >= 100, since this wouldn't be linear.
More formally, here is the definition of the linear programming problem
DEFINITION OF LINEAR PROGRAMMING PROBLEM:
========================================
Have n variables x_1,..., x_n.
Have m linear inequalities in these variables (equalities OK too):
E.g.,
3x_1 + 4x_2 <= 6
x_1 >= 0
etc.
May also have an objective function: 2x_1 + 3x_2 + x_3.
Goal: find values for the x_i's that satisfy the constraints and
maximizes the objective.
"feasibility problem": no objective, just want to satisfy the constraints.
For instance, let's write out our time allocation problem this way.
Variables are S, P, E.
objective is to maximize 2P+E.
subject to these constraints:
S + P + E = 168
E >= 56
S >= 60
2S+E-3P >= 150
P+E >= 70
P >= 0 (can't spend negative time partying)
MORE EXAMPLES OF MODELLING PROBLEMS AS LINEAR PROGRAMS:
======================================================
Typical Operations-Research kind of problem (from Mike Trick):
Have 4 production plants for making cars. Each works a little
differently in terms of labor needed, materials, and
pollution produced per car:
labor materials pollution
plant 1 2 3 15
plant 2 3 4 10
plant 3 4 5 9
plant 4 5 6 7
We need to produce 400 cars at plant 3 according to labor agreement.
Have 3300 hours of labor, 4000 units of material available. Allowed
to produce 12000 units of pollution. Want to maximize number of cars
produced. How to model?
First step: What are the variables?
x_1,x_2,x_3,x_4, where x_i = # cars at plant i.
Second step: What is our objective?
maximize x_1+x_2+x_3+x_4
Last step: what are the constraints?
x_i >= 0 for all i
x_3 >= 400
2x_1 + 3x_2 + 4x_3 + 5x_4 <= 3300
3x_1 + 4x_2 + 5x_3 + 6x_4 <= 4000
15x_1 + 10x_2 + 9x_3 + 7x_4 <= 12000
MAX FLOW:
Variables: set up one variable x_e per edge e. Let's just represent
the positive flow.
Objective: maximize SUM x_e
edges e into T
Constraints:
For all e, x_e <= c_e and x_e >= 0. [c_e is capacity of edge e]
For each node v except S and T,
SUM x_e = SUM x_e'
edges e into v edges e' leaving v
Example:
S-->A, cap = 4. A-->C, cap=3. C-->T, cap = 2.
S-->B, cap = 2. B-->D, cap=3. D-->T, cap = 4.
C-->B, cap = 1. B-->C, cap=2.
LP is: maximize x_ct + x_dt subject to
0 <= x_sa <= 4, etc.
x_sa = x_ac,
x_sb + x_cb = x_bc + x_bd,
x_ac + x_bc = x_cb + x_ct,
x_bd = x_dt
How about min cost max flow? First solve for max flow f. Then add a
constraint that flow must equal f, and minimize linear cost function
sum_e cost(e)*flow(e).
2-PLAYER ZERO-SUM GAMES:
Here is payoff matrix for row player:
20 -10 5
5 10 -10
-5 0 10
What is minimax optimal strategy for row? Use x_1, x_2, x_3 are
probabilities on rows 1, 2, and 3 respectively. Want to maximize the
worst case (minimum), over all columns opponent can play, of expected
gain. Can do like this:
maximize v such that:
x's are a prob dist: x_1 + x_2 + x_3 = 1
x_1 >= 0, x_2 >= 0, x_3 >=0
get at least v if col1: 20*x_1 + 5*x_2 -5*x_3 >= v
..... if col2: -10*x_1 + 10*x_2 >= v
..... if col3: 5*x_1 - 10x_2 + 10x_3 >= v
How to solve linear programs? History: the standard algorithm for
solving LPs the Simplex Algorithm, developed in the 40s. It's *not*
guaranteed to run in polynomial time, and you can come up with bad
examples for it, but in general it runs pretty fast. Only much later
in 1980 was it shown that linear programming could be done in
polynomial time by something called the Ellipsoid Algorithm (but it is
pretty slow). Later on, a faster polynomial-time algorithm Karmarkar's
Alg was developed, which is competitive with Simplex. There are a lot
of commercial LP packages, for instance LINDO, CPLEX, Solver (in Excel).
Won't have time to describe any of these in detail. Instead, give
some intuition by viewing LP as a geometrical problem.
Think of an n-dimensional space with one coordinate per variable. A
solution is a point in this space. An inequality, like x_1 + x_2 <= 6
is saying that we need solution to be on a specified side of a certain
hyperplane. Feasible region is the convex region in space defined by
these constraints. Then we want to find the feasible point that is
farthest in the "objective" direction.
Let's go to first example with S, P, E. To make this easier to draw,
can use our first constraint that S+P+E = 168 to replace S with 168-P-E.
So, just draw in 2 dimensions: P and E.
Constraints are:
E >= 56
P+E >= 70
P >= 0
S >= 60 which means 168-P-E >= 60 or P+E <= 108.
2S-3P+E >= 150 which means 2(168-P-E)-3P+E >= 150 or 5P+E <= 186
For objective of max P, this happens at E=56, P = 26.
For objective of max 2P+E, this happens at P=19.5, E=88.5
Can use this view to motivate the algorithms.
SIMPLEX ALG: Earliest and most common algorithm called Simplex method.
Idea: start at some "corner" of the feasible region (to make this
easier, we can add in "slack variables" that will drop out when we do
our optimization). Then we repeatedly do the following step: look at
all neighboring corners and go to the best one if it is better. Stop
when we get to a corner where no neighbor is better than we are. Neat
fact is that since the objective is linear, the optimal solution will
be at a corner (or maybe multiple corners). Furthermore, there are no
local maxima: if you're *not* optimal then some neighbor of you is
better than you are. That's because this is a convex region. So,
Simplex method is guaranteed to halt at the best solution. The
problem is that it is possible for there to be an exponential number
of corners and it is possible for Simplex to take an exponential
number of steps to converge. But, in practice this usually works
suboptimal corners that are better than all their neighbors.
ELLIPSOID ALGORITHM: Invented by Khachiyan in 1980 in Russia.
Solve "feasibility problem" (Then can do binary search with our
objective function). Start with big ellipse (called an
ellipsoid in higher dimensions) that we can be sure contains the
feasible region. Then try the center of the ellipse -- see if it
violates any constraints. If not, you're done. If so, look at the
constraint violated. So we know the solution (if any) is contained in
the remaining half-ellipse. Now, find a new smaller ellipse that
contains the half-ellipse remaining. Can show the new smaller ellipse
has a volume that's significantly smaller. If ever get to too small
volume can prove there can't be a solution.
One nice thing about ellipsoid algorithm is you just need to tell if
the current solution violates any constraints or not, and if so, to
produce one. Don't need to explicitly write them all down.
KARMARKAR'S ALGORITHM: Sort of has aspects of both. Works with
feasible points but doesn't go from corner to corner. Instead it
moves inside the interior of the feasible region. One of first of a
whole class of so-called "interior-point methods".
Development of better and better algorithms is a big ongoing area of
research. In particular, get a lot of mileage by using good data
structures to speed up time in making each decision.