Skip to content
Tactiverge

Textbooks/Engineering Design and Optimization/Chapter 7Lite (plain text) version

7Linear programming and search

Version 1 · Technically checked (automated checks only) · 3 source lessons · 8 practice items

Text
All chapters and search
  1. 1. Problems and requirements
  2. 2. Decisions and trade-offs
  3. 3. Verification and reliability
  4. 4. Documentation, tolerances and design review
  5. 5. System architecture and budgets
  6. 6. Formulating optimisation problems
  7. 7. Linear programming and search
  8. 8. Gradient methods and convexity

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.

xy(0, 0): 0(6, 0): 18(4, 4): 20(0, 8): 16maximise 3x + 2yx + y ≤ 82x + y ≤ 12x, y ≥ 0best (4, 4)= 20The optimum of alinear objectivesits at a corner.
Figure 7.1. The optimum is at a corner. 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

This chapter is built from 3 School lessons. Each part below is the lesson's own explanation; open the lesson for its predict-and-discover activities.

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

  • The best plan uses a bit of everything, somewhere in the middle.
    ✓ For linear objectives and constraints, the best plan is at a corner of the feasible region.
  • Adding resources always improves the optimum.
    ✓ Only binding constraints have a positive shadow price; spare capacity is worth nothing at the margin.

Open the full 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

  • Gradient descent finds the best design.
    ✓ It finds a nearby stationary point, usually a local minimum. Restarts or global search are needed to be confident.
  • A finer grid is always worth it.
    ✓ Its cost grows as k^d; for more than a few parameters, a fine grid is unaffordable.

Open the full 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

  • NP means 'not polynomial'.
    ✓ It means 'nondeterministic polynomial': solutions are checkable in polynomial time. P is inside NP.
  • If a problem is NP-hard, engineers cannot solve it.
    ✓ They solve large instances well with heuristics, approximations and solvers, and small ones exactly.

Open the full 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

Figure 7.2 from Linear programming: why the corners winRead 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.
Can't use the interactive? Read a description instead

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.

Interactive figure (online). Description: 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 minimaGradient 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?
Can't use the interactive? Read a description instead

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.

Interactive figure (online). Description: 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 reachStart 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?
Can't use the interactive? Read a description instead

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.

Interactive figure (online). Description: 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.

Laboratory

Everything runs in your browser. No kit, nothing mains-powered. Simulations are simplified educational models.

  • Equation Lab exploration

    Equation Lab: Optimisation

    Compare a coarse grid search with gradient descent on a two-variable landscape and count the function evaluations each needs.

    Open Equation Lab: Optimisation →
  • Simulation OS experiment

    Simulation OS: Traffic-light junction timing

    Search over green times for two directions to minimise the worst queue, and report whether your best setting is a corner of the allowed range.

    Open Simulation OS: Traffic-light junction timing →

Guided practice

Answers are checked on the server; wrong answers get a hint and another try. Signed in, solved items also count towards the source lesson.

Practice 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?

Practice 2

At the optimum, the assembly constraint has 6 hours of slack. What happens to the optimum if you buy 4 more assembly hours?

Practice 3

The LP optimum is 8.4 frames and 7.2 chassis, but you can only build whole items. What is true?

Practice 4

Gradient descent's cost goes up and down and then grows each step. What is the most likely cause?

Practice 5

Gradient descent from three random starts gives costs 1.52, 0.61 and 1.52. What should you report?

Practice 6

Which statement captures membership of NP?

Practice 7

Your greedy scheduler beats random scheduling on every test. What should the report claim?

Practice 8

Which problem has a known polynomial-time algorithm?

  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?
  2. At the optimum, the assembly constraint has 6 hours of slack. What happens to the optimum if you buy 4 more assembly hours?
    • It rises
    • Nothing: assembly isn't the limiting resource
    • It falls
    • The problem becomes infeasible
  3. The LP optimum is 8.4 frames and 7.2 chassis, but you can only build whole items. What is true?
    • Round to (8, 7): that is guaranteed optimal
    • The best whole-number plan must be found separately; rounding may be sub-optimal or even infeasible
    • Fractional plans are always fine
    • The LP was wrong
  4. Gradient descent's cost goes up and down and then grows each step. What is the most likely cause?
    • The learning rate is too small
    • The learning rate is too large, so steps overshoot the minimum
    • There is no minimum
    • Gradient descent always does this
  5. Gradient descent from three random starts gives costs 1.52, 0.61 and 1.52. What should you report?
    • The average, 1.22
    • The best found, 0.61, and that two of three starts reached a worse local minimum
    • 1.52, because it occurred most often
    • That the method failed
  6. Which statement captures membership of NP?
    • It can be solved in polynomial time
    • A proposed solution can be checked in polynomial time
    • It can never be solved exactly
    • It needs a non-deterministic computer
  7. Your greedy scheduler beats random scheduling on every test. What should the report claim?
    • It is optimal
    • It is better than random on these tests; its gap to optimal is measured on small cases where the optimum can be computed
    • NP-hard problems cannot be evaluated
    • Nothing until P vs NP is solved
  8. Which problem has a known polynomial-time algorithm?
    • Shortest path between two nodes in a road graph with positive lengths
    • Shortest tour visiting every node once
    • Choosing a subset of parcels that exactly fills a van's weight limit
    • Colouring a map with 3 colours so neighbours differ

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 verified videos. Nothing loads from YouTube until you press play.

A worked graphical linear programme: shade the constraints, find the corners, test the objective at each.

Length: see YouTube · captions on YouTube · source

Nothing loads from YouTube until you press play.

A brisk tour of what P and NP mean, why checking an answer can be easy when finding it seems hard, and why it matters to real engineering.

Length: see YouTube · captions on YouTube · source

Nothing loads from YouTube until you press play.

  • Linear Programming (maximize the objective function given the constraints) (Math Problems Solved Craig Faulhaber)
  • P vs. NP and the Computational Complexity Zoo (hackerdashery)

Chapter summary

  • In a linear programme the optimum lies at a vertex of the feasible region.
  • Binding constraints at the optimum show where extra resources would pay off.
  • Integer answers may not be at the LP vertex; rounding needs checking against the constraints.
  • Grid search is simple but scales badly; gradient descent is efficient but can stop in local minima.
  • For intractable problems, use heuristics and state honestly that the result is not proven optimal.

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.
Bill of materials
A bill of materials lists every part needed to build something, with quantity, exact part number or specification, supplier and cost.

Definitions from the 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

  • The LP with units
  • The optimum and binding constraints
  • The best integer plan and how it differs

Keep your work in your Engineering Journal; it stays private unless you choose to share it.

References

  • George B. Dantzig (1963). Linear Programming and Extensions. Princeton University Press.
  • Stephen Boyd and Lieven Vandenberghe (2004). Convex Optimization. Cambridge University Press.
  • Panos Y. Papalambros and Douglass J. Wilde (2017). Principles of Optimal Design: Modeling and Computation, 3rd edition. Cambridge University Press.

Publication record

Version
1
Status
Technically checked (automated checks only)
Technical review
Automated checks only, last run 2026-11-29. No human, educator or mentor review is claimed.src/content/textbooks/textbooks.test.ts: schema, every lesson, diagram, practice item, video, Field Guide entry, lab and reference resolves; figure numbers recomputed; no practice answers in client payloads.
Written by
Compiled and written by the Tactiverge team with AI assistance, from Tactiverge School lessons that were themselves written with AI assistance.
Licence
All rights reserved by the founders unless a licence is approved.
Corrections
None recorded yet.Spotted a mistake? Use “Report a problem” on any chapter, or see the corrections page.