g2o
Toggle main menu visibility
Loading...
Searching...
No Matches
g2o
solvers
pcg
solver_pcg.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_factory.h
"
29
#include "
g2o/core/optimization_algorithm_gauss_newton.h
"
30
#include "
g2o/core/optimization_algorithm_levenberg.h
"
31
#include "
g2o/core/solver.h
"
32
#include "
g2o/stuff/logger.h
"
33
#include "
g2o/stuff/macros.h
"
34
#include "
linear_solver_pcg.h
"
35
36
using namespace
std
;
37
38
namespace
g2o
{
39
namespace
{
40
template
<
int
p,
int
l>
41
std::unique_ptr<g2o::Solver> AllocateSolver() {
42
G2O_DEBUG
(
"Using PCG poseDim {} landMarkDim {}"
, p, l);
43
return
std::make_unique<BlockSolverPL<p, l>>(
44
std::make_unique<
45
LinearSolverPCG<typename BlockSolverPL<p, l>::PoseMatrixType
>>());
46
}
47
}
// namespace
48
49
static
OptimizationAlgorithm
*
createSolver
(
const
std::string& fullSolverName) {
50
static
const
std::map<std::string,
51
std::function<std::unique_ptr<g2o::Solver>()>>
52
solver_factories{
53
{
"pcg"
, &AllocateSolver<-1, -1>},
54
{
"pcg3_2"
, &AllocateSolver<3, 2>},
55
{
"pcg6_3"
, &AllocateSolver<6, 3>},
56
{
"pcg7_3"
, &AllocateSolver<7, 3>},
57
};
58
59
string
solverName = fullSolverName.substr(3);
60
auto
solverf = solver_factories.find(solverName);
61
if
(solverf == solver_factories.end())
return
nullptr
;
62
63
string
methodName = fullSolverName.substr(0, 2);
64
65
if
(methodName ==
"gn"
) {
66
return
new
OptimizationAlgorithmGaussNewton
(solverf->second());
67
}
else
if
(methodName ==
"lm"
) {
68
return
new
OptimizationAlgorithmLevenberg
(solverf->second());
69
}
70
71
return
nullptr
;
72
}
73
74
class
PCGSolverCreator
:
public
AbstractOptimizationAlgorithmCreator
{
75
public
:
76
explicit
PCGSolverCreator
(
const
OptimizationAlgorithmProperty
& p)
77
:
AbstractOptimizationAlgorithmCreator
(p) {}
78
virtual
OptimizationAlgorithm
*
construct
() {
79
return
createSolver
(
property
().name);
80
}
81
};
82
83
G2O_REGISTER_OPTIMIZATION_LIBRARY
(pcg);
84
85
G2O_REGISTER_OPTIMIZATION_ALGORITHM
(
86
gn_pcg,
new
PCGSolverCreator
(
OptimizationAlgorithmProperty
(
87
"gn_pcg"
,
88
"Gauss-Newton: PCG solver using block-Jacobi pre-conditioner "
89
"(variable blocksize)"
,
90
"PCG"
,
false
, Eigen::Dynamic, Eigen::Dynamic)));
91
G2O_REGISTER_OPTIMIZATION_ALGORITHM
(
92
gn_pcg3_2,
new
PCGSolverCreator
(
OptimizationAlgorithmProperty
(
93
"gn_pcg3_2"
,
94
"Gauss-Newton: PCG solver using block-Jacobi "
95
"pre-conditioner (fixed blocksize)"
,
96
"PCG"
,
true
, 3, 2)));
97
G2O_REGISTER_OPTIMIZATION_ALGORITHM
(
98
gn_pcg6_3,
new
PCGSolverCreator
(
OptimizationAlgorithmProperty
(
99
"gn_pcg6_3"
,
100
"Gauss-Newton: PCG solver using block-Jacobi "
101
"pre-conditioner (fixed blocksize)"
,
102
"PCG"
,
true
, 6, 3)));
103
G2O_REGISTER_OPTIMIZATION_ALGORITHM
(
104
gn_pcg7_3,
new
PCGSolverCreator
(
OptimizationAlgorithmProperty
(
105
"gn_pcg7_3"
,
106
"Gauss-Newton: PCG solver using block-Jacobi "
107
"pre-conditioner (fixed blocksize)"
,
108
"PCG"
,
true
, 7, 3)));
109
G2O_REGISTER_OPTIMIZATION_ALGORITHM
(
110
lm_pcg,
new
PCGSolverCreator
(
OptimizationAlgorithmProperty
(
111
"lm_pcg"
,
112
"Levenberg: PCG solver using block-Jacobi pre-conditioner "
113
"(variable blocksize)"
,
114
"PCG"
,
false
, Eigen::Dynamic, Eigen::Dynamic)));
115
G2O_REGISTER_OPTIMIZATION_ALGORITHM
(
116
lm_pcg3_2,
new
PCGSolverCreator
(
OptimizationAlgorithmProperty
(
117
"lm_pcg3_2"
,
118
"Levenberg: PCG solver using block-Jacobi pre-conditioner "
119
"(fixed blocksize)"
,
120
"PCG"
,
true
, 3, 2)));
121
G2O_REGISTER_OPTIMIZATION_ALGORITHM
(
122
lm_pcg6_3,
new
PCGSolverCreator
(
OptimizationAlgorithmProperty
(
123
"lm_pcg6_3"
,
124
"Levenberg: PCG solver using block-Jacobi pre-conditioner "
125
"(fixed blocksize)"
,
126
"PCG"
,
true
, 6, 3)));
127
G2O_REGISTER_OPTIMIZATION_ALGORITHM
(
128
lm_pcg7_3,
new
PCGSolverCreator
(
OptimizationAlgorithmProperty
(
129
"lm_pcg7_3"
,
130
"Levenberg: PCG solver using block-Jacobi pre-conditioner "
131
"(fixed blocksize)"
,
132
"PCG"
,
true
, 7, 3)));
133
}
// 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::LinearSolverPCG
linear solver using PCG, pre-conditioner is block Jacobi
Definition
linear_solver_pcg.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
g2o::PCGSolverCreator
Definition
solver_pcg.cpp:74
g2o::PCGSolverCreator::construct
virtual OptimizationAlgorithm * construct()
allocate a solver operating on optimizer, re-implement for your creator
Definition
solver_pcg.cpp:78
g2o::PCGSolverCreator::PCGSolverCreator
PCGSolverCreator(const OptimizationAlgorithmProperty &p)
Definition
solver_pcg.cpp:76
linear_solver_pcg.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_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