alpaqa 1.0.0a9
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 /// Name of the problem.
35 std::string name;
36
37 /// Number of independent variables.
38 int nvar = 0;
39 /// Number of constraints.
40 int ncon = 0;
41
42 /// Status returned by CUTEst.
43 /// @todo I don't think this is useful, remove it.
44 enum Status {
45 Success = 0, ///< Successful call.
46 AllocationError = 1, ///< Array allocation/deallocation error.
47 ArrayBoundError = 2, ///< Array bound error.
48 EvaluationError = 3, ///< Evaluation error.
49 } status = Status::Success; ///< Exit status.
50
51 /// Function call counters.
52 ///
53 /// @note Note that hessian_times_vector, constraints and constraints_grad
54 /// may account for codes which allow the evaluation of a
55 /// selection of constraints only and may thus be much smaller
56 /// than the number of constraints times the number of
57 /// iterations.
58 struct {
59 /// Number of calls to the objective function.
60 unsigned objective = 0;
61 /// Number of calls to the objective gradient.
62 unsigned objective_grad = 0;
63 /// Number of calls to the objective Hessian.
64 unsigned objective_hess = 0;
65 /// Number of Hessian times vector products.
66 unsigned hessian_times_vector = 0;
67 /// Number of calls to the constraint functions.
68 unsigned constraints = 0;
69 /// Number of calls to the constraint gradients.
70 unsigned constraints_grad = 0;
71 /// Number of calls to the constraint Hessians.
72 unsigned constraints_hess = 0;
73 } calls; ///< Function call counters.
74
75 /// CPU time (in seconds) for CUTEST_csetup.
76 double time_setup = 0;
77 /// CPU time (in seconds) since the end of CUTEST_csetup.
78 double time = 0;
79 };
80
81 [[nodiscard]] Report get_report() const;
82
83 public:
84 std::string name = "<UNKNOWN>"; ///< Problem name
85 vec x0; ///< Initial value of decision variables
86 vec y0; ///< Initial value of Lagrange multipliers
87
88 private:
90 bool sparse = false;
91 mutable int nnz_H = -1;
92 mutable int nnz_J = -1;
93 mutable Eigen::VectorX<int> H_row, H_col, J_row, J_col;
94 mutable vec H_work, J_work;
96
97 public:
98 [[nodiscard]] real_t eval_f(crvec x) const;
99 void eval_grad_f(crvec x, rvec grad_fx) const;
100 void eval_g(crvec x, rvec gx) const;
101 void eval_grad_g_prod(crvec x, crvec y, rvec grad_gxy) const;
102
103 void eval_jac_g(crvec x, rindexvec inner_idx, rindexvec outer_ptr,
104 rvec J_values) const;
105 [[nodiscard]] length_t get_jac_g_num_nonzeros() const;
106 void eval_grad_gi(crvec x, index_t i, rvec grad_gi) const;
107 void eval_hess_L_prod(crvec x, crvec y, real_t scale, crvec v,
108 rvec Hv) const;
109 void eval_hess_L(crvec x, crvec y, real_t scale, rindexvec inner_idx,
110 rindexvec outer_ptr, rvec H_values) const;
111 [[nodiscard]] length_t get_hess_L_num_nonzeros() const;
112 void eval_hess_ψ_prod(crvec x, crvec y, crvec Σ, real_t scale, crvec v,
113 rvec Hv) const;
114 [[nodiscard]] real_t eval_f_grad_f(crvec x, rvec grad_fx) const;
115 [[nodiscard]] real_t eval_f_g(crvec x, rvec g) const;
116 void eval_grad_L(crvec x, crvec y, rvec grad_L, rvec work_n) const;
117};
118
119/// @related CUTEstProblem::Report
120std::ostream &operator<<(std::ostream &, const CUTEstProblem::Report &);
121/// @related CUTEstProblem::Report::Status
123/// @related CUTEstProblem::Report::Status
124std::ostream &operator<<(std::ostream &, CUTEstProblem::Report::Status);
125
126} // 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
real_t eval_f_g(crvec x, rvec g) 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
Report get_report() 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
CUTEstProblem & operator=(const CUTEstProblem &)
void eval_jac_g(crvec x, rindexvec inner_idx, rindexvec outer_ptr, rvec J_values) 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
#define USING_ALPAQA_CONFIG(Conf)
Definition: config.hpp:54
typename Conf::indexvec indexvec
Definition: config.hpp:76
std::ostream & operator<<(std::ostream &os, PANOCStopCrit s)
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
constexpr const char * enum_name(PANOCStopCrit s)
The report generated by CUTEst.
Status
Status returned by CUTEst.
std::string name
Name of the problem.
Double-precision double configuration.
Definition: config.hpp:127