Using CloneForest in EliminationTree and JunctionTree

release/4.3a0
Richard Roberts 2013-06-06 15:36:33 +00:00
parent b814e146ef
commit 12ba0351d0
2 changed files with 9 additions and 28 deletions

View File

@ -156,27 +156,8 @@ namespace gtsam {
EliminationTreeUnordered<BAYESNET,GRAPH>&
EliminationTreeUnordered<BAYESNET,GRAPH>::operator=(const EliminationTreeUnordered<BAYESNET,GRAPH>& other)
{
// Start by duplicating the roots.
roots_.clear();
std::stack<sharedNode, std::vector<sharedNode> > stack;
BOOST_FOREACH(const sharedNode& root, other.roots_) {
roots_.push_back(boost::make_shared<Node>(*root));
stack.push(roots_.back());
}
// Traverse the tree, duplicating each node's children and fixing the pointers as we go. We do
// not clone any factors, only copy their pointers (this is a standard in GTSAM).
while(!stack.empty()) {
sharedNode node = stack.top();
stack.pop();
BOOST_FOREACH(sharedNode& child, node->children) {
// Important: since we are working with a *reference* to a shared pointer in this
// BOOST_FOREACH loop, the next statement modifies the pointer in the current node's child
// list - it replaces it with a pointer to a copy of the child.
child = boost::make_shared<Node>(*child);
stack.push(child);
}
}
// Start by duplicating the tree.
roots_ = treeTraversal::CloneForest(other);
// Assign the remaining factors - these are pointers to factors in the original factor graph and
// we do not clone them.

View File

@ -156,18 +156,18 @@ namespace gtsam {
remainingFactors_ = eliminationTree.remainingFactors();
}
/* ************************************************************************* */
template<class BAYESTREE, class GRAPH>
JunctionTreeUnordered<BAYESTREE,GRAPH>::JunctionTreeUnordered(const This& other)
{
}
/* ************************************************************************* */
template<class BAYESTREE, class GRAPH>
JunctionTreeUnordered<BAYESTREE,GRAPH>& JunctionTreeUnordered<BAYESREE,GRAPH>::operator=(const This& other)
{
// Start by duplicating the tree.
roots_ = treeTraversal::CloneForest(other);
// Assign the remaining factors - these are pointers to factors in the original factor graph and
// we do not clone them.
remainingFactors_ = other.remainingFactors_;
return *this;
}
/* ************************************************************************* */