19. Nonlinear Constraint Reference
This chapter gives the constrained-problem interface, the four entries and the multiplier conventions. The theory is in chapter 11.
19.1 Constraint conventions
Problem form:
with Lagrangian
Constraints carries constraint values and row-wise Jacobians at one point:
pub struct Constraints {
pub equalities: Vector, // h(x)
pub inequalities: Vector, // g(x)
pub equality_jacobian: Matrix, // m_e x n
pub inequality_jacobian: Matrix, // m_i x n
}
API page (docs.rs): Constraints.
Constructors:
| Constructor | Use |
|---|---|
Constraints::empty(n) | Unconstrained, with \(0\times n\) Jacobians |
Constraints::equalities_only(values, jacobian) | Equalities alone |
Constraints::inequalities_only(values, jacobian) | \(g(x)\ge0\) alone |
Constraints::linear(x, ae, be, ai, bi) | Linear constraints \(A_ex=b_e\), \(A_ix\ge b_i\) |
Constraints::from_nonpositive(...) | Translates \(c(x)\le0\) into \(g=-c\ge0\) |
Constraint counts stay fixed within one solve.
19.2 Problem interface
pub trait ConstrainedProblem: Evaluator {
fn constraints(&self, x: &Vector) -> Constraints;
fn lagrangian_hessian(&self, x: &Vector, mu: &Vector, lambda: &Vector)
-> Option<Matrix> { None }
fn try_constraints(&self, x: &Vector) -> Result<Constraints, EvaluationError> { ... }
fn try_lagrangian_hessian(&self, x: &Vector, mu: &Vector, lambda: &Vector)
-> Result<Option<Matrix>, EvaluationError> { ... }
}
API page (docs.rs): ConstrainedProblem.
- objective values and gradients come from
Evaluatoror theObjectiveadapter; lagrangian_hessianreturns the Hessian of \(L\), and both exact-Hessian methods require it;- a failing constraint callback reports as
Error::Evaluation { operation: "constraints" }throughtry_constraints.
19.3 Entries and options
API pages (docs.rs): Method, minimize, augmented_lagrangian, ConstrainedOptions, ConstrainedSolution.
| Entry | Algorithm | Constraint types |
|---|---|---|
minimize(..., Method::Sqp, ...) | Powell damped BFGS + \(l_1\) exact penalty | Equalities and inequalities |
minimize(..., Method::NewtonLagrange, ...) | Newton on the KKT equations | Equalities alone |
minimize(..., Method::LagrangeSqp, ...) | SQP with a stabilized Lagrange Hessian | Equalities alone |
sqp_with_restoration | SQP + feasibility restoration phase | Equalities and inequalities |
augmented_lagrangian | PHR multiplier/penalty iteration + BFGS inner loop | Equalities and inequalities |
ConstrainedOptions defaults:
| Field | Default | Notes |
|---|---|---|
solver | Options::default() | Outer stopping and Armijo parameters |
feasibility_tolerance | 1e-6 | Feasibility and complementarity threshold |
max_inner_iterations | 1000 | PHR inner budget; other entries ignore it |
initial_penalty | 2 | PHR initial penalty parameter |
Solve signatures:
pub fn minimize<P: ConstrainedProblem + ?Sized>(
p: &P, x0: &Vector, method: Method, options: &ConstrainedOptions,
) -> Result<ConstrainedSolution, Error>
pub fn augmented_lagrangian<P: ConstrainedProblem + ?Sized>(
p: &P, x0: &Vector, options: &ConstrainedOptions,
) -> Result<ConstrainedSolution, Error>
The SQP \(l_1\) penalty parameter is the larger of its current value and the largest multiplier magnitude plus one. SQP multipliers interpolate along the accepted step:
PHR instead updates multipliers by \(\mu\leftarrow\mu-\rho h\) and \(\lambda\leftarrow\max(0,\lambda-\rho g)\). Its inner objective is
and the penalty parameter doubles when consecutive outer iterations reach \(k\ge2\) with the residual above 0.8 times the previous value.
19.4 SQP with restoration
pub fn sqp_with_restoration<P: ConstrainedProblem + ?Sized>(
p: &P, x0: &Vector, options: &SqpOptions,
) -> Result<SqpSolution, SqpError>
API pages (docs.rs): sqp_with_restoration, SqpOptions, SqpSolution, SqpError, RestorationEvent.
An infeasible linearized QP starts a constraint-only restoration phase:
- restoration objective \(\theta(x)=\tfrac12(\lVert h\rVert^2+\lVert\min(g,0)\rVert^2)\);
- restoration direction from a damped least-squares QR solve;
- acceptance when the violation drops by at least the
restoration_reductionratio; - one
RestorationEventper attempt.
SqpOptions defaults:
| Field | Default |
|---|---|
solver | ConstrainedOptions::default() |
max_subproblem_iterations | 1000 (per QP phase) |
max_subproblem_evaluations | 10000 (whole run) |
max_restoration_iterations | 100 (per attempt) |
restoration_reduction | 0.1 |
restoration_damping | 1e-3 |
Return structure:
pub struct SqpSolution {
pub constrained: ConstrainedSolution, // nested convergence flag
pub restoration: Vec<RestorationEvent>, // in execution order
}
RestorationEvent fields: iteration, trigger (the triggering error), initial_violation, final_violation, iterations, failure.
Failures return SqpError:
| Field | Meaning |
|---|---|
source | Solver error with its source chain |
restoration | Restoration attempts so far |
last_constrained | Complete outer checkpoint (with multipliers), None before a valid state appears |
19.5 Reading results
API page (docs.rs): ConstrainedSolution.
ConstrainedSolution fields:
| Field | Meaning |
|---|---|
solution | Objective, Lagrangian stationarity norm, iterations and status |
equality_multipliers | \(\mu\) |
inequality_multipliers | \(\lambda\ge0\), zero for inactive constraints |
constraint_violation | Maximum of equality residuals and the negative part of inequality residuals |
complementarity | \(\lVert\min(g,\lambda)\rVert\) (component-wise) |
inner_iterations | Total PHR inner iterations, zero for other entries |
The convergence conditions hold simultaneously:
where \(\tau\) is solver.stopping.gradient_tolerance.
19.6 Example
An equality-constrained quadratic with analytic solution \((0,1)\):
#![allow(unused)]
fn main() {
use nlopt4r::{Matrix, Objective, Vector};
use nlopt4r::constrained::{ConstrainedProblem, Constraints, SqpOptions, sqp_with_restoration};
struct Model;
impl Objective for Model {
fn value(&self, x: &Vector) -> f64 {
(x[0] - 1.0).powi(2) + (x[1] - 2.0).powi(2)
}
fn gradient(&self, x: &Vector) -> Vector {
Vector::from_vec(vec![2.0 * (x[0] - 1.0), 2.0 * (x[1] - 2.0)])
}
}
impl ConstrainedProblem for Model {
fn constraints(&self, x: &Vector) -> Constraints {
Constraints {
equalities: Vector::from_vec(vec![x[0] + x[1] - 1.0]),
equality_jacobian: Matrix::from_row_slice(1, 2, &[1.0, 1.0]),
inequalities: Vector::zeros(0),
inequality_jacobian: Matrix::zeros(0, 2),
}
}
}
let mut options = SqpOptions::default();
options.solver.solver.stopping.max_evaluations = Some(500);
let result = sqp_with_restoration(&Model, &Vector::zeros(2), &options)?;
assert!(result.constrained.solution.converged());
assert!(result.constrained.constraint_violation < 1e-6);
Ok::<(), Box<dyn std::error::Error>>(())
}
For inequality problems, write the constraints as \(g(x)\ge0\) or translate \(c(x)\le0\) with Constraints::from_nonpositive.
19.7 Counts and budgets
- each outer state evaluation counts once each in
evaluations.objective,gradient,constraintsandjacobian; - constraint Jacobians and objective gradients count separately;
- PHR inner objective calls share the strict outer budget;
- SQP subproblem states count in
evaluations.subproblem, separate from the external callback budget; - budget interruption returns a non-converged report, and callback or subproblem failures keep the checkpoint.
Theory background
- Full derivations of SQP, restoration and PHR: see chapter 11.
- KKT conditions and multiplier signs: see chapter 1.
- Stopping criteria and error checkpoints: see chapter 12.