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());
59 std::span<std::string_view> prob_opts,
64 auto register_name = get_reg_name_option(prob_opts);
65 std::any dl_opt = prob_opts;
67 .
problem = TEProblem::make<CntProblem>(std::in_place, full_path.c_str(),
68 register_name, &dl_opt),
69 .abs_path = fs::absolute(full_path),
72 auto &cnt_problem = problem.problem.
as<CntProblem>();
74 using sig_t = std::string(
const DLProblem::instance_t *);
75 problem.name = cnt_problem.problem.call_extra_func<sig_t>(
"get_name");
76 }
catch (std::out_of_range &) {
77 problem.name = problem.path.filename();
79 problem.evaluations = cnt_problem.evaluations;
88 std::span<std::string_view> prob_opts,
90 static std::mutex mtx;
91 std::unique_lock lck{mtx};
96 .
problem = TEProblem::make<CntProblem>(std::in_place,
97 full_path.string().c_str()),
98 .abs_path = fs::absolute(full_path),
102 auto &cnt_problem = problem.problem.
as<CntProblem>();
103 auto &cs_problem = cnt_problem.problem;
104 problem.name = problem.path.filename().string();
105 problem.evaluations = cnt_problem.evaluations;
106 auto param_size = cs_problem.param.size();
108 if (cs_problem.param.size() != param_size)
110 "Incorrect problem parameter size: got " +
111 std::to_string(cs_problem.param.size()) +
", should be " +
112 std::to_string(param_size));
118#ifdef ALPAQA_HAVE_CUTEST
119template <
bool = true>
121 std::span<std::string_view> prob_opts,
123 std::string outsdif_path;
127 static std::mutex mtx;
128 std::unique_lock lck{mtx};
133 .
problem = TEProblem::make<CntProblem>(std::in_place, full_path.c_str(),
134 outsdif_path.c_str(), sparse),
135 .abs_path = fs::absolute(full_path),
139 auto &cnt_problem = problem.problem.
as<CntProblem>();
140 auto &cu_problem = cnt_problem.problem;
141 problem.name = cu_problem.name;
142 problem.evaluations = cnt_problem.evaluations;
143 problem.initial_guess_x = std::move(cu_problem.x0);
144 problem.initial_guess_y = std::move(cu_problem.y0);
153 const fs::path &file,
Options &opts) {
156 std::vector<std::string_view> prob_opts;
157 std::string_view prob_prefix =
"problem.";
159 auto used = opts.
used();
160 for (
auto opt = options.begin(); opt != options.end(); ++opt) {
161 if (opt->starts_with(prob_prefix)) {
162 prob_opts.push_back(opt->substr(prob_prefix.size()));
163 ++used.begin()[opt - options.begin()];
167 auto full_path = dir / file;
168 if (type ==
"dl" || type.empty()) {
170 return load_dl_problem(full_path, prob_opts, opts);
172 throw std::logic_error(
"This version of alpaqa was compiled without "
173 "support for dynamic problem loading");
175 }
else if (type ==
"cs") {
176#if ALPAQA_HAVE_CASADI
177 if constexpr (std::is_same_v<config_t, alpaqa::EigenConfigd>)
178 return load_cs_problem(full_path, prob_opts, opts);
180 throw std::logic_error(
"CasADi only supports double precision.");
182 throw std::logic_error(
183 "This version of alpaqa was compiled without CasADi support");
185 }
else if (type ==
"cu") {
186#ifdef ALPAQA_HAVE_CUTEST
187 if constexpr (std::is_same_v<config_t, alpaqa::EigenConfigd>)
188 return load_cu_problem(full_path, prob_opts, opts);
190 throw std::logic_error(
"CUTEst only supports double precision.");
192 throw std::logic_error(
193 "This version of alpaqa was compiled without CUTEst support");
196 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.