24 #include <gtsam/dllexport.h> 26 #include <boost/optional/optional.hpp> 27 #include <boost/smart_ptr/shared_ptr.hpp> 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: ",
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); }
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());
void print(const Matrix &A, const string &s, ostream &stream)
boost::shared_ptr< VariableIndex > shared_ptr
bool empty(Key variable) const
Return true if no factors associated with a variable.
const_iterator begin() const
Iterator to the first variable entry.
KeyMap::const_iterator iterator
Factor_iterator factorsBegin(Key variable)
FastVector< FactorIndex > FactorIndices
Define collection types:
const_iterator find(Key key) const
Find the iterator for the requested variable entry.
GaussianFactorGraph factors(list_of(factor1)(factor2)(factor3))
const FactorIndices & operator[](Key variable) const
Access a list of factors by variable.
KeyMap::value_type value_type
static const KeyFormatter DefaultKeyFormatter
size_t size() const
The number of variable entries. This is equal to the number of unique variable Keys.
const FactorIndices & internalAt(Key variable) const
Internal version of 'at' that asserts existence.
Factor_iterator factorsEnd(Key variable)
size_t nEntries() const
The number of nonzero blocks, i.e. the number of variable-factor entries.
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
VariableIndex()
Default constructor, creates an empty VariableIndex.
FastMap< Key, FactorIndices > KeyMap
const_iterator end() 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")
Factor_const_iterator factorsBegin(Key variable) const
size_t nFactors() const
The number of factors in the original factor graph.
FactorIndices::iterator Factor_iterator
std::uint64_t FactorIndex
Integer nonlinear factor index type.
Factor_const_iterator factorsEnd(Key variable) const
FactorIndices::const_iterator Factor_const_iterator
std::uint64_t Key
Integer nonlinear key type.
The base class for all factors.