g2o
solver_cholmod.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 
27 #include "linear_solver_cholmod.h"
28 
29 #include "g2o/core/block_solver.h"
30 #include "g2o/core/solver.h"
32 
36 
37 #include "g2o/stuff/macros.h"
38 
39 //#define ADD_SCALAR_ORDERING
40 
41 #define DIM_TO_SOLVER(p, l) BlockSolver< BlockSolverTraits<p, l> >
42 
43 #define ALLOC_CHOLMOD(s, p, l, blockorder) \
44  if (1) { \
45  std::cerr << "# Using CHOLMOD poseDim " << p << " landMarkDim " << l << " blockordering " << blockorder << std::endl; \
46  LinearSolverCholmod < DIM_TO_SOLVER(p, l)::PoseMatrixType >* linearSolver = new LinearSolverCholmod<DIM_TO_SOLVER(p, l)::PoseMatrixType>(); \
47  linearSolver->setBlockOrdering(blockorder); \
48  s = new DIM_TO_SOLVER(p, l)(linearSolver); \
49  } else (void)0
50 
51 using namespace std;
52 
53 namespace g2o {
54 
55  static OptimizationAlgorithm* createSolver(const std::string& fullSolverName)
56  {
57  g2o::Solver* s = 0;
58 
59  string methodName = fullSolverName.substr(0, 2);
60  string solverName = fullSolverName.substr(3);
61 
62  if (solverName == "var_cholmod") {
63  ALLOC_CHOLMOD(s, -1, -1, false);
64  }
65  else if (solverName == "fix3_2_cholmod") {
66  ALLOC_CHOLMOD(s, 3, 2, true);
67  }
68  else if (solverName == "fix6_3_cholmod") {
69  ALLOC_CHOLMOD(s, 6, 3, true);
70  }
71  else if (solverName == "fix7_3_cholmod") {
72  ALLOC_CHOLMOD(s, 7, 3, true);
73  }
74 #ifdef ADD_SCALAR_ORDERING
75  else if (solverName == "fix3_2_cholmod_scalar") {
76  ALLOC_CHOLMOD(s, 3, 2, false);
77  }
78  else if (solverName == "fix6_3_cholmod_scalar") {
79  ALLOC_CHOLMOD(s, 6, 3, false);
80  }
81  else if (solverName == "fix7_3_cholmod_scalar") {
82  ALLOC_CHOLMOD(s, 7, 3, false);
83  }
84 #endif
85 
86  OptimizationAlgorithm* snl = 0;
87  if (methodName == "gn") {
89  }
90  else if (methodName == "lm") {
91  snl = new OptimizationAlgorithmLevenberg(s);
92  }
93  else if (methodName == "dl") {
94  BlockSolverBase* blockSolver = dynamic_cast<BlockSolverBase*>(s);
95  snl = new OptimizationAlgorithmDogleg(blockSolver);
96  }
97  else {
98  delete s;
99  }
100 
101  return snl;
102  }
103 
105  {
106  public:
109  {
110  return createSolver(property().name);
111  }
112  };
113 
115 
116  G2O_REGISTER_OPTIMIZATION_ALGORITHM(gn_var_cholmod, new CholmodSolverCreator(OptimizationAlgorithmProperty("gn_var_cholmod", "Gauss-Newton: Cholesky solver using CHOLMOD (variable blocksize)", "CHOLMOD", false, Eigen::Dynamic, Eigen::Dynamic)));
117  G2O_REGISTER_OPTIMIZATION_ALGORITHM(gn_fix3_2_cholmod, new CholmodSolverCreator(OptimizationAlgorithmProperty("gn_fix3_2_cholmod", "Gauss-Newton: Cholesky solver using CHOLMOD (fixed blocksize)", "CHOLMOD", true, 3, 2)));
118  G2O_REGISTER_OPTIMIZATION_ALGORITHM(gn_fix6_3_cholmod, new CholmodSolverCreator(OptimizationAlgorithmProperty("gn_fix6_3_cholmod", "Gauss-Newton: Cholesky solver using CHOLMOD (fixed blocksize)", "CHOLMOD", true, 6, 3)));
119  G2O_REGISTER_OPTIMIZATION_ALGORITHM(gn_fix7_3_cholmod, new CholmodSolverCreator(OptimizationAlgorithmProperty("gn_fix7_3_cholmod", "Gauss-Newton: Cholesky solver using CHOLMOD (fixed blocksize)", "CHOLMOD", true, 7, 3)));
120  G2O_REGISTER_OPTIMIZATION_ALGORITHM(lm_var_cholmod, new CholmodSolverCreator(OptimizationAlgorithmProperty("lm_var_cholmod", "Levenberg: Cholesky solver using CHOLMOD (variable blocksize)", "CHOLMOD", false, Eigen::Dynamic, Eigen::Dynamic)));
121  G2O_REGISTER_OPTIMIZATION_ALGORITHM(lm_fix3_2_cholmod, new CholmodSolverCreator(OptimizationAlgorithmProperty("lm_fix3_2_cholmod", "Levenberg: Cholesky solver using CHOLMOD (fixed blocksize)", "CHOLMOD", true, 3, 2)));
122  G2O_REGISTER_OPTIMIZATION_ALGORITHM(lm_fix6_3_cholmod, new CholmodSolverCreator(OptimizationAlgorithmProperty("lm_fix6_3_cholmod", "Levenberg: Cholesky solver using CHOLMOD (fixed blocksize)", "CHOLMOD", true, 6, 3)));
123  G2O_REGISTER_OPTIMIZATION_ALGORITHM(lm_fix7_3_cholmod, new CholmodSolverCreator(OptimizationAlgorithmProperty("lm_fix7_3_cholmod", "Levenberg: Cholesky solver using CHOLMOD (fixed blocksize)", "CHOLMOD", true, 7, 3)));
124 
125 #ifdef ADD_SCALAR_ORDERING
126  G2O_REGISTER_OPTIMIZATION_ALGORITHM(gn_fix3_2_cholmod_scalar, new CholmodSolverCreator(OptimizationAlgorithmProperty("gn_fix3_2_cholmod_scalar", "Gauss-Newton: Cholesky solver using CHOLMOD (fixed blocksize, scalar ordering)", "CHOLMOD", true, 3, 2)));
127  G2O_REGISTER_OPTIMIZATION_ALGORITHM(gn_fix6_3_cholmod_scalar, new CholmodSolverCreator(OptimizationAlgorithmProperty("gn_fix6_3_cholmod_scalar", "Gauss-Newton: Cholesky solver using CHOLMOD (fixed blocksize, scalar ordering)", "CHOLMOD", true, 6, 3)));
128  G2O_REGISTER_OPTIMIZATION_ALGORITHM(gn_fix7_3_cholmod_scalar, new CholmodSolverCreator(OptimizationAlgorithmProperty("gn_fix7_3_cholmod_scalar", "Gauss-Newton: Cholesky solver using CHOLMOD (fixed blocksize, scalar ordering)", "CHOLMOD", true, 7, 3)));
129  G2O_REGISTER_OPTIMIZATION_ALGORITHM(lm_fix3_2_cholmod_scalar, new CholmodSolverCreator(OptimizationAlgorithmProperty("lm_fix3_2_cholmod_scalar", "Levenberg: Cholesky solver using CHOLMOD (fixed blocksize, scalar ordering)", "CHOLMOD", true, 3, 2)));
130  G2O_REGISTER_OPTIMIZATION_ALGORITHM(lm_fix6_3_cholmod_scalar, new CholmodSolverCreator(OptimizationAlgorithmProperty("lm_fix6_3_cholmod_scalar", "Levenberg: Cholesky solver using CHOLMOD (fixed blocksize, scalar ordering)", "CHOLMOD", true, 6, 3)));
131  G2O_REGISTER_OPTIMIZATION_ALGORITHM(lm_fix7_3_cholmod_scalar, new CholmodSolverCreator(OptimizationAlgorithmProperty("lm_fix7_3_cholmod_scalar", "Levenberg: Cholesky solver using CHOLMOD (fixed blocksize, scalar ordering)", "CHOLMOD", true, 7, 3)));
132 #endif
133 
134  G2O_REGISTER_OPTIMIZATION_ALGORITHM(dl_var_cholmod, new CholmodSolverCreator(OptimizationAlgorithmProperty("dl_var_cholmod", "Dogleg: Cholesky solver using CHOLMOD (variable blocksize)", "CHOLMOD", false, Eigen::Dynamic, Eigen::Dynamic)));
135 }
#define G2O_REGISTER_OPTIMIZATION_ALGORITHM(optimizername, instance)
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
Implementation of Powell&#39;s Dogleg Algorithm.
CholmodSolverCreator(const OptimizationAlgorithmProperty &p)
Generic interface for a non-linear solver operating on a graph.
#define ALLOC_CHOLMOD(s, p, l, blockorder)
base for the block solvers with some basic function interfaces
Definition: block_solver.h:82
virtual OptimizationAlgorithm * construct()
allocate a solver operating on optimizer, re-implement for your creator