From 71a5f26d401c447e6372f893cfee6520d3b8410b Mon Sep 17 00:00:00 2001 From: Yong-Dian Jian Date: Tue, 26 Oct 2010 21:43:57 +0000 Subject: [PATCH] revised interfaces --- gtsam/linear/ConjugateGradientSolver.h | 12 ++++++-- .../linear/IterativeOptimizationParameters.h | 29 ++++++++++++++----- gtsam/linear/IterativeSolver.h | 3 ++ gtsam/linear/SubgraphSolver.h | 8 ++--- 4 files changed, 39 insertions(+), 13 deletions(-) diff --git a/gtsam/linear/ConjugateGradientSolver.h b/gtsam/linear/ConjugateGradientSolver.h index 83a614a98..2db9f6501 100644 --- a/gtsam/linear/ConjugateGradientSolver.h +++ b/gtsam/linear/ConjugateGradientSolver.h @@ -20,19 +20,27 @@ namespace gtsam { class ConjugateGradientSolver : public IterativeSolver { protected: - const LINEAR *ptr_; + typedef boost::shared_ptr sharedGRAPH ; + typedef boost::shared_ptr sharedLINEAR ; + typedef boost::shared_ptr sharedVALUES ; typedef boost::shared_ptr sharedVectorValues ; + + const LINEAR *ptr_; sharedVectorValues zeros_; public: typedef boost::shared_ptr shared_ptr ; - ConjugateGradientSolver(const GRAPH &graph, const VALUES &initial, const Ordering &ordering, const sharedParameters parameters): +// ConjugateGradientSolver(const GRAPH &graph, const VALUES &initial, const Ordering &ordering, const sharedParameters parameters): +// IterativeSolver(parameters), ptr_(0), zeros_(boost::make_shared(initial.zero(ordering))) {} + + ConjugateGradientSolver(const GRAPH &graph, const VALUES &initial, const Ordering &ordering, const Parameters ¶meters = Parameters()): IterativeSolver(parameters), ptr_(0), zeros_(boost::make_shared(initial.zero(ordering))) {} ConjugateGradientSolver(const LINEAR &GFG) { + std::cout << "[ConjugateGradientSolver] Unexpected usage.." << std::endl; throw std::runtime_error("SubgraphSolver: gaussian factor graph initialization not supported"); } diff --git a/gtsam/linear/IterativeOptimizationParameters.h b/gtsam/linear/IterativeOptimizationParameters.h index 97ea92577..d1e5c9fa7 100644 --- a/gtsam/linear/IterativeOptimizationParameters.h +++ b/gtsam/linear/IterativeOptimizationParameters.h @@ -11,15 +11,36 @@ namespace gtsam { // a container for all related parameters struct IterativeOptimizationParameters { + + public: + typedef enum { SILENT, ERROR, } verbosityLevel; + protected: + int maxIterations_; + int reset_ ; // number of iterations before reset, for cg and gmres + double epsilon_; // relative error + double epsilon_abs_; // absolute error + verbosityLevel verbosity_; + + public: IterativeOptimizationParameters(): maxIterations_(100), reset_(101), - epsilon_(1e-5),epsilon_abs_(1e-5),verbosity_(SILENT) {} + epsilon_(1e-5), + epsilon_abs_(1e-5), + verbosity_(SILENT) {} + + IterativeOptimizationParameters(const IterativeOptimizationParameters ¶meters): + maxIterations_(parameters.maxIterations_), + reset_(parameters.reset_), + epsilon_(parameters.epsilon_), + epsilon_abs_(parameters.epsilon_abs_), + verbosity_(parameters.verbosity_) {} + IterativeOptimizationParameters (int maxIterations, double epsilon, double epsilon_abs, verbosityLevel verbosity=SILENT, int reset=-1): @@ -34,11 +55,5 @@ namespace gtsam { double epsilon_abs() const { return epsilon_abs_ ; } verbosityLevel verbosity() const { return verbosity_ ; } - protected: - int maxIterations_; - int reset_ ; // number of iterations before reset, for cg and gmres - double epsilon_; // relative error - double epsilon_abs_; // absolute error - verbosityLevel verbosity_; }; } diff --git a/gtsam/linear/IterativeSolver.h b/gtsam/linear/IterativeSolver.h index 2d45e2f78..d35d455da 100644 --- a/gtsam/linear/IterativeSolver.h +++ b/gtsam/linear/IterativeSolver.h @@ -30,6 +30,9 @@ public: IterativeSolver(const IterativeSolver &solver): parameters_(solver.parameters_) {} + IterativeSolver(const IterativeOptimizationParameters ¶meters): + parameters_(new IterativeOptimizationParameters(parameters)) {} + IterativeSolver(const sharedParameters parameters): parameters_(parameters) {} }; diff --git a/gtsam/linear/SubgraphSolver.h b/gtsam/linear/SubgraphSolver.h index 364cb97ef..059c0fc28 100644 --- a/gtsam/linear/SubgraphSolver.h +++ b/gtsam/linear/SubgraphSolver.h @@ -54,7 +54,11 @@ namespace gtsam { public: + SubgraphSolver(const GRAPH& G, const VALUES& theta0, const Parameters ¶meters = Parameters()): + IterativeSolver(parameters){ initialize(G,theta0); } + SubgraphSolver(const LINEAR &GFG) { + std::cout << "[SubgraphSolver] Unexpected usage.." << std::endl; throw std::runtime_error("SubgraphSolver: gaussian factor graph initialization not supported"); } @@ -67,10 +71,6 @@ namespace gtsam { sharedParameters parameters = boost::make_shared()) : IterativeSolver(parameters), ordering_(ordering), pairs_(pairs), pc_(pc) {} - SubgraphSolver(const GRAPH& G, const VALUES& theta0):IterativeSolver(){ - initialize(G,theta0); - } - shared_ptr update(const LINEAR &graph) const ; VectorValues::shared_ptr optimize() const ; shared_ordering ordering() const { return ordering_; }