Lot sizing with setup costs: an integer programming example, solved and checked
The lot sizing with setup costs is a classic integer 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 is 20, 30 and 25 units in periods 1-3. Each production run costs $100 to set up plus $5 per unit; holding a unit for one period costs $2. No starting or ending stock. When should you produce, and how much?
How the model was built
The objective as written from the problem, before the numbers are multiplied out:
- xt is the number of units made in period t, st the stock at the end of period t, and yt = 1 if there is a production run (a setup) in period t.
- x1 − s1 = 20: what is made minus what is carried on is what is sold. The last period ends with no stock: s2 + x3 = 25.
- x1 ≤ 75 y1: with no run, nothing is made. 75 = 20 + 30 + 25, all the demand still to come, so this never cuts off a sensible plan; 55 and 25 do the same for periods 2 and 3.
- Cost = $100 for each run + $5 for each unit made + $2 for each unit carried to the next period.
The model
Each line has a plain-language note on the right.
| make this as small as possible | |
| limit 1: left side must equal 20 | |
| limit 2: left side must equal 30 | |
| limit 3: left side must equal 25 | |
| limit 4: left side cannot exceed the right side | |
| limit 5: left side cannot exceed the right side | |
| limit 6: left side cannot exceed the right side | |
| units produced in period 1 (units) cannot be negative | |
| units produced in period 2 (units) cannot be negative | |
| units produced in period 3 (units) cannot be negative | |
| inventory held at end of period 1 (units) cannot be negative | |
| inventory held at end of period 2 (units) cannot be negative | |
| yes (1) or no (0) |
In matrix form
With its numbers:
What is being decided
There are 8 decision variables.
| Variable | Type | Meaning |
|---|---|---|
| x1 | real number | units produced in period 1 (units) |
| s1 | real number | inventory held at end of period 1 (units) |
| x2 | real number | units produced in period 2 (units) |
| s2 | real number | inventory held at end of period 2 (units) |
| x3 | real number | units produced in period 3 (units) |
| y1 | binary (0 or 1) | 1 if a production run is set up in period 1, else 0 |
| y2 | binary (0 or 1) | 1 if a production run is set up in period 2, else 0 |
| y3 | binary (0 or 1) | 1 if a production run is set up in period 3, else 0 |
Goal and limits
Minimize the objective subject to 11 constraints, of which 5 are simple bounds on a single variable.
Problem type
MILP, complexity level 5: integer variables with linear objective and constraints. 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): constraints 1, 2, 3, 5, 6, 9, 10 (see the table). Changing a binding constraint changes the answer; a slack one can move a little without effect.
| # | Constraint | Value | Limit | Slack | Binding |
|---|---|---|---|---|---|
| 1 | -s1 + x1 = 20 | 20 | 20 | 0 | yes |
| 2 | s1 - s2 + x2 = 30 | 30 | 30 | 0 | yes |
| 3 | s2 + x3 = 25 | 25 | 25 | 0 | yes |
| 4 | x1 <= 75*y1 | 20 | 75 | 55 | |
| 5 | x2 <= 55*y2 | 55 | 55 | 0 | yes |
| 6 | x3 <= 25*y3 | 0 | 0 | 0 | yes |
| 7 | x1 >= 0 | 20 | 0 | 20 | |
| 8 | x2 >= 0 | 55 | 0 | 55 | |
| 9 | x3 >= 0 | 0 | 0 | 0 | yes |
| 10 | s1 >= 0 | 0 | 0 | 0 | yes |
| 11 | s2 >= 0 | 25 | 0 | 25 |
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
x1 = cp.Variable(name='x1') # units produced in period 1 (units)
s1 = cp.Variable(name='s1') # inventory held at end of period 1 (units)
x2 = cp.Variable(name='x2') # units produced in period 2 (units)
s2 = cp.Variable(name='s2') # inventory held at end of period 2 (units)
x3 = cp.Variable(name='x3') # units produced in period 3 (units)
y1 = cp.Variable(name='y1', boolean=True) # 1 if a production run is set up in period 1, else 0
y2 = cp.Variable(name='y2', boolean=True) # 1 if a production run is set up in period 2, else 0
y3 = cp.Variable(name='y3', boolean=True) # 1 if a production run is set up in period 3, else 0
objective = cp.Minimize(2*s1 + 2*s2 + 5*x1 + 5*x2 + 5*x3 + 100*y1 + 100*y2 + 100*y3)
constraints = [
-s1 + x1 == 20,
s1 - s2 + x2 == 30,
s2 + x3 == 25,
x1 <= 75*y1,
x2 <= 55*y2,
x3 <= 25*y3,
x1 >= 0,
x2 >= 0,
x3 >= 0,
s1 >= 0,
s2 >= 0,
]
problem = cp.Problem(objective, constraints)
problem.solve(solver='HIGHS')
print(problem.status, problem.value)
print('x1 =', x1.value)
print('s1 =', s1.value)
print('x2 =', x2.value)
print('s2 =', s2.value)
print('x3 =', x3.value)
print('y1 =', y1.value)
print('y2 =', y2.value)
print('y3 =', y3.value)The dual problem
Every constraint of the original (primal) problem gets a price, and every primal variable becomes a constraint on those prices. Integer variables are relaxed: this is the dual of the continuous (LP) relaxation, which gives a bound on the integer optimum, not its exact value. Only weak duality: the dual of the continuous relaxation gives an lower bound of 551.667 on the integer optimum 625, a duality gap of 73.3333. Integer problems generally have a gap.
| Dual variable | Prices | Value |
|---|---|---|
| y1 | price of constraint '-s1 + x1 = 20' (objective change per extra unit of its right-hand side) | 6.33333 |
| y2 | price of constraint 's1 - s2 + x2 = 30' (objective change per extra unit of its right-hand side) | 6.81818 |
| y3 | price of constraint 's2 + x3 = 25' (objective change per extra unit of its right-hand side) | 8.81818 |
| y4 | price of constraint 'x1 <= 75*y1' (objective change per extra unit of its right-hand side) | -1.33333 |
| y5 | price of constraint 'x2 <= 55*y2' (objective change per extra unit of its right-hand side) | -1.81818 |
| y6 | price of constraint 'x3 <= 25*y3' (objective change per extra unit of its right-hand side) | -3.81818 |
| y7 | price of constraint 'y1 <= 1' (objective change per extra unit of its right-hand side) | 0 |
| y8 | price of constraint 'y2 <= 1' (objective change per extra unit of its right-hand side) | 0 |
| y9 | price of constraint 'y3 <= 1' (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 100*y1 + 100*y2 + 100*y3 + 5*x1 + 5*x2 + 5*x3 + 2*s1 + 2*s2
subject to
x1 - s1 = 20
s1 + x2 - s2 = 30
s2 + x3 = 25
x1 <= 75*y1
x2 <= 55*y2
x3 <= 25*y3
x1, x2, x3, s1, s2 >= 0
binary: y1, y2, y3
# x1 = units produced in period 1 (units)
# x2 = units produced in period 2 (units)
# x3 = units produced in period 3 (units)
# s1 = inventory held at end of period 1 (units)
# s2 = inventory held at end of period 2 (units)
# y1 = 1 if a production run is set up in period 1, else 0
# y2 = 1 if a production run is set up in period 2, else 0
# y3 = 1 if a production run is set up in period 3, else 0
# asked: the production schedule (which periods to produce in and how much in each), along with the minimum total costChecked: the app's answer matches the reference answer in our test set, which two solvers (HIGHS, SCIP) 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.