Linear programming (LP) is a mathematical technique used to find the best outcomemaximum profit or minimum costsubject to a set of linear constraints. In nutrition, it can help design a diet that satisfies daily nutrient requirements at the lowest possible cost, while respecting dietary preferences or restrictions.
Suppose a nutritionist wants to advise a client on a daily menu composed of a limited set of foods. The goal is to minimize the total cost while ensuring the client receives enough of each essential nutrient (protein, vitamins, minerals, etc.) and does not exceed recommended upper limits for certain nutrients (e.g., sodium, saturated fat).
Let
For each food i we need:
For each nutrient j we need:
Minimize total daily cost:
Nutrientminimum constraints (ensure enough intake):
Nutrientmaximum constraints (if upper limits exist):
Servingsize constraints (practical limits):
Where Mi may represent a realistic maximum portion (e.g., 3 servings of cereal per day).
Consider a simplified diet with four foods: Milk, Bread, Chicken, and Apples. The table below shows cost and nutrient content per serving.
| Food | Cost ($) | Protein (g) | Calcium (mg) | Iron (mg) | Sodium (mg) |
|---|---|---|---|---|---|
| Milk | 0.50 | 8 | 300 | 0.1 | 120 |
| Bread | 0.20 | 3 | 20 | 0.8 | 150 |
| Chicken | 1.80 | 25 | 15 | 1.0 | 70 |
| Apples | 0.30 | 0.5 | 10 | 0.2 | 5 |
Daily nutrient requirements (example):
Formulating the LP:
The LP can be solved with free tools such as:
PuLP or SciPy.optimize.linproglpSolveSample Python code (PuLP):
import pulp# Create problemprob = pulp.LpProblem("Diet", pulp.LpMinimize)# Decision variablesx = {i: pulp.LpVariable(f"x{i}", lowBound=0) for i in range(4)}# Cost coefficientscost = [0.5, 0.2, 1.8, 0.3]prob += pulp.lpSum(cost[i]*x[i] for i in range(4)), "Total Cost"# Nutrient matricesprotein = [8, 3, 25, 0.5]calcium = [300, 20, 15, 10]iron = [0.1, 0.8, 1.0, 0.2]sodium = [120, 150, 70, 5]# Minimum requirementsprob += pulp.lpSum(protein[i]*x[i] for i in range(4)) >= 50, "Protein"prob += pulp.lpSum(calcium[i]*x[i] for i in range(4)) >= 800, "Calcium"prob += pulp.lpSum(iron[i]*x[i] for i in range(4)) >= 8, "Iron"# Maximum sodiumprob += pulp.lpSum(sodium[i]*x[i] for i in range(4)) <= 1500, "Sodium"# Solveprob.solve()print("Status:", pulp.LpStatus[prob.status])for i in range(4): print(f"Food {i+1} servings =", x[i].varValue)print("Minimum cost = $", pulp.value(prob.objective)) After solving, the output provides the optimal number of servings for each food. For example, the solver might return:
The total daily cost would be the objective value (e.g., $2.94). All nutrient constraints are satisfiedmeaning the diet meets the clients nutritional goals at the lowest possible price.
Realworld diet plans often need additional features:
Linear programming offers a transparent, costeffective way to design personalized diets that meet nutritional standards. By defining clear objectives, collecting accurate foodnutrient data, and applying an LP solver, nutritionists can quickly generate feasible meal plans, explore tradeoffs, and adapt recommendations to budget changes or dietary restrictions.
