diff --git a/gtsam/inference/MetisIndex-inl.h b/gtsam/inference/MetisIndex-inl.h index 0be1c503c..50bed2e3b 100644 --- a/gtsam/inference/MetisIndex-inl.h +++ b/gtsam/inference/MetisIndex-inl.h @@ -1,85 +1,85 @@ /* ---------------------------------------------------------------------------- -* GTSAM Copyright 2010, Georgia Tech Research Corporation, -* Atlanta, Georgia 30332-0415 -* All Rights Reserved -* Authors: Frank Dellaert, et al. (see THANKS for the full author list) + * GTSAM Copyright 2010, Georgia Tech Research Corporation, + * Atlanta, Georgia 30332-0415 + * All Rights Reserved + * Authors: Frank Dellaert, et al. (see THANKS for the full author list) -* See LICENSE for the license information + * See LICENSE for the license information -* -------------------------------------------------------------------------- */ + * -------------------------------------------------------------------------- */ /** -* @file MetisIndex-inl.h -* @author Andrew Melim -* @date Oct. 10, 2014 -*/ + * @file MetisIndex-inl.h + * @author Andrew Melim + * @date Oct. 10, 2014 + */ #pragma once +#include #include #include namespace gtsam { - /* ************************************************************************* */ template -void MetisIndex::augment(const FactorGraph& factors) -{ +void MetisIndex::augment(const FactorGraph& factors) { std::map > iAdjMap; // Stores a set of keys that are adjacent to key x, with adjMap.first std::map >::iterator iAdjMapIt; - std::set keySet; - - /* ********** Convert to CSR format ********** */ - // Assuming that vertex numbering starts from 0 (C style), - // then the adjacency list of vertex i is stored in array adjncy - // starting at index xadj[i] and ending at(but not including) - // index xadj[i + 1](i.e., adjncy[xadj[i]] through - // and including adjncy[xadj[i + 1] - 1]). + std::set keySet; + + /* ********** Convert to CSR format ********** */ + // Assuming that vertex numbering starts from 0 (C style), + // then the adjacency list of vertex i is stored in array adjncy + // starting at index xadj[i] and ending at(but not including) + // index xadj[i + 1](i.e., adjncy[xadj[i]] through + // and including adjncy[xadj[i + 1] - 1]). idx_t keyCounter = 0; // First: Record a copy of each key inside the factorgraph and create a // key to integer mapping. This is referenced during the adjaceny step - for (size_t i = 0; i < factors.size(); i++){ + for (size_t i = 0; i < factors.size(); i++) { if (factors[i]) { - BOOST_FOREACH(const Key& key, *factors[i]){ + BOOST_FOREACH(const Key& key, *factors[i]) { keySet.insert(keySet.end(), key); // Keep a track of all unique keys - if (intKeyBMap_.left.find(key) == intKeyBMap_.left.end()){ + if (intKeyBMap_.left.find(key) == intKeyBMap_.left.end()) { intKeyBMap_.insert(bm_type::value_type(key, keyCounter)); keyCounter++; } } } } - + // Create an adjacency mapping that stores the set of all adjacent keys for every key - for (size_t i = 0; i < factors.size(); i++){ - if (factors[i]){ - BOOST_FOREACH(const Key& k1, *factors[i]) - BOOST_FOREACH(const Key& k2, *factors[i]) - if (k1 != k2){ + for (size_t i = 0; i < factors.size(); i++) { + if (factors[i]) { + BOOST_FOREACH(const Key& k1, *factors[i]) + BOOST_FOREACH(const Key& k2, *factors[i]) + if (k1 != k2) { // Store both in Key and idx_t format int i = intKeyBMap_.left.at(k1); int j = intKeyBMap_.left.at(k2); iAdjMap[i].insert(iAdjMap[i].end(), j); } - } - } + } + } - // Number of keys referenced in this factor graph - nKeys_ = keySet.size(); - - xadj_.push_back(0);// Always set the first index to zero + // Number of keys referenced in this factor graph + nKeys_ = keySet.size(); + + xadj_.push_back(0); // Always set the first index to zero for (iAdjMapIt = iAdjMap.begin(); iAdjMapIt != iAdjMap.end(); ++iAdjMapIt) { - std::vector temp; - // Copy from the FastSet into a temporary vector - std::copy(iAdjMapIt->second.begin(), iAdjMapIt->second.end(), std::back_inserter(temp)); - // Insert each index's set in order by appending them to the end of adj_ - adj_.insert(adj_.end(), temp.begin(), temp.end()); - //adj_.push_back(temp); - xadj_.push_back((idx_t)adj_.size()); - } + std::vector temp; + // Copy from the FastSet into a temporary vector + std::copy(iAdjMapIt->second.begin(), iAdjMapIt->second.end(), + std::back_inserter(temp)); + // Insert each index's set in order by appending them to the end of adj_ + adj_.insert(adj_.end(), temp.begin(), temp.end()); + //adj_.push_back(temp); + xadj_.push_back((idx_t) adj_.size()); + } } -} +} // \ gtsam diff --git a/gtsam/inference/MetisIndex.h b/gtsam/inference/MetisIndex.h index 3eef4739c..51624e29e 100644 --- a/gtsam/inference/MetisIndex.h +++ b/gtsam/inference/MetisIndex.h @@ -1,89 +1,106 @@ /* ---------------------------------------------------------------------------- -* GTSAM Copyright 2010, Georgia Tech Research Corporation, -* Atlanta, Georgia 30332-0415 -* All Rights Reserved -* Authors: Frank Dellaert, et al. (see THANKS for the full author list) + * GTSAM Copyright 2010, Georgia Tech Research Corporation, + * Atlanta, Georgia 30332-0415 + * All Rights Reserved + * Authors: Frank Dellaert, et al. (see THANKS for the full author list) -* See LICENSE for the license information - -* -------------------------------------------------------------------------- */ + * See LICENSE for the license information + * -------------------------------------------------------------------------- */ /** -* @file MetisIndex.h -* @author Andrew Melim -* @date Oct. 10, 2014 -*/ + * @file MetisIndex.h + * @author Andrew Melim + * @date Oct. 10, 2014 + */ #pragma once -#include -#include -#include -#include -#include #include #include +#include +#include +#include #include + +// Boost bimap generates many ugly warnings in CLANG +#ifdef __clang__ +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wredeclared-class-member" +#endif #include +#ifdef __clang__ +# pragma clang diagnostic pop +#endif + +#include namespace gtsam { /** - * The MetisIndex class converts a factor graph into the Compressed Sparse Row format for use in - * METIS algorithms. Specifically, two vectors store the adjacency structure of the graph. It is built - * from a factor graph prior to elimination, and stores the list of factors - * that involve each variable. - * \nosubgrouping - */ -class GTSAM_EXPORT MetisIndex -{ + * The MetisIndex class converts a factor graph into the Compressed Sparse Row format for use in + * METIS algorithms. Specifically, two vectors store the adjacency structure of the graph. It is built + * from a factor graph prior to elimination, and stores the list of factors + * that involve each variable. + * \nosubgrouping + */ +class GTSAM_EXPORT MetisIndex { public: - typedef boost::shared_ptr shared_ptr; - typedef boost::bimap bm_type; + typedef boost::shared_ptr shared_ptr; + typedef boost::bimap bm_type; private: - FastVector xadj_; // Index of node's adjacency list in adj - FastVector adj_; // Stores ajacency lists of all nodes, appended into a single vector - FastVector iadj_; // Integer keys for passing into metis. One to one mapping with adj_; + FastVector xadj_; // Index of node's adjacency list in adj + FastVector adj_; // Stores ajacency lists of all nodes, appended into a single vector + FastVector iadj_; // Integer keys for passing into metis. One to one mapping with adj_; boost::bimap intKeyBMap_; // Stores Key <-> integer value relationship - size_t nFactors_; // Number of factors in the original factor graph - size_t nKeys_; + size_t nKeys_; public: - /// @name Standard Constructors - /// @{ + /// @name Standard Constructors + /// @{ - /** Default constructor, creates empty MetisIndex */ - MetisIndex() : nFactors_(0), nKeys_(0) {} + /** Default constructor, creates empty MetisIndex */ + MetisIndex() : + nKeys_(0) { + } - template - MetisIndex(const FG& factorGraph) : nFactors_(0), nKeys_(0) { - augment(factorGraph); } + template + MetisIndex(const FG& factorGraph) : + nKeys_(0) { + augment(factorGraph); + } - ~MetisIndex(){} - /// @} - /// @name Advanced Interface - /// @{ + ~MetisIndex() { + } + /// @} + /// @name Advanced Interface + /// @{ - /** - * Augment the variable index with new factors. This can be used when - * solving problems incrementally. - */ - template - void augment(const FactorGraph& factors); + /** + * Augment the variable index with new factors. This can be used when + * solving problems incrementally. + */ + template + void augment(const FactorGraph& factors); - std::vector xadj() const { return xadj_; } - std::vector adj() const { return adj_; } - size_t nValues() const { return nKeys_; } + std::vector xadj() const { + return xadj_; + } + std::vector adj() const { + return adj_; + } + size_t nValues() const { + return nKeys_; + } Key intToKey(idx_t value) const { assert(value >= 0); return intKeyBMap_.right.find(value)->second; } - /// @} + /// @} }; -} +} // \ namesace gtsam #include