24 #include <unordered_map>
30 template class EliminatableClusterTree<HybridBayesTree,
31 HybridGaussianFactorGraph>;
32 template class JunctionTree<HybridBayesTree, HybridGaussianFactorGraph>;
54 const std::shared_ptr<HybridEliminationTree::Node>& node,
61 data.junctionTreeNode = std::make_shared<Node>(node->key, node->factors);
65 for (
const auto&
f : node->factors) {
66 if (
auto hf = std::dynamic_pointer_cast<HybridFactor>(
f)) {
67 for (
auto& k : hf->discreteKeys()) {
68 data.discreteKeys.insert(k.first);
70 }
else if (
auto hf = std::dynamic_pointer_cast<DiscreteFactor>(
f)) {
71 for (
auto& k : hf->discreteKeys()) {
72 data.discreteKeys.insert(k.first);
82 const std::shared_ptr<HybridEliminationTree::Node>& node,
95 symbolicFactors.
reserve(node->factors.size() +
96 data.childSymbolicFactors.size());
103 keyAsOrdering.push_back(node->key);
104 const auto [conditional, separatorFactor] =
108 data.parentData->childSymbolicConditionals.push_back(conditional);
109 data.parentData->childSymbolicFactors.push_back(separatorFactor);
110 data.parentData->discreteKeys.merge(
data.discreteKeys);
114 data.childSymbolicConditionals;
115 jt_node->problemSize_ = (
int)(conditional->size() * symbolicFactors.
size());
119 const size_t nrParents = conditional->nrParents();
120 const size_t nrChildren = jt_node->nrChildren();
121 assert(childConditionals.size() == nrChildren);
124 std::vector<size_t> nrChildrenFrontals = jt_node->nrFrontalsOfChildren();
125 std::vector<bool> merge(nrChildren,
false);
126 size_t nrFrontals = 1;
127 for (
size_t i = 0;
i < nrChildren;
i++) {
129 if (nrParents + nrFrontals == childConditionals[
i]->nrParents()) {
131 data.discreteKeys.exists(conditional->frontals().front());
132 const bool theirType =
133 data.discreteKeys.exists(childConditionals[
i]->frontals().front());
135 if (myType == theirType) {
137 nrFrontals += nrChildrenFrontals[
i];
144 jt_node->mergeChildren(merge);
151 gttic(JunctionTree_FromEliminationTree);
163 rootData.junctionTreeNode =
164 std::make_shared<typename Base::Node>();
167 Data::ConstructorTraversalVisitorPre,
168 Data::ConstructorTraversalVisitorPost);
171 this->addChildrenAsRoots(rootData.junctionTreeNode);