1. use DSFVector for spanning tree in SubgraphSolver

2. move DSFVector from unstable to stable
3. create Dummy.cpp to prevent base_unstable degenerate
release/4.3a0
Yong-Dian Jian 2012-09-05 15:03:35 +00:00
parent 7266293a61
commit 6c2f213091
7 changed files with 55 additions and 95 deletions

View File

@ -18,7 +18,7 @@
#include <boost/make_shared.hpp>
#include <boost/foreach.hpp>
#include <gtsam_unstable/base/DSFVector.h>
#include <gtsam/base/DSFVector.h>
using namespace std;

View File

@ -24,7 +24,7 @@
using namespace boost::assign;
#include <CppUnitLite/TestHarness.h>
#include <gtsam_unstable/base/DSFVector.h>
#include <gtsam/base/DSFVector.h>
using namespace std;
using namespace gtsam;

View File

@ -19,6 +19,7 @@
#include <gtsam/linear/VectorValues.h>
#include <gtsam/inference/graph-inl.h>
#include <gtsam/inference/EliminationTree.h>
#include <gtsam/base/DSFVector.h>
#include <boost/foreach.hpp>
#include <boost/shared_ptr.hpp>
#include <list>
@ -102,7 +103,7 @@ SubgraphSolver::splitGraph(const GaussianFactorGraph &jfg) {
const VariableIndex index(jfg);
const size_t n = index.size();
DisjointSet D(n) ;
DSFVector D(n);
GaussianFactorGraph::shared_ptr At(new GaussianFactorGraph());
GaussianFactorGraph::shared_ptr Ac( new GaussianFactorGraph());
@ -126,10 +127,10 @@ SubgraphSolver::splitGraph(const GaussianFactorGraph &jfg) {
if ( jf->keys().size() == 1 ) augment = true;
else {
const Index u = jf->keys()[0], v = jf->keys()[1],
u_root = D.find(u), v_root = D.find(v);
u_root = D.findSet(u), v_root = D.findSet(v);
if ( u_root != v_root ) {
t++; augment = true ;
D.makeUnion(u_root, v_root);
D.makeUnionInPlace(u_root, v_root);
}
}
if ( augment ) At->push_back(jf);
@ -139,53 +140,4 @@ SubgraphSolver::splitGraph(const GaussianFactorGraph &jfg) {
return boost::tie(At, Ac);
}
SubgraphSolver::DisjointSet::DisjointSet(const size_t n):n_(n),rank_(n,1),parent_(n) {
for ( Index i = 0 ; i < n ; ++i ) parent_[i] = i ;
}
Index SubgraphSolver::DisjointSet::makeUnion(const Index &u, const Index &v) {
Index u_root = find(u), v_root = find(v) ;
Index u_rank = rank(u), v_rank = rank(v) ;
if ( u_root != v_root ) {
if ( v_rank > u_rank ) {
parent_[u_root] = v_root ;
rank_[v_root] += rank_[u_root] ;
return v_root ;
}
else {
parent_[v_root] = u_root ;
rank_[u_root] += rank_[v_root] ;
return u_root ;
}
}
return u_root ;
}
Index SubgraphSolver::DisjointSet::find(const Index &u) {
vector<Index> path ;
Index x = u;
Index x_root = parent_[x] ;
// find the root, and keep the vertices along the path
while ( x != x_root ) {
path.push_back(x) ;
x = x_root ;
x_root = parent_[x] ;
}
// path compression
BOOST_FOREACH(const Index &i, path) {
rank_[i] = 1 ;
parent_[i] = x_root ;
}
return x_root ;
}
} // \namespace gtsam

View File

@ -82,31 +82,6 @@ protected:
boost::tuple<GaussianFactorGraph::shared_ptr, GaussianFactorGraph::shared_ptr>
splitGraph(const GaussianFactorGraph &gfg) ;
public:
// a simplfied implementation of disjoint set data structure.
class DisjointSet {
protected:
size_t n_ ;
std::vector<size_t> rank_ ;
std::vector<Index> parent_ ;
public:
// initialize a disjoint set, point every vertex to itself
DisjointSet(const size_t n) ;
inline size_t size() const { return n_ ; }
// union the root of u and and the root of v, return the root of u and v
Index makeUnion(const Index &u, const Index &v) ;
// return the root of u
Index find(const Index &u) ;
// return the rank of x, which is defined as the cardinality of the set containing x
inline size_t rank(const Index &x) {return rank_[find(x)] ;}
};
};
} // namespace gtsam

View File

@ -0,0 +1,43 @@
/* ----------------------------------------------------------------------------
* 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
* -------------------------------------------------------------------------- */
/**
* @file Dummy.h
* @brief Dummy class for testing MATLAB memory allocation
* @author Andrew Melim
* @author Frank Dellaert
* @date June 14, 2012
*/
#include <gtsam_unstable/base/Dummy.h>
#include <iostream>
namespace gtsam {
static size_t gDummyCount = 0;
Dummy::Dummy():id(++gDummyCount) {
std::cout << "Dummy constructor " << id << std::endl;
}
Dummy::~Dummy() {
std::cout << "Dummy destructor " << id << std::endl;
}
void Dummy::print(const std::string& s) const {
std::cout << s << "Dummy " << id << std::endl;
}
unsigned char Dummy::dummyTwoVar(unsigned char a) const {
return a;
}
}

View File

@ -17,26 +17,16 @@
* @date June 14, 2012
*/
namespace gtsam {
#include <string>
static size_t gDummyCount;
namespace gtsam {
struct Dummy {
size_t id;
Dummy():id(++gDummyCount) {
std::cout << "Dummy constructor " << id << std::endl;
}
~Dummy() {
std::cout << "Dummy destructor " << id << std::endl;
}
void print(const std::string& s="") const {
std::cout << s << "Dummy " << id << std::endl;
}
unsigned char dummyTwoVar(unsigned char a) const {
return a;
}
Dummy();
~Dummy();
void print(const std::string& s="") const ;
unsigned char dummyTwoVar(unsigned char a) const ;
};
} // namespace gtsam