g2o
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 //
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 
17 #include "linear_solver_eigen.h"
18 
19 #include "g2o/core/block_solver.h"
20 #include "g2o/core/solver.h"
23 
27 
28 #include "g2o/stuff/macros.h"
29 
30 #define DIM_TO_SOLVER(p, l) BlockSolver< BlockSolverTraits<p, l> >
31 
32 #define ALLOC_EIGEN_SPARSE_CHOLESKY(s, p, l, blockorder) \
33  if (1) { \
34  std::cerr << "# Using EigenSparseCholesky poseDim " << p << " landMarkDim " << l << " blockordering " << blockorder << std::endl; \
35  LinearSolverEigen< DIM_TO_SOLVER(p, l)::PoseMatrixType >* linearSolver = new LinearSolverEigen<DIM_TO_SOLVER(p, l)::PoseMatrixType>(); \
36  linearSolver->setBlockOrdering(blockorder); \
37  s = new DIM_TO_SOLVER(p, l)(linearSolver); \
38  } else (void)0
39 
40 using namespace std;
41 
42 namespace g2o {
43 
47  static OptimizationAlgorithm* createSolver(const std::string& fullSolverName)
48  {
49  g2o::Solver* s = 0;
50 
51  string methodName = fullSolverName.substr(0, 2);
52  string solverName = fullSolverName.substr(3);
53 
54  if (solverName == "var_eigen") {
55  ALLOC_EIGEN_SPARSE_CHOLESKY(s, -1, -1, true);
56  }
57 #if 0
58  else if (solverName == "fix3_2_eigen") {
59  ALLOC_EIGEN_SPARSE_CHOLESKY(s, 3, 2, true);
60  }
61  else if (solverName == "fix6_3_eigen") {
62  ALLOC_EIGEN_SPARSE_CHOLESKY(s, 6, 3, true);
63  }
64  else if (solverName == "fix7_3_eigen") {
65  ALLOC_EIGEN_SPARSE_CHOLESKY(s, 7, 3, true);
66  }
67  else if (solverName == "fix3_2_scalar_eigen") {
68  ALLOC_EIGEN_SPARSE_CHOLESKY(s, 3, 2, false);
69  }
70  else if (solverName == "fix6_3_scalar_eigen") {
71  ALLOC_EIGEN_SPARSE_CHOLESKY(s, 6, 3, false);
72  }
73  else if (solverName == "fix7_3_scalar_eigen") {
74  ALLOC_EIGEN_SPARSE_CHOLESKY(s, 7, 3, false);
75  }
76 #endif
77 
78  OptimizationAlgorithm* snl = 0;
79  if (methodName == "gn") {
81  }
82  else if (methodName == "lm") {
83  snl = new OptimizationAlgorithmLevenberg(s);
84  }
85  else if (methodName == "dl") {
86  BlockSolverBase* blockSolver = dynamic_cast<BlockSolverBase*>(s);
87  snl = new OptimizationAlgorithmDogleg(blockSolver);
88  }
89 
90  return snl;
91  }
92 
94  {
95  public:
98  {
99  return createSolver(property().name);
100  }
101  };
102 
103 
105 
106  G2O_REGISTER_OPTIMIZATION_ALGORITHM(gn_var_eigen, new EigenSolverCreator(OptimizationAlgorithmProperty("gn_var_eigen", "Gauss-Newton: Cholesky solver using Eigen's Sparse Cholesky methods (variable blocksize)", "Eigen", false, Eigen::Dynamic, Eigen::Dynamic)));
107 
108  G2O_REGISTER_OPTIMIZATION_ALGORITHM(lm_var_eigen, new EigenSolverCreator(OptimizationAlgorithmProperty("lm_var_eigen", "Levenberg: Cholesky solver using Eigen's Sparse Cholesky methods (variable blocksize)", "Eigen", false, Eigen::Dynamic, Eigen::Dynamic)));
109 
110  G2O_REGISTER_OPTIMIZATION_ALGORITHM(dl_var_eigen, new EigenSolverCreator(OptimizationAlgorithmProperty("dl_var_eigen", "Dogleg: Cholesky solver using Eigen's Sparse Cholesky methods (variable blocksize)", "Eigen", false, Eigen::Dynamic, Eigen::Dynamic)));
111 }
#define G2O_REGISTER_OPTIMIZATION_ALGORITHM(optimizername, instance)
describe the properties of a solver
#define G2O_REGISTER_OPTIMIZATION_LIBRARY(libraryname)
virtual OptimizationAlgorithm * construct()
allocate a solver operating on optimizer, re-implement for your creator
Implementation of the Levenberg Algorithm.
EigenSolverCreator(const OptimizationAlgorithmProperty &p)
static OptimizationAlgorithm * createSolver(const std::string &fullSolverName)
Implementation of the Gauss Newton Algorithm.
base for allocating an optimization algorithm
Generic interface for a sparse solver operating on a graph which solves one iteration of the lineariz...
Definition: solver.h:44
Implementation of Powell&#39;s Dogleg Algorithm.
Generic interface for a non-linear solver operating on a graph.
base for the block solvers with some basic function interfaces
Definition: block_solver.h:82
#define ALLOC_EIGEN_SPARSE_CHOLESKY(s, p, l, blockorder)