/* ---------------------------------------------------------------------------- * 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 * -------------------------------------------------------------------------- */ /* * NonlinearOptimization-inl.h * * Created on: Oct 17, 2010 * Author: Kai Ni * Description: Easy interfaces for NonlinearOptimizer */ #pragma once #include #include #include #include #include using namespace std; namespace gtsam { /** * The Elimination solver */ template T optimizeElimination(const G& graph, const T& initialEstimate, const NonlinearOptimizationParameters& parameters) { // Use a variable ordering from COLAMD Ordering::shared_ptr ordering = graph.orderingCOLAMD(initialEstimate); // initial optimization state is the same in both cases tested typedef NonlinearOptimizer Optimizer; Optimizer optimizer(boost::make_shared(graph), boost::make_shared(initialEstimate), ordering); // Levenberg-Marquardt Optimizer result = optimizer.levenbergMarquardt(parameters); return *result.config(); } /** * The multifrontal solver */ template T optimizeMultiFrontal(const G& graph, const T& initialEstimate, const NonlinearOptimizationParameters& parameters) { // Use a variable ordering from COLAMD Ordering::shared_ptr ordering = graph.orderingCOLAMD(initialEstimate); // initial optimization state is the same in both cases tested typedef NonlinearOptimizer Optimizer; Optimizer optimizer(boost::make_shared(graph), boost::make_shared(initialEstimate), ordering); // Levenberg-Marquardt Optimizer result = optimizer.levenbergMarquardt(parameters); return *result.config(); } // /** // * The multifrontal solver // */ // template // T optimizeSPCG(const G& graph, const T& initialEstimate, const NonlinearOptimizationParameters& parameters = NonlinearOptimizationParameters()) { // // // initial optimization state is the same in both cases tested // typedef NonlinearOptimizer > SPCGOptimizer; // typename SPCGOptimizer::shared_solver solver(new SubgraphSolver(graph, initialEstimate)); // SPCGOptimizer optimizer( // boost::make_shared(graph), // boost::make_shared(initialEstimate), // solver); // // // Levenberg-Marquardt // SPCGOptimizer result = optimizer.levenbergMarquardt(parameters); // return *result.config(); // } /** * optimization that returns the values */ template T optimize(const G& graph, const T& initialEstimate, const NonlinearOptimizationParameters& parameters, const enum LinearSolver& solver) { switch (solver) { case ELIMINATION: return optimizeElimination(graph, initialEstimate, parameters); case MULTIFRONTAL: return optimizeMultiFrontal(graph, initialEstimate, parameters); case SPCG: throw runtime_error("optimize: SPCG not supported yet due to the specific pose constraint"); break; } throw runtime_error("optimize: undefined solver"); } } //namespace gtsam