Awesome recursive version of removePath
parent
072846a70f
commit
00b5b25591
|
@ -352,32 +352,15 @@ namespace gtsam {
|
||||||
FactorGraph<Factor>
|
FactorGraph<Factor>
|
||||||
BayesTree<Conditional>::removePath(sharedClique clique) {
|
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;
|
// remove path above me
|
||||||
if (verbose) {
|
FactorGraph<Factor> factors = removePath<Factor>(clique->parent_);
|
||||||
clique->print("removing");
|
|
||||||
cout << "before" << endl;
|
|
||||||
BOOST_FOREACH(typename Nodes::value_type clique, nodes_)
|
|
||||||
clique.second->print();
|
|
||||||
}
|
|
||||||
|
|
||||||
// convert clique to factor
|
// remove me and add my factors
|
||||||
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);
|
|
||||||
}
|
|
||||||
removeClique(clique);
|
removeClique(clique);
|
||||||
|
factors.push_back(*clique);
|
||||||
if (verbose) {
|
|
||||||
cout << "after" << endl;
|
|
||||||
BOOST_FOREACH(typename Nodes::value_type clique, nodes_)
|
|
||||||
clique.second->print();
|
|
||||||
}
|
|
||||||
|
|
||||||
return factors;
|
return factors;
|
||||||
}
|
}
|
||||||
|
|
|
@ -328,9 +328,9 @@ TEST( BayesTree, removePath )
|
||||||
// remove C, expected outcome: factor graph with ABC,
|
// remove C, expected outcome: factor graph with ABC,
|
||||||
// Bayes Tree now contains two orphan trees: D|C and E|B,F|E
|
// Bayes Tree now contains two orphan trees: D|C and E|B,F|E
|
||||||
SymbolicFactorGraph expected;
|
SymbolicFactorGraph expected;
|
||||||
expected.push_factor("A","C");
|
|
||||||
expected.push_factor("A","B");
|
expected.push_factor("A","B");
|
||||||
expected.push_factor("A");
|
expected.push_factor("A");
|
||||||
|
expected.push_factor("A","C");
|
||||||
|
|
||||||
SymbolicFactorGraph actual = bayesTree.removePath<SymbolicFactor>(bayesTree["C"]);
|
SymbolicFactorGraph actual = bayesTree.removePath<SymbolicFactor>(bayesTree["C"]);
|
||||||
CHECK(assert_equal(expected, actual));
|
CHECK(assert_equal(expected, actual));
|
||||||
|
|
Loading…
Reference in New Issue