∇ProvenDecisions
Ctrl K

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.

Answer. The smallest objective value is 1655, at p1 = 55, i1 = 15, p2 = 45, i2 = 0, p3 = 50. All 11 constraints are satisfied exactly. Exactly proven optimal.

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:

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.

VariableTypeMeaning
p1real numberunits produced in month 1 (units)
i1real numberinventory held from month 1 to month 2 (units)
p2real numberunits produced in month 2 (units)
i2real numberinventory held from month 2 to month 3 (units)
p3real numberunits 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.

p155i115p245i20p350

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.

#ConstraintValueLimitSlackBinding
1-i1 + p1 = 4040400yes
2i1 - i2 + p2 = 6060600yes
3i2 + p3 = 5050500yes
4p1 <= 5555550yes
5p2 <= 55455510
6p3 <= 5550555
7p1 >= 055055
8p2 >= 045045
9p3 >= 050050
10i1 >= 015015
11i2 >= 0000yes

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.

#ConstraintWeight
1-i1 + p1 = 4011
2i1 - i2 + p2 = 6012
3i2 + p3 = 5011
4p1 ≤ 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 variablePricesValue
y1price of constraint '-i1 + p1 = 40' (objective change per extra unit of its right-hand side)11
y2price of constraint 'i1 - i2 + p2 = 60' (objective change per extra unit of its right-hand side)12
y3price of constraint 'i2 + p3 = 50' (objective change per extra unit of its right-hand side)11
y4price of constraint 'p1 <= 55' (objective change per extra unit of its right-hand side)-1
y5price of constraint 'p2 <= 55' (objective change per extra unit of its right-hand side)0
y6price 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)

Change the numbers and solve it

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

All 50 solved examples

Try ProvenDecisions free: type, photograph or say an optimization problem; every answer is checked by a solver.

What do you want to optimize?

Type the math, describe it in words, snap a photo or say it. ProvenDecisions builds the model, solves it, checks it and walks you through it.

One constraint per line, or separated by commas. Add integer: x, y or binary: z for whole-number decisions. LaTeX works too.

Try: