Fixed many warnings with Clang, reformatted using BORG template.
							parent
							
								
									97d6088467
								
							
						
					
					
						commit
						ce033f5594
					
				|  | @ -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 <boost/foreach.hpp> | ||||
| #include <map> | ||||
| #include <vector> | ||||
| 
 | ||||
| namespace gtsam { | ||||
| 
 | ||||
| 
 | ||||
| /* ************************************************************************* */ | ||||
| template<class FACTOR> | ||||
| void MetisIndex::augment(const FactorGraph<FACTOR>& factors) | ||||
| { | ||||
| void MetisIndex::augment(const FactorGraph<FACTOR>& factors) { | ||||
|   std::map<idx_t, FastSet<idx_t> > iAdjMap; // Stores a set of keys that are adjacent to key x, with  adjMap.first
 | ||||
|   std::map<idx_t, FastSet<idx_t> >::iterator iAdjMapIt; | ||||
| 	std::set<Key> 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<Key> 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<idx_t> 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<idx_t> 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
 | ||||
|  |  | |||
|  | @ -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 <vector> | ||||
| #include <boost/foreach.hpp> | ||||
| 
 | ||||
| #include <gtsam/base/FastList.h> | ||||
| #include <gtsam/base/types.h> | ||||
| #include <gtsam/base/timing.h> | ||||
| #include <gtsam/inference/Key.h> | ||||
| #include <gtsam/inference/FactorGraph.h> | ||||
| #include <gtsam/base/FastVector.h> | ||||
| #include <gtsam/base/types.h> | ||||
| #include <gtsam/base/timing.h> | ||||
| #include <gtsam/3rdparty/metis/metis.h> | ||||
| 
 | ||||
| // Boost bimap generates many ugly warnings in CLANG
 | ||||
| #ifdef __clang__ | ||||
| #  pragma clang diagnostic push | ||||
| #  pragma clang diagnostic ignored "-Wredeclared-class-member" | ||||
| #endif | ||||
| #include <boost/bimap.hpp> | ||||
| #ifdef __clang__ | ||||
| #  pragma clang diagnostic pop | ||||
| #endif | ||||
| 
 | ||||
| #include <vector> | ||||
| 
 | ||||
| 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<MetisIndex> shared_ptr; | ||||
|   typedef boost::bimap<Key, idx_t>      bm_type; | ||||
|   typedef boost::shared_ptr<MetisIndex> shared_ptr; | ||||
|   typedef boost::bimap<Key, idx_t> bm_type; | ||||
| 
 | ||||
| private: | ||||
|   FastVector<idx_t>        xadj_; // Index of node's adjacency list in adj
 | ||||
|   FastVector<idx_t>        adj_; // Stores ajacency lists of all nodes, appended into a single vector
 | ||||
|   FastVector<idx_t>        iadj_; // Integer keys for passing into metis. One to one mapping with adj_;
 | ||||
|   FastVector<idx_t> xadj_; // Index of node's adjacency list in adj
 | ||||
|   FastVector<idx_t> adj_; // Stores ajacency lists of all nodes, appended into a single vector
 | ||||
|   FastVector<idx_t> iadj_; // Integer keys for passing into metis. One to one mapping with adj_;
 | ||||
|   boost::bimap<Key, idx_t> 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<class FG> | ||||
| 	MetisIndex(const FG& factorGraph) : nFactors_(0), nKeys_(0) { | ||||
| 			augment(factorGraph); } | ||||
|   template<class FG> | ||||
|   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<class FACTOR> | ||||
| 	void augment(const FactorGraph<FACTOR>& factors); | ||||
|   /**
 | ||||
|    * Augment the variable index with new factors.  This can be used when | ||||
|    * solving problems incrementally. | ||||
|    */ | ||||
|   template<class FACTOR> | ||||
|   void augment(const FactorGraph<FACTOR>& factors); | ||||
| 
 | ||||
|   std::vector<idx_t> xadj() const { return   xadj_; } | ||||
|   std::vector<idx_t>  adj() const { return    adj_; } | ||||
| 	size_t          nValues() const { return  nKeys_; } | ||||
|   std::vector<idx_t> xadj() const { | ||||
|     return xadj_; | ||||
|   } | ||||
|   std::vector<idx_t> 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 <gtsam/inference/MetisIndex-inl.h> | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue