g2o
Toggle main menu visibility
Loading...
Searching...
No Matches
g2o
solvers
cholmod
solver_cholmod.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/stuff/logger.h
"
34
#include "
g2o/stuff/macros.h
"
35
#include "
linear_solver_cholmod.h
"
36
37
// #define ADD_SCALAR_ORDERING
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
(
"Using CHOLMOD poseDim {} landMarkDim {} blockordering {}"
, p, l,
46
blockorder);
47
auto
linearSolver = std::make_unique<
48
LinearSolverCholmod<typename BlockSolverPL<p, l>::PoseMatrixType
>>();
49
linearSolver->
setBlockOrdering
(blockorder);
50
return
std::make_unique<BlockSolverPL<p, l>>(std::move(linearSolver));
51
}
52
}
// namespace
53
54
static
OptimizationAlgorithm
*
createSolver
(
const
std::string& fullSolverName) {
55
static
const
std::map<std::string,
56
std::function<std::unique_ptr<BlockSolverBase>()>>
57
solver_factories{
58
{
"var_cholmod"
, &AllocateSolver<-1, -1,
true
>},
59
{
"fix3_2_cholmod"
, &AllocateSolver<3, 2, true>},
60
{
"fix6_3_cholmod"
, &AllocateSolver<6, 3, true>},
61
{
"fix7_3_cholmod"
, &AllocateSolver<7, 3, true>},
62
#ifdef ADD_SCALAR_ORDERING
63
{
"fix3_2_cholmod_scalar"
, &AllocateSolver<3, 2, false>},
64
{
"fix6_3_cholmod_scalar"
, &AllocateSolver<6, 3, false>},
65
{
"fix7_3_cholmod_scalar"
, &AllocateSolver<7, 3, false>},
66
#endif
67
};
68
69
string
solverName = fullSolverName.substr(3);
70
auto
solverf = solver_factories.find(solverName);
71
if
(solverf == solver_factories.end())
return
nullptr
;
72
73
string
methodName = fullSolverName.substr(0, 2);
74
75
if
(methodName ==
"gn"
) {
76
return
new
OptimizationAlgorithmGaussNewton
(solverf->second());
77
}
else
if
(methodName ==
"lm"
) {
78
return
new
OptimizationAlgorithmLevenberg
(solverf->second());
79
}
else
if
(methodName ==
"dl"
) {
80
return
new
OptimizationAlgorithmDogleg
(solverf->second());
81
}
82
83
return
nullptr
;
84
}
85
86
class
CholmodSolverCreator
:
public
AbstractOptimizationAlgorithmCreator
{
87
public
:
88
explicit
CholmodSolverCreator
(
const
OptimizationAlgorithmProperty
& p)
89
:
AbstractOptimizationAlgorithmCreator
(p) {}
90
virtual
OptimizationAlgorithm
*
construct
() {
91
return
createSolver
(
property
().name);
92
}
93
};
94
95
G2O_REGISTER_OPTIMIZATION_LIBRARY
(
cholmod
);
96
97
G2O_REGISTER_OPTIMIZATION_ALGORITHM
(
98
gn_var_cholmod,
99
new
CholmodSolverCreator
(
OptimizationAlgorithmProperty
(
100
"gn_var_cholmod"
,
101
"Gauss-Newton: Cholesky solver using CHOLMOD (variable blocksize)"
,
102
"CHOLMOD"
,
false
, Eigen::Dynamic, Eigen::Dynamic)));
103
G2O_REGISTER_OPTIMIZATION_ALGORITHM
(
104
gn_fix3_2_cholmod,
105
new
CholmodSolverCreator
(
OptimizationAlgorithmProperty
(
106
"gn_fix3_2_cholmod"
,
107
"Gauss-Newton: Cholesky solver using CHOLMOD (fixed blocksize)"
,
108
"CHOLMOD"
,
true
, 3, 2)));
109
G2O_REGISTER_OPTIMIZATION_ALGORITHM
(
110
gn_fix6_3_cholmod,
111
new
CholmodSolverCreator
(
OptimizationAlgorithmProperty
(
112
"gn_fix6_3_cholmod"
,
113
"Gauss-Newton: Cholesky solver using CHOLMOD (fixed blocksize)"
,
114
"CHOLMOD"
,
true
, 6, 3)));
115
G2O_REGISTER_OPTIMIZATION_ALGORITHM
(
116
gn_fix7_3_cholmod,
117
new
CholmodSolverCreator
(
OptimizationAlgorithmProperty
(
118
"gn_fix7_3_cholmod"
,
119
"Gauss-Newton: Cholesky solver using CHOLMOD (fixed blocksize)"
,
120
"CHOLMOD"
,
true
, 7, 3)));
121
G2O_REGISTER_OPTIMIZATION_ALGORITHM
(
122
lm_var_cholmod,
123
new
CholmodSolverCreator
(
OptimizationAlgorithmProperty
(
124
"lm_var_cholmod"
,
125
"Levenberg: Cholesky solver using CHOLMOD (variable blocksize)"
,
126
"CHOLMOD"
,
false
, Eigen::Dynamic, Eigen::Dynamic)));
127
G2O_REGISTER_OPTIMIZATION_ALGORITHM
(
128
lm_fix3_2_cholmod,
129
new
CholmodSolverCreator
(
OptimizationAlgorithmProperty
(
130
"lm_fix3_2_cholmod"
,
131
"Levenberg: Cholesky solver using CHOLMOD (fixed blocksize)"
,
"CHOLMOD"
,
132
true
, 3, 2)));
133
G2O_REGISTER_OPTIMIZATION_ALGORITHM
(
134
lm_fix6_3_cholmod,
135
new
CholmodSolverCreator
(
OptimizationAlgorithmProperty
(
136
"lm_fix6_3_cholmod"
,
137
"Levenberg: Cholesky solver using CHOLMOD (fixed blocksize)"
,
"CHOLMOD"
,
138
true
, 6, 3)));
139
G2O_REGISTER_OPTIMIZATION_ALGORITHM
(
140
lm_fix7_3_cholmod,
141
new
CholmodSolverCreator
(
OptimizationAlgorithmProperty
(
142
"lm_fix7_3_cholmod"
,
143
"Levenberg: Cholesky solver using CHOLMOD (fixed blocksize)"
,
"CHOLMOD"
,
144
true
, 7, 3)));
145
146
#ifdef ADD_SCALAR_ORDERING
147
G2O_REGISTER_OPTIMIZATION_ALGORITHM
(
148
gn_fix3_2_cholmod_scalar,
149
new
CholmodSolverCreator
(
OptimizationAlgorithmProperty
(
150
"gn_fix3_2_cholmod_scalar"
,
151
"Gauss-Newton: Cholesky solver using CHOLMOD (fixed blocksize, scalar "
152
"ordering)"
,
153
"CHOLMOD"
,
true
, 3, 2)));
154
G2O_REGISTER_OPTIMIZATION_ALGORITHM
(
155
gn_fix6_3_cholmod_scalar,
156
new
CholmodSolverCreator
(
OptimizationAlgorithmProperty
(
157
"gn_fix6_3_cholmod_scalar"
,
158
"Gauss-Newton: Cholesky solver using CHOLMOD (fixed blocksize, scalar "
159
"ordering)"
,
160
"CHOLMOD"
,
true
, 6, 3)));
161
G2O_REGISTER_OPTIMIZATION_ALGORITHM
(
162
gn_fix7_3_cholmod_scalar,
163
new
CholmodSolverCreator
(
OptimizationAlgorithmProperty
(
164
"gn_fix7_3_cholmod_scalar"
,
165
"Gauss-Newton: Cholesky solver using CHOLMOD (fixed blocksize, scalar "
166
"ordering)"
,
167
"CHOLMOD"
,
true
, 7, 3)));
168
G2O_REGISTER_OPTIMIZATION_ALGORITHM
(
169
lm_fix3_2_cholmod_scalar,
170
new
CholmodSolverCreator
(
OptimizationAlgorithmProperty
(
171
"lm_fix3_2_cholmod_scalar"
,
172
"Levenberg: Cholesky solver using CHOLMOD (fixed blocksize, scalar "
173
"ordering)"
,
174
"CHOLMOD"
,
true
, 3, 2)));
175
G2O_REGISTER_OPTIMIZATION_ALGORITHM
(
176
lm_fix6_3_cholmod_scalar,
177
new
CholmodSolverCreator
(
OptimizationAlgorithmProperty
(
178
"lm_fix6_3_cholmod_scalar"
,
179
"Levenberg: Cholesky solver using CHOLMOD (fixed blocksize, scalar "
180
"ordering)"
,
181
"CHOLMOD"
,
true
, 6, 3)));
182
G2O_REGISTER_OPTIMIZATION_ALGORITHM
(
183
lm_fix7_3_cholmod_scalar,
184
new
CholmodSolverCreator
(
OptimizationAlgorithmProperty
(
185
"lm_fix7_3_cholmod_scalar"
,
186
"Levenberg: Cholesky solver using CHOLMOD (fixed blocksize, scalar "
187
"ordering)"
,
188
"CHOLMOD"
,
true
, 7, 3)));
189
#endif
190
191
G2O_REGISTER_OPTIMIZATION_ALGORITHM
(
192
dl_var_cholmod,
193
new
CholmodSolverCreator
(
OptimizationAlgorithmProperty
(
194
"dl_var_cholmod"
,
195
"Dogleg: Cholesky solver using CHOLMOD (variable blocksize)"
,
"CHOLMOD"
,
196
false
, Eigen::Dynamic, Eigen::Dynamic)));
197
}
// 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::CholmodSolverCreator
Definition
solver_cholmod.cpp:86
g2o::CholmodSolverCreator::construct
virtual OptimizationAlgorithm * construct()
allocate a solver operating on optimizer, re-implement for your creator
Definition
solver_cholmod.cpp:90
g2o::CholmodSolverCreator::CholmodSolverCreator
CholmodSolverCreator(const OptimizationAlgorithmProperty &p)
Definition
solver_cholmod.cpp:88
g2o::LinearSolverCCS::setBlockOrdering
void setBlockOrdering(bool blockOrdering)
Definition
linear_solver.h:177
g2o::LinearSolverCholmod
basic solver for Ax = b which has to reimplemented for different linear algebra libraries
Definition
linear_solver_cholmod.h:47
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_cholmod.h
G2O_DEBUG
#define G2O_DEBUG(...)
logger.h
macros.h
g2o::cholmod
Definition
graph_optimizer_sparse_incremental.h:27
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
g2o::OptimizationAlgorithmProperty
describe the properties of a solver
Definition
optimization_algorithm_property.h:39
Generated on
for g2o by
1.17.0