gtsam 4.2.0
gtsam
Loading...
Searching...
No Matches
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#include <boost/serialization/nvp.hpp>
25#include <boost/shared_ptr.hpp>
26
27#include <gtsam/base/types.h>
29#include <gtsam/inference/Key.h>
30
31namespace gtsam {
32
35 typedef FastSet<FactorIndex> FactorIndexSet;
36
37 class HybridValues; // forward declaration of a Value type for error.
38
67 class GTSAM_EXPORT Factor
68 {
69
70 private:
71 // These typedefs are private because they must be overridden in derived classes.
72 typedef Factor This;
73 typedef boost::shared_ptr<Factor> shared_ptr;
74
75 public:
77 typedef KeyVector::iterator iterator;
78
80 typedef KeyVector::const_iterator const_iterator;
81
82 protected:
83
86
89
91 Factor() {}
92
95 template<typename CONTAINER>
96 explicit Factor(const CONTAINER& keys) : keys_(keys.begin(), keys.end()) {}
97
100 template<typename ITERATOR>
101 Factor(ITERATOR first, ITERATOR last) : keys_(first, last) {}
102
105 template<typename CONTAINER>
106 static Factor FromKeys(const CONTAINER& keys) {
107 return Factor(keys.begin(), keys.end()); }
108
111 template<typename ITERATOR>
112 static Factor FromIterators(ITERATOR first, ITERATOR last) {
113 return Factor(first, last); }
114
116
117 public:
119 // public since it is required for boost serialization and static methods.
120 // virtual since it is public.
121 // http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-dtor-virtual
122 virtual ~Factor() = default;
123
126
128 bool empty() const { return keys_.empty(); }
129
131 Key front() const { return keys_.front(); }
132
134 Key back() const { return keys_.back(); }
135
137 const_iterator find(Key key) const { return std::find(begin(), end(), key); }
138
140 const KeyVector& keys() const { return keys_; }
141
143 const_iterator begin() const { return keys_.begin(); }
144
146 const_iterator end() const { return keys_.end(); }
147
152 virtual double error(const HybridValues& c) const;
153
157 size_t size() const { return keys_.size(); }
158
160
163
165 virtual void print(
166 const std::string& s = "Factor",
167 const KeyFormatter& formatter = DefaultKeyFormatter) const;
168
170 virtual void printKeys(
171 const std::string& s = "Factor",
172 const KeyFormatter& formatter = DefaultKeyFormatter) const;
173
175 bool equals(const This& other, double tol = 1e-9) const;
176
180
182 KeyVector& keys() { return keys_; }
183
185 iterator begin() { return keys_.begin(); }
186
188 iterator end() { return keys_.end(); }
189
191
192 private:
193
196
198 friend class boost::serialization::access;
199 template<class Archive>
200 void serialize(Archive & ar, const unsigned int /*version*/) {
201 ar & BOOST_SERIALIZATION_NVP(keys_);
202 }
203
205
206 };
207
208} // \namespace gtsam
A thin wrapper around std::vector that uses a custom allocator.
Typedefs for easier changing of types.
std::vector< T, typename internal::FastDefaultVectorAllocator< T >::type > FastVector
FastVector is a type alias to a std::vector with a custom memory allocator.
Definition FastVector.h:34
Global functions in a separate testing namespace.
Definition chartTesting.h:28
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition Key.h:86
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition Matrix.cpp:156
FastVector< FactorIndex > FactorIndices
Define collection types:
Definition Factor.h:34
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:100
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
FastSet is a thin wrapper around std::set that uses the boost fast_pool_allocator instead of the defa...
Definition FastSet.h:50
Template to create a binary predicate.
Definition Testable.h:111
HybridValues represents a collection of DiscreteValues and VectorValues.
Definition HybridValues.h:38
Definition Factor.h:68
const KeyVector & keys() const
Access the factor's involved variable keys.
Definition Factor.h:140
KeyVector keys_
The keys involved in this factor.
Definition Factor.h:85
const_iterator find(Key key) const
find
Definition Factor.h:137
const_iterator begin() const
Iterator at beginning of involved variable keys.
Definition Factor.h:143
Factor()
Default constructor for I/O.
Definition Factor.h:91
iterator end()
Iterator at end of involved variable keys.
Definition Factor.h:188
bool empty() const
Whether the factor is empty (involves zero variables).
Definition Factor.h:128
KeyVector & keys()
Definition Factor.h:182
static Factor FromIterators(ITERATOR first, ITERATOR last)
Construct factor from iterator keys.
Definition Factor.h:112
static Factor FromKeys(const CONTAINER &keys)
Construct factor from container of keys.
Definition Factor.h:106
iterator begin()
Iterator at beginning of involved variable keys.
Definition Factor.h:185
virtual ~Factor()=default
Default destructor.
Factor(ITERATOR first, ITERATOR last)
Construct factor from iterator keys.
Definition Factor.h:101
KeyVector::const_iterator const_iterator
Const iterator over keys.
Definition Factor.h:80
const_iterator end() const
Iterator at end of involved variable keys.
Definition Factor.h:146
Factor(const CONTAINER &keys)
Construct factor from container of keys.
Definition Factor.h:96
KeyVector::iterator iterator
Iterator over keys.
Definition Factor.h:77
Key back() const
Last key.
Definition Factor.h:134
Key front() const
First key.
Definition Factor.h:131
size_t size() const
Definition Factor.h:157