/* ---------------------------------------------------------------------------- * 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 * -------------------------------------------------------------------------- */ #pragma once #include #include #include #include #include #include #include #include using namespace std; namespace gtsam { template typename SubgraphSolver::shared_ptr SubgraphSolver::update(const LINEAR &graph) const { shared_linear Ab1 = boost::make_shared(), Ab2 = boost::make_shared(); if (parameters_->verbosity()) cout << "split the graph ..."; graph.split(pairs_, *Ab1, *Ab2) ; if (parameters_->verbosity()) cout << ",with " << Ab1->size() << " and " << Ab2->size() << " factors" << endl; // // Add a HardConstra int to the root, otherwise the root will be singular // Key root = keys.back(); // T_.addHardConstraint(root, theta0[root]); // // // compose the approximate solution // theta_bar_ = composePoses (T_, tree, theta0[root]); LINEAR sacrificialAb1 = *Ab1; // duplicate !!!!! SubgraphPreconditioner::sharedBayesNet Rc1 = EliminationTree::Create(sacrificialAb1)->eliminate(); SubgraphPreconditioner::sharedValues xbar = gtsam::optimize_(*Rc1); shared_preconditioner pc = boost::make_shared(Ab1,Ab2,Rc1,xbar); return boost::make_shared(ordering_, pairs_, pc, parameters_) ; } template VectorValues::shared_ptr SubgraphSolver::optimize() const { // preconditioned conjugate gradient VectorValues zeros = pc_->zero(); VectorValues ybar = conjugateGradients (*pc_, zeros, parameters_); boost::shared_ptr xbar = boost::make_shared() ; *xbar = pc_->x(ybar); return xbar; } template void SubgraphSolver::initialize(const GRAPH& G, const VALUES& theta0) { // generate spanning tree PredecessorMap tree_ = gtsam::findMinimumSpanningTree(G); // make the ordering list keys = predecessorMap2Keys(tree_); ordering_ = boost::make_shared(list(keys.begin(), keys.end())); // build factor pairs pairs_.clear(); typedef pair EG ; BOOST_FOREACH( const EG &eg, tree_ ) { Symbol key1 = Symbol(eg.first), key2 = Symbol(eg.second) ; pairs_.insert(pair((*ordering_)[key1], (*ordering_)[key2])) ; } } }