Constrained Problems and Feasible Sets
Most real problems have constraints: budgets, capacities, physical limits, probabilities that must sum to one. A constraint changes what "optimal" means: the best point may sit on the boundary of the feasible set, where the gradient is not zero at all. This lesson sets up the geometry that the Lagrange and KKT conditions turn into equations.
Feasible set, active constraints
For the problem
the feasible set is . At a feasible point, an inequality is active if (the point is on that boundary) and inactive if . Equalities are always active. Inactive constraints do not matter locally: near the point you could delete them.
The minimum moves to the boundary
import numpy as np
# minimize (x - 3)^2 + (y - 2)^2 subject to x + y <= 4, x >= 0, y >= 0
f = lambda x, y: (x - 3)**2 + (y - 2)**2
xs = np.linspace(0, 4, 4001)
X, Y = np.meshgrid(xs, xs)
feasible = (X + Y <= 4 + 1e-12)
F = np.where(feasible, f(X, Y), np.inf)
i = np.unravel_index(np.argmin(F), F.shape)
x, y = X[i], Y[i]
print("constrained minimum near", (round(float(x), 3), round(float(y), 3)), " f =", round(float(F[i]), 4))
print("active constraints: x + y = 4 ->", bool(abs(x + y - 4) < 1e-9), "; x = 0 ->", bool(x == 0), "; y = 0 ->", bool(y == 0))
gx, gy = 2 * (x - 3), 2 * (y - 2)
print("gradient of f there:", (round(float(gx), 3), round(float(gy), 3)), " (parallel to the constraint normal (1, 1))")constrained minimum near (2.5, 1.5) f = 0.5
active constraints: x + y = 4 -> True ; x = 0 -> False ; y = 0 -> False
gradient of f there: (-1.0, -1.0) (parallel to the constraint normal (1, 1))
The unconstrained minimum violates , so the solution is its projection onto the line , the point . There, points straight out of the feasible set: you would like to go further, but the constraint stops you.
Feasible directions and tangent cones
A direction is feasible at if small steps stay feasible. At a local minimum, no feasible direction can be a descent direction:
For linear constraints, the feasible directions at are exactly those with for each active . For curved constraints you linearize them, which requires a constraint qualification, a regularity condition that the linearization describes the true geometry. The most common, LICQ, asks that the gradients of the active constraints be linearly independent.
Reformulation tricks
| Constraint | Equivalent form |
|---|---|
| and | |
| for all | |
| (convex) | |
| (non-convex: better left as an integer constraint) |
Box constraints in code
The simplest constraints, bounds on each variable, are handled natively by many solvers:
import numpy as np
from scipy.optimize import minimize
f = lambda p: (p[0] - 3)**2 + (p[1] - 2)**2 + p[0] * p[1]
r_free = minimize(f, [0.0, 0.0])
r_box = minimize(f, [0.0, 0.0], method="L-BFGS-B", bounds=[(0, 1), (0, 1)])
print("unconstrained:", np.round(r_free.x, 4), round(r_free.fun, 4))
print("in [0,1]^2: ", np.round(r_box.x, 4), round(r_box.fun, 4))unconstrained: [2.6667 0.6667] 3.6667
in [0,1]^2: [1. 1.] 6.0
In software
- SciPy:
bounds=for boxes (L-BFGS-B, TNC, trust-constr),constraints=withLinearConstraint/NonlinearConstraintfor general ones (SLSQP, trust-constr). - Solvers report "constraint violation" alongside the objective; a solution with violation may be useless if your constraint is a physical limit.
Exercises
Exercise 1: Active or not?
For constraints , , , which are active at ? At ?
Answer
At : and . At : none.
Solution
At : (active), (inactive), (active). At : , , , so is an interior point.
Exercise 2: Project onto a line
Minimize subject to by substituting .
Answer
, with .
Solution
, , so , , .
Exercise 3: LICQ fails (code)
Take and at the origin. Compute both gradients and check whether they are linearly independent.
Answer
They are and : linearly dependent, so LICQ fails.
Solution
import numpy as np
G = np.array([[0.0, 1.0], [0.0, -1.0]]) # rows: grad g1, grad g2 at (0, 0)
print("rank of active gradients:", np.linalg.matrix_rank(G))rank of active gradients: 1
The feasible set is the single point (since ), but the linearized constraints allow the whole -axis. The linearization lies about the geometry, which is exactly what constraint qualifications rule out.
Test yourself
An inequality constraint is active at when…
- it is linear
At a constrained minimum on the boundary, the gradient of …
- is always zero
- may be nonzero, but no feasible direction is a descent direction
- points into the feasible set
- is undefined
LICQ requires…
- all constraints to be linear
- the gradients of the active constraints to be linearly independent
- the objective to be convex
- no constraint to be active