linear_solver_pcg.h
Go to the documentation of this file.
00001 // g2o - General Graph Optimization
00002 // Copyright (C) 2011 R. Kuemmerle, G. Grisetti, W. Burgard
00003 // 
00004 // g2o is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU Lesser General Public License as published
00006 // by the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 // 
00009 // g2o is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU Lesser General Public License for more details.
00013 // 
00014 // You should have received a copy of the GNU Lesser General Public License
00015 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017 #ifndef LINEAR_SOLVER_PCG_H
00018 #define LINEAR_SOLVER_PCG_H
00019 
00020 #include "g2o/core/linear_solver.h"
00021 #include "g2o/core/batch_stats.h"
00022 
00023 #include <vector>
00024 #include <utility>
00025 #include<Eigen/Core>
00026 //#ifndef EIGEN_USE_NEW_STDVECTOR
00027 //#define EIGEN_USE_NEW_STDVECTOR
00028 //#endif
00029 #include<Eigen/StdVector>
00030 
00031 namespace g2o {
00032 
00036   template <typename MatrixType>
00037   class LinearSolverPCG : public LinearSolver<MatrixType>
00038   {
00039     public:
00040       LinearSolverPCG() :
00041       LinearSolver<MatrixType>()
00042       {
00043         _tolerance = 1e-6;
00044         _verbose = false;
00045         _absoluteTolerance = true;
00046         _residual = -1.0;
00047         _maxIter = -1;
00048       }
00049 
00050       virtual ~LinearSolverPCG()
00051       {
00052       }
00053 
00054       virtual bool init()
00055       {
00056         _residual = -1.0;
00057         _indices.clear();
00058         _sparseMat.clear();
00059         return true;
00060       }
00061 
00062       bool solve(const SparseBlockMatrix<MatrixType>& A, double* x, double* b);
00063 
00065       double tolerance() const { return _tolerance;}
00066       void setTolerance(double tolerance) { _tolerance = tolerance;}
00067 
00068       int maxIterations() const { return _maxIter;}
00069       void setMaxIterations(int maxIter) { _maxIter = maxIter;}
00070 
00071       bool absoluteTolerance() const { return _absoluteTolerance;}
00072       void setAbsoluteTolerance(bool absoluteTolerance) { _absoluteTolerance = absoluteTolerance;}
00073 
00074       bool verbose() const { return _verbose;}
00075       void setVerbose(bool verbose) { _verbose = verbose;}
00076 
00077     protected:
00078       typedef std::vector< MatrixType, Eigen::aligned_allocator<MatrixType> > MatrixVector;
00079       typedef std::vector< const MatrixType* > MatrixPtrVector;
00080 
00081       double _tolerance;
00082       double _residual;
00083       bool _absoluteTolerance;
00084       bool _verbose;
00085       int _maxIter;
00086 
00087       MatrixPtrVector _diag;
00088       MatrixVector _J;
00089 
00090       std::vector<std::pair<int, int> > _indices;
00091       MatrixPtrVector _sparseMat;
00092 
00093       void multDiag(const std::vector<int>& colBlockIndices, MatrixVector& A, const Eigen::VectorXd& src, Eigen::VectorXd& dest);
00094       void multDiag(const std::vector<int>& colBlockIndices, MatrixPtrVector& A, const Eigen::VectorXd& src, Eigen::VectorXd& dest);
00095       void mult(const std::vector<int>& colBlockIndices, const Eigen::VectorXd& src, Eigen::VectorXd& dest);
00096   };
00097 
00098 #include "linear_solver_pcg.hpp"
00099 
00100 }// end namespace
00101 
00102 #endif


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:31:39