Sensitivity and Shadow Prices
An optimal solution answers "what should we do?". The multipliers answer the manager's next question: "what if we had a bit more of this resource?" Under strong duality, the optimal dual variables are exactly the sensitivities of the optimal value to the constraints, so a solver gives you this what-if analysis for free.
The perturbed problem
Relax each constraint by an amount:
If strong duality holds and is differentiable at :
Even without differentiability there is a global inequality: .
| Multiplier | Meaning |
|---|---|
| large | the constraint binds hard; loosening it helps a lot |
| the constraint is slack; extra resource is worthless (locally) | |
| increasing raises the cost; , lowers it |
Shadow prices in a production plan
A factory makes three products with profits 20, 30 and 25 per unit, limited by machine hours, labour hours and material:
import numpy as np
from scipy.optimize import linprog
profit = np.array([20.0, 30.0, 25.0])
A = np.array([[2.0, 3.0, 2.0], # machine hours per unit
[1.0, 2.0, 2.0], # labour hours per unit
[3.0, 2.0, 2.0]]) # kg of material per unit
b = np.array([100.0, 80.0, 150.0])
res = linprog(-profit, A_ub=A, b_ub=b, bounds=[(0, None)] * 3, method="highs")
print("plan:", np.round(res.x, 4), " profit:", round(-res.fun, 4))
prices = -res.ineqlin.marginals # HiGHS reports d(objective)/d(b) for the min problem
for name, p, slack in zip(["machine", "labour", "material"], prices, res.ineqlin.residual):
print(f"{name:9s} shadow price {p:7.4f} slack {slack:7.4f}")plan: [20. 0. 30.] profit: 1150.0
machine shadow price 7.5000 slack 0.0000
labour shadow price 5.0000 slack 0.0000
material shadow price 0.0000 slack 30.0000
The best plan makes no units of the second product. One more machine hour is worth 7.5 in extra profit and one more labour hour 5; material has 30 kg of slack left, so its price is zero, and buying more would be wasted money.
Checking the prediction
Shadow prices are local. Increase machine hours step by step and watch the profit grow at the predicted rate until the basis changes:
import numpy as np
from scipy.optimize import linprog
profit = np.array([20.0, 30.0, 25.0])
A = np.array([[2.0, 3.0, 2.0], [1.0, 2.0, 2.0], [3.0, 2.0, 2.0]])
def best(machine):
r = linprog(-profit, A_ub=A, b_ub=[machine, 80.0, 150.0], bounds=[(0, None)] * 3, method="highs")
return -r.fun
base = best(100)
for extra in (1, 10, 20, 40, 60):
gain = best(100 + extra) - base
print(f"+{extra:2d} machine hours: profit +{gain:8.4f} (rate {gain / extra:.4f} per hour)")+ 1 machine hours: profit + 7.5000 (rate 7.5000 per hour)
+10 machine hours: profit + 75.0000 (rate 7.5000 per hour)
+20 machine hours: profit +137.5000 (rate 6.8750 per hour)
+40 machine hours: profit +225.0000 (rate 5.6250 per hour)
+60 machine hours: profit +225.0000 (rate 3.7500 per hour)
The rate stays constant for small changes and drops once another constraint starts to bind: is piecewise linear for LPs.
Uses beyond pricing
- Which constraint to relax: in design problems, the largest multiplier points at the bottleneck.
- Regularization paths: in the lasso, the multiplier of a norm constraint is the penalty weight of the equivalent penalized form.
- Economics: in market-clearing models, the multipliers of supply-demand balance constraints are the market prices (electricity markets compute locational prices exactly this way).
In software
- SciPy's HiGHS interface reports
res.ineqlin.marginals,res.eqlin.marginalsand bound marginals; CVXPY usesconstraint.dual_value; Gurobi usesConstr.Piand reports ranges over which a price is valid (SARHSLow,SARHSUp).
Exercises
Exercise 1: Estimate a change
A cost-minimizing problem has optimal cost 500 and a capacity constraint with multiplier . Estimate the cost if capacity is increased by 3 units.
Answer
About .
Solution
Relaxing the constraint by changes the cost by about . For a convex problem, 464 is a lower bound on the new cost in any case.
Exercise 2: Slack constraint
In the production plan, why is the material shadow price exactly zero?
Answer
Because material is not used up (positive slack), so by complementary slackness its multiplier is zero.
Solution
with forces . A small change in the material limit does not change the optimal plan.
Exercise 3: Labour price (code)
Check the labour shadow price by solving the LP with 81 labour hours.
Answer
The profit rises by the labour shadow price.
Solution
import numpy as np
from scipy.optimize import linprog
profit = np.array([20.0, 30.0, 25.0]); A = np.array([[2.0, 3.0, 2.0], [1.0, 2.0, 2.0], [3.0, 2.0, 2.0]])
f = lambda lab: -linprog(-profit, A_ub=A, b_ub=[100.0, lab, 150.0], bounds=[(0, None)] * 3).fun
print(round(f(81) - f(80), 4))5.0
Test yourself
Under strong duality, the multiplier of equals…
- the number of active constraints
A resource with positive slack at the optimum has shadow price…
- positive
- negative
- zero
- infinite
For an LP, the optimal value as a function of a right-hand side is…
- quadratic
- piecewise linear and convex (for minimization)
- constant
- discontinuous everywhere