g2o
Toggle main menu visibility
Loading...
Searching...
No Matches
g2o
solvers
eigen
solver_eigen.cpp
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
#include "
g2o/core/block_solver.h
"
28
#include "
g2o/core/optimization_algorithm_dogleg.h
"
29
#include "
g2o/core/optimization_algorithm_factory.h
"
30
#include "
g2o/core/optimization_algorithm_gauss_newton.h
"
31
#include "
g2o/core/optimization_algorithm_levenberg.h
"
32
#include "
g2o/core/solver.h
"
33
#include "
g2o/core/sparse_optimizer.h
"
34
#include "
g2o/stuff/logger.h
"
35
#include "
g2o/stuff/macros.h
"
36
#include "
linear_solver_eigen.h
"
37
38
using namespace
std
;
39
40
namespace
g2o
{
41
42
namespace
{
43
template
<
int
p,
int
l,
bool
blockorder>
44
std::unique_ptr<BlockSolverBase> AllocateSolver() {
45
G2O_DEBUG
(
46
"Using EigenSparseCholesky poseDim {} landMarkDim {} blockordering {}"
, p,
47
l, blockorder);
48
auto
linearSolver = std::make_unique<
49
LinearSolverEigen<typename BlockSolverPL<p, l>::PoseMatrixType
>>();
50
linearSolver->
setBlockOrdering
(blockorder);
51
return
std::make_unique<BlockSolverPL<p, l>>(std::move(linearSolver));
52
}
53
}
// namespace
54
58
static
OptimizationAlgorithm
*
createSolver
(
const
std::string& fullSolverName) {
59
static
const
std::map<std::string,
60
std::function<std::unique_ptr<BlockSolverBase>()>>
61
solver_factories{
62
{
"var"
, &AllocateSolver<-1, -1,
true
>},
63
{
"fix3_2"
, &AllocateSolver<3, 2, true>},
64
{
"fix6_3"
, &AllocateSolver<6, 3, true>},
65
{
"fix7_3"
, &AllocateSolver<7, 3, true>},
66
{
"fix3_2_scalar"
, &AllocateSolver<3, 2, false>},
67
{
"fix6_3_scalar"
, &AllocateSolver<6, 3, false>},
68
{
"fix7_3_scalar"
, &AllocateSolver<7, 3, false>},
69
};
70
71
string
solverName = fullSolverName.substr(3);
72
auto
solverf = solver_factories.find(solverName);
73
if
(solverf == solver_factories.end())
return
nullptr
;
74
75
string
methodName = fullSolverName.substr(0, 2);
76
77
if
(methodName ==
"gn"
) {
78
return
new
OptimizationAlgorithmGaussNewton
(solverf->second());
79
}
else
if
(methodName ==
"lm"
) {
80
return
new
OptimizationAlgorithmLevenberg
(solverf->second());
81
}
else
if
(methodName ==
"dl"
) {
82
return
new
OptimizationAlgorithmDogleg
(solverf->second());
83
}
84
85
return
nullptr
;
86
}
87
88
class
EigenSolverCreator
:
public
AbstractOptimizationAlgorithmCreator
{
89
public
:
90
explicit
EigenSolverCreator
(
const
OptimizationAlgorithmProperty
& p)
91
:
AbstractOptimizationAlgorithmCreator
(p) {}
92
virtual
OptimizationAlgorithm
*
construct
() {
93
return
createSolver
(
property
().name);
94
}
95
};
96
97
// clang-format off
98
G2O_REGISTER_OPTIMIZATION_LIBRARY
(eigen);
99
100
G2O_REGISTER_OPTIMIZATION_ALGORITHM
(gn_var,
new
EigenSolverCreator
(
OptimizationAlgorithmProperty
(
"gn_var"
,
"Gauss-Newton: Cholesky solver using Eigen's Sparse Cholesky methods (variable blocksize)"
,
"Eigen"
,
false
, Eigen::Dynamic, Eigen::Dynamic)));
101
G2O_REGISTER_OPTIMIZATION_ALGORITHM
(gn_fix3_2,
new
EigenSolverCreator
(
OptimizationAlgorithmProperty
(
"gn_fix3_2"
,
"Gauss-Newton: Cholesky solver using Eigen's Sparse Cholesky (fixed blocksize)"
,
"Eigen"
,
true
, 3, 2)));
102
G2O_REGISTER_OPTIMIZATION_ALGORITHM
(gn_fix6_3,
new
EigenSolverCreator
(
OptimizationAlgorithmProperty
(
"gn_fix6_3"
,
"Gauss-Newton: Cholesky solver using Eigen's Sparse Cholesky (fixed blocksize)"
,
"Eigen"
,
true
, 6, 3)));
103
G2O_REGISTER_OPTIMIZATION_ALGORITHM
(gn_fix7_3,
new
EigenSolverCreator
(
OptimizationAlgorithmProperty
(
"gn_fix7_3"
,
"Gauss-Newton: Cholesky solver using Eigen's Sparse Cholesky (fixed blocksize)"
,
"Eigen"
,
true
, 7, 3)));
104
105
G2O_REGISTER_OPTIMIZATION_ALGORITHM
(lm_var,
new
EigenSolverCreator
(
OptimizationAlgorithmProperty
(
"lm_var"
,
"Levenberg: Cholesky solver using Eigen's Sparse Cholesky methods (variable blocksize)"
,
"Eigen"
,
false
, Eigen::Dynamic, Eigen::Dynamic)));
106
G2O_REGISTER_OPTIMIZATION_ALGORITHM
(lm_fix3_2,
new
EigenSolverCreator
(
OptimizationAlgorithmProperty
(
"lm_fix3_2"
,
"Levenberg: Cholesky solver using Eigen's Sparse Cholesky (fixed blocksize)"
,
"Eigen"
,
true
, 3, 2)));
107
G2O_REGISTER_OPTIMIZATION_ALGORITHM
(lm_fix6_3,
new
EigenSolverCreator
(
OptimizationAlgorithmProperty
(
"lm_fix6_3"
,
"Levenberg: Cholesky solver using Eigen's Sparse Cholesky (fixed blocksize)"
,
"Eigen"
,
true
, 6, 3)));
108
G2O_REGISTER_OPTIMIZATION_ALGORITHM
(lm_fix7_3,
new
EigenSolverCreator
(
OptimizationAlgorithmProperty
(
"lm_fix7_3"
,
"Levenberg: Cholesky solver using Eigen's Sparse Cholesky (fixed blocksize)"
,
"Eigen"
,
true
, 7, 3)));
109
110
G2O_REGISTER_OPTIMIZATION_ALGORITHM
(dl_var,
new
EigenSolverCreator
(
OptimizationAlgorithmProperty
(
"dl_var"
,
"Dogleg: Cholesky solver using Eigen's Sparse Cholesky methods (variable blocksize)"
,
"Eigen"
,
false
, Eigen::Dynamic, Eigen::Dynamic)));
111
// clang-format on
112
}
// namespace g2o
block_solver.h
g2o::AbstractOptimizationAlgorithmCreator::property
const OptimizationAlgorithmProperty & property() const
return the properties of the solver
Definition
optimization_algorithm_factory.h:60
g2o::AbstractOptimizationAlgorithmCreator::AbstractOptimizationAlgorithmCreator
AbstractOptimizationAlgorithmCreator(const OptimizationAlgorithmProperty &p)
Definition
optimization_algorithm_factory.cpp:39
g2o::EigenSolverCreator
Definition
solver_eigen.cpp:88
g2o::EigenSolverCreator::EigenSolverCreator
EigenSolverCreator(const OptimizationAlgorithmProperty &p)
Definition
solver_eigen.cpp:90
g2o::EigenSolverCreator::construct
virtual OptimizationAlgorithm * construct()
allocate a solver operating on optimizer, re-implement for your creator
Definition
solver_eigen.cpp:92
g2o::LinearSolverCCS::setBlockOrdering
void setBlockOrdering(bool blockOrdering)
Definition
linear_solver.h:177
g2o::LinearSolverEigen
linear solver which uses the sparse Cholesky solver from Eigen
Definition
linear_solver_eigen.h:51
g2o::OptimizationAlgorithmDogleg
Implementation of Powell's Dogleg Algorithm.
Definition
optimization_algorithm_dogleg.h:43
g2o::OptimizationAlgorithmGaussNewton
Implementation of the Gauss Newton Algorithm.
Definition
optimization_algorithm_gauss_newton.h:41
g2o::OptimizationAlgorithmLevenberg
Implementation of the Levenberg Algorithm.
Definition
optimization_algorithm_levenberg.h:41
g2o::OptimizationAlgorithm
Generic interface for a non-linear solver operating on a graph.
Definition
optimization_algorithm.h:46
linear_solver_eigen.h
G2O_DEBUG
#define G2O_DEBUG(...)
logger.h
macros.h
g2o
Definition
dl_wrapper.cpp:55
g2o::createSolver
static OptimizationAlgorithm * createSolver(const std::string &solverName)
Definition
graph_optimizer_sparse_incremental.cpp:471
std
Definition
jet.h:876
optimization_algorithm_dogleg.h
optimization_algorithm_factory.h
G2O_REGISTER_OPTIMIZATION_LIBRARY
#define G2O_REGISTER_OPTIMIZATION_LIBRARY(libraryname)
Definition
optimization_algorithm_factory.h:160
G2O_REGISTER_OPTIMIZATION_ALGORITHM
#define G2O_REGISTER_OPTIMIZATION_ALGORITHM(optimizername, instance)
Definition
optimization_algorithm_factory.h:181
optimization_algorithm_gauss_newton.h
optimization_algorithm_levenberg.h
solver.h
sparse_optimizer.h
g2o::OptimizationAlgorithmProperty
describe the properties of a solver
Definition
optimization_algorithm_property.h:39
Generated on
for g2o by
1.17.0