Search

Search papers and lessons

Linear Programming

Level 2 · 9 min read

Linear programming maximizes or minimizes a linear objective over a region bounded by linear inequalities, and the best answer always sits at a corner of that region.

On this page

  • Colour = topic mix
  • Linear algebra
  • Optimization
  • Discrete math
  • Sign in to see your progress

TL;DR

A linear program asks for the best value of a linear function, such as profit or cost, subject to a set of linear limits such as "no more than 4 hours of machine time." The allowed choices form a flat-sided region, and a linear function on such a region reaches its best value at one of the corners. Linear programming is the study of finding that corner efficiently, even when there are thousands of variables.

Where you'll see it: in production planning and shipping logistics, in airline crew scheduling, in choosing the cheapest mix of ingredients that meets nutritional limits, and inside many machine-learning and control pipelines that reduce to a linear objective.

Intuition

Choices with limits

Suppose a workshop makes two products, and each product uses machine time and labour. You want the mix that earns the most money. Each limit on time or labour is a straight line in the plane of possible production amounts. Together the limits cut out a region: a polygon with straight edges. Any production plan inside the region is feasible. Any plan outside it breaks a limit.

Now the profit. A profit of 3x+2y3x + 2y for xx units of one product and yy of the other is a family of parallel straight lines, one for each profit level. Moving the profit level up slides these lines outward. The last line that still touches the region is the best one, and it touches at a corner (if it happens to lie along a whole edge, the two corners at that edge's ends tie). Nothing in the middle of an edge beats the better of its two end corners, because profit changes at a constant rate along a straight edge.

That observation is the core of linear programming. You do not have to search the whole region. You only have to compare its corners.

01234501234xy
  • x + y = 4
  • x + 3y = 6
The feasible region is the area below both lines and above zero. Its corners are (0,0), (4,0), (3,1) and (0,2). The best corner for profit 3x + 2y is (4,0).

Why the corner matters

A convex set is one where the segment between any two points stays inside. The feasible region of a linear program is convex, because each linear inequality defines a half-plane, and the intersection of half-planes is convex. On a convex polygon a linear objective has no local maxima other than global ones, and it is always achieved at an extreme point. That is why the search can be restricted to corners.

The math

Standard form

A linear program is usually written as

maximizec⊤xsubject toAx≤b,x≥0.\begin{aligned} \text{maximize} \quad & \mathbf{c}^\top \mathbf{x} \\ \text{subject to} \quad & A\mathbf{x} \le \mathbf{b}, \\ & \mathbf{x} \ge 0. \end{aligned}

Here x\mathbf{x} is a vector of nn decision variables, c\mathbf{c} holds the objective coefficients, AA is an m×nm \times n Matrix of constraint coefficients, and b\mathbf{b} holds the limits. The inequality between vectors is read entry by entry. Minimization is the same problem with −c-\mathbf{c}, and equality or reversed constraints can be rewritten into this form by adding slack variables.

For the workshop example with profit 3x+2y3x + 2y, the constraints x+y≤4x + y \le 4 and x+3y≤6x + 3y \le 6 are two rows of AA, and b=(4,6)⊤\mathbf{b} = (4, 6)^\top.

Vertices

A point of the feasible region is a vertex if it is the unique solution of nn linearly independent constraints set to equality. Geometrically, it is a corner. The fundamental theorem says that if a linear program has a finite optimum, then some optimal solution is a vertex.

The proof idea is short. Suppose the optimum lies strictly inside an edge. Move along the edge in the direction that keeps the objective nondecreasing, and you reach an endpoint that is at least as good. Repeating this pushes you to a corner.

Duality

Every linear program has a companion called its dual, which uses the same data to produce a bound on the optimum. For the maximization above, the dual is a minimization over multipliers y≥0\mathbf{y} \ge 0:

minimizeb⊤ysubject toA⊤y≥c,y≥0.\text{minimize} \quad \mathbf{b}^\top \mathbf{y} \quad \text{subject to} \quad A^\top \mathbf{y} \ge \mathbf{c}, \quad \mathbf{y} \ge 0.

Any feasible y\mathbf{y} gives an upper bound on the primal objective, because c⊤x≤(A⊤y)⊤x=y⊤Ax≤b⊤y\mathbf{c}^\top\mathbf{x} \le (A^\top \mathbf{y})^\top \mathbf{x} = \mathbf{y}^\top A \mathbf{x} \le \mathbf{b}^\top \mathbf{y}. When both problems have optima, they are equal (strong duality). This idea is the bridge to Lagrangian Duality.

Worked examples

Example
Maximize profit on the workshop region

Maximize 3x+2y3x + 2y subject to x+y≤4x + y \le 4, x+3y≤6x + 3y \le 6, x≥0x \ge 0, y≥0y \ge 0.

  1. List the vertices. The four corners of the region are (0,0)(0,0), (4,0)(4,0), (3,1)(3,1) and (0,2)(0,2).
  2. Find (3,1)(3,1) by solving x+y=4x + y = 4 and x+3y=6x + 3y = 6. Subtracting gives 2y=22y = 2, so y=1y = 1 and x=3x = 3.
  3. Evaluate the objective at each vertex:
    • (0,0)(0,0) gives 00.
    • (4,0)(4,0) gives 1212.
    • (3,1)(3,1) gives 1111.
    • (0,2)(0,2) gives 44.
  4. Check feasibility of the best one. At (4,0)(4,0), x+y=4≤4x + y = 4 \le 4 and x+3y=4≤6x + 3y = 4 \le 6, so it is feasible.
  5. The maximum is 1212, attained at (4,0)(4,0).

Interpretation: the workshop should spend all its first-type capacity and nothing on the second product. Note that the intersection vertex (3,1)(3,1) looks like a balanced mix but earns less. The corner comparison catches this without any intuition about balance.

Example
Minimize cost with covering constraints

Minimize 2x+3y2x + 3y subject to x+2y≥8x + 2y \ge 8, 3x+y≥93x + y \ge 9, x≥0x \ge 0, y≥0y \ge 0. Think of a diet where xx and yy are servings of two foods that must together supply at least 8 units of protein and 9 units of vitamin.

  1. The feasible region is unbounded upward, but both costs are positive, so the cost cannot fall without limit and a minimum exists at a corner. Find the candidate vertices.
  2. Intersection of x+2y=8x + 2y = 8 and 3x+y=93x + y = 9: from the second, y=9−3xy = 9 - 3x. Substituting gives x+18−6x=8x + 18 - 6x = 8, so x=2x = 2 and y=3y = 3. Check: 2+6=82 + 6 = 8 and 6+3=96 + 3 = 9. Cost =4+9=13= 4 + 9 = 13.
  3. On the xx-axis, y=0y = 0 requires x≥8x \ge 8 and x≥3x \ge 3, so the corner is (8,0)(8,0) with cost 1616.
  4. On the yy-axis, x=0x = 0 requires y≥4y \ge 4 and y≥9y \ge 9, so the corner is (0,9)(0,9) with cost 2727.
  5. The minimum over these corners is 1313, at (2,3)(2,3).

Interpretation: two servings of the first food and three of the second meet both requirements at the lowest cost. Covering problems have the same geometry as packing problems, only the feasible region is on the other side of the lines.

Tradeoffs and failure modes

Linear programming is fast and reliable when the model really is linear. The usual failures come from the model rather than the solver.

SituationProblemBetter choice
Objective or constraint is curvedThe corner argument no longer holdsConvex optimization, or piecewise-linear approximation
Variables must be whole numbersThe LP optimum can be fractional, for example half a machineInteger programming, which is much harder in general
Infeasible limitsThe region is empty and the solver reports infeasibilityRelax the least important limit, or find the conflicting pair
Unbounded objectiveProfit can grow forever because a limit is missingCheck that every real limit appears in the model
Very large sparse problemsDense tableau methods are slowRevised simplex on sparse matrices, or interior-point methods

The simplex method moves from one vertex to a neighbouring vertex that improves the objective, and stops when no neighbour is better. In the worst case it can visit exponentially many vertices, but in practice it is fast on real problems. Interior-point methods travel through the middle of the region and have polynomial worst-case guarantees.

History

The ideas appeared in several places at once in the late 1930s and 1940s. Leonid Kantorovich studied production planning with linear objectives in the Soviet Union in the late 1930s. George Dantzig, working on US Air Force planning problems, developed the simplex method in 1947 and promoted linear programming as a general planning tool. Tjalling Koopmans, who worked on the transport problem, helped establish the field's economic applications. Kantorovich and Koopmans shared the 1975 Nobel Memorial Prize in Economic Sciences for work on optimal resource allocation.

It caught on because industries had many linear limits and needed a reliable way to plan with them. The advent of computers made large instances solvable. In 1984 Narendra Karmarkar's interior-point method showed a practical alternative to the simplex method, and modern solvers use both.

Check yourself

QuestionRecall: why is the best point of a linear program at a corner of the feasible region?Show answer

The objective is linear, so along any straight edge it increases or decreases monotonically. If the optimum were in the middle of an edge, you could slide along the edge to an endpoint that is at least as good. Repeating this brings you to a vertex. The region is a polygon with a finite number of corners, so the search space is finite in this sense.

QuestionComputation: evaluate the objective 5x+y5x + y at the vertices (0,0)(0,0), (2,0)(2,0) and (1,3)(1,3) of some feasible region. Which is the maximum?Show answer

At (0,0)(0,0) the value is 00. At (2,0)(2,0) it is 1010. At (1,3)(1,3) it is 5+3=85 + 3 = 8. The maximum is 1010 at (2,0)(2,0).

QuestionWhy does a feasible point y\mathbf{y} of the dual give an upper bound on the primal maximum?Show answer

For any feasible primal x\mathbf{x} and dual y\mathbf{y}, we have c⊤x≤y⊤Ax\mathbf{c}^\top\mathbf{x} \le \mathbf{y}^\top A\mathbf{x} because A⊤y≥cA^\top\mathbf{y} \ge \mathbf{c} and x≥0\mathbf{x} \ge 0. Then y⊤Ax≤b⊤y\mathbf{y}^\top A\mathbf{x} \le \mathbf{b}^\top\mathbf{y} because Ax≤bA\mathbf{x} \le \mathbf{b} and y≥0\mathbf{y} \ge 0. Chaining gives c⊤x≤b⊤y\mathbf{c}^\top\mathbf{x} \le \mathbf{b}^\top\mathbf{y}, so no primal value can exceed any dual value.

QuestionApplied: a planner needs whole numbers of trucks, but the LP solution says 3.4 trucks. What is the right next step?Show answer

Dropping the whole-number requirement (the LP relaxation) gives an upper bound on the best integer profit (a lower bound for a cost minimisation), but not an integer solution. Round the variable carefully and check feasibility, or move to integer programming, which solves the discrete problem exactly but can be much slower. The planner should confirm which rounding still meets every constraint before committing.

Sources