/* ---------------------------------------------------------------------------- * 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 #include #include namespace gtsam { // Forward declarations class KeyInfo; class KeyInfoEntry; class GaussianFactorGraph; class Values; class VectorValues; /************************************************************************************/ /** * parameters for iterative linear solvers */ class GTSAM_EXPORT IterativeOptimizationParameters { public: typedef boost::shared_ptr shared_ptr; enum Verbosity { SILENT = 0, COMPLEXITY, ERROR } verbosity_; public: IterativeOptimizationParameters(Verbosity v = SILENT) : verbosity_(v) {} virtual ~IterativeOptimizationParameters() {} /* utility */ inline Verbosity verbosity() const { return verbosity_; } std::string getVerbosity() const; void setVerbosity(const std::string &s) ; /* matlab interface */ void print() const ; /* virtual print function */ virtual void print(std::ostream &os) const ; /* for serialization */ friend std::ostream& operator<<(std::ostream &os, const IterativeOptimizationParameters &p); static Verbosity verbosityTranslator(const std::string &s); static std::string verbosityTranslator(Verbosity v); }; /************************************************************************************/ class GTSAM_EXPORT IterativeSolver { public: typedef boost::shared_ptr shared_ptr; IterativeSolver() {} virtual ~IterativeSolver() {} /* interface to the nonlinear optimizer, without metadata, damping and initial estimate */ VectorValues optimize ( const GaussianFactorGraph &gfg, boost::optional = boost::none, boost::optional&> lambda = boost::none ); /* interface to the nonlinear optimizer, without initial estimate */ VectorValues optimize ( const GaussianFactorGraph &gfg, const KeyInfo &keyInfo, const std::map &lambda ); /* interface to the nonlinear optimizer that the subclasses have to implement */ virtual VectorValues optimize ( const GaussianFactorGraph &gfg, const KeyInfo &keyInfo, const std::map &lambda, const VectorValues &initial ) = 0; }; /************************************************************************************/ /* Handy data structure for iterative solvers * key to (index, dimension, colstart) */ class GTSAM_EXPORT KeyInfoEntry : public boost::tuple { public: typedef boost::tuple Base; KeyInfoEntry(){} KeyInfoEntry(size_t idx, size_t d, Key start) : Base(idx, d, start) {} const size_t index() const { return this->get<0>(); } const size_t dim() const { return this->get<1>(); } const size_t colstart() const { return this->get<2>(); } }; /************************************************************************************/ class GTSAM_EXPORT KeyInfo : public std::map { public: typedef std::map Base; KeyInfo() : numCols_(0) {} KeyInfo(const GaussianFactorGraph &fg); KeyInfo(const GaussianFactorGraph &fg, const Ordering &ordering); std::vector colSpec() const ; VectorValues x0() const; Vector x0vector() const; inline size_t numCols() const { return numCols_; } inline const Ordering & ordering() const { return ordering_; } protected: void initialize(const GaussianFactorGraph &fg); Ordering ordering_; size_t numCols_; }; }