alpaqa cmake-targets
Nonconvex constrained optimization
Loading...
Searching...
No Matches
functional-problem.hpp
Go to the documentation of this file.
1#pragma once
2
5
6namespace alpaqa {
7
8/// Problem class that allows specifying the basic functions as C++
9/// `std::function`s.
10/// @ingroup grp_Problems
11template <Config Conf = DefaultConfig>
12class FunctionalProblem : public BoxConstrProblem<Conf> {
13 public:
15 using BoxConstrProblem<Conf>::BoxConstrProblem;
16
17 std::function<real_t(crvec)> f;
18 std::function<void(crvec, rvec)> grad_f;
19 std::function<void(crvec, rvec)> g;
20 std::function<void(crvec, crvec, rvec)> grad_g_prod;
21 std::function<void(crvec, index_t, rvec)> grad_gi;
22 std::function<void(crvec, rmat)> jac_g;
24 std::function<void(crvec, crvec, real_t, rmat)> hess_L;
26 std::function<void(crvec, crvec, crvec, real_t, rmat)> hess_ψ;
27
28 // clang-format off
29 real_t eval_f(crvec x) const { ScopedMallocAllower ma; return f(x); }
31 void eval_g(crvec x, rvec gx) const { ScopedMallocAllower ma; g(x, gx); }
36 // clang-format on
37 void eval_jac_g(crvec x, rvec J_values) const {
39 jac_g(x, J_values.reshaped(this->m, this->n));
40 }
43 hess_L(x, y, scale, H_values.reshaped(this->n, this->n));
44 }
47 hess_ψ(x, y, Σ, scale, H_values.reshaped(this->n, this->n));
48 }
49
50 /// @see @ref TypeErasedProblem::provides_eval_grad_gi
51 [[nodiscard]] bool provides_eval_grad_gi() const { return bool{grad_gi}; }
52 /// @see @ref TypeErasedProblem::provides_eval_jac_g
53 [[nodiscard]] bool provides_eval_jac_g() const { return bool{jac_g}; }
54 /// @see @ref TypeErasedProblem::provides_eval_hess_L_prod
55 [[nodiscard]] bool provides_eval_hess_L_prod() const { return bool{hess_L_prod}; }
56 /// @see @ref TypeErasedProblem::provides_eval_hess_L
57 [[nodiscard]] bool provides_eval_hess_L() const { return bool{hess_L}; }
58 /// @see @ref TypeErasedProblem::provides_eval_hess_ψ_prod
59 [[nodiscard]] bool provides_eval_hess_ψ_prod() const { return bool{hess_ψ_prod}; }
60 /// @see @ref TypeErasedProblem::provides_eval_hess_ψ
61 [[nodiscard]] bool provides_eval_hess_ψ() const { return bool{hess_ψ}; }
62
67};
68
69} // namespace alpaqa
Implements common problem functions for minimization problems with box constraints.
Problem class that allows specifying the basic functions as C++ std::functions.
std::function< void(crvec, crvec, real_t, rmat)> hess_L
std::function< real_t(crvec)> f
void eval_jac_g(crvec x, rvec J_values) const
std::function< void(crvec, crvec, real_t, crvec, rvec)> hess_L_prod
std::function< void(crvec, index_t, rvec)> grad_gi
std::function< void(crvec, crvec, crvec, real_t, crvec, rvec)> hess_ψ_prod
std::function< void(crvec, crvec, crvec, real_t, rmat)> hess_ψ
void eval_hess_ψ(crvec x, crvec y, crvec Σ, real_t scale, rvec H_values) const
std::function< void(crvec, crvec, rvec)> grad_g_prod
std::function< void(crvec, rvec)> g
FunctionalProblem & operator=(const FunctionalProblem &)=default
std::function< void(crvec, rmat)> jac_g
std::function< void(crvec, rvec)> grad_f
FunctionalProblem(const FunctionalProblem &)=default
void eval_grad_g_prod(crvec x, crvec y, rvec grad_gxy) const
void eval_hess_L_prod(crvec x, crvec y, real_t scale, crvec v, rvec Hv) const
void eval_grad_f(crvec x, rvec grad_fx) const
FunctionalProblem(FunctionalProblem &&) noexcept=default
void eval_g(crvec x, rvec gx) const
void eval_hess_L(crvec x, crvec y, real_t scale, rvec H_values) const
real_t eval_f(crvec x) const
void eval_grad_gi(crvec x, index_t i, rvec grad_gix) const
void eval_hess_ψ_prod(crvec x, crvec y, crvec Σ, real_t scale, crvec v, rvec Hv) const
#define USING_ALPAQA_CONFIG(Conf)
Definition config.hpp:56
typename Conf::rmat rmat
Definition config.hpp:74
typename Conf::real_t real_t
Definition config.hpp:65
typename Conf::index_t index_t
Definition config.hpp:77
constexpr const auto inf
Definition config.hpp:85
typename Conf::rvec rvec
Definition config.hpp:69
typename Conf::crvec crvec
Definition config.hpp:70