9#ifdef ALPAQA_HAVE_CUTEST
24namespace fs = std::filesystem;
30std::string get_prefix_option(std::span<const std::string_view> prob_opts) {
31 std::string prefix =
"alpaqa_problem";
32 std::string_view prefix_key =
"prefix=";
33 auto prefix_it = std::find_if(
34 prob_opts.rbegin(), prob_opts.rend(),
35 [&](std::string_view opt) { return opt.starts_with(prefix_key); });
36 if (prefix_it != prob_opts.rend())
37 prefix = prefix_it->substr(prefix_key.size());
56 std::span<std::string_view> prob_opts,
61 auto prefix = get_prefix_option(prob_opts);
62 std::any dl_opt = prob_opts;
64 .
problem = TEProblem::make<CntProblem>(std::in_place, full_path.c_str(),
66 .abs_path = fs::absolute(full_path),
69 auto &cnt_problem = problem.
problem.
as<CntProblem>();
71 using sig_t = std::string(
const DLProblem::instance_t *);
72 problem.
name = cnt_problem.problem.call_extra_func<sig_t>(
"get_name");
73 }
catch (std::out_of_range &) {
74 problem.
name = problem.
path.filename();
77 load_initial_guess(opts, problem);
84 std::span<std::string_view> prob_opts,
86 static std::mutex mtx;
87 std::unique_lock lck{mtx};
93 TEProblem::make<CntProblem>(std::in_place, full_path.c_str()),
94 .abs_path = fs::absolute(full_path),
98 auto &cnt_problem = problem.
problem.
as<CntProblem>();
99 auto &cs_problem = cnt_problem.problem;
100 problem.
name = problem.
path.filename();
102 auto param_size = cs_problem.param.size();
104 if (cs_problem.param.size() != param_size)
106 "Incorrect problem parameter size: got " +
107 std::to_string(cs_problem.param.size()) +
", should be " +
108 std::to_string(param_size));
109 load_initial_guess(opts, problem);
114#ifdef ALPAQA_HAVE_CUTEST
115template <
bool = true>
117 std::span<std::string_view> prob_opts,
119 std::string outsdif_path;
121 if (outsdif_path.empty())
122 outsdif_path = full_path.parent_path() /
"OUTSDIF.d";
125 static std::mutex mtx;
126 std::unique_lock lck{mtx};
131 .
problem = TEProblem::make<CntProblem>(std::in_place, full_path.c_str(),
132 outsdif_path.c_str(), sparse),
133 .abs_path = fs::absolute(full_path),
137 auto &cnt_problem = problem.
problem.
as<CntProblem>();
138 auto &cu_problem = cnt_problem.problem;
139 problem.
name = cu_problem.name;
143 load_initial_guess(opts, problem);
151 const fs::path &file,
Options &opts) {
154 std::vector<std::string_view> prob_opts;
155 std::string_view prob_prefix =
"problem.";
157 auto used = opts.
used();
158 for (
auto opt = options.begin(); opt != options.end(); ++opt) {
159 if (opt->starts_with(prob_prefix)) {
160 prob_opts.push_back(opt->substr(prob_prefix.size()));
161 ++used.begin()[opt - options.begin()];
165 auto full_path = dir / file;
166 if (type ==
"dl" || type.empty()) {
167 return load_dl_problem(full_path, prob_opts, opts);
168 }
else if (type ==
"cs") {
169#if ALPAQA_HAVE_CASADI
170 if constexpr (std::is_same_v<config_t, alpaqa::EigenConfigd>)
171 return load_cs_problem(full_path, prob_opts, opts);
173 throw std::logic_error(
"CasADi only supports double precision.");
175 throw std::logic_error(
176 "This version of alpaqa was compiled without CasADi support");
178 }
else if (type ==
"cu") {
179#ifdef ALPAQA_HAVE_CUTEST
180 if constexpr (std::is_same_v<config_t, alpaqa::EigenConfigd>)
181 return load_cu_problem(full_path, prob_opts, opts);
183 throw std::logic_error(
"CUTEst only supports double precision.");
185 throw std::logic_error(
186 "This version of alpaqa was compiled without CUTEst support");
189 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.
Problem definition for a CasADi problem, loaded from a DLL.
The main polymorphic minimization problem interface.
length_t get_n() const
[Required] Number of decision variables.
length_t get_m() const
[Required] Number of constraints.
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.
decltype(auto) 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
Unknowns.
vec initial_guess_w
Multipliers g.
alpaqa::TypeErasedProblem< config_t > problem
std::shared_ptr< alpaqa::EvalCounter > evaluations
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.