Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Constrained

The constrained module in GTSAM provides constrained nonlinear optimization on top of factor graphs. It includes classes for representing constraints, building constrained problems, and solving them with penalty and augmented Lagrangian methods.

Core Problem Model

Equality Constraints

Inequality Constraints

QP and QCQP Problems

The leading factor of 1/2 in row-space QpCost construction is intentional: it follows GTSAM’s standard factor-error convention. To represent a QCQP objective written without the 1/2, pass twice the row-space Q blocks to QpCost.

The rotation conversion has two tracks. Rot2 at D=1 uses an exact homogeneous lift and supports a sign-pinning hard prior. At D>=N, Rot2 (D>=2) and Rot3 (D>=3) use row-Stiefel variables satisfying XX=IXX^\top=I. Between costs have a common right-O(D)O(D) gauge. Matrix-form priors are intentionally unsupported: a fixed target X[M  0]F2\|X-[M^\top\;0]\|_F^2 breaks that gauge and cannot be represented by the Burer--Monteiro Gram matrix alone. A future BM-compatible lowering can introduce an anchor block and use the invariant cost XMXanchorF2\|X-M^\top X_{\mathrm{anchor}}\|_F^2. The Stiefel constraints do not enforce determinant +1, so square variables also admit reflections. Unsupported factors throw from NonlinearFactor::qcqpFactors.

Optimizers

How the Pieces Fit Together

For a new user, it helps to think in two phases:

  1. Build a constrained problem.

  2. Run a constrained solver on that problem.

Inequality constraints can use different smooth penalty shapes via InequalityPenaltyFunction (ramp, smooth polynomial ramps, or softplus), which controls behavior near the active constraint boundary in PenaltyOptimizer. AugmentedLagrangianOptimizer instead requires exact PHR inequality terms and rejects custom smooth penalties so its projected multiplier update remains mathematically consistent.

1) Build the Problem

This stage is about modeling: you separate what you want to minimize (objective terms) from what must hold (constraints), then combine them into a single ConstrainedOptProblem object that the solvers can consume.

2) Solve the Problem

This stage is algorithmic: pick a constrained solver, form iterative unconstrained subproblems internally, and solve those subproblems with a standard nonlinear optimizer until constraint violation and cost are reduced.