alpaqa 1.0.0a19
Nonconvex constrained optimization
Loading...
Searching...
No Matches
cutest-loader.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <alpaqa/cutest-interface-export.h>
8
9#include <iosfwd>
10#include <memory>
11#include <string>
12
13namespace alpaqa {
14
15/// Wrapper for CUTEst problems loaded from an external shared library.
16///
17/// @ingroup grp_Problems
19 : public BoxConstrProblem<alpaqa::EigenConfigd> {
20 public:
23
24 /// Load a CUTEst problem from the given shared library and OUTSDIF.d file.
25 /// If @p so_fname points to a directory, `"PROBLEM.so"` is appended
26 /// automatically. If @p outsdif_fname is `nullptr`, the same directory as
27 /// @p so_fname is used.
28 CUTEstProblem(const char *so_fname, const char *outsdif_fname = nullptr,
29 bool sparse = false);
35
36 public:
37 /// The report generated by CUTEst.
38 ///
39 /// @see `man CUTEST_creport` and `man CUTEST_ureport`
41 /// Function call counters.
42 ///
43 /// @note Note that hessian_times_vector, constraints and constraints_grad
44 /// may account for codes which allow the evaluation of a
45 /// selection of constraints only and may thus be much smaller
46 /// than the number of constraints times the number of
47 /// iterations.
48 struct Calls {
49 /// Number of calls to the objective function.
50 unsigned objective = 0;
51 /// Number of calls to the objective gradient.
52 unsigned objective_grad = 0;
53 /// Number of calls to the objective Hessian.
54 unsigned objective_hess = 0;
55 /// Number of Hessian times vector products.
56 unsigned hessian_times_vector = 0;
57 /// Number of calls to the constraint functions.
58 unsigned constraints = 0;
59 /// Number of calls to the constraint gradients.
60 unsigned constraints_grad = 0;
61 /// Number of calls to the constraint Hessians.
62 unsigned constraints_hess = 0;
63 };
64 Calls calls; ///< Function call counters.
65
66 /// CPU time (in seconds) for CUTEST_csetup.
67 double time_setup = 0;
68 /// CPU time (in seconds) since the end of CUTEST_csetup.
69 double time = 0;
70 };
71
72 [[nodiscard]] Report get_report() const;
73 std::ostream &format_report(std::ostream &os, const Report &r) const;
74 std::ostream &format_report(std::ostream &os) const {
75 return format_report(os, get_report());
76 }
77
78 public:
79 std::string name = "<UNKNOWN>"; ///< Problem name
80 vec x0; ///< Initial value of decision variables
81 vec y0; ///< Initial value of Lagrange multipliers
82
83 private:
85 bool sparse = false;
86 mutable int nnz_H = -1;
87 mutable int nnz_J = -1;
89 Eigen::VectorX<int> rows, cols;
90 } mutable storage_jac_g, storage_hess_L;
91
92 public:
93 [[nodiscard]] real_t eval_f(crvec x) const;
94 void eval_grad_f(crvec x, rvec grad_fx) const;
95 void eval_g(crvec x, rvec gx) const;
96 void eval_grad_g_prod(crvec x, crvec y, rvec grad_gxy) const;
97
98 void eval_jac_g(crvec x, rvec J_values) const;
99 [[nodiscard]] Sparsity get_jac_g_sparsity() const;
100 void eval_grad_gi(crvec x, index_t i, rvec grad_gi) const;
101 void eval_hess_L_prod(crvec x, crvec y, real_t scale, crvec v,
102 rvec Hv) const;
103 void eval_hess_L(crvec x, crvec y, real_t scale, rvec H_values) const;
104 [[nodiscard]] Sparsity get_hess_L_sparsity() const;
105 void eval_hess_ψ_prod(crvec x, crvec y, crvec Σ, real_t scale, crvec v,
106 rvec Hv) const;
107 [[nodiscard]] real_t eval_f_grad_f(crvec x, rvec grad_fx) const;
108 [[nodiscard]] real_t eval_f_g(crvec x, rvec g) const;
109 void eval_grad_L(crvec x, crvec y, rvec grad_L, rvec work_n) const;
110 [[nodiscard]] std::string get_name() const { return name; }
111};
112
113} // namespace alpaqa
Implements common problem functions for minimization problems with box constraints.
Wrapper for CUTEst problems loaded from an external shared library.
std::string get_name() const
Calls calls
Function call counters.
CUTEstProblem(CUTEstProblem &&) noexcept
CUTEstProblem(const CUTEstProblem &)
util::copyable_unique_ptr< class CUTEstLoader > impl
vec y0
Initial value of Lagrange multipliers.
vec x0
Initial value of decision variables.
CUTEstProblem & operator=(const CUTEstProblem &)
std::ostream & format_report(std::ostream &os) const
The report generated by CUTEst.
#define USING_ALPAQA_CONFIG(Conf)
Definition config.hpp:77
typename Conf::real_t real_t
Definition config.hpp:86
typename Conf::index_t index_t
Definition config.hpp:104
constexpr const auto inf
Definition config.hpp:112
typename Conf::rvec rvec
Definition config.hpp:91
typename Conf::crvec crvec
Definition config.hpp:92
typename Conf::vec vec
Definition config.hpp:88
Double-precision double configuration.
Definition config.hpp:174
Stores any of the supported sparsity patterns.
Definition sparsity.hpp:106