24 #include <boost/bind.hpp> 92 j), feasible_(feasible), allow_error_(false), error_gain_(0.0),
102 j), feasible_(feasible), allow_error_(true), error_gain_(error_gain),
110 virtual void print(
const std::string& s =
"",
111 const KeyFormatter& keyFormatter = DefaultKeyFormatter)
const {
112 std::cout << s <<
"Constraint: on [" << keyFormatter(this->key()) <<
"]\n";
119 const This* e = dynamic_cast<const This*>(&f);
121 && std::abs(error_gain_ - e->error_gain_) < tol;
130 const T& xj = c.
at<T>(this->key());
132 if (allow_error_ || !compare_(xj, feasible_)) {
133 return error_gain_ *
dot(e, e);
141 boost::optional<Matrix&> H = boost::none)
const {
145 *H = Matrix::Identity(nj,nj);
147 }
else if (compare_(feasible_, xj)) {
149 *H = Matrix::Identity(nj,nj);
150 return Vector::Zero(nj);
153 throw std::invalid_argument(
154 "Linearization point not feasible for " 155 + DefaultKeyFormatter(this->key()) +
"!");
156 return Vector::Constant(nj, std::numeric_limits<double>::infinity());
162 const T& xj = x.
at<T>(this->key());
171 virtual gtsam::NonlinearFactor::shared_ptr
clone()
const {
172 return boost::static_pointer_cast<gtsam::NonlinearFactor>(
173 gtsam::NonlinearFactor::shared_ptr(
new This(*
this)));
182 template<
class ARCHIVE>
183 void serialize(ARCHIVE & ar,
const unsigned int ) {
185 & boost::serialization::make_nvp(
"NoiseModelFactor1",
186 boost::serialization::base_object<Base>(*
this));
187 ar & BOOST_SERIALIZATION_NVP(feasible_);
188 ar & BOOST_SERIALIZATION_NVP(allow_error_);
189 ar & BOOST_SERIALIZATION_NVP(error_gain_);
195 template<
typename VALUE>
203 template<
class VALUE>
219 GTSAM_CONCEPT_MANIFOLD_TYPE(X)
221 GTSAM_CONCEPT_TESTABLE_TYPE(X)
225 typedef boost::shared_ptr<NonlinearEquality1<VALUE> >
shared_ptr;
236 std::abs(mu)), key), value_(value) {
243 virtual gtsam::NonlinearFactor::shared_ptr
clone()
const {
244 return boost::static_pointer_cast<gtsam::NonlinearFactor>(
245 gtsam::NonlinearFactor::shared_ptr(
new This(*
this)));
250 boost::optional<Matrix&> H = boost::none)
const {
258 virtual void print(
const std::string& s =
"",
259 const KeyFormatter& keyFormatter = DefaultKeyFormatter)
const {
260 std::cout << s <<
": NonlinearEquality1(" << keyFormatter(this->key())
262 this->noiseModel_->print();
270 template<
class ARCHIVE>
271 void serialize(ARCHIVE & ar,
const unsigned int ) {
273 & boost::serialization::make_nvp(
"NoiseModelFactor1",
274 boost::serialization::base_object<Base>(*
this));
275 ar & BOOST_SERIALIZATION_NVP(value_);
280 template<
typename VALUE>
289 template<
class VALUE>
298 GTSAM_CONCEPT_MANIFOLD_TYPE(X)
306 typedef boost::shared_ptr<NonlinearEquality2<VALUE> > shared_ptr;
316 virtual gtsam::NonlinearFactor::shared_ptr
clone()
const {
317 return boost::static_pointer_cast<gtsam::NonlinearFactor>(
318 gtsam::NonlinearFactor::shared_ptr(
new This(*
this)));
322 Vector
evaluateError(
const X& x1,
const X& x2, boost::optional<Matrix&> H1 =
323 boost::none, boost::optional<Matrix&> H2 = boost::none)
const {
325 if (H1) *H1 = -Matrix::Identity(p,p);
326 if (H2) *H2 = Matrix::Identity(p,p);
334 template<
class ARCHIVE>
335 void serialize(ARCHIVE & ar,
const unsigned int ) {
337 & boost::serialization::make_nvp(
"NoiseModelFactor2",
338 boost::serialization::base_object<Base>(*
this));
343 template<
typename VALUE>
Vector evaluateError(const X &x1, const X &x2, boost::optional< Matrix & > H1=boost::none, boost::optional< Matrix & > H2=boost::none) const
g(x) with optional derivative2
Definition: NonlinearEquality.h:322
Base class and basic functions for Manifold types.
double dot(const V1 &a, const V2 &b)
Dot product.
Definition: Vector.h:162
This is the base class for all factor types.
Definition: Factor.h:54
Vector evaluateError(const T &xj, boost::optional< Matrix & > H=boost::none) const
error function
Definition: NonlinearEquality.h:140
A non-templated config holding any types of Manifold-group elements.
Definition: Values.h:70
A convenient base class for creating your own NoiseModelFactor with 2 variables.
Definition: NonlinearFactor.h:345
virtual Vector unwhitenedError(const Values &x, boost::optional< std::vector< Matrix > & > H=boost::none) const =0
Error function without the NoiseModel, .
ValueType at(Key j) const
Retrieve a variable by key j.
Definition: Values-inl.h:342
virtual gtsam::NonlinearFactor::shared_ptr clone() const
Definition: NonlinearEquality.h:316
friend class boost::serialization::access
Serialization function.
Definition: NonlinearEquality.h:269
static shared_ptr All(size_t dim)
Fully constrained variations.
Definition: NoiseModel.h:460
An equality factor that forces either one variable to a constant, or a set of variables to be equal t...
Definition: NonlinearEquality.h:45
virtual GaussianFactor::shared_ptr linearize(const Values &x) const
linearize to a GaussianFactor
Definition: NonlinearEquality.h:161
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:57
NonlinearEquality1()
default constructor to allow for serialization
Definition: NonlinearEquality.h:214
friend class boost::serialization::access
Serialization function.
Definition: NonlinearEquality.h:181
A helper that implements the traits interface for GTSAM types.
Definition: Testable.h:150
Simple unary equality constraint - fixes a value for a variable.
Definition: NonlinearEquality.h:204
NonlinearEquality()
default constructor - only for serialization
Definition: NonlinearEquality.h:77
NonlinearEquality(Key j, const T &feasible, const CompareFunction &_compare=boost::bind(traits< T >::Equals, _1, _2, 1e-9))
Constructor - forces exact evaluation.
Definition: NonlinearEquality.h:89
boost::function< bool(const T &, const T &)> CompareFunction
Function that compares two values.
Definition: NonlinearEquality.h:72
boost::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition: Key.h:33
A convenient base class for creating your own NoiseModelFactor with 1 variable.
Definition: NonlinearFactor.h:276
NonlinearEquality2(Key key1, Key key2, double mu=1000.0)
TODO: comment.
Definition: NonlinearEquality.h:309
Nonlinear factor base class.
Definition: NonlinearFactor.h:50
virtual void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
Print.
Definition: NonlinearEquality.h:110
Simple binary equality constraint - this constraint forces two factors to be the same.
Definition: NonlinearEquality.h:290
const SharedNoiseModel & noiseModel() const
access to the noise model
Definition: NonlinearFactor.h:210
Key key1() const
methods to retrieve both keys
Definition: NonlinearFactor.h:377
Vector evaluateError(const X &x1, boost::optional< Matrix & > H=boost::none) const
g(x) with optional derivative
Definition: NonlinearEquality.h:249
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition: concepts.h:30
virtual gtsam::NonlinearFactor::shared_ptr clone() const
Definition: NonlinearEquality.h:243
Non-linear factor base classes.
A Gaussian factor in the squared-error form.
Definition: JacobianFactor.h:87
virtual bool equals(const NonlinearFactor &f, double tol=1e-9) const
Check if two factors are equal.
Definition: NonlinearEquality.h:118
virtual double error(const Values &c) const
actual error function calculation
Definition: NonlinearEquality.h:129
NonlinearEquality1(const X &value, Key key, double mu=1000.0)
Constructor.
Definition: NonlinearEquality.h:234
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
Concept check for values that can be used in unit tests.
boost::shared_ptr< NonlinearEquality1< VALUE > > shared_ptr
fixed value for variable
Definition: NonlinearEquality.h:225
virtual void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
Print.
Definition: NonlinearEquality.h:258
virtual gtsam::NonlinearFactor::shared_ptr clone() const
Definition: NonlinearEquality.h:171
friend class boost::serialization::access
Serialization function.
Definition: NonlinearEquality.h:333
virtual bool equals(const NonlinearFactor &f, double tol=1e-9) const
Check if two factors are equal.
Definition: NonlinearFactor.cpp:71
NonlinearEquality(Key j, const T &feasible, double error_gain, const CompareFunction &_compare=boost::bind(traits< T >::Equals, _1, _2, 1e-9))
Constructor - allows inexact evaluation.
Definition: NonlinearEquality.h:99
boost::shared_ptr< This > shared_ptr
shared_ptr to this class
Definition: GaussianFactor.h:42