g2o
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_SOLVER_H
28 #define G2O_SOLVER_H
29 
30 #include "hyper_graph.h"
31 #include "batch_stats.h"
32 #include "sparse_block_matrix.h"
33 #include "g2o_core_api.h"
34 #include <cstddef>
35 
36 namespace g2o {
37 
38 
39  class SparseOptimizer;
40 
45  {
46  public:
47  Solver();
48  virtual ~Solver();
49 
50  public:
54  virtual bool init(SparseOptimizer* optimizer, bool online = false) = 0;
55 
59  virtual bool buildStructure(bool zeroBlocks = false) = 0;
63  virtual bool updateStructure(const std::vector<HyperGraph::Vertex*>& vset, const HyperGraph::EdgeSet& edges) = 0;
67  virtual bool buildSystem() = 0;
68 
72  virtual bool solve() = 0;
73 
78  virtual bool computeMarginals(SparseBlockMatrix<MatrixXD>& spinv, const std::vector<std::pair<int, int> >& blockIndices) = 0;
79 
88  virtual bool setLambda(double lambda, bool backup = false) = 0;
89 
93  virtual void restoreDiagonal() = 0;
94 
96  double* x() { return _x;}
97  const double* x() const { return _x;}
99  double* b() { return _b;}
100  const double* b() const { return _b;}
101 
103  size_t vectorSize() const { return _xSize;}
104 
106  SparseOptimizer* optimizer() const { return _optimizer;}
107  void setOptimizer(SparseOptimizer* optimizer);
108 
110  bool levenberg() const { return _isLevenberg;}
111  void setLevenberg(bool levenberg);
112 
117  virtual bool supportsSchur() {return false;}
118 
120  virtual bool schur()=0;
121  virtual void setSchur(bool s)=0;
122 
123  size_t additionalVectorSpace() const { return _additionalVectorSpace;}
124  void setAdditionalVectorSpace(size_t s);
125 
129  virtual void setWriteDebug(bool) = 0;
130  virtual bool writeDebug() const = 0;
131 
133  virtual bool saveHessian(const std::string& /*fileName*/) const = 0;
134 
135  protected:
137  double* _x;
138  double* _b;
139  size_t _xSize, _maxXSize;
142 
143  void resizeVector(size_t sx);
144 
145  private:
146  // Disable the copy constructor and assignment operator
147  Solver(const Solver&) { }
148  Solver& operator= (const Solver&) { return *this; }
149  };
150 } // end namespace
151 
152 #endif
double * _b
Definition: solver.h:138
SparseOptimizer * _optimizer
Definition: solver.h:136
size_t _xSize
Definition: solver.h:139
double * _x
Definition: solver.h:137
bool levenberg() const
the system is Levenberg-Marquardt
Definition: solver.h:110
std::set< Edge * > EdgeSet
Definition: hyper_graph.h:135
class G2O_CORE_API SparseOptimizer
virtual bool supportsSchur()
Definition: solver.h:117
Generic interface for a sparse solver operating on a graph which solves one iteration of the lineariz...
Definition: solver.h:44
const double * b() const
Definition: solver.h:100
Solver(const Solver &)
Definition: solver.h:147
size_t _additionalVectorSpace
Definition: solver.h:141
SparseOptimizer * optimizer() const
the optimizer (graph) on which the solver works
Definition: solver.h:106
bool _isLevenberg
the system we gonna solve is a Levenberg-Marquardt system
Definition: solver.h:140
double * x()
return x, the solution vector
Definition: solver.h:96
double * b()
return b, the right hand side of the system
Definition: solver.h:99
size_t vectorSize() const
return the size of the solution vector (x) and b
Definition: solver.h:103
size_t additionalVectorSpace() const
Definition: solver.h:123
const double * x() const
Definition: solver.h:97
#define G2O_CORE_API
Definition: g2o_core_api.h:29
Sparse matrix which uses blocks.