g2o
Loading...
Searching...
No Matches
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 <cstddef>
31
32#include "g2o_core_api.h"
33#include "hyper_graph.h"
34#include "sparse_block_matrix.h"
35
36namespace g2o {
37
38class SparseOptimizer;
39
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,
63 const HyperGraph::EdgeSet& edges) = 0;
67 virtual bool buildSystem() = 0;
68
72 virtual bool solve() = 0;
73
78 virtual bool computeMarginals(
80 const std::vector<std::pair<int, int> >& blockIndices) = 0;
81
90 virtual bool setLambda(double lambda, bool backup = false) = 0;
91
95 virtual void restoreDiagonal() = 0;
96
98 double* x() { return _x; }
99 const double* x() const { return _x; }
101 double* b() { return _b; }
102 const double* b() const { return _b; }
103
105 size_t vectorSize() const { return _xSize; }
106
108 SparseOptimizer* optimizer() const { return _optimizer; }
109 void setOptimizer(SparseOptimizer* optimizer);
110
112 bool levenberg() const { return _isLevenberg; }
113 void setLevenberg(bool levenberg);
114
120 virtual bool supportsSchur() { return false; }
121
123 virtual bool schur() = 0;
124 virtual void setSchur(bool s) = 0;
125
126 size_t additionalVectorSpace() const { return _additionalVectorSpace; }
127 void setAdditionalVectorSpace(size_t s);
128
132 virtual void setWriteDebug(bool) = 0;
133 virtual bool writeDebug() const = 0;
134
136 virtual bool saveHessian(const std::string& /*fileName*/) const = 0;
137
138 protected:
140 double* _x;
141 double* _b;
142 size_t _xSize, _maxXSize;
146
147 void resizeVector(size_t sx);
148
149 private:
150 // Disable the copy constructor and assignment operator
151 Solver(const Solver&) {}
152 Solver& operator=(const Solver&) { return *this; }
153};
154} // namespace g2o
155
156#endif
std::set< Edge * > EdgeSet
Generic interface for a sparse solver operating on a graph which solves one iteration of the lineariz...
Definition solver.h:44
virtual bool updateStructure(const std::vector< HyperGraph::Vertex * > &vset, const HyperGraph::EdgeSet &edges)=0
Solver(const Solver &)
Definition solver.h:151
double * b()
return b, the right hand side of the system
Definition solver.h:101
virtual bool writeDebug() const =0
virtual bool computeMarginals(SparseBlockMatrix< MatrixX > &spinv, const std::vector< std::pair< int, int > > &blockIndices)=0
virtual bool saveHessian(const std::string &) const =0
write the hessian to disk using the specified file name
size_t _maxXSize
Definition solver.h:142
virtual void setSchur(bool s)=0
virtual bool supportsSchur()
Definition solver.h:120
virtual void restoreDiagonal()=0
const double * b() const
Definition solver.h:102
double * _b
Definition solver.h:141
virtual bool init(SparseOptimizer *optimizer, bool online=false)=0
size_t _additionalVectorSpace
Definition solver.h:145
virtual bool buildStructure(bool zeroBlocks=false)=0
size_t vectorSize() const
return the size of the solution vector (x) and b
Definition solver.h:105
double * x()
return x, the solution vector
Definition solver.h:98
bool _isLevenberg
Definition solver.h:143
virtual bool setLambda(double lambda, bool backup=false)=0
double * _x
Definition solver.h:140
virtual bool solve()=0
Solver & operator=(const Solver &)
Definition solver.h:152
bool levenberg() const
the system is Levenberg-Marquardt
Definition solver.h:112
virtual bool buildSystem()=0
size_t additionalVectorSpace() const
Definition solver.h:126
virtual bool schur()=0
should the solver perform the schur complement or not
virtual void setWriteDebug(bool)=0
const double * x() const
Definition solver.h:99
SparseOptimizer * optimizer() const
the optimizer (graph) on which the solver works
Definition solver.h:108
SparseOptimizer * _optimizer
Definition solver.h:139
Sparse matrix which uses blocks.
#define G2O_CORE_API