22#include <gtsam/config.h>
24#ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V43
31typedef Eigen::RowVectorXd RowVector;
39 typedef LinearInequality This;
40 typedef JacobianFactor Base;
41 typedef std::shared_ptr<This> shared_ptr;
50 Base(), active_(true) {
54 explicit LinearInequality(
const HessianFactor& hf) {
55 throw std::runtime_error(
56 "Cannot convert HessianFactor to LinearInequality");
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");
67 if (jf.get_model()->dim() != 1) {
68 throw std::runtime_error(
"Only support single-valued inequality factor!");
73 LinearInequality(Key i1,
const RowVector& A1,
double b, Key dualKey)
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)),
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)),
97 template <
typename TERMS>
98 LinearInequality(
const TERMS& terms,
double b, Key dualKey)
99 : Base(terms, Vector{{b}}, noiseModel::Constrained::All(1)),
104 ~LinearInequality()
override {
108 bool equals(
const GaussianFactor& lf,
double tol = 1e-9)
const override {
109 return Base::equals(lf, tol);
113 void print(
const std::string& s =
"",
const KeyFormatter& formatter =
114 DefaultKeyFormatter)
const override {
116 Base::print(s +
" Active", formatter);
118 Base::print(s +
" Inactive", formatter);
122 GaussianFactor::shared_ptr clone()
const override {
123 return std::static_pointer_cast < GaussianFactor
124 > (std::make_shared < LinearInequality > (*
this));
128 Key dualKey()
const {
133 bool active()
const {
149 return unweighted_error(c);
154 return error_vector(c)[0];
160 for (const_iterator xj = begin(); xj != end(); ++xj) {
161 Vector pj = p.at(*xj);
162 Vector aj = getA(xj).transpose();
172template<>
struct traits<LinearInequality> :
public Testable<LinearInequality> {
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.