12#ifdef ALPAQA_WITH_CUTEST
26namespace fs = std::filesystem;
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) {
93 std::span<std::string_view> prob_opts,
98 auto register_name = get_reg_name_option(prob_opts);
99 std::any dl_opt = prob_opts;
101 .
problem = TEProblem::make<CntProblem>(std::in_place, full_path.c_str(),
102 register_name, &dl_opt),
103 .abs_path = fs::absolute(full_path),
106 auto &cnt_problem = problem.problem.
as<CntProblem>();
108 using sig_t = std::string(
const DLProblem::instance_t *);
109 problem.name = cnt_problem.problem.call_extra_func<sig_t>(
"get_name");
110 }
catch (std::out_of_range &) {
111 problem.name = problem.path.filename();
113 problem.evaluations = cnt_problem.evaluations;
120#if ALPAQA_WITH_CASADI
121template <
bool = true>
123 std::span<std::string_view> prob_opts,
125 static std::mutex mtx;
126 std::unique_lock lck{mtx};
131 .
problem = TEProblem::make<CntProblem>(std::in_place,
132 full_path.string().c_str()),
133 .abs_path = fs::absolute(full_path),
137 auto &cnt_problem = problem.problem.
as<CntProblem>();
138 auto &cs_problem = cnt_problem.problem;
139 problem.name = problem.path.filename().string();
140 problem.evaluations = cnt_problem.evaluations;
141 auto param_size = cs_problem.param.size();
143 if (cs_problem.param.size() != param_size)
145 "Incorrect problem parameter size (expected " +
146 std::to_string(param_size) +
", but got " +
147 std::to_string(cs_problem.param.size()) +
")");
154#ifdef ALPAQA_WITH_CUTEST
155template <
bool = true>
157 std::span<std::string_view> prob_opts,
159 std::string outsdif_path;
163 static std::mutex mtx;
164 std::unique_lock lck{mtx};
169 .
problem = TEProblem::make<CntProblem>(std::in_place, full_path.c_str(),
170 outsdif_path.c_str(), sparse),
171 .abs_path = fs::absolute(full_path),
175 auto &cnt_problem = problem.problem.
as<CntProblem>();
176 auto &cu_problem = cnt_problem.problem;
177 problem.name = cu_problem.name;
178 problem.evaluations = cnt_problem.evaluations;
179 problem.initial_guess_x = std::move(cu_problem.x0);
180 problem.initial_guess_y = std::move(cu_problem.y0);
190 const fs::path &file,
Options &opts) {
193 std::vector<std::string_view> prob_opts;
194 std::string_view prob_prefix =
"problem.";
196 auto used = opts.
used();
197 for (
auto opt = options.begin(); opt != options.end(); ++opt) {
198 if (opt->starts_with(prob_prefix)) {
199 prob_opts.push_back(opt->substr(prob_prefix.size()));
200 ++used.begin()[opt - options.begin()];
204 auto full_path = dir / file;
205 if (type ==
"dl" || type.empty()) {
207 return load_dl_problem(full_path, prob_opts, opts);
209 throw std::logic_error(
"This version of alpaqa was compiled without "
210 "support for dynamic problem loading");
212 }
else if (type ==
"cs") {
213#if ALPAQA_WITH_CASADI
214 if constexpr (std::is_same_v<config_t, alpaqa::EigenConfigd>)
215 return load_cs_problem(full_path, prob_opts, opts);
217 throw std::logic_error(
"CasADi only supports double precision.");
219 throw std::logic_error(
220 "This version of alpaqa was compiled without CasADi support");
222 }
else if (type ==
"cu") {
223#ifdef ALPAQA_WITH_CUTEST
224 if constexpr (std::is_same_v<config_t, alpaqa::EigenConfigd>)
225 return load_cu_problem(full_path, prob_opts, opts);
227 throw std::logic_error(
"CUTEst only supports double precision.");
229 throw std::logic_error(
230 "This version of alpaqa was compiled without CUTEst support");
233 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.
bool provides_get_hess_L_sparsity() const
Returns true if the problem provides an implementation of get_hess_L_sparsity.
const Box & get_box_D() const
[Optional] Get the rectangular constraint set of the general constraint function, .
bool provides_get_box_C() const
Returns true if the problem provides an implementation of get_box_C.
Sparsity get_jac_g_sparsity() const
[Optional] Function that returns (a view of) the sparsity pattern of the Jacobian of the constraints.
Sparsity get_hess_ψ_sparsity() const
[Optional] Function that returns (a view of) the sparsity pattern of the Hessian of the augmented Lag...
length_t get_n() const
[Required] Number of decision variables.
Sparsity get_hess_L_sparsity() const
[Optional] Function that returns (a view of) the sparsity pattern of the Hessian of the Lagrangian.
length_t get_m() const
[Required] Number of constraints.
bool provides_get_hess_ψ_sparsity() const
Returns true if the problem provides an implementation of get_hess_ψ_sparsity.
bool provides_get_jac_g_sparsity() const
Returns true if the problem provides an implementation of get_jac_g_sparsity.
bool provides_get_box_D() const
Returns true if the problem provides an implementation of get_box_D.
const Box & get_box_C() const
[Optional] Get the rectangular constraint set of the decision variables, .
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.
void count_constr(ConstrCount &cnt, const alpaqa::Box< config_t > &C)
std::string get_reg_name_option(std::span< const std::string_view > prob_opts)
void count_problem(LoadedProblem &p)
void load_initial_guess(Options &opts, LoadedProblem &problem)
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
Multipliers g.
vec initial_guess_x
Unknowns.
vec initial_guess_w
Multipliers bounds.
std::optional< length_t > nnz_hess_L
std::optional< ConstrCount > general_constr_count
std::optional< length_t > nnz_hess_ψ
alpaqa::TypeErasedProblem< config_t > problem
std::optional< ConstrCount > box_constr_count
std::optional< length_t > nnz_jac_g
length_t ub
Number of variables with only upper bound.
length_t eq
Number of variables with equal bounds.
length_t lb
Number of variables with only lower bound.
length_t lbub
Number of variables with both bounds.
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.