diff --git a/.cproject b/.cproject index 3d81f6b05..307d0f1cb 100644 --- a/.cproject +++ b/.cproject @@ -322,14 +322,6 @@ true true - - make - -j2 - testGaussianFactor.run - true - true - true - make -j2 @@ -356,6 +348,7 @@ make + tests/testBayesTree.run true false @@ -363,6 +356,7 @@ make + testBinaryBayesNet.run true false @@ -410,6 +404,7 @@ make + testSymbolicBayesNet.run true false @@ -417,6 +412,7 @@ make + tests/testSymbolicFactor.run true false @@ -424,6 +420,7 @@ make + testSymbolicFactorGraph.run true false @@ -439,11 +436,20 @@ make + tests/testBayesTree true false true + + make + -j2 + testGaussianFactor.run + true + true + true + make -j2 @@ -478,7 +484,6 @@ make - testGraph.run true false @@ -574,7 +579,6 @@ make - testInference.run true false @@ -582,7 +586,6 @@ make - testGaussianBayesNet.run true false @@ -590,7 +593,6 @@ make - testGaussianFactor.run true false @@ -598,7 +600,6 @@ make - testJunctionTree.run true false @@ -606,7 +607,6 @@ make - testSymbolicBayesNet.run true false @@ -614,7 +614,6 @@ make - testSymbolicFactorGraph.run true false @@ -958,6 +957,7 @@ make + testErrors.run true false @@ -1317,7 +1317,6 @@ make - testSimulated2DOriented.run true false @@ -1357,7 +1356,6 @@ make - testSimulated2D.run true false @@ -1365,7 +1363,6 @@ make - testSimulated3D.run true false @@ -1379,6 +1376,14 @@ true true + + make + -j2 + tests/testDSFVector.run + true + true + true + make -j2 @@ -1445,7 +1450,6 @@ make - tests/testGaussianISAM2 true false @@ -1467,6 +1471,86 @@ true true + + make + -j2 + install + true + true + true + + + make + -j2 + clean + true + true + true + + + make + -j2 + check + true + true + true + + + make + -j2 + all + true + true + true + + + make + -j2 + dist + true + true + true + + + make + -j2 + inference/tests/testEliminationTree + true + true + true + + + make + -j2 + slam/tests/testGaussianISAM2 + true + true + true + + + make + -j2 + inference/tests/testVariableIndex + true + true + true + + + make + -j2 + inference/tests/testJunctionTree + true + true + true + + + make + -j2 + linear/tests/testGaussianJunctionTree + true + true + true + make -j2 @@ -1563,94 +1647,6 @@ true true - - make - -j2 - install - true - true - true - - - make - -j2 - clean - true - true - true - - - make - -j2 - check - true - true - true - - - make - -j2 - all - true - true - true - - - make - -j2 - dist - true - true - true - - - make - -j2 - inference/tests/testEliminationTree - true - true - true - - - make - -j2 - slam/tests/testGaussianISAM2 - true - true - true - - - make - -j2 - inference/tests/testVariableIndex - true - true - true - - - make - -j2 - inference/tests/testJunctionTree - true - true - true - - - make - -j2 - linear/tests/testGaussianJunctionTree - true - true - true - - - make - -j2 - check - true - true - true - make -j2 @@ -1683,6 +1679,14 @@ true true + + make + -j2 + check + true + true + true + @@ -2005,14 +2009,6 @@ true true - - make - -j2 - testGaussianFactor.run - true - true - true - make -j2 @@ -2039,6 +2035,7 @@ make + tests/testBayesTree.run true false @@ -2046,6 +2043,7 @@ make + testBinaryBayesNet.run true false @@ -2093,6 +2091,7 @@ make + testSymbolicBayesNet.run true false @@ -2100,6 +2099,7 @@ make + tests/testSymbolicFactor.run true false @@ -2107,6 +2107,7 @@ make + testSymbolicFactorGraph.run true false @@ -2122,11 +2123,20 @@ make + tests/testBayesTree true false true + + make + -j2 + testGaussianFactor.run + true + true + true + make -j2 @@ -2161,7 +2171,6 @@ make - testGraph.run true false @@ -2257,7 +2266,6 @@ make - testInference.run true false @@ -2265,7 +2273,6 @@ make - testGaussianBayesNet.run true false @@ -2273,7 +2280,6 @@ make - testGaussianFactor.run true false @@ -2281,7 +2287,6 @@ make - testJunctionTree.run true false @@ -2289,7 +2294,6 @@ make - testSymbolicBayesNet.run true false @@ -2297,7 +2301,6 @@ make - testSymbolicFactorGraph.run true false @@ -2641,6 +2644,7 @@ make + testErrors.run true false @@ -3000,7 +3004,6 @@ make - testSimulated2DOriented.run true false @@ -3040,7 +3043,6 @@ make - testSimulated2D.run true false @@ -3048,7 +3050,6 @@ make - testSimulated3D.run true false @@ -3062,6 +3063,14 @@ true true + + make + -j2 + tests/testDSFVector.run + true + true + true + make -j2 @@ -3128,7 +3137,6 @@ make - tests/testGaussianISAM2 true false @@ -3150,6 +3158,86 @@ true true + + make + -j2 + install + true + true + true + + + make + -j2 + clean + true + true + true + + + make + -j2 + check + true + true + true + + + make + -j2 + all + true + true + true + + + make + -j2 + dist + true + true + true + + + make + -j2 + inference/tests/testEliminationTree + true + true + true + + + make + -j2 + slam/tests/testGaussianISAM2 + true + true + true + + + make + -j2 + inference/tests/testVariableIndex + true + true + true + + + make + -j2 + inference/tests/testJunctionTree + true + true + true + + + make + -j2 + linear/tests/testGaussianJunctionTree + true + true + true + make -j2 @@ -3246,94 +3334,6 @@ true true - - make - -j2 - install - true - true - true - - - make - -j2 - clean - true - true - true - - - make - -j2 - check - true - true - true - - - make - -j2 - all - true - true - true - - - make - -j2 - dist - true - true - true - - - make - -j2 - inference/tests/testEliminationTree - true - true - true - - - make - -j2 - slam/tests/testGaussianISAM2 - true - true - true - - - make - -j2 - inference/tests/testVariableIndex - true - true - true - - - make - -j2 - inference/tests/testJunctionTree - true - true - true - - - make - -j2 - linear/tests/testGaussianJunctionTree - true - true - true - - - make - -j2 - check - true - true - true - make -j2 @@ -3366,6 +3366,14 @@ true true + + make + -j2 + check + true + true + true + diff --git a/gtsam/base/DSFVector.cpp b/gtsam/base/DSFVector.cpp index 06fb53372..0881465ba 100644 --- a/gtsam/base/DSFVector.cpp +++ b/gtsam/base/DSFVector.cpp @@ -33,37 +33,53 @@ namespace gtsam { } /* ************************************************************************* */ - size_t DSFVector::findSet(const size_t& key) const { + DSFVector::Label DSFVector::findSet(const size_t& key) const { size_t parent = at(key); return parent == key ? key : findSet(parent); } /* ************************************************************************* */ - std::set DSFVector::set(const std::size_t& label) const { + bool DSFVector::isSingleton(const Label& label) const { + bool result = false; + std::vector::const_iterator it = begin(); + for (; it != end(); ++it) { + if(findSet(*it) == label) { + if (!result) // find the first occurrence + result = true; + else + return false; + } + } + return result; + } + + /* ************************************************************************* */ + std::set DSFVector::set(const Label& label) const { std::set set; size_t key = 0; - std::vector::const_iterator it = begin(); + std::vector::const_iterator it = begin(); for (; it != end(); it++, key++) { - if (*it == label || findSet(*it) == label) + if (findSet(*it) == label) set.insert(key); } return set; } /* ************************************************************************* */ - void DSFVector::makeUnionInPlace(const std::size_t& i1, const std::size_t& i2) { - at(findSet(i2)) = findSet(i1); - } - - /* ************************************************************************* */ - std::map > DSFVector::sets() const { - std::map > sets; + std::map > DSFVector::sets() const { + std::map > sets; size_t key = 0; - std::vector::const_iterator it = begin(); + std::vector::const_iterator it = begin(); for (; it != end(); it++, key++) { sets[findSet(*it)].insert(key); } return sets; } -} + /* ************************************************************************* */ + void DSFVector::makeUnionInPlace(const size_t& i1, const size_t& i2) { + at(findSet(i2)) = findSet(i1); + } + +} // namespace + diff --git a/gtsam/base/DSFVector.h b/gtsam/base/DSFVector.h index 16adae1d3..435304ba5 100644 --- a/gtsam/base/DSFVector.h +++ b/gtsam/base/DSFVector.h @@ -27,26 +27,32 @@ namespace gtsam { /** - * A fast impelementation of disjoint set forests + * A fast impelementation of disjoint set forests that uses vector as underly data structure. */ class DSFVector : protected std::vector { private: public: + typedef size_t Label; + // constructor DSFVector(const std::size_t numNodes); // find the label of the set in which {key} lives - size_t findSet(const size_t& key) const; + Label findSet(const size_t& key) const; + + // find whether there is one and only one occurrence for the given {label} + bool isSingleton(const Label& label) const; + + // get the nodes in the tree with the given label + std::set set(const Label& label) const; + + // return all sets, i.e. a partition of all elements + std::map > sets() const; // the in-place version of makeUnion void makeUnionInPlace(const std::size_t& i1, const std::size_t& i2); - // get the nodes in the tree with the given label - std::set set(const std::size_t& label) const; - - // return all sets, i.e. a partition of all elements - std::map > sets() const; }; } diff --git a/gtsam/base/tests/testDSFVector.cpp b/gtsam/base/tests/testDSFVector.cpp index abe3e1ac0..ce4ea7f21 100644 --- a/gtsam/base/tests/testDSFVector.cpp +++ b/gtsam/base/tests/testDSFVector.cpp @@ -113,6 +113,14 @@ TEST(DSFVector, set2) { CHECK(expected == set); } +/* ************************************************************************* */ +TEST(DSFVector, isSingleton) { + DSFVector dsf(3); + dsf.makeUnionInPlace(0,1); + CHECK(!dsf.isSingleton(0)); + CHECK(!dsf.isSingleton(1)); + CHECK( dsf.isSingleton(2)); +} /* ************************************************************************* */ int main() { TestResult tr; return TestRegistry::runAllTests(tr);} /* ************************************************************************* */