gtsam
Loading...
Searching...
No Matches
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
18
19#pragma once
20
21#include <gtsam/config.h>
22
23#ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V43
24
26
27namespace gtsam {
28
29typedef Eigen::RowVectorXd RowVector;
30
35class LinearCost: public JacobianFactor {
36public:
37 typedef LinearCost This;
38 typedef JacobianFactor Base;
39 typedef std::shared_ptr<This> shared_ptr;
40
41public:
43 LinearCost() :
44 Base() {
45 }
46
48 explicit LinearCost(const HessianFactor& hf) {
49 throw std::runtime_error("Cannot convert HessianFactor to LinearCost");
50 }
51
53 explicit LinearCost(const JacobianFactor& jf) :
54 Base(jf) {
55 if (jf.isConstrained()) {
56 throw std::runtime_error(
57 "Cannot convert a constrained JacobianFactor to LinearCost");
58 }
59
60 if (jf.get_model()->dim() != 1) {
61 throw std::runtime_error(
62 "Only support single-valued linear cost factor!");
63 }
64 }
65
67 LinearCost(Key i1, const RowVector& A1) :
68 Base(i1, A1, Vector1::Zero()) {
69 }
70
72 LinearCost(Key i1, const RowVector& A1, Key i2, const RowVector& A2, double b) :
73 Base(i1, A1, i2, A2, Vector1::Zero()) {
74 }
75
77 LinearCost(Key i1, const RowVector& A1, Key i2, const RowVector& A2, Key i3,
78 const RowVector& A3) :
79 Base(i1, A1, i2, A2, i3, A3, Vector1::Zero()) {
80 }
81
85 template<typename TERMS>
86 LinearCost(const TERMS& terms) :
87 Base(terms, Vector1::Zero()) {
88 }
89
91 ~LinearCost() override {
92 }
93
95 bool equals(const GaussianFactor& lf, double tol = 1e-9) const override {
96 return Base::equals(lf, tol);
97 }
98
100 void print(const std::string& s = "", const KeyFormatter& formatter =
101 DefaultKeyFormatter) const override {
102 Base::print(s + " LinearCost: ", formatter);
103 }
104
106 GaussianFactor::shared_ptr clone() const override {
107 return std::static_pointer_cast < GaussianFactor
108 > (std::make_shared < LinearCost > (*this));
109 }
110
112 Vector error_vector(const VectorValues& c) const {
113 return unweighted_error(c);
114 }
115
117 double error(const VectorValues& c) const override {
118 return error_vector(c)[0];
119 }
120};
121// \ LinearCost
122
124template<> struct traits<LinearCost> : public Testable<LinearCost> {
125};
126
127} // \ namespace gtsam
128
129#endif // GTSAM_ALLOW_DEPRECATED_SINCE_V43
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
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition Group.h:37
A helper that implements the traits interface for GTSAM types.
Definition Testable.h:152
A Gaussian factor in the squared-error form.
Definition JacobianFactor.h:92