24#include <gtsam/dllexport.h>
26#include <boost/optional/optional.hpp>
27#include <boost/smart_ptr/shared_ptr.hpp>
45 typedef boost::shared_ptr<VariableIndex> shared_ptr;
46 typedef FactorIndices::iterator Factor_iterator;
47 typedef FactorIndices::const_iterator Factor_const_iterator;
56 typedef KeyMap::const_iterator const_iterator;
57 typedef KeyMap::const_iterator iterator;
58 typedef KeyMap::value_type value_type;
71 explicit VariableIndex(
const FG& factorGraph) : nFactors_(0), nEntries_(0) {
80 size_t size()
const {
return index_.size(); }
90 KeyMap::const_iterator item = index_.find(variable);
91 if(item == index_.end())
92 throw std::invalid_argument(
"Requested non-existent variable from VariableIndex");
99 return (*
this)[variable].empty();
110 void print(
const std::string& str =
"VariableIndex: ",
111 const KeyFormatter& keyFormatter = DefaultKeyFormatter)
const;
117 void outputMetisFormat(std::ostream& os)
const;
129 void augment(
const FG& factors, boost::optional<const FactorIndices&> newFactorIndices = boost::none);
136 void augmentExistingFactor(
const FactorIndex factorIndex,
const KeySet & newKeys);
148 template<
typename ITERATOR,
class FG>
149 void remove(ITERATOR firstFactor, ITERATOR lastFactor,
const FG& factors);
152 template<
typename ITERATOR>
153 void removeUnusedVariables(ITERATOR firstKey, ITERATOR lastKey);
156 const_iterator
begin()
const {
return index_.begin(); }
159 const_iterator
end()
const {
return index_.end(); }
162 const_iterator
find(
Key key)
const {
return index_.find(key); }
165 Factor_iterator factorsBegin(
Key variable) {
return internalAt(variable).begin(); }
166 Factor_iterator factorsEnd(
Key variable) {
return internalAt(variable).end(); }
168 Factor_const_iterator factorsBegin(
Key variable)
const {
return internalAt(variable).begin(); }
169 Factor_const_iterator factorsEnd(
Key variable)
const {
return internalAt(variable).end(); }
173 const KeyMap::const_iterator item = index_.find(variable);
174 assert(item != index_.end());
180 const KeyMap::iterator item = index_.find(variable);
181 assert(item != index_.end());
187 friend class boost::serialization::access;
188 template<
class ARCHIVE>
189 void serialize(ARCHIVE & ar,
const unsigned int ) {
190 ar & BOOST_SERIALIZATION_NVP(index_);
191 ar & BOOST_SERIALIZATION_NVP(nFactors_);
192 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
std::uint64_t FactorIndex
Integer nonlinear factor index type.
Definition: types.h:72
std::string serialize(const T &input)
serializes to a string
Definition: serialization.h:112
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition: Matrix.cpp:155
FastVector< FactorIndex > FactorIndices
Define collection types:
Definition: Factor.h:33
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:69
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
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition: concepts.h:30
Template to create a binary predicate.
Definition: Testable.h:111
A helper that implements the traits interface for GTSAM types.
Definition: Testable.h:151
The VariableIndex class computes and stores the block column structure of a factor graph.
Definition: VariableIndex.h:43
const FactorIndices & internalAt(Key variable) const
Internal version of 'at' that asserts existence.
Definition: VariableIndex.h:172
size_t nEntries() const
The number of nonzero blocks, i.e. the number of variable-factor entries.
Definition: VariableIndex.h:86
const_iterator begin() const
Iterator to the first variable entry.
Definition: VariableIndex.h:156
const_iterator find(Key key) const
Find the iterator for the requested variable entry.
Definition: VariableIndex.h:162
const FactorIndices & operator[](Key variable) const
Access a list of factors by variable.
Definition: VariableIndex.h:89
VariableIndex(const FG &factorGraph)
Create a VariableIndex that computes and stores the block column structure of a factor graph.
Definition: VariableIndex.h:71
bool empty(Key variable) const
Return true if no factors associated with a variable.
Definition: VariableIndex.h:98
size_t size() const
The number of variable entries. This is equal to the number of unique variable Keys.
Definition: VariableIndex.h:80
FactorIndices & internalAt(Key variable)
Internal version of 'at' that asserts existence.
Definition: VariableIndex.h:179
const_iterator end() const
Iterator to the first variable entry.
Definition: VariableIndex.h:159
VariableIndex()
Default constructor, creates an empty VariableIndex.
Definition: VariableIndex.h:64
size_t nFactors() const
The number of factors in the original factor graph.
Definition: VariableIndex.h:83