22 #include <boost/shared_ptr.hpp> 23 #include <boost/bind.hpp> 35 struct EliminationData {
36 EliminationData*
const parentData;
37 FastVector<typename TREE::sharedFactor> childFactors;
38 EliminationData(EliminationData* _parentData,
size_t nChildren) :
39 parentData(_parentData) { childFactors.reserve(nChildren); }
44 EliminationData<TREE> eliminationPreOrderVisitor(
45 const typename TREE::sharedNode& node, EliminationData<TREE>& parentData)
49 return EliminationData<TREE>(&parentData, node->children.size());
53 template<
class TREE,
class RESULT>
54 struct EliminationPostOrderVisitor
57 const typename TREE::Eliminate& eliminationFunction;
58 EliminationPostOrderVisitor(RESULT& result,
const typename TREE::Eliminate& eliminationFunction) :
59 result(result), eliminationFunction(eliminationFunction) {}
60 void operator()(
const typename TREE::sharedNode& node, EliminationData<TREE>& myData)
63 typename TREE::sharedFactor childFactor = node->eliminate(result, eliminationFunction, myData.childFactors);
64 if(childFactor && !childFactor->empty())
65 myData.parentData->childFactors.push_back(childFactor);
74 template<
class TREE,
class RESULT>
75 FastVector<typename TREE::sharedFactor>
76 EliminateTree(RESULT& result,
const TREE& tree,
const typename TREE::Eliminate&
function)
84 EliminationData<TREE> rootData(0, tree.roots().size());
85 EliminationPostOrderVisitor<TREE,RESULT> visitorPost(result,
function);
89 return rootData.childFactors;
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
A thin wrapper around std::vector that uses a custom allocator.
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
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:76