Formatting

release/4.3a0
Andrew Melim 2014-11-07 22:00:19 -05:00
parent 88a11329c0
commit ea19fae155
2 changed files with 81 additions and 83 deletions

View File

@ -23,55 +23,53 @@
namespace gtsam {
/* ************************************************************************* */
template<class FACTOR>
void MetisIndex::augment(const FactorGraph<FACTOR>& factors)
{
std::map<int, FastSet<int> > adjMap;
std::map<int, FastSet<int> >::iterator adjMapIt;
std::set<Key> keySet;
/* ************************************************************************* */
template<class FACTOR>
void MetisIndex::augment(const FactorGraph<FACTOR>& factors)
{
std::map<int, FastSet<int> > adjMap;
std::map<int, FastSet<int> >::iterator adjMapIt;
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]).
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<Key> 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<Key> 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<size_t>(), minKey));
}
// Normalize, subtract the smallest key
std::transform(adj_.begin(), adj_.end(), adj_.begin(), std::bind2nd(std::minus<size_t>(), minKey));
}
}

View File

@ -28,53 +28,53 @@
#include <gtsam/inference/FactorGraph.h>
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<MetisIndex> 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<MetisIndex> shared_ptr;
private:
FastVector<int> xadj_; // Index of node's adjacency list in adj
FastVector<int> 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<int> xadj_; // Index of node's adjacency list in adj
FastVector<int> 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<class FG>
MetisIndex(const FG& factorGraph) : nFactors_(0), nKeys_(0) {
augment(factorGraph); }
template<class FG>
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<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<int> xadj() const { return xadj_; }
std::vector<int> adj() const { return adj_; }
size_t nValues() const { return nKeys_; }
std::vector<int> xadj() const { return xadj_; }
std::vector<int> adj() const { return adj_; }
size_t nValues() const { return nKeys_; }
/// @}
};
/// @}
};
}