24 #include <unordered_map>
29 template class EliminatableClusterTree<HybridBayesTree,
30 HybridGaussianFactorGraph>;
31 template class JunctionTree<HybridBayesTree, HybridGaussianFactorGraph>;
53 const std::shared_ptr<HybridEliminationTree::Node>& node,
60 data.junctionTreeNode = std::make_shared<Node>(node->key, node->factors);
64 for (
const auto&
f : node->factors) {
65 if (
auto hf = std::dynamic_pointer_cast<HybridFactor>(
f)) {
66 for (
auto& k : hf->discreteKeys()) {
67 data.discreteKeys.insert(k.first);
69 }
else if (
auto hf = std::dynamic_pointer_cast<DiscreteFactor>(
f)) {
70 for (
auto& k : hf->discreteKeys()) {
71 data.discreteKeys.insert(k.first);
81 const std::shared_ptr<HybridEliminationTree::Node>& node,
94 symbolicFactors.
reserve(node->factors.size() +
95 data.childSymbolicFactors.size());
102 keyAsOrdering.push_back(node->key);
103 const auto [conditional, separatorFactor] =
107 data.parentData->childSymbolicConditionals.push_back(conditional);
108 data.parentData->childSymbolicFactors.push_back(separatorFactor);
109 data.parentData->discreteKeys.merge(
data.discreteKeys);
113 data.childSymbolicConditionals;
114 jt_node->problemSize_ = (
int)(conditional->size() * symbolicFactors.
size());
118 const size_t nrParents = conditional->nrParents();
119 const size_t nrChildren = jt_node->nrChildren();
120 assert(childConditionals.size() == nrChildren);
123 std::vector<size_t> nrChildrenFrontals = jt_node->nrFrontalsOfChildren();
124 std::vector<bool> merge(nrChildren,
false);
125 size_t nrFrontals = 1;
126 for (
size_t i = 0;
i < nrChildren;
i++) {
128 if (nrParents + nrFrontals == childConditionals[
i]->nrParents()) {
130 data.discreteKeys.exists(conditional->frontals().front());
131 const bool theirType =
132 data.discreteKeys.exists(childConditionals[
i]->frontals().front());
134 if (myType == theirType) {
136 nrFrontals += nrChildrenFrontals[
i];
143 jt_node->mergeChildren(merge);
150 gttic(JunctionTree_FromEliminationTree);
162 rootData.junctionTreeNode =
163 std::make_shared<typename Base::Node>();
166 Data::ConstructorTraversalVisitorPre,
167 Data::ConstructorTraversalVisitorPost);
170 this->addChildrenAsRoots(rootData.junctionTreeNode);