/* * JunctionTree.h * * Created on: Feb 4, 2010 * Author: nikai * Description: The junction tree */ #pragma once #include #include #include "BayesTree.h" #include "SymbolicConditional.h" namespace gtsam { /* ************************************************************************* */ template class JunctionTree : public Testable > { public: // the class for subgraphs that also include the pointers to the parents and two children class Clique : public FG { private: typedef typename boost::shared_ptr shared_ptr; shared_ptr parent_; // the parent subgraph node std::vector children_; // the child cliques Ordering frontal_; // the frontal varaibles Unordered separator_; // the separator variables friend class JunctionTree; public: // empty constructor Clique() {} // constructor with all the information Clique(const FG& fgLocal, const Ordering& frontal, const Unordered& separator, const shared_ptr& parent) : frontal_(frontal), separator_(separator), FG(fgLocal), parent_(parent) {} // constructor for an empty graph Clique(const Ordering& frontal, const Unordered& separator, const shared_ptr& parent) : frontal_(frontal), separator_(separator), parent_(parent) {} // return the members const Ordering& frontal() const { return frontal_;} const Unordered& separator() const { return separator_;} const std::vector& children() { return children_; } // add a child node void addChild(const shared_ptr& child) { children_.push_back(child); } // print the object void print(const std::string& indent) const; void printTree(const std::string& indent) const; // check equality bool equals(const Clique& other) const; }; // typedef for shared pointers to cliques typedef typename Clique::shared_ptr sharedClique; protected: // Root clique sharedClique root_; private: // distribute the factors along the Bayes tree sharedClique distributeFactors(FG& fg, const BayesTree::sharedClique clique); // utility function called by eliminate template std::pair > eliminateOneClique(sharedClique fg_); public: // constructor JunctionTree() {} // constructor given a factor graph and the elimination ordering JunctionTree(FG& fg, const Ordering& ordering); // return the root clique sharedClique root() const { return root_; } // eliminate the factors in the subgraphs template BayesTree eliminate(); // print the object void print(const std::string& str) const { cout << str << endl; if (root_.get()) root_->printTree(""); } /** check equality */ bool equals(const JunctionTree& other, double tol = 1e-9) const; }; // JunctionTree } // namespace gtsam