24#include <gtsam/dllexport.h>
43 typedef std::shared_ptr<VariableIndex> shared_ptr;
44 typedef FactorIndices::iterator Factor_iterator;
45 typedef FactorIndices::const_iterator Factor_const_iterator;
54 typedef KeyMap::const_iterator const_iterator;
55 typedef KeyMap::const_iterator iterator;
56 typedef KeyMap::value_type value_type;
69 explicit VariableIndex(
const FG& factorGraph) : nFactors_(0), nEntries_(0) {
78 size_t size()
const {
return index_.size(); }
92 bool empty(
Key variable)
const;
102 void print(
const std::string& str =
"VariableIndex: ",
109 void outputMetisFormat(std::ostream& os)
const;
121 void augment(
const FG& factors,
const FactorIndices* newFactorIndices =
nullptr);
129 augment(factor, &newFactorIndices);
137 void augmentExistingFactor(
const FactorIndex factorIndex,
const KeySet & newKeys);
149 template<
typename ITERATOR,
class FG>
150 void remove(ITERATOR firstFactor, ITERATOR lastFactor,
const FG& factors);
153 template<
typename ITERATOR>
154 void removeUnusedVariables(ITERATOR firstKey, ITERATOR lastKey);
157 const_iterator
begin()
const {
return index_.begin(); }
160 const_iterator
end()
const {
return index_.end(); }
163 const_iterator
find(
Key key)
const {
return index_.find(key); }
166 Factor_iterator factorsBegin(
Key variable) {
return internalAt(variable).begin(); }
167 Factor_iterator factorsEnd(Key variable) {
return internalAt(variable).end(); }
169 Factor_const_iterator factorsBegin(Key variable)
const {
return internalAt(variable).begin(); }
170 Factor_const_iterator factorsEnd(Key variable)
const {
return internalAt(variable).end(); }
174 const KeyMap::const_iterator item = index_.find(variable);
175 assert(item != index_.end());
181 const KeyMap::iterator item = index_.find(variable);
182 assert(item != index_.end());
187#if GTSAM_ENABLE_BOOST_SERIALIZATION
189 friend class boost::serialization::access;
190 template<
class ARCHIVE>
191 void serialize(ARCHIVE & ar,
const unsigned int ) {
192 ar & BOOST_SERIALIZATION_NVP(index_);
193 ar & BOOST_SERIALIZATION_NVP(nFactors_);
194 ar & BOOST_SERIALIZATION_NVP(nEntries_);
A thin wrapper around std::vector that uses a custom allocator.
A thin wrapper around std::map that uses boost's fast_pool_allocator.
The base class for all factors.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition Key.cpp:30
std::uint64_t FactorIndex
Integer nonlinear factor index type.
Definition types.h:46
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition Matrix.cpp:143
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
FastVector< FactorIndex > FactorIndices
Define collection types:
Definition Factor.h:37
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:43
FastMap is a thin wrapper around std::map that uses the boost fast_pool_allocator instead of the defa...
Definition FastMap.h:40
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition Group.h:37
Template to create a binary predicate.
Definition Testable.h:112
A helper that implements the traits interface for GTSAM types.
Definition Testable.h:152
The VariableIndex class computes and stores the block column structure of a factor graph.
Definition VariableIndex.h:41
const FactorIndices & internalAt(Key variable) const
Internal version of 'at' that asserts existence.
Definition VariableIndex.h:173
size_t nEntries() const
The number of nonzero blocks, i.e. the number of variable-factor entries.
Definition VariableIndex.h:84
const_iterator begin() const
Iterator to the first variable entry.
Definition VariableIndex.h:157
const_iterator find(Key key) const
Find the iterator for the requested variable entry.
Definition VariableIndex.h:163
VariableIndex(const FG &factorGraph)
Create a VariableIndex that computes and stores the block column structure of a factor graph.
Definition VariableIndex.h:69
size_t size() const
The number of variable entries. This is equal to the number of unique variable Keys.
Definition VariableIndex.h:78
FactorIndices & internalAt(Key variable)
Internal version of 'at' that asserts existence.
Definition VariableIndex.h:180
const_iterator end() const
Iterator to the first variable entry.
Definition VariableIndex.h:160
void augment(const FG &factor, const FactorIndices &newFactorIndices)
An overload of augment() that takes a single factor.
Definition VariableIndex.h:128
void augment(const FG &factors, const FactorIndices *newFactorIndices=nullptr)
Augment the variable index with new factors.
Definition VariableIndex-inl.h:27
VariableIndex()
Default constructor, creates an empty VariableIndex.
Definition VariableIndex.h:62
size_t nFactors() const
The number of factors in the original factor graph.
Definition VariableIndex.h:81