Linear Programming
LP formulation, graphical method, simplex algorithm, duality theory, transportation and assignment problems — with step-by-step worked examples, key theorems, and interactive practice.
A linear programming (LP) problem seeks to optimise a linear objective function subject to linear constraints. Formulating real-world problems as LPs is the first and most important step.
- Feasible region: The set $S = \{\mathbf{x} : A\mathbf{x} \le \mathbf{b}, \mathbf{x} \ge \mathbf{0}\}$. This is always a convex polyhedron (possibly empty or unbounded).
- Feasible solution: Any $\mathbf{x} \in S$.
- Optimal solution: A feasible solution $\mathbf{x}^*$ at which $z$ attains its maximum.
- Basic feasible solution (BFS): A vertex (extreme point) of the feasible polyhedron.
Maximise $z = 40x_1 + 70x_2$
Subject to: $2x_1 + 3x_2 \le 120$ (carpentry), $x_1 + 2x_2 \le 80$ (finishing), $x_1, x_2 \ge 0$.
Any LP can be converted to the form: Maximise $\mathbf{c}^T\mathbf{x}$ subject to $A\mathbf{x} = \mathbf{b}$, $\mathbf{x} \ge 0$, using these transformations:
- Minimisation to maximisation: $\min z = \max(-z)$.
- $\le$ to equality: Add a slack variable $s \ge 0$: $a^T\mathbf{x} + s = b$.
- $\ge$ to equality: Subtract a surplus variable $s \ge 0$: $a^T\mathbf{x} - s = b$.
- Unrestricted variable: Replace $x_j$ by $x_j^+ - x_j^-$ where $x_j^+, x_j^- \ge 0$.
For LP problems with two decision variables, the feasible region can be drawn in the plane and the optimal vertex identified by inspection or by evaluating the objective at each vertex.
Algorithm:
- Step 1: Plot each constraint as a line and shade the feasible half-plane.
- Step 2: Identify the feasible region (the intersection of all half-planes and the non-negativity constraints).
- Step 3: Find all vertices (corner points) of the feasible region by solving pairs of constraint equations simultaneously.
- Step 4: Evaluate the objective function at each vertex and select the maximum (or minimum).
- $(0, 0)$: $z = 0$
- $(60, 0)$: $z = 2400$
- $(0, 40)$: $z = 2800$
- Intersection of $2x_1 + 3x_2 = 120$ and $x_1 + 2x_2 = 80$: solving gives $x_1 = 2(120 - 3x_2)/2$ and substituting, $x_1 = 0$... Let us solve correctly: from the second equation $x_1 = 80 - 2x_2$. Substituting: $2(80 - 2x_2) + 3x_2 = 120 \Rightarrow 160 - 4x_2 + 3x_2 = 120 \Rightarrow x_2 = 40$, $x_1 = 0$.
- Unbounded solution: The feasible region is unbounded in the direction of optimisation. The LP has no finite optimal value.
- Infeasible problem: The feasible region is empty (constraints are contradictory).
- Multiple optimal solutions: The objective function is parallel to a binding constraint, so the entire edge (between two optimal vertices) is optimal.
- Degenerate vertex: More than two constraint lines pass through the same point.
The simplex method is the workhorse algorithm of linear programming. It systematically moves from one basic feasible solution to an adjacent one with a better (or equal) objective value, reaching optimality in finitely many steps.
- Basic variables: Variables currently in the basis (their columns form an identity submatrix).
- Non-basic variables: Variables set to $0$.
- Pivot column: The column with the most negative coefficient in the objective row (entering variable).
- Pivot row: Determined by the minimum ratio test: $\min\{b_i / a_{ij} : a_{ij} > 0\}$ (leaving variable).
$6x_1 + 4x_2 + s_1 = 24$, $x_1 + 2x_2 + s_2 = 6$, $x_1, x_2, s_1, s_2 \ge 0$.
Initial tableau:
$\begin{array}{c|cccc|c} & x_1 & x_2 & s_1 & s_2 & \text{RHS} \\ \hline s_1 & 6 & 4 & 1 & 0 & 24 \\ s_2 & 1 & 2 & 0 & 1 & 6 \\ \hline z & -5 & -4 & 0 & 0 & 0 \end{array}$
Iteration 1: Most negative in $z$-row: $-5$ ($x_1$ enters). Ratios: $24/6 = 4$, $6/1 = 6$. Min ratio $= 4$ (row 1). Pivot on $a_{11} = 6$.
Divide row 1 by 6: $(1, \frac{2}{3}, \frac{1}{6}, 0 \mid 4)$.
Row 2 $\leftarrow$ Row 2 $- 1 \cdot$ (new Row 1): $(0, \frac{4}{3}, -\frac{1}{6}, 1 \mid 2)$.
$z$-row $\leftarrow$ $z$-row $+ 5 \cdot$ (new Row 1): $(0, -\frac{2}{3}, \frac{5}{6}, 0 \mid 20)$.
Iteration 2: Most negative: $-\frac{2}{3}$ ($x_2$ enters). Ratios: $4/(2/3) = 6$, $2/(4/3) = 3/2$. Min ratio $= 3/2$ (row 2). Pivot on $\frac{4}{3}$.
Divide row 2 by $\frac{4}{3}$: $(0, 1, -\frac{1}{8}, \frac{3}{4} \mid \frac{3}{2})$.
Row 1 $\leftarrow$ Row 1 $- \frac{2}{3} \cdot$ (new Row 2): $(1, 0, \frac{1}{4}, -\frac{1}{2} \mid 3)$.
$z$-row $\leftarrow$ $z$-row $+ \frac{2}{3} \cdot$ (new Row 2): $(0, 0, \frac{3}{4}, \frac{1}{2} \mid 21)$.
Result: All $z$-row coefficients $\ge 0$. Optimal solution: $x_1 = 3$, $x_2 = 3/2$, $z^* = 21$.
Big-M Method: Add artificial variables $a_i$ with a very large penalty $-Ma_i$ in the objective (for maximisation, where $M \gg 0$). If any artificial variable remains positive in the optimal solution, the original LP is infeasible.
Two-Phase Method:
- Phase I: Minimise the sum of artificial variables. If the minimum is $0$, a BFS for the original problem is found.
- Phase II: Drop artificial variables and optimise the original objective starting from the Phase I basis.
Every LP (the primal) has a companion LP (the dual). Duality theory provides deep insights into the structure of optimal solutions and economic interpretation of constraints.
- $x_j^*\left(\sum_i a_{ij}y_i^* - c_j\right) = 0$ for all $j$ — if $x_j^* > 0$, the corresponding dual constraint is tight.
- $y_i^*\left(b_i - \sum_j a_{ij}x_j^*\right) = 0$ for all $i$ — if $y_i^* > 0$, the corresponding primal constraint is tight.
Transportation and assignment problems are special LP problems with efficient solution methods that exploit their network structure.
Initial BFS methods:
- North-West Corner: Start at $(1,1)$ and allocate as much as possible, moving right or down.
- Least Cost Method: Allocate first to the cell with the smallest $c_{ij}$.
- Vogel's Approximation (VAM): For each row/column, compute the penalty (difference between the two smallest costs). Allocate to the cell with the smallest cost in the row/column with the largest penalty. Repeat. VAM generally produces a near-optimal initial solution.
Cell $(1,1)$: $\min(20, 10) = 10$. $x_{11} = 10$. Remaining: $s_1 = 10$, $d_1 = 0$. Move right.
Cell $(1,2)$: $\min(10, 25) = 10$. $x_{12} = 10$. Remaining: $s_1 = 0$, $d_2 = 15$. Move down.
Cell $(2,2)$: $\min(30, 15) = 15$. $x_{22} = 15$. Remaining: $s_2 = 15$, $d_2 = 0$. Move right.
Cell $(2,3)$: $\min(15, 15) = 15$. $x_{23} = 15$. Done.
Initial BFS: $x_{11} = 10$, $x_{12} = 10$, $x_{22} = 15$, $x_{23} = 15$.
Hungarian Algorithm:
- Step 1: Subtract the row minimum from each row.
- Step 2: Subtract the column minimum from each column.
- Step 3: Cover all zeros using the minimum number of lines (rows/columns).
- Step 4: If the number of lines equals $n$, an optimal assignment exists. Otherwise, find the smallest uncovered element $\varepsilon$, subtract $\varepsilon$ from all uncovered elements, add $\varepsilon$ to doubly-covered elements, and repeat Step 3.
Step 2 (Column reduction): Col mins: $3, 0, 0$. Subtract: $\begin{pmatrix} 4 & 0 & 5 \\ 0 & 1 & 0 \\ 1 & 7 & 0 \end{pmatrix}$.
Step 3: Zeros can be covered by 3 lines (e.g., row 2, col 2, col 3). Since $3 = n$, we can find an optimal assignment.
Assignment: $(1,2)$: cost $2$; $(2,1)$: cost $6$; $(3,3)$: cost $1$. Total cost $= 2 + 6 + 1 = 9$.
- An LP has a linear objective and linear constraints. The feasible region is a convex polyhedron, and the optimum occurs at a vertex.
- The graphical method works for 2-variable problems by evaluating the objective at each vertex of the feasible polygon.
- The simplex method moves between adjacent vertices, improving the objective at each step, using the most negative coefficient to select the entering variable and the minimum ratio test for the leaving variable.
- Weak duality: $\mathbf{c}^T\mathbf{x} \le \mathbf{b}^T\mathbf{y}$ for any primal-dual feasible pair. Strong duality: equality holds at optimality.
- Complementary slackness links primal and dual solutions: a positive variable implies its constraint is tight, and vice versa.
- Transportation and assignment problems have specialised algorithms (VAM, Hungarian method) that are much faster than general simplex.