Linear Programs |
Example:
We can make dough for 2 types of muffins (A or B). We can charge different prices for these:
The different doughs have different compositions:
We have the following amounts of ingredients available:
How do we find out how much dough of which type we want to make for maximum revenue?
We can denote the amount of dough (in grams) of Type A with $x_1$ and the amount of dough of Type B with $x_2$.
We therefore want to determine the amount of dough of Type A and B that brings us the maximum revenue:
\[ \begin{aligned} \max \quad & 0.6 x_1 + 0.5 x_2 \\ \end{aligned} \] (Revenue in Cents)
We have 1500g flour. Dough A consists of 80% flour, Dough B of 50%.
What does this mean for $x_1$ and $x_2$?
$0.8 x_1 + 0.5 x_2 \leq 1500$
We can try to visualize this:
|
The line |
|
We can, of course, use less than the total amount of flour:
$\color{blue} 0.8 x_1 + 0.5 x_2 \leq 1500$
Similarly, we have 900g of chocolate. Dough A consists of 20% chocolate, dough B of 50%.
$\color{red} 0.2 x_1 + 0.5 x_2 \leq 900$
Of course, we cannot produce less than 0 grams of any dough:
| $ x_1 \geq 0\\ x_2 \geq 0 $ |
|
We now know the amount with all possible dough combinations we can make.
Which generates the highest revenue?
Our goal was:
\[ \begin{aligned} \max \quad & 0.6 x_1 + 0.5 x_2 \\ \end{aligned} \]All mix ratios in which we earn exactly 500 cents:
$0.6 x_1 + 0.5 x_2 = 500$
The direction in which we earn more is e.g., the vector \[ \begin{bmatrix} 0.6 \\ 0.5 \end{bmatrix} \qquad \text{or} \qquad \begin{bmatrix} 6 \\ 5 \end{bmatrix} \]
Graphically, we can now determine the best dough ratio:
|
|
What we can also see directly from the graphical solution:
The entire problem taken together could be formulated as follows:
\[ \begin{aligned} \max \quad & 0.6 x_1 + 0.5 x_2 \\ \text{subject to} \quad & 0.8 x_1 + 0.5 x_2 \leq 1500 \\ & 0.2 x_1 + 0.5 x_2 \leq 900 \\ & x_1 \geq 0 \\ & x_2 \geq 0 \end{aligned} \]
This formulation is called a
Linear Program (LP).
An LP has the following structure:
Linear means that a term consists only of a sum, and each summand may contain at most one variable. The variable can be multiplied by a factor.
A linear term can always be graphically interpreted as a line or plane.
Linear:
Non-linear:
What do we want to do with LPs?
We can also express LPs in a vectorized form.
The constraints as a matrix-vector product:
\[ \underbrace{ \begin{bmatrix} 0.8 & 0.5 \\ 0.2 & 0.5 \end{bmatrix} }_{A} \underbrace{ \begin{bmatrix} x_1 \\ x_2 \end{bmatrix} }_{x} \leq \underbrace{ \begin{bmatrix} 1500 \\ 900 \end{bmatrix} }_{b} \]
The objective function as a vector-vector product:
\[ \max \quad {\underbrace{ \begin{bmatrix} 0.6 \\ 0.5 \end{bmatrix} }_{c}}^T \underbrace{ \begin{bmatrix} x_1 \\ x_2 \end{bmatrix} }_{x} \]Every linear program can generally be written as:
\[ \begin{aligned} \max \quad & c^T x \\ \text{subject to} \quad & Ax \leq b \\ & x \geq 0 \end{aligned} \]What matters is what's in $A$, $b$, and $c$.
This notation is called canonical form.
Every LP can be converted into canonical form.
$$\min \; c^T x \quad \Leftrightarrow \quad \max\; -c^T x$$
What if we do not want $x_i \geq 0$?
We can simply replace $x_i$ with $x_i^+ - x_i^-$.
\[ \begin{aligned} \max \quad & \underbrace{\begin{bmatrix} c_1 & c_2 & \cdots & c_n \end{bmatrix}}_{\color{blue} c^T} \underbrace{\begin{bmatrix} x_1 \\ x_2 \\ \vdots\\ x_n \end{bmatrix}}_{\color{blue} x}\\ \text{subject to} \quad & \underbrace{\begin{bmatrix} a_{11} & a_{12} & \cdots & a_{1n} \\ a_{21} & a_{22} & \cdots & a_{2n} \\ \vdots & \vdots & \ddots & \vdots \\ a_{m1} & a_{m2} & \cdots & a_{mn} \end{bmatrix}}_{\color{blue} A} \underbrace{\begin{bmatrix} x_1 \\ x_2 \\ \vdots\\ x_n \end{bmatrix}}_{\color{blue} x} \leq \underbrace{\begin{bmatrix} b_1\\ b_2 \\ \vdots\\ b_m \end{bmatrix}}_{\color{blue} b} \\ & x \geq 0 \end{aligned} \]
Suppose we now have a very general "Muffin" problem:
\[ \begin{aligned} \max \quad & c^T x \\ \text{subject to} \quad & Ax \leq b \\ & x \geq 0 \end{aligned} \]
With more than 3 recipes, we cannot proceed with the graphical method. We need a more general algorithm.