diff --git a/gtsam/inference/EliminationTree-inst.h b/gtsam/inference/EliminationTree-inst.h index 33ba6e18d..3390a3aac 100644 --- a/gtsam/inference/EliminationTree-inst.h +++ b/gtsam/inference/EliminationTree-inst.h @@ -98,7 +98,7 @@ namespace gtsam { for (size_t j = 0; j < n; j++) { // Retrieve the factors involving this variable and create the current node - const VariableIndex::Factors& factors = structure[order[j]]; + const FactorIndices& factors = structure[order[j]]; const sharedNode node = boost::make_shared(); node->key = order[j]; diff --git a/gtsam/inference/Ordering.cpp b/gtsam/inference/Ordering.cpp index 1165b4a0f..da61ca57e 100644 --- a/gtsam/inference/Ordering.cpp +++ b/gtsam/inference/Ordering.cpp @@ -79,7 +79,7 @@ Ordering Ordering::ColamdConstrained(const VariableIndex& variableIndex, size_t index = 0; for (auto key_factors: variableIndex) { // Arrange factor indices into COLAMD format - const VariableIndex::Factors& column = key_factors.second; + const FactorIndices& column = key_factors.second; for(size_t factorIndex: column) { A[count++] = (int) factorIndex; // copy sparse column } diff --git a/gtsam/inference/VariableIndex-inl.h b/gtsam/inference/VariableIndex-inl.h index bc8100e4a..727ef8fd8 100644 --- a/gtsam/inference/VariableIndex-inl.h +++ b/gtsam/inference/VariableIndex-inl.h @@ -67,8 +67,8 @@ void VariableIndex::remove(ITERATOR firstFactor, ITERATOR lastFactor, "Internal error, requested inconsistent number of factor indices and factors in VariableIndex::remove"); if (factors[i]) { for(Key j: *factors[i]) { - Factors& factorEntries = internalAt(j); - Factors::iterator entry = std::find(factorEntries.begin(), + FactorIndices& factorEntries = internalAt(j); + auto entry = std::find(factorEntries.begin(), factorEntries.end(), *factorIndex); if (entry == factorEntries.end()) throw std::invalid_argument( diff --git a/gtsam/inference/VariableIndex.h b/gtsam/inference/VariableIndex.h index a96a53289..0d7320428 100644 --- a/gtsam/inference/VariableIndex.h +++ b/gtsam/inference/VariableIndex.h @@ -41,26 +41,22 @@ namespace gtsam { * \nosubgrouping */ class GTSAM_EXPORT VariableIndex { -public: - + public: typedef boost::shared_ptr shared_ptr; - typedef FactorIndices Factors; - typedef Factors::iterator Factor_iterator; - typedef Factors::const_iterator Factor_const_iterator; + typedef FactorIndices::iterator Factor_iterator; + typedef FactorIndices::const_iterator Factor_const_iterator; -protected: - typedef FastMap KeyMap; + protected: + typedef FastMap KeyMap; KeyMap index_; - size_t nFactors_; // Number of factors in the original factor graph. - size_t nEntries_; // Sum of involved variable counts of each factor. + size_t nFactors_; // Number of factors in the original factor graph. + size_t nEntries_; // Sum of involved variable counts of each factor. -public: + public: typedef KeyMap::const_iterator const_iterator; typedef KeyMap::const_iterator iterator; typedef KeyMap::value_type value_type; -public: - /// @name Standard Constructors /// @{ @@ -71,8 +67,10 @@ public: * Create a VariableIndex that computes and stores the block column structure * of a factor graph. */ - template - VariableIndex(const FG& factorGraph) : nFactors_(0), nEntries_(0) { augment(factorGraph); } + template + explicit VariableIndex(const FG& factorGraph) : nFactors_(0), nEntries_(0) { + augment(factorGraph); + } /// @} /// @name Standard Interface @@ -88,7 +86,7 @@ public: size_t nEntries() const { return nEntries_; } /// Access a list of factors by variable - const Factors& operator[](Key variable) const { + const FactorIndices& operator[](Key variable) const { KeyMap::const_iterator item = index_.find(variable); if(item == index_.end()) throw std::invalid_argument("Requested non-existent variable from VariableIndex"); @@ -96,6 +94,11 @@ public: return item->second; } + /// Return true if no factors associated with a variable + const bool empty(Key variable) const { + return (*this)[variable].empty(); + } + /// @} /// @name Testable /// @{ @@ -166,16 +169,18 @@ protected: Factor_const_iterator factorsEnd(Key variable) const { return internalAt(variable).end(); } /// Internal version of 'at' that asserts existence - const Factors& internalAt(Key variable) const { + const FactorIndices& internalAt(Key variable) const { const KeyMap::const_iterator item = index_.find(variable); assert(item != index_.end()); - return item->second; } + return item->second; + } /// Internal version of 'at' that asserts existence - Factors& internalAt(Key variable) { + FactorIndices& internalAt(Key variable) { const KeyMap::iterator item = index_.find(variable); assert(item != index_.end()); - return item->second; } + return item->second; + } /// @} }; diff --git a/gtsam_unstable/discrete/CSP.cpp b/gtsam_unstable/discrete/CSP.cpp index cf5abdcb1..0223250b5 100644 --- a/gtsam_unstable/discrete/CSP.cpp +++ b/gtsam_unstable/discrete/CSP.cpp @@ -43,7 +43,7 @@ namespace gtsam { // keep track of which domains changed changed[v] = false; // loop over all factors/constraints for variable v - const VariableIndex::Factors& factors = index[v]; + const FactorIndices& factors = index[v]; for(size_t f: factors) { // if not already a singleton if (!domains[v].isSingleton()) {