g2o
Loading...
Searching...
No Matches
solver_csparse.cpp
Go to the documentation of this file.
1// g2o - General Graph Optimization
2// Copyright (C) 2011 R. Kuemmerle, G. Grisetti, W. Burgard
3//
4// g2o is free software: you can redistribute it and/or modify
5// it under the terms of the GNU Lesser General Public License as published
6// by the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// g2o is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU Lesser General Public License for more details.
13//
14// You should have received a copy of the GNU Lesser General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16
22#include "g2o/core/solver.h"
24#include "g2o/stuff/logger.h"
25#include "g2o/stuff/macros.h"
27
28using namespace std;
29
30namespace g2o {
31
32namespace {
33template <int p, int l, bool blockorder>
34std::unique_ptr<BlockSolverBase> AllocateSolver() {
35 G2O_DEBUG("Using CSparse poseDim {} landMarkDim {} blockordering {}", p, l,
36 blockorder);
37 auto linearSolver = std::make_unique<
39 linearSolver->setBlockOrdering(blockorder);
40 return std::make_unique<BlockSolverPL<p, l>>(std::move(linearSolver));
41}
42} // namespace
43
47static OptimizationAlgorithm* createSolver(const std::string& fullSolverName) {
48 static const std::map<std::string,
49 std::function<std::unique_ptr<BlockSolverBase>()>>
50 solver_factories{
51 {"var_csparse", &AllocateSolver<-1, -1, true>},
52 {"fix3_2_csparse", &AllocateSolver<3, 2, true>},
53 {"fix6_3_csparse", &AllocateSolver<6, 3, true>},
54 {"fix7_3_csparse", &AllocateSolver<7, 3, true>},
55 {"fix3_2_scalar_csparse", &AllocateSolver<3, 2, false>},
56 {"fix6_3_scalar_csparse", &AllocateSolver<6, 3, false>},
57 {"fix7_3_scalar_csparse", &AllocateSolver<7, 3, false>},
58 };
59
60 string solverName = fullSolverName.substr(3);
61 auto solverf = solver_factories.find(solverName);
62 if (solverf == solver_factories.end()) return nullptr;
63
64 string methodName = fullSolverName.substr(0, 2);
65
66 if (methodName == "gn") {
67 return new OptimizationAlgorithmGaussNewton(solverf->second());
68 } else if (methodName == "lm") {
69 return new OptimizationAlgorithmLevenberg(solverf->second());
70 } else if (methodName == "dl") {
71 return new OptimizationAlgorithmDogleg(solverf->second());
72 }
73
74 return nullptr;
75}
76
85
86// clang-format off
88
89 G2O_REGISTER_OPTIMIZATION_ALGORITHM(gn_var_csparse, new CSparseSolverCreator(OptimizationAlgorithmProperty("gn_var_csparse", "Gauss-Newton: Cholesky solver using CSparse (variable blocksize)", "CSparse", false, Eigen::Dynamic, Eigen::Dynamic)));
90 G2O_REGISTER_OPTIMIZATION_ALGORITHM(gn_fix3_2_csparse, new CSparseSolverCreator(OptimizationAlgorithmProperty("gn_fix3_2_csparse", "Gauss-Newton: Cholesky solver using CSparse (fixed blocksize)", "CSparse", true, 3, 2)));
91 G2O_REGISTER_OPTIMIZATION_ALGORITHM(gn_fix6_3_csparse, new CSparseSolverCreator(OptimizationAlgorithmProperty("gn_fix6_3_csparse", "Gauss-Newton: Cholesky solver using CSparse (fixed blocksize)", "CSparse", true, 6, 3)));
92 G2O_REGISTER_OPTIMIZATION_ALGORITHM(gn_fix7_3_csparse, new CSparseSolverCreator(OptimizationAlgorithmProperty("gn_fix7_3_csparse", "Gauss-Newton: Cholesky solver using CSparse (fixed blocksize)", "CSparse", true, 7, 3)));
93 G2O_REGISTER_OPTIMIZATION_ALGORITHM(lm_var_csparse, new CSparseSolverCreator(OptimizationAlgorithmProperty("lm_var_csparse", "Levenberg: Cholesky solver using CSparse (variable blocksize)", "CSparse", false, Eigen::Dynamic, Eigen::Dynamic)));
94 G2O_REGISTER_OPTIMIZATION_ALGORITHM(lm_fix3_2_csparse, new CSparseSolverCreator(OptimizationAlgorithmProperty("lm_fix3_2_csparse", "Levenberg: Cholesky solver using CSparse (fixed blocksize)", "CSparse", true, 3, 2)));
95 G2O_REGISTER_OPTIMIZATION_ALGORITHM(lm_fix6_3_csparse, new CSparseSolverCreator(OptimizationAlgorithmProperty("lm_fix6_3_csparse", "Levenberg: Cholesky solver using CSparse (fixed blocksize)", "CSparse", true, 6, 3)));
96 G2O_REGISTER_OPTIMIZATION_ALGORITHM(lm_fix7_3_csparse, new CSparseSolverCreator(OptimizationAlgorithmProperty("lm_fix7_3_csparse", "Levenberg: Cholesky solver using CSparse (fixed blocksize)", "CSparse", true, 7, 3)));
97
98 G2O_REGISTER_OPTIMIZATION_ALGORITHM(dl_var_csparse, new CSparseSolverCreator(OptimizationAlgorithmProperty("dl_var_csparse", "Dogleg: Cholesky solver using CSparse (variable blocksize)", "CSparse", false, Eigen::Dynamic, Eigen::Dynamic)));
99// clang-format on
100
101} // namespace g2o
const OptimizationAlgorithmProperty & property() const
return the properties of the solver
AbstractOptimizationAlgorithmCreator(const OptimizationAlgorithmProperty &p)
CSparseSolverCreator(const OptimizationAlgorithmProperty &p)
virtual OptimizationAlgorithm * construct()
allocate a solver operating on optimizer, re-implement for your creator
void setBlockOrdering(bool blockOrdering)
linear solver which uses CSparse
Implementation of Powell's Dogleg Algorithm.
Implementation of the Gauss Newton Algorithm.
Implementation of the Levenberg Algorithm.
Generic interface for a non-linear solver operating on a graph.
#define G2O_DEBUG(...)
static OptimizationAlgorithm * createSolver(const std::string &solverName)
Definition jet.h:876
#define G2O_REGISTER_OPTIMIZATION_LIBRARY(libraryname)
#define G2O_REGISTER_OPTIMIZATION_ALGORITHM(optimizername, instance)