
Mathematical Modeling 6 - Convex Optimization

Imagine a snack factory with limited flour and sugar. It can make boxes of snack A or B, each with different ingredients and profit. How many boxes should it make today? Write down a plausible plan before learning the words “linear program.” The first job is to translate kilograms of supplies into inequalities and profit per box into an objective. If the numbers in your plan violate the pantry limits, even a large profit is irrelevant.
From that small factory, we will grow toward worker assignment, supply depots, and balancing return against risk. Each time, I will ask the same beginner’s questions: what can we choose, what cannot we violate, and what would a solution mean in the original situation? Convexity enters later because it tells us when a solver’s answer has a reliable global interpretation. It should feel like a property of the problem you formulated, not a magic adjective attached to an algorithm.
Optimization sounds intimidating because textbooks usually begin with a block of symbols. In practice, the idea is much friendlier: we have several choices, limited resources, and a definition of what “better” means. An optimization model is simply a careful way to put those three ingredients in the same room.
Let us begin as if we were talking in class. Imagine that you run a small snack workshop. You can make two products tomorrow morning, but you do not have unlimited flour or sugar. Product A earns more money per box, while Product B uses the ingredients in a different proportion. What should you produce?
Before reading any formula, pause for ten seconds. Would you make only the product with the larger profit? That is a reasonable first instinct, but it ignores the fact that a product can be profitable and still consume the scarce resource inefficiently. Optimization begins exactly where that intuition becomes uncertain.
By the end of this lesson, you should be able to do four things without copying a template:
- turn a verbal decision problem into variables, an objective, and constraints;
- recognize whether the result is an LP, MILP, QP, or SOCP;
- solve small models by reasoning and larger models with a solver;
- explain why a solution is good, which constraint is limiting it, and how the answer changes when the data change.
The difficult part is usually not pressing “Solve.” The difficult part is deciding what every symbol means and making sure every real-world rule appears exactly once in the mathematical model. We will therefore work problem-first: each technique begins with a concrete question, then we build and solve the model together.
A first classroom problem
The question
A workshop produces snack boxes A and B. One box of A uses 4 kg of flour and 1 kg of sugar and earns 60 yuan. One box of B uses 2 kg of flour and 2 kg of sugar and earns 40 yuan. Tomorrow the workshop has 80 kg of flour and 50 kg of sugar.

