Fixed-charge (setup cost) problem: an integer programming example, solved and checked
The fixed-charge (setup cost) problem 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
An order of at least 12 parts can be made on two machines. Machine 1 costs $20 to set up, then $3 per part, and makes at most 10 parts; machine 2 costs $8 to set up, then $6 per part, and makes at most 15 parts. A machine that makes no parts is not set up. Parts are whole numbers. Minimize total cost.
How the model was built
The objective as written from the problem, before the numbers are multiplied out:
- y1 = 1 if machine 1 is set up. x1 ≤ 10 y1: without a setup it makes nothing; with one, at most 10 parts. x2 ≤ 15 y2 is the same for machine 2.
- Cost = $3 per part + $20 setup on machine 1, and $6 per part + $8 setup on machine 2.
The model
Each line has a plain-language note on the right.
| make as small as possible: total cost of setup plus per-part costs ($) | |
| limit 1: left side must reach at least 12 | |
| limit 2: left side cannot exceed the right side | |
| limit 3: left side cannot exceed the right side | |
| parts made on machine 1 (parts) cannot be negative | |
| parts made on machine 2 (parts) cannot be negative | |
| whole numbers only | |
| yes (1) or no (0) |
In matrix form
With its numbers:
What is being decided
There are 4 decision variables.
| Variable | Type | Meaning |
|---|---|---|
| x1 | integer | parts made on machine 1 (parts) |
| x2 | integer | parts made on machine 2 (parts) |
| y1 | binary (0 or 1) | 1 if machine 1 is set up, 0 otherwise (yes/no) |
| y2 | binary (0 or 1) | 1 if machine 2 is set up, 0 otherwise (yes/no) |
Goal and limits
Minimize total cost of setup plus per-part costs ($) subject to 5 constraints, of which 2 are simple bounds on a single variable.
Problem type
ILP, 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): (1) x1 + x2 >= 12; (2) x1 <= 10*y1. Changing a binding constraint changes the answer; a slack one can move a little without effect.
| # | Constraint | Value | Limit | Slack | Binding |
|---|---|---|---|---|---|
| 1 | x1 + x2 >= 12 | 12 | 12 | 0 | yes |
| 2 | x1 <= 10*y1 | 10 | 10 | 0 | yes |
| 3 | x2 <= 15*y2 | 2 | 15 | 13 | |
| 4 | x1 >= 0 | 10 | 0 | 10 | |
| 5 | x2 >= 0 | 2 | 0 | 2 |
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', integer=True) # parts made on machine 1 (parts)
x2 = cp.Variable(name='x2', integer=True) # parts made on machine 2 (parts)
y1 = cp.Variable(name='y1', boolean=True) # 1 if machine 1 is set up, 0 otherwise (yes/no)
y2 = cp.Variable(name='y2', boolean=True) # 1 if machine 2 is set up, 0 otherwise (yes/no)
objective = cp.Minimize(3*x1 + 6*x2 + 20*y1 + 8*y2)
constraints = [
x1 + x2 >= 12,
x1 <= 10*y1,
x2 <= 15*y2,
x1 >= 0,
x2 >= 0,
]
problem = cp.Problem(objective, constraints)
problem.solve(solver='HIGHS')
print(problem.status, problem.value)
print('x1 =', x1.value)
print('x2 =', x2.value)
print('y1 =', y1.value)
print('y2 =', y2.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 63.0667 on the integer optimum 70, a duality gap of 6.93333. Integer problems generally have a gap.
| Dual variable | Prices | Value |
|---|---|---|
| y1 | price of constraint 'x1 + x2 >= 12' (objective change per extra unit of its right-hand side) | 6.53333 |
| y2 | price of constraint 'x1 <= 10*y1' (objective change per extra unit of its right-hand side) | -3.53333 |
| y3 | price of constraint 'x2 <= 15*y2' (objective change per extra unit of its right-hand side) | -0.533333 |
| y4 | price of constraint 'y1 <= 1' (objective change per extra unit of its right-hand side) | -15.3333 |
| y5 | price of constraint 'y2 <= 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 20*y1 + 3*x1 + 8*y2 + 6*x2
subject to
x1 + x2 >= 12
x1 <= 10*y1
x2 <= 15*y2
x1, x2 >= 0
integer: x1, x2
binary: y1, y2
# x1 = parts made on machine 1 (parts)
# x2 = parts made on machine 2 (parts)
# y1 = 1 if machine 1 is set up, 0 otherwise (yes/no)
# y2 = 1 if machine 2 is set up, 0 otherwise (yes/no)
# objective = total cost of setup plus per-part costs ($)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
Try ProvenDecisions free: type, photograph or say an optimization problem; every answer is checked by a solver.