g2o
Loading...
Searching...
No Matches
sparse_optimizer.h
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#ifndef G2O_GRAPH_OPTIMIZER_CHOL_H_
28#define G2O_GRAPH_OPTIMIZER_CHOL_H_
29
30#include "batch_stats.h"
31#include "g2o/stuff/macros.h"
32#include "g2o_core_api.h"
33#include "optimizable_graph.h"
34#include "sparse_block_matrix.h"
35
36namespace g2o {
37
38// forward declaration
40class EstimatePropagatorCost;
41
43 public:
44 enum {
45 AT_COMPUTEACTIVERROR = OptimizableGraph::AT_NUM_ELEMENTS,
46 AT_NUM_ELEMENTS, // keep as last element
47 };
48
49 friend class ActivePathCostFunction;
50
51 // Attention: _solver & _statistics is own by SparseOptimizer and will be
52 // deleted in its destructor.
54 virtual ~SparseOptimizer();
55
56 // new interface for the optimizer
57 // the old functions will be dropped
66 virtual bool initializeOptimization(HyperGraph::EdgeSet& eset);
67
77 virtual bool initializeOptimization(HyperGraph::VertexSet& vset,
78 int level = 0);
79
88 virtual bool initializeOptimization(int level = 0);
89
93 virtual bool updateInitialization(HyperGraph::VertexSet& vset,
95
106 virtual void computeInitialGuess();
107
111 virtual void computeInitialGuess(EstimatePropagatorCost& propagator);
112
116 virtual void setToOrigin();
117
123 int optimize(int iterations, bool online = false);
124
132 bool computeMarginals(SparseBlockMatrix<MatrixX>& spinv,
133 const std::vector<std::pair<int, int> >& blockIndices);
134
141 bool computeMarginals(SparseBlockMatrix<MatrixX>& spinv,
142 const Vertex* vertex);
143
151 bool computeMarginals(SparseBlockMatrix<MatrixX>& spinv,
152 const VertexContainer& vertices);
153
155 // The gauge should be fixed() and then the optimization can work (if no
156 // additional dof are in the system. The default implementation returns a node
157 // with maximum dimension.
158 virtual Vertex* findGauge();
159
160 bool gaugeFreedom();
161
163 double activeChi2() const;
169 double activeRobustChi2() const;
170
172 bool verbose() const { return _verbose; }
173 void setVerbose(bool verbose);
174
179 void setForceStopFlag(bool* flag);
180 bool* forceStopFlag() const { return _forceStopFlag; };
181
183 bool terminate() { return _forceStopFlag ? (*_forceStopFlag) : false; }
184
186 const VertexContainer& indexMapping() const { return _ivMap; }
188 const VertexContainer& activeVertices() const { return _activeVertices; }
190 const EdgeContainer& activeEdges() const { return _activeEdges; }
191
198 virtual bool removeVertex(HyperGraph::Vertex* v, bool detach = false);
199
204 VertexContainer::const_iterator findActiveVertex(
205 const OptimizableGraph::Vertex* v) const;
210 EdgeContainer::const_iterator findActiveEdge(
211 const OptimizableGraph::Edge* e) const;
212
214 const OptimizationAlgorithm* algorithm() const { return _algorithm; }
215 OptimizationAlgorithm* solver() { return _algorithm; }
216 void setAlgorithm(OptimizationAlgorithm* algorithm);
217
219 void push(SparseOptimizer::VertexContainer& vlist);
221 void push(HyperGraph::VertexSet& vlist);
223 void push();
225 void pop(SparseOptimizer::VertexContainer& vlist);
227 void pop(HyperGraph::VertexSet& vlist);
229 void pop();
230
233 void discardTop(SparseOptimizer::VertexContainer& vlist);
235 void discardTop();
236 using OptimizableGraph::discardTop;
237
243 virtual void clear();
244
248 void computeActiveErrors();
249
254 G2O_ATTRIBUTE_DEPRECATED(void linearizeSystem()) {
255 // nothing needed, linearization is now done inside the solver
256 }
257
263 void update(const double* update);
264
269 return _batchStatistics;
270 }
274 BatchStatisticsContainer& batchStatistics() { return _batchStatistics; }
275
276 void setComputeBatchStatistics(bool computeBatchStatistics);
277
278 bool computeBatchStatistics() const { return _computeBatchStatistics; }
279
280 /**** callbacks ****/
282 bool addComputeErrorAction(HyperGraphAction* action);
285 bool removeComputeErrorAction(HyperGraphAction* action);
286
287 protected:
290
294
295 void sortVectorContainers();
296
298
303 bool buildIndexMapping(SparseOptimizer::VertexContainer& vlist);
304 void clearIndexMapping();
305
310};
311} // namespace g2o
312
313#endif
cost for traversing along active edges in the optimizer
Abstract action that operates on an entire graph.
abstract Vertex, your types must derive from that one
std::set< Edge * > EdgeSet
std::set< Vertex * > VertexSet
std::vector< Vertex * > VertexContainer
A general case Vertex for optimization.
Generic interface for a non-linear solver operating on a graph.
Sparse matrix which uses blocks.
const EdgeContainer & activeEdges() const
the edges active in the current optimization
const OptimizationAlgorithm * algorithm() const
the solver used by the optimizer
BatchStatisticsContainer _batchStatistics
EdgeContainer _activeEdges
sorted according to EdgeIDCompare
G2O_ATTRIBUTE_DEPRECATED(void linearizeSystem())
const BatchStatisticsContainer & batchStatistics() const
OptimizationAlgorithm * _algorithm
VertexContainer _activeVertices
sorted according to VertexIDCompare
BatchStatisticsContainer & batchStatistics()
bool verbose() const
verbose information during optimization
bool * forceStopFlag() const
const VertexContainer & indexMapping() const
the index mapping of the vertices
const VertexContainer & activeVertices() const
the vertices active in the current optimization
bool computeBatchStatistics() const
OptimizationAlgorithm * solver()
bool terminate()
if external stop flag is given, return its state. False otherwise
#define G2O_CORE_API
class G2O_CORE_API OptimizationAlgorithm
std::vector< G2OBatchStatistics > BatchStatisticsContainer
Definition batch_stats.h:86
std::vector< OptimizableGraph::Edge * > EdgeContainer
vector container for edges
std::vector< OptimizableGraph::Vertex * > VertexContainer
vector container for vertices