From ea19fae15582c4f681994f25d5640efac935d27a Mon Sep 17 00:00:00 2001 From: Andrew Melim Date: Fri, 7 Nov 2014 22:00:19 -0500 Subject: [PATCH] Formatting --- gtsam/inference/MetisIndex-inl.h | 86 ++++++++++++++++---------------- gtsam/inference/MetisIndex.h | 78 ++++++++++++++--------------- 2 files changed, 81 insertions(+), 83 deletions(-) diff --git a/gtsam/inference/MetisIndex-inl.h b/gtsam/inference/MetisIndex-inl.h index 43bc7a111..cab184ad0 100644 --- a/gtsam/inference/MetisIndex-inl.h +++ b/gtsam/inference/MetisIndex-inl.h @@ -23,55 +23,53 @@ namespace gtsam { - /* ************************************************************************* */ - template - void MetisIndex::augment(const FactorGraph& factors) - { - std::map > adjMap; - std::map >::iterator adjMapIt; - std::set keySet; +/* ************************************************************************* */ +template +void MetisIndex::augment(const FactorGraph& factors) +{ + std::map > adjMap; + std::map >::iterator adjMapIt; + 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]). - 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) - adjMap[k1].insert(adjMap[k1].end(), k2); // Insert at the end - } - keySet.insert(keySet.end(), k1); // Keep a track of all unique 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]). + 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) + adjMap[k1].insert(adjMap[k1].end(), k2); // Insert at the end + } + keySet.insert(keySet.end(), k1); // Keep a track of all unique keySet + } + } + } - // Number of keys referenced in this factor graph - nKeys_ = keySet.size(); + // Number of keys referenced in this factor graph + nKeys_ = keySet.size(); - // Starting with a nonzero key crashes METIS - // Find the smallest key in the graph - size_t minKey = *keySet.begin(); // set is ordered + // Starting with a nonzero key crashes METIS + // Find the smallest key in the graph + size_t minKey = *keySet.begin(); // set is ordered - xadj_.push_back(0);// Always set the first index to zero - for (adjMapIt = adjMap.begin(); adjMapIt != adjMap.end(); ++adjMapIt) { - std::vector temp; - // Copy from the FastSet into a temporary vector - std::copy(adjMapIt->second.begin(), adjMapIt->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(adj_.size()); - } + xadj_.push_back(0);// Always set the first index to zero + for (adjMapIt = adjMap.begin(); adjMapIt != adjMap.end(); ++adjMapIt) { + std::vector temp; + // Copy from the FastSet into a temporary vector + std::copy(adjMapIt->second.begin(), adjMapIt->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(adj_.size()); + } - // Normalize, subtract the smallest key - std::transform(adj_.begin(), adj_.end(), adj_.begin(), std::bind2nd(std::minus(), minKey)); - - - } + // Normalize, subtract the smallest key + std::transform(adj_.begin(), adj_.end(), adj_.begin(), std::bind2nd(std::minus(), minKey)); +} } diff --git a/gtsam/inference/MetisIndex.h b/gtsam/inference/MetisIndex.h index 6aaa9246d..eaff2546f 100644 --- a/gtsam/inference/MetisIndex.h +++ b/gtsam/inference/MetisIndex.h @@ -28,53 +28,53 @@ #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 - * fromt 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; + /** + * 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 + * fromt 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; -private: - FastVector xadj_; // Index of node's adjacency list in adj - FastVector adj_; // Stores ajacency lists of all nodes, appended into a single vector - size_t nFactors_; // Number of factors in the original factor graph - size_t nKeys_; // + private: + FastVector xadj_; // Index of node's adjacency list in adj + FastVector adj_; // Stores ajacency lists of all nodes, appended into a single vector + size_t nFactors_; // Number of factors in the original factor graph + size_t nKeys_; // -public: - /// @name Standard Constructors - /// @{ + public: + /// @name Standard Constructors + /// @{ - /** Default constructor, creates empty MetisIndex */ - MetisIndex() : nFactors_(0), nKeys_(0) {} + /** Default constructor, creates empty MetisIndex */ + MetisIndex() : nFactors_(0), nKeys_(0) {} - template - MetisIndex(const FG& factorGraph) : nFactors_(0), nKeys_(0) { - augment(factorGraph); } + template + MetisIndex(const FG& factorGraph) : nFactors_(0), 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_; } - /// @} -}; + /// @} + }; }