35 template <
class GRAPH>
37 std::vector<size_t> nrFrontals;
38 nrFrontals.reserve(nrChildren());
40 nrFrontals.push_back(child->nrFrontals());
45 template <
class GRAPH>
48 orderedFrontalKeys.insert(orderedFrontalKeys.end(), cluster->orderedFrontalKeys.rbegin(),
49 cluster->orderedFrontalKeys.rend());
50 factors.push_back(cluster->factors);
51 children.insert(children.end(), cluster->children.begin(), cluster->children.end());
53 problemSize_ =
std::max(problemSize_, cluster->problemSize_);
59 const std::vector<bool>& merge) {
60 gttic(Cluster_mergeChildren);
61 assert(merge.size() ==
this->children.size());
64 size_t nrKeys = orderedFrontalKeys.size();
65 size_t nrFactors =
factors.size();
66 size_t nrNewChildren = 0;
71 nrKeys += child->orderedFrontalKeys.size();
72 nrFactors += child->factors.size();
73 nrNewChildren += child->nrChildren();
81 auto oldChildren = this->children;
82 this->children.clear();
83 this->children.reserve(nrNewChildren);
84 orderedFrontalKeys.reserve(
nrKeys);
91 this->addChild(child);
95 std::reverse(orderedFrontalKeys.begin(), orderedFrontalKeys.end());
99 template <
class GRAPH>
111 template <
class GRAPH>
115 for (
auto&& root :
roots_) {
116 std::queue<sharedNode> bfs_queue;
118 bfs_queue.push(root);
123 while (!bfs_queue.empty()) {
125 auto node = bfs_queue.front();
129 for (
auto child : node->children) {
130 bfs_queue.push(child);
140 template <
class GRAPH>
151 template<
class CLUSTERTREE>
165 std::shared_ptr<std::mutex> writeLock;
178 myIndexInParent =
parentData->childFactors.size();
189 bayesTreeNode->parent_ =
parentData->bayesTreeNode;
190 parentData->bayesTreeNode->children.push_back(bayesTreeNode);
214 typename CLUSTERTREE::BayesTreeType::Nodes& nodesIndex) :
224 gatheredFactors.reserve(node->factors.size() + node->nrChildren());
225 gatheredFactors.push_back(node->factors);
239 auto eliminationResult = eliminationFunction_(gatheredFactors, node->orderedFrontalKeys);
244 myData.
bayesTreeNode->setEliminationResult(eliminationResult);
257 if (!eliminationResult.second->empty()) {
271 template<
class BAYESTREE,
class GRAPH>
278 remainingFactors_ =
other.remainingFactors_;
284 template <
class BAYESTREE,
class GRAPH>
285 std::pair<std::shared_ptr<BAYESTREE>, std::shared_ptr<GRAPH> >
287 gttic(ClusterTree_eliminate);
291 std::shared_ptr<BayesTreeType>
result = std::make_shared<BayesTreeType>();
294 Data rootsContainer(0, this->
nrRoots());
296 typename Data::EliminationPostOrderVisitor visitorPost(
function,
result->nodes_);
304 result->roots_.insert(
result->roots_.end(), rootsContainer.bayesTreeNode->children.begin(),
305 rootsContainer.bayesTreeNode->children.end());
308 std::shared_ptr<FactorGraphType> remaining = std::make_shared<FactorGraphType>();
309 remaining->reserve(remainingFactors_.size() + rootsContainer.childFactors.size());
310 remaining->push_back(remainingFactors_.begin(), remainingFactors_.end());
313 remaining->push_back(
factor);
317 return {
result, remaining};