Inequality Constraints and the KKT Conditions
Inequality constraints add a twist to Lagrange multipliers: a constraint either matters (it is active and pushes back) or it does not (it is inactive and its multiplier is zero). The Karush-Kuhn-Tucker (KKT) conditions capture both cases in one system and are the optimality conditions that every constrained solver checks.
The KKT conditions
For s.t. , , with Lagrangian , a point with multipliers satisfies KKT if
Complementary slackness says: for each inequality, either it is active () or its multiplier is zero. Dual feasibility says the constraint can only push, not pull: must point out of the feasible set, into the region the constraint forbids.
| Problem type | KKT conditions are… |
|---|---|
| any problem, with a constraint qualification (LICQ, Slater, …) | necessary for a local minimum |
| convex problem (, convex, affine) | sufficient for a global minimum |
| convex problem with Slater's condition | necessary and sufficient |
Checking KKT by hand and in code
Minimize subject to and (written ). From the previous lesson the solution is , with only the first constraint active.
import numpy as np
x = np.array([2.5, 1.5])
grad_f = 2 * (x - np.array([3.0, 2.0]))
g = np.array([x[0] + x[1] - 4, -x[0]]) # constraint values
grad_g = np.array([[1.0, 1.0], [-1.0, 0.0]]) # rows: gradients of g1, g2
lam2 = 0.0 # inactive -> multiplier 0
lam1 = -grad_f[0] / grad_g[0, 0] # from stationarity, first component
lam = np.array([lam1, lam2])
print("multipliers:", lam)
print("stationarity residual:", grad_f + grad_g.T @ lam)
print("primal feasible:", bool(np.all(g <= 1e-12)), " dual feasible:", bool(np.all(lam >= 0)))
print("complementary slackness lambda_i * g_i:", lam * g + 0)multipliers: [1. 0.]
stationarity residual: [0. 0.]
primal feasible: True dual feasible: True
complementary slackness lambda_i * g_i: [0. 0.]
Solving KKT by trying active sets
For small problems you can solve the KKT system by guessing which constraints are active, solving the resulting equalities, and checking the signs:
import numpy as np
from itertools import combinations
# minimize x^2 + y^2 - 4x - 6y subject to x + y <= 3, x - y <= 1, -x <= 0
Q = 2 * np.eye(2); c = np.array([-4.0, -6.0])
A = np.array([[1.0, 1.0], [1.0, -1.0], [-1.0, 0.0]]); b = np.array([3.0, 1.0, 0.0])
for k in range(0, 3):
for S in combinations(range(3), k):
S = list(S); m = len(S)
K = np.block([[Q, A[S].T], [A[S], np.zeros((m, m))]]) if m else Q
sol = np.linalg.solve(K, np.concatenate([-c, b[S]]))
x, lam = sol[:2], sol[2:]
ok = np.all(A @ x <= b + 1e-9) and np.all(lam >= -1e-9)
if ok:
print("active set", S, " x =", np.round(x, 4), " multipliers =", np.round(lam, 4))active set [0] x = [1. 2.] multipliers = [2.]
Exactly one guess passes all the checks. Trying every subset is exponential in the number of constraints; active-set methods walk through the subsets intelligently, and interior-point methods avoid guessing altogether.
A worked example: water filling
Allocate power to channels with noise levels to maximize capacity subject to . KKT gives for a "water level" chosen so the powers sum to : pour water over an uneven floor.
import numpy as np
noise = np.array([0.5, 1.0, 2.0, 4.0]); P = 3.0
lo, hi = 0.0, noise.max() + P
for _ in range(100): # bisection on the water level
w = (lo + hi) / 2
lo, hi = (w, hi) if np.maximum(0, w - noise).sum() < P else (lo, w)
p = np.maximum(0, w - noise)
print("water level:", round(w, 6), " powers:", np.round(p, 4), " sum:", round(p.sum(), 6))water level: 2.166667 powers: [1.6667 1.1667 0.1667 0. ] sum: 3.0
The noisiest channel gets no power: its constraint is active.
In software
- Solvers report the KKT residuals (stationarity, feasibility, complementarity) as their stopping criteria; IPOPT's log shows
inf_pr,inf_duandmuper iteration. scipy.optimize.minimize(method="trust-constr")returns multipliers inres.v; CVXPY exposes them asconstraint.dual_value.
Exercises
Exercise 1: One variable
Minimize subject to . Write the KKT conditions and find .
Answer
, .
Solution
Stationarity: . The unconstrained minimum is infeasible, so the constraint is active: , giving . Dual feasibility holds.
Exercise 2: Inactive constraint
Minimize subject to . What is ?
Answer
, .
Solution
The unconstrained minimum is feasible with ; complementary slackness forces , and stationarity holds.
Exercise 3: Wrong sign (code)
For s.t. , someone claims is optimal with constraint inactive. Which KKT condition fails?
Answer
Stationarity: with the gradient is .
Solution
x, lam = 0.5, 0.0
print("stationarity:", 2 * (x - 2) + lam, " feasibility:", x - 1 <= 0, " complementarity:", lam * (x - 1) + 0)stationarity: -3.0 feasibility: True complementarity: 0.0
is feasible and complementarity holds trivially, but still decreases toward .
Test yourself
Complementary slackness means…
- all constraints are active
- an inactive constraint has a zero multiplier
- all multipliers are zero
- the objective is zero
For a convex problem, a point satisfying the KKT conditions is…
- a global minimum
- possibly a saddle point
- always infeasible
- a local maximum
The multipliers of inequality constraints must be…
- negative
- non-negative
- zero
- equal to 1