alpaqa 1.0.0a10
Nonconvex constrained optimization
Loading...
Searching...
No Matches
cutest-loader.hpp
Go to the documentation of this file.
1#pragma once
2
6
7#include <iosfwd>
8#include <memory>
9#include <string>
10
11namespace alpaqa {
12
13/// Wrapper for CUTEst problems loaded from an external shared library.
14///
15/// @ingroup grp_Problems
16class CUTEstProblem : public BoxConstrProblem<alpaqa::EigenConfigd> {
17 public:
19
20 /// Load a CUTEst problem from the given shared library and OUTSDIF.d file.
21 CUTEstProblem(const char *so_fname, const char *outsdif_fname,
22 bool sparse = false);
26 CUTEstProblem &operator=(CUTEstProblem &&) noexcept;
28
29 public:
30 /// The report generated by CUTEst.
31 ///
32 /// @see `man CUTEST_creport` and `man CUTEST_ureport`
33 struct Report {
34 /// Function call counters.
35 ///
36 /// @note Note that hessian_times_vector, constraints and constraints_grad
37 /// may account for codes which allow the evaluation of a
38 /// selection of constraints only and may thus be much smaller
39 /// than the number of constraints times the number of
40 /// iterations.
41 struct Calls {
42 /// Number of calls to the objective function.
43 unsigned objective = 0;
44 /// Number of calls to the objective gradient.
45 unsigned objective_grad = 0;
46 /// Number of calls to the objective Hessian.
47 unsigned objective_hess = 0;
48 /// Number of Hessian times vector products.
49 unsigned hessian_times_vector = 0;
50 /// Number of calls to the constraint functions.
51 unsigned constraints = 0;
52 /// Number of calls to the constraint gradients.
53 unsigned constraints_grad = 0;
54 /// Number of calls to the constraint Hessians.
55 unsigned constraints_hess = 0;
56 };
57 Calls calls; ///< Function call counters.
58
59 /// CPU time (in seconds) for CUTEST_csetup.
60 double time_setup = 0;
61 /// CPU time (in seconds) since the end of CUTEST_csetup.
62 double time = 0;
63 };
64
65 [[nodiscard]] Report get_report() const;
66 std::ostream &format_report(std::ostream &os, const Report &r) const;
67 std::ostream &format_report(std::ostream &os) const;
68
69 public:
70 std::string name = "<UNKNOWN>"; ///< Problem name
71 vec x0; ///< Initial value of decision variables
72 vec y0; ///< Initial value of Lagrange multipliers
73
74 private:
76 bool sparse = false;
77 mutable int nnz_H = -1;
78 mutable int nnz_J = -1;
79 mutable Eigen::VectorX<int> H_row, H_col, J_row, J_col;
80 mutable vec H_work, J_work;
82
83 public:
84 [[nodiscard]] real_t eval_f(crvec x) const;
85 void eval_grad_f(crvec x, rvec grad_fx) const;
86 void eval_g(crvec x, rvec gx) const;
87 void eval_grad_g_prod(crvec x, crvec y, rvec grad_gxy) const;
88
89 void eval_jac_g(crvec x, rindexvec inner_idx, rindexvec outer_ptr,
90 rvec J_values) const;
91 [[nodiscard]] length_t get_jac_g_num_nonzeros() const;
92 void eval_grad_gi(crvec x, index_t i, rvec grad_gi) const;
93 void eval_hess_L_prod(crvec x, crvec y, real_t scale, crvec v,
94 rvec Hv) const;
95 void eval_hess_L(crvec x, crvec y, real_t scale, rindexvec inner_idx,
96 rindexvec outer_ptr, rvec H_values) const;
97 [[nodiscard]] length_t get_hess_L_num_nonzeros() const;
98 void eval_hess_ψ_prod(crvec x, crvec y, crvec Σ, real_t scale, crvec v,
99 rvec Hv) const;
100 [[nodiscard]] real_t eval_f_grad_f(crvec x, rvec grad_fx) const;
101 [[nodiscard]] real_t eval_f_g(crvec x, rvec g) const;
102 void eval_grad_L(crvec x, crvec y, rvec grad_L, rvec work_n) const;
103};
104
105} // namespace alpaqa
Implements common problem functions for minimization problems with box constraints.
Wrapper for CUTEst problems loaded from an external shared library.
void eval_grad_gi(crvec x, index_t i, rvec grad_gi) const
Calls calls
Function call counters.
real_t eval_f_g(crvec x, rvec g) const
Report get_report() const
void eval_grad_L(crvec x, crvec y, rvec grad_L, rvec work_n) const
Eigen::VectorX< int > J_row
Eigen::VectorX< int > J_col
CUTEstProblem(CUTEstProblem &&) noexcept
Eigen::VectorX< int > H_col
CUTEstProblem(const CUTEstProblem &)
void eval_hess_L(crvec x, crvec y, real_t scale, rindexvec inner_idx, rindexvec outer_ptr, rvec H_values) const
std::string name
Problem name.
util::copyable_unique_ptr< class CUTEstLoader > impl
real_t eval_f_grad_f(crvec x, rvec grad_fx) const
vec y0
Initial value of Lagrange multipliers.
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
vec x0
Initial value of decision variables.
Eigen::VectorX< int > H_row
void eval_grad_f(crvec x, rvec grad_fx) const
real_t eval_f(crvec x) const
void eval_g(crvec x, rvec gx) const
length_t get_jac_g_num_nonzeros() const
std::ostream & format_report(std::ostream &os, const Report &r) const
CUTEstProblem & operator=(const CUTEstProblem &)
void eval_jac_g(crvec x, rindexvec inner_idx, rindexvec outer_ptr, rvec J_values) const
std::ostream & format_report(std::ostream &os) const
void eval_hess_ψ_prod(crvec x, crvec y, crvec Σ, real_t scale, crvec v, rvec Hv) const
length_t get_hess_L_num_nonzeros() const
The report generated by CUTEst.
#define USING_ALPAQA_CONFIG(Conf)
Definition: config.hpp:54
typename Conf::indexvec indexvec
Definition: config.hpp:76
typename Conf::real_t real_t
Definition: config.hpp:63
typename Conf::rindexvec rindexvec
Definition: config.hpp:77
typename Conf::index_t index_t
Definition: config.hpp:75
typename Conf::length_t length_t
Definition: config.hpp:74
typename Conf::rvec rvec
Definition: config.hpp:67
typename Conf::crvec crvec
Definition: config.hpp:68
typename Conf::vec vec
Definition: config.hpp:64
Double-precision double configuration.
Definition: config.hpp:127