g2o
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
g2o::Solver Class Referenceabstract

Generic interface for a sparse solver operating on a graph which solves one iteration of the linearized objective function. More...

#include <solver.h>

Inheritance diagram for g2o::Solver:
Inheritance graph
[legend]
Collaboration diagram for g2o::Solver:
Collaboration graph
[legend]

Public Member Functions

 Solver ()
 
virtual ~Solver ()
 
virtual bool init (SparseOptimizer *optimizer, bool online=false)=0
 
virtual bool buildStructure (bool zeroBlocks=false)=0
 
virtual bool updateStructure (const std::vector< HyperGraph::Vertex * > &vset, const HyperGraph::EdgeSet &edges)=0
 
virtual bool buildSystem ()=0
 
virtual bool solve ()=0
 
virtual bool computeMarginals (SparseBlockMatrix< MatrixXD > &spinv, const std::vector< std::pair< int, int > > &blockIndices)=0
 
virtual bool setLambda (double lambda, bool backup=false)=0
 
virtual void restoreDiagonal ()=0
 
double * x ()
 return x, the solution vector More...
 
const double * x () const
 
double * b ()
 return b, the right hand side of the system More...
 
const double * b () const
 
size_t vectorSize () const
 return the size of the solution vector (x) and b More...
 
SparseOptimizeroptimizer () const
 the optimizer (graph) on which the solver works More...
 
void setOptimizer (SparseOptimizer *optimizer)
 
bool levenberg () const
 the system is Levenberg-Marquardt More...
 
void setLevenberg (bool levenberg)
 
virtual bool supportsSchur ()
 
virtual bool schur ()=0
 should the solver perform the schur complement or not More...
 
virtual void setSchur (bool s)=0
 
size_t additionalVectorSpace () const
 
void setAdditionalVectorSpace (size_t s)
 
virtual void setWriteDebug (bool)=0
 
virtual bool writeDebug () const =0
 
virtual bool saveHessian (const std::string &) const =0
 write the hessian to disk using the specified file name More...
 

Protected Member Functions

void resizeVector (size_t sx)
 

Protected Attributes

SparseOptimizer_optimizer
 
double * _x
 
double * _b
 
size_t _xSize
 
size_t _maxXSize
 
bool _isLevenberg
 the system we gonna solve is a Levenberg-Marquardt system More...
 
size_t _additionalVectorSpace
 

Private Member Functions

 Solver (const Solver &)
 
Solveroperator= (const Solver &)
 

Detailed Description

Generic interface for a sparse solver operating on a graph which solves one iteration of the linearized objective function.

Definition at line 44 of file solver.h.

Constructor & Destructor Documentation

g2o::Solver::Solver ( )

Definition at line 34 of file solver.cpp.

34  :
35  _optimizer(0), _x(0), _b(0), _xSize(0), _maxXSize(0),
37 {
38 }
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
size_t _additionalVectorSpace
Definition: solver.h:141
bool _isLevenberg
the system we gonna solve is a Levenberg-Marquardt system
Definition: solver.h:140
size_t _maxXSize
Definition: solver.h:139
g2o::Solver::~Solver ( )
virtual

Definition at line 40 of file solver.cpp.

References _b, and _x.

41 {
42  delete[] _x;
43  delete[] _b;
44 }
double * _b
Definition: solver.h:138
double * _x
Definition: solver.h:137
g2o::Solver::Solver ( const Solver )
inlineprivate

Definition at line 147 of file solver.h.

147 { }

Member Function Documentation

size_t g2o::Solver::additionalVectorSpace ( ) const
inline

Definition at line 123 of file solver.h.

123 { return _additionalVectorSpace;}
size_t _additionalVectorSpace
Definition: solver.h:141
double* g2o::Solver::b ( )
inline
const double* g2o::Solver::b ( ) const
inline

Definition at line 100 of file solver.h.

100 { return _b;}
double * _b
Definition: solver.h:138
virtual bool g2o::Solver::buildStructure ( bool  zeroBlocks = false)
pure virtual
virtual bool g2o::Solver::buildSystem ( )
pure virtual
virtual bool g2o::Solver::computeMarginals ( SparseBlockMatrix< MatrixXD > &  spinv,
const std::vector< std::pair< int, int > > &  blockIndices 
)
pure virtual