Think before calculating. What are we allowed to choose? What does the workshop want to maximize? Which sentences describe limits rather than preferences?
The quantities we control are the numbers of boxes. Let
Translate one sentence at a time
The profit from A is
Now translate the flour sentence. Every A consumes 4 kg and every B consumes 2 kg. The total cannot exceed 80 kg:
Sugar gives a second restriction:
Finally, negative production is meaningless, so
Notice the order in which we worked: meaning first, symbols second. If you begin by searching for an algorithm, it is surprisingly easy to optimize the wrong problem very efficiently.
Solve it without software
Because there are only two variables, draw the feasible region. The flour boundary is
Multiply the first equation by two and subtract the second. We obtain
For a linear program, an optimum occurs at a corner of the feasible polygon whenever an optimum exists. The other corners are
Read the answer like a modeler
The number 1400 is not the whole conclusion. At
There is also a modeling decision hiding in plain sight: can we produce fractional boxes? If the answer is no, then
A quick variation
Suppose A earns 80 rather than 60. Do not rerun software immediately. Compare the objective at the corners:
The opening allocation question tells us what must be chosen and what “better” means. If both the objective and the hard rules can be written as linear expressions, we get a linear program; let us build one from the story before naming a solver.
Let’s test the model against the factory floor
Before we leave the workshop, I want you to try an awkward but useful question: what exactly is a “box”? If one box can be prepared with any nonnegative real quantity of ingredients, our continuous model is a reasonable approximation. If it is a sealed retail package, boxes are indivisible. If the factory produces in batches of ten, the decision should perhaps be
Try a seemingly harmless production plan: 12 boxes of A and 18 of B. Flour consumption is
Now try 8 boxes of A and 20 of B. Flour usage is
The chart of feasible plans is a polygon only because we allowed continuous quantities and the inequalities are linear. If the plan must be integral, picture a grid of candidate points inside the polygon. The best continuous point may land between grid points; we then need to compare nearby legal points, not simply round each coordinate independently. Rounding up both coordinates may step outside the pantry limits, while rounding down can waste resources. In our particular numerical example, the intersection happens to sit on a legal grid point. This coincidence makes the hand calculation especially neat; it should not become a habit of ignoring integrality.
What if the owner asks for a minimum of five boxes of each snack because regular customers expect both? Add
Here is another trap: “A earns 60 yuan” may mean revenue, not profit. If raw materials cost money, transport is billed per box, or unsold snacks are returned, maximizing stated revenue is not the same as maximizing net profit. Ask whether 60 and 40 are already net contribution margins. If they are not, subtract variable costs from the objective. An optimization model can be solved exactly while answering the wrong business question, so the meaning of the coefficients deserves as much attention as the equations.
Finally, test the units. The term
From linear programs to conic constraints
A linear program has the standard form
The coefficients must be constants. Products such as
Why a line stays a line
Let us unpack the word “linear” rather than treating it as a badge. If the production of A increases by one box while B stays fixed, profit rises by 60 yuan, regardless of whether we started at zero A or ten A. Similarly, each extra A always consumes four more kilograms of flour. The marginal effects are constant. That is exactly the assumption encoded by a linear coefficient.
Real factories sometimes violate it. A bulk discount might reduce ingredient cost after the twentieth box; overtime may increase labor cost after a shift threshold; a setup operation may cost money whenever a recipe is produced at all. We can often represent thresholds with additional variables and constraints, but we should not pretend the original two-variable LP already contains them. Start simple, state the assumption, and add complexity only when it changes the decision. A beginner can practice this by asking, “If I produce one more box, does the effect really stay the same everywhere?” If not, the coefficient may need a different model.
The feasible region of an LP is an intersection of half-spaces. In two dimensions we can draw it. In higher dimensions we cannot draw every coordinate at once, but the geometry still tells us something: the feasible set is convex. If two plans each respect every linear resource limit, then every proportional mixture of those plans also respects the same limits, provided fractional mixtures are physically meaningful. To see why, take two flour-feasible plans
Why did we only check corners for the snack LP? Imagine sliding a straight line representing constant profit across the feasible polygon. We slide it toward higher profit until it touches the polygon for the last time. That last touch occurs at a vertex, unless the line lies along an edge, in which case every point on the touched edge shares the same optimum. Our variation with A earning 80 yuan produced exactly such an edge of equally good answers. The geometry also explains why changing profits can suddenly switch the preferred production mix: the objective line changes its slope and may touch a different corner.
This picture is powerful but has boundaries. A linear objective on an empty feasible set has no answer. If a direction lets profit grow without limit because a resource constraint is missing, the model is unbounded. If the model contains integer variables, the continuous polygon is only a relaxation. The first three solver statuses you should understand are therefore optimal, infeasible, and unbounded. Do not read “infeasible” as “the algorithm failed”; it may be telling you that the rules conflict. Do not read “unbounded” as “unlimited real profit”; it may reveal a missing limit in your formulation.
Take a tiny infeasible variant: the owner demands at least 30 boxes of A while flour remains at 80 kg. Thirty A alone require 120 kg flour. No arrangement of B can repair that. The solver should report infeasibility, and we can explain it in one sentence to the owner. Take a tiny unbounded variant: remove both resource limits but keep positive profit coefficients and nonnegative production. The mathematical answer is to make arbitrarily many boxes. Real production cannot do this, so the model must be missing capacity, time, or demand limits. This is why status messages can be diagnostic evidence about the story rather than merely about the software.
A resource is valuable only in context
At
The second equation says
There is an important qualification: the numbers 13.33 and 6.67 are local. As we add flour, the optimal mix changes; eventually one resource or one product may cease to be active, and the marginal value changes. A shadow price is a slope of the optimal-value curve near the current data, not a promise that a thousand extra kilograms will be equally valuable. This is why sensitivity intervals or fresh solves matter. You can explain the same point in ordinary language: the first extra flour kilogram may be useful because sugar still exists to turn it into snacks; after enough flour arrives, sugar becomes the only bottleneck.
What if the owner can buy additional sugar for five yuan/kg? Its local value is about 6.67 yuan/kg, so a very small purchase also looks worthwhile. But if the owner can buy either flour or sugar under a fixed cash budget, compare net value per yuan spent, consider integer batches, and test how far the local approximation remains valid. The dual values guide a conversation; they do not replace the new decision model. This is the bridge from finding an optimum to using an optimum.
For two products with profits
subject to
If boxes must be whole, the variables are integer and the problem becomes a mixed-integer linear program. Do not solve the continuous relaxation and round blindly: rounding can violate constraints or destroy optimality.
Assignment and logical decisions
Let
with
Binary variables also encode activation, ordering, coverage, and incompatibility. If alternatives
Quadratic programs
A quadratic program uses
with linear constraints. It is convex when
Portfolio selection is a canonical example:
Here
Conic structure
Second-order cone constraints have the form
They represent norm bounds, robust linear constraints, and many risk limits. Recognizing convex structure matters because a convex feasible problem has no misleading local optimum: solver certificates and dual information become meaningful.
Formulation workflow
Write the model in this order:
- indices and sets;
- known parameters and units;
- decision variables and domains;
- objective, with each term interpreted;
- constraints, grouped by real rule;
- solver and numerical tolerances;
- post-solve feasibility and sensitivity checks.
Scale coefficients when one part of the model is near
Interpreting the solution
Report active constraints, unused capacity, and marginal values—not only
SciPy’s official linprog interface uses exactly the inequality, equality, and bound form above and currently delegates to HiGHS methods (documentation ). After solving, independently recompute the objective, integrality, and every constraint from the returned decisions.
For the snack example, SciPy minimizes, so negate the profit coefficients:
1 | import numpy as np |
Read the answer in domain language: how many boxes of each product, expected profit, which resource is binding, and whether continuous quantities are physically allowed. If boxes must be integral, use a mixed-integer solver instead of this continuous model.
Worked problem: assigning students to projects
Linear programming becomes much more expressive when the decisions are yes-or-no choices. Here is a complete assignment problem, not merely the final formula.

