alpaqa 1.1.0a1
Nonconvex constrained optimization
Loading...
Searching...
No Matches
type-erased-problem.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <alpaqa/export.hpp>
9#include <guanaqo/not-implemented.hpp>
10#include <guanaqo/required-method.hpp>
11#include <guanaqo/type-erasure.hpp>
12#include <type_traits>
13#include <utility>
14
15namespace alpaqa {
16
17/// Raised when calling problem functions that are not implemented.
18using guanaqo::not_implemented_error;
19
20/// Struct containing function pointers to all problem functions (like the
21/// objective and constraint functions, with their derivatives, and more).
22/// Some default implementations are available.
23/// Internal struct, it is used by @ref TypeErasedProblem.
24template <Config Conf>
25struct ProblemVTable : guanaqo::BasicVTable {
28
29 template <class F>
30 using optional_function_t = guanaqo::optional_function_t<F, ProblemVTable>;
31 template <class F>
32 using required_function_t = guanaqo::required_function_t<F>;
33
34 // clang-format off
35
36 // Required
37 required_function_t<void(crvec z, rvec e) const>
39 required_function_t<void(rvec y, real_t M) const>
41 required_function_t<real_t(real_t γ, crvec x, crvec grad_ψ, rvec x̂, rvec p) const>
45 required_function_t<void(crvec x, rvec grad_fx) const>
47 required_function_t<void(crvec x, rvec gx) const>
49 required_function_t<void(crvec x, crvec y, rvec grad_gxy) const>
51 optional_function_t<index_t(real_t γ, crvec x, crvec grad_ψ, rindexvec J) const>
53
54 // Second order
55 optional_function_t<void(crvec x, rvec J_values) const>
57 optional_function_t<Sparsity() const>
59 optional_function_t<void(crvec x, index_t i, rvec grad_gi) const>
61 optional_function_t<void(crvec x, crvec y, real_t scale, crvec v, rvec Hv) const>
63 optional_function_t<void(crvec x, crvec y, real_t scale, rvec H_values) const>
65 optional_function_t<Sparsity() const>
67 optional_function_t<void(crvec x, crvec y, crvec Σ, real_t scale, crvec v, rvec Hv) const>
69 optional_function_t<void(crvec x, crvec y, crvec Σ, real_t scale, rvec H_values) const>
71 optional_function_t<Sparsity() const>
73
74 // Combined evaluations
75 optional_function_t<real_t(crvec x, rvec grad_fx) const>
79 optional_function_t<void(crvec x, crvec y, rvec grad_f, rvec grad_gxy) const>
81
82 // Lagrangian and augmented lagrangian evaluations
83 optional_function_t<void(crvec x, crvec y, rvec grad_L, rvec work_n) const>
85 optional_function_t<real_t(crvec x, crvec y, crvec Σ, rvec ŷ) const>
87 optional_function_t<void(crvec x, crvec y, crvec Σ, rvec grad_ψ, rvec work_n, rvec work_m) const>
89 optional_function_t<real_t(crvec x, crvec y, crvec Σ, rvec grad_ψ, rvec work_n, rvec work_m) const>
91
92 // Constraint sets
93 optional_function_t<const Box &() const>
95 optional_function_t<const Box &() const>
97
98 // Check
99 optional_function_t<void() const>
101 optional_function_t<std::string() const>
103
104 // clang-format on
105
106 ALPAQA_EXPORT static real_t calc_ŷ_dᵀŷ(const void *self, rvec g_ŷ, crvec y, crvec Σ,
107 const ProblemVTable &vtable);
108 ALPAQA_EXPORT static index_t default_eval_inactive_indices_res_lna(const void *, real_t, crvec,
110 const ProblemVTable &);
111 ALPAQA_EXPORT static void default_eval_constraints_jacobian(const void *, crvec, rvec,
112 const ProblemVTable &);
113 ALPAQA_EXPORT static Sparsity default_get_constraints_jacobian_sparsity(const void *,
114 const ProblemVTable &);
115 ALPAQA_EXPORT static void default_eval_grad_gi(const void *, crvec, index_t, rvec,
116 const ProblemVTable &);
117 ALPAQA_EXPORT static void default_eval_lagrangian_hessian_product(const void *, crvec, crvec,
118 real_t, crvec, rvec,
119 const ProblemVTable &);
120 ALPAQA_EXPORT static void default_eval_lagrangian_hessian(const void *, crvec, crvec, real_t,
121 rvec, const ProblemVTable &);
122 ALPAQA_EXPORT static Sparsity default_get_lagrangian_hessian_sparsity(const void *,
123 const ProblemVTable &);
124 ALPAQA_EXPORT static void
126 real_t scale, crvec v, rvec Hv,
127 const ProblemVTable &vtable);
128 ALPAQA_EXPORT static void
130 real_t scale, rvec H_values,
131 const ProblemVTable &vtable);
132 ALPAQA_EXPORT static Sparsity
134 ALPAQA_EXPORT static real_t default_eval_objective_and_gradient(const void *self, crvec x,
135 rvec grad_fx,
136 const ProblemVTable &vtable);
137 ALPAQA_EXPORT static real_t default_eval_objective_and_constraints(const void *self, crvec x,
138 rvec g,
139 const ProblemVTable &vtable);
141 const void *self, crvec x, crvec y, rvec grad_f, rvec grad_gxy,
142 const ProblemVTable &vtable);
143 ALPAQA_EXPORT static void default_eval_lagrangian_gradient(const void *self, crvec x, crvec y,
144 rvec grad_L, rvec work_n,
145 const ProblemVTable &vtable);
146 ALPAQA_EXPORT static real_t default_eval_augmented_lagrangian(const void *self, crvec x,
147 crvec y, crvec Σ, rvec ŷ,
148 const ProblemVTable &vtable);
149 ALPAQA_EXPORT static void
151 rvec grad_ψ, rvec work_n, rvec work_m,
152 const ProblemVTable &vtable);
153 ALPAQA_EXPORT static real_t
155 rvec grad_ψ, rvec work_n, rvec work_m,
156 const ProblemVTable &vtable);
157 ALPAQA_EXPORT static const Box &default_get_variable_bounds(const void *,
158 const ProblemVTable &);
159 ALPAQA_EXPORT static const Box &default_get_general_bounds(const void *, const ProblemVTable &);
160 ALPAQA_EXPORT static void default_check(const void *, const ProblemVTable &);
161 ALPAQA_EXPORT static std::string default_get_name(const void *, const ProblemVTable &);
162
164
165 template <class P>
166 ProblemVTable(std::in_place_t, P &p) : guanaqo::BasicVTable{std::in_place, p} {
167 auto &vtable = *this;
168
169 // Initialize all methods
170
171 // Required
172 GUANAQO_TE_REQUIRED_METHOD(vtable, P, eval_projecting_difference_constraints);
173 GUANAQO_TE_REQUIRED_METHOD(vtable, P, eval_projection_multipliers);
174 GUANAQO_TE_REQUIRED_METHOD(vtable, P, eval_proximal_gradient_step);
175 GUANAQO_TE_REQUIRED_METHOD(vtable, P, eval_objective);
176 GUANAQO_TE_REQUIRED_METHOD(vtable, P, eval_objective_gradient);
177 GUANAQO_TE_REQUIRED_METHOD(vtable, P, eval_constraints);
178 GUANAQO_TE_REQUIRED_METHOD(vtable, P, eval_constraints_gradient_product);
179 GUANAQO_TE_OPTIONAL_METHOD(vtable, P, eval_inactive_indices_res_lna, p);
180 // Second order
181 GUANAQO_TE_OPTIONAL_METHOD(vtable, P, eval_constraints_jacobian, p);
182 GUANAQO_TE_OPTIONAL_METHOD(vtable, P, get_constraints_jacobian_sparsity, p);
183 GUANAQO_TE_OPTIONAL_METHOD(vtable, P, eval_grad_gi, p);
184 GUANAQO_TE_OPTIONAL_METHOD(vtable, P, eval_lagrangian_hessian_product, p);
185 GUANAQO_TE_OPTIONAL_METHOD(vtable, P, eval_lagrangian_hessian, p);
186 GUANAQO_TE_OPTIONAL_METHOD(vtable, P, get_lagrangian_hessian_sparsity, p);
187 GUANAQO_TE_OPTIONAL_METHOD(vtable, P, eval_augmented_lagrangian_hessian_product, p);
188 GUANAQO_TE_OPTIONAL_METHOD(vtable, P, eval_augmented_lagrangian_hessian, p);
189 GUANAQO_TE_OPTIONAL_METHOD(vtable, P, get_augmented_lagrangian_hessian_sparsity, p);
190 // Combined evaluations
191 GUANAQO_TE_OPTIONAL_METHOD(vtable, P, eval_objective_and_gradient, p);
192 GUANAQO_TE_OPTIONAL_METHOD(vtable, P, eval_objective_and_constraints, p);
193 GUANAQO_TE_OPTIONAL_METHOD(vtable, P,
195 // Lagrangian and augmented lagrangian evaluations
196 GUANAQO_TE_OPTIONAL_METHOD(vtable, P, eval_lagrangian_gradient, p);
197 GUANAQO_TE_OPTIONAL_METHOD(vtable, P, eval_augmented_lagrangian, p);
198 GUANAQO_TE_OPTIONAL_METHOD(vtable, P, eval_augmented_lagrangian_gradient, p);
199 GUANAQO_TE_OPTIONAL_METHOD(vtable, P, eval_augmented_lagrangian_and_gradient, p);
200 // Constraint set
201 GUANAQO_TE_OPTIONAL_METHOD(vtable, P, get_variable_bounds, p);
202 GUANAQO_TE_OPTIONAL_METHOD(vtable, P, get_general_bounds, p);
203 // Check
204 GUANAQO_TE_OPTIONAL_METHOD(vtable, P, check, p);
205 GUANAQO_TE_OPTIONAL_METHOD(vtable, P, get_name, p);
206
207 // Dimensions
208 vtable.n = p.get_num_variables();
209 vtable.m = p.get_num_constraints();
210 }
211 ProblemVTable() = default;
212};
213
214// clang-format off
219// clang-format on
220
221/// @addtogroup grp_Problems
222/// @{
223
224/// The main polymorphic minimization problem interface.
225///
226/// This class wraps the actual problem implementation class, filling in the
227/// missing member functions with sensible defaults, and providing a uniform
228/// interface that is used by the solvers.
229///
230/// The problem implementations do not inherit from an abstract base class.
231/// Instead, [structural typing](https://en.wikipedia.org/wiki/Structural_type_system)
232/// is used. The @ref ProblemVTable constructor uses reflection to discover
233/// which member functions are provided by the problem implementation. See
234/// @ref page-problem-formulations for more information, and
235/// @ref C++/CustomCppProblem/main.cpp for an example.
236template <Config Conf = DefaultConfig, class Allocator = std::allocator<std::byte>>
237class TypeErasedProblem : public guanaqo::TypeErased<ProblemVTable<Conf>, Allocator> {
238 public:
242 using allocator_type = Allocator;
243 using TypeErased = guanaqo::TypeErased<VTable, allocator_type>;
244 using TypeErased::TypeErased;
245
246 protected:
247 using TypeErased::call;
248 using TypeErased::self;
249 using TypeErased::vtable;
250
251 public:
252 template <class T, class... Args>
253 static TypeErasedProblem make(Args &&...args) {
254 return TypeErased::template make<TypeErasedProblem, T>(std::forward<Args>(args)...);
255 }
256
257 /// @name Problem dimensions
258 /// @{
259
260 /// **[Required]**
261 /// Number of decision variables.
262 [[nodiscard]] length_t get_num_variables() const;
263 /// **[Required]**
264 /// Number of constraints.
265 [[nodiscard]] length_t get_num_constraints() const;
266
267 /// @}
268
269 /// @name Required cost and constraint functions
270 /// @{
271
272 /// **[Required]**
273 /// Function that evaluates the cost, @f$ f(x) @f$
274 /// @param [in] x
275 /// Decision variable @f$ x \in \R^n @f$
276 [[nodiscard]] real_t eval_objective(crvec x) const;
277 /// **[Required]**
278 /// Function that evaluates the gradient of the cost, @f$ \nabla f(x) @f$
279 /// @param [in] x
280 /// Decision variable @f$ x \in \R^n @f$
281 /// @param [out] grad_fx
282 /// Gradient of cost function @f$ \nabla f(x) \in \R^n @f$
283 void eval_objective_gradient(crvec x, rvec grad_fx) const;
284 /// **[Required]**
285 /// Function that evaluates the constraints, @f$ g(x) @f$
286 /// @param [in] x
287 /// Decision variable @f$ x \in \R^n @f$
288 /// @param [out] gx
289 /// Value of the constraints @f$ g(x) \in \R^m @f$
290 void eval_constraints(crvec x, rvec gx) const;
291 /// **[Required]**
292 /// Function that evaluates the gradient of the constraints times a vector,
293 /// @f$ \nabla g(x)\,y = \tp{\jac_g(x)}y @f$
294 /// @param [in] x
295 /// Decision variable @f$ x \in \R^n @f$
296 /// @param [in] y
297 /// Vector @f$ y \in \R^m @f$ to multiply the gradient by
298 /// @param [out] grad_gxy
299 /// Gradient of the constraints
300 /// @f$ \nabla g(x)\,y \in \R^n @f$
302
303 /// @}
304
305 /// @name Projections onto constraint sets and proximal mappings
306 /// @{
307
308 /// **[Required]**
309 /// Function that evaluates the difference between the given point @f$ z @f$
310 /// and its projection onto the constraint set @f$ D @f$.
311 /// @param [in] z
312 /// Slack variable, @f$ z \in \R^m @f$
313 /// @param [out] e
314 /// The difference relative to its projection,
315 /// @f$ e = z - \Pi_D(z) \in \R^m @f$
316 /// @note @p z and @p e can refer to the same vector.
318 /// **[Required]**
319 /// Function that projects the Lagrange multipliers for ALM.
320 /// @param [inout] y
321 /// Multipliers, @f$ y \leftarrow \Pi_Y(y) \in \R^m @f$
322 /// @param [in] M
323 /// The radius/size of the set @f$ Y @f$.
324 /// See @ref ALMParams::max_multiplier.
326 /// **[Required]**
327 /// Function that computes a proximal gradient step.
328 /// @param [in] γ
329 /// Step size, @f$ \gamma \in \R_{>0} @f$
330 /// @param [in] x
331 /// Decision variable @f$ x \in \R^n @f$
332 /// @param [in] grad_ψ
333 /// Gradient of the subproblem cost, @f$ \nabla\psi(x) \in \R^n @f$
334 /// @param [out] x̂
335 /// Next proximal gradient iterate, @f$ \hat x = T_\gamma(x) =
336 /// \prox_{\gamma h}(x - \gamma\nabla\psi(x)) \in \R^n @f$
337 /// @param [out] p
338 /// The proximal gradient step,
339 /// @f$ p = \hat x - x \in \R^n @f$
340 /// @return The nonsmooth function evaluated at x̂,
341 /// @f$ h(\hat x) @f$.
342 /// @note The vector @f$ p @f$ is often used in stopping criteria, so its
343 /// numerical accuracy is more important than that of @f$ \hat x @f$.
345 /// **[Optional]**
346 /// Function that computes the inactive indices @f$ \mathcal J(x) @f$ for
347 /// the evaluation of the linear Newton approximation of the residual, as in
348 /// @cite pas2022alpaqa.
349 /// @param [in] γ
350 /// Step size, @f$ \gamma \in \R_{>0} @f$
351 /// @param [in] x
352 /// Decision variable @f$ x \in \R^n @f$
353 /// @param [in] grad_ψ
354 /// Gradient of the subproblem cost, @f$ \nabla\psi(x) \in \R^n @f$
355 /// @param [out] J
356 /// The indices of the components of @f$ x @f$ that are in the
357 /// index set @f$ \mathcal J(x) @f$. In ascending order, at most n.
358 /// @return The number of inactive constraints, @f$ \# \mathcal J(x) @f$.
359 ///
360 /// For example, in the case of box constraints, we have
361 /// @f[ \mathcal J(x) \defeq \defset{i \in \N_{[0, n-1]}}{\underline x_i
362 /// \lt x_i - \gamma\nabla_{\!x_i}\psi(x) \lt \overline x_i}. @f]
364 rindexvec J) const;
365
366 /// @}
367
368 /// @name Constraint sets
369 /// @{
370
371 /// **[Optional]**
372 /// Get the rectangular constraint set of the decision variables,
373 /// @f$ x \in C @f$.
374 [[nodiscard]] const Box &get_variable_bounds() const;
375 /// **[Optional]**
376 /// Get the rectangular constraint set of the general constraint function,
377 /// @f$ g(x) \in D @f$.
378 [[nodiscard]] const Box &get_general_bounds() const;
379
380 /// @}
381
382 /// @name Functions for second-order solvers
383 /// @{
384
385 /// **[Optional]**
386 /// Function that evaluates the nonzero values of the Jacobian matrix of the
387 /// constraints, @f$ \jac_g(x) @f$
388 /// @param [in] x
389 /// Decision variable @f$ x \in \R^n @f$
390 /// @param [out] J_values
391 /// Nonzero values of the Jacobian
392 /// @f$ \jac_g(x) \in \R^{m\times n} @f$
393 ///
394 /// Required for second-order solvers only.
395 void eval_constraints_jacobian(crvec x, rvec J_values) const;
396 /// **[Optional]**
397 /// Function that returns (a view of) the sparsity pattern of the Jacobian
398 /// of the constraints.
399 ///
400 /// Required for second-order solvers only.
401 [[nodiscard]] Sparsity get_constraints_jacobian_sparsity() const;
402 /// **[Optional]**
403 /// Function that evaluates the gradient of one specific constraint,
404 /// @f$ \nabla g_i(x) @f$
405 /// @param [in] x
406 /// Decision variable @f$ x \in \R^n @f$
407 /// @param [in] i
408 /// Which constraint @f$ 0 \le i \lt m @f$
409 /// @param [out] grad_gi
410 /// Gradient of the constraint
411 /// @f$ \nabla g_i(x) \in \R^n @f$
412 ///
413 /// Required for second-order solvers only.
414 void eval_grad_gi(crvec x, index_t i, rvec grad_gi) const;
415 /// **[Optional]**
416 /// Function that evaluates the Hessian of the Lagrangian multiplied by a
417 /// vector,
418 /// @f$ \nabla_{xx}^2L(x, y)\,v @f$
419 /// @param [in] x
420 /// Decision variable @f$ x \in \R^n @f$
421 /// @param [in] y
422 /// Lagrange multipliers @f$ y \in \R^m @f$
423 /// @param [in] scale
424 /// Scale factor for the cost function.
425 /// @param [in] v
426 /// Vector to multiply by @f$ v \in \R^n @f$
427 /// @param [out] Hv
428 /// Hessian-vector product
429 /// @f$ \nabla_{xx}^2 L(x, y)\,v \in \R^{n} @f$
430 ///
431 /// Required for second-order solvers only.
433 /// **[Optional]**
434 /// Function that evaluates the nonzero values of the Hessian of the
435 /// Lagrangian, @f$ \nabla_{xx}^2L(x, y) @f$
436 /// @param [in] x
437 /// Decision variable @f$ x \in \R^n @f$
438 /// @param [in] y
439 /// Lagrange multipliers @f$ y \in \R^m @f$
440 /// @param [in] scale
441 /// Scale factor for the cost function.
442 /// @param [out] H_values
443 /// Nonzero values of the Hessian
444 /// @f$ \nabla_{xx}^2 L(x, y) \in \R^{n\times n} @f$.
445 ///
446 /// Required for second-order solvers only.
447 void eval_lagrangian_hessian(crvec x, crvec y, real_t scale, rvec H_values) const;
448 /// **[Optional]**
449 /// Function that returns (a view of) the sparsity pattern of the Hessian of
450 /// the Lagrangian.
451 ///
452 /// Required for second-order solvers only.
453 [[nodiscard]] Sparsity get_lagrangian_hessian_sparsity() const;
454 /// **[Optional]**
455 /// Function that evaluates the Hessian of the augmented Lagrangian
456 /// multiplied by a vector,
457 /// @f$ \nabla_{xx}^2L_\Sigma(x, y)\,v @f$
458 /// @param [in] x
459 /// Decision variable @f$ x \in \R^n @f$
460 /// @param [in] y
461 /// Lagrange multipliers @f$ y \in \R^m @f$
462 /// @param [in] Σ
463 /// Penalty weights @f$ \Sigma @f$
464 /// @param [in] scale
465 /// Scale factor for the cost function.
466 /// @param [in] v
467 /// Vector to multiply by @f$ v \in \R^n @f$
468 /// @param [out] Hv
469 /// Hessian-vector product
470 /// @f$ \nabla_{xx}^2 L_\Sigma(x, y)\,v \in \R^{n} @f$
471 ///
472 /// Required for second-order solvers only.
474 rvec Hv) const;
475 /// **[Optional]**
476 /// Function that evaluates the nonzero values of the Hessian of the
477 /// augmented Lagrangian, @f$ \nabla_{xx}^2L_\Sigma(x, y) @f$
478 /// @param [in] x
479 /// Decision variable @f$ x \in \R^n @f$
480 /// @param [in] y
481 /// Lagrange multipliers @f$ y \in \R^m @f$
482 /// @param [in] Σ
483 /// Penalty weights @f$ \Sigma @f$
484 /// @param [in] scale
485 /// Scale factor for the cost function.
486 /// @param [out] H_values
487 /// Nonzero values of the Hessian
488 /// @f$ \nabla_{xx}^2 L_\Sigma(x, y) \in \R^{n\times n} @f$
489 ///
490 /// Required for second-order solvers only.
492 rvec H_values) const;
493 /// **[Optional]**
494 /// Function that returns (a view of) the sparsity pattern of the Hessian of
495 /// the augmented Lagrangian.
496 ///
497 /// Required for second-order solvers only.
498 [[nodiscard]] Sparsity get_augmented_lagrangian_hessian_sparsity() const;
499
500 /// @}
501
502 /// @name Combined evaluations
503 /// @{
504
505 /// **[Optional]**
506 /// Evaluate both @f$ f(x) @f$ and its gradient, @f$ \nabla f(x) @f$.
507 /// @default_impl ProblemVTable::default_eval_objective_and_gradient
509 /// **[Optional]**
510 /// Evaluate both @f$ f(x) @f$ and @f$ g(x) @f$.
511 /// @default_impl ProblemVTable::default_eval_objective_and_constraints
513 /// **[Optional]**
514 /// Evaluate both @f$ \nabla f(x) @f$ and @f$ \nabla g(x)\,y @f$.
515 /// @default_impl ProblemVTable::default_eval_objective_gradient_and_constraints_gradient_product
517 rvec grad_gxy) const;
518 /// **[Optional]**
519 /// Evaluate the gradient of the Lagrangian
520 /// @f$ \nabla_x L(x, y) = \nabla f(x) + \nabla g(x)\,y @f$
521 /// @default_impl ProblemVTable::default_eval_lagrangian_gradient
522 void eval_lagrangian_gradient(crvec x, crvec y, rvec grad_L, rvec work_n) const;
523
524 /// @}
525
526 /// @name Augmented Lagrangian
527 /// @{
528
529 /// **[Optional]**
530 /// Calculate both ψ(x) and the vector ŷ that can later be used to compute
531 /// ∇ψ.
532 /// @f[ \psi(x) = f(x) + \tfrac{1}{2}
533 /// \text{dist}_\Sigma^2\left(g(x) + \Sigma^{-1}y,\;D\right) @f]
534 /// @f[ \hat y = \Sigma\, \left(g(x) + \Sigma^{-1}y - \Pi_D\left(g(x)
535 /// + \Sigma^{-1}y\right)\right) @f]
536 /// @default_impl ProblemVTable::default_eval_augmented_lagrangian
537 [[nodiscard]] real_t
538 eval_augmented_lagrangian(crvec x, ///< [in] Decision variable @f$ x @f$
539 crvec y, ///< [in] Lagrange multipliers @f$ y @f$
540 crvec Σ, ///< [in] Penalty weights @f$ \Sigma @f$
541 rvec ŷ ///< [out] @f$ \hat y @f$
542 ) const;
543 /// **[Optional]**
544 /// Calculate the gradient ∇ψ(x).
545 /// @f[ \nabla \psi(x) = \nabla f(x) + \nabla g(x)\,\hat y(x) @f]
546 /// @default_impl ProblemVTable::default_eval_augmented_lagrangian_gradient
547 void eval_augmented_lagrangian_gradient(crvec x, ///< [in] Decision variable @f$ x @f$
548 crvec y, ///< [in] Lagrange multipliers @f$ y @f$
549 crvec Σ, ///< [in] Penalty weights @f$ \Sigma @f$
550 rvec grad_ψ, ///< [out] @f$ \nabla \psi(x) @f$
551 rvec work_n, ///< Dimension @f$ n @f$
552 rvec work_m ///< Dimension @f$ m @f$
553 ) const;
554 /// **[Optional]**
555 /// Calculate both ψ(x) and its gradient ∇ψ(x).
556 /// @f[ \psi(x) = f(x) + \tfrac{1}{2}
557 /// \text{dist}_\Sigma^2\left(g(x) + \Sigma^{-1}y,\;D\right) @f]
558 /// @f[ \nabla \psi(x) = \nabla f(x) + \nabla g(x)\,\hat y(x) @f]
559 /// @default_impl ProblemVTable::default_eval_augmented_lagrangian_and_gradient
560 [[nodiscard]] real_t
561 eval_augmented_lagrangian_and_gradient(crvec x, ///< [in] Decision variable @f$ x @f$
562 crvec y, ///< [in] Lagrange multipliers @f$ y @f$
563 crvec Σ, ///< [in] Penalty weights @f$ \Sigma @f$
564 rvec grad_ψ, ///< [out] @f$ \nabla \psi(x) @f$
565 rvec work_n, ///< Dimension @f$ n @f$
566 rvec work_m ///< Dimension @f$ m @f$
567 ) const;
568
569 /// @}
570
571 /// @name Checks
572 /// @{
573
574 /// **[Optional]**
575 /// Check that the problem formulation is well-defined, the dimensions match,
576 /// etc. Throws an exception if this is not the case.
577 void check() const;
578
579 /// @}
580
581 /// @name Metadata
582 /// @{
583
584 /// **[Optional]**
585 /// Get a descriptive name for the problem.
586 [[nodiscard]] std::string get_name() const;
587
588 /// @}
589
590 /// @name Querying specialized implementations
591 /// @{
592
593 /// Returns true if the problem provides an implementation of
594 /// @ref eval_inactive_indices_res_lna.
595 [[nodiscard]] bool provides_eval_inactive_indices_res_lna() const {
596 return vtable.eval_inactive_indices_res_lna != vtable.default_eval_inactive_indices_res_lna;
597 }
598 /// Returns true if the problem provides an implementation of
599 /// @ref eval_constraints_jacobian.
600 [[nodiscard]] bool provides_eval_constraints_jacobian() const {
601 return vtable.eval_constraints_jacobian != vtable.default_eval_constraints_jacobian;
602 }
603 /// Returns true if the problem provides an implementation of
604 /// @ref get_constraints_jacobian_sparsity.
606 return vtable.get_constraints_jacobian_sparsity !=
607 vtable.default_get_constraints_jacobian_sparsity;
608 }
609 /// Returns true if the problem provides an implementation of
610 /// @ref eval_grad_gi.
611 [[nodiscard]] bool provides_eval_grad_gi() const {
612 return vtable.eval_grad_gi != vtable.default_eval_grad_gi;
613 }
614 /// Returns true if the problem provides an implementation of
615 /// @ref eval_lagrangian_hessian_product.
616 [[nodiscard]] bool provides_eval_lagrangian_hessian_product() const {
617 return vtable.eval_lagrangian_hessian_product !=
618 vtable.default_eval_lagrangian_hessian_product;
619 }
620 /// Returns true if the problem provides an implementation of
621 /// @ref eval_lagrangian_hessian.
622 [[nodiscard]] bool provides_eval_lagrangian_hessian() const {
623 return vtable.eval_lagrangian_hessian != vtable.default_eval_lagrangian_hessian;
624 }
625 /// Returns true if the problem provides an implementation of
626 /// @ref get_lagrangian_hessian_sparsity.
627 [[nodiscard]] bool provides_get_lagrangian_hessian_sparsity() const {
628 return vtable.get_lagrangian_hessian_sparsity !=
629 vtable.default_get_lagrangian_hessian_sparsity;
630 }
631 /// Returns true if the problem provides an implementation of
632 /// @ref eval_augmented_lagrangian_hessian_product.
634 return vtable.eval_augmented_lagrangian_hessian_product !=
635 vtable.default_eval_augmented_lagrangian_hessian_product;
636 }
637 /// Returns true if the problem provides an implementation of
638 /// @ref eval_augmented_lagrangian_hessian.
640 return vtable.eval_augmented_lagrangian_hessian !=
641 vtable.default_eval_augmented_lagrangian_hessian;
642 }
643 /// Returns true if the problem provides an implementation of
644 /// @ref get_augmented_lagrangian_hessian_sparsity.
646 return vtable.get_augmented_lagrangian_hessian_sparsity !=
647 vtable.default_get_augmented_lagrangian_hessian_sparsity;
648 }
649 /// Returns true if the problem provides a specialized implementation of
650 /// @ref eval_objective_and_gradient, false if it uses the default implementation.
651 [[nodiscard]] bool provides_eval_objective_and_gradient() const {
652 return vtable.eval_objective_and_gradient != vtable.default_eval_objective_and_gradient;
653 }
654 /// Returns true if the problem provides a specialized implementation of
655 /// @ref eval_objective_and_constraints, false if it uses the default implementation.
656 [[nodiscard]] bool provides_eval_objective_and_constraints() const {
657 return vtable.eval_objective_and_constraints !=
658 vtable.default_eval_objective_and_constraints;
659 }
660 /// Returns true if the problem provides a specialized implementation of
661 /// @ref eval_objective_gradient_and_constraints_gradient_product, false if it uses the default implementation.
663 return vtable.eval_objective_gradient_and_constraints_gradient_product !=
664 vtable.default_eval_objective_gradient_and_constraints_gradient_product;
665 }
666 /// Returns true if the problem provides a specialized implementation of
667 /// @ref eval_lagrangian_gradient, false if it uses the default implementation.
668 [[nodiscard]] bool provides_eval_lagrangian_gradient() const {
669 return vtable.eval_lagrangian_gradient != vtable.default_eval_lagrangian_gradient;
670 }
671 /// Returns true if the problem provides a specialized implementation of
672 /// @ref eval_augmented_lagrangian, false if it uses the default implementation.
673 [[nodiscard]] bool provides_eval_augmented_lagrangian() const {
674 return vtable.eval_augmented_lagrangian != vtable.default_eval_augmented_lagrangian;
675 }
676 /// Returns true if the problem provides a specialized implementation of
677 /// @ref eval_augmented_lagrangian_gradient, false if it uses the default implementation.
679 return vtable.eval_augmented_lagrangian_gradient !=
680 vtable.default_eval_augmented_lagrangian_gradient;
681 }
682 /// Returns true if the problem provides a specialized implementation of
683 /// @ref eval_augmented_lagrangian_and_gradient, false if it uses the default implementation.
685 return vtable.eval_augmented_lagrangian_and_gradient !=
686 vtable.default_eval_augmented_lagrangian_and_gradient;
687 }
688 /// Returns true if the problem provides an implementation of
689 /// @ref get_variable_bounds.
690 [[nodiscard]] bool provides_get_variable_bounds() const {
691 return vtable.get_variable_bounds != vtable.default_get_variable_bounds;
692 }
693 /// Returns true if the problem provides an implementation of
694 /// @ref get_general_bounds.
695 [[nodiscard]] bool provides_get_general_bounds() const {
696 return vtable.get_general_bounds != vtable.default_get_general_bounds;
697 }
698 /// Returns true if the problem provides an implementation of @ref check.
699 [[nodiscard]] bool provides_check() const { return vtable.check != vtable.default_check; }
700 /// Returns true if the problem provides an implementation of @ref get_name.
701 [[nodiscard]] bool provides_get_name() const {
702 return vtable.get_name != vtable.default_get_name;
703 }
704
705 /// @}
706
707 /// @name Querying available functions
708 /// @{
709
710 /// Returns true if @ref eval_augmented_lagrangian_hessian_product can be called.
715 /// Returns true if @ref eval_augmented_lagrangian_hessian can be called.
718 (vtable.m == 0 && provides_eval_lagrangian_hessian());
719 }
720
721 /// @}
722
723 /// @name Helpers
724 /// @{
725
726 /// Given g(x), compute the intermediate results ŷ and dᵀŷ that can later be
727 /// used to compute ψ(x) and ∇ψ(x).
728 ///
729 /// Computes the result using the following algorithm:
730 /// @f[ \begin{aligned}
731 /// \zeta &= g(x) + \Sigma^{-1} y \\[]
732 /// d &= \zeta - \Pi_D(\zeta)
733 /// = \operatorname{eval\_proj\_diff\_g}(\zeta, \zeta) \\[]
734 /// \hat y &= \Sigma d \\[]
735 /// \end{aligned} @f]
736 /// @see @ref page_math
737 ///
738 /// @param[inout] g_ŷ
739 /// Input @f$ g(x) @f$, outputs @f$ \hat y @f$
740 /// @param[in] y
741 /// Lagrange multipliers @f$ y @f$
742 /// @param[in] Σ
743 /// Penalty weights @f$ \Sigma @f$
744 /// @return The inner product @f$ d^\top \hat y @f$
746
747 /// @}
748};
749
750/// @}
751
752#ifndef DOXYGEN
753template <class Tref>
754explicit TypeErasedProblem(Tref &&d)
756
757template <class Tref, class Allocator>
758explicit TypeErasedProblem(Tref &&d, Allocator alloc)
760#endif
761
762template <Config Conf, class Allocator>
764 return vtable.n;
765}
766template <Config Conf, class Allocator>
768 return vtable.m;
769}
770
771template <Config Conf, class Allocator>
773 rvec e) const {
774 return call(vtable.eval_projecting_difference_constraints, z, e);
775}
776template <Config Conf, class Allocator>
778 return call(vtable.eval_projection_multipliers, y, M);
779}
780template <Config Conf, class Allocator>
782 crvec grad_ψ, rvec x̂,
783 rvec p) const -> real_t {
784 return call(vtable.eval_proximal_gradient_step, γ, x, grad_ψ, x̂, p);
785}
786template <Config Conf, class Allocator>
788 real_t γ, crvec x, crvec grad_ψ, rindexvec J) const -> index_t {
789 return call(vtable.eval_inactive_indices_res_lna, γ, x, grad_ψ, J);
790}
791template <Config Conf, class Allocator>
793 return call(vtable.eval_objective, x);
794}
795template <Config Conf, class Allocator>
797 return call(vtable.eval_objective_gradient, x, grad_fx);
798}
799template <Config Conf, class Allocator>
801 return call(vtable.eval_constraints, x, gx);
802}
803template <Config Conf, class Allocator>
805 rvec grad_gxy) const {
806 return call(vtable.eval_constraints_gradient_product, x, y, grad_gxy);
807}
808template <Config Conf, class Allocator>
810 return call(vtable.eval_grad_gi, x, i, grad_gi);
811}
812template <Config Conf, class Allocator>
814 return call(vtable.eval_constraints_jacobian, x, J_values);
815}
816template <Config Conf, class Allocator>
818 return call(vtable.get_constraints_jacobian_sparsity);
819}
820template <Config Conf, class Allocator>
822 real_t scale, crvec v,
823 rvec Hv) const {
824 return call(vtable.eval_lagrangian_hessian_product, x, y, scale, v, Hv);
825}
826template <Config Conf, class Allocator>
828 rvec H_values) const {
829 return call(vtable.eval_lagrangian_hessian, x, y, scale, H_values);
830}
831template <Config Conf, class Allocator>
833 return call(vtable.get_lagrangian_hessian_sparsity);
834}
835template <Config Conf, class Allocator>
837 crvec x, crvec y, crvec Σ, real_t scale, crvec v, rvec Hv) const {
838 return call(vtable.eval_augmented_lagrangian_hessian_product, x, y, Σ, scale, v, Hv);
839}
840template <Config Conf, class Allocator>
842 crvec Σ, real_t scale,
843 rvec H_values) const {
844 return call(vtable.eval_augmented_lagrangian_hessian, x, y, Σ, scale, H_values);
845}
846template <Config Conf, class Allocator>
848 -> Sparsity {
849 return call(vtable.get_augmented_lagrangian_hessian_sparsity);
850}
851template <Config Conf, class Allocator>
853 rvec grad_fx) const -> real_t {
854 return call(vtable.eval_objective_and_gradient, x, grad_fx);
855}
856template <Config Conf, class Allocator>
858 rvec g) const -> real_t {
859 return call(vtable.eval_objective_and_constraints, x, g);
860}
861template <Config Conf, class Allocator>
863 crvec x, crvec y, rvec grad_f, rvec grad_gxy) const {
864 return call(vtable.eval_objective_gradient_and_constraints_gradient_product, x, y, grad_f,
865 grad_gxy);
866}
867template <Config Conf, class Allocator>
869 rvec work_n) const {
870 return call(vtable.eval_lagrangian_gradient, x, y, grad_L, work_n);
871}
872template <Config Conf, class Allocator>
874 rvec ŷ) const -> real_t {
875 return call(vtable.eval_augmented_lagrangian, x, y, Σ, ŷ);
876}
877template <Config Conf, class Allocator>
879 crvec Σ, rvec grad_ψ,
880 rvec work_n,
881 rvec work_m) const {
882 return call(vtable.eval_augmented_lagrangian_gradient, x, y, Σ, grad_ψ, work_n, work_m);
883}
884template <Config Conf, class Allocator>
886 crvec x, crvec y, crvec Σ, rvec grad_ψ, rvec work_n, rvec work_m) const -> real_t {
887 return call(vtable.eval_augmented_lagrangian_and_gradient, x, y, Σ, grad_ψ, work_n, work_m);
888}
889template <Config Conf, class Allocator>
891 return call(vtable.calc_ŷ_dᵀŷ, g_ŷ, y, Σ);
892}
893template <Config Conf, class Allocator>
895 return call(vtable.get_variable_bounds);
896}
897template <Config Conf, class Allocator>
899 return call(vtable.get_general_bounds);
900}
901template <Config Conf, class Allocator>
903 return call(vtable.check);
904}
905template <Config Conf, class Allocator>
907 return call(vtable.get_name);
908}
909
910/// @addtogroup grp_Problems
911/// @{
912
913template <Config Conf>
914void print_provided_functions(std::ostream &os, const TypeErasedProblem<Conf> &problem) {
915 // clang-format off
916 os << " eval_inactive_indices_res_lna: " << problem.provides_eval_inactive_indices_res_lna() << '\n'
917 << " eval_grad_gi: " << problem.provides_eval_grad_gi() << '\n'
918 << " eval_constraints_jacobian: " << problem.provides_eval_constraints_jacobian() << '\n'
919 << " eval_lagrangian_hessian_product: " << problem.provides_eval_lagrangian_hessian_product() << '\n'
920 << " eval_lagrangian_hessian: " << problem.provides_eval_lagrangian_hessian() << '\n'
921 << " eval_augmented_lagrangian_hessian_product: " << problem.provides_eval_augmented_lagrangian_hessian_product() << '\n'
922 << " eval_augmented_lagrangian_hessian: " << problem.provides_eval_augmented_lagrangian_hessian() << '\n'
923 << " eval_objective_and_gradient: " << problem.provides_eval_objective_and_gradient() << '\n'
924 << " eval_objective_and_constraints: " << problem.provides_eval_objective_and_constraints() << '\n'
925 << " eval_objective_gradient_and_constraints_gradient_product: " << problem.provides_eval_objective_gradient_and_constraints_gradient_product() << '\n'
926 << " eval_lagrangian_gradient: " << problem.provides_eval_lagrangian_gradient() << '\n'
927 << " eval_augmented_lagrangian: " << problem.provides_eval_augmented_lagrangian() << '\n'
928 << " eval_augmented_lagrangian_gradient: " << problem.provides_eval_augmented_lagrangian_gradient() << '\n'
929 << " eval_augmented_lagrangian_and_gradient: " << problem.provides_eval_augmented_lagrangian_and_gradient() << '\n'
930 << " get_variable_bounds: " << problem.provides_get_variable_bounds() << '\n'
931 << " get_general_bounds: " << problem.provides_get_general_bounds() << '\n'
932 << " check: " << problem.provides_check() << '\n'
933 << " get_name: " << problem.provides_get_name() << '\n';
934 // clang-format on
935}
936
937/// @}
938
939} // namespace alpaqa
The main polymorphic minimization problem interface.
void eval_constraints(crvec x, rvec gx) const
[Required] Function that evaluates the constraints,
std::string get_name() const
[Optional] Get a descriptive name for the problem.
bool provides_eval_constraints_jacobian() const
Returns true if the problem provides an implementation of eval_constraints_jacobian.
Sparsity get_lagrangian_hessian_sparsity() const
[Optional] Function that returns (a view of) the sparsity pattern of the Hessian of the Lagrangian.
void eval_grad_gi(crvec x, index_t i, rvec grad_gi) const
[Optional] Function that evaluates the gradient of one specific constraint,
void eval_lagrangian_hessian_product(crvec x, crvec y, real_t scale, crvec v, rvec Hv) const
[Optional] Function that evaluates the Hessian of the Lagrangian multiplied by a vector,
real_t eval_augmented_lagrangian_and_gradient(crvec x, crvec y, crvec Σ, rvec grad_ψ, rvec work_n, rvec work_m) const
[Optional] Calculate both ψ(x) and its gradient ∇ψ(x).
void eval_lagrangian_hessian(crvec x, crvec y, real_t scale, rvec H_values) const
[Optional] Function that evaluates the nonzero values of the Hessian of the Lagrangian,
bool provides_eval_augmented_lagrangian() const
Returns true if the problem provides a specialized implementation of eval_augmented_lagrangian,...
real_t eval_objective_and_gradient(crvec x, rvec grad_fx) const
[Optional] Evaluate both and its gradient, .
void eval_projection_multipliers(rvec y, real_t M) const
[Required] Function that projects the Lagrange multipliers for ALM.
bool provides_check() const
Returns true if the problem provides an implementation of check.
void check() const
[Optional] Check that the problem formulation is well-defined, the dimensions match,...
bool provides_eval_objective_and_gradient() const
Returns true if the problem provides a specialized implementation of eval_objective_and_gradient,...
bool provides_eval_augmented_lagrangian_and_gradient() const
Returns true if the problem provides a specialized implementation of eval_augmented_lagrangian_and_gr...
const Box & get_variable_bounds() const
[Optional] Get the rectangular constraint set of the decision variables, .
void eval_constraints_jacobian(crvec x, rvec J_values) const
[Optional] Function that evaluates the nonzero values of the Jacobian matrix of the constraints,
bool provides_eval_inactive_indices_res_lna() const
Returns true if the problem provides an implementation of eval_inactive_indices_res_lna.
bool provides_get_name() const
Returns true if the problem provides an implementation of get_name.
void eval_objective_gradient_and_constraints_gradient_product(crvec x, crvec y, rvec grad_f, rvec grad_gxy) const
[Optional] Evaluate both and .
bool provides_eval_objective_gradient_and_constraints_gradient_product() const
Returns true if the problem provides a specialized implementation of eval_objective_gradient_and_cons...
bool provides_eval_objective_and_constraints() const
Returns true if the problem provides a specialized implementation of eval_objective_and_constraints,...
real_t eval_objective(crvec x) const
[Required] Function that evaluates the cost,
length_t get_num_constraints() const
[Required] Number of constraints.
void eval_augmented_lagrangian_hessian_product(crvec x, crvec y, crvec Σ, real_t scale, crvec v, rvec Hv) const
[Optional] Function that evaluates the Hessian of the augmented Lagrangian multiplied by a vector,
bool provides_get_lagrangian_hessian_sparsity() const
Returns true if the problem provides an implementation of get_lagrangian_hessian_sparsity.
static TypeErasedProblem make(Args &&...args)
index_t eval_inactive_indices_res_lna(real_t γ, crvec x, crvec grad_ψ, rindexvec J) const
[Optional] Function that computes the inactive indices for the evaluation of the linear Newton appro...
bool supports_eval_augmented_lagrangian_hessian() const
Returns true if eval_augmented_lagrangian_hessian can be called.
bool provides_eval_lagrangian_hessian_product() const
Returns true if the problem provides an implementation of eval_lagrangian_hessian_product.
bool provides_get_constraints_jacobian_sparsity() const
Returns true if the problem provides an implementation of get_constraints_jacobian_sparsity.
length_t get_num_variables() const
[Required] Number of decision variables.
void eval_lagrangian_gradient(crvec x, crvec y, rvec grad_L, rvec work_n) const
[Optional] Evaluate the gradient of the Lagrangian
Sparsity get_constraints_jacobian_sparsity() const
[Optional] Function that returns (a view of) the sparsity pattern of the Jacobian of the constraints.
void eval_augmented_lagrangian_gradient(crvec x, crvec y, crvec Σ, rvec grad_ψ, rvec work_n, rvec work_m) const
[Optional] Calculate the gradient ∇ψ(x).
const Box & get_general_bounds() const
[Optional] Get the rectangular constraint set of the general constraint function, .
void eval_augmented_lagrangian_hessian(crvec x, crvec y, crvec Σ, real_t scale, rvec H_values) const
[Optional] Function that evaluates the nonzero values of the Hessian of the augmented Lagrangian,
bool provides_eval_augmented_lagrangian_hessian() const
Returns true if the problem provides an implementation of eval_augmented_lagrangian_hessian.
real_t eval_objective_and_constraints(crvec x, rvec g) const
[Optional] Evaluate both and .
bool provides_eval_augmented_lagrangian_gradient() const
Returns true if the problem provides a specialized implementation of eval_augmented_lagrangian_gradie...
bool provides_get_variable_bounds() const
Returns true if the problem provides an implementation of get_variable_bounds.
bool provides_eval_grad_gi() const
Returns true if the problem provides an implementation of eval_grad_gi.
guanaqo::TypeErased< VTable, allocator_type > TypeErased
void eval_projecting_difference_constraints(crvec z, rvec e) const
[Required] Function that evaluates the difference between the given point and its projection onto th...
void eval_objective_gradient(crvec x, rvec grad_fx) const
[Required] Function that evaluates the gradient of the cost,
bool provides_eval_augmented_lagrangian_hessian_product() const
Returns true if the problem provides an implementation of eval_augmented_lagrangian_hessian_product.
bool provides_get_general_bounds() const
Returns true if the problem provides an implementation of get_general_bounds.
bool provides_eval_lagrangian_hessian() const
Returns true if the problem provides an implementation of eval_lagrangian_hessian.
void eval_constraints_gradient_product(crvec x, crvec y, rvec grad_gxy) const
[Required] Function that evaluates the gradient of the constraints times a vector,
bool provides_get_augmented_lagrangian_hessian_sparsity() const
Returns true if the problem provides an implementation of get_augmented_lagrangian_hessian_sparsity.
real_t calc_ŷ_dᵀŷ(rvec g_ŷ, crvec y, crvec Σ) const
Given g(x), compute the intermediate results ŷ and dᵀŷ that can later be used to compute ψ(x) and ∇ψ(...
Sparsity get_augmented_lagrangian_hessian_sparsity() const
[Optional] Function that returns (a view of) the sparsity pattern of the Hessian of the augmented Lag...
real_t eval_augmented_lagrangian(crvec x, crvec y, crvec Σ, rvec ŷ) const
[Optional] Calculate both ψ(x) and the vector ŷ that can later be used to compute ∇ψ.
bool provides_eval_lagrangian_gradient() const
Returns true if the problem provides a specialized implementation of eval_lagrangian_gradient,...
bool supports_eval_augmented_lagrangian_hessian_product() const
Returns true if eval_augmented_lagrangian_hessian_product can be called.
real_t eval_proximal_gradient_step(real_t γ, crvec x, crvec grad_ψ, rvec x̂, rvec p) const
[Required] Function that computes a proximal gradient step.
#define USING_ALPAQA_CONFIG(Conf)
Definition config.hpp:77
#define ALPAQA_IF_QUADF(...)
Definition config.hpp:223
#define ALPAQA_IF_LONGD(...)
Definition config.hpp:235
#define ALPAQA_IF_FLOAT(...)
Definition config.hpp:229
#define ALPAQA_EXPORT_EXTERN_TEMPLATE(...)
Definition export.hpp:21
void print_provided_functions(std::ostream &os, const TypeErasedProblem< Conf > &problem)
EigenConfigd DefaultConfig
Definition config.hpp:31
typename Conf::real_t real_t
Definition config.hpp:86
typename Conf::rindexvec rindexvec
Definition config.hpp:106
typename Conf::index_t index_t
Definition config.hpp:104
typename Conf::length_t length_t
Definition config.hpp:103
typename Conf::rvec rvec
Definition config.hpp:91
typename Conf::crvec crvec
Definition config.hpp:92
Double-precision double configuration.
Definition config.hpp:176
Single-precision float configuration.
Definition config.hpp:172
long double configuration.
Definition config.hpp:181
Struct containing function pointers to all problem functions (like the objective and constraint funct...
optional_function_t< void(crvec x, rvec J_values) const > eval_constraints_jacobian
guanaqo::required_function_t< F > required_function_t
optional_function_t< void() const > check
static std::string default_get_name(const void *, const ProblemVTable &)
optional_function_t< void(crvec x, crvec y, crvec Σ, real_t scale, crvec v, rvec Hv) const > eval_augmented_lagrangian_hessian_product
guanaqo::optional_function_t< F, ProblemVTable > optional_function_t
optional_function_t< Sparsity() const > get_lagrangian_hessian_sparsity
static Sparsity default_get_lagrangian_hessian_sparsity(const void *, const ProblemVTable &)
optional_function_t< Sparsity() const > get_constraints_jacobian_sparsity
static Sparsity default_get_constraints_jacobian_sparsity(const void *, const ProblemVTable &)
optional_function_t< void(crvec x, crvec y, real_t scale, rvec H_values) const > eval_lagrangian_hessian
optional_function_t< void(crvec x, index_t i, rvec grad_gi) const > eval_grad_gi
required_function_t< void(rvec y, real_t M) const > eval_projection_multipliers
ProblemVTable(std::in_place_t, P &p)
static void default_eval_objective_gradient_and_constraints_gradient_product(const void *self, crvec x, crvec y, rvec grad_f, rvec grad_gxy, const ProblemVTable &vtable)
static real_t default_eval_augmented_lagrangian(const void *self, crvec x, crvec y, crvec Σ, rvec ŷ, const ProblemVTable &vtable)
optional_function_t< real_t(crvec x, rvec grad_fx) const > eval_objective_and_gradient
static void default_eval_lagrangian_hessian(const void *, crvec, crvec, real_t, rvec, const ProblemVTable &)
required_function_t< void(crvec x, rvec grad_fx) const > eval_objective_gradient
optional_function_t< void(crvec x, crvec y, crvec Σ, rvec grad_ψ, rvec work_n, rvec work_m) const > eval_augmented_lagrangian_gradient
static void default_eval_grad_gi(const void *, crvec, index_t, rvec, const ProblemVTable &)
static Sparsity default_get_augmented_lagrangian_hessian_sparsity(const void *, const ProblemVTable &)
optional_function_t< const Box &() const > get_variable_bounds
required_function_t< real_t(real_t γ, crvec x, crvec grad_ψ, rvec x̂, rvec p) const > eval_proximal_gradient_step
static void default_eval_lagrangian_gradient(const void *self, crvec x, crvec y, rvec grad_L, rvec work_n, const ProblemVTable &vtable)
required_function_t< void(crvec z, rvec e) const > eval_projecting_difference_constraints
optional_function_t< void(crvec x, crvec y, rvec grad_L, rvec work_n) const > eval_lagrangian_gradient
static const Box & default_get_general_bounds(const void *, const ProblemVTable &)
optional_function_t< real_t(crvec x, crvec y, crvec Σ, rvec ŷ) const > eval_augmented_lagrangian
optional_function_t< void(crvec x, crvec y, crvec Σ, real_t scale, rvec H_values) const > eval_augmented_lagrangian_hessian
optional_function_t< void(crvec x, crvec y, rvec grad_f, rvec grad_gxy) const > eval_objective_gradient_and_constraints_gradient_product
static void default_eval_lagrangian_hessian_product(const void *, crvec, crvec, real_t, crvec, rvec, const ProblemVTable &)
required_function_t< void(crvec x, rvec gx) const > eval_constraints
static const Box & default_get_variable_bounds(const void *, const ProblemVTable &)
optional_function_t< Sparsity() const > get_augmented_lagrangian_hessian_sparsity
static void default_eval_constraints_jacobian(const void *, crvec, rvec, const ProblemVTable &)
required_function_t< void(crvec x, crvec y, rvec grad_gxy) const > eval_constraints_gradient_product
static real_t default_eval_objective_and_gradient(const void *self, crvec x, rvec grad_fx, const ProblemVTable &vtable)
alpaqa::Box< config_t > Box
static real_t default_eval_augmented_lagrangian_and_gradient(const void *self, crvec x, crvec y, crvec Σ, rvec grad_ψ, rvec work_n, rvec work_m, const ProblemVTable &vtable)
static void default_eval_augmented_lagrangian_hessian_product(const void *self, crvec x, crvec y, crvec, real_t scale, crvec v, rvec Hv, const ProblemVTable &vtable)
static index_t default_eval_inactive_indices_res_lna(const void *, real_t, crvec, crvec, rindexvec, const ProblemVTable &)
static void default_check(const void *, const ProblemVTable &)
static real_t default_eval_objective_and_constraints(const void *self, crvec x, rvec g, const ProblemVTable &vtable)
static real_t calc_ŷ_dᵀŷ(const void *self, rvec g_ŷ, crvec y, crvec Σ, const ProblemVTable &vtable)
optional_function_t< std::string() const > get_name
required_function_t< real_t(crvec x) const > eval_objective
optional_function_t< void(crvec x, crvec y, real_t scale, crvec v, rvec Hv) const > eval_lagrangian_hessian_product
optional_function_t< const Box &() const > get_general_bounds
static void default_eval_augmented_lagrangian_hessian(const void *self, crvec x, crvec y, crvec, real_t scale, rvec H_values, const ProblemVTable &vtable)
optional_function_t< index_t(real_t γ, crvec x, crvec grad_ψ, rindexvec J) const > eval_inactive_indices_res_lna
optional_function_t< real_t(crvec x, rvec g) const > eval_objective_and_constraints
optional_function_t< real_t(crvec x, crvec y, crvec Σ, rvec grad_ψ, rvec work_n, rvec work_m) const > eval_augmented_lagrangian_and_gradient
static void default_eval_augmented_lagrangian_gradient(const void *self, crvec x, crvec y, crvec Σ, rvec grad_ψ, rvec work_n, rvec work_m, const ProblemVTable &vtable)