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());
59 const fs::path &file,
Options &opts) {
62 std::vector<std::string_view> prob_opts;
63 std::string_view prob_prefix =
"problem.";
65 auto used = opts.
used();
66 for (
auto opt = options.begin(); opt != options.end(); ++opt) {
67 if (opt->starts_with(prob_prefix)) {
68 prob_opts.push_back(opt->substr(prob_prefix.size()));
69 used.begin()[opt - options.begin()] =
true;
73 auto full_path = dir / file;
74 if (type ==
"dl" || type.empty()) {
78 auto prefix = get_prefix_option(prob_opts);
79 std::any dl_opt = std::span{prob_opts};
81 .
problem = TEProblem::make<CntProblem>(
82 std::in_place, full_path.c_str(), prefix, &dl_opt),
83 .abs_path = fs::absolute(full_path),
86 auto &cnt_problem = problem.
problem.
as<CntProblem>();
88 load_initial_guess(opts, problem);
90 }
else if (type ==
"cs") {
92 static std::mutex mtx;
93 std::unique_lock lck{mtx};
99 TEProblem::make<CntProblem>(std::in_place, full_path.c_str()),
100 .abs_path = fs::absolute(full_path),
104 auto &cnt_problem = problem.
problem.
as<CntProblem>();
105 auto &cs_problem = cnt_problem.problem;
107 auto param_size = cs_problem.param.size();
109 if (cs_problem.param.size() != param_size)
111 "Incorrect problem parameter size: got " +
112 std::to_string(cs_problem.param.size()) +
", should be " +
113 std::to_string(param_size));
114 load_initial_guess(opts, problem);
117 throw std::logic_error(
118 "This version of alpaqa was compiled without CasADi support");
120 }
else if (type ==
"cu") {
121#if ALPAQA_HAVE_CUTEST
122 std::string outsdif_path;
124 if (outsdif_path.empty())
125 outsdif_path = full_path.parent_path() /
"OUTSDIF.d";
128 static std::mutex mtx;
129 std::unique_lock lck{mtx};
134 .
problem = TEProblem::make<CntProblem>(
135 std::in_place, full_path.c_str(), outsdif_path.c_str(), sparse),
136 .abs_path = fs::absolute(full_path),
140 auto &cnt_problem = problem.
problem.
as<CntProblem>();
141 auto &cu_problem = cnt_problem.problem;
145 load_initial_guess(opts, problem);
148 throw std::logic_error(
149 "This version of alpaqa was compiled without CUTEst support");
152 throw std::invalid_argument(
"Unknown problem type '" + std::string(type) +
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< bool > > 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
Problem wrapper that keeps track of the number of evaluations and the run time of each function.
Custom parameter parsing exception.