Fixed many warnings with Clang, reformatted using BORG template.
parent
97d6088467
commit
ce033f5594
|
@ -1,85 +1,85 @@
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
|
|
||||||
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
|
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
|
||||||
* Atlanta, Georgia 30332-0415
|
* Atlanta, Georgia 30332-0415
|
||||||
* All Rights Reserved
|
* All Rights Reserved
|
||||||
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)
|
* 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
|
* @file MetisIndex-inl.h
|
||||||
* @author Andrew Melim
|
* @author Andrew Melim
|
||||||
* @date Oct. 10, 2014
|
* @date Oct. 10, 2014
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <boost/foreach.hpp>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
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<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> > 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::map<idx_t, FastSet<idx_t> >::iterator iAdjMapIt;
|
||||||
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]).
|
||||||
idx_t keyCounter = 0;
|
idx_t keyCounter = 0;
|
||||||
|
|
||||||
// First: Record a copy of each key inside the factorgraph and create a
|
// First: Record a copy of each key inside the factorgraph and create a
|
||||||
// key to integer mapping. This is referenced during the adjaceny step
|
// 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]) {
|
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
|
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));
|
intKeyBMap_.insert(bm_type::value_type(key, keyCounter));
|
||||||
keyCounter++;
|
keyCounter++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create an adjacency mapping that stores the set of all adjacent keys for every key
|
// Create an adjacency mapping that stores the set of all adjacent keys for every key
|
||||||
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) {
|
||||||
// Store both in Key and idx_t format
|
// Store both in Key and idx_t format
|
||||||
int i = intKeyBMap_.left.at(k1);
|
int i = intKeyBMap_.left.at(k1);
|
||||||
int j = intKeyBMap_.left.at(k2);
|
int j = intKeyBMap_.left.at(k2);
|
||||||
iAdjMap[i].insert(iAdjMap[i].end(), j);
|
iAdjMap[i].insert(iAdjMap[i].end(), j);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Number of keys referenced in this factor graph
|
// Number of keys referenced in this factor graph
|
||||||
nKeys_ = keySet.size();
|
nKeys_ = keySet.size();
|
||||||
|
|
||||||
xadj_.push_back(0);// Always set the first index to zero
|
xadj_.push_back(0); // Always set the first index to zero
|
||||||
for (iAdjMapIt = iAdjMap.begin(); iAdjMapIt != iAdjMap.end(); ++iAdjMapIt) {
|
for (iAdjMapIt = iAdjMap.begin(); iAdjMapIt != iAdjMap.end(); ++iAdjMapIt) {
|
||||||
std::vector<idx_t> temp;
|
std::vector<idx_t> temp;
|
||||||
// Copy from the FastSet into a temporary vector
|
// Copy from the FastSet into a temporary vector
|
||||||
std::copy(iAdjMapIt->second.begin(), iAdjMapIt->second.end(), std::back_inserter(temp));
|
std::copy(iAdjMapIt->second.begin(), iAdjMapIt->second.end(),
|
||||||
// Insert each index's set in order by appending them to the end of adj_
|
std::back_inserter(temp));
|
||||||
adj_.insert(adj_.end(), temp.begin(), temp.end());
|
// Insert each index's set in order by appending them to the end of adj_
|
||||||
//adj_.push_back(temp);
|
adj_.insert(adj_.end(), temp.begin(), temp.end());
|
||||||
xadj_.push_back((idx_t)adj_.size());
|
//adj_.push_back(temp);
|
||||||
}
|
xadj_.push_back((idx_t) adj_.size());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // \ gtsam
|
||||||
|
|
|
@ -1,89 +1,106 @@
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
|
|
||||||
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
|
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
|
||||||
* Atlanta, Georgia 30332-0415
|
* Atlanta, Georgia 30332-0415
|
||||||
* All Rights Reserved
|
* All Rights Reserved
|
||||||
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)
|
* 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
|
* @file MetisIndex.h
|
||||||
* @author Andrew Melim
|
* @author Andrew Melim
|
||||||
* @date Oct. 10, 2014
|
* @date Oct. 10, 2014
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#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/Key.h>
|
||||||
#include <gtsam/inference/FactorGraph.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>
|
#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>
|
#include <boost/bimap.hpp>
|
||||||
|
#ifdef __clang__
|
||||||
|
# pragma clang diagnostic pop
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
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
|
||||||
* from a factor graph prior to elimination, and stores the list of factors
|
* from 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;
|
||||||
typedef boost::bimap<Key, idx_t> bm_type;
|
typedef boost::bimap<Key, idx_t> bm_type;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FastVector<idx_t> xadj_; // Index of node's adjacency list in 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> 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> iadj_; // Integer keys for passing into metis. One to one mapping with adj_;
|
||||||
boost::bimap<Key, idx_t> intKeyBMap_; // Stores Key <-> integer value relationship
|
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:
|
public:
|
||||||
/// @name Standard Constructors
|
/// @name Standard Constructors
|
||||||
/// @{
|
/// @{
|
||||||
|
|
||||||
/** Default constructor, creates empty MetisIndex */
|
/** Default constructor, creates empty MetisIndex */
|
||||||
MetisIndex() : nFactors_(0), nKeys_(0) {}
|
MetisIndex() :
|
||||||
|
nKeys_(0) {
|
||||||
|
}
|
||||||
|
|
||||||
template<class FG>
|
template<class FG>
|
||||||
MetisIndex(const FG& factorGraph) : nFactors_(0), nKeys_(0) {
|
MetisIndex(const FG& factorGraph) :
|
||||||
augment(factorGraph); }
|
nKeys_(0) {
|
||||||
|
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<idx_t> xadj() const { return xadj_; }
|
std::vector<idx_t> xadj() const {
|
||||||
std::vector<idx_t> adj() const { return adj_; }
|
return xadj_;
|
||||||
size_t nValues() const { return nKeys_; }
|
}
|
||||||
|
std::vector<idx_t> adj() const {
|
||||||
|
return adj_;
|
||||||
|
}
|
||||||
|
size_t nValues() const {
|
||||||
|
return nKeys_;
|
||||||
|
}
|
||||||
Key intToKey(idx_t value) const {
|
Key intToKey(idx_t value) const {
|
||||||
assert(value >= 0);
|
assert(value >= 0);
|
||||||
return intKeyBMap_.right.find(value)->second;
|
return intKeyBMap_.right.find(value)->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // \ namesace gtsam
|
||||||
|
|
||||||
#include <gtsam/inference/MetisIndex-inl.h>
|
#include <gtsam/inference/MetisIndex-inl.h>
|
||||||
|
|
Loading…
Reference in New Issue