Machine scheduling (makespan): an integer programming example, solved and checked
The machine scheduling (makespan) 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
Five jobs of 3, 3, 2, 2 and 2 hours go to two identical machines. Assign them to finish everything as early as possible.
How the model was built
The objective as written from the problem, before the numbers are multiplied out:
- xj = 1 puts job j on machine 1, and xj = 0 puts it on machine 2. T is the time when everything is finished, in hours.
- Machine 1 works 3x_1 + 3x_2 + 2x_3 + 2x_4 + 2x_5 hours. The jobs take 12 hours in all, so machine 2 works 12 minus that. Both must be at most T.
The model
Each line has a plain-language note on the right.
| make as small as possible: time at which all jobs are finished (hours) | |
| limit 1: left side cannot exceed the right side | |
| limit 2: left side cannot exceed the right side | |
| finish time of the last machine, the makespan (hours) cannot be negative | |
| yes (1) or no (0) |
In matrix form
With its numbers:
What is being decided
There are 6 decision variables.
| Variable | Type | Meaning |
|---|---|---|
| x1 | binary (0 or 1) | 1 if the 3-hour job A is on machine 1, 0 if on machine 2 |
| x2 | binary (0 or 1) | 1 if the 3-hour job B is on machine 1, 0 if on machine 2 |
| x3 | binary (0 or 1) | 1 if the first 2-hour job is on machine 1, 0 if on machine 2 |
| x4 | binary (0 or 1) | 1 if the second 2-hour job is on machine 1, 0 if on machine 2 |
| x5 | binary (0 or 1) | 1 if the third 2-hour job is on machine 1, 0 if on machine 2 |
| T | real number | finish time of the last machine, the makespan (hours) |
Goal and limits
Minimize time at which all jobs are finished (hours) subject to 3 constraints, of which 1 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): (1) 3*x1 + 3*x2 + 2*x3 + 2*x4 + 2*x5 <= T; (2) -3*x1 - 3*x2 - 2*x3 - 2*x4 - 2*x5 + 12 <= T. Changing a binding constraint changes the answer; a slack one can move a little without effect.
| # | Constraint | Value | Limit | Slack | Binding |
|---|---|---|---|---|---|
| 1 | 3*x1 + 3*x2 + 2*x3 + 2*x4 + 2*x5 <= T | 6 | 6 | 0 | yes |
| 2 | -3*x1 - 3*x2 - 2*x3 - 2*x4 - 2*x5 + 12 <= T | 6 | 6 | 0 | yes |
| 3 | T >= 0 | 6 | 0 | 6 |
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', boolean=True) # 1 if the 3-hour job A is on machine 1, 0 if on machine 2
x2 = cp.Variable(name='x2', boolean=True) # 1 if the 3-hour job B is on machine 1, 0 if on machine 2
x3 = cp.Variable(name='x3', boolean=True) # 1 if the first 2-hour job is on machine 1, 0 if on machine 2
x4 = cp.Variable(name='x4', boolean=True) # 1 if the second 2-hour job is on machine 1, 0 if on machine 2
x5 = cp.Variable(name='x5', boolean=True) # 1 if the third 2-hour job is on machine 1, 0 if on machine 2
T = cp.Variable(name='T') # finish time of the last machine, the makespan (hours)
objective = cp.Minimize(T)
constraints = [
3*x1 + 3*x2 + 2*x3 + 2*x4 + 2*x5 <= T,
-3*x1 - 3*x2 - 2*x3 - 2*x4 - 2*x5 + 12 <= T,
T >= 0,
]
problem = cp.Problem(objective, constraints)
problem.solve(solver='HIGHS')
print(problem.status, problem.value)
print('x1 =', x1.value)
print('x2 =', x2.value)
print('x3 =', x3.value)
print('x4 =', x4.value)
print('x5 =', x5.value)
print('T =', T.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 6 on the integer optimum 6, a duality gap of 0. Integer problems generally have a gap.
| Dual variable | Prices | Value |
|---|---|---|
| y1 | price of constraint '3*x1 + 3*x2 + 2*x3 + 2*x4 + 2*x5 <= T' (objective change per extra unit of its right-hand side) | -0.5 |
| y2 | price of constraint '-3*x1 - 3*x2 - 2*x3 - 2*x4 - 2*x5 + 12 <= T' (objective change per extra unit of its right-hand side) | -0.5 |
| y3 | price of constraint 'x1 <= 1' (objective change per extra unit of its right-hand side) | 0 |
| y4 | price of constraint 'x2 <= 1' (objective change per extra unit of its right-hand side) | 0 |
| y5 | price of constraint 'x3 <= 1' (objective change per extra unit of its right-hand side) | 0 |
| y6 | price of constraint 'x4 <= 1' (objective change per extra unit of its right-hand side) | 0 |
| y7 | price of constraint 'x5 <= 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 T
subject to
3 x1 + 3 x2 + 2 x3 + 2 x4 + 2 x5 <= T
3 (1 - x1) + 3 (1 - x2) + 2 (1 - x3) + 2 (1 - x4) + 2 (1 - x5) <= T
T >= 0
binary: x1, x2, x3, x4, x5
# x1 = 1 if the 3-hour job A is on machine 1, 0 if on machine 2
# x2 = 1 if the 3-hour job B is on machine 1, 0 if on machine 2
# x3 = 1 if the first 2-hour job is on machine 1, 0 if on machine 2
# x4 = 1 if the second 2-hour job is on machine 1, 0 if on machine 2
# x5 = 1 if the third 2-hour job is on machine 1, 0 if on machine 2
# T = finish time of the last machine, the makespan (hours)
# objective = time at which all jobs are finished (hours)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.