24 #include <gtsam/dllexport.h> 69 explicit VariableIndex(
const FG& factorGraph) : nFactors_(0), nEntries_(0) {
78 size_t size()
const {
return index_.size(); }
88 KeyMap::const_iterator item = index_.find(variable);
89 if(item == index_.end())
90 throw std::invalid_argument(
"Requested non-existent variable from VariableIndex");
97 return (*
this)[variable].empty();
108 void print(
const std::string&
str =
"VariableIndex: ",
115 void outputMetisFormat(std::ostream&
os)
const;
135 augment(factor, &newFactorIndices);
143 void augmentExistingFactor(
const FactorIndex factorIndex,
const KeySet & newKeys);
155 template<
typename ITERATOR,
class FG>
156 void remove(ITERATOR firstFactor, ITERATOR lastFactor,
const FG&
factors);
159 template<
typename ITERATOR>
160 void removeUnusedVariables(ITERATOR firstKey, ITERATOR lastKey);
163 const_iterator
begin()
const {
return index_.begin(); }
166 const_iterator
end()
const {
return index_.end(); }
169 const_iterator
find(
Key key)
const {
return index_.find(key); }
173 Factor_iterator
factorsEnd(
Key variable) {
return internalAt(variable).end(); }
175 Factor_const_iterator
factorsBegin(
Key variable)
const {
return internalAt(variable).begin(); }
176 Factor_const_iterator
factorsEnd(
Key variable)
const {
return internalAt(variable).end(); }
180 const KeyMap::const_iterator item = index_.find(variable);
181 assert(item != index_.end());
187 const KeyMap::iterator item = index_.find(variable);
188 assert(item != index_.end());
193 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION 195 friend class boost::serialization::access;
196 template<
class ARCHIVE>
197 void serialize(ARCHIVE & ar,
const unsigned int ) {
198 ar & BOOST_SERIALIZATION_NVP(index_);
199 ar & BOOST_SERIALIZATION_NVP(nFactors_);
200 ar & BOOST_SERIALIZATION_NVP(nEntries_);
void print(const Matrix &A, const string &s, ostream &stream)
const gtsam::Symbol key('X', 0)
void augment(const FG &factor, const FactorIndices &newFactorIndices)
const_iterator find(Key key) const
Find the iterator for the requested variable entry.
size_t size() const
The number of variable entries. This is equal to the number of unique variable Keys.
std::string serialize(const T &input)
serializes to a string
KeyMap::const_iterator iterator
Factor_iterator factorsBegin(Key variable)
size_t nEntries() const
The number of nonzero blocks, i.e. the number of variable-factor entries.
Factor_const_iterator factorsBegin(Key variable) const
const GaussianFactorGraph factors
size_t nFactors() const
The number of factors in the original factor graph.
KeyMap::value_type value_type
static const KeyFormatter DefaultKeyFormatter
const_iterator end() const
Iterator to the first variable entry.
std::shared_ptr< VariableIndex > shared_ptr
FastVector< FactorIndex > FactorIndices
Define collection types:
Factor_iterator factorsEnd(Key variable)
Factor_const_iterator factorsEnd(Key variable) const
VariableIndex()
Default constructor, creates an empty VariableIndex.
FastMap< Key, FactorIndices > KeyMap
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
const FactorIndices & internalAt(Key variable) const
Internal version of 'at' that asserts existence.
const_iterator begin() const
Iterator to the first variable entry.
A thin wrapper around std::vector that uses a custom allocator.
A thin wrapper around std::map that uses boost's fast_pool_allocator.
KeyMap::const_iterator const_iterator
VariableIndex(const FG &factorGraph)
FactorIndices & internalAt(Key variable)
Internal version of 'at' that asserts existence.
ofstream os("timeSchurFactors.csv")
FactorIndices::iterator Factor_iterator
std::uint64_t FactorIndex
Integer nonlinear factor index type.
FactorIndices::const_iterator Factor_const_iterator
std::uint64_t Key
Integer nonlinear key type.
const FactorIndices & operator[](Key variable) const
Access a list of factors by variable.
The base class for all factors.
bool empty(Key variable) const
Return true if no factors associated with a variable.