GCC Code Coverage Report


Directory: ./
File: lib/geogram/numerics/lbfgs_optimizers.h
Date: 2026-09-07 02:37:58
Exec Total Coverage
Lines: 0 9 0.0%
Functions: 0 3 0.0%
Branches: 0 0 -%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2000-2022 Inria
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 met:
7 *
8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * * Neither the name of the ALICE Project-Team nor the names of its
14 * contributors may be used to endorse or promote products derived from this
15 * software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
28 *
29 * Contact: Bruno Levy
30 *
31 * https://www.inria.fr/fr/bruno-levy
32 *
33 * Inria,
34 * Domaine de Voluceau,
35 * 78150 Le Chesnay - Rocquencourt
36 * FRANCE
37 *
38 */
39
40 #ifndef GEOGRAM_NUMERICS_LBFGS_OPTIMIZERS
41 #define GEOGRAM_NUMERICS_LBFGS_OPTIMIZERS
42
43 #ifdef GEOGRAM_WITH_HLBFGS
44
45 #include <geogram/basic/common.h>
46 #include <geogram/numerics/optimizer.h>
47 #include <geogram/basic/assert.h>
48
49 /**
50 * \file geogram/numerics/lbfgs_optimizers.h
51 * \brief Implementation of optimizer using the HLBFGS library.
52 */
53
54 namespace GEO {
55
56 /**
57 * \brief Base class for Optimizer implementation using the HLBFGS
58 * library.
59 */
60 class GEOGRAM_API HLBFGSOptimizer : public Optimizer {
61 public:
62 /**
63 * \brief Constructs a new HLBFGSOptimizer.
64 */
65 HLBFGSOptimizer();
66
67 void optimize(double* x) override;
68
69 /**
70 * \brief Enables or disables M1QN3 mode.
71 * \param[in] m1qn3 true if M1QN3 mode should be used, false otherwise
72 */
73 void set_m1qn3(bool m1qn3) {
74 b_m1qn3_ = m1qn3;
75 }
76
77 /**
78 * \brief Enables or disables Conjugate Gradient mode.
79 * \param[in] cg true if conjugate gradient mode should be used,
80 * false otherwise
81 */
82 void set_cg(bool cg) {
83 b_cg_ = cg;
84 }
85
86 protected:
87 /**
88 * \brief HLBFGSOptimizer destructor .
89 */
90 ~HLBFGSOptimizer() override;
91
92 protected:
93 bool b_m1qn3_;
94 bool b_cg_;
95 };
96
97 /************************************************************************/
98
99 /**
100 * \brief Optimizer implementation using the M1QN3 mode
101 */
102 class HLBFGS_M1QN3Optimizer : public HLBFGSOptimizer {
103 public:
104 /*
105 * \brief Optimizer constructor
106 * \details This sets the M1QN3 parameter to true
107 * \see set_m1qn3()
108 */
109 HLBFGS_M1QN3Optimizer();
110
111 protected:
112 /*
113 * \brief HLBFGS_M1QN3Optimizer destructor
114 */
115 ~HLBFGS_M1QN3Optimizer() override;
116 };
117
118 /************************************************************************/
119
120 /**
121 * \brief Optimizer implementation using the Conjugate Gradient mode
122 */
123 class HLBFGS_CGOptimizer : public HLBFGSOptimizer {
124 public:
125 /*
126 * \brief Optimizer constructor
127 * \details This sets the CG parameter to true
128 * \see set_cg()
129 */
130 HLBFGS_CGOptimizer();
131
132 protected:
133 /*
134 * \brief HLBFGS_CGOptimizer destructor
135 */
136 ~HLBFGS_CGOptimizer() override;
137 };
138
139 /************************************************************************/
140
141 /**
142 * \brief Optimizer implementation using the LBFGS method with
143 * Hessian evaluation.
144 * \details This version needs the callback that evaluates the Hessian,
145 * specified with set_evalhessian_callback()
146 */
147 class GEOGRAM_API HLBFGS_HessOptimizer : public HLBFGSOptimizer {
148 public:
149 /**
150 * \brief Constructs a new HLBFGS_HessOptimizer.
151 */
152 HLBFGS_HessOptimizer();
153
154 void optimize(double* x) override;
155
156 /**
157 * \brief Sets the update interval of the Hessian.
158 * \param[in] T the update interval of the Hessian
159 */
160 void set_T(index_t T) {
161 T_ = T;
162 }
163
164 protected:
165 /**
166 * \brief HLBFGS_HessOptimizer destructor
167 */
168 ~HLBFGS_HessOptimizer() override;
169
170 protected:
171 index_t T_;
172 };
173 }
174
175 #endif
176
177 #endif
178