The question
Three students—Ada, Ben, and Chen—must each receive one of three projects: Vision, Planning, and Control. Their estimated completion times in hours are
| Student | Vision | Planning | Control |
|---|---|---|---|
| Ada | 6 | 9 | 7 |
| Ben | 8 | 5 | 6 |
| Chen | 7 | 8 | 4 |
Every project must be assigned exactly once. Find the assignment with the smallest total time.
Before the solution: there are only six possible assignments, so we could enumerate them. Why build a model? Because the model will still work when there are 300 students, eligibility rules, workloads, and team constraints.
Choose a representation
Let
The total time is the sum of time multiplied by the corresponding selection indicator:
Each student gets exactly one project,
and each project is used exactly once,
Finally,
Solve and explain
Choosing Ada–Vision, Ben–Planning, and Chen–Control gives
The useful answer is not “the solver returned 15.” It is: Ada should take Vision, Ben Planning, and Chen Control; every student and every project appears once; and the predicted workload is 15 hours. If the time estimates are uncertain, perturb them and see whether the same assignment remains optimal. A plan that changes after a one-hour estimation error is much less trustworthy than one that survives all plausible estimates.
Add real rules
Suppose Ada is not certified for Control. Set
Read that inequality aloud: at most one of the two named events can occur. This habit catches logical mistakes faster than staring at indices.
Now suppose a student can take two small projects but at most 12 hours of predicted work. Replace “one project per student” with
The same binary language supports scheduling, facility opening, feature selection, set cover, and routing. The algorithm may change, but the modeling habit stays the same.
Why the assignment is not three separate choices
Let’s slow down at the point that usually trips up a first-time reader. Ada’s fastest project is Vision at six hours. Ben’s fastest is Planning at five hours. Chen’s fastest is Control at four hours. In our invented table those individual favorites happen to fit together, so the greedy choice gives the optimum. But that happy outcome is not a theorem. If Ada and Ben both favor Vision, only one of them may receive it. The cost of giving Vision to Ada includes an opportunity cost: what does Ben do instead? This coupling is why the constraint “each project exactly once” is not decorative.
To make that visible, change only Ben’s Vision estimate from eight hours to three hours. His preferred project is now Vision, and Ada still prefers Vision at six. If we give Vision to Ada, Planning to Ben, and Control to Chen, the total remains fifteen hours. If we give Vision to Ben, the best legal way to place Ada and Chen may be Ada–Planning at nine and Chen–Control at four, totaling sixteen hours, or Ada–Control at seven and Chen–Planning at eight, totaling eighteen hours. The individually fastest-looking Ben–Vision option is not the globally fastest complete assignment. We should compare whole plans, not rank each row in isolation.
Here is a small exercise worth doing with pencil. List the six permutations explicitly:
What if one task takes two people rather than one? The right model depends on what “takes two” means. If two workers independently contribute to the same task, change that task’s coverage equation to
Now return to the certification and shared-equipment constraints. Ada not certified for Control deletes two of the six permutations. The incompatibility rule
This example suggests a way to test any binary constraint. Construct a plan that should be legal and a plan that should be illegal. Substitute their zero-one values into the inequality. If the first is rejected or the second is accepted, the encoding is wrong. For “if A then B,” write all four possibilities: no A/no B, no A/yes B, yes A/no B, yes A/yes B. The inequality
What if completion times are only guesses?
Suppose Ada’s Vision estimate might be anywhere from six to ten hours depending on how much image-labeling work arrives. Our 15-hour plan could then take as long as 19 hours. The alternative Ada–Control, Ben–Planning, Chen–Vision currently takes 19 hours. Under some plausible cost changes it may become preferable. We should not report “Ada must take Vision” as a universal truth. We should report the assumptions and ask how stable the assignment is across scenarios.
A simple sensitivity experiment changes one table entry at a time. Increase Ada–Vision from six to seven, eight, nine, and ten, re-solve, and mark the first value at which the preferred assignment changes. Then test simultaneous changes, because real delays are often correlated: a complicated project may delay several students. You can show a small heat map of assignments across scenarios rather than a single hard-to-read table of solver statuses. The lesson is not that uncertainty forces a complicated algorithm. It is that a result computed from estimates should be spoken about as an estimate.
There is one more subtle point about the assignment LP. If every student receives exactly one project and every project exactly one student, the linear relaxation with
The snack decision used continuous quantities, and this assignment uses discrete yes-or-no choices. Both are ways to coordinate limited resources. The next case adds geography: there are several recipients, two suppliers, and route distances. First the supplier positions are fixed, so the optimization remains linear. Then we let the suppliers move and watch why the mathematical structure changes.
Worked problem: locating supply depots
This example from the course is especially useful because it shows how a small change in the question can change the entire mathematical class of the problem.

