g2o
Toggle main menu visibility
Loading...
Searching...
No Matches
g2o
core
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
27
#include "
optimization_algorithm_gauss_newton.h
"
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
39
using namespace
std
;
40
41
namespace
g2o
{
42
43
OptimizationAlgorithmGaussNewton::OptimizationAlgorithmGaussNewton
(
44
std::unique_ptr<Solver>
solver
)
45
:
OptimizationAlgorithmWithHessian
(*
solver
.get()),
46
m_solver
{
std
::move(
solver
)} {}
47
48
OptimizationAlgorithmGaussNewton::~OptimizationAlgorithmGaussNewton
() {}
49
50
OptimizationAlgorithm::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();
60
G2OBatchStatistics
* globalStats =
G2OBatchStatistics::globalStats
();
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
74
t =
get_monotonic_time
();
75
_solver
.buildSystem();
76
if
(globalStats) {
77
globalStats->
timeQuadraticForm
=
get_monotonic_time
() - t;
78
t =
get_monotonic_time
();
79
}
80
81
ok =
_solver
.solve();
82
if
(globalStats) {
83
globalStats->
timeLinearSolution
=
get_monotonic_time
() - t;
84
t =
get_monotonic_time
();
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
97
void
OptimizationAlgorithmGaussNewton::printVerbose
(std::ostream& os)
const
{
98
os <<
"\t schur= "
<<
_solver
.schur();
99
}
100
101
}
// namespace g2o
batch_stats.h
g2o::OptimizationAlgorithmGaussNewton::m_solver
std::unique_ptr< Solver > m_solver
Definition
optimization_algorithm_gauss_newton.h:55
g2o::OptimizationAlgorithmGaussNewton::OptimizationAlgorithmGaussNewton
OptimizationAlgorithmGaussNewton(std::unique_ptr< Solver > solver)
Definition
optimization_algorithm_gauss_newton.cpp:43
g2o::OptimizationAlgorithmGaussNewton::solve
virtual SolverResult solve(int iteration, bool online=false)
Definition
optimization_algorithm_gauss_newton.cpp:50
g2o::OptimizationAlgorithmGaussNewton::~OptimizationAlgorithmGaussNewton
virtual ~OptimizationAlgorithmGaussNewton()
Definition
optimization_algorithm_gauss_newton.cpp:48
g2o::OptimizationAlgorithmGaussNewton::printVerbose
virtual void printVerbose(std::ostream &os) const
Definition
optimization_algorithm_gauss_newton.cpp:97
g2o::OptimizationAlgorithmWithHessian::solver
Solver & solver()
return the underlying solver used to solve the linear system
Definition
optimization_algorithm_with_hessian.h:61
g2o::OptimizationAlgorithmWithHessian::OptimizationAlgorithmWithHessian
OptimizationAlgorithmWithHessian(Solver &solver)
Definition
optimization_algorithm_with_hessian.cpp:39
g2o::OptimizationAlgorithmWithHessian::_solver
Solver & _solver
Definition
optimization_algorithm_with_hessian.h:70
g2o::OptimizationAlgorithm::_optimizer
SparseOptimizer * _optimizer
the optimizer the solver is working on
Definition
optimization_algorithm.h:109
G2O_WARN
#define G2O_WARN(...)
logger.h
macros.h
__PRETTY_FUNCTION__
#define __PRETTY_FUNCTION__
Definition
macros.h:90
g2o
Definition
dl_wrapper.cpp:55
g2o::get_monotonic_time
double get_monotonic_time()
Definition
timeutil.cpp:43
std
Definition
jet.h:876
OK
OK
Definition
optimization_algorithm.h:48
optimization_algorithm_gauss_newton.h
solver.h
sparse_optimizer.h
g2o::G2OBatchStatistics
statistics about the optimization
Definition
batch_stats.h:40
g2o::G2OBatchStatistics::timeLinearSolution
double timeLinearSolution
Definition
batch_stats.h:59
g2o::G2OBatchStatistics::timeResiduals
double timeResiduals
residuals
Definition
batch_stats.h:49
g2o::G2OBatchStatistics::globalStats
static G2OBatchStatistics * globalStats()
Definition
batch_stats.h:77
g2o::G2OBatchStatistics::timeUpdate
double timeUpdate
time to apply the update
Definition
batch_stats.h:64
g2o::G2OBatchStatistics::timeQuadraticForm
double timeQuadraticForm
construct the quadratic form in the graph
Definition
batch_stats.h:51
timeutil.h
utility functions for handling time related stuff
Generated on
for g2o by
1.17.0