5#include <IpIpoptCalculatedQuantities.hpp>
6#include <IpIpoptData.hpp>
14 Index &nnz_h_lag, IndexStyleEnum &index_style) {
21 if (jac_g_index != hess_L_index)
22 throw std::invalid_argument(
23 "All problem matrices should use the same index convention");
24 if (jac_g_index != 0 && jac_g_index != 1)
25 throw std::invalid_argument(
26 "Sparse matrix indices should start at 0 or 1");
27 index_style = jac_g_index == 0 ? TNLP::C_STYLE : TNLP::FORTRAN_STYLE;
29 using enum sparsity::Symmetry;
30 if (hess_L_sym != Upper && hess_L_sym != Lower)
31 throw std::invalid_argument(
"Hessian matrix should be symmetric");
37 const auto &C =
problem.get_variable_bounds();
38 mvec{x_l, n} = C.lower;
39 mvec{x_u, n} = C.upper;
40 const auto &D =
problem.get_general_bounds();
41 mvec{g_l, m} = D.lower;
42 mvec{g_u, m} = D.upper;
48 Index m,
bool init_lambda,
61 mvec{z_L, n}.setZero();
66 mvec{z_U, n}.setZero();
72 mvec{lambda, m}.setZero();
84 [[maybe_unused]]
bool new_x,
Number *grad_f) {
96 [[maybe_unused]]
bool new_x,
99 if (!
problem.provides_eval_constraints_jacobian())
100 throw std::logic_error(
101 "Missing required function: eval_constraints_jacobian");
102 if (values ==
nullptr) {
107 std::span{values,
static_cast<size_t>(nele_jac)},
108 [&](std::span<real_t> v) {
118 [[maybe_unused]]
bool new_lambda,
Index nele_hess,
120 if (!
problem.provides_eval_lagrangian_hessian())
121 throw std::logic_error(
122 "Missing required function: eval_lagrangian_hessian");
123 if (values ==
nullptr) {
128 std::span{values,
static_cast<size_t>(nele_hess)},
129 [&](std::span<real_t> v) {
142 const Ipopt::IpoptData *ip_data,
143 Ipopt::IpoptCalculatedQuantities *ip_cq) {
150 results.solution_f = obj_value;
151 results.infeasibility = ip_cq->curr_constraint_violation();
152 results.nlp_error = ip_cq->unscaled_curr_nlp_error();
153 results.iter_count = ip_data->iter_count();
IpoptAdapter(const Problem &problem)
vec initial_guess_bounds_multipliers
bool eval_g(Index n, const Number *x, bool new_x, Index m, Number *g) override
bool eval_grad_f(Index n, const Number *x, bool new_x, Number *grad_f) override
SparsityConv cvt_sparsity_jac_g
bool eval_h(Index n, const Number *x, bool new_x, Number obj_factor, Index m, const Number *lambda, bool new_lambda, Index nele_hess, Index *iRow, Index *jCol, Number *values) override
bool get_starting_point(Index n, bool init_x, Number *x, bool init_z, Number *z_L, Number *z_U, Index m, bool init_lambda, Number *lambda) override
bool get_bounds_info(Index n, Number *x_l, Number *x_u, Index m, Number *g_l, Number *g_u) override
struct alpaqa::IpoptAdapter::Results results
bool eval_f(Index n, const Number *x, bool new_x, Number &obj_value) override
bool get_nlp_info(Index &n, Index &m, Index &nnz_jac_g, Index &nnz_h_lag, IndexStyleEnum &index_style) override
bool eval_jac_g(Index n, const Number *x, bool new_x, Index m, Index nele_jac, Index *iRow, Index *jCol, Number *values) override
vec initial_guess_multipliers
void finalize_solution(Ipopt::SolverReturn status, Index n, const Number *x, const Number *z_L, const Number *z_U, Index m, const Number *g, const Number *lambda, Number obj_value, const Ipopt::IpoptData *ip_data, Ipopt::IpoptCalculatedQuantities *ip_cq) override
TypeErasedProblem< config_t > Problem
SparsityConv cvt_sparsity_hess_L
auto as_vec(std::span< T, E > s)
Convert a std::span to an Eigen::Vector view.
typename Conf::cmvec cmvec