23 #include <gtsam/dllexport.h> 25 #include <boost/optional/optional.hpp> 26 #include <boost/smart_ptr/shared_ptr.hpp> 45 typedef boost::shared_ptr<VariableIndex> shared_ptr;
47 typedef Factors::iterator Factor_iterator;
48 typedef Factors::const_iterator Factor_const_iterator;
57 typedef KeyMap::const_iterator const_iterator;
58 typedef KeyMap::const_iterator iterator;
59 typedef KeyMap::value_type value_type;
74 VariableIndex(
const FG& factorGraph) : nFactors_(0), nEntries_(0) { augment(factorGraph); }
84 size_t size()
const {
return index_.size(); }
94 KeyMap::const_iterator item = index_.find(variable);
95 if(item == index_.end())
96 throw std::invalid_argument(
"Requested non-existent variable from VariableIndex");
109 void print(
const std::string& str =
"VariableIndex: ",
110 const KeyFormatter& keyFormatter = DefaultKeyFormatter)
const;
116 void outputMetisFormat(std::ostream& os)
const;
128 void augment(
const FG& factors, boost::optional<
const FastVector<size_t>&> newFactorIndices = boost::none);
140 template<
typename ITERATOR,
class FG>
141 void remove(ITERATOR firstFactor, ITERATOR lastFactor,
const FG& factors);
144 template<
typename ITERATOR>
145 void removeUnusedVariables(ITERATOR firstKey, ITERATOR lastKey);
148 const_iterator
begin()
const {
return index_.begin(); }
151 const_iterator
end()
const {
return index_.end(); }
154 const_iterator
find(
Key key)
const {
return index_.find(key); }
157 Factor_iterator factorsBegin(
Key variable) {
return internalAt(variable).begin(); }
158 Factor_iterator factorsEnd(
Key variable) {
return internalAt(variable).end(); }
160 Factor_const_iterator factorsBegin(
Key variable)
const {
return internalAt(variable).begin(); }
161 Factor_const_iterator factorsEnd(
Key variable)
const {
return internalAt(variable).end(); }
165 const KeyMap::const_iterator item = index_.find(variable);
166 assert(item != index_.end());
167 return item->second; }
171 const KeyMap::iterator item = index_.find(variable);
172 assert(item != index_.end());
173 return item->second; }
const_iterator find(Key key) const
Find the iterator for the requested variable entry.
Definition: VariableIndex.h:154
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition: Matrix.cpp:140
size_t nFactors() const
The number of factors in the original factor graph.
Definition: VariableIndex.h:87
const_iterator end() const
Iterator to the first variable entry.
Definition: VariableIndex.h:151
const_iterator begin() const
Iterator to the first variable entry.
Definition: VariableIndex.h:148
const Factors & operator[](Key variable) const
Access a list of factors by variable.
Definition: VariableIndex.h:93
A helper that implements the traits interface for GTSAM types.
Definition: Testable.h:150
The VariableIndex class computes and stores the block column structure of a factor graph...
Definition: VariableIndex.h:42
Template to create a binary predicate.
Definition: Testable.h:110
VariableIndex(const FG &factorGraph)
Create a VariableIndex that computes and stores the block column structure of a factor graph...
Definition: VariableIndex.h:74
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition: concepts.h:30
const Factors & internalAt(Key variable) const
Internal version of 'at' that asserts existence.
Definition: VariableIndex.h:164
size_t nEntries() const
The number of nonzero blocks, i.e.
Definition: VariableIndex.h:90
size_t size() const
The number of variable entries.
Definition: VariableIndex.h:84
VariableIndex()
Default constructor, creates an empty VariableIndex.
Definition: VariableIndex.h:67
A thin wrapper around std::vector that uses boost's pool_allocator.
A thin wrapper around std::map that uses boost's fast_pool_allocator.
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:57
Factors & internalAt(Key variable)
Internal version of 'at' that asserts existence.
Definition: VariableIndex.h:170
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
boost::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition: Key.h:33