← Back to course

Math — Mechina

Linear programming

Summary

In linear programming we look for the largest (or smallest) value of a linear expression ax+byax+by when the variables satisfy several linear inequalities. The inequalities make a region — a polygon in the plane — and the extreme value is always reached at one of its vertices.

objective:  z=ax+by → max⁡/min⁡,constraints:  a1x+b1y≤c1, …, x,y≥0\text{objective: }\ z=ax+by\ \to\ \max/\min,\qquad \text{constraints: }\ a_1x+b_1y\le c_1,\ \ldots,\ x,y\ge0

Symbols in the formulas

zz
The objective function — what we want to increase (profit) or decrease (cost)
x, yx,\ y
The variables — for example how many units of each product
a1x+b1y≤c1a_1x+b_1y\le c_1
A constraint — a limit (machine hours, material, budget)

Where it comes from: the lines ax+by=zax+by=z for different zz are parallel. Move the line in the direction in which zz grows; the last point still touching the region is a vertex (or a whole edge, and then the value is the same at both of its vertices).

  • Draw each constraint as a line and mark the side that satisfies it (test with the point (0,0)(0,0)).
  • Vertices = intersections of pairs of lines that satisfy all the constraints.
  • Substitute each vertex into the objective function and choose the right one.
  • In a practical problem — check that the answer is in whole numbers and fits the story.

Question types

1

Maximum on a region

Constraints and an objective function are given, or a practical problem (a factory, a diet) to translate.

Worked example

x,y≥0x,y\ge0, x+y≤4x+y\le4, x+3y≤6x+3y\le6. What is the largest value of 2x+3y2x+3y?

Solution

IdeaFind the vertices of the region and substitute into each.
  1. Vertices on the axes: (0,0)(0,0), (4,0)(4,0) (from x+y=4x+y=4), (0,2)(0,2) (from x+3y=6x+3y=6).
  2. Intersection of the two lines: x+y=4x+y=4 and x+3y=6x+3y=6 give 2y=22y=2, i.e. (3,1)(3,1).
  3. Substitute: (4,0)→8(4,0)\to8, (0,2)→6(0,2)\to6, (3,1)→9(3,1)\to9, (0,0)→0(0,0)\to0.
  4. The maximum: 99 at (3,1)(3,1).
Check(3,1)(3,1) satisfies both constraints: 4≤44\le4, 6≤66\le6 ✓.
Common mistakeTaking an axis intersection outside the region, such as (0,4)(0,4).
2

A practical problem

Profit from several products with limited resources.

Worked example

Product A: profit 3030, 22 machine hours and one work hour. B: profit 2020, one machine hour and one work hour. There are 100100 machine hours and 8080 work hours. How many of each to produce?

Solution

Ideaxx units of A, yy units of B: 2x+y≤1002x+y\le100, x+y≤80x+y\le80, objective 30x+20y30x+20y.
  1. Vertices: (0,0)(0,0), (50,0)(50,0), (0,80)(0,80).
  2. Intersection: 2x+y=1002x+y=100 and x+y=80x+y=80 give x=20x=20, y=60y=60.
  3. Substitute: (50,0)→1500(50,0)\to1500, (0,80)→1600(0,80)\to1600, (20,60)→1800(20,60)\to1800.
  4. Produce 2020 of A and 6060 of B, profit 18001800.
Check2⋅20+60=1002\cdot20+60=100, 20+60=8020+60=80 — all hours are used ✓.
Common mistakeProducing only the most profitable product per unit.

Practice · 13

Test yourself with problems and full solutions.

Go to practice