The fixed-depot question
There are six construction sites with coordinates and demands:
| Site | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|
| 1.25 | 8.75 | 0.50 | 5.75 | 3.00 | 7.25 | |
| 1.25 | 0.75 | 4.75 | 5.00 | 6.50 | 7.25 | |
| Demand | 3 | 5 | 4 | 7 | 6 | 11 |
Two existing depots are at
Take a moment to identify what is fixed. The site coordinates, depot coordinates, site demands, and depot capacities are data. The shipment quantities are decisions. Therefore let
is a constant because
subject to demand balance
and depot capacity
This is a transportation LP. Total demand is
Read the map before solving
Let’s walk around the map as if we were arranging deliveries on a whiteboard. Six sites need a total of 36 tons each day. Two depots together can provide 40 tons. That leaves four tons of aggregate spare capacity, but the spare capacity is not one big anonymous pool: each individual depot has only 20 tons. If we accidentally write just
The coordinates are measured in some unit of distance. If they are kilometers, a shipment of three tons over a five-kilometer route contributes fifteen ton-kilometers. If the coordinates are map-grid units rather than kilometers, do not call the objective literal ton-kilometers until you know the scale. The model is still valid as a comparative distance-weighted cost if all routes use the same grid. This is one of those small questions that makes the final explanation honest.
Before opening any software, compute a few distances to see whether the numbers make sense. For site 1 at
The exact Euclidean formula assumes trucks travel in straight lines. Real road travel may be longer, may depend on traffic, and may have one-way restrictions. If we have a road network and travel-time data, replace each straight-line coefficient
Why the nearest-depot rule can fail
A tempting shortcut is to send every site’s demand to the nearest depot. Try it. If too many sites choose the same depot, its 20-ton capacity may be exceeded. A locally cheapest choice for each site need not be globally feasible. The LP coordinates all shipments at once and can split a site’s demand if that lowers cost or restores feasibility.
Let’s do the shortcut completely rather than merely warning against it. With the stated coordinates, A is closer to sites 1, 2, and 4, whose demands are
Which ton should move from B’s nearest-depot group to A? Compute the additional distance per ton for each candidate. For site 3, A is about
The all-nearest plan’s distance-weighted sum is about
What if split deliveries are prohibited? Then the repaired plan, which divides site 6’s shipment between depots, is illegal. We need a binary assignment variable saying which depot serves a site, link flow to that assignment, and re-solve a mixed-integer model. Site 6 has eleven tons of demand, so moving all of its deliveries to A would load A with 26 tons and violate capacity. Moving site 3’s four tons to A would give A 19 and B 17, but it adds about
The LP also assumes all demand must be met exactly. If deliveries may be delayed, introduce unmet-demand variables with a justified penalty. If surplus deliveries can be stored at a site, change the equality to an inventory balance over time rather than silently allowing overdelivery. If capacity resets daily, the model applies separately each day; if unused stock carries over, the state of the depot must be linked across dates. These are not details for a solver manual. They are the questions that make the result operational.
After solving, draw only the routes with positive flow and label their tonnage. Then independently check three things: each site receives exactly its demand, neither depot ships more than 20 tons, and the displayed objective equals the sum of distance times flow. This small audit is more persuasive than a screenshot of solver output.
Now allow the depots to move
Suppose the question changes: where should the two depots be located? The coordinates
The product
One practical baseline alternates two steps:
- hold depot locations fixed and solve the transportation LP;
- hold allocations fixed and update each depot location using its assigned weighted points.
The objective cannot increase if each step is solved correctly, but the procedure can settle at a local solution. Use several starting locations, compare with a simple grid search for a small instance, and report how sensitive the final configuration is to initialization.
Understand what changed mathematically
For a fixed depot at
We can make this distinction tangible with two simpler questions. If every site is permanently assigned to A and the delivered quantities are fixed, choosing A’s coordinates to minimize the weighted sum of distances is a geometric-median-type problem; the objective is convex in A’s coordinates. If A and B have fixed coordinates, choosing shipment flows is the transportation LP we just solved. When both assignments/flows and coordinates vary together, the separate nice structures do not automatically combine into one convex problem. This is why alternation is reasonable as a heuristic: it temporarily restores one easy subproblem at a time. It is also why one alternating run is not a global-optimality certificate.
Suppose there are two plausible initial location pairs: near the two old depots, and near clusters of high-demand sites. Solve the alternating method from both. If the final objectives differ, we have direct evidence of initialization sensitivity. If they match, that is encouraging but not a proof of a unique global optimum; perhaps both starts fell into the same basin. For six sites we might perform a coarse grid search, solve the allocation LP at each grid point, then refine promising locations. For a larger instance we might use multistart, specialized location algorithms, or a mixed-integer discrete-candidate formulation. The choice depends on the required guarantee, the size of the candidate region, and the time available.
The 20-ton stocks can also change when depots move. Are we relocating warehouses and their existing inventory, building new facilities, or deciding tomorrow’s loading points? If a new depot must be built, add construction cost and perhaps zoning restrictions. If stock at old depots remains physically there, a solution that simply moves the coordinate labels would be nonsense. The course exercise asks us to minimize transport work, but a practical recommendation should distinguish transport savings from total project economics. A model can be perfectly solved and still omit the cost that decides whether relocation is worthwhile.
We now have three related optimization languages: quantity choice at a factory, yes-or-no assignment of people, and distance-weighted flows on a map. Their common thread is that the objective must be evaluated only for plans respecting all constraints. In the next case, the objective itself becomes curved because spreading an investment across assets changes risk in a way that depends on how the assets move together.
What to report
Coordinates alone are not a decision story. Report the original and optimized ton-kilometers, percentage saving, utilization of each depot, routes that change, and whether a small demand perturbation changes the recommended sites. If building a new depot costs money, add that cost before declaring relocation worthwhile.
Worked problem: balancing return and risk
Quadratic programming is easiest to understand through a trade-off that linear terms cannot express naturally.
The question
An investor allocates proportions
First, let’s say plainly what is being chosen. A weight of
Risk is modeled by portfolio variance
Build variance from a two-asset toy example
Before accepting
The corresponding standard deviation is
Does an 8.66% standard deviation mean the portfolio will lose no more than 8.66% in a year? No. Standard deviation summarizes a distribution; it is not a hard loss ceiling, and the quality of the estimate depends on the data and assumptions. A course solution should keep that statistical interpretation separate from the optimization guarantee. Convexity can tell us that we found the minimum of the specified estimated-variance objective under the specified constraints. It cannot tell us that the future behaves like the past.
Now think about the target-return rule
The no-short-selling rule also affects geometry. Without
Think first: why not minimize the average of the three individual variances? Because covariance matters. Two volatile assets can partially cancel one another if they move differently, while two apparently safe assets can reinforce the same risk.
Convexity is a promise
A covariance matrix is positive semidefinite in exact mathematics, so the variance objective is convex. Geometrically, its level sets are ellipses rather than a landscape full of unrelated valleys. If the constraints are also convex, every local optimum is global. This does not mean every numerical answer is automatically meaningful: estimated covariance can be noisy, the target return can be infeasible, and tiny eigenvalues can make the solution unstable.
Check that
The reason a covariance matrix should be positive semidefinite is almost elementary. For any portfolio weight vector
Portfolio variance is a quadratic objective. Its gradient changes with
Interpret the result
Suppose the target-return constraint is active. Its dual value measures the local increase in minimum variance caused by demanding slightly more expected return. If the dual value is large, the investor is near a costly part of the frontier. If a weight is zero, its reduced-cost or KKT condition explains why that asset does not enter the current optimum.
Finally, validate out of sample. A portfolio optimized on the same period used to estimate
Imagine reporting three weights to a classmate and saying, “The model selected these because they minimize estimated variance while meeting a ten-percent target return.” Your classmate asks, “What if the estimated return of asset 2 was overoptimistic?” That is the right challenge. Re-estimate returns from a different period, perturb the most uncertain mean, or optimize under several plausible scenarios. If the chosen weights jump from nearly zero to nearly one under a tiny perturbation, report the instability. A mathematically global optimum can be practically fragile. That distinction between optimization accuracy and input uncertainty will lead naturally to our next lesson about multi-objective and robust decisions.
Where a cone enters the story
The course also introduces second-order cone programs. A beginner can understand the core constraint without learning conic geometry all at once. Suppose a robot’s estimated position error is a two-component vector
Picture a circle of allowed error vectors in two dimensions. The circular boundary is curved, but the feasible set inside it is convex: average any two allowed error vectors and their average is still allowed. This is very different from requiring the error to be at least
One common robust-optimization interpretation is this: a constraint must hold for every coefficient perturbation inside a Euclidean uncertainty ball. Instead of enumerating infinitely many perturbations, the worst-case linear effect may be written as a norm of a decision-dependent vector. That reformulation can give a cone inequality. But do not label every vague claim about uncertainty “SOCP.” State the uncertainty set, derive or justify the worst-case bound, and check whether the resulting right-hand side is nonnegative. Our purpose is not to collect solver acronyms; it is to give the physical uncertainty a valid mathematical shape.
Assignment, depot location, and return–risk balance look like different problems. The unifying question is whether a local best point can also be a global best under the declared feasible set. That is why we now examine convexity, not as vocabulary but as a guarantee about the search.
Convexity clinic: how to recognize the safe structure

