BoundingConstraint.h
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
18 #pragma once
19 
20 #include <gtsam/base/Lie.h>
22 
23 namespace gtsam {
24 
32 template<class VALUE>
33 struct BoundingConstraint1: public NoiseModelFactor1<VALUE> {
34  typedef VALUE X;
36  typedef boost::shared_ptr<BoundingConstraint1<VALUE> > shared_ptr;
37 
38  double threshold_;
40 
42  bool isGreaterThan, double mu = 1000.0) :
43  Base(noiseModel::Constrained::All(1, mu), key),
44  threshold_(threshold), isGreaterThan_(isGreaterThan) {
45  }
46 
47  ~BoundingConstraint1() override {}
48 
49  inline double threshold() const { return threshold_; }
50  inline bool isGreaterThan() const { return isGreaterThan_; }
51 
57  virtual double value(const X& x, boost::optional<Matrix&> H =
58  boost::none) const = 0;
59 
61  bool active(const Values& c) const override {
62  // note: still active at equality to avoid zigzagging
63  double x = value(c.at<X>(this->key()));
64  return (isGreaterThan_) ? x <= threshold_ : x >= threshold_;
65  }
66 
67  Vector evaluateError(const X& x, boost::optional<Matrix&> H =
68  boost::none) const override {
69  Matrix D;
70  double error = value(x, D) - threshold_;
71  if (H) {
72  if (isGreaterThan_) *H = D;
73  else *H = -1.0 * D;
74  }
75 
76  if (isGreaterThan_)
77  return (Vector(1) << error).finished();
78  else
79  return -1.0 * (Vector(1) << error).finished();
80  }
81 
82 private:
83 
86  template<class ARCHIVE>
87  void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
88  ar & boost::serialization::make_nvp("NoiseModelFactor1",
89  boost::serialization::base_object<Base>(*this));
90  ar & BOOST_SERIALIZATION_NVP(threshold_);
91  ar & BOOST_SERIALIZATION_NVP(isGreaterThan_);
92  }
93 };
94 
99 template<class VALUE1, class VALUE2>
100 struct BoundingConstraint2: public NoiseModelFactor2<VALUE1, VALUE2> {
101  typedef VALUE1 X1;
102  typedef VALUE2 X2;
103 
105  typedef boost::shared_ptr<BoundingConstraint2<VALUE1, VALUE2> > shared_ptr;
106 
107  double threshold_;
109 
111  bool isGreaterThan, double mu = 1000.0)
112  : Base(noiseModel::Constrained::All(1, mu), key1, key2),
113  threshold_(threshold), isGreaterThan_(isGreaterThan) {}
114 
115  ~BoundingConstraint2() override {}
116 
117  inline double threshold() const { return threshold_; }
118  inline bool isGreaterThan() const { return isGreaterThan_; }
119 
124  virtual double value(const X1& x1, const X2& x2,
125  boost::optional<Matrix&> H1 = boost::none,
126  boost::optional<Matrix&> H2 = boost::none) const = 0;
127 
129  bool active(const Values& c) const override {
130  // note: still active at equality to avoid zigzagging
131  double x = value(c.at<X1>(this->key1()), c.at<X2>(this->key2()));
132  return (isGreaterThan_) ? x <= threshold_ : x >= threshold_;
133  }
134 
135  Vector evaluateError(const X1& x1, const X2& x2,
136  boost::optional<Matrix&> H1 = boost::none,
137  boost::optional<Matrix&> H2 = boost::none) const override {
138  Matrix D1, D2;
139  double error = value(x1, x2, D1, D2) - threshold_;
140  if (H1) {
141  if (isGreaterThan_) *H1 = D1;
142  else *H1 = -1.0 * D1;
143  }
144  if (H2) {
145  if (isGreaterThan_) *H2 = D2;
146  else *H2 = -1.0 * D2;
147  }
148 
149  if (isGreaterThan_)
150  return (Vector(1) << error).finished();
151  else
152  return -1.0 * (Vector(1) << error).finished();
153  }
154 
155 private:
156 
158  friend class boost::serialization::access;
159  template<class ARCHIVE>
160  void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
161  ar & boost::serialization::make_nvp("NoiseModelFactor2",
162  boost::serialization::base_object<Base>(*this));
163  ar & BOOST_SERIALIZATION_NVP(threshold_);
164  ar & BOOST_SERIALIZATION_NVP(isGreaterThan_);
165  }
166 };
167 
168 } // \namespace gtsam
double error(const Values &c) const override
boost::shared_ptr< BoundingConstraint1< VALUE > > shared_ptr
friend class boost::serialization::access
BoundingConstraint1(Key key, double threshold, bool isGreaterThan, double mu=1000.0)
flag for greater/less than
double mu
Eigen::MatrixXd Matrix
Definition: base/Matrix.h:43
Scalar Scalar * c
Definition: benchVecAdd.cpp:17
NoiseModelFactor2< VALUE1, VALUE2 > Base
void serialize(ARCHIVE &ar, const unsigned int)
Pose3 x2(Rot3::Ypr(0.0, 0.0, 0.0), l2)
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set set set set surface set nocontour set clabel set mapping cartesian set nohidden3d set cntrparam order set cntrparam linear set cntrparam levels auto set cntrparam points set size set set xzeroaxis lt lw set x2zeroaxis lt lw set yzeroaxis lt lw set y2zeroaxis lt lw set tics in set ticslevel set tics set mxtics default set mytics default set mx2tics default set my2tics default set xtics border mirror norotate autofreq set ytics border mirror norotate autofreq set ztics border nomirror norotate autofreq set nox2tics set noy2tics set timestamp bottom norotate set rrange[*:*] noreverse nowriteback set trange[*:*] noreverse nowriteback set urange[*:*] noreverse nowriteback set vrange[*:*] noreverse nowriteback set xlabel matrix size set x2label set timefmt d m y n H
bool active(const Values &c) const override
const SharedNoiseModel & noiseModel() const
access to the noise model
NoiseModelFactor1< VALUE > Base
const Symbol key1('v', 1)
boost::shared_ptr< BoundingConstraint2< VALUE1, VALUE2 > > shared_ptr
Eigen::VectorXd Vector
Definition: Vector.h:38
const ValueType at(Key j) const
Definition: Values-inl.h:342
Vector evaluateError(const X &x, boost::optional< Matrix & > H=boost::none) const override
Base class and basic functions for Lie types.
BoundingConstraint2(Key key1, Key key2, double threshold, bool isGreaterThan, double mu=1000.0)
flag for greater/less than
traits
Definition: chartTesting.h:28
Vector evaluateError(const X1 &x1, const X2 &x2, boost::optional< Matrix & > H1=boost::none, boost::optional< Matrix & > H2=boost::none) const override
Non-linear factor base classes.
Pose3 x1
Definition: testPose3.cpp:588
const Symbol key2('v', 2)
void serialize(ARCHIVE &ar, const unsigned int)
bool active(const Values &c) const override
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:61
virtual double value(const X &x, boost::optional< Matrix & > H=boost::none) const =0


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:41:43