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