22 #include <boost/shared_ptr.hpp> 23 #include <boost/bind.hpp> 35 struct EliminationData {
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
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>
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)
FastVector< typename TREE::sharedFactor > EliminateTree(RESULT &result, const TREE &tree, const typename TREE::Eliminate &function)
EliminationData *const parentData
A thin wrapper around std::vector that uses a custom allocator.
const TREE::Eliminate & eliminationFunction
FastVector< typename TREE::sharedFactor > childFactors