1#include <alpaqa/export.h>
13#ifdef ALPAQA_WITH_CUTEST
23namespace fs = std::filesystem;
33 std::string name =
"register_alpaqa_problem";
34 std::string_view name_key =
"register=";
35 auto name_it = std::find_if(
36 prob_opts.rbegin(), prob_opts.rend(),
37 [&](std::string_view opt) { return opt.starts_with(name_key); });
38 if (name_it != prob_opts.rend())
39 name = name_it->substr(name_key.size());
63 for (index_t i = 0; i < n; ++i) {
93 std::span<std::string_view> prob_opts,
98 auto register_name = get_reg_name_option(prob_opts);
100 .
problem = TEProblem::make<CntProblem>(std::in_place, full_path,
101 register_name, prob_opts),
102 .abs_path = fs::absolute(full_path),
105 auto &cnt_problem = problem.problem.
as<CntProblem>();
106 problem.name = cnt_problem.problem.get_name();
107 problem.evaluations = cnt_problem.evaluations;
114#if ALPAQA_WITH_CASADI
115template <
bool = true>
117 std::span<std::string_view> prob_opts,
119 static std::mutex mtx;
120 std::unique_lock lck{mtx};
125 .
problem = TEProblem::make<CntProblem>(std::in_place,
126 full_path.string().c_str()),
127 .abs_path = fs::absolute(full_path),
131 auto &cnt_problem = problem.problem.
as<CntProblem>();
132 auto &cs_problem = cnt_problem.problem;
133 problem.name = cs_problem.get_name();
134 problem.evaluations = cnt_problem.evaluations;
135 auto param_size = cs_problem.param.size();
137 if (cs_problem.param.size() != param_size)
139 "Incorrect problem parameter size (expected " +
140 std::to_string(param_size) +
", but got " +
141 std::to_string(cs_problem.param.size()) +
")");
148#ifdef ALPAQA_WITH_CUTEST
149template <
bool = true>
151 std::span<std::string_view> prob_opts,
153 std::string outsdif_path;
157 static std::mutex mtx;
158 std::unique_lock lck{mtx};
163 .
problem = TEProblem::make<CntProblem>(std::in_place, full_path.c_str(),
164 outsdif_path.c_str(), sparse),
165 .abs_path = fs::absolute(full_path),
169 auto &cnt_problem = problem.problem.
as<CntProblem>();
170 auto &cu_problem = cnt_problem.problem;
171 problem.name = cu_problem.get_name();
172 problem.evaluations = cnt_problem.evaluations;
173 problem.initial_guess_x = std::move(cu_problem.x0);
174 problem.initial_guess_y = std::move(cu_problem.y0);
184 const fs::path &file,
Options &opts) {
187 std::vector<std::string_view> prob_opts;
188 std::string_view prob_prefix =
"problem.";
190 auto used = opts.
used();
191 for (
auto opt = options.begin(); opt != options.end(); ++opt) {
192 if (opt->starts_with(prob_prefix)) {
193 prob_opts.push_back(opt->substr(prob_prefix.size()));
194 ++used.begin()[opt - options.begin()];
198 auto full_path = dir / file;
199 if (type ==
"dl" || type.empty()) {
201 return load_dl_problem(full_path, prob_opts, opts);
203 throw std::logic_error(
"This version of alpaqa was compiled without "
204 "support for dynamic problem loading");
206 }
else if (type ==
"cs") {
207#if ALPAQA_WITH_CASADI
208 if constexpr (std::is_same_v<config_t, alpaqa::EigenConfigd>)
209 return load_cs_problem(full_path, prob_opts, opts);
211 throw std::logic_error(
"CasADi only supports double precision.");
213 throw std::logic_error(
214 "This version of alpaqa was compiled without CasADi support");
216 }
else if (type ==
"cu") {
217#ifdef ALPAQA_WITH_CUTEST
218 if constexpr (std::is_same_v<config_t, alpaqa::EigenConfigd>)
219 return load_cu_problem(full_path, prob_opts, opts);
221 throw std::logic_error(
"CUTEst only supports double precision.");
223 throw std::logic_error(
224 "This version of alpaqa was compiled without CUTEst support");
227 throw std::invalid_argument(
"Unknown problem type '" + std::string(type) +
std::span< unsigned > used()
std::span< const std::string_view > options() const
Wrapper for CUTEst problems loaded from an external shared library.
The main polymorphic minimization problem interface.
bool provides_get_hess_L_sparsity() const
Returns true if the problem provides an implementation of get_hess_L_sparsity.
const Box & get_box_D() const
[Optional] Get the rectangular constraint set of the general constraint function, .
bool provides_get_box_C() const
Returns true if the problem provides an implementation of get_box_C.
Sparsity get_jac_g_sparsity() const
[Optional] Function that returns (a view of) the sparsity pattern of the Jacobian of the constraints.
Sparsity get_hess_ψ_sparsity() const
[Optional] Function that returns (a view of) the sparsity pattern of the Hessian of the augmented Lag...
length_t get_n() const
[Required] Number of decision variables.
Sparsity get_hess_L_sparsity() const
[Optional] Function that returns (a view of) the sparsity pattern of the Hessian of the Lagrangian.
length_t get_m() const
[Required] Number of constraints.
bool provides_get_hess_ψ_sparsity() const
Returns true if the problem provides an implementation of get_hess_ψ_sparsity.
bool provides_get_jac_g_sparsity() const
Returns true if the problem provides an implementation of get_jac_g_sparsity.
bool provides_get_box_D() const
Returns true if the problem provides an implementation of get_box_D.
const Box & get_box_C() const
[Optional] Get the rectangular constraint set of the decision variables, .
Class that loads a problem using dlopen.
T & as() &
Convert the type-erased object to the given type.
#define USING_ALPAQA_CONFIG(Conf)
void set_params(T &t, std::string_view prefix, std::span< const std::string_view > options, std::optional< std::span< unsigned > > used=std::nullopt)
Overwrites t based on the options that start with prefix.
void count_constr(ConstrCount &cnt, const alpaqa::Box< config_t > &C)
std::string get_reg_name_option(std::span< const std::string_view > prob_opts)
void count_problem(LoadedProblem &p)
void load_initial_guess(Options &opts, LoadedProblem &problem)
void set_params(T &t, std::string_view prefix, Options &opts)
LoadedProblem load_problem(std::string_view type, const fs::path &dir, const fs::path &file, Options &opts)
vec initial_guess_y
Multipliers g.
vec initial_guess_x
Unknowns.
vec initial_guess_w
Multipliers bounds.
std::optional< length_t > nnz_hess_L
std::optional< ConstrCount > general_constr_count
std::optional< length_t > nnz_hess_ψ
alpaqa::TypeErasedProblem< config_t > problem
std::optional< ConstrCount > box_constr_count
std::optional< length_t > nnz_jac_g
length_t ub
Number of variables with only upper bound.
length_t eq
Number of variables with equal bounds.
length_t lb
Number of variables with only lower bound.
length_t lbub
Number of variables with both bounds.
Double-precision double configuration.
Problem wrapper that keeps track of the number of evaluations and the run time of each function.
Custom parameter parsing exception.