g2o
linear_solver.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_H
28 #define G2O_LINEAR_SOLVER_H
29 #include "sparse_block_matrix.h"
31 
32 namespace g2o {
33 
40 template <typename MatrixType>
42 {
43  public:
45  virtual ~LinearSolver() {}
46 
50  virtual bool init() = 0;
51 
58  virtual bool solve(const SparseBlockMatrix<MatrixType>& A, double* x, double* b) = 0;
59 
64  virtual bool solveBlocks(double**&blocks, const SparseBlockMatrix<MatrixType>& A) { (void)blocks; (void) A; return false; }
65 
66 
71  virtual bool solvePattern(SparseBlockMatrix<MatrixXD>& spinv, const std::vector<std::pair<int, int> >& blockIndices, const SparseBlockMatrix<MatrixType>& A){
72  (void) spinv;
73  (void) blockIndices;
74  (void) A;
75  return false;
76  }
77 
79  virtual bool writeDebug() const { return false;}
80  virtual void setWriteDebug(bool) {}
81 };
82 
86 template <typename MatrixType>
87 class LinearSolverCCS : public LinearSolver<MatrixType>
88 {
89  public:
90  LinearSolverCCS() : LinearSolver<MatrixType>(), _ccsMatrix(0) {}
92  {
93  delete _ccsMatrix;
94  }
95 
96  protected:
98 
100  {
101  delete _ccsMatrix;
103  A.fillSparseBlockMatrixCCS(*_ccsMatrix);
104  }
105 };
106 
107 } // end namespace
108 
109 #endif
const std::vector< int > & rowBlockIndices() const
indices of the row blocks
int fillSparseBlockMatrixCCS(SparseBlockMatrixCCS< MatrixType > &blockCCS) const
virtual bool solve(const SparseBlockMatrix< MatrixType > &A, double *x, double *b)=0
virtual bool solveBlocks(double **&blocks, const SparseBlockMatrix< MatrixType > &A)
Definition: linear_solver.h:64
virtual bool solvePattern(SparseBlockMatrix< MatrixXD > &spinv, const std::vector< std::pair< int, int > > &blockIndices, const SparseBlockMatrix< MatrixType > &A)
Definition: linear_solver.h:71
virtual bool init()=0
const std::vector< int > & colBlockIndices() const
indices of the column blocks
virtual void setWriteDebug(bool)
Definition: linear_solver.h:80
basic solver for Ax = b
Definition: linear_solver.h:41
Sparse matrix which uses blocks.
virtual bool writeDebug() const
write a debug dump of the system matrix if it is not PSD in solve
Definition: linear_solver.h:79
SparseBlockMatrixCCS< MatrixType > * _ccsMatrix
Definition: linear_solver.h:97
void initMatrixStructure(const SparseBlockMatrix< MatrixType > &A)
Definition: linear_solver.h:99
Solver with faster iterating structure for the linear matrix.
Definition: linear_solver.h:87
virtual ~LinearSolver()
Definition: linear_solver.h:45
Sparse matrix which uses blocks.