g2o
Loading...
Searching...
No Matches
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
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
36using namespace std;
37
38namespace g2o {
39namespace {
40template <int p, int l>
41std::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
49static 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
82
84
87 "gn_pcg",
88 "Gauss-Newton: PCG solver using block-Jacobi pre-conditioner "
89 "(variable blocksize)",
90 "PCG", false, Eigen::Dynamic, Eigen::Dynamic)));
93 "gn_pcg3_2",
94 "Gauss-Newton: PCG solver using block-Jacobi "
95 "pre-conditioner (fixed blocksize)",
96 "PCG", true, 3, 2)));
99 "gn_pcg6_3",
100 "Gauss-Newton: PCG solver using block-Jacobi "
101 "pre-conditioner (fixed blocksize)",
102 "PCG", true, 6, 3)));
105 "gn_pcg7_3",
106 "Gauss-Newton: PCG solver using block-Jacobi "
107 "pre-conditioner (fixed blocksize)",
108 "PCG", true, 7, 3)));
111 "lm_pcg",
112 "Levenberg: PCG solver using block-Jacobi pre-conditioner "
113 "(variable blocksize)",
114 "PCG", false, Eigen::Dynamic, Eigen::Dynamic)));
117 "lm_pcg3_2",
118 "Levenberg: PCG solver using block-Jacobi pre-conditioner "
119 "(fixed blocksize)",
120 "PCG", true, 3, 2)));
123 "lm_pcg6_3",
124 "Levenberg: PCG solver using block-Jacobi pre-conditioner "
125 "(fixed blocksize)",
126 "PCG", true, 6, 3)));
129 "lm_pcg7_3",
130 "Levenberg: PCG solver using block-Jacobi pre-conditioner "
131 "(fixed blocksize)",
132 "PCG", true, 7, 3)));
133} // namespace g2o
base for allocating an optimization algorithm
const OptimizationAlgorithmProperty & property() const
return the properties of the solver
Implementation of the Gauss Newton Algorithm.
Implementation of the Levenberg Algorithm.
Generic interface for a non-linear solver operating on a graph.
virtual OptimizationAlgorithm * construct()
allocate a solver operating on optimizer, re-implement for your creator
PCGSolverCreator(const OptimizationAlgorithmProperty &p)
#define G2O_DEBUG(...)
Definition logger.h:90
static OptimizationAlgorithm * createSolver(const std::string &solverName)
Definition jet.h:876
#define G2O_REGISTER_OPTIMIZATION_LIBRARY(libraryname)
#define G2O_REGISTER_OPTIMIZATION_ALGORITHM(optimizername, instance)