Real problems have limits. Wings can't be infinitely thin, budgets can't be negative. Learn to optimize within boundaries.
Every previous chapter assumed the domain was all of Rn. In practice, a hedge fund manager cannot sell more stock than they own, an airplane cannot have zero-thickness wings, and you cannot spend negative dollars.
The general constrained optimization problem is: minimize f(x) subject to x ∈ X. This chapter presents a toolbox of techniques to handle this: transformations, projections, Lagrange multipliers, penalty methods, and barrier methods.
Any optimization problem can be rewritten using two types of constraints:
| Type | Form | Example |
|---|---|---|
| Equality | h(x) = 0 | Budget must exactly equal $100 |
| Inequality | g(x) ≤ 0 | Weight must not exceed 50 kg |
Greater-than inequalities g(x) ≥ 0 become less-than by negation: −g(x) ≤ 0. Equality constraints can be decomposed into two inequalities: h(x) ≤ 0 and −h(x) ≤ 0.
Sometimes you can transform the problem so constraints vanish. Two approaches:
1. Bound transforms: An interval constraint a ≤ x ≤ b can be removed by substituting:
This maps all of R to [a,b], so optimizing over x̂ ∈ R automatically satisfies a ≤ x ≤ b.
2. Equality substitution: If h(x) = c1x1 + c2x2 = 0, solve for x2 = −(c1/c2)x1 and substitute into f, eliminating one variable and one constraint.
Another approach: run your favorite unconstrained method, and after each step, project back onto the feasible set. The projection finds the closest feasible point to the unconstrained iterate:
For box constraints a ≤ x ≤ b, the projection is trivial: clamp each component to its nearest bound. For linear constraints, it becomes a quadratic program.
For equality constraints h(x) = 0, the method of Lagrange multipliers gives necessary conditions for optimality. The idea: at a constrained minimum, the gradient of f must be aligned with the gradient of h.
where λ is the Lagrange multiplier. We form the Lagrangian:
Setting ∇L = 0 gives us both the alignment condition (∇f = λ∇h) and the constraint satisfaction (h(x) = 0).
With inequalities g(x) ≤ 0, the optimum can be either on the constraint boundary (constraint is active, g(x*) = 0) or in the interior (constraint is inactive, g(x*) < 0).
When active: the Lagrange condition holds with ∇f + μ∇g = 0, and we need μ ≥ 0 (the penalty pushes inward). When inactive: ∇f = 0 (as if unconstrained) and μ = 0 (the constraint does not matter).
This leads to complementary slackness: μ · g(x*) = 0. Either the constraint is tight (g = 0) or the multiplier is zero (μ = 0) — but not both positive simultaneously.
The Karush-Kuhn-Tucker (KKT) conditions are the first-order necessary conditions for optimality with both equality and inequality constraints. They generalize the Lagrange conditions:
| Condition | Requirement | Meaning |
|---|---|---|
| Feasibility | g(x*) ≤ 0, h(x*) = 0 | Point satisfies all constraints |
| Dual feasibility | μ ≥ 0 | Inequality multipliers push inward |
| Complementary slackness | μ ⊙ g = 0 | Inactive constraints have zero multiplier |
| Stationarity | ∇f + ∑μi∇gi + ∑λj∇hj = 0 | Gradient of f lies in span of constraint gradients |
Penalty methods convert constrained problems to unconstrained ones by adding a penalty for constraint violations:
Common penalty functions:
| Penalty | Formula | Property |
|---|---|---|
| Count | ∑(gi(x) > 0) | Sharp boundary but no gradient info |
| Quadratic | ∑max(gi, 0)² | Smooth but may need large ρ |
| Augmented Lagrangian | ρ/2 ∑hi² + ∑λihi | Works with smaller ρ |
The augmented Lagrangian (method of multipliers) adds linear penalty terms that are updated each iteration: λ(k+1) = λ(k) + ρh(x(k+1)). This avoids needing ρ → ∞.
Interior point methods (barrier methods) keep all iterates strictly feasible by adding a barrier function that approaches infinity at constraint boundaries:
Common barriers: the inverse barrier p = −∑1/gi(x) and the log barrier p = −∑log(−gi(x)). As ρ increases, the barrier weakens and the solution approaches the true constrained optimum.
Interior point methods require a strictly feasible starting point. If one is not known, you can find it by solving an auxiliary problem: minimize s subject to g(x) ≤ s·1, starting from a large s.
| Method | Approach | Best For |
|---|---|---|
| Transform | Remove constraints algebraically | Simple bounds, linear equalities |
| Projected descent | Project infeasible iterates | Box constraints, convex feasible sets |
| Lagrange multipliers | Analytical optimality conditions | Equality constraints, theory |
| Penalty methods | Penalize infeasibility | General constraints, simple to implement |
| Augmented Lagrangian | Penalty + adaptive multipliers | General equality constraints |
| Interior point | Barrier function, stay feasible | When feasibility is required at all times |