Factor.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 
20 // \callgraph
21 
22 #pragma once
23 
24 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
25 #include <boost/serialization/nvp.hpp>
26 #endif
27 #include <gtsam/base/FastVector.h>
28 #include <gtsam/base/types.h>
29 #include <gtsam/inference/Key.h>
30 
31 #include <algorithm>
32 #include <memory>
33 
34 namespace gtsam {
35 
39 
40  class HybridValues; // forward declaration of a Value type for error.
41 
70  class GTSAM_EXPORT Factor
71  {
72 
73  private:
74  // These typedefs are private because they must be overridden in derived classes.
75  typedef Factor This;
76  typedef std::shared_ptr<Factor> shared_ptr;
77 
78  public:
80  typedef KeyVector::iterator iterator;
81 
83  typedef KeyVector::const_iterator const_iterator;
84 
85  protected:
86 
89 
92 
94  Factor() {}
95 
98  template<typename CONTAINER>
99  explicit Factor(const CONTAINER& keys) : keys_(keys.begin(), keys.end()) {}
100 
103  template<typename ITERATOR>
104  Factor(ITERATOR first, ITERATOR last) : keys_(first, last) {}
105 
108  template<typename CONTAINER>
109  static Factor FromKeys(const CONTAINER& keys) {
110  return Factor(keys.begin(), keys.end()); }
111 
114  template<typename ITERATOR>
115  static Factor FromIterators(ITERATOR first, ITERATOR last) {
116  return Factor(first, last); }
117 
119 
120  public:
122  // public since it is required for boost serialization and static methods.
123  // virtual since it is public.
124  // http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-dtor-virtual
125  virtual ~Factor() = default;
126 
129 
131  bool empty() const { return keys_.empty(); }
132 
134  Key front() const { return keys_.front(); }
135 
137  Key back() const { return keys_.back(); }
138 
140  const_iterator find(Key key) const { return std::find(begin(), end(), key); }
141 
143  const KeyVector& keys() const { return keys_; }
144 
146  const_iterator begin() const { return keys_.begin(); }
147 
149  const_iterator end() const { return keys_.end(); }
150 
155  virtual double error(const HybridValues& c) const;
156 
160  size_t size() const { return keys_.size(); }
161 
163 
166 
168  virtual void print(
169  const std::string& s = "Factor",
171 
173  virtual void printKeys(
174  const std::string& s = "Factor",
176 
178  bool equals(const This& other, double tol = 1e-9) const;
179 
183 
185  KeyVector& keys() { return keys_; }
186 
188  iterator begin() { return keys_.begin(); }
189 
191  iterator end() { return keys_.end(); }
192 
194 
195  private:
196 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
197 
200  friend class boost::serialization::access;
201  template<class Archive>
202  void serialize(Archive & ar, const unsigned int /*version*/) {
203  ar & BOOST_SERIALIZATION_NVP(keys_);
204  }
205 #endif
206 
208 
209  };
210 
211 } // \namespace gtsam
gtsam::Factor::FromIterators
static Factor FromIterators(ITERATOR first, ITERATOR last)
Definition: Factor.h:115
gtsam::HybridValues
Definition: HybridValues.h:37
gtsam::Factor::keys
KeyVector & keys()
Definition: Factor.h:185
FastVector.h
A thin wrapper around std::vector that uses a custom allocator.
s
RealScalar s
Definition: level1_cplx_impl.h:126
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
types.h
Typedefs for easier changing of types.
keys
const KeyVector keys
Definition: testRegularImplicitSchurFactor.cpp:40
gtsam::Factor::begin
iterator begin()
Definition: Factor.h:188
c
Scalar Scalar * c
Definition: benchVecAdd.cpp:17
gtsam::FastVector
std::vector< T, typename internal::FastDefaultVectorAllocator< T >::type > FastVector
Definition: FastVector.h:34
gtsam::Factor::end
iterator end()
Definition: Factor.h:191
gtsam::Factor::find
const_iterator find(Key key) const
find
Definition: Factor.h:140
formatter
const KeyFormatter & formatter
Definition: treeTraversal-inst.h:204
gtsam::Factor::empty
bool empty() const
Whether the factor is empty (involves zero variables).
Definition: Factor.h:131
gtsam::Factor::back
Key back() const
Last key.
Definition: Factor.h:137
gtsam::Factor
Definition: Factor.h:70
gtsam::FastSet
Definition: FastSet.h:51
iterator
Definition: pytypes.h:1460
gtsam::Factor::begin
const_iterator begin() const
Definition: Factor.h:146
Eigen::last
static const symbolic::SymbolExpr< internal::symbolic_last_tag > last
Definition: IndexedViewHelper.h:38
gtsam::Factor::shared_ptr
std::shared_ptr< Factor > shared_ptr
A shared_ptr to this class.
Definition: Factor.h:76
gtsam::KeyVector
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition: Key.h:92
gtsam::DefaultKeyFormatter
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition: Key.cpp:30
Key.h
gtsam::Factor::This
Factor This
This class.
Definition: Factor.h:75
gtsam::print
void print(const Matrix &A, const string &s, ostream &stream)
Definition: Matrix.cpp:155
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::Factor::iterator
KeyVector::iterator iterator
Iterator over keys.
Definition: Factor.h:80
gtsam::Factor::end
const_iterator end() const
Definition: Factor.h:149
gtsam::equals
Definition: Testable.h:112
gtsam::Factor::FromKeys
static Factor FromKeys(const CONTAINER &keys)
Definition: Factor.h:109
key
const gtsam::Symbol key('X', 0)
gtsam::Factor::const_iterator
KeyVector::const_iterator const_iterator
Const iterator over keys.
Definition: Factor.h:83
gtsam
traits
Definition: SFMdata.h:40
gtsam::Factor::keys_
KeyVector keys_
The keys involved in this factor.
Definition: Factor.h:88
gtsam::Factor::front
Key front() const
First key.
Definition: Factor.h:134
error
static double error
Definition: testRot3.cpp:37
gtsam::FactorIndexSet
FastSet< FactorIndex > FactorIndexSet
Definition: Factor.h:38
gtsam::Factor::keys
const KeyVector & keys() const
Access the factor's involved variable keys.
Definition: Factor.h:143
gtsam::Factor::Factor
Factor(ITERATOR first, ITERATOR last)
Definition: Factor.h:104
This
#define This
Definition: ActiveSetSolver-inl.h:27
gtsam::Factor::Factor
Factor(const CONTAINER &keys)
Definition: Factor.h:99
gtsam::tol
const G double tol
Definition: Group.h:79
gtsam::Factor::Factor
Factor()
Definition: Factor.h:94
Eigen::placeholders::end
static const EIGEN_DEPRECATED end_t end
Definition: IndexedViewHelper.h:181
gtsam::Factor::size
size_t size() const
Definition: Factor.h:160
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:97
pybind_wrapper_test_script.other
other
Definition: pybind_wrapper_test_script.py:42
gtsam::FactorIndices
FastVector< FactorIndex > FactorIndices
Define collection types:
Definition: Factor.h:37


gtsam
Author(s):
autogenerated on Fri Nov 1 2024 03:32:31