Formatting
parent
88a11329c0
commit
ea19fae155
|
@ -23,55 +23,53 @@
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
template<class FACTOR>
|
template<class FACTOR>
|
||||||
void MetisIndex::augment(const FactorGraph<FACTOR>& factors)
|
void MetisIndex::augment(const FactorGraph<FACTOR>& factors)
|
||||||
{
|
{
|
||||||
std::map<int, FastSet<int> > adjMap;
|
std::map<int, FastSet<int> > adjMap;
|
||||||
std::map<int, FastSet<int> >::iterator adjMapIt;
|
std::map<int, FastSet<int> >::iterator adjMapIt;
|
||||||
std::set<Key> keySet;
|
std::set<Key> keySet;
|
||||||
|
|
||||||
/* ********** Convert to CSR format ********** */
|
/* ********** Convert to CSR format ********** */
|
||||||
// Assuming that vertex numbering starts from 0 (C style),
|
// Assuming that vertex numbering starts from 0 (C style),
|
||||||
// then the adjacency list of vertex i is stored in array adjncy
|
// then the adjacency list of vertex i is stored in array adjncy
|
||||||
// starting at index xadj[i] and ending at(but not including)
|
// starting at index xadj[i] and ending at(but not including)
|
||||||
// index xadj[i + 1](i.e., adjncy[xadj[i]] through
|
// index xadj[i + 1](i.e., adjncy[xadj[i]] through
|
||||||
// and including adjncy[xadj[i + 1] - 1]).
|
// and including adjncy[xadj[i + 1] - 1]).
|
||||||
for (size_t i = 0; i < factors.size(); i++){
|
for (size_t i = 0; i < factors.size(); i++){
|
||||||
if (factors[i]){
|
if (factors[i]){
|
||||||
BOOST_FOREACH(const Key& k1, *factors[i]){
|
BOOST_FOREACH(const Key& k1, *factors[i]){
|
||||||
BOOST_FOREACH(const Key& k2, *factors[i]){
|
BOOST_FOREACH(const Key& k2, *factors[i]){
|
||||||
if (k1 != k2)
|
if (k1 != k2)
|
||||||
adjMap[k1].insert(adjMap[k1].end(), k2); // Insert at the end
|
adjMap[k1].insert(adjMap[k1].end(), k2); // Insert at the end
|
||||||
}
|
}
|
||||||
keySet.insert(keySet.end(), k1); // Keep a track of all unique keySet
|
keySet.insert(keySet.end(), k1); // Keep a track of all unique keySet
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Number of keys referenced in this factor graph
|
// Number of keys referenced in this factor graph
|
||||||
nKeys_ = keySet.size();
|
nKeys_ = keySet.size();
|
||||||
|
|
||||||
|
|
||||||
// Starting with a nonzero key crashes METIS
|
// Starting with a nonzero key crashes METIS
|
||||||
// Find the smallest key in the graph
|
// Find the smallest key in the graph
|
||||||
size_t minKey = *keySet.begin(); // set is ordered
|
size_t minKey = *keySet.begin(); // set is ordered
|
||||||
|
|
||||||
xadj_.push_back(0);// Always set the first index to zero
|
xadj_.push_back(0);// Always set the first index to zero
|
||||||
for (adjMapIt = adjMap.begin(); adjMapIt != adjMap.end(); ++adjMapIt) {
|
for (adjMapIt = adjMap.begin(); adjMapIt != adjMap.end(); ++adjMapIt) {
|
||||||
std::vector<Key> temp;
|
std::vector<Key> temp;
|
||||||
// Copy from the FastSet into a temporary vector
|
// Copy from the FastSet into a temporary vector
|
||||||
std::copy(adjMapIt->second.begin(), adjMapIt->second.end(), std::back_inserter(temp));
|
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_
|
// Insert each index's set in order by appending them to the end of adj_
|
||||||
adj_.insert(adj_.end(), temp.begin(), temp.end());
|
adj_.insert(adj_.end(), temp.begin(), temp.end());
|
||||||
//adj_.push_back(temp);
|
//adj_.push_back(temp);
|
||||||
xadj_.push_back(adj_.size());
|
xadj_.push_back(adj_.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Normalize, subtract the smallest key
|
// Normalize, subtract the smallest key
|
||||||
std::transform(adj_.begin(), adj_.end(), adj_.begin(), std::bind2nd(std::minus<size_t>(), minKey));
|
std::transform(adj_.begin(), adj_.end(), adj_.begin(), std::bind2nd(std::minus<size_t>(), minKey));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,53 +28,53 @@
|
||||||
#include <gtsam/inference/FactorGraph.h>
|
#include <gtsam/inference/FactorGraph.h>
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
/**
|
/**
|
||||||
* The MetisIndex class converts a factor graph into the Compressed Sparse Row format for use in
|
* 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
|
* 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
|
* fromt a factor graph prior to elimination, and stores the list of factors
|
||||||
* that involve each variable.
|
* that involve each variable.
|
||||||
* \nosubgrouping
|
* \nosubgrouping
|
||||||
*/
|
*/
|
||||||
class GTSAM_EXPORT MetisIndex
|
class GTSAM_EXPORT MetisIndex
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef boost::shared_ptr<MetisIndex> shared_ptr;
|
typedef boost::shared_ptr<MetisIndex> shared_ptr;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FastVector<int> xadj_; // Index of node's adjacency list in adj
|
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
|
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 nFactors_; // Number of factors in the original factor graph
|
||||||
size_t nKeys_; //
|
size_t nKeys_; //
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// @name Standard Constructors
|
/// @name Standard Constructors
|
||||||
/// @{
|
/// @{
|
||||||
|
|
||||||
/** Default constructor, creates empty MetisIndex */
|
/** Default constructor, creates empty MetisIndex */
|
||||||
MetisIndex() : nFactors_(0), nKeys_(0) {}
|
MetisIndex() : nFactors_(0), nKeys_(0) {}
|
||||||
|
|
||||||
template<class FG>
|
template<class FG>
|
||||||
MetisIndex(const FG& factorGraph) : nFactors_(0), nKeys_(0) {
|
MetisIndex(const FG& factorGraph) : nFactors_(0), nKeys_(0) {
|
||||||
augment(factorGraph); }
|
augment(factorGraph); }
|
||||||
|
|
||||||
~MetisIndex(){}
|
~MetisIndex(){}
|
||||||
/// @}
|
/// @}
|
||||||
/// @name Advanced Interface
|
/// @name Advanced Interface
|
||||||
/// @{
|
/// @{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Augment the variable index with new factors. This can be used when
|
* Augment the variable index with new factors. This can be used when
|
||||||
* solving problems incrementally.
|
* solving problems incrementally.
|
||||||
*/
|
*/
|
||||||
template<class FACTOR>
|
template<class FACTOR>
|
||||||
void augment(const FactorGraph<FACTOR>& factors);
|
void augment(const FactorGraph<FACTOR>& factors);
|
||||||
|
|
||||||
std::vector<int> xadj() const { return xadj_; }
|
std::vector<int> xadj() const { return xadj_; }
|
||||||
std::vector<int> adj() const { return adj_; }
|
std::vector<int> adj() const { return adj_; }
|
||||||
size_t nValues() const { return nKeys_; }
|
size_t nValues() const { return nKeys_; }
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue