add nrKeys and set

release/4.3a0
Kai Ni 2010-04-09 23:36:13 +00:00
parent 6355b128fc
commit 0142cc3d3f
4 changed files with 26 additions and 2 deletions

View File

@ -105,6 +105,14 @@ namespace gtsam {
return partitions; return partitions;
} }
// get the nodes in the given tree
Set set(const Label& label) {
Set set;
BOOST_FOREACH(const KeyLabel& pair, (Tree)*this)
if (pair.second==label) set.insert(pair.first);
return set;
}
/** equality */ /** equality */
bool operator==(const Self& t) const { return (Tree)*this == (Tree)t; } bool operator==(const Self& t) const { return (Tree)*this == (Tree)t; }

View File

@ -407,8 +407,7 @@ std::pair<FactorGraph<Factor>, FactorGraph<Factor> > FactorGraph<Factor>::splitM
DSF<Symbol> dsf(keys()); DSF<Symbol> dsf(keys());
// while G is nonempty and T is not yet spanning // while G is nonempty and T is not yet spanning
size_t m = nrFactors(); for (size_t i=0;i<size();i++) {
for (size_t i=0;i<m;i++) {
const sharedFactor& f = factors_[i]; const sharedFactor& f = factors_[i];
// retrieve the labels of all the keys // retrieve the labels of all the keys

View File

@ -92,6 +92,9 @@ namespace gtsam {
/** return keys in some random order */ /** return keys in some random order */
Ordering keys() const; Ordering keys() const;
/** return the number of the keys */
inline size_t nrKeys() const {return indices_.size(); };
/** Check whether a factor with this variable exists */ /** Check whether a factor with this variable exists */
bool involves(const Symbol& key) const { bool involves(const Symbol& key) const {
return !(indices_.find(key)==indices_.end()); return !(indices_.find(key)==indices_.end());

View File

@ -181,6 +181,20 @@ TEST(DSF, partition3) {
CHECK(expected == partitions[dsf.findSet(5)]); CHECK(expected == partitions[dsf.findSet(5)]);
} }
/* ************************************************************************* */
TEST(DSF, set) {
DSFInt dsf;
dsf = dsf.makeSet(5);
dsf = dsf.makeSet(6);
dsf = dsf.makeSet(7);
dsf = dsf.makeUnion(5,6);
set<int> set = dsf.set(5);
LONGS_EQUAL(2, set.size());
std::set<int> expected; expected += 5, 6;
CHECK(expected == set);
}
/* ************************************************************************* */ /* ************************************************************************* */
int func(const int& a) { return a + 10; } int func(const int& a) { return a + 10; }
TEST(DSF, map) { TEST(DSF, map) {