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,
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();
76 problem.evaluations = cnt_problem.evaluations;
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();
101 problem.evaluations = cnt_problem.evaluations;
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));
114#ifdef ALPAQA_HAVE_CUTEST
115template <
bool = true>
117 std::span<std::string_view> prob_opts,
119 std::string outsdif_path;
123 static std::mutex mtx;
124 std::unique_lock lck{mtx};
129 .
problem = TEProblem::make<CntProblem>(std::in_place, full_path.c_str(),
130 outsdif_path.c_str(), sparse),
131 .abs_path = fs::absolute(full_path),
135 auto &cnt_problem = problem.problem.
as<CntProblem>();
136 auto &cu_problem = cnt_problem.problem;
137 problem.name = cu_problem.name;
138 problem.evaluations = cnt_problem.evaluations;
139 problem.initial_guess_x = std::move(cu_problem.x0);
140 problem.initial_guess_y = std::move(cu_problem.y0);
149 const fs::path &file,
Options &opts) {
152 std::vector<std::string_view> prob_opts;
153 std::string_view prob_prefix =
"problem.";
155 auto used = opts.
used();
156 for (
auto opt = options.begin(); opt != options.end(); ++opt) {
157 if (opt->starts_with(prob_prefix)) {
158 prob_opts.push_back(opt->substr(prob_prefix.size()));
159 ++used.begin()[opt - options.begin()];
163 auto full_path = dir / file;
164 if (type ==
"dl" || type.empty()) {
166 }
else if (type ==
"cs") {
167#if ALPAQA_HAVE_CASADI
168 if constexpr (std::is_same_v<config_t, alpaqa::EigenConfigd>)
169 return load_cs_problem(full_path, prob_opts, opts);
171 throw std::logic_error(
"CasADi only supports double precision.");
173 throw std::logic_error(
174 "This version of alpaqa was compiled without CasADi support");
176 }
else if (type ==
"cu") {
177#ifdef ALPAQA_HAVE_CUTEST
178 if constexpr (std::is_same_v<config_t, alpaqa::EigenConfigd>)
179 return load_cu_problem(full_path, prob_opts, opts);
181 throw std::logic_error(
"CUTEst only supports double precision.");
183 throw std::logic_error(
184 "This version of alpaqa was compiled without CUTEst support");
187 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.