34 template <
class GRAPH>
36 std::vector<size_t> nrFrontals;
37 nrFrontals.reserve(nrChildren());
39 nrFrontals.push_back(child->nrFrontals());
44 template <
class GRAPH>
47 orderedFrontalKeys.insert(orderedFrontalKeys.end(), cluster->orderedFrontalKeys.rbegin(),
48 cluster->orderedFrontalKeys.rend());
49 factors.push_back(cluster->factors);
50 children.insert(children.end(), cluster->children.begin(), cluster->children.end());
52 problemSize_ =
std::max(problemSize_, cluster->problemSize_);
58 const std::vector<bool>& merge) {
59 gttic(Cluster_mergeChildren);
60 assert(merge.size() ==
this->children.size());
63 size_t nrKeys = orderedFrontalKeys.size();
64 size_t nrFactors =
factors.size();
65 size_t nrNewChildren = 0;
70 nrKeys += child->orderedFrontalKeys.size();
71 nrFactors += child->factors.size();
72 nrNewChildren += child->nrChildren();
80 auto oldChildren = this->children;
81 this->children.clear();
82 this->children.reserve(nrNewChildren);
83 orderedFrontalKeys.reserve(
nrKeys);
90 this->addChild(child);
94 std::reverse(orderedFrontalKeys.begin(), orderedFrontalKeys.end());
98 template <
class GRAPH>
110 template <
class GRAPH>
114 for (
auto&& root :
roots_) {
115 std::queue<sharedNode> bfs_queue;
117 bfs_queue.push(root);
122 while (!bfs_queue.empty()) {
124 auto node = bfs_queue.front();
128 for (
auto child : node->children) {
129 bfs_queue.push(child);
139 template <
class GRAPH>
150 template<
class CLUSTERTREE>
164 std::shared_ptr<std::mutex> writeLock;
177 myIndexInParent =
parentData->childFactors.size();
188 bayesTreeNode->parent_ =
parentData->bayesTreeNode;
189 parentData->bayesTreeNode->children.push_back(bayesTreeNode);
213 typename CLUSTERTREE::BayesTreeType::Nodes& nodesIndex) :
223 gatheredFactors.reserve(node->factors.size() + node->nrChildren());
224 gatheredFactors.push_back(node->factors);
238 auto eliminationResult = eliminationFunction_(gatheredFactors, node->orderedFrontalKeys);
243 myData.
bayesTreeNode->setEliminationResult(eliminationResult);
256 if (!eliminationResult.second->empty()) {
270 template<
class BAYESTREE,
class GRAPH>
277 remainingFactors_ =
other.remainingFactors_;
283 template <
class BAYESTREE,
class GRAPH>
284 std::pair<std::shared_ptr<BAYESTREE>, std::shared_ptr<GRAPH> >
286 gttic(ClusterTree_eliminate);
290 std::shared_ptr<BayesTreeType>
result = std::make_shared<BayesTreeType>();
293 Data rootsContainer(0, this->
nrRoots());
295 typename Data::EliminationPostOrderVisitor visitorPost(
function,
result->nodes_);
303 result->roots_.insert(
result->roots_.end(), rootsContainer.bayesTreeNode->children.begin(),
304 rootsContainer.bayesTreeNode->children.end());
307 std::shared_ptr<FactorGraphType> remaining = std::make_shared<FactorGraphType>();
308 remaining->reserve(remainingFactors_.size() + rootsContainer.childFactors.size());
309 remaining->push_back(remainingFactors_.begin(), remainingFactors_.end());
310 for (
const sharedFactor& factor : rootsContainer.childFactors) {
312 remaining->push_back(factor);
316 return {
result, remaining};