2#include <alpaqa/ipopt-adapter-export.h>
4#include <IpIpoptApplication.hpp>
14 auto penult = std::prev(tbl.end());
15 auto quote_concat = [](std::string &&a,
auto b) {
16 return a +
"'" + b.first +
"', ";
18 return std::accumulate(tbl.begin(), penult, std::string{}, quote_concat) +
19 "'" + std::string(penult->first) +
"'";
23void IPOPT_ADAPTER_EXPORT
set_param(Ipopt::IpoptApplication &app,
35 const auto &ipopt_opts = app.RegOptions()->RegisteredOptionsList();
36 const auto regops_it = ipopt_opts.find(std::string(opt_name));
37 if (regops_it == ipopt_opts.end())
38 throw std::invalid_argument(
39 "Invalid key '" + std::string(opt_name) +
"' for type '" +
40 "IpoptApplication" +
"' in '" + std::string(s.
full_key) +
45 const auto type = regops_it->second->Type();
47 case Ipopt::OT_Number: {
50 success = app.Options()->SetNumericValue(std::string(opt_name),
53 case Ipopt::OT_Integer: {
56 success = app.Options()->SetIntegerValue(std::string(opt_name),
59 case Ipopt::OT_String: {
60 success = app.Options()->SetStringValue(
61 std::string(opt_name), std::string(val_param.value),
false);
63 case Ipopt::OT_Unknown:
65 throw std::invalid_argument(
"Unknown type in '" +
70 throw std::invalid_argument(
"Invalid option in '" +
void set_param(bool &b, ParamString s)
std::string_view key
The subkey to resolve next.
std::string_view full_key
Full key string, used for diagnostics.
auto split_key(std::string_view full, char tok='.')
Split the string full on the first occurrence of tok.
std::string_view value
The value of the parameter to store.
auto possible_keys()
Return a string enumerating the possible attribute names for the struct type T.
Represents a parameter value encoded as a string in the format abc.def.key=value.