From 00023f0c6727e415e4d1e87ad5051161de907a26 Mon Sep 17 00:00:00 2001 From: Yong-Dian Jian Date: Wed, 1 Feb 2012 16:35:18 +0000 Subject: [PATCH] start to fix iterative solvers --- gtsam/linear/IterativeSolver.h | 31 ++++++++++++++++++++++++++++--- gtsam/linear/SubgraphSolver-inl.h | 2 +- gtsam/linear/SubgraphSolver.h | 2 +- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/gtsam/linear/IterativeSolver.h b/gtsam/linear/IterativeSolver.h index c7e7edeab..3be67789b 100644 --- a/gtsam/linear/IterativeSolver.h +++ b/gtsam/linear/IterativeSolver.h @@ -18,6 +18,8 @@ #pragma once +#include +#include #include namespace gtsam { @@ -25,10 +27,29 @@ namespace gtsam { class IterativeSolver { public: - typedef IterativeOptimizationParameters Parameters; - typedef boost::shared_ptr sharedParameters; - sharedParameters parameters_ ; + typedef IterativeOptimizationParameters Parameters; + typedef Parameters::shared_ptr sharedParameters; + +protected: + + GaussianFactorGraph::shared_ptr graph_; + VariableIndex::shared_ptr variableIndex_; + Parameters::shared_ptr parameters_ ; + +public: + + IterativeSolver( + const GaussianFactorGraph::shared_ptr& factorGraph, + const VariableIndex::shared_ptr& variableIndex): + graph_(factorGraph), variableIndex_(variableIndex), + parameters_(new Parameters()) { } + + IterativeSolver( + const GaussianFactorGraph::shared_ptr& factorGraph, + const VariableIndex::shared_ptr& variableIndex, + const Parameters::shared_ptr& parameters): + graph_(factorGraph), variableIndex_(variableIndex), parameters_(parameters) { } IterativeSolver(): parameters_(new IterativeOptimizationParameters()) {} @@ -41,6 +62,10 @@ public: IterativeSolver(const sharedParameters parameters): parameters_(parameters) {} + + virtual ~IterativeSolver() {} + + virtual VectorValues::shared_ptr optimize () = 0; }; } diff --git a/gtsam/linear/SubgraphSolver-inl.h b/gtsam/linear/SubgraphSolver-inl.h index 6f7ad5f50..4aa12532e 100644 --- a/gtsam/linear/SubgraphSolver-inl.h +++ b/gtsam/linear/SubgraphSolver-inl.h @@ -48,7 +48,7 @@ void SubgraphSolver::replaceFactors(const typename LINEAR:: } template -VectorValues::shared_ptr SubgraphSolver::optimize() const { +VectorValues::shared_ptr SubgraphSolver::optimize() { // preconditioned conjugate gradient VectorValues zeros = pc_->zero(); diff --git a/gtsam/linear/SubgraphSolver.h b/gtsam/linear/SubgraphSolver.h index 539f102e6..9e0f0a9d7 100644 --- a/gtsam/linear/SubgraphSolver.h +++ b/gtsam/linear/SubgraphSolver.h @@ -85,7 +85,7 @@ public: IterativeSolver(parameters), ordering_(ordering), pairs_(pairs), pc_(pc), useQR_(useQR) {} void replaceFactors(const typename LINEAR::shared_ptr &graph); - VectorValues::shared_ptr optimize() const ; + VectorValues::shared_ptr optimize() ; shared_ordering ordering() const { return ordering_; } protected: