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 <cstddef>
34 
35 namespace g2o {
36 
37 
38  class SparseOptimizer;
39 
43  class Solver
44  {
45  public:
46  Solver();
47  virtual ~Solver();
48 
49  public:
53  virtual bool init(SparseOptimizer* optimizer, bool online = false) = 0;
54 
58  virtual bool buildStructure(bool zeroBlocks = false) = 0;
62  virtual bool updateStructure(const std::vector<HyperGraph::Vertex*>& vset, const HyperGraph::EdgeSet& edges) = 0;
66  virtual bool buildSystem() = 0;
67 
71  virtual bool solve() = 0;
72 
77  virtual bool computeMarginals(SparseBlockMatrix<MatrixXd>& spinv, const std::vector<std::pair<int, int> >& blockIndices) = 0;
78 
87  virtual bool setLambda(double lambda, bool backup = false) = 0;
88 
92  virtual void restoreDiagonal() = 0;
93 
95  double* x() { return _x;}
96  const double* x() const { return _x;}
98  double* b() { return _b;}
99  const double* b() const { return _b;}
100 
102  size_t vectorSize() const { return _xSize;}
103 
106  void setOptimizer(SparseOptimizer* optimizer);
107 
109  bool levenberg() const { return _isLevenberg;}
110  void setLevenberg(bool levenberg);
111 
116  virtual bool supportsSchur() {return false;}
117 
119  virtual bool schur()=0;
120  virtual void setSchur(bool s)=0;
121 
123  void setAdditionalVectorSpace(size_t s);
124 
128  virtual void setWriteDebug(bool) = 0;
129  virtual bool writeDebug() const = 0;
130 
132  virtual bool saveHessian(const std::string& /*fileName*/) const = 0;
133 
134  protected:
136  double* _x;
137  double* _b;
138  size_t _xSize, _maxXSize;
141 
142  void resizeVector(size_t sx);
143 
144  private:
145  // Disable the copy constructor and assignment operator
146  Solver(const Solver&) { }
147  Solver& operator= (const Solver&) { return *this; }
148  };
149 } // end namespace
150 
151 #endif
double * _b
Definition: solver.h:137
virtual void restoreDiagonal()=0
virtual bool schur()=0
should the solver perform the schur complement or not
virtual bool updateStructure(const std::vector< HyperGraph::Vertex * > &vset, const HyperGraph::EdgeSet &edges)=0
Solver & operator=(const Solver &)
Definition: solver.h:147
void setLevenberg(bool levenberg)
Definition: solver.cpp:77
XmlRpcServer s
SparseOptimizer * _optimizer
Definition: solver.h:135
virtual bool setLambda(double lambda, bool backup=false)=0
virtual bool writeDebug() const =0
size_t _xSize
Definition: solver.h:138
double * _x
Definition: solver.h:136
bool levenberg() const
the system is Levenberg-Marquardt
Definition: solver.h:109
void setAdditionalVectorSpace(size_t s)
Definition: solver.cpp:82
void setOptimizer(SparseOptimizer *optimizer)
Definition: solver.cpp:72
std::set< Edge * > EdgeSet
Definition: hyper_graph.h:90
virtual bool supportsSchur()
Definition: solver.h:116
Generic interface for a sparse solver operating on a graph which solves one iteration of the lineariz...
Definition: solver.h:43
const double * b() const
Definition: solver.h:99
Solver(const Solver &)
Definition: solver.h:146
size_t _additionalVectorSpace
Definition: solver.h:140
void resizeVector(size_t sx)
Definition: solver.cpp:46
SparseOptimizer * optimizer() const
the optimizer (graph) on which the solver works
Definition: solver.h:105
virtual bool solve()=0
bool _isLevenberg
the system we gonna solve is a Levenberg-Marquardt system
Definition: solver.h:139
double * x()
return x, the solution vector
Definition: solver.h:95
double * b()
return b, the right hand side of the system
Definition: solver.h:98
virtual bool buildSystem()=0
size_t vectorSize() const
return the size of the solution vector (x) and b
Definition: solver.h:102
size_t additionalVectorSpace() const
Definition: solver.h:122
const double * x() const
Definition: solver.h:96
virtual void setWriteDebug(bool)=0
virtual bool init(SparseOptimizer *optimizer, bool online=false)=0
virtual ~Solver()
Definition: solver.cpp:40
virtual bool saveHessian(const std::string &) const =0
write the hessian to disk using the specified file name
Sparse matrix which uses blocks.
virtual void setSchur(bool s)=0
virtual bool computeMarginals(SparseBlockMatrix< MatrixXd > &spinv, const std::vector< std::pair< int, int > > &blockIndices)=0
size_t _maxXSize
Definition: solver.h:138
virtual bool buildStructure(bool zeroBlocks=false)=0


orb_slam2_ros
Author(s):
autogenerated on Wed Apr 21 2021 02:53:05