TExcelTAD
Home › Optimization › Constrained Problems and Feasible Sets

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

min⁡f(x)s.t.gi(x)≤0, i=1,…,m,hj(x)=0, j=1,…,p\min f(\mathbf{x}) \quad \text{s.t.} \quad g_i(\mathbf{x}) \le 0, \ i = 1, \dots, m, \qquad h_j(\mathbf{x}) = 0, \ j = 1, \dots, p

the feasible set is F={x:gi(x)≤0,hj(x)=0}\mathcal{F} = \{\mathbf{x} : g_i(\mathbf{x}) \le 0, h_j(\mathbf{x}) = 0\}. At a feasible point, an inequality is active if gi(x)=0g_i(\mathbf{x}) = 0 (the point is on that boundary) and inactive if gi(x)<0g_i(\mathbf{x}) < 0. Equalities are always active. Inactive constraints do not matter locally: near the point you could delete them.

The minimum moves to the boundary

python · try it yourself
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 (3,2)(3, 2) violates x+y≤4x + y \le 4, so the solution is its projection onto the line x+y=4x + y = 4, the point (2.5,1.5)(2.5, 1.5). There, −∇f-\nabla f 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 d\mathbf{d} is feasible at x\mathbf{x} if small steps x+td\mathbf{x} + t\mathbf{d} stay feasible. At a local minimum, no feasible direction can be a descent direction:

∇f(x∗)Td≥0for every feasible direction d\nabla f(\mathbf{x}^*)^T\mathbf{d} \ge 0 \quad \text{for every feasible direction } \mathbf{d}

For linear constraints, the feasible directions at x\mathbf{x} are exactly those with aiTd≤0\mathbf{a}_i^T\mathbf{d} \le 0 for each active aiTx≤bi\mathbf{a}_i^T\mathbf{x} \le b_i. 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
∣x∣≤c\lvert x \rvert \le c x≤cx \le c and −x≤c-x \le c
max⁡i(aiTx)≤c\max_i(\mathbf{a}_i^T\mathbf{x}) \le c aiTx≤c\mathbf{a}_i^T\mathbf{x} \le c for all ii
∥x∥2≤r\lVert \mathbf{x} \rVert_2 \le r xTx−r2≤0\mathbf{x}^T\mathbf{x} - r^2 \le 0 (convex)
x∈{0,1}x \in \{0, 1\} x(1−x)=0x(1 - x) = 0 (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:

python · try it yourself
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= with LinearConstraint / NonlinearConstraint for general ones (SLSQP, trust-constr).
  • Solvers report "constraint violation" alongside the objective; a solution with violation 10−310^{-3} may be useless if your constraint is a physical limit.

Exercises

Exercise 1: Active or not?

For constraints x≥0x \ge 0, y≥0y \ge 0, x+2y≤4x + 2y \le 4, which are active at (0,2)(0, 2)? At (1,1)(1, 1)?

Answer

At (0,2)(0, 2): x≥0x \ge 0 and x+2y≤4x + 2y \le 4. At (1,1)(1, 1): none.

Solution

At (0,2)(0, 2): x=0x = 0 (active), y=2>0y = 2 > 0 (inactive), 0+4=40 + 4 = 4 (active). At (1,1)(1, 1): 1>01 > 0, 1>01 > 0, 3<43 < 4, so (1,1)(1, 1) is an interior point.

Exercise 2: Project onto a line

Minimize (x−3)2+(y−2)2(x - 3)^2 + (y - 2)^2 subject to x+y=4x + y = 4 by substituting y=4−xy = 4 - x.

Answer

(2.5,1.5)(2.5, 1.5), with f=0.5f = 0.5.

Solution

g(x)=(x−3)2+(2−x)2g(x) = (x - 3)^2 + (2 - x)^2, g′(x)=2(x−3)−2(2−x)=4x−10=0g'(x) = 2(x - 3) - 2(2 - x) = 4x - 10 = 0, so x=2.5x = 2.5, y=1.5y = 1.5, f=0.25+0.25=0.5f = 0.25 + 0.25 = 0.5.

Exercise 3: LICQ fails (code)

Take g1=y≤0g_1 = y \le 0 and g2=x2−y≤0g_2 = x^2 - y \le 0 at the origin. Compute both gradients and check whether they are linearly independent.

Answer

They are (0,1)(0, 1) and (0,−1)(0, -1): linearly dependent, so LICQ fails.

Solution
python · try it yourself
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 {(0,0)}\{(0, 0)\} (since x2≤y≤0x^2 \le y \le 0), but the linearized constraints allow the whole xx-axis. The linearization lies about the geometry, which is exactly what constraint qualifications rule out.

Test yourself

An inequality constraint gi(x)≤0g_i(\mathbf{x}) \le 0 is active at x\mathbf{x} when…

  1. gi(x)<0g_i(\mathbf{x}) < 0
  2. gi(x)=0g_i(\mathbf{x}) = 0
  3. gi(x)>0g_i(\mathbf{x}) > 0
  4. it is linear

At a constrained minimum on the boundary, the gradient of ff…

  1. is always zero
  2. may be nonzero, but no feasible direction is a descent direction
  3. points into the feasible set
  4. is undefined

LICQ requires…

  1. all constraints to be linear
  2. the gradients of the active constraints to be linearly independent
  3. the objective to be convex
  4. no constraint to be active