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>
7#include <guanaqo/copyable-unique_ptr.hpp>
8#include <guanaqo/dl-flags.hpp>
9
10#include <iosfwd>
11#include <string>
12
13namespace alpaqa {
14
15using guanaqo::DynamicLoadFlags;
16
17/// Wrapper for CUTEst problems loaded from an external shared library.
18///
19/// @ingroup grp_Problems
20class CUTEST_INTERFACE_EXPORT CUTEstProblem
21 : public BoxConstrProblem<alpaqa::EigenConfigd> {
22 public:
24
25 /// Load a CUTEst problem from the given shared library and OUTSDIF.d file.
26 /// If @p so_fname points to a directory, `"PROBLEM.so"` is appended
27 /// automatically. If @p outsdif_fname is `nullptr`, the same directory as
28 /// @p so_fname is used.
29 CUTEstProblem(const char *so_fname, const char *outsdif_fname = nullptr,
30 bool sparse = false, DynamicLoadFlags dl_flags = {});
34 CUTEstProblem &operator=(CUTEstProblem &&) noexcept;
36
37 public:
38 /// The report generated by CUTEst.
39 ///
40 /// @see `man CUTEST_creport` and `man CUTEST_ureport`
41 struct Report {
42 /// Function call counters.
43 ///
44 /// @note Note that hessian_times_vector, constraints and constraints_grad
45 /// may account for codes which allow the evaluation of a
46 /// selection of constraints only and may thus be much smaller
47 /// than the number of constraints times the number of
48 /// iterations.
49 struct Calls {
50 /// Number of calls to the objective function.
51 unsigned objective = 0;
52 /// Number of calls to the objective gradient.
53 unsigned objective_grad = 0;
54 /// Number of calls to the objective Hessian.
55 unsigned objective_hess = 0;
56 /// Number of Hessian times vector products.
58 /// Number of calls to the constraint functions.
59 unsigned constraints = 0;
60 /// Number of calls to the constraint gradients.
61 unsigned constraints_grad = 0;
62 /// Number of calls to the constraint Hessians.
63 unsigned constraints_hess = 0;
64 };
65 Calls calls; ///< Function call counters.
66
67 /// CPU time (in seconds) for CUTEST_csetup.
68 double time_setup = 0;
69 /// CPU time (in seconds) since the end of CUTEST_csetup.
70 double time = 0;
71 };
72
73 [[nodiscard]] Report get_report() const;
74 std::ostream &format_report(std::ostream &os, const Report &r) const;
75 std::ostream &format_report(std::ostream &os) const {
76 return format_report(os, get_report());
77 }
78
79 public:
80 std::string name = "<UNKNOWN>"; ///< Problem name
81 vec x0; ///< Initial value of decision variables
82 vec y0; ///< Initial value of Lagrange multipliers
83
84 private:
85 guanaqo::copyable_unique_ptr<class CUTEstLoader> impl;
86 bool sparse = false;
87 mutable int nnz_H = -1;
88 mutable int nnz_J = -1;
90 Eigen::VectorX<int> rows, cols;
91 } mutable storage_jac_g, storage_hess_L;
92
93 public:
94 [[nodiscard]] real_t eval_objective(crvec x) const;
95 void eval_objective_gradient(crvec x, rvec grad_fx) const;
96 void eval_constraints(crvec x, rvec gx) const;
97 void eval_constraints_gradient_product(crvec x, crvec y,
98 rvec grad_gxy) const;
99
100 void eval_constraints_jacobian(crvec x, rvec J_values) const;
101 [[nodiscard]] Sparsity get_constraints_jacobian_sparsity() const;
102 void eval_grad_gi(crvec x, index_t i, rvec grad_gi) const;
103 void eval_lagrangian_hessian_product(crvec x, crvec y, real_t scale,
104 crvec v, rvec Hv) const;
105 void eval_lagrangian_hessian(crvec x, crvec y, real_t scale,
106 rvec H_values) const;
107 [[nodiscard]] Sparsity get_lagrangian_hessian_sparsity() const;
108 void eval_augmented_lagrangian_hessian_product(crvec x, crvec y, crvec Σ,
109 real_t scale, crvec v,
110 rvec Hv) const;
111 [[nodiscard]] real_t eval_objective_and_gradient(crvec x,
112 rvec grad_fx) const;
113 [[nodiscard]] real_t eval_objective_and_constraints(crvec x, rvec g) const;
114 void eval_lagrangian_gradient(crvec x, crvec y, rvec grad_L,
115 rvec work_n) const;
116 [[nodiscard]] std::string get_name() const { return name; }
117};
118
119} // namespace alpaqa
BoxConstrProblem(length_t num_variables, length_t num_constraints)
std::string get_name() const
Calls calls
Function call counters.
unsigned constraints_grad
Number of calls to the constraint gradients.
double time_setup
CPU time (in seconds) for CUTEST_csetup.
Report get_report() const
CUTEstProblem(const char *so_fname, const char *outsdif_fname=nullptr, bool sparse=false, DynamicLoadFlags dl_flags={})
Load a CUTEst problem from the given shared library and OUTSDIF.d file.
unsigned objective
Number of calls to the objective function.
CUTEstProblem(CUTEstProblem &&) noexcept
CUTEstProblem(const CUTEstProblem &)
unsigned constraints
Number of calls to the constraint functions.
std::string name
Problem name.
vec y0
Initial value of Lagrange multipliers.
unsigned hessian_times_vector
Number of Hessian times vector products.
double time
CPU time (in seconds) since the end of CUTEST_csetup.
vec x0
Initial value of decision variables.
unsigned objective_hess
Number of calls to the objective Hessian.
std::ostream & format_report(std::ostream &os, const Report &r) const
guanaqo::copyable_unique_ptr< class CUTEstLoader > impl
unsigned constraints_hess
Number of calls to the constraint Hessians.
CUTEstProblem & operator=(const CUTEstProblem &)
std::ostream & format_report(std::ostream &os) const
unsigned objective_grad
Number of calls to the objective gradient.
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
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:176