g2o
Loading...
Searching...
No Matches
linear_solver_pcg.h
Go to the documentation of this file.
1// g2o - General Graph Optimization
2// Copyright (C) 2011 R. Kuemmerle, G. Grisetti, W. Burgard
3// All rights reserved.
4//
5// Redistribution and use in source and binary forms, with or without
6// modification, are permitted provided that the following conditions are
7// met:
8//
9// * Redistributions of source code must retain the above copyright notice,
10// this list of conditions and the following disclaimer.
11// * Redistributions in binary form must reproduce the above copyright
12// notice, this list of conditions and the following disclaimer in the
13// documentation and/or other materials provided with the distribution.
14//
15// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
16// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
18// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
27#ifndef G2O_LINEAR_SOLVER_PCG_H
28#define G2O_LINEAR_SOLVER_PCG_H
29
30#include <Eigen/Core>
31#include <utility>
32#include <vector>
33
36
37namespace g2o {
38
42template <typename MatrixType>
43class LinearSolverPCG : public LinearSolver<MatrixType> {
44 public:
45 LinearSolverPCG() : LinearSolver<MatrixType>() {
46 _tolerance = cst(1e-6);
47 _absoluteTolerance = true;
48 _residual = -1.0;
49 _maxIter = -1;
50 }
51
52 virtual ~LinearSolverPCG() {}
53
54 virtual bool init() {
55 _residual = -1.0;
56 _indices.clear();
57 _sparseMat.clear();
58 return true;
59 }
60
61 bool solve(const SparseBlockMatrix<MatrixType>& A, double* x, double* b);
62
64 double tolerance() const { return _tolerance; }
66
67 int maxIterations() const { return _maxIter; }
68 void setMaxIterations(int maxIter) { _maxIter = maxIter; }
69
70 bool absoluteTolerance() const { return _absoluteTolerance; }
74
75 protected:
76 using MatrixVector = std::vector<MatrixType>;
77 using MatrixPtrVector = std::vector<const MatrixType*>;
78
79 double _tolerance;
80 double _residual;
83
86
87 std::vector<std::pair<int, int> > _indices;
89
90 void multDiag(const std::vector<int>& colBlockIndices, MatrixVector& A,
91 const VectorX& src, VectorX& dest);
92 void multDiag(const std::vector<int>& colBlockIndices, MatrixPtrVector& A,
93 const VectorX& src, VectorX& dest);
94 void mult(const std::vector<int>& colBlockIndices, const VectorX& src,
95 VectorX& dest);
96};
97
98#include "linear_solver_pcg.hpp"
99
100} // namespace g2o
101
102#endif
linear solver using PCG, pre-conditioner is block Jacobi
MatrixPtrVector _sparseMat
double tolerance() const
return the tolerance for terminating PCG before convergence
void mult(const std::vector< int > &colBlockIndices, const VectorX &src, VectorX &dest)
bool absoluteTolerance() const
std::vector< std::pair< int, int > > _indices
std::vector< MatrixType > MatrixVector
std::vector< const MatrixType * > MatrixPtrVector
bool solve(const SparseBlockMatrix< MatrixType > &A, double *x, double *b)
void setAbsoluteTolerance(bool absoluteTolerance)
void setMaxIterations(int maxIter)
void setTolerance(double tolerance)
void multDiag(const std::vector< int > &colBlockIndices, MatrixVector &A, const VectorX &src, VectorX &dest)
basic solver for Ax = b
Sparse matrix which uses blocks.
constexpr double cst(long double v)
Definition misc.h:60
VectorN< Eigen::Dynamic > VectorX
Definition eigen_types.h:55