Optimization and Linear Programming
A workshop can make two products that share the same limited machine-hours and material. What mix makes the most money? Optimization finds the best decision — not just a good guess.
What you'll learn
- Prescriptive analytics — finding the best decision, not just predicting an outcome
- Linear programming: objective function, constraints, and the feasible region
- Why the optimum is always at a corner of the feasible region
- How to solve a product-mix problem by evaluating corner points
- Why the highest-margin product is not always the right answer
Before you start
You run a small workshop. Product A earns $40 per unit. Product B earns $30 per unit. Every instinct says: make as many A’s as possible. By the end of this lesson you will see exactly why that instinct is wrong — and how a method called linear programming finds the true best mix in seconds.
Two kinds of analytics
The analytics world has four types. Two of them tell you what happened or what will happen. The third, prescriptive analytics — also called optimization — goes further: it tells you the best decision to make, not just what the outcome might be.
Optimization needs two ingredients:
- An objective — the number you want to maximize (profit, throughput) or minimize (cost, waste).
- Constraints — the real-world limits you must stay within (hours, materials, budget).
Without constraints the answer is trivial (“make infinite units”). Without an objective the answer is vague (“make more”). Together they define a real decision problem.
The product-mix problem
Here are the exact numbers for our workshop.
Decision variables (the quantities you control):
A= units of Product A to makeB= units of Product B to make
Objective function (maximize total profit): 40A + 30B
Constraints (the limits):
Labour: 2A + B <= 100 (A needs 2 hrs, B needs 1 hr; 100 hrs available)
Material: A + B <= 80 (each product uses 1 unit; 80 units available)
Non-neg: A >= 0, B >= 0
This is an example of linear programming (LP) — optimization where every constraint and the objective are linear, meaning they graph as straight lines (or flat planes). “Linear” is the key word: no squares, no products of variables, just additions and multiplications by constants.
The feasible region
Every point (A, B) that satisfies all four constraints at once belongs to the feasible region — the set of all mixes the workshop can legally produce. When you draw the two constraint lines on a graph, the feasible region is the area below both lines and above the axes.
For our problem the feasible region is a four-sided polygon (quadrilateral) with these corner points (also called vertices):
| Corner | A | B |
|---|---|---|
| Origin | 0 | 0 |
| Labour limit only | 50 | 0 |
| Both limits cross | 20 | 60 |
| Material limit only | 0 | 80 |
The crossing point deserves a close look. Where do 2A + B = 100 and A + B = 80 meet? Subtract the second from the first:
(2A + B) - (A + B) = 100 - 80
A = 20
Substitute back: 20 + B = 80, so B = 60. Confirmed: the two constraints cross at (20, 60).
The feasible region diagram
The shaded polygon is the feasible region. Every corner is labelled with its profit. The optimal corner (20, 60) at $2,600 is highlighted in green.
The corner-point theorem — why it works
Here is the most important theorem in LP, stated without jargon:
The optimal solution to any LP is always found at a corner (vertex) of the feasible region.
Why? Imagine walking in the direction of increasing profit across the feasible region. Profit increases in a fixed direction (toward more A and more B). You keep walking until the boundary stops you. The last point you can reach before leaving the feasible region is always a corner — never a point in the middle of an edge, never an interior point.
This matters enormously in practice. A real LP might have millions of feasible points. The theorem says you only need to check the corners — a finite, enumerable list.
Evaluating the corners
Corner (A, B) | Profit calculation | Profit |
|---|---|---|
| (0, 0) | 40(0) + 30(0) | $0 |
| (50, 0) | 40(50) + 30(0) | $2,000 |
| (0, 80) | 40(0) + 30(80) | $2,400 |
| (20, 60) | 40(20) + 30(60) = 800 + 1,800 | $2,600 |
The winner is (20, 60): make 20 units of A and 60 units of B for a profit of $2,600.
Notice that both constraints are binding at this corner — meaning both inequalities are satisfied with equality (2(20) + 60 = 100 exactly, and 20 + 60 = 80 exactly). A binding constraint is one that is tight; it is actually limiting you. A non-binding constraint has slack — you could do more but some other constraint stops you first.
What makes a constraint “binding”
A binding constraint is actively limiting your profit — remove or relax it and your optimal profit rises. In this problem, both constraints are binding at the optimum. If you could get just 10 more labour-hours (100 to 110), the feasible region would expand and you could earn more. Knowing which constraints bind tells you where to invest: buying extra capacity on a non-binding constraint wastes money; buying it on a binding one has direct payoff.
Quiz
Quick check
Next
A/B testing — deciding which change actually works, with statistical evidence rather than gut feel.
Practice this in an interview
All questionsCost scales with input plus output tokens; latency scales with output tokens and model size. The highest-leverage levers are: model routing (use a small model when the task is simple), prompt caching (reuse expensive prefix computation), output length control, and batching. Together these can cut spend 60–90% without quality regression.
LLMOps extends classical MLOps to handle foundation model scale, prompt-based configuration, non-deterministic outputs, and evaluation without a scalar ground truth. Key new concerns include prompt versioning, output quality evaluation via LLM judges or human review, hallucination monitoring, cost management, and RAG pipeline observability.
Optimize precision when a false positive is costly — spam filters, ad targeting, legal evidence — because you'd rather miss some positives than act on wrong ones. Optimize recall when a false negative is costly — cancer screening, fraud detection, safety systems — because missing a true positive can be catastrophic. The business cost of each error type should drive the choice, not the metric itself.
The default 0.5 threshold optimises for balanced accuracy but is rarely the right choice for business objectives. The correct threshold is found by translating the business cost of false positives and false negatives into a cost matrix, then sweeping the threshold on a held-out set to find the point that minimises expected cost or maximises expected profit. Operational constraints — such as review-team capacity — further bound the feasible region.