g2o
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 
17 #include "linear_solver_csparse.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 ADD_SCALAR_ORDERING
31 
32 #define DIM_TO_SOLVER(p, l) BlockSolver< BlockSolverTraits<p, l> >
33 
34 #define ALLOC_CSPARSE(s, p, l, blockorder) \
35  if (1) { \
36  std::cerr << "# Using CSparse poseDim " << p << " landMarkDim " << l << " blockordering " << blockorder << std::endl; \
37  LinearSolverCSparse< DIM_TO_SOLVER(p, l)::PoseMatrixType >* linearSolver = new LinearSolverCSparse<DIM_TO_SOLVER(p, l)::PoseMatrixType>(); \
38  linearSolver->setBlockOrdering(blockorder); \
39  s = new DIM_TO_SOLVER(p, l)(linearSolver); \
40  } else (void)0
41 
42 using namespace std;
43 
44 namespace g2o {
45 
49  static OptimizationAlgorithm* createSolver(const std::string& fullSolverName)
50  {
51  g2o::Solver* s = 0;
52 
53  string methodName = fullSolverName.substr(0, 2);
54  string solverName = fullSolverName.substr(3);
55 
56  if (solverName == "var") {
57  ALLOC_CSPARSE(s, -1, -1, false);
58  }
59  else if (solverName == "fix3_2") {
60  ALLOC_CSPARSE(s, 3, 2, true);
61  }
62  else if (solverName == "fix6_3") {
63  ALLOC_CSPARSE(s, 6, 3, true);
64  }
65  else if (solverName == "fix7_3") {
66  ALLOC_CSPARSE(s, 7, 3, true);
67  }
68 # ifdef ADD_SCALAR_ORDERING
69  else if (solverName == "fix3_2_scalar") {
70  ALLOC_CSPARSE(s, 3, 2, false);
71  }
72  else if (solverName == "fix6_3_scalar") {
73  ALLOC_CSPARSE(s, 6, 3, false);
74  }
75  else if (solverName == "fix7_3_scalar") {
76  ALLOC_CSPARSE(s, 7, 3, false);
77  }
78 #endif
79 
80  OptimizationAlgorithm* snl = 0;
81  if (methodName == "gn") {
83  }
84  else if (methodName == "lm") {
85  snl = new OptimizationAlgorithmLevenberg(s);
86  }
87  else if (methodName == "dl") {
88  BlockSolverBase* blockSolver = dynamic_cast<BlockSolverBase*>(s);
89  snl = new OptimizationAlgorithmDogleg(blockSolver);
90  }
91 
92  return snl;
93  }
94 
96  {
97  public:
100  {
101  return createSolver(property().name);
102  }
103  };
104 
105 
107 
108  G2O_REGISTER_OPTIMIZATION_ALGORITHM(gn_var, new CSparseSolverCreator(OptimizationAlgorithmProperty("gn_var", "Gauss-Newton: Cholesky solver using CSparse (variable blocksize)", "CSparse", false, Eigen::Dynamic, Eigen::Dynamic)));
109  G2O_REGISTER_OPTIMIZATION_ALGORITHM(gn_fix3_2, new CSparseSolverCreator(OptimizationAlgorithmProperty("gn_fix3_2", "Gauss-Newton: Cholesky solver using CSparse (fixed blocksize)", "CSparse", true, 3, 2)));
110  G2O_REGISTER_OPTIMIZATION_ALGORITHM(gn_fix6_3, new CSparseSolverCreator(OptimizationAlgorithmProperty("gn_fix6_3", "Gauss-Newton: Cholesky solver using CSparse (fixed blocksize)", "CSparse", true, 6, 3)));
111  G2O_REGISTER_OPTIMIZATION_ALGORITHM(gn_fix7_3, new CSparseSolverCreator(OptimizationAlgorithmProperty("gn_fix7_3", "Gauss-Newton: Cholesky solver using CSparse (fixed blocksize)", "CSparse", true, 7, 3)));
112  G2O_REGISTER_OPTIMIZATION_ALGORITHM(lm_var, new CSparseSolverCreator(OptimizationAlgorithmProperty("lm_var", "Levenberg: Cholesky solver using CSparse (variable blocksize)", "CSparse", false, Eigen::Dynamic, Eigen::Dynamic)));
113  G2O_REGISTER_OPTIMIZATION_ALGORITHM(lm_fix3_2, new CSparseSolverCreator(OptimizationAlgorithmProperty("lm_fix3_2", "Levenberg: Cholesky solver using CSparse (fixed blocksize)", "CSparse", true, 3, 2)));
114  G2O_REGISTER_OPTIMIZATION_ALGORITHM(lm_fix6_3, new CSparseSolverCreator(OptimizationAlgorithmProperty("lm_fix6_3", "Levenberg: Cholesky solver using CSparse (fixed blocksize)", "CSparse", true, 6, 3)));
115  G2O_REGISTER_OPTIMIZATION_ALGORITHM(lm_fix7_3, new CSparseSolverCreator(OptimizationAlgorithmProperty("lm_fix7_3", "Levenberg: Cholesky solver using CSparse (fixed blocksize)", "CSparse", true, 7, 3)));
116 
117 #ifdef ADD_SCALAR_ORDERING
118  G2O_REGISTER_OPTIMIZATION_ALGORITHM(gn_fix3_2_scalar, new CSparseSolverCreator(OptimizationAlgorithmProperty("gn_fix3_2_scalar", "Gauss-Newton: Cholesky solver using CSparse (fixed blocksize, scalar ordering)", "CSparse", true, 3, 2)));
119  G2O_REGISTER_OPTIMIZATION_ALGORITHM(gn_fix6_3_scalar, new CSparseSolverCreator(OptimizationAlgorithmProperty("gn_fix6_3_scalar", "Gauss-Newton: Cholesky solver using CSparse (fixed blocksize, scalar ordering)", "CSparse", true, 6, 3)));
120  G2O_REGISTER_OPTIMIZATION_ALGORITHM(gn_fix7_3_scalar, new CSparseSolverCreator(OptimizationAlgorithmProperty("gn_fix7_3_scalar", "Gauss-Newton: Cholesky solver using CSparse (fixed blocksize, scalar ordering)", "CSparse", true, 7, 3)));
121  G2O_REGISTER_OPTIMIZATION_ALGORITHM(lm_fix3_2_scalar, new CSparseSolverCreator(OptimizationAlgorithmProperty("lm_fix3_2_scalar", "Levenberg: Cholesky solver using CSparse (fixed blocksize, scalar ordering)", "CSparse", true, 3, 2)));
122  G2O_REGISTER_OPTIMIZATION_ALGORITHM(lm_fix6_3_scalar, new CSparseSolverCreator(OptimizationAlgorithmProperty("lm_fix6_3_scalar", "Levenberg: Cholesky solver using CSparse (fixed blocksize, scalar ordering)", "CSparse", true, 6, 3)));
123  G2O_REGISTER_OPTIMIZATION_ALGORITHM(lm_fix7_3_scalar,new CSparseSolverCreator(OptimizationAlgorithmProperty("lm_fix7_3_scalar", "Levenberg: Cholesky solver using CSparse (fixed blocksize, scalar ordering)", "CSparse", true, 7, 3)));
124 #endif
125 
126  G2O_REGISTER_OPTIMIZATION_ALGORITHM(dl_var, new CSparseSolverCreator(OptimizationAlgorithmProperty("dl_var", "Dogleg: Cholesky solver using CSparse (variable blocksize)", "CSparse", false, Eigen::Dynamic, Eigen::Dynamic)));
127 }
CSparseSolverCreator(const OptimizationAlgorithmProperty &p)
#define G2O_REGISTER_OPTIMIZATION_ALGORITHM(optimizername, instance)
virtual OptimizationAlgorithm * construct()
allocate a solver operating on optimizer, re-implement for your creator
describe the properties of a solver
#define G2O_REGISTER_OPTIMIZATION_LIBRARY(libraryname)
Implementation of the Levenberg Algorithm.
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
#define ALLOC_CSPARSE(s, p, l, blockorder)
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