34 template <
class GRAPH>
39 nrFrontals.push_back(child->nrFrontals());
44 template <
class GRAPH>
48 cluster->orderedFrontalKeys.rend());
49 factors.push_back(cluster->factors);
50 children.insert(
children.end(), cluster->children.begin(), cluster->children.end());
58 const std::vector<bool>&
merge) {
59 gttic(Cluster_mergeChildren);
60 assert(merge.size() == this->
children.size());
65 size_t nrNewChildren = 0;
70 nrKeys += child->orderedFrontalKeys.size();
71 nrFactors += child->factors.size();
72 nrNewChildren += child->nrChildren();
81 this->children.clear();
82 this->children.reserve(nrNewChildren);
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;
168 parentData(_parentData), bayesTreeNode(
std::
make_shared<BTNode>())
175 parentData->writeLock->lock();
180 parentData->writeLock->unlock();
189 parentData->
bayesTreeNode->children.push_back(bayesTreeNode);
213 typename CLUSTERTREE::BayesTreeType::Nodes& nodesIndex) :
214 eliminationFunction_(eliminationFunction), nodesIndex_(nodesIndex) {
222 FactorGraphType gatheredFactors;
223 gatheredFactors.reserve(node->factors.size() + node->nrChildren());
224 gatheredFactors.push_back(node->factors);
229 for (
const sharedFactor& factor: 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>
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};
SymbolicEliminationTree::sharedNode sharedNode
void PrintKeyVector(const KeyVector &keys, const string &s, const KeyFormatter &keyFormatter)
Utility function to print sets of keys with optional prefix.
FactorGraphType factors
Factors associated with this node.
FastVector< sharedNode > roots_
std::pair< std::shared_ptr< BayesTreeType >, std::shared_ptr< FactorGraphType > > eliminate(const Eliminate &function) const
std::vector< T, typename internal::FastDefaultVectorAllocator< T >::type > FastVector
void merge(const std::shared_ptr< Cluster > &cluster)
Merge in given cluster.
void addChild(const std::shared_ptr< Cluster > &cluster)
Add a child cluster.
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
void operator()(const typename CLUSTERTREE::sharedNode &node, EliminationData &myData)
This & operator=(const This &other)
size_t nrFrontals() const
EliminationData *const parentData
CLUSTERTREE::FactorGraphType FactorGraphType
size_t nrChildren() const
static const size_t nrKeys
gtsam::enable_if_t< needs_eigen_aligned_allocator< T >::value, std::shared_ptr< T > > make_shared(Args &&... args)
void DepthFirstForestParallel(FOREST &forest, DATA &rootData, VISITOR_PRE &visitorPre, VISITOR_POST &visitorPost, int problemSizeThreshold=10)
EliminationData(EliminationData *_parentData, size_t nChildren)
std::vector< size_t > nrFrontalsOfChildren() const
Return a vector with nrFrontal keys for each child.
CLUSTERTREE::ConditionalType ConditionalType
void PrintForest(const FOREST &forest, std::string str, const KeyFormatter &keyFormatter)
CLUSTERTREE::FactorType FactorType
EliminationPostOrderVisitor(const typename CLUSTERTREE::Eliminate &eliminationFunction, typename CLUSTERTREE::BayesTreeType::Nodes &nodesIndex)
static sharedNode Node(Key key, const SymbolicFactorGraph &factors, const ChildNodes::Result &children)
std::shared_ptr< BTNode > bayesTreeNode
static EliminationData EliminationPreOrderVisitor(const typename CLUSTERTREE::sharedNode &node, EliminationData &parentData)
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
FastVector< sharedFactor > childFactors
Bayes Tree is a tree of cliques of a Bayes Chain.
FastVector< std::shared_ptr< typename FOREST::Node > > CloneForest(const FOREST &forest)
Keys orderedFrontalKeys
Frontal keys of this node.
CLUSTERTREE::BayesTreeType::Node BTNode
This & operator=(const This &other)
Children children
sub-trees
const TREE::Eliminate & eliminationFunction
void reverse(const MatrixType &m)
std::shared_ptr< FactorType > sharedFactor
Shared pointer to a factor.
CLUSTERTREE::sharedFactor sharedFactor
CLUSTERTREE::BayesTreeType::Nodes & nodesIndex_
SymbolicFactorGraph ::Eliminate Eliminate
Typedef for an eliminate subroutine.
FastVector< sharedFactor > remainingFactors_
void mergeChildren(const std::vector< bool > &merge)
Merge all children for which bit is set into this node.
std::shared_ptr< FactorType > sharedFactor
Shared pointer to a factor.
std::uint64_t Key
Integer nonlinear key type.
Collects factorgraph fragments defined on variable clusters, arranged in a tree.
virtual void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
print this node
const CLUSTERTREE::Eliminate & eliminationFunction_