Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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:

$$ \min_x f(x)\quad\text{s.t.}\quad h(x)=0,\quad g(x)\ge0, $$

with Lagrangian

$$ L(x,\mu,\lambda)=f(x)-\mu^\top h(x)-\lambda^\top g(x),\qquad \lambda\ge0. $$

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:

ConstructorUse
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 Evaluator or the Objective adapter;
  • lagrangian_hessian returns the Hessian of \(L\), and both exact-Hessian methods require it;
  • a failing constraint callback reports as Error::Evaluation { operation: "constraints" } through try_constraints.

19.3 Entries and options

API pages (docs.rs): Method, minimize, augmented_lagrangian, ConstrainedOptions, ConstrainedSolution.

EntryAlgorithmConstraint types
minimize(..., Method::Sqp, ...)Powell damped BFGS + \(l_1\) exact penaltyEqualities and inequalities
minimize(..., Method::NewtonLagrange, ...)Newton on the KKT equationsEqualities alone
minimize(..., Method::LagrangeSqp, ...)SQP with a stabilized Lagrange HessianEqualities alone
sqp_with_restorationSQP + feasibility restoration phaseEqualities and inequalities
augmented_lagrangianPHR multiplier/penalty iteration + BFGS inner loopEqualities and inequalities

ConstrainedOptions defaults:

FieldDefaultNotes
solverOptions::default()Outer stopping and Armijo parameters
feasibility_tolerance1e-6Feasibility and complementarity threshold
max_inner_iterations1000PHR inner budget; other entries ignore it
initial_penalty2PHR 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:

$$ \mu^+=(1-\alpha)\mu+\alpha\mu^{\text{QP}},\qquad \lambda^+=(1-\alpha)\lambda+\alpha\lambda^{\text{QP}}. $$

PHR instead updates multipliers by \(\mu\leftarrow\mu-\rho h\) and \(\lambda\leftarrow\max(0,\lambda-\rho g)\). Its inner objective is

$$ \Phi(x)=f(x)-\mu^\top h(x)+\frac{\rho}{2}\lVert h(x)\rVert^2 +\sum_j\frac{1}{2\rho}\Bigl[\max(0,\lambda_j-\rho g_j)^2-\lambda_j^2\Bigr], $$

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_reduction ratio;
  • one RestorationEvent per attempt.

SqpOptions defaults:

FieldDefault
solverConstrainedOptions::default()
max_subproblem_iterations1000 (per QP phase)
max_subproblem_evaluations10000 (whole run)
max_restoration_iterations100 (per attempt)
restoration_reduction0.1
restoration_damping1e-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:

FieldMeaning
sourceSolver error with its source chain
restorationRestoration attempts so far
last_constrainedComplete outer checkpoint (with multipliers), None before a valid state appears

19.5 Reading results

API page (docs.rs): ConstrainedSolution.

ConstrainedSolution fields:

FieldMeaning
solutionObjective, Lagrangian stationarity norm, iterations and status
equality_multipliers\(\mu\)
inequality_multipliers\(\lambda\ge0\), zero for inactive constraints
constraint_violationMaximum of equality residuals and the negative part of inequality residuals
complementarity\(\lVert\min(g,\lambda)\rVert\) (component-wise)
inner_iterationsTotal PHR inner iterations, zero for other entries

The convergence conditions hold simultaneously:

$$ \lVert\nabla_xL\rVert\le\tau,\qquad \texttt{constraint\_violation}\le\min(\tau,\ \texttt{feasibility\_tolerance}),\qquad \texttt{complementarity}\le\min(\tau,\ \texttt{feasibility\_tolerance}), $$

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, constraints and jacobian;
  • 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.