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) {
87 std::span<std::string_view> prob_opts,
92 auto register_name = get_reg_name_option(prob_opts);
93 std::any dl_opt = prob_opts;
95 .
problem = TEProblem::make<CntProblem>(std::in_place, full_path.c_str(),
96 register_name, &dl_opt),
97 .abs_path = fs::absolute(full_path),
100 auto &cnt_problem = problem.problem.
as<CntProblem>();
102 using sig_t = std::string(
const DLProblem::instance_t *);
103 problem.name = cnt_problem.problem.call_extra_func<sig_t>(
"get_name");
104 }
catch (std::out_of_range &) {
105 problem.name = problem.path.filename();
107 problem.evaluations = cnt_problem.evaluations;
114#if ALPAQA_HAVE_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 = problem.path.filename().string();
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_HAVE_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.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_HAVE_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_HAVE_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) +
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.