/* ---------------------------------------------------------------------------- * GTSAM Copyright 2010, Georgia Tech Research Corporation, * Atlanta, Georgia 30332-0415 * All Rights Reserved * Authors: Frank Dellaert, et al. (see THANKS for the full author list) * See LICENSE for the license information * -------------------------------------------------------------------------- */ /** * @file GenericMultifrontalSolver-inl.h * @author Richard Roberts * @date Oct 21, 2010 */ #pragma once #include #include #include namespace gtsam { /* ************************************************************************* */ template GenericMultifrontalSolver::GenericMultifrontalSolver( const FactorGraphOrdered& graph) : structure_(new VariableIndexOrdered(graph)), junctionTree_( new JT(graph, *structure_)) { } /* ************************************************************************* */ template GenericMultifrontalSolver::GenericMultifrontalSolver( const sharedGraph& graph, const VariableIndexOrdered::shared_ptr& variableIndex) : structure_(variableIndex), junctionTree_(new JT(*graph, *structure_)) { } /* ************************************************************************* */ template void GenericMultifrontalSolver::print(const std::string& s) const { this->structure_->print(s + " structure:\n"); this->junctionTree_->print(s + " jtree:"); } /* ************************************************************************* */ template bool GenericMultifrontalSolver::equals( const GenericMultifrontalSolver& expected, double tol) const { if (!this->structure_->equals(*expected.structure_, tol)) return false; if (!this->junctionTree_->equals(*expected.junctionTree_, tol)) return false; return true; } /* ************************************************************************* */ template void GenericMultifrontalSolver::replaceFactors(const sharedGraph& graph) { junctionTree_.reset(new JT(*graph, *structure_)); } /* ************************************************************************* */ template typename BayesTreeOrdered::shared_ptr GenericMultifrontalSolver::eliminate(Eliminate function) const { // eliminate junction tree, returns pointer to root typename BayesTreeOrdered::sharedClique root = junctionTree_->eliminate(function); // create an empty Bayes tree and insert root clique typename BayesTreeOrdered::shared_ptr bayesTree(new BayesTreeOrdered); bayesTree->insert(root); // return the Bayes tree return bayesTree; } /* ************************************************************************* */ template typename FactorGraphOrdered::shared_ptr GenericMultifrontalSolver::jointFactorGraph( const std::vector& js, Eliminate function) const { // FIXME: joint for arbitrary sets of variables not present // TODO: develop and implement theory for shortcuts of more than two variables if (js.size() != 2) throw std::domain_error( "*MultifrontalSolver::joint(js) currently can only compute joint marginals\n" "for exactly two variables. You can call marginal to compute the\n" "marginal for one variable. *SequentialSolver::joint(js) can compute the\n" "joint marginal over any number of variables, so use that if necessary.\n"); return eliminate(function)->joint(js[0], js[1], function); } /* ************************************************************************* */ template typename boost::shared_ptr GenericMultifrontalSolver::marginalFactor( Index j, Eliminate function) const { return eliminate(function)->marginalFactor(j, function); } }