computes the block diagonal elements of the pattern specified in the input and stores them in given SparseBlockMatrix

Implemented in g2o::BlockSolver< Traits >.

Referenced by g2o::OptimizationAlgorithmWithHessian::computeMarginals().

virtual bool g2o::Solver::init ( SparseOptimizer optimizer,
bool  online = false 
)
pure virtual

initialize the solver, called once before the first iteration

Implemented in g2o::BlockSolver< Traits >.

Referenced by g2o::OptimizationAlgorithmWithHessian::init().

bool g2o::Solver::levenberg ( ) const
inline

the system is Levenberg-Marquardt

Definition at line 110 of file solver.h.

Referenced by setLevenberg().

110 { return _isLevenberg;}
bool _isLevenberg
the system we gonna solve is a Levenberg-Marquardt system
Definition: solver.h:140
Solver& g2o::Solver::operator= ( const Solver )
inlineprivate

Definition at line 148 of file solver.h.

148 { return *this; }
SparseOptimizer* g2o::Solver::optimizer ( ) const
inline

the optimizer (graph) on which the solver works

Definition at line 106 of file solver.h.

Referenced by g2o::BlockSolver< Traits >::init(), setOptimizer(), g2o::OptimizationAlgorithmLevenberg::solve(), g2o::OptimizationAlgorithmGaussNewton::solve(), and g2o::OptimizationAlgorithmDogleg::solve().

106 { return _optimizer;}
SparseOptimizer * _optimizer
Definition: solver.h:136
void g2o::Solver::resizeVector ( size_t  sx)
protected

Definition at line 46 of file solver.cpp.

References _additionalVectorSpace, _b, _maxXSize, _x, and _xSize.

Referenced by g2o::BlockSolver< Traits >::resize(), and g2o::BlockSolver< Traits >::updateStructure().

47 {
48  size_t oldSize = _xSize;
49  _xSize = sx;
50  sx += _additionalVectorSpace; // allocate some additional space if requested
51  if (_maxXSize < sx) {
52  _maxXSize = 2*sx;
53  delete[] _x;
54  _x = new double[_maxXSize];
55 #ifndef NDEBUG
56  memset(_x, 0, _maxXSize * sizeof(double));
57 #endif
58  if (_b) { // backup the former b, might still be needed for online processing
59  memcpy(_x, _b, oldSize * sizeof(double));
60  delete[] _b;
61  _b = new double[_maxXSize];
62  std::swap(_b, _x);
63  } else {
64  _b = new double[_maxXSize];
65 #ifndef NDEBUG
66  memset(_b, 0, _maxXSize * sizeof(double));
67 #endif
68  }
69  }
70 }
double * _b
Definition: solver.h:138
size_t _xSize
Definition: solver.h:139
double * _x
Definition: solver.h:137
size_t _additionalVectorSpace
Definition: solver.h:141
size_t _maxXSize
Definition: solver.h:139
virtual void g2o::Solver::restoreDiagonal ( )
pure virtual

restore a previosly made backup of the diagonal

Implemented in g2o::BlockSolver< Traits >.

Referenced by g2o::OptimizationAlgorithmLevenberg::solve(), and g2o::OptimizationAlgorithmDogleg::solve().

virtual bool g2o::Solver::saveHessian ( const std::string &  ) const
pure virtual

write the hessian to disk using the specified file name

Implemented in g2o::BlockSolver< Traits >.

virtual bool g2o::Solver::schur ( )
pure virtual

should the solver perform the schur complement or not

Implemented in g2o::BlockSolver< Traits >.

Referenced by g2o::OptimizationAlgorithmGaussNewton::printVerbose(), and g2o::OptimizationAlgorithmLevenberg::printVerbose().

void g2o::Solver::setAdditionalVectorSpace ( size_t  s)

Definition at line 82 of file solver.cpp.

References _additionalVectorSpace.

Referenced by g2o::SparseOptimizerIncremental::initSolver().

