diff --git a/cpp/BayesTree-inl.h b/cpp/BayesTree-inl.h index f845797f4..d2b5db148 100644 --- a/cpp/BayesTree-inl.h +++ b/cpp/BayesTree-inl.h @@ -262,6 +262,20 @@ namespace gtsam { equal(nodes_.begin(),nodes_.end(),other.nodes_.begin(),check_pair); } + /* ************************************************************************* */ + template + Symbol BayesTree::findParentClique(const list& parents, const list& ordering) const { + Symbol parent; + for (list::const_iterator it = ordering.begin(); it!=ordering.end(); it++) { + list::const_iterator pit = find(parents.begin(), parents.end(), *it); + if (pit!=parents.end()) { + parent = *pit; + break; + } + } + return parent; + } + /* ************************************************************************* */ template void BayesTree::insert(const sharedConditional& conditional, const list* ordering) @@ -281,13 +295,7 @@ namespace gtsam { if (!ordering) { parent = parents.front(); // assumes parents are in current variable order, which is not the case (after COLAMD was activated) } else { - for (list::const_iterator it = ordering->begin(); it!=ordering->end(); it++) { - list::iterator pit = find(parents.begin(), parents.end(), *it); - if (pit!=parents.end()) { - parent = *pit; - break; - } - } + parent = findParentClique(parents, *ordering); } sharedClique parent_clique = (*this)[parent]; diff --git a/cpp/BayesTree.h b/cpp/BayesTree.h index 52305f9c2..aeb0533a0 100644 --- a/cpp/BayesTree.h +++ b/cpp/BayesTree.h @@ -128,6 +128,9 @@ namespace gtsam { /** check equality */ bool equals(const BayesTree& other, double tol = 1e-9) const; + /** find parent clique of a conditional, given an ordering */ + Symbol findParentClique(const std::list& parents, const std::list& ordering) const; + /** insert a new conditional */ void insert(const sharedConditional& conditional, const std::list* ordering = NULL); diff --git a/cpp/ISAM2-inl.h b/cpp/ISAM2-inl.h index 4ddaaf9b8..5da4a479e 100644 --- a/cpp/ISAM2-inl.h +++ b/cpp/ISAM2-inl.h @@ -126,7 +126,7 @@ namespace gtsam { FactorGraph affectedFactors; list newFactorsKeys = newFactors.keys(); -#if 0 +#if 1 // relinearize all keys that are in newFactors, and already exist (not new variables!) list keysToRelinearize; @@ -237,7 +237,8 @@ namespace gtsam { // add orphans to the bottom of the new tree BOOST_FOREACH(sharedClique orphan, orphans) { - Symbol key = orphan->separator_.front(); +// Symbol key = orphan->separator_.front(); + Symbol key = findParentClique(orphan->separator_, ordering); sharedClique parent = (*this)[key]; parent->children_ += orphan;