gtsam
Loading...
Searching...
No Matches
LinearInequality.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
19
20#pragma once
21
22#include <gtsam/config.h>
23
24#ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V43
25
28
29namespace gtsam {
30
31typedef Eigen::RowVectorXd RowVector;
32
37class LinearInequality: public JacobianFactor {
38public:
39 typedef LinearInequality This;
40 typedef JacobianFactor Base;
41 typedef std::shared_ptr<This> shared_ptr;
42
43private:
44 Key dualKey_;
45 bool active_;
46
47public:
49 LinearInequality() :
50 Base(), active_(true) {
51 }
52
54 explicit LinearInequality(const HessianFactor& hf) {
55 throw std::runtime_error(
56 "Cannot convert HessianFactor to LinearInequality");
57 }
58
60 explicit LinearInequality(const JacobianFactor& jf, Key dualKey) :
61 Base(jf), dualKey_(dualKey), active_(true) {
62 if (!jf.isConstrained()) {
63 throw std::runtime_error(
64 "Cannot convert an unconstrained JacobianFactor to LinearInequality");
65 }
66
67 if (jf.get_model()->dim() != 1) {
68 throw std::runtime_error("Only support single-valued inequality factor!");
69 }
70 }
71
73 LinearInequality(Key i1, const RowVector& A1, double b, Key dualKey)
74 : Base(i1, A1, Vector{{b}}, noiseModel::Constrained::All(1)),
75 dualKey_(dualKey),
76 active_(true) {}
77
79 LinearInequality(Key i1, const RowVector& A1, Key i2, const RowVector& A2,
80 double b, Key dualKey)
81 : Base(i1, A1, i2, A2, Vector{{b}}, noiseModel::Constrained::All(1)),
82 dualKey_(dualKey),
83 active_(true) {}
84
86 LinearInequality(Key i1, const RowVector& A1, Key i2, const RowVector& A2,
87 Key i3, const RowVector& A3, double b, Key dualKey)
88 : Base(i1, A1, i2, A2, i3, A3, Vector{{b}},
89 noiseModel::Constrained::All(1)),
90 dualKey_(dualKey),
91 active_(true) {}
92
97 template <typename TERMS>
98 LinearInequality(const TERMS& terms, double b, Key dualKey)
99 : Base(terms, Vector{{b}}, noiseModel::Constrained::All(1)),
100 dualKey_(dualKey),
101 active_(true) {}
102
104 ~LinearInequality() override {
105 }
106
108 bool equals(const GaussianFactor& lf, double tol = 1e-9) const override {
109 return Base::equals(lf, tol);
110 }
111
113 void print(const std::string& s = "", const KeyFormatter& formatter =
114 DefaultKeyFormatter) const override {
115 if (active())
116 Base::print(s + " Active", formatter);
117 else
118 Base::print(s + " Inactive", formatter);
119 }
120
122 GaussianFactor::shared_ptr clone() const override {
123 return std::static_pointer_cast < GaussianFactor
124 > (std::make_shared < LinearInequality > (*this));
125 }
126
128 Key dualKey() const {
129 return dualKey_;
130 }
131
133 bool active() const {
134 return active_;
135 }
136
138 void activate() {
139 active_ = true;
140 }
141
143 void inactivate() {
144 active_ = false;
145 }
146
148 Vector error_vector(const VectorValues& c) const {
149 return unweighted_error(c);
150 }
151
153 double error(const VectorValues& c) const override {
154 return error_vector(c)[0];
155 }
156
158 double dotProductRow(const VectorValues& p) const {
159 double aTp = 0.0;
160 for (const_iterator xj = begin(); xj != end(); ++xj) {
161 Vector pj = p.at(*xj);
162 Vector aj = getA(xj).transpose();
163 aTp += aj.dot(pj);
164 }
165 return aTp;
166 }
167
168};
169// \ LinearInequality
170
172template<> struct traits<LinearInequality> : public Testable<LinearInequality> {
173};
174
175} // \ namespace gtsam
176
177#endif // GTSAM_ALLOW_DEPRECATED_SINCE_V43
Factor Graph Values.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition Matrix.cpp:143
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:43
A Gaussian factor in the squared-error form.
Definition JacobianFactor.h:92
static shared_ptr All(size_t dim)
Fully constrained variations.
Definition NoiseModel.h:512
The Factor::error simply extracts the.