83 {
85 }
size_t _additionalVectorSpace
Definition: solver.h:141
virtual bool g2o::Solver::setLambda ( double  lambda,
bool  backup = false 
)
pure virtual

update the system while performing Levenberg, i.e., modifying the diagonal components of A by doing += lambda along the main diagonal of the Matrix. Note that this function may be called with a positive and a negative lambda. The latter is used to undo a former modification. If backup is true, then the solver should store a backup of the diagonal, which can be restored by restoreDiagonal()

Implemented in g2o::BlockSolver< Traits >.

Referenced by g2o::OptimizationAlgorithmLevenberg::solve(), and g2o::OptimizationAlgorithmDogleg::solve().

void g2o::Solver::setLevenberg ( bool  levenberg)

Definition at line 77 of file solver.cpp.

References _isLevenberg, and levenberg().

78 {
80 }
bool levenberg() const
the system is Levenberg-Marquardt
Definition: solver.h:110
bool _isLevenberg
the system we gonna solve is a Levenberg-Marquardt system
Definition: solver.h:140
void g2o::Solver::setOptimizer ( SparseOptimizer optimizer)

Definition at line 72 of file solver.cpp.

References _optimizer, and optimizer().

73 {
75 }
SparseOptimizer * _optimizer
Definition: solver.h:136
SparseOptimizer * optimizer() const
the optimizer (graph) on which the solver works
Definition: solver.h:106
virtual void g2o::Solver::setSchur ( bool  s)
pure virtual
virtual void g2o::Solver::setWriteDebug ( bool  )
pure virtual

write debug output of the Hessian if system is not positive definite

Implemented in g2o::BlockSolver< Traits >.

Referenced by g2o::OptimizationAlgorithmWithHessian::init().

virtual bool g2o::Solver::solve ( )
pure virtual
virtual bool g2o::Solver::supportsSchur ( )
inlinevirtual

does this solver support the Schur complement for solving a system consisting of poses and landmarks. Re-implemement in a derived solver, if your solver supports it.

Reimplemented in g2o::BlockSolver< Traits >.

Definition at line 117 of file solver.h.

Referenced by g2o::OptimizationAlgorithmWithHessian::init().

117 {return false;}
virtual bool g2o::Solver::updateStructure ( const std::vector< HyperGraph::Vertex * > &  vset,
const HyperGraph::EdgeSet edges 
)
pure virtual

update the structures for online processing

Implemented in g2o::BlockSolver< Traits >.

Referenced by g2o::OptimizationAlgorithmWithHessian::updateStructure().

size_t g2o::Solver::vectorSize ( ) const
inline

return the size of the solution vector (x) and b

Definition at line 103 of file solver.h.

Referenced by g2o::OptimizationAlgorithmLevenberg::computeScale(), and g2o::OptimizationAlgorithmDogleg::solve().

103 { return _xSize;}
size_t _xSize
Definition: solver.h:139
virtual bool g2o::Solver::writeDebug ( ) const
pure virtual

Implemented in g2o::BlockSolver< Traits >.

double* g2o::Solver::x ( )
inline
const double* g2o::Solver::x ( ) const
inline

Definition at line 97 of file solver.h.

97 { return _x;}
double * _x
Definition: solver.h:137

Member Data Documentation

size_t g2o::Solver::_additionalVectorSpace
protected

Definition at line 141 of file solver.h.

Referenced by resizeVector(), and setAdditionalVectorSpace().

double* g2o::Solver::_b
protected
bool g2o::Solver::_isLevenberg
protected

the system we gonna solve is a Levenberg-Marquardt system

Definition at line 140 of file solver.h.

Referenced by setLevenberg().

size_t g2o::Solver::_maxXSize
protected

Definition at line 139 of file solver.h.

Referenced by resizeVector().

SparseOptimizer* g2o::Solver::_optimizer
protected
double* g2o::Solver::_x
protected

Definition at line 137 of file solver.h.

Referenced by resizeVector(), g2o::BlockSolver< Traits >::solve(), and ~Solver().

size_t g2o::Solver::_xSize
protected

Definition at line 139 of file solver.h.

Referenced by g2o::BlockSolver< Traits >::BlockSolver(), and resizeVector().


The documentation for this class was generated from the following files: