Awesome recursive version of removePath

release/4.3a0
Frank Dellaert 2009-11-21 06:14:53 +00:00
parent 072846a70f
commit 00b5b25591
2 changed files with 7 additions and 24 deletions

View File

@ -352,32 +352,15 @@ namespace gtsam {
FactorGraph<Factor>
BayesTree<Conditional>::removePath(sharedClique clique) {
//if (clique==NULL) return;
// base case is NULL, return empty factor graph
if (clique==NULL) return FactorGraph<Factor>();
bool verbose = false;
if (verbose) {
clique->print("removing");
cout << "before" << endl;
BOOST_FOREACH(typename Nodes::value_type clique, nodes_)
clique.second->print();
}
// remove path above me
FactorGraph<Factor> factors = removePath<Factor>(clique->parent_);
// convert clique to factor
FactorGraph<Factor> factors(*clique);// = removePath(clique->parent_);
while (!(clique->isRoot())) {
sharedClique old_clique = clique;
clique = old_clique->parent_;
removeClique(old_clique);
factors.push_back(*clique);
}
// remove me and add my factors
removeClique(clique);
if (verbose) {
cout << "after" << endl;
BOOST_FOREACH(typename Nodes::value_type clique, nodes_)
clique.second->print();
}
factors.push_back(*clique);
return factors;
}

View File

@ -328,9 +328,9 @@ TEST( BayesTree, removePath )
// remove C, expected outcome: factor graph with ABC,
// Bayes Tree now contains two orphan trees: D|C and E|B,F|E
SymbolicFactorGraph expected;
expected.push_factor("A","C");
expected.push_factor("A","B");
expected.push_factor("A");
expected.push_factor("A","C");
SymbolicFactorGraph actual = bayesTree.removePath<SymbolicFactor>(bayesTree["C"]);
CHECK(assert_equal(expected, actual));