g2o
Loading...
Searching...
No Matches
optimization_algorithm_gauss_newton.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
28
29#include <cassert>
30#include <iostream>
31
32#include "batch_stats.h"
33#include "g2o/stuff/logger.h"
34#include "g2o/stuff/macros.h"
35#include "g2o/stuff/timeutil.h"
36#include "solver.h"
37#include "sparse_optimizer.h"
38
39using namespace std;
40
41namespace g2o {
42
47
49
50OptimizationAlgorithm::SolverResult OptimizationAlgorithmGaussNewton::solve(
51 int iteration, bool online) {
52 assert(_solver.optimizer() == _optimizer &&
53 "underlying linear solver operates on different graph");
54 bool ok = true;
55
56 // here so that correct component for max-mixtures can be computed before the
57 // build structure
58 double t = get_monotonic_time();
59 _optimizer->computeActiveErrors();
61 if (globalStats) {
62 globalStats->timeResiduals = get_monotonic_time() - t;
63 }
64
65 if (iteration == 0 &&
66 !online) { // built up the CCS structure, here due to easy time measure
67 ok = _solver.buildStructure();
68 if (!ok) {
69 G2O_WARN("{}: Failure while building CCS structure", __PRETTY_FUNCTION__);
70 return OptimizationAlgorithm::Fail;
71 }
72 }
73
75 _solver.buildSystem();
76 if (globalStats) {
77 globalStats->timeQuadraticForm = get_monotonic_time() - t;
79 }
80
81 ok = _solver.solve();
82 if (globalStats) {
83 globalStats->timeLinearSolution = get_monotonic_time() - t;
85 }
86
87 _optimizer->update(_solver.x());
88 if (globalStats) {
89 globalStats->timeUpdate = get_monotonic_time() - t;
90 }
91 if (ok)
92 return OK;
93 else
94 return Fail;
95}
96
98 os << "\t schur= " << _solver.schur();
99}
100
101} // namespace g2o
OptimizationAlgorithmGaussNewton(std::unique_ptr< Solver > solver)
virtual SolverResult solve(int iteration, bool online=false)
Solver & solver()
return the underlying solver used to solve the linear system
SparseOptimizer * _optimizer
the optimizer the solver is working on
#define G2O_WARN(...)
#define __PRETTY_FUNCTION__
Definition macros.h:90
double get_monotonic_time()
Definition timeutil.cpp:43
Definition jet.h:876
statistics about the optimization
Definition batch_stats.h:40
double timeResiduals
residuals
Definition batch_stats.h:49
static G2OBatchStatistics * globalStats()
Definition batch_stats.h:77
double timeUpdate
time to apply the update
Definition batch_stats.h:64
double timeQuadraticForm
construct the quadratic form in the graph
Definition batch_stats.h:51
utility functions for handling time related stuff