Multi-period production and inventory planning: a linear programming example, solved and checked
The multi-period production and inventory planning is a classic linear programming problem. Here it is solved by a real solver (HIGHS) and checked: every constraint, the dual, and the optimality certificate. Change the numbers below and solve your own.
Solve your own version free, no account needed
The problem
Demand for the next three months is 40, 60 and 50 units. Production costs $10, $12 and $11 per unit in months 1-3, capacity is 55 units a month, and holding a unit to the next month costs $1. Start and end with no inventory. Minimize total cost.
How the model was built
The objective as written from the problem, before the numbers are multiplied out:
- pt is the production in month t, and it is the stock carried from month t to the next.
- Each month: stock in + production − demand = stock out. Month 1 starts with none: p1 − i1 = 40. Month 2: i1 + p2 − i2 = 60. Month 3 ends with none: i2 + p3 = 50.
- Cost = $10 p1 + $12 p2 + $11 p3 for production, plus $1 for each unit carried (i1 + i2).
- Making a unit early and carrying it costs $1 more, so it pays when a later month is more than $1 dearer: month 1 plus a month's holding is $11, less than month 2's $12.
The model
Each line has a plain-language note on the right.
| make this as small as possible | |
| limit 1: left side must equal 40 | |
| limit 2: left side must equal 60 | |
| limit 3: left side must equal 50 | |
| units produced in month 1 (units) is at most 55 | |
| units produced in month 2 (units) is at most 55 | |
| units produced in month 3 (units) is at most 55 | |
| units produced in month 1 (units) cannot be negative | |
| units produced in month 2 (units) cannot be negative | |
| units produced in month 3 (units) cannot be negative | |
| inventory held from month 1 to month 2 (units) cannot be negative | |
| inventory held from month 2 to month 3 (units) cannot be negative |
In matrix form
With its numbers:
What is being decided
There are 5 decision variables.
| Variable | Type | Meaning |
|---|---|---|
| p1 | real number | units produced in month 1 (units) |
| i1 | real number | inventory held from month 1 to month 2 (units) |
| p2 | real number | units produced in month 2 (units) |
| i2 | real number | inventory held from month 2 to month 3 (units) |
| p3 | real number | units produced in month 3 (units) |
Goal and limits
Minimize the objective subject to 11 constraints, of which 8 are simple bounds on a single variable.
Problem type
LP, complexity level 2: a linear program. Solved with HIGHS at the Medium solver tier.
The answer at a glance
The optimal value of each decision, as the solver returned it.
Which constraints hold the answer in place
Binding (no slack left): (1) -i1 + p1 = 40; (2) i1 - i2 + p2 = 60; (3) i2 + p3 = 50; (4) p1 <= 55; (11) i2 >= 0. Changing a binding constraint changes the answer; a slack one can move a little without effect.
| # | Constraint | Value | Limit | Slack | Binding |
|---|---|---|---|---|---|
| 1 | -i1 + p1 = 40 | 40 | 40 | 0 | yes |
| 2 | i1 - i2 + p2 = 60 | 60 | 60 | 0 | yes |
| 3 | i2 + p3 = 50 | 50 | 50 | 0 | yes |
| 4 | p1 <= 55 | 55 | 55 | 0 | yes |
| 5 | p2 <= 55 | 45 | 55 | 10 | |
| 6 | p3 <= 55 | 50 | 55 | 5 | |
| 7 | p1 >= 0 | 55 | 0 | 55 | |
| 8 | p2 >= 0 | 45 | 0 | 45 | |
| 9 | p3 >= 0 | 50 | 0 | 50 | |
| 10 | i1 >= 0 | 15 | 0 | 15 | |
| 11 | i2 >= 0 | 0 | 0 | 0 | yes |
Why this is optimal
A proof you can check by hand. Multiply each constraint in the table by its weight and add them up: the result is a lower limit on the objective that holds for every plan meeting the constraints. Our answer reaches that limit exactly, so no plan does better. A negative weight turns a limit around (for example ≥ into ≤) before adding. Every step was checked in exact fractions, not rounded decimals.
| # | Constraint | Weight |
|---|---|---|
| 1 | -i1 + p1 = 40 | 11 |
| 2 | i1 - i2 + p2 = 60 | 12 |
| 3 | i2 + p3 = 50 | 11 |
| 4 | p1 ≤ 55 | -1 |
Algebraic model (low level)
Decision variables, objective and every constraint written out; this is exactly what the solver receives.
Standard form
As a linear program: minimize cᵀx subject to A x ≤ b (the inequality rows) and A_eq x = b_eq (the equations); a maximization is written as minimizing the negative.
Model code (cvxpy)
The same model in cvxpy, ready to run.
import cvxpy as cp
p1 = cp.Variable(name='p1') # units produced in month 1 (units)
i1 = cp.Variable(name='i1') # inventory held from month 1 to month 2 (units)
p2 = cp.Variable(name='p2') # units produced in month 2 (units)
i2 = cp.Variable(name='i2') # inventory held from month 2 to month 3 (units)
p3 = cp.Variable(name='p3') # units produced in month 3 (units)
objective = cp.Minimize(i1 + i2 + 10*p1 + 12*p2 + 11*p3)
constraints = [
-i1 + p1 == 40,
i1 - i2 + p2 == 60,
i2 + p3 == 50,
p1 <= 55,
p2 <= 55,
p3 <= 55,
p1 >= 0,
p2 >= 0,
p3 >= 0,
i1 >= 0,
i2 >= 0,
]
problem = cp.Problem(objective, constraints)
problem.solve(solver='HIGHS')
print(problem.status, problem.value)
print('p1 =', p1.value)
print('i1 =', i1.value)
print('p2 =', p2.value)
print('i2 =', i2.value)
print('p3 =', p3.value)The dual problem
Every constraint of the original (primal) problem gets a price, and every primal variable becomes a constraint on those prices. Strong duality: primal and dual optima are equal (1655).
| Dual variable | Prices | Value |
|---|---|---|
| y1 | price of constraint '-i1 + p1 = 40' (objective change per extra unit of its right-hand side) | 11 |
| y2 | price of constraint 'i1 - i2 + p2 = 60' (objective change per extra unit of its right-hand side) | 12 |
| y3 | price of constraint 'i2 + p3 = 50' (objective change per extra unit of its right-hand side) | 11 |
| y4 | price of constraint 'p1 <= 55' (objective change per extra unit of its right-hand side) | -1 |
| y5 | price of constraint 'p2 <= 55' (objective change per extra unit of its right-hand side) | 0 |
| y6 | price of constraint 'p3 <= 55' (objective change per extra unit of its right-hand side) | 0 |
Solve your own
This is the model as the app reads it. Change any number and solve it in the free box on the front page (no account needed).
minimize 10 p1 + 12 p2 + 11 p3 + 1 i1 + 1 i2
subject to
p1 - i1 = 40
i1 + p2 - i2 = 60
i2 + p3 = 50
p1 <= 55
p2 <= 55
p3 <= 55
p1, p2, p3, i1, i2 >= 0
# p1 = units produced in month 1 (units)
# p2 = units produced in month 2 (units)
# p3 = units produced in month 3 (units)
# i1 = inventory held from month 1 to month 2 (units)
# i2 = inventory held from month 2 to month 3 (units)Checked: the app's answer matches the reference answer in our test set, which two solvers (HIGHS, CLARABEL) agree on. Built 2026-11-10.
Related examples
Try ProvenDecisions free: type, photograph or say an optimization problem; every answer is checked by a solver.