∇ProvenDecisions
Ctrl K

Dual of a transportation problem: a linear programming example, solved and checked

The dual of a transportation problem is a classic linear 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 dual problem and the dual prices of supply and demand. Shadow prices (objective change per extra unit of each limit): (1) x11 + x12 <= 30: 0; (2) x21 + x22 <= 25: -3; (3) x11 + x21 = 20: 4; (4) x12 + x22 = 30: 6; (5) x11 >= 0: 0; (6) x12 >= 0: 0; (7) x21 >= 0: 4; (8) x22 >= 0: 0. Assumed: warehouse supplies are upper limits, so not all stock must be shipped. The smallest objective value is 185, at x11 = 20, x12 = 5, x21 = 0, x22 = 25. All 8 constraints are satisfied exactly. Exactly proven optimal.

Solve your own version free, no account needed

The problem

Two warehouses hold 30 and 25 units. Two shops need exactly 20 and 30 units. Shipping one unit costs $4 and $6 from warehouse 1 to shops 1 and 2, and $5 and $3 from warehouse 2. Minimize shipping cost. Write the dual problem and find the dual prices of supply and demand.

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 shipping cost (dollars)
limit 1: left side cannot exceed 30
limit 2: left side cannot exceed 25
limit 3: left side must equal 20
limit 4: left side must equal 30
units shipped from warehouse 1 to shop 1 (units) cannot be negative
units shipped from warehouse 1 to shop 2 (units) cannot be negative
units shipped from warehouse 2 to shop 1 (units) cannot be negative
units shipped from warehouse 2 to shop 2 (units) cannot be negative

In matrix form

With its numbers:

The dual problem

Every constraint of the original (primal) problem gets a price, and every primal variable becomes a constraint on those prices. Strong duality: primal and dual optima are equal (185).

Dual variablePricesValue
y1price of constraint 'x11 + x12 <= 30' (objective change per extra unit of its right-hand side)0
y2price of constraint 'x21 + x22 <= 25' (objective change per extra unit of its right-hand side)-3
y3price of constraint 'x11 + x21 = 20' (objective change per extra unit of its right-hand side)4
y4price of constraint 'x12 + x22 = 30' (objective change per extra unit of its right-hand side)6

What is being decided

There are 4 decision variables.

VariableTypeMeaning
x11real numberunits shipped from warehouse 1 to shop 1 (units)
x12real numberunits shipped from warehouse 1 to shop 2 (units)
x21real numberunits shipped from warehouse 2 to shop 1 (units)
x22real numberunits shipped from warehouse 2 to shop 2 (units)

Goal and limits

Minimize total shipping cost (dollars) subject to 8 constraints, of which 4 are simple bounds on a single variable.

Problem type

LP, complexity level 2: a linear program. Solved with HIGHS at the Medium solver tier.

The answer at a glance

The optimal value of each decision, as the solver returned it.

x1120x125x210x2225

Which constraints hold the answer in place

Binding (no slack left): (2) x21 + x22 <= 25; (3) x11 + x21 = 20; (4) x12 + x22 = 30; (7) x21 >= 0. Changing a binding constraint changes the answer; a slack one can move a little without effect.

#ConstraintValueLimitSlackBinding
1x11 + x12 <= 3025305
2x21 + x22 <= 2525250yes
3x11 + x21 = 2020200yes
4x12 + x22 = 3030300yes
5x11 >= 020020
6x12 >= 0505
7x21 >= 0000yes
8x22 >= 025025

Why this is optimal

A proof you can check by hand. Multiply each constraint in the table by its weight and add them up: the result is a lower limit on the objective that holds for every plan meeting the constraints. Our answer reaches that limit exactly, so no plan does better. A negative weight turns a limit around (for example ≥ into ≤) before adding. Every step was checked in exact fractions, not rounded decimals.

#ConstraintWeight
2x21 + x22 ≤ 25-3
3x11 + x21 = 204
4x12 + x22 = 306

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

x11 = cp.Variable(name='x11')  # units shipped from warehouse 1 to shop 1 (units)
x12 = cp.Variable(name='x12')  # units shipped from warehouse 1 to shop 2 (units)
x21 = cp.Variable(name='x21')  # units shipped from warehouse 2 to shop 1 (units)
x22 = cp.Variable(name='x22')  # units shipped from warehouse 2 to shop 2 (units)

objective = cp.Minimize(4*x11 + 6*x12 + 5*x21 + 3*x22)
constraints = [
    x11 + x12 <= 30,
    x21 + x22 <= 25,
    x11 + x21 == 20,
    x12 + x22 == 30,
    x11 >= 0,
    x12 >= 0,
    x21 >= 0,
    x22 >= 0,
]
problem = cp.Problem(objective, constraints)
problem.solve(solver='HIGHS')
print(problem.status, problem.value)
print('x11 =', x11.value)
print('x12 =', x12.value)
print('x21 =', x21.value)
print('x22 =', x22.value)

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 4*x11 + 6*x12 + 5*x21 + 3*x22
subject to
x11 + x12 <= 30
x21 + x22 <= 25
x11 + x21 = 20
x12 + x22 = 30
x11, x12, x21, x22 >= 0
# x11 = units shipped from warehouse 1 to shop 1 (units)
# x12 = units shipped from warehouse 1 to shop 2 (units)
# x21 = units shipped from warehouse 2 to shop 1 (units)
# x22 = units shipped from warehouse 2 to shop 2 (units)
# objective = total shipping cost (dollars)
# assume: warehouse supplies are upper limits, so not all stock must be shipped
# asked: the dual problem and the dual prices of supply and demand

Change the numbers and solve it

Checked: the app's answer matches the reference answer in our test set, which two solvers (HIGHS, CLARABEL) 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: