Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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
00027
00028
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 }
00101
00102 #endif