22#include <boost/shared_ptr.hpp>
34 struct EliminationData {
35 EliminationData*
const parentData;
36 FastVector<typename TREE::sharedFactor> childFactors;
37 EliminationData(EliminationData* _parentData,
size_t nChildren) :
38 parentData(_parentData) { childFactors.reserve(nChildren); }
43 EliminationData<TREE> eliminationPreOrderVisitor(
44 const typename TREE::sharedNode& node, EliminationData<TREE>& parentData)
48 return EliminationData<TREE>(&parentData, node->children.size());
52 template<
class TREE,
class RESULT>
53 struct EliminationPostOrderVisitor
56 const typename TREE::Eliminate& eliminationFunction;
57 EliminationPostOrderVisitor(RESULT& result,
const typename TREE::Eliminate& eliminationFunction) :
58 result(result), eliminationFunction(eliminationFunction) {}
59 void operator()(
const typename TREE::sharedNode& node, EliminationData<TREE>& myData)
62 typename TREE::sharedFactor childFactor = node->eliminate(result, eliminationFunction, myData.childFactors);
63 if(childFactor && !childFactor->empty())
64 myData.parentData->childFactors.push_back(childFactor);
73 template<
class TREE,
class RESULT>
74 FastVector<typename TREE::sharedFactor>
75 EliminateTree(RESULT& result,
const TREE& tree,
const typename TREE::Eliminate& function)
83 EliminationData<TREE> rootData(0, tree.roots().size());
84 EliminationPostOrderVisitor<TREE,RESULT> visitorPost(result, function);
88 return rootData.childFactors;
A thin wrapper around std::vector that uses a custom allocator.
FastVector< typename TREE::sharedFactor > EliminateTree(RESULT &result, const TREE &tree, const typename TREE::Eliminate &function)
Eliminate an elimination tree or a Bayes tree (used internally).
Definition: inference-inst.h:75
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
void DepthFirstForest(FOREST &forest, DATA &rootData, VISITOR_PRE &visitorPre, VISITOR_POST &visitorPost)
Traverse a forest depth-first with pre-order and post-order visits.
Definition: treeTraversal-inst.h:77