21#include <gtsam/config.h>
23#ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V43
29typedef Eigen::RowVectorXd RowVector;
37 typedef LinearCost This;
38 typedef JacobianFactor Base;
39 typedef std::shared_ptr<This> shared_ptr;
48 explicit LinearCost(
const HessianFactor& hf) {
49 throw std::runtime_error(
"Cannot convert HessianFactor to LinearCost");
53 explicit LinearCost(
const JacobianFactor& jf) :
55 if (jf.isConstrained()) {
56 throw std::runtime_error(
57 "Cannot convert a constrained JacobianFactor to LinearCost");
60 if (jf.get_model()->dim() != 1) {
61 throw std::runtime_error(
62 "Only support single-valued linear cost factor!");
67 LinearCost(Key i1,
const RowVector& A1) :
68 Base(i1, A1, Vector1::Zero()) {
72 LinearCost(Key i1,
const RowVector& A1, Key i2,
const RowVector& A2,
double b) :
73 Base(i1, A1, i2, A2, Vector1::Zero()) {
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()) {
85 template<
typename TERMS>
86 LinearCost(
const TERMS& terms) :
87 Base(terms, Vector1::Zero()) {
91 ~LinearCost()
override {
95 bool equals(
const GaussianFactor& lf,
double tol = 1e-9)
const override {
96 return Base::equals(lf, tol);
100 void print(
const std::string& s =
"",
const KeyFormatter& formatter =
101 DefaultKeyFormatter)
const override {
102 Base::print(s +
" LinearCost: ", formatter);
106 GaussianFactor::shared_ptr clone()
const override {
107 return std::static_pointer_cast < GaussianFactor
108 > (std::make_shared < LinearCost > (*
this));
112 Vector error_vector(
const VectorValues& c)
const {
113 return unweighted_error(c);
117 double error(
const VectorValues& c)
const override {
118 return error_vector(c)[0];
124template<>
struct traits<LinearCost> :
public Testable<LinearCost> {
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