12using namespace std::string_literals;
17 throw std::runtime_error(s +
" (" + std::to_string(code) +
")");
29 throw std::runtime_error(
"Failed to open "s + so_fname);
33 auto fptr_open = dlfun<decltype(FORTRAN_open)>(
"fortran_open_");
34 fptr_open(&
funit, outsdif_fname, &ierr);
36 throw std::runtime_error(
"Failed to open "s + outsdif_fname);
40 auto fptr_cdimen = dlfun<decltype(CUTEST_cdimen)>(
"cutest_cdimen_");
60 dlfun<decltype(CUTEST_csetup)>(
"cutest_cint_csetup_");
62 x.data(),
x_l.data(),
x_u.data(),
y.data(),
c_l.data(),
64 (logical *)
linear.data(), &e_order, &l_order, &v_order);
69 auto fptr_usetup = dlfun<decltype(CUTEST_usetup)>(
"cutest_usetup_");
78 ? dlfun<void>(
"cutest_cfn_")
79 : dlfun<void>(
"cutest_ufn_");
81 ? dlfun<void>(
"cutest_cint_cofg_")
82 : dlfun<void>(
"cutest_ugr_");
87 ? dlfun<void>(
"cutest_cint_cjprod_")
90 ? dlfun<void>(
"cutest_cint_ccifg_")
93 ? dlfun<void>(
"cutest_cint_chprod_")
94 : dlfun<void>(
"cutest_cint_uhprod_");
96 ? dlfun<void>(
"cutest_cdh_")
97 : dlfun<void>(
"cutest_udh_");
101 static inline constexpr auto call_as(
void *funp) {
106 assert(
x.size() ==
nvar);
111 x.data(), &
f,
work.data());
117 assert(
x.size() ==
nvar);
127 assert(
x.size() ==
nvar);
138 assert(
x.size() ==
nvar);
148 assert(
x.size() ==
nvar);
149 assert(
g.size() ==
ncon);
160 assert(
x.size() ==
nvar);
161 assert(
v.size() ==
ncon);
162 assert(grad_g_v.size() ==
nvar);
168 logical gotJ =
false;
169 logical jtrans =
true;
172 grad_g_v.data(), &
nvar);
178 assert(
x.size() ==
nvar);
185 integer icon = i + 1;
187 assert(icon <=
ncon);
191 &status, &
nvar, &icon,
x.data(), &ci,
grad_gi.data(), &grad);
197 assert(
x.size() ==
nvar);
198 assert(
y.size() ==
ncon);
199 assert(
v.rows() ==
nvar);
200 assert(Hv.rows() ==
nvar);
202 logical gotH =
false;
205 &status, &
nvar, &gotH,
x.data(),
v.data(), Hv.data());
209 &status, &
nvar, &
ncon, &gotH,
x.data(),
y.data(),
217 assert(
x.size() ==
nvar);
218 assert(
y.size() ==
ncon);
219 assert(
H.rows() >=
nvar);
220 assert(
H.cols() >=
nvar);
222 integer ldH =
H.rows();
225 &status, &
nvar,
x.data(), &ldH,
H.data());
229 &status, &
nvar, &
ncon,
x.data(),
y.data(), &ldH,
H.data());
235 return std::count_if(
x_l.data(),
x_l.data() +
nvar,
245 dlfun<decltype(CUTEST_probname)>(
"cutest_probname_")(&status,
248 auto nspace = std::find_if(
name.rbegin(),
name.rend(),
249 [](
char c) { return c !=
' '; });
257 ncon > 0 ? dlfun<decltype(CUTEST_creport)>(
"cutest_creport_")
258 : dlfun<decltype(CUTEST_ureport)>(
"cutest_ureport_");
259 fptr_report(&status, calls, time);
267 auto fptr_cterminate =
268 dlfun<decltype(CUTEST_cterminate)>(
"cutest_cterminate_");
269 fptr_cterminate(&status);
273 auto fptr_uterminate =
274 dlfun<decltype(CUTEST_uterminate)>(
"cutest_uterminate_");
275 fptr_uterminate(&status);
281 auto fptr_close = dlfun<decltype(FORTRAN_close)>(
"fortran_close_");
282 fptr_close(&
funit, &ierr);
294 if (
const char *error = dlerror(); error)
295 throw std::runtime_error(error);
329 implementation = std::make_unique<CUTEstLoader>(so_fname, outsdif_fname);
331 name =
l->get_name();
339 using namespace std::placeholders;
358 x0 = std::move(
l->x);
359 y0 = std::move(
l->y);
363 const std::string &outsdif_fname)
374 using stat_t =
decltype(r.
status);
379 r.
calls.objective = calls[0];
380 r.
calls.objective_grad = calls[1];
381 r.
calls.objective_hess = calls[2];
382 r.
calls.hessian_times_vector = calls[3];
394 case Status::Success:
return "Success";
395 case Status::AllocationError:
return "AllocationError";
396 case Status::ArrayBoundError:
return "ArrayBoundError";
397 case Status::EvaluationError:
return "EvaluationError";
399 throw std::out_of_range(
400 "invalid value for alpaqa::CUTEstProblem::Report::Status");
408 os <<
"CUTEst problem: " << r.
name <<
"\r\n\n"
409 <<
"Number of variables: " << r.
nvar <<
"\r\n"
410 <<
"Number of constraints: " << r.
ncon <<
"\r\n\n"
411 <<
"Status: " << r.
status <<
" (" << +r.
status <<
")\r\n\n"
412 <<
"Objective function evaluations: " << r.
calls.objective
414 <<
"Objective function gradient evaluations: "
415 << r.
calls.objective_grad <<
"\r\n"
416 <<
"Objective function Hessian evaluations: "
417 << r.
calls.objective_hess <<
"\r\n"
418 <<
"Hessian times vector products: "
419 << r.
calls.objective_hess <<
"\r\n\n";
421 os <<
"Constraint function evaluations: "
422 << r.
calls.constraints <<
"\r\n"
423 <<
"Constraint function gradients evaluations: "
424 << r.
calls.constraints_grad <<
"\r\n"
425 <<
"Constraint function Hessian evaluations: "
426 << r.
calls.constraints_hess <<
"\r\n\n";
428 return os <<
"Setup time: " << r.
time_setup <<
"s\r\n"
429 <<
"Time since setup: " << r.
time <<
"s";
const char * enum_name(CUTEstProblem::Report::Status s)
doublereal eval_objective_unconstrained(alpaqa::crvec x) const
void * eval_constr_grad_prod_p
alpaqa::vec y
lagrange multipliers
void eval_constraints_grad_prod(alpaqa::crvec x, alpaqa::crvec v, alpaqa::rvec grad_g_v) const
integer ncon
Number of constraints.
static constexpr auto call_as(void *funp)
alpaqa::vec x
decision variable
void eval_objective_grad_unconstrained(alpaqa::crvec x, alpaqa::rvec grad_f) const
alpaqa::vec c_u
upper bounds on constraints
CUTEstLoader(const char *so_fname, const char *outsdif_fname)
doublereal eval_objective_constrained(alpaqa::crvec x) const
integer iout
Fortran Unit Number for standard output.
integer get_report(doublereal *calls, doublereal *time)
integer funit
Fortran Unit Number for OUTSDIF.d file.
alpaqa::vec x_l
lower bound on x
static void throw_if_error(std::string s, int code)
alpaqa::vec x_u
upper bound on x
Eigen::Matrix< logical, Eigen::Dynamic, 1 > logical_vec
integer nvar
Number of decision variabls.
T * dlfun(const char *name)
void eval_lagr_hess(alpaqa::crvec x, alpaqa::crvec y, alpaqa::rmat H) const
void eval_constraints(alpaqa::crvec x, alpaqa::rvec g) const
void eval_objective_grad_constrained(alpaqa::crvec x, alpaqa::rvec grad_f) const
void * eval_lagr_hess_prod_p
unsigned count_box_constraints() const
void eval_lagr_hess_prod(alpaqa::crvec x, alpaqa::crvec y, alpaqa::crvec v, alpaqa::rvec Hv) const
void * eval_constr_i_grad_p
void * so_handle
dlopen handle to shared library
alpaqa::vec work
work vector
logical_vec equatn
whether the constraint is an equality
static void throw_error(std::string s, int code)
void eval_constraint_i_grad(alpaqa::crvec x, unsigned i, alpaqa::rvec grad_gi) const
logical_vec linear
whether the constraint is linear
integer io_buffer
Fortran Unit Number for internal IO.
alpaqa::vec c_l
lower bounds on constraints
Wrapper for CUTEst problems loaded from an external shared library.
alpaqa::vec x0
Initial value of decision variables.
unsigned number_box_constraints
The number of box constraints on x.
std::string name
Problem name.
CUTEstProblem(const char *so_fname, const char *outsdif_fname)
Load a CUTEst problem from the given shared library and OUTSDIF.d file.
alpaqa::vec y0
Initial value of Lagrange multipliers.
Report get_report() const
alpaqa::Problem problem
Problem statement (bounds, objective, constraints)
std::unique_ptr< class CUTEstLoader > implementation
CUTEstProblem & operator=(CUTEstProblem &&)
Eigen::Ref< const vec > crvec
Default type for immutable references to vectors.
realvec vec
Default type for vectors.
Eigen::Ref< mat > rmat
Default type for mutable references to matrices.
double real_t
Default floating point type.
Eigen::Ref< vec > rvec
Default type for mutable references to vectors.
The report generated by CUTEst.
double time_setup
CPU time (in seconds) for CUTEST_csetup.
std::ostream & operator<<(std::ostream &, const CUTEstProblem::Report &)
struct CUTEstProblem::Report::@1 calls
Function call counters.
Status
Status returned by CUTEst.
std::string name
Name of the problem.
unsigned ncon
Number of constraints.
double time
CPU time (in seconds) since the end of CUTEST_csetup.
unsigned nvar
Number of independent variables.
enum CUTEstProblem::Report::Status status
Exit status.
Box C
Constraints of the decision variables, .
std::function< hess_L_sig > hess_L
Hessian of the Lagrangian function .
std::function< f_sig > f
Cost function .
std::function< grad_gi_sig > grad_gi
Gradient of a specific constraint .
unsigned int m
Number of constraints, dimension of g(x) and z.
std::function< grad_f_sig > grad_f
Gradient of the cost function .
unsigned int n
Number of decision variables, dimension of x.
std::function< hess_L_prod_sig > hess_L_prod
Hessian of the Lagrangian function times vector .
std::function< g_sig > g
Constraint function .
Box D
Other constraints, .
std::function< grad_g_prod_sig > grad_g_prod
Gradient of the constraint function times vector .