Least-Cost Feed Formulation Explained: How the Math Works and How to Run It Without a Spreadsheet
Least-cost feed formulation finds the cheapest mix of ingredients that still meets every nutrient target. Here is how the linear programme works, what shadow prices and entry prices tell you, why a spec can be infeasible, and how to run it inside your ERP instead of a spreadsheet.

Least-cost feed formulation is the method of finding the cheapest combination of available ingredients that still meets every nutrient requirement of the animal you are feeding. It is a linear programming problem: minimise cost subject to a set of nutrient and ingredient constraints, and the solver returns the exact percentage of each ingredient to include.
Every feed mill does some version of this, whether in a nutritionist's head, a spreadsheet, a standalone formulation package, or inside the ERP that already holds the ingredient prices. This guide walks through the mathematics in plain terms, works a small example by hand, explains the two numbers most people ignore (shadow prices and entry prices), and compares the three ways of running it day to day.
The problem in one sentence
Given a list of candidate ingredients, each with a price per kilogram and a known nutrient profile, choose the share of each ingredient in 100 kg of finished feed so that the total cost is as low as possible and every nutrient lands inside its allowed range.
Written out, the pieces are:
- Decision variables — the percentage of each ingredient in the mix (xcorn, xSBM, and so on).
- Objective — minimise the sum of price × percentage across all ingredients. Because the percentages add to 100, the objective is simply the cost of 100 kg of feed.
- Mass balance — all percentages must add up to exactly 100.
- Nutrient constraints — for each nutrient, the weighted sum of ingredient values must be at least the minimum and at most the maximum in the specification.
- Ratio constraints — some targets are ratios, such as methionine plus cystine to lysine of at least 0.74, or calcium to available phosphorus between 1.8 and 2.2.
- Ingredient limits — practical caps such as "no more than 8% wheat bran" or "exactly 0.5% premix", which encode what the LP cannot know: palatability, pellet quality, mycotoxin risk, bin availability.
All of these are linear in the decision variables, which is exactly why linear programming solves the problem quickly and exactly. A mix with 40 candidate ingredients and 30 nutrient constraints solves in milliseconds.
A worked example with four ingredients
Numbers below are illustrative, not a recommendation. Suppose a simple grower feed must reach at least 18% crude protein (CP), at least 2,900 kcal/kg metabolisable energy (ME) and between 0.9% and 1.1% calcium (Ca). Four ingredients are available:
| Ingredient | Price (USD/kg) | CP % | ME kcal/kg | Ca % |
|---|---|---|---|---|
| Corn | 0.26 | 8.5 | 3,350 | 0.02 |
| Soybean meal (48%) | 0.52 | 48.0 | 2,450 | 0.30 |
| Wheat bran | 0.18 | 15.5 | 1,900 | 0.12 |
| Limestone | 0.05 | 0.0 | 0 | 38.0 |
The LP reads:
minimise 0.26·corn + 0.52·sbm + 0.18·bran + 0.05·lime
subject to
corn + sbm + bran + lime = 100
8.5·corn + 48·sbm + 15.5·bran ≥ 1,800 (CP ≥ 18%)
3350·corn + 2450·sbm + 1900·bran ≥ 290,000 (ME ≥ 2,900)
0.02·corn + 0.30·sbm + 0.12·bran + 38·lime ≥ 90 (Ca ≥ 0.9%)
0.02·corn + 0.30·sbm + 0.12·bran + 38·lime ≤ 110 (Ca ≤ 1.1%)
all variables ≥ 0
Notice the trick: a nutrient constraint "level ≥ 18%" becomes "weighted sum ≥ 100 × 18" because the variables are percentages. That keeps every row linear.
Run through a solver, a feasible least-cost answer lands around corn 66%, soybean meal 24%, wheat bran 8%, limestone 2%, costing roughly USD 0.32 per kg. Protein sits right on 18%, energy clears the minimum with room to spare, and calcium sits inside its band. Change the soybean price by five cents and the mix shifts — that sensitivity is the whole point.
Binding limits and shadow prices
In the example above, crude protein is binding: the optimum sits exactly on 18%, and the solver would use less soybean meal if it were allowed to. Energy is not binding; there is slack.
Every binding constraint has a shadow price (the dual value in LP terms). It answers a precise question: if I relaxed this limit by one unit, how much would the cost of a kilogram of feed change? If the CP shadow price is USD 0.012 per percentage point, then dropping the protein minimum from 18% to 17% would save about 1.2 cents per kg — roughly USD 1,200 on a 100-tonne run.
Shadow prices turn a formulation screen into a negotiation tool between the nutritionist and the buyer:
- A high shadow price on an amino acid says "this is where the money goes" — maybe a synthetic amino acid should be added as a candidate.
- A high shadow price on an ingredient cap ("max 8% bran") says the cap itself is expensive; is it still justified?
- A zero shadow price means the constraint costs nothing today and can be ignored in the next price discussion.
Entry prices: what an unused ingredient would have to cost
Ingredients that end up at 0% are not useless; they are simply too expensive at today's price. The solver can report, for each unused ingredient, the entry price — the price per kg below which it would start entering the mix. If rapeseed meal has an entry price of USD 0.31 and a supplier is quoting USD 0.33, you now know the exact discount to ask for. Buyers who see entry prices stop guessing and start negotiating.
When the spec is infeasible
Sometimes the solver reports "infeasible": no combination of the candidates can satisfy every constraint. Common causes are:
- A nutrient minimum that no candidate can reach without breaking another nutrient's maximum (very high protein with a tight fibre cap and no protein concentrate on the list).
- Ingredient caps that leave too little mass — fixed inclusions adding to more than 100%, or every energy source capped low.
- A ratio constraint that conflicts with absolute limits.
- Missing nutrient values: an ingredient with no value for a nutrient counts as zero, so the solver cannot use it to meet that target.
A good formulation tool does not stop at "infeasible". It re-solves with every limit allowed to break at a high penalty and then reports which limits were in conflict and by how much — for example, "Lysine min 1.10% is reachable only to 0.98% with the current candidates". That tells you whether to add an ingredient, relax a target, or fix a data gap.
Spreadsheet vs standalone tool vs ERP-integrated formulation
| Capability | Spreadsheet | Standalone formulation tool | Formulation inside the ERP |
|---|---|---|---|
| Finds the true least-cost mix | Only with Solver add-in, fragile | Yes | Yes |
| Shadow prices and entry prices | Manual re-solving | Yes | Yes |
| Ingredient prices | Typed by hand | Imported or typed | Latest purchase cost, automatically |
| Stock on hand and open purchase orders | No | Usually no | Yes — the same inventory |
| Result becomes a production recipe | Copy and paste | Export, then re-key in ERP | Saved as a draft recipe version |
| Recipe approval and version history | No | Partial | Yes, same approval as every BOM |
| Batch costing and accounting | No | No | Posted to the ledger per batch |
| Lot traceability of the batch produced | No | No | Yes |
Standalone packages solve the mathematics well; their weakness is everything around it. Prices are re-keyed, results are re-keyed, and the formula that was optimised on Monday is not the one the mixer ran on Thursday. Running the optimiser inside the system that already holds purchases, stock, recipes and work orders closes that loop. ERES, for example, prices candidates from the latest purchase cost per kg, solves with the open-source HiGHS solver, and writes the accepted mix into a draft recipe version that still goes through normal recipe approval — so nothing on the production floor changes until a nutritionist signs it off.
A practical workflow
- Build the nutrient library once: the handful of nutrients you formulate on daily (CP, ME, Ca, available P, Na, lysine, methionine, Met+Cys, threonine) switched on; the rest available but off.
- Load ingredient values from your lab or a typical-values table, and paste updates from a spreadsheet when a new lot is analysed.
- Write specifications per species and stage — broiler starter, grower, finisher; layer phase 1 and 2 — with min, max and ratios.
- Set ingredient limits that encode practical knowledge the LP cannot know.
- Solve, read the binding limits and entry prices, and adjust. Most of the value is in the second and third solve, not the first.
- Accept into a draft recipe, approve, and let the work order consume real lots at real cost.
Done this way, formulation stops being a monthly spreadsheet exercise and becomes a response to every price change. When soybean meal moves, the buyer and the nutritionist see the same number within minutes.
Frequently asked questions
Is least-cost formulation the same as linear programming?
Least-cost formulation is the feed industry's application of linear programming. The LP is the mathematical engine; formulation is the problem definition — ingredients, nutrient values, specification and limits — wrapped around it.
Can the optimiser handle ratios like Met+Cys to lysine?
Yes. A ratio constraint (sum of top nutrients) ÷ (bottom nutrient) ≥ r rewrites to a linear row: Σ(topi − r·bottomi)·xi ≥ 0. Any proper formulation tool, including the one in ERES, supports this directly.
Should I formulate on an as-fed or dry-matter basis?
Either works as long as the ingredient values and the specification use the same basis. Dry-matter basis is common for ruminant rations with wet forages; as-fed is typical for poultry and swine compound feed.
What stops the optimiser from producing an unusable feed?
Ingredient limits and ratio constraints. The LP only knows numbers, so caps on fibrous or anti-nutritional ingredients, fixed premix inclusions and minimum energy sources are how nutritionists keep the result practical.
If you run a feed mill and still formulate in a spreadsheet, try the least-cost feed formulation module in ERES: nutrient library, specifications, HiGHS optimiser, shadow and entry prices, and a result that becomes an approved recipe on the same ledger as your purchases and batches. Create a free account — no credit card required.
Run your books on ERES
Accounting, inventory, POS, manufacturing, payroll and tax in one system — and an MCP server so your AI agent can use it too.


