24#include <gtsam/inference/ClusterTree-inst.h>
30template<
class BAYESTREE,
class GRAPH,
class ETREE_NODE>
33 typedef typename JunctionTree<BAYESTREE, GRAPH>::sharedNode sharedNode;
37 FastVector<SymbolicConditional::shared_ptr> childSymbolicConditionals;
38 FastVector<SymbolicFactor::shared_ptr> childSymbolicFactors;
45 parentData(_parentData) {
50 const boost::shared_ptr<ETREE_NODE>& node,
56 myData.myJTNode = boost::make_shared<Node>(node->key, node->factors);
57 parentData.myJTNode->addChild(myData.myJTNode);
62 static void ConstructorTraversalVisitorPostAlg2(
63 const boost::shared_ptr<ETREE_NODE>& ETreeNode,
64 const ConstructorTraversalData& myData) {
75 SymbolicFactors symbolicFactors;
76 symbolicFactors.reserve(
77 ETreeNode->factors.size() + myData.childSymbolicFactors.size());
79 symbolicFactors += ETreeNode->factors;
81 symbolicFactors += myData.childSymbolicFactors;
84 keyAsOrdering.push_back(ETreeNode->key);
87 boost::tie(myConditional, mySeparatorFactor) = internal::EliminateSymbolic(
88 symbolicFactors, keyAsOrdering);
91 myData.parentData->childSymbolicConditionals.push_back(myConditional);
92 myData.parentData->childSymbolicFactors.push_back(mySeparatorFactor);
94 sharedNode node = myData.myJTNode;
95 const FastVector<SymbolicConditional::shared_ptr>& childConditionals =
96 myData.childSymbolicConditionals;
97 node->problemSize_ = (int) (myConditional->size() * symbolicFactors.size());
101 const size_t myNrParents = myConditional->nrParents();
102 const size_t nrChildren = node->nrChildren();
103 assert(childConditionals.size() == nrChildren);
106 std::vector<size_t> nrFrontals = node->nrFrontalsOfChildren();
107 std::vector<bool> merge(nrChildren,
false);
108 size_t myNrFrontals = 1;
109 for (
size_t i = 0;i<nrChildren;i++){
111 if (myNrParents + myNrFrontals == childConditionals[i]->nrParents()) {
113 myNrFrontals += nrFrontals[i];
119 node->mergeChildren(merge);
124template<
class BAYESTREE,
class GRAPH>
125template<
class ETREE_BAYESNET,
class ETREE_GRAPH>
128 gttic(JunctionTree_FromEliminationTree);
141 rootData.myJTNode = boost::make_shared<typename Base::Node>();
144 Data::ConstructorTraversalVisitorPre,
145 Data::ConstructorTraversalVisitorPostAlg2);
148 this->addChildrenAsRoots(rootData.myJTNode);
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
void DepthFirstForest(FOREST &forest, DATA &rootData, VISITOR_PRE &visitorPre, VISITOR_POST &visitorPost)
Traverse a forest depth-first with pre-order and post-order visits.
Definition: treeTraversal-inst.h:77
A factor graph is a bipartite graph with factor nodes connected to variable nodes.
Definition: FactorGraph.h:93
A Cluster is just a collection of factors.
Definition: ClusterTree.h:36
An elimination tree is a data structure used intermediately during elimination.
Definition: EliminationTree.h:52
const FastVector< sharedFactor > & remainingFactors() const
Return the remaining factors that are not pulled into elimination.
Definition: EliminationTree.h:154
Definition: EliminationTree.h:66
Definition: JunctionTree-inst.h:31
Definition: JunctionTree-inst.h:41
Definition: JunctionTree.h:50
Definition: Ordering.h:34
boost::shared_ptr< This > shared_ptr
Typedef to the conditional base class.
Definition: SymbolicConditional.h:44
boost::shared_ptr< This > shared_ptr
Overriding the shared_ptr typedef.
Definition: SymbolicFactor.h:48