When we call a problem convex, we are making two statements:
- the feasible set contains the whole line segment between any two feasible points;
- the objective lies below the chord connecting any two points on its graph.
For a differentiable function, the first-order condition
means that every tangent plane is a global under-estimator. For twice-differentiable
Here is a useful classroom test. Consider each expression and decide before reading the answer:
— a half-space, hence convex. — a disk, hence convex. — the outside of a disk, not convex. with — despite the product, this particular feasible set is convex: it is the epigraph , and is convex on . Do not classify a set from syntax alone. — a second-order cone constraint when the right side is nonnegative.
The direction of an inequality matters. A convex function bounded above defines a convex sublevel set; the same function bounded below generally does not.
Test the guarantee rather than memorizing the label
We should be precise about the two ingredients of a convex minimization problem. A convex objective is not enough if the permitted decisions form a disconnected set. A convex feasible region is not enough if the objective has two separated valleys. Both properties work together to make a local optimum global. In our snack LP, linear inequalities make a convex polygon and linear profit is both convex and concave; maximizing linear profit over that polygon is equivalent to minimizing its negative, also linear. In the assignment problem, the zero-one decisions break the continuous line-segment property: the average of two legal binary assignments is generally fractional and not a legal assignment. In the portfolio QP, both the variance objective and the simple allocation rules have the right convex shape, provided the covariance estimate is positive semidefinite.
Take the simplest objective
Now look back at the feasible-set test
When a rule contains a norm, test the whole rule.
From optimality conditions to explanation
For a constrained convex problem, the Karush–Kuhn–Tucker conditions connect the numerical optimum to a human explanation. Introduce one multiplier for each constraint. At the optimum we look for:
- primal feasibility — the decisions satisfy the original rules;
- dual feasibility — inequality multipliers have the correct sign;
- stationarity — objective and active-constraint gradients balance;
- complementary slackness — an inactive inequality has zero multiplier.
In the snack problem, both ingredient constraints are active. Their multipliers can be interpreted as marginal values of flour and sugar. If sugar had 10 kg left unused, complementary slackness would force its shadow price to zero locally: one more kilogram of an already abundant resource cannot improve profit. For the stated data, the dual values are approximately 13.33 yuan per extra kilogram of flour and 6.67 yuan per extra kilogram of sugar, within the range over which the same production basis remains optimal. Flour, not sugar, has the higher local marginal value here.
This language helps us explain a solver result without pretending the solver is an oracle. “The plan uses all available flour and sugar; the marginal values show sugar is currently more valuable; product B remains in the mix because it converts flour into profit more efficiently” is a modeling conclusion. “Status: optimal” is only a software message.
From linear programs to networks
Optimization becomes easier when every symbol answers a physical question. Consider shipping a product from factories
Write balance equations
At warehouse
Factory capacity gives
This is a minimum-cost flow structure. Recognizing structure matters because specialized algorithms are fast and the resulting solution has an interpretable network.
A small warehouse story with actual quantities
Imagine a factory that can ship at most twelve crates tomorrow. There are two warehouses, East and West, each able to handle eight crates. Two customers need five and seven crates respectively. The total customer demand is twelve, exactly equal to the factory’s capacity, so every crate produced must reach a customer. Suppose the factory-to-East shipping cost is 2 yuan per crate and factory-to-West cost is 1 yuan per crate. From East to customer 1 the cost is 1, and to customer 2 it is 5. From West to customer 1 the cost is 4, and to customer 2 it is 1. We can see the route tendencies before writing code: customer 1 is cheaper through East, and customer 2 through West.
Let
What does a natural plan look like? Send five crates through East to customer 1 and seven through West to customer 2. East receives five, West receives seven, so both stay below eight. The factory sends twelve. The total cost is
Now change West’s handling capacity from eight to six. The original seven-crate delivery through West violates capacity. At least one customer-2 crate must go through East. The repaired plan sends five customer-1 crates and one customer-2 crate via East, and six customer-2 crates via West. East handles six, West six; customer demand and factory capacity still balance. Its cost is
This exercise also explains why we separate flow conservation from capacity. The equation
There is a useful third check: sum the two customer balances to get twelve required crates, and sum the two warehouse balances to get twelve outgoing crates. The factory balance should then show twelve incoming crates, too. If those totals disagree, inspect an omitted route, a duplicated customer, or a mistaken inequality sign before calling the result optimal. Conservation at each node is stronger than a single total-balance check, but the total is a fast way to locate a problem. In a large network, both local and aggregate audits are worth keeping.
If crates are indivisible, would the continuous LP solution still make sense? In this particular integer-data network flow problem, the classical flow structure has integral optimal extreme points under standard conditions. But if we add a fixed cost for opening East, a minimum shipment size, or a yes-or-no routing rule, the continuous relaxation can propose fractional openings or other impossible behavior. Structure is a tool to exploit, not permission to forget the real decision domain. Test what the factory actually permits and verify that every returned shipment is a whole crate when that is required.
Add discrete decisions carefully
If a warehouse must be either open or closed, introduce
Choose
Logical statements can often be encoded similarly. “Choose at most one of A and B” becomes
Learn the major graph templates
Many competition problems reduce to a few network patterns:
- shortest path: minimum additive cost from a source to a destination;
- maximum flow: greatest feasible flow under edge capacities;
- minimum spanning tree: connect all nodes with minimum total edge weight;
- matching/assignment: pair two sets while respecting exclusivity;
- facility location: choose nodes to open and assign demand to them;
- vehicle routing: construct capacity- and time-constrained tours.
Do not use Dijkstra’s algorithm when edges can have negative costs; do not use a spanning tree when traffic must travel from a source to destinations; do not confuse straight-line distance with travel time on a road network.
Use dual information
Suppose the dual value of factory capacity is
Diagnose infeasibility
When no solution exists, do not immediately remove constraints. Check units, signs, index ranges, duplicated demand, and lower bounds. Introduce labeled nonnegative slack variables temporarily and penalize them heavily. The locations of unavoidable slack reveal which business rules conflict. Then decide with the domain owner which rule is wrong or negotiable.
Return to the little warehouse instance and imagine the factory can make only ten crates while the customers still require five plus seven. The equality demand rules demand twelve crates. The factory can supply ten. No solver can turn ten into twelve. A useful diagnostic message would tell us that two crates of demand cannot be served under the current rules. We might introduce shortage variables
The same diagnosis works for snack production. A minimum production contract can exceed ingredient supply. It works for assignments: three projects may require four certified workers. It works for portfolio targets: an impossible expected return can be demanded without leverage. Instead of saying “optimization failed,” identify the smallest set of conflicting real rules. This is a better conversation with the decision maker and a better explanation in the report.
What a solver result must survive
Once software returns a vector of numbers, read it back as a proposed physical plan. In the snack problem, calculate flour and sugar usage from the returned box counts. In the assignment problem, list each student’s selected project and check every project appears exactly once. In the depot problem, add shipments received by each site and shipments sent from each warehouse; compare with demands and stock. In the portfolio problem, add weights, recompute return and variance, and inspect whether the target is met. These independent calculations do not need to solve the optimization again. They verify that the answer we report is the answer the equations actually allow.
Numerical tolerances need interpretation too. A solver might report a depot shipment sum of
Finally, compare with a simple feasible plan. For snacks, making only twenty A boxes earns 1200 yuan and respects both resources; the optimized 1400 has a clear 200-yuan advantage under the model. For depots, the nearest-choice map is not a feasible baseline because B exceeds stock; the one-ton repaired route is. For a portfolio, equal weights may be an informative baseline if it meets the target and trading rules. The comparison must obey the same constraints and be evaluated using the same data. Otherwise the extra precision of a solver is covering an unfair contest.
This lesson’s methods differ, but our way of reading answers has stayed continuous. We began with a factory owner who needed a feasible production plan, then met discrete assignments, geography, and correlated risk. At each step the best plan depended on a declared objective and allowed decisions. Next we will see why a single objective may not capture what all stakeholders want, and why uncertain resource and cost numbers can make a nominal optimum too brittle to implement.
Practice
Build a three-factory, two-warehouse, four-customer instance. Solve the continuous flow model, then add warehouse opening decisions. Verify every balance independently from the solver, visualize positive-flow edges, and explain the change using fixed costs and capacity shadow prices. Finally perturb demand by
The worked cases introduced three kinds of decision. The slide examples now let us compare their formulations side by side and check which constraints, units, and interpretations transfer from one case to another.
Course examples in full
Snack production
A factory makes A and B. A uses 4 kg flour and 1 kg sugar and earns 60 yuan; B uses 2 kg flour and 2 kg sugar and earns 40 yuan. Daily supplies are 80 kg flour and 50 kg sugar:
The continuous optimum is the intersection
Assignment
For task
The first constraint assigns every task; the second prevents double booking. Forbidden pairings are fixed to zero. Capacity greater than one changes the right side. Naming an algorithm is not a formulation until these rules are explicit.
Supply and facility location
The lecture gives six construction sites:
| Site | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|
| 1.25 | 8.75 | 0.50 | 5.75 | 3.00 | 7.25 | |
| 1.25 | 0.75 | 4.75 | 5.00 | 6.50 | 7.25 | |
| 3 | 5 | 4 | 7 | 6 | 11 |
Existing depots
Relocating the depots makes coordinates decision variables, so distance and allocation become coupled and nonlinear. An alternating location-allocation heuristic supplies a baseline; multistart or global search tests local sensitivity. Report saved ton-kilometers, not merely new coordinates.
Quadratic and conic structure
Portfolio variance, least squares, and smoothing produce
If
The factory, assignment, depot, and portfolio examples all produced a best feasible plan under stated preferences and data. The next lesson asks what changes when several stakeholders value different outcomes or when the data are uncertain.
- Title: Mathematical Modeling 6 - Convex Optimization
- Author: Gavin0576
- Created at : 2026-09-14 20:00:11
- Updated at : 2026-09-15 07:06:54
- Link: https://jiangpf2022.github.io/blog/2026/09/14/Mathematical-Modeling-06-Convex-Optimization/
- License: This work is licensed under CC BY-NC-SA 4.0.