TactivergeLite

Lite / Textbooks / Engineering Design and Optimization / Chapter 7

7. Linear programming and search

Version 1 · Technically checked (automated checks only) · 3 source lessons · Full interactive version

Introduction

When the objective and constraints are straight lines, the best design always sits at a corner of the feasible region, and linear programming finds it. When the landscape is bumpy, engineers search: a grid tries everything at a fixed spacing, gradient descent walks downhill, and both can be fooled by local minima. Some problems, such as ordering many tasks, are so large that only good heuristics are practical, and they must be reported as such.

Figure 7.1. The optimum is at a corner (described in words)

A linear programme: maximise 3x + 2y subject to x + y ≤ 8, 2x + y ≤ 12 and x, y ≥ 0. The feasible region has corners (0, 0), (6, 0), (4, 4) and (0, 8), scoring 0, 18, 20 and 16. The best is the corner (4, 4) with 20.

Explanation

Built from 3 School lessons. Each part is the lesson's own explanation.

7.1 Linear programming: why the corners win

A workshop has 24 machining hours and 30 assembly hours. Among infinitely many weekly plans, you only need to check four. Why?

Drawing the region

Turn each inequality into its boundary line (2x + y = 24 meets the axes at (12, 0) and (0, 24)), then shade the side that satisfies it (test the origin: 0 ≤ 24, so the origin's side). Non-negativity keeps you in the first quadrant. The overlap of all shaded regions is feasible.

Binding and slack constraints

At the optimum, a constraint that holds with equality is binding: that resource is fully used. One with spare capacity has slack. In the example both machining and assembly bind at (8.4, 7.2). A non-binding constraint could be loosened without changing the answer at all.

Sensitivity: what's an extra hour worth?

Raise machining from 24 to 25 hours and re-solve: the optimum rises by the shadow price of machining. In the explorer it is about £0.80 per hour. If an extra hour costs less than its shadow price, buy it. Changes to the objective coefficients can make the best corner jump to a neighbour: the plan is stable only within a range of prices.

Beyond two variables

Real problems have thousands of variables, but the theorem still holds: optima sit at vertices of a high-dimensional polytope. The simplex method walks from vertex to better neighbouring vertex; interior-point methods cut through the middle. If the variables must be whole numbers (integer programming) the corner can be fractional, and the problem becomes much harder.

Derivation: The corner-point theorem in two dimensions
  1. Maximise z = c₁x + c₂y subject to linear inequalities. Each inequality is a half-plane; their intersection is a convex polygon (the feasible region).

  2. The level sets z = k are parallel straight lines with normal vector (c₁, c₂). Increasing k slides the line in the direction (c₁, c₂).

  3. Suppose an optimum were at an interior point. A small step in direction (c₁, c₂) stays feasible and increases z, a contradiction. So the optimum is on the boundary.

  4. On an edge, z varies linearly along the edge, so it is largest at one of the edge's two endpoints (or constant, if the edge is parallel to the level lines).

  5. Therefore some vertex is optimal. Algorithm: find every vertex (intersect pairs of constraint lines, keep the feasible ones), evaluate z at each, take the largest.

  6. Example: 2x + y ≤ 24, x + 3y ≤ 30, x, y ≥ 0. Crossing: from the first y = 24 − 2x; substitute: x + 72 − 6x = 30, x = 8.4, y = 7.2. Corners (0, 0), (12, 0), (0, 10), (8.4, 7.2). With z = 3x + 5y: 0, 36, 50, 61.2. The optimum is £61.20 at (8.4, 7.2).

Common mix-ups

Open the Lite lesson: Linear programming: why the corners win

7.2 Searching a design landscape: grids, gradients and local minima

Rolling downhill finds a valley fast. But is it the deepest valley?

Grid search: thorough and expensive

Evaluate the cost on a regular grid and keep the best. It needs no derivatives, handles noisy or discontinuous costs, and with fine enough spacing can't miss a wide valley. But its cost is k^d evaluations, and its resolution is the grid spacing: the true optimum can sit between grid points. Use it for one to three parameters, or as a coarse first look.

Gradient descent: fast and local

Step against the slope: x ← x − η·f′(x). Near a minimum the slope shrinks, so steps shrink. Each step needs the gradient, which you can estimate with finite differences (two evaluations per parameter). It scales to many parameters, but it only ever goes downhill, so it settles in whichever valley it starts in.

The learning rate

η sets the step size. Too small and progress is painfully slow. Too large and the step jumps over the valley floor, bouncing or diverging. For f = a(x − b)², steps converge only if η < 1/a. In practice engineers try a few η values, or shrink η when the cost stops falling.

Guarding against local minima

A local minimum beats its neighbours but not the whole landscape. Defences: a coarse grid to find promising regions, then gradient descent to polish (a hybrid); several random restarts; or global methods (simulated annealing, genetic algorithms) that sometimes accept uphill moves. Always report the method and its limits: 'best found', not 'optimal'.

Common mix-ups

Open the Lite lesson: Searching a design landscape: grids, gradients and local minima

7.3 When exact answers are out of reach

A delivery van must visit 20 shops. Trying every route would take a fast computer about two years. How do real route planners answer in a second?

Tractable means polynomial

A problem is usually called tractable if some algorithm solves it in O(n^k) time for a fixed k. Sorting, shortest paths (Dijkstra) and linear systems are tractable. Problems whose best known algorithms take 2ⁿ or n! time become impossible to solve exactly beyond a few dozen items, whatever the hardware.

P, NP and NP-hard, informally

P: problems solvable in polynomial time. NP: problems where a proposed answer can be checked in polynomial time (is this route shorter than 500 km? add up its legs). NP-hard: at least as hard as every NP problem; a fast algorithm for one would give fast algorithms for all. Nobody has proved P ≠ NP, but no one has found a polynomial algorithm for an NP-hard problem either, so engineers plan as if none exists.

Heuristics and approximations

A heuristic (nearest neighbour, greedy packing, simulated annealing) is fast but has no promise about quality. An approximation algorithm comes with a proof: for travelling-salesperson maps that obey the triangle inequality, Christofides' algorithm is never worse than 1.5× optimal. Either way, measure the gap on cases small enough to solve exactly, as the explorer does.

Common mix-ups

Open the Lite lesson: When exact answers are out of reach

Worked examples

Linear programming: why the corners win: example 1

Maximise 4x + 3y subject to x + y ≤ 10, 2x + y ≤ 16, x, y ≥ 0.

Solution

Corners: (0, 0) → 0; (8, 0) → 32; (0, 10) → 30; crossing: subtract the equations, x = 6, y = 4 → 36. Optimum 36 at (6, 4). Both constraints bind.

Searching a design landscape: grids, gradients and local minima: example 1

f(x) = 2(x − 3)², x₀ = 7, η = 0.1. Take two steps.

Solution

f′(x) = 4(x − 3). Step 1: f′(7) = 16, x₁ = 7 − 1.6 = 5.4. Step 2: f′(5.4) = 9.6, x₂ = 5.4 − 0.96 = 4.44. The error shrinks by 1 − 2·2·0.1 = 0.6 each step.

When exact answers are out of reach: example 1

How many distinct round trips through 12 cities, ignoring direction?

Solution

(12 − 1)!/2 = 39,916,800/2 = 19,958,400. At a million tours a second that is 20 s; at 15 cities it is 43.6 billion tours, about half a day.

When exact answers are out of reach: example 2

A greedy route is 112 km and the exact best is 100 km. Report the heuristic's quality.

Solution

Gap = (112 − 100)/100 = 12%, ratio 1.12. One map is one data point: report the worst and average gap over many maps before trusting it.

Interactive figures, in words

Figure 7.2 from Linear programming: why the corners win

Read the corner table and find the best corner. Move your trial plan (the square) to a point inside the region and compare its profit. Then raise the profit per chassis until the best corner jumps, and add machining hours to see how much one extra hour is worth.

The explorer shows the feasible region for 2x + y ≤ M (machining) and x + 3y ≤ A (assembly) with x, y ≥ 0, as a shaded polygon. A table lists each corner and its profit c₁x + c₂y; the largest is marked best. With M = 24, A = 30, c₁ = 3 and c₂ = 5 the corners are (0, 0), (12, 0), (0, 10) and (8.4, 7.2), and the optimum is 61.20 at (8.4, 7.2). Adding one machining hour raises it to about 62.00.

Figure 7.3 from Searching a design landscape: grids, gradients and local minima

Gradient descent from x₀ = 1: where does it end? Move x₀ to 5. Now try η = 4 and watch it overshoot. Switch to grid search: what is the smallest k that finds the global valley near 7.4, and how many evaluations does it cost?

The explorer plots an illustrative cost against one design parameter x from 0 to 10, with a local valley near x = 2.3 (cost about 1.52), a ridge near 3.8, and the deepest valley near 7.4 (cost about 0.61). Gradient descent from x₀ = 1 ends in the shallow valley; from x₀ = 5 it reaches the deep one; with a learning rate above about 3 it overshoots. Grid search with k points evaluates the cost k times and finds the deep valley once the spacing is fine enough.

Figure 7.4 from When exact answers are out of reach

Start at 4 cities and add one at a time up to 9, watching 'tours tried'. On several random maps, compare the greedy nearest-neighbour route with the exact best. How far off is greedy at its worst?

The explorer draws 4 to 9 random cities with two routes: the exact best tour (found by trying all (n−1)!/2 tours) and the greedy nearest-neighbour tour. A table reports tours tried, both lengths and the percentage gap; at 20 cities brute force would need about 6×10¹⁶ tours.

The interactive versions are in the full chapter.

Laboratory

These run in a browser on the full site (they need a faster connection). Simulations are simplified educational models.

Practice

Each question links to its Lite lesson, where your answer is checked on our server and a wrong answer gets a hint. Answers are never sent to your device.

  1. Corners of a feasible region are (0, 0), (12, 0), (0, 10) and (8.4, 7.2). What is the maximum of 3x + 5y?
    Answer it in “Linear programming: why the corners win”
  2. At the optimum, the assembly constraint has 6 hours of slack. What happens to the optimum if you buy 4 more assembly hours?
    Answer it in “Linear programming: why the corners win”
  3. The LP optimum is 8.4 frames and 7.2 chassis, but you can only build whole items. What is true?
    Answer it in “Linear programming: why the corners win”
  4. Gradient descent's cost goes up and down and then grows each step. What is the most likely cause?
    Answer it in “Searching a design landscape: grids, gradients and local minima”
  5. Gradient descent from three random starts gives costs 1.52, 0.61 and 1.52. What should you report?
    Answer it in “Searching a design landscape: grids, gradients and local minima”
  6. Which statement captures membership of NP?
    Answer it in “When exact answers are out of reach”
  7. Your greedy scheduler beats random scheduling on every test. What should the report claim?
    Answer it in “When exact answers are out of reach”
  8. Which problem has a known polynomial-time algorithm?
    Answer it in “When exact answers are out of reach”

Engineering applications

Production planning

A workshop deciding how many of two products to make with limited machine hours and materials is a linear programme. Its binding constraints show which resource is worth buying more of.

Scheduling tests

Ordering dozens of tests on shared rigs is a combinatorial problem with no fast exact method. Greedy schedules improved by swaps are used, and reported as good rather than optimal.

Watch (optional)

Streaming video uses a lot of data. Everything you need is in the text.

Summary

Glossary

Efficiency
Efficiency is the fraction of input energy or power that comes out as useful output. The rest becomes heat, sound or other losses. Field Guide
Bill of materials
A bill of materials lists every part needed to build something, with quantity, exact part number or specification, supplier and cost. Field Guide

Project: Plan a production run

Invent a small production problem with two or three products, at least three resource limits and profits per unit. Solve it graphically or by checking corners, report the binding constraints and the value of one more unit of the scarcest resource, then find the best whole-number plan.

Deliverables

Write it up on paper or in your own notes. Lite never stores what you write.

References

← 6. Formulating optimisation problems8. Gradient methods and convexity →