29 template <
class GRAPH>
34 nrFrontals.push_back(child->nrFrontals());
39 template <
class GRAPH>
43 cluster->orderedFrontalKeys.rend());
44 factors.push_back(cluster->factors);
45 children.insert(
children.end(), cluster->children.begin(), cluster->children.end());
53 const std::vector<bool>&
merge) {
54 gttic(Cluster_mergeChildren);
55 assert(merge.size() == this->
children.size());
60 size_t nrNewChildren = 0;
65 nrKeys += child->orderedFrontalKeys.size();
66 nrFactors += child->factors.size();
67 nrNewChildren += child->nrChildren();
76 this->children.clear();
77 this->children.reserve(nrNewChildren);
93 template <
class GRAPH>
99 template <
class GRAPH>
110 template<
class CLUSTERTREE>
117 typedef typename CLUSTERTREE::BayesTreeType::Node
BTNode;
136 parentData->
bayesTreeNode->children.push_back(bayesTreeNode);
142 const typename CLUSTERTREE::sharedNode& node,
160 typename CLUSTERTREE::BayesTreeType::Nodes& nodesIndex) :
161 eliminationFunction_(eliminationFunction), nodesIndex_(nodesIndex) {
169 FactorGraphType gatheredFactors;
170 gatheredFactors.reserve(node->factors.size() + node->nrChildren());
171 gatheredFactors += node->factors;
176 for (
const sharedFactor& factor: node->factors) {
185 auto eliminationResult = eliminationFunction_(gatheredFactors, node->orderedFrontalKeys);
190 myData.
bayesTreeNode->setEliminationResult(eliminationResult);
199 if (!eliminationResult.second->empty())
206 template<
class BAYESTREE,
class GRAPH>
213 remainingFactors_ = other.remainingFactors_;
219 template <
class BAYESTREE,
class GRAPH>
220 std::pair<boost::shared_ptr<BAYESTREE>, boost::shared_ptr<GRAPH> >
222 gttic(ClusterTree_eliminate);
226 boost::shared_ptr<BayesTreeType>
result = boost::make_shared<BayesTreeType>();
229 Data rootsContainer(0, this->
nrRoots());
231 typename Data::EliminationPostOrderVisitor visitorPost(
function, result->nodes_);
239 result->roots_.insert(result->roots_.end(), rootsContainer.bayesTreeNode->children.begin(),
240 rootsContainer.bayesTreeNode->children.end());
243 boost::shared_ptr<FactorGraphType> remaining = boost::make_shared<FactorGraphType>();
244 remaining->reserve(remainingFactors_.size() + rootsContainer.childFactors.size());
245 remaining->push_back(remainingFactors_.begin(), remainingFactors_.end());
246 for (
const sharedFactor& factor : rootsContainer.childFactors) {
248 remaining->push_back(factor);
252 return std::make_pair(result, remaining);
gtsam::enable_if_t< needs_eigen_aligned_allocator< T >::value, boost::shared_ptr< T > > make_shared(Args &&...args)
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
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.
virtual void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
print this node
FastVector< sharedNode > roots_
std::pair< boost::shared_ptr< BayesTreeType >, boost::shared_ptr< FactorGraphType > > eliminate(const Eliminate &function) const
void operator()(const typename CLUSTERTREE::sharedNode &node, EliminationData &myData)
This & operator=(const This &other)
boost::shared_ptr< FactorType > sharedFactor
Shared pointer to a factor.
EliminationData *const parentData
CLUSTERTREE::FactorGraphType FactorGraphType
static const size_t nrKeys
void DepthFirstForestParallel(FOREST &forest, DATA &rootData, VISITOR_PRE &visitorPre, VISITOR_POST &visitorPost, int problemSizeThreshold=10)
std::vector< size_t > nrFrontalsOfChildren() const
Return a vector with nrFrontal keys for each child.
EliminationData(EliminationData *_parentData, size_t nChildren)
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
CLUSTERTREE::ConditionalType ConditionalType
void PrintForest(const FOREST &forest, std::string str, const KeyFormatter &keyFormatter)
boost::shared_ptr< BTNode > bayesTreeNode
CLUSTERTREE::FactorType FactorType
EliminationPostOrderVisitor(const typename CLUSTERTREE::Eliminate &eliminationFunction, typename CLUSTERTREE::BayesTreeType::Nodes &nodesIndex)
FastVector< boost::shared_ptr< typename FOREST::Node > > CloneForest(const FOREST &forest)
static EliminationData EliminationPreOrderVisitor(const typename CLUSTERTREE::sharedNode &node, EliminationData &parentData)
size_t nrChildren() const
FastVector< sharedFactor > childFactors
Bayes Tree is a tree of cliques of a Bayes Chain.
Keys orderedFrontalKeys
Frontal keys of this node.
CLUSTERTREE::BayesTreeType::Node BTNode
size_t nrFrontals() const
This & operator=(const This &other)
Children children
sub-trees
const TREE::Eliminate & eliminationFunction
void reverse(const MatrixType &m)
CLUSTERTREE::sharedFactor sharedFactor
void addChild(const boost::shared_ptr< Cluster > &cluster)
Add a child cluster.
std::vector< T, typename internal::FastDefaultVectorAllocator< T >::type > FastVector
void merge(const boost::shared_ptr< Cluster > &cluster)
Merge in given cluster.
CLUSTERTREE::BayesTreeType::Nodes & nodesIndex_
GRAPH::Eliminate Eliminate
Typedef for an eliminate subroutine.
boost::shared_ptr< FactorType > sharedFactor
Shared pointer to a factor.
void mergeChildren(const std::vector< bool > &merge)
Merge all children for which bit is set into this node.
std::uint64_t Key
Integer nonlinear key type.
const CLUSTERTREE::Eliminate & eliminationFunction_