The NonlinearEquality family of factors in GTSAM provides constraints to enforce equality between variables or between a variable and a constant value. These factors are useful in optimization problems where strict equality constraints are required. Below is an overview of the API, grouped by functionality.
NonlinearEquality¶
The NonlinearEquality factor enforces equality between a variable and a feasible value. It supports both exact and inexact evaluation modes.
Constructors¶
NonlinearEquality(Key j, const T& feasible, const CompareFunction& compare)
Creates a factor that enforces exact equality between the variable at keyjand the feasible valuefeasible.j: Key of the variable to constrain.feasible: The feasible value to enforce equality with.compare: Optional comparison function (default usestraits<T>::Equals).
NonlinearEquality(Key j, const T& feasible, double error_gain, const CompareFunction& compare)
Creates a factor that allows inexact evaluation with a specified error gain.error_gain: Gain applied to the error when the constraint is violated.
Methods¶
double error(const Values& c) const
Computes the error for the given values. Returns0.0if the constraint is satisfied, or a scaled error ifallow_error_is enabled.Vector evaluateError(const T& xj, OptionalMatrixType H = nullptr) const
Evaluates the error vector for the given variable valuexj. Optionally computes the Jacobian matrixH.GaussianFactor::shared_ptr linearize(const Values& x) const
Linearizes the factor at the given valuesxto create a Gaussian factor.
NonlinearEquality1¶
The NonlinearEquality1 factor is a unary equality constraint that fixes a variable to a specific value.
Constructors¶
NonlinearEquality1(const X& value, Key key, double mu = 1000.0)
Creates a factor that fixes the variable atkeyto the valuevalue.value: The fixed value for the variable.key: Key of the variable to constrain.mu: Strength of the constraint (default:1000.0).
Methods¶
Vector evaluateError(const X& x1, OptionalMatrixType H = nullptr) const
Evaluates the error vector for the given variable valuex1. Optionally computes the Jacobian matrixH.void print(const std::string& s, const KeyFormatter& keyFormatter) const
Prints the factor details, including the fixed value and noise model.
NonlinearEquality2¶
The NonlinearEquality2 factor is a binary equality constraint that enforces equality between two variables.
Constructors¶
NonlinearEquality2(Key key1, Key key2, double mu = 1e4)
Creates a factor that enforces equality between the variables atkey1andkey2.key1: Key of the first variable.key2: Key of the second variable.mu: Strength of the constraint (default:1e4).
Methods¶
Vector evaluateError(const T& x1, const T& x2, OptionalMatrixType H1 = nullptr, OptionalMatrixType H2 = nullptr) const
Evaluates the error vector for the given variable valuesx1andx2. Optionally computes the Jacobian matricesH1andH2.void print(const std::string& s, const KeyFormatter& keyFormatter) const
Prints the factor details, including the keys and noise model.
Common Features¶
Error Handling Modes¶
Exact Evaluation: Throws an error during linearization if the constraint is violated.
Inexact Evaluation: Allows nonzero error and scales it using the
error_gain_parameter.
Serialization¶
All factors support serialization for saving and loading models.
Testable Interface¶
All factors implement the Testable interface, providing methods like:
void print(const std::string& s, const KeyFormatter& keyFormatter) const
Prints the factor details.bool equals(const NonlinearFactor& f, double tol) const
Checks if two factors are equal within a specified tolerance.
These factors provide a flexible way to enforce equality constraints in nonlinear optimization problems, making them useful for applications like SLAM, robotics, and control systems.