g2o
Loading...
Searching...
No Matches
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
32#include "g2o/core/solver.h"
34#include "g2o/stuff/logger.h"
35#include "g2o/stuff/macros.h"
36#include "linear_solver_eigen.h"
37
38using namespace std;
39
40namespace g2o {
41
42namespace {
43template <int p, int l, bool blockorder>
44std::unique_ptr<BlockSolverBase> AllocateSolver() {
46 "Using EigenSparseCholesky poseDim {} landMarkDim {} blockordering {}", p,
47 l, blockorder);
48 auto linearSolver = std::make_unique<
50 linearSolver->setBlockOrdering(blockorder);
51 return std::make_unique<BlockSolverPL<p, l>>(std::move(linearSolver));
52}
53} // namespace
54
58static 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
96
97// clang-format off
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
const OptimizationAlgorithmProperty & property() const
return the properties of the solver
AbstractOptimizationAlgorithmCreator(const OptimizationAlgorithmProperty &p)
EigenSolverCreator(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 the sparse Cholesky solver from Eigen
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)