∇ProvenDecisions
Ctrl K

Big-M either-or constraint: an integer programming example, solved and checked

The big-M either-or constraint 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. Assumed: "either ... or (or both)" is modeled with a binary switch w. When w=1, x+y>=6 is enforced. When w=0, x>=3 is enforced. Both can still hold when one is selected. The smallest objective value is 11, at y = 1, x = 3, w = 0. All 5 constraints are satisfied exactly. Optimal within gap tolerance.

Solve your own version free, no account needed

The problem

A buyer orders x tonnes of grade A and y tonnes of grade B (x, y >= 0) at $3 and $2 per tonne, and must take at least 1 tonne of grade B. The contract is met if either the total order is at least 6 tonnes, or at least 3 tonnes of grade A are ordered (or both). Minimize cost.

How the model was built

The objective as written from the problem, before the numbers are multiplied out:

Assumptions:

The model

Each line has a plain-language note on the right.

make as small as possible: total purchase cost (dollars)
tonnes of grade B ordered (tonnes) is at least 1
limit 2: left side must reach at least the right side
limit 3: left side must reach at least the right side
tonnes of grade A ordered (tonnes) cannot be negative
tonnes of grade B ordered (tonnes) cannot be negative
yes (1) or no (0)

In matrix form

With its numbers:

What is being decided

There are 3 decision variables.

VariableTypeMeaning
yreal numbertonnes of grade B ordered (tonnes)
xreal numbertonnes of grade A ordered (tonnes)
wbinary (0 or 1)1 if the contract is met via total order >= 6 tonnes, 0 if via grade A >= 3 tonnes (yes/no)

Goal and limits

Minimize total purchase cost (dollars) subject to 5 constraints, of which 3 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.

y1x3w0

Which constraints hold the answer in place

Binding (no slack left): (1) y >= 1; (3) x >= 3 - 3*w. Changing a binding constraint changes the answer; a slack one can move a little without effect.

#ConstraintValueLimitSlackBinding
1y >= 1110yes
2x + y >= 6*w404
3x >= 3 - 3*w330yes
4x >= 0303
5y >= 0101

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

y = cp.Variable(name='y')  # tonnes of grade B ordered (tonnes)
x = cp.Variable(name='x')  # tonnes of grade A ordered (tonnes)
w = cp.Variable(name='w', boolean=True)  # 1 if the contract is met via total order >= 6 tonnes, 0 if via grade A >= 3 tonnes (yes/no)

objective = cp.Minimize(3*x + 2*y)
constraints = [
    y >= 1,
    x + y >= 6*w,
    x >= 3 - 3*w,
    x >= 0,
    y >= 0,
]
problem = cp.Problem(objective, constraints)
problem.solve(solver='HIGHS')
print(problem.status, problem.value)
print('y =', y.value)
print('x =', x.value)
print('w =', w.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 7 on the integer optimum 11, a duality gap of 4. Integer problems generally have a gap.

Dual variablePricesValue
y1price of constraint 'y >= 1' (objective change per extra unit of its right-hand side)1
y2price of constraint 'x + y >= 6*w' (objective change per extra unit of its right-hand side)1
y3price of constraint 'x >= 3 - 3*w' (objective change per extra unit of its right-hand side)2
y4price of constraint 'w <= 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 3*x + 2*y
subject to
  y >= 1
  x + y >= 6*w
  x >= 3 - 3*w
  x, y >= 0
binary: w
# x = tonnes of grade A ordered (tonnes)
# y = tonnes of grade B ordered (tonnes)
# w = 1 if the contract is met via total order >= 6 tonnes, 0 if via grade A >= 3 tonnes (yes/no)
# objective = total purchase cost (dollars)
# assume: "either ... or (or both)" is modeled with a binary switch w. When w=1, x+y>=6 is enforced. When w=0, x>=3 is enforced. Both can still hold when one is selected.

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: