g2o
Loading...
Searching...
No Matches
solver.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 "solver.h"
28
29#include <algorithm>
30#include <cstring>
31
33
34namespace g2o {
35
37 : _optimizer(0),
38 _x(0),
39 _b(0),
40 _xSize(0),
41 _maxXSize(0),
42 _isLevenberg(false),
43 _additionalVectorSpace(0) {}
44
49
50void Solver::resizeVector(size_t sx) {
51 size_t oldSize = _xSize;
52 _xSize = sx;
53 sx += _additionalVectorSpace; // allocate some additional space if requested
54 if (_maxXSize < sx) {
55 _maxXSize = 2 * sx;
57 _x = allocate_aligned<double>(_maxXSize);
58#ifndef NDEBUG
59 memset(_x, 0, _maxXSize * sizeof(double));
60#endif
61 if (_b) { // backup the former b, might still be needed for online
62 // processing
63 memcpy(_x, _b, oldSize * sizeof(double));
65 _b = allocate_aligned<double>(_maxXSize);
66 std::swap(_b, _x);
67 } else {
68 _b = allocate_aligned<double>(_maxXSize);
69#ifndef NDEBUG
70 memset(_b, 0, _maxXSize * sizeof(double));
71#endif
72 }
73 }
74}
75
79
80void Solver::setLevenberg(bool levenberg) { _isLevenberg = levenberg; }
81
83
84} // namespace g2o
void setLevenberg(bool levenberg)
Definition solver.cpp:80
size_t _maxXSize
Definition solver.h:142
virtual ~Solver()
Definition solver.cpp:45
double * _b
Definition solver.h:141
size_t _additionalVectorSpace
Definition solver.h:145
bool _isLevenberg
Definition solver.h:143
double * _x
Definition solver.h:140
bool levenberg() const
the system is Levenberg-Marquardt
Definition solver.h:112
size_t _xSize
Definition solver.h:142
void resizeVector(size_t sx)
Definition solver.cpp:50
void setAdditionalVectorSpace(size_t s)
Definition solver.cpp:82
void setOptimizer(SparseOptimizer *optimizer)
Definition solver.cpp:76
SparseOptimizer * optimizer() const
the optimizer (graph) on which the solver works
Definition solver.h:108
SparseOptimizer * _optimizer
Definition solver.h:139
void free_aligned(Type *block)