Allowed regions
An inequality constraint allows a whole region: the curve and everything on one side of it. Many limits are like this. A quantity may not be negative, or may not exceed a capacity, but anything within the limit is fine.
Start in one variable, as in lesson 2.4.1: minimise subject to . The function's own lowest point is .
- : the point 3 is allowed, so the constraint changes nothing. The minimum is , inside the allowed interval.
- : 3 is not allowed. falls all the way to the edge , where and the slope is .
Rule: Slack or binding
At a minimum, an inequality constraint is slack, with the point inside the region, or binding, with the point on the edge. A slack constraint has and lesson 4.4.1's condition; a binding one has lesson 4.5.1's.
Slack or binding in two variables
Take the bowl of lesson 4.5.1 again. Its lowest point is the origin, where .
With , the origin is allowed, since . The constraint is slack: the minimum is and .
With the origin is not allowed, so the minimum must lie on the edge . Lesson 4.5.1 found it: , with and .
The shaded side is allowed. When it contains the bowl's lowest point, the constraint is slack. When it does not, the minimum sits on the edge, and points into the allowed side.
The sign of
At a binding constraint the allowed region lies on one side of the edge. At the minimum, no step into the region may go downhill. So , the uphill direction, points into the allowed side, and that fixes the sign of .
- : the allowed side is the way points. At , , so .
- : the origin is not allowed, and the allowed side is the way points. Lesson 4.5.1's edge minimum is , where , so .
- One variable: for , points to the left, into the allowed side. Here has slope 1, so .
The rate of lesson 4.5.1, , says the same. Raising enlarges the region , so the best value can only fall: . It shrinks the region , so the best value can only rise: .
A wrong sign means a wrong guess
Suppose you guess that binds. The edge gives with , the wrong sign for a constraint: points out of the allowed side. A step inward then goes downhill, so the constraint is slack, not binding.
The KKT conditions
The two cases and the sign fit into one list, named after Karush, Kuhn and Tucker.
Rule: KKT conditions for g ≤ c
A minimum of subject to satisfies all four. For a constraint , the same list holds with .
The last condition, , is called complementary slackness. A product is 0 only if a factor is 0, so either (slack) or (binding).
Both can be 0 at once. With , the bowl's lowest point lies on the edge itself, and there , so while .
To solve a problem, guess which case holds, solve it, and keep the guess that passes every condition. The table does this for the bowl:
| constraint | guess | point | passes? | |
|---|---|---|---|---|
| slack | 0 | yes | ||
| binding | 4 | no: sign | ||
| slack | 0 | no: not allowed | ||
| binding | 4 | yes | ||
| binding | yes |
Try it
The first loops are the one-variable example: the lowest allowed point and there, for and for .
kkt tests a guess for the bowl: is the point allowed, does have the right sign, and is ? Stationarity, , holds for both guesses by construction.
Optimisation books usually write every constraint of a minimum as and the first condition as , with . That is the same list with . This module keeps lesson 4.5.1's form, so that is always the rate .
Two constraints
With two constraints, each multiplier belongs to its own constraint.
Rule: KKT with two constraints
The point must satisfy both constraints. Each is 0 if its constraint is slack, and otherwise has the sign set by its direction: for , for .
Minimise the bowl subject to and . Each constraint can be slack or binding, so there are four cases:
| binding | point | ? | ? | |
|---|---|---|---|---|
| neither | no | yes | 0 | |
| only | yes | no | 6 | |
| only | no | yes | 1 | |
| both | yes | yes | 9 |
The second row is lesson 4.5.1's answer. The third minimises on the line . Only the last point is allowed.
Check its signs at , where , and . Solving gives and . The first is for a constraint and the second for a constraint, so is the minimum, with .
Each multiplier is a rate again. Moving from 3 changes the best value at the rate 8; moving from 1, at the rate . Loosen to instead, and is allowed: the second constraint goes slack, with .
With inequality constraints there are cases. Solvers search them far more cleverly, but they test the same conditions.
Try it
The loop checks each guess against both constraints. Then np.linalg.solve finds and at (lesson 3.3.1).
best_value is with both constraints binding: and . Its central differences in and are the two multipliers.
Checking with a solver
scipy.optimize.minimize, named in lesson 4.4.3, accepts constraints. Each is a dictionary: "type": "eq" means fun(v) = 0, and "type": "ineq" means fun(v) >= 0. The method "SLSQP" handles both.
So is v[0] + v[1] - 3, and is 1 - v[0]. A constraint must be turned round. Typed as v[0] + v[1] - 3, the constraint meant as silently becomes , and the solver returns instead of .
Try it
The first call solves the two-constraint problem and returns with .
The loop then shows the trap: the wrong way round, then the right way round. ftol sets how precisely the solver stops; the answers are rounded to 4 decimals.
Lesson 4.5.3 shows when a point that passes the KKT conditions is sure to be the minimum. Case study 4.5.5 uses them to forbid negative portfolio weights.
Common mistakes
- Do not assume a constraint binds. With the bowl's minimum is the origin, inside the region.
- Check that the point is allowed. The bowl's lowest point, , breaks .
- Check the sign of . A binding guess for gives , the wrong sign: the guess is wrong.
- The sign depends on the direction. With , a constraint needs and a constraint . Books that write have .
- Complementary slackness allows both factors to be 0. With the minimum is on the edge and .
- SciPy's
"ineq"means . Write as3 - v[0] - v[1].
Inequality constraints and the KKT conditions
0 of 12 correct
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
How to type answers
- Powers with
^:x^7,2^(1/3),a^-2. - Multiply with
*or by writing side by side:3x^2,2(x+1). ln(x)is the natural log,log(x, 2)is log base 2,eis Euler's number,sqrt(x)is a square root.sin(x),cos(x)andtan(x)take radians; writepifor π andsin(x)^2for sin²x.- Your first answer to each question is saved: it counts towards your score and brings the question back for review.
- Exact answers like
ln(20)/ln(3)are best. Decimals need about 4 significant figures.
Summary card
- An inequality constraint allows a region. At a minimum it is slack (inside, , ) or binding (on the edge, ).
- At a binding constraint points into the allowed side. With , a constraint has and a constraint ; as before.
- KKT for : , , , (complementary slackness).
- With several constraints, , each with its own sign or 0. Solve by guessing which constraints bind, then check every condition.
- In SciPy,
"ineq"meansfun(v) >= 0.