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