25 #include <boost/assign/list_of.hpp> 26 #include <boost/assign/std/vector.hpp> 27 #include <boost/assign/std/list.hpp> 28 #include <boost/range/adaptor/indirected.hpp> 30 using boost::adaptors::indirected;
36 using namespace gtsam;
45 template<
typename KEYS>
48 return boost::make_shared<SymbolicBayesTreeClique>(
49 boost::make_shared<SymbolicConditional>(
50 SymbolicConditional::FromKeys(keys, nrFrontals)));
53 template<
typename KEYS,
typename CHILDREN>
55 const KEYS& keys,
DenseIndex nrFrontals,
const CHILDREN& children)
58 boost::make_shared<SymbolicBayesTreeClique>(
59 boost::make_shared<SymbolicConditional>(
60 SymbolicConditional::FromKeys(keys, nrFrontals)));
61 clique->children.assign(children.begin(), children.end());
62 for(
typename CHILDREN::const_iterator child = children.begin(); child != children.end(); ++child)
63 (*child)->parent_ = clique;
103 MakeClique(list_of(
X(2)) (
X(3)), 2, list_of
104 (MakeClique(list_of(
X(4)) (
X(3)), 1, list_of
105 (MakeClique(list_of(
X(5)) (
L(2)) (
X(4)), 2, list_of
106 (MakeClique(list_of(
L(3)) (
X(4)) (
X(5)), 1))))))
107 (MakeClique(list_of(
X(1)) (
L(1)) (
X(2)), 2))));
109 Ordering order = list_of(
X(1)) (
L(3)) (
L(1)) (
X(5)) (
X(2)) (
L(2)) (
X(4)) (
X(3));
129 MakeClique(list_of(_A_)(
_B_), 2, list_of
130 (MakeClique(list_of(
_C_)(_A_), 1, list_of
131 (MakeClique(list_of(
_D_)(
_C_), 1))))
132 (MakeClique(list_of(_E_)(
_B_), 1, list_of
133 (MakeClique(list_of(_F_)(_E_), 1))))));
142 SymbolicBayesTree::Cliques expectedOrphans;
143 expectedOrphans += bayesTree[
_D_], bayesTree[_E_];
146 SymbolicBayesTree::Cliques orphans;
147 bayesTree.removePath(bayesTree[
_C_], &bn, &orphans);
152 bayesTree = bayesTreeOrig;
158 SymbolicBayesTree::Cliques expectedOrphans2;
159 expectedOrphans2 += bayesTree[_F_];
160 expectedOrphans2 += bayesTree[
_C_];
163 SymbolicBayesTree::Cliques orphans2;
164 bayesTree.removePath(bayesTree[_E_], &bn2, &orphans2);
177 SymbolicBayesTree::Cliques orphans;
185 SymbolicBayesTree::Cliques expectedOrphans;
186 expectedOrphans += bayesTree[_S_], bayesTree[_T_], bayesTree[_X_];
197 SymbolicBayesTree::Cliques orphans;
198 bayesTree.
removePath(bayesTree[_T_], &bn, &orphans);
206 SymbolicBayesTree::Cliques expectedOrphans;
207 expectedOrphans += bayesTree[_S_], bayesTree[_X_];
211 void getAllCliques(
const SymbolicBayesTree::sharedClique& subtree, SymbolicBayesTree::Cliques& cliques) {
214 cliques.push_back(subtree);
216 for(SymbolicBayesTree::sharedClique& childClique: subtree->children) {
239 SymbolicBayesTree::sharedClique rootClique = bayesTree.
roots().front();
241 SymbolicBayesTree::Cliques allCliques;
244 for(SymbolicBayesTree::sharedClique& clique: allCliques) {
252 rootClique->deleteCachedShortcuts();
253 for(SymbolicBayesTree::sharedClique& clique: allCliques) {
254 bool notCleared = clique->cachedSeparatorMarginal().is_initialized();
255 CHECK( notCleared ==
false);
281 SymbolicBayesTree::Cliques orphans;
286 expected += SymbolicConditional::FromKeys(list_of(_E_)(
_L_)(
_B_), 3);
287 expected += SymbolicConditional::FromKeys(list_of(_S_)(
_B_)(
_L_), 1);
290 SymbolicBayesTree::Cliques expectedOrphans;
291 expectedOrphans += bayesTree[_T_], bayesTree[_X_];
297 SymbolicBayesTree::Cliques orphans2;
298 bayesTree.removeTop(list_of(
_B_), &bn2, &orphans2);
302 SymbolicBayesTree::Cliques expectedOrphans2;
318 SymbolicBayesTree::Cliques orphans;
319 bayesTree.
removeTop(list_of(_T_), &bn, &orphans);
323 (SymbolicConditional::FromKeys(list_of(_E_)(
_L_)(
_B_), 3))
324 (SymbolicConditional::FromKeys(list_of(_T_)(_E_)(
_L_), 1));
327 SymbolicBayesTree::Cliques expectedOrphans;
328 expectedOrphans += bayesTree[_S_], bayesTree[_X_];
345 SymbolicBayesTree::Cliques orphans;
346 bayesTree.
removeTop(list_of(
L(5))(
X(4))(
X(2))(
X(3)), &bn, &orphans);
349 (SymbolicConditional::FromKeys(list_of(
X(4))(
L(5)), 2))
369 SymbolicBayesTree::Cliques orphans;
370 bayesTree.
removeTop(list_of(
X(2))(
L(5))(
X(4))(
X(3)), &bn, &orphans);
373 (SymbolicConditional::FromKeys(list_of(
X(4))(
L(5)), 2))
394 SymbolicBayesTree::Cliques orphans;
395 bayesTree.
removeTop(list_of(
X(10)), &bn, &orphans);
407 bayesNet.
push_back(boost::make_shared<SymbolicConditional>(14));
409 bayesNet.
push_back(boost::make_shared<SymbolicConditional>(13, 14));
410 bayesNet.
push_back(boost::make_shared<SymbolicConditional>(12, 14));
412 bayesNet.
push_back(boost::make_shared<SymbolicConditional>(11, 13, 14));
413 bayesNet.
push_back(boost::make_shared<SymbolicConditional>(10, 13, 14));
414 bayesNet.
push_back(boost::make_shared<SymbolicConditional>(9, 12, 14));
415 bayesNet.
push_back(boost::make_shared<SymbolicConditional>(8, 12, 14));
417 bayesNet.
push_back(boost::make_shared<SymbolicConditional>(7, 11, 13));
418 bayesNet.
push_back(boost::make_shared<SymbolicConditional>(6, 11, 13));
419 bayesNet.
push_back(boost::make_shared<SymbolicConditional>(5, 10, 13));
420 bayesNet.
push_back(boost::make_shared<SymbolicConditional>(4, 10, 13));
422 bayesNet.
push_back(boost::make_shared<SymbolicConditional>(3, 9, 12));
423 bayesNet.
push_back(boost::make_shared<SymbolicConditional>(2, 9, 12));
424 bayesNet.
push_back(boost::make_shared<SymbolicConditional>(1, 8, 12));
425 bayesNet.
push_back(boost::make_shared<SymbolicConditional>(0, 8, 12));
429 bayesNet.
saveGraph(
"/tmp/symbolicBayesNet.dot");
436 bayesTree.
saveGraph(
"/tmp/SymbolicBayesTree.dot");
491 expected.
push_back(boost::make_shared<SymbolicConditional>(8));
492 expected.
push_back(boost::make_shared<SymbolicConditional>(2, 8));
500 expected.
push_back(boost::make_shared<SymbolicConditional>(2));
501 expected.
push_back(boost::make_shared<SymbolicConditional>(1, 2));
509 expected.
push_back(boost::make_shared<SymbolicConditional>(2, 6));
510 expected.
push_back(boost::make_shared<SymbolicConditional>(6));
518 expected.
push_back(boost::make_shared<SymbolicConditional>(6));
519 expected.
push_back(boost::make_shared<SymbolicConditional>(4, 6));
570 bayesNet.saveGraph(
"/tmp/symbolicBayesNet.dot");
577 bayesTree.
saveGraph(
"/tmp/SymbolicBayesTree.dot");
616 root->children += MakeClique(list_of(9)(10)(11)(12), 2);
617 root->children.back()->parent_ =
root;
619 root->children += MakeClique(list_of(7)(8)(11), 2);
620 root->children.back()->parent_ =
root;
621 cur = root->children.back();
623 cur->children += MakeClique(list_of(5)(6)(7)(8), 2);
624 cur->children.back()->parent_ = cur;
625 cur = cur->children.back();
627 cur->children += MakeClique(list_of(3)(4)(6), 2);
628 cur->children.back()->parent_ = cur;
630 cur->children += MakeClique(list_of(1)(2)(5), 2);
631 cur->children.back()->parent_ = cur;
638 bt.
saveGraph(
"/tmp/SymbolicBayesTree.dot");
718 MakeClique(list_of(4)(2)(3), 3,
720 MakeClique(list_of(1)(2)(4), 1,
722 MakeClique(list_of(5)(1)(4), 1,
723 list_of(MakeClique(list_of(0)(1)(5), 1))))))));
729 #ifdef GTSAM_SUPPORT_NESTED_DISSECTION 734 #if !defined(__APPLE__) 745 #if !defined(__APPLE__) 747 MakeClique(list_of(2)(4)(1), 3,
749 MakeClique(list_of(0)(1)(4), 1,
750 list_of(MakeClique(list_of(5)(0)(4), 1))))(
751 MakeClique(list_of(3)(2)(4), 1))));
754 MakeClique(list_of(1)(0)(3), 3,
756 MakeClique(list_of(4)(0)(3), 1,
757 list_of(MakeClique(list_of(5)(0)(4), 1))))(
758 MakeClique(list_of(2)(1)(3), 1))));
void removePath(sharedClique clique, BayesNetType *bn, Cliques *orphans)
Provides additional testing facilities for common data structures.
boost::shared_ptr< This > shared_ptr
GTSAM_EXPORT void saveGraph(const std::string &s, const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
void removeTop(const KeyVector &keys, BayesNetType *bn, Cliques *orphans)
static int runAllTests(TestResult &result)
boost::shared_ptr< This > shared_ptr
static enum @843 ordering
boost::shared_ptr< BayesTreeType > eliminateMultifrontal(OptionalOrderingType orderingType=boost::none, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex=boost::none) const
Rot2 R(Rot2::fromAngle(0.1))
GaussianFactorGraph factors(list_of(factor1)(factor2)(factor3))
IsDerived< DERIVEDFACTOR > push_back(boost::shared_ptr< DERIVEDFACTOR > factor)
Add a factor directly using a shared_ptr.
const mpreal root(const mpreal &x, unsigned long int k, mp_rnd_t r=mpreal::get_default_rnd())
NonlinearFactorGraph graph
Matrix< SCALARB, Dynamic, Dynamic > B
ptrdiff_t DenseIndex
The index type for Eigen objects.
void insertRoot(const sharedClique &subtree)
sharedConditional marginalFactor(Key j, const Eliminate &function=EliminationTraitsType::DefaultEliminate) const
sharedBayesNet jointBayesNet(Key j1, Key j2, const Eliminate &function=EliminationTraitsType::DefaultEliminate) const
void push_factor(Key key)
#define EXPECT(condition)
void saveGraph(const std::string &s, const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
boost::shared_ptr< This > shared_ptr
Array< double, 1, 3 > e(1./3., 0.5, 2.)
bool assert_container_equal(const std::map< V1, V2 > &expected, const std::map< V1, V2 > &actual, double tol=1e-9)
Matrix< Scalar, Dynamic, Dynamic > C
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
#define EXPECT_LONGS_EQUAL(expected, actual)
void getAllCliques(const SymbolicBayesTree::sharedClique &subtree, SymbolicBayesTree::Cliques &cliques)
boost::shared_ptr< BayesNetType > eliminateSequential(OptionalOrderingType orderingType=boost::none, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex=boost::none) const
TEST(SymbolicBayesTree, clear)
const Roots & roots() const
std::uint64_t Key
Integer nonlinear key type.