alpaqa 1.0.0a19
Nonconvex constrained optimization
Loading...
Searching...
No Matches
unconstr-problem.hpp
Go to the documentation of this file.
1#pragma once
2
4
5#include <numeric>
6
7namespace alpaqa {
8
9/// Implements common problem functions for minimization problems without
10/// constraints. Meant to be used as a base class for custom problem
11/// implementations.
12/// @ingroup grp_Problems
13template <Config Conf>
15 public:
17
18 /// Number of decision variables, dimension of x
20
21 /// @param n Number of decision variables
23
24 /// Change the number of decision variables.
25 void resize(length_t n) { this->n = n; }
26
27 UnconstrProblem(const UnconstrProblem &) = default;
31
32 /// Number of decision variables, @ref n
33 length_t get_n() const { return n; }
34 /// Number of constraints (always zero)
35 length_t get_m() const { return 0; }
36
37 /// No-op, no constraints.
38 /// @see @ref TypeErasedProblem::eval_g
39 void eval_g(crvec, rvec) const {}
40 /// Constraint gradient is always zero.
41 /// @see @ref TypeErasedProblem::eval_grad_g_prod
42 void eval_grad_g_prod(crvec, crvec, rvec grad) const { grad.setZero(); }
43 /// Constraint Jacobian is always empty.
44 /// @see @ref TypeErasedProblem::eval_jac_g
45 void eval_jac_g(crvec, rvec) const {}
46 /// Constraint gradient is always zero.
47 /// @see @ref TypeErasedProblem::eval_grad_gi
48 void eval_grad_gi(crvec, index_t, rvec grad_gi) const { grad_gi.setZero(); }
49
50 /// No proximal mapping, just a forward (gradient) step.
51 /// @see @ref TypeErasedProblem::eval_prox_grad_step
52 real_t eval_prox_grad_step(real_t γ, crvec x, crvec grad_ψ, rvec x̂, rvec p) const {
53 p = -γ * grad_ψ;
54 x̂ = x + p;
55 return 0;
56 }
57
58 /// @see @ref TypeErasedProblem::eval_proj_diff_g
59 void eval_proj_diff_g(crvec, rvec) const {}
60
61 /// @see @ref TypeErasedProblem::eval_proj_multipliers
63
64 /// @see @ref TypeErasedProblem::eval_inactive_indices_res_lna
66 std::iota(J.begin(), J.end(), index_t{0});
67 return J.size();
68 }
69
70 /// @see @ref TypeErasedProblem::get_name
71 [[nodiscard]] std::string get_name() const { return "UnconstrProblem"; }
72};
73
74} // namespace alpaqa
Implements common problem functions for minimization problems without constraints.
std::string get_name() const
UnconstrProblem(const UnconstrProblem &)=default
void eval_jac_g(crvec, rvec) const
Constraint Jacobian is always empty.
UnconstrProblem & operator=(const UnconstrProblem &)=default
length_t get_m() const
Number of constraints (always zero)
void eval_proj_multipliers(rvec, real_t) const
void eval_grad_gi(crvec, index_t, rvec grad_gi) const
Constraint gradient is always zero.
length_t n
Number of decision variables, dimension of x.
void eval_proj_diff_g(crvec, rvec) const
UnconstrProblem(UnconstrProblem &&) noexcept=default
void eval_g(crvec, rvec) const
No-op, no constraints.
index_t eval_inactive_indices_res_lna(real_t, crvec, crvec, rindexvec J) const
void resize(length_t n)
Change the number of decision variables.
real_t eval_prox_grad_step(real_t γ, crvec x, crvec grad_ψ, rvec x̂, rvec p) const
No proximal mapping, just a forward (gradient) step.
length_t get_n() const
Number of decision variables, n.
void eval_grad_g_prod(crvec, crvec, rvec grad) const
Constraint gradient is always zero.
#define USING_ALPAQA_CONFIG(Conf)
Definition config.hpp:77
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
constexpr const auto inf
Definition config.hpp:112
typename Conf::rvec rvec
Definition config.hpp:91
typename Conf::crvec crvec
Definition config.hpp:92