graph_optimizer_sparse.h
Go to the documentation of this file.
00001 // g2o - General Graph Optimization
00002 // Copyright (C) 2011 R. Kuemmerle, G. Grisetti, W. Burgard
00003 // 
00004 // g2o is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU Lesser General Public License as published
00006 // by the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 // 
00009 // g2o is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU Lesser General Public License for more details.
00013 // 
00014 // You should have received a copy of the GNU Lesser General Public License
00015 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017 #ifndef _GRAPH_OPTIMIZER_CHOL_H_
00018 #define _GRAPH_OPTIMIZER_CHOL_H_
00019 
00020 #include "optimizable_graph.h"
00021 
00022 #include "solver.h"
00023 
00024 #include <map>
00025 
00026 // forward declaration
00027 namespace g2o {
00028 class ActivePathCostFunction;
00029 }
00030 
00031 namespace g2o {
00032 
00033   struct G2OBatchStatistics;
00034 
00035   struct SparseOptimizer : public OptimizableGraph {
00036 
00037     enum Method{GaussNewton, LevenbergMarquardt};
00038 
00039     friend class ActivePathCostFunction;
00040 
00041     // Attention: _solver & _statistics is own by SparseOptimizer and will be
00042     // deleted in its destructor.
00043     SparseOptimizer();
00044     virtual ~SparseOptimizer();
00045 
00046     // new interface for the optimizer
00047     // the old functions will be dropped
00056     virtual bool initializeOptimization(HyperGraph::EdgeSet& eset);
00057 
00067     virtual bool initializeOptimization
00068        (HyperGraph::VertexSet& vset, int level=0);
00069 
00078     virtual bool initializeOptimization(int level=0);
00079 
00083     virtual bool updateInitialization
00084        (HyperGraph::VertexSet& vset, HyperGraph::EdgeSet& eset);
00085   
00096     virtual void computeInitialGuess();
00097 
00098 
00104     int optimize(int iterations, bool online = false);
00105 
00110     bool computeMarginals();
00111 
00119     bool computeMarginals
00120     (
00121        SparseBlockMatrix<MatrixXd>& spinv, 
00122        const std::vector<std::pair<int, int> >& blockIndices
00123     );
00124 
00131     virtual Vertex* findGauge();
00132 
00133     bool gaugeFreedom();
00134 
00138     double activeChi2() const;
00139 
00143     bool verbose()  const {return _verbose;}
00144     void setVerbose(bool verbose);
00145 
00150     Method method() const { return _method;}
00151     void setMethod(Method method);
00152 
00157     void setForceStopFlag(bool* flag);
00158 
00162     bool terminate() {return _forceStopFlag ? (*_forceStopFlag) : false; }
00163 
00167     const VertexContainer& indexMapping() const {return _ivMap;}
00168 
00172     const VertexContainer& activeVertices() const { return _activeVertices;}
00173 
00177     const EdgeContainer& activeEdges() const { return _activeEdges;}
00178 
00179     virtual bool removeVertex(Vertex* v);
00180 
00185     VertexContainer::const_iterator findActiveVertex
00186        (OptimizableGraph::Vertex* v) const;
00187 
00192     EdgeContainer::const_iterator findActiveEdge
00193        (OptimizableGraph::Edge* e) const;
00194 
00198     const Solver* solver() const { return _solver;}
00199     Solver* solver() { return _solver;}
00200     void setSolver(Solver* solver);
00201 
00205     void push(SparseOptimizer::VertexContainer& vlist);
00206 
00210     void push(HyperGraph::VertexSet& vlist);
00211 
00215     void pop(SparseOptimizer::VertexContainer& vlist);
00216 
00220     void pop(HyperGraph::VertexSet& vlist);
00221 
00226     void discardTop(SparseOptimizer::VertexContainer& vlist);
00227 
00232     double userLambdaInit() {return _userLambdaInit;}
00233 
00238     void setUserLambdaInit(double lambda);
00239 
00243     virtual void clear();
00244 
00248     void computeActiveErrors();
00249 
00254     void linearizeSystem();
00255 
00261     void update(double* update);
00262 
00266     double currentLambda() const { return _currentLambda;}
00267 
00272     void setMaxTrialsAfterFailure(int max_trials);
00273 
00277     int maxTrialsAfterFailure() const { return _maxTrialsAfterFailure;}
00278 
00279     protected:
00280     bool* _forceStopFlag;
00281     bool _verbose;
00282 
00283     Method _method;
00284     double _currentLambda;
00285     int _maxTrialsAfterFailure;
00286 
00287     VertexContainer _ivMap;
00288     VertexContainer _activeVertices;   
00289     EdgeContainer _activeEdges;        
00290 
00291     void sortVectorContainers();
00292  
00293     Solver* _solver;
00294 
00295     // LM parameters
00296     double _tau;
00297     double _userLambdaInit;
00299     double _goodStepLowerScale;
00301     double _goodStepUpperScale;
00302 
00307     double computeLambdaInit();
00308     double computeScale(double currentLMLambda, Solver* solver);
00309 
00314     bool buildIndexMapping(SparseOptimizer::VertexContainer& vlist);
00315     void clearIndexMapping();
00316 
00317   public:
00319     G2OBatchStatistics* _statistics;
00320 
00321   };
00322 
00323 } // end namespace
00324 
00325 #endif


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:31:16