LinearCost.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 #pragma once
20 
22 
23 namespace gtsam {
24 
25 typedef Eigen::RowVectorXd RowVector;
26 
31 class LinearCost: public JacobianFactor {
32 public:
33  typedef LinearCost This;
34  typedef JacobianFactor Base;
35  typedef std::shared_ptr<This> shared_ptr;
36 
37 public:
40  Base() {
41  }
42 
44  explicit LinearCost(const HessianFactor& hf) {
45  throw std::runtime_error("Cannot convert HessianFactor to LinearCost");
46  }
47 
49  explicit LinearCost(const JacobianFactor& jf) :
50  Base(jf) {
51  if (jf.isConstrained()) {
52  throw std::runtime_error(
53  "Cannot convert a constrained JacobianFactor to LinearCost");
54  }
55 
56  if (jf.get_model()->dim() != 1) {
57  throw std::runtime_error(
58  "Only support single-valued linear cost factor!");
59  }
60  }
61 
64  Base(i1, A1, Vector1::Zero()) {
65  }
66 
68  LinearCost(Key i1, const RowVector& A1, Key i2, const RowVector& A2, double b) :
69  Base(i1, A1, i2, A2, Vector1::Zero()) {
70  }
71 
73  LinearCost(Key i1, const RowVector& A1, Key i2, const RowVector& A2, Key i3,
74  const RowVector& A3) :
75  Base(i1, A1, i2, A2, i3, A3, Vector1::Zero()) {
76  }
77 
81  template<typename TERMS>
82  LinearCost(const TERMS& terms) :
83  Base(terms, Vector1::Zero()) {
84  }
85 
87  ~LinearCost() override {
88  }
89 
91  bool equals(const GaussianFactor& lf, double tol = 1e-9) const override {
92  return Base::equals(lf, tol);
93  }
94 
96  void print(const std::string& s = "", const KeyFormatter& formatter =
97  DefaultKeyFormatter) const override {
98  Base::print(s + " LinearCost: ", formatter);
99  }
100 
103  return std::static_pointer_cast < GaussianFactor
104  > (std::make_shared < LinearCost > (*this));
105  }
106 
109  return unweighted_error(c);
110  }
111 
113  double error(const VectorValues& c) const override {
114  return error_vector(c)[0];
115  }
116 };
117 // \ LinearCost
118 
120 template<> struct traits<LinearCost> : public Testable<LinearCost> {
121 };
122 
123 } // \ namespace gtsam
124 
gtsam::JacobianFactor::unweighted_error
Vector unweighted_error(const VectorValues &c) const
Definition: JacobianFactor.cpp:472
A3
static const double A3[]
Definition: expn.h:8
gtsam::HessianFactor
A Gaussian factor using the canonical parameters (information form)
Definition: HessianFactor.h:99
s
RealScalar s
Definition: level1_cplx_impl.h:126
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
gtsam::JacobianFactor::get_model
const SharedDiagonal & get_model() const
Definition: JacobianFactor.h:292
gtsam::RowVector
Eigen::RowVectorXd RowVector
Definition: LinearCost.h:25
c
Scalar Scalar * c
Definition: benchVecAdd.cpp:17
gtsam::LinearCost::equals
bool equals(const GaussianFactor &lf, double tol=1e-9) const override
Definition: LinearCost.h:91
gtsam::JacobianFactor::isConstrained
bool isConstrained() const
Definition: JacobianFactor.h:270
gtsam::JacobianFactor
Definition: JacobianFactor.h:91
gtsam::GaussianFactor
Definition: GaussianFactor.h:38
formatter
const KeyFormatter & formatter
Definition: treeTraversal-inst.h:204
gtsam::LinearCost::~LinearCost
~LinearCost() override
Definition: LinearCost.h:87
gtsam::LinearCost::shared_ptr
std::shared_ptr< This > shared_ptr
shared_ptr to this class
Definition: LinearCost.h:35
gtsam::Factor
Definition: Factor.h:70
gtsam::Vector
Eigen::VectorXd Vector
Definition: Vector.h:39
gtsam::LinearCost::error
double error(const VectorValues &c) const override
Definition: LinearCost.h:113
gtsam::DefaultKeyFormatter
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition: Key.cpp:30
gtsam::LinearCost::Base
JacobianFactor Base
Typedef to base class.
Definition: LinearCost.h:34
gtsam::LinearCost::error_vector
Vector error_vector(const VectorValues &c) const
Definition: LinearCost.h:108
gtsam::VectorValues
Definition: VectorValues.h:74
gtsam::LinearCost::LinearCost
LinearCost(Key i1, const RowVector &A1, Key i2, const RowVector &A2, Key i3, const RowVector &A3)
Definition: LinearCost.h:73
gtsam::LinearCost
Definition: LinearCost.h:31
gtsam::KeyFormatter
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition: Key.h:35
gtsam::GaussianFactor::shared_ptr
std::shared_ptr< This > shared_ptr
shared_ptr to this class
Definition: GaussianFactor.h:42
gtsam::LinearCost::LinearCost
LinearCost(Key i1, const RowVector &A1, Key i2, const RowVector &A2, double b)
Definition: LinearCost.h:68
A2
static const double A2[]
Definition: expn.h:7
gtsam::LinearCost::LinearCost
LinearCost()
Definition: LinearCost.h:39
gtsam::LinearCost::print
void print(const std::string &s="", const KeyFormatter &formatter=DefaultKeyFormatter) const override
Definition: LinearCost.h:96
JacobianFactor.h
gtsam::b
const G & b
Definition: Group.h:79
gtsam
traits
Definition: SFMdata.h:40
gtsam::Testable
Definition: Testable.h:152
gtsam::traits
Definition: Group.h:36
i1
double i1(double x)
Definition: i1.c:150
gtsam::JacobianFactor::equals
bool equals(const GaussianFactor &lf, double tol=1e-9) const override
assert equality up to a tolerance
Definition: JacobianFactor.cpp:421
A1
static const double A1[]
Definition: expn.h:6
gtsam::JacobianFactor::print
void print(const std::string &s="", const KeyFormatter &formatter=DefaultKeyFormatter) const override
print with optional string
Definition: JacobianFactor.cpp:404
gtsam::tol
const G double tol
Definition: Group.h:79
gtsam::LinearCost::LinearCost
LinearCost(const JacobianFactor &jf)
Definition: LinearCost.h:49
Eigen::Matrix
The matrix class, also used for vectors and row-vectors.
Definition: 3rdparty/Eigen/Eigen/src/Core/Matrix.h:178
gtsam::LinearCost::This
LinearCost This
Typedef to this class.
Definition: LinearCost.h:33
gtsam::LinearCost::LinearCost
LinearCost(const TERMS &terms)
Definition: LinearCost.h:82
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:97
gtsam::LinearCost::LinearCost
LinearCost(Key i1, const RowVector &A1)
Definition: LinearCost.h:63
gtsam::LinearCost::LinearCost
LinearCost(const HessianFactor &hf)
Definition: LinearCost.h:44
gtsam::LinearCost::clone
GaussianFactor::shared_ptr clone() const override
Definition: LinearCost.h:102


gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:11:55