∇ProvenDecisions
Ctrl K

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.

Answer. You asked for: the production schedule (which periods to produce in and how much in each), along with the minimum total cost. The smallest objective value is 625, at x1 = 20, s1 = 0, x2 = 55, s2 = 25, x3 = 0, y1 = 1, y2 = 1, y3 = 0. All 11 constraints are satisfied exactly. Optimal within gap tolerance.

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:

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.

VariableTypeMeaning
x1real numberunits produced in period 1 (units)
s1real numberinventory held at end of period 1 (units)
x2real numberunits produced in period 2 (units)
s2real numberinventory held at end of period 2 (units)
x3real numberunits produced in period 3 (units)
y1binary (0 or 1)1 if a production run is set up in period 1, else 0
y2binary (0 or 1)1 if a production run is set up in period 2, else 0
y3binary (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.

x120s10x255s225x30y11y21y30

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.

#ConstraintValueLimitSlackBinding
1-s1 + x1 = 2020200yes
2s1 - s2 + x2 = 3030300yes
3s2 + x3 = 2525250yes
4x1 <= 75*y1207555
5x2 <= 55*y255550yes
6x3 <= 25*y3000yes
7x1 >= 020020
8x2 >= 055055
9x3 >= 0000yes
10s1 >= 0000yes
11s2 >= 025025

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 variablePricesValue
y1price of constraint '-s1 + x1 = 20' (objective change per extra unit of its right-hand side)6.33333
y2price of constraint 's1 - s2 + x2 = 30' (objective change per extra unit of its right-hand side)6.81818
y3price of constraint 's2 + x3 = 25' (objective change per extra unit of its right-hand side)8.81818
y4price of constraint 'x1 <= 75*y1' (objective change per extra unit of its right-hand side)-1.33333
y5price of constraint 'x2 <= 55*y2' (objective change per extra unit of its right-hand side)-1.81818
y6price of constraint 'x3 <= 25*y3' (objective change per extra unit of its right-hand side)-3.81818
y7price of constraint 'y1 <= 1' (objective change per extra unit of its right-hand side)0
y8price of constraint 'y2 <= 1' (objective change per extra unit of its right-hand side)0
y9price 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 cost

Change the numbers and solve it

Checked: 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

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: