alpaqa pi-pico
Nonconvex constrained optimization
Loading...
Searching...
No Matches
ipopt-adapter.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <alpaqa/ipopt-adapter-export.h>
7
8#include <IpTNLP.hpp>
9
10namespace alpaqa {
11
12/// Based on https://coin-or.github.io/Ipopt/INTERFACES.html
13class IPOPT_ADAPTER_EXPORT IpoptAdapter : public Ipopt::TNLP {
14 public:
22 using Index = Ipopt::Index;
23 using Number = Ipopt::Number;
24
25 struct Results {
26 Ipopt::SolverReturn status = Ipopt::SolverReturn::UNASSIGNED;
27 vec solution_x, solution_z_L, solution_z_U, solution_y, solution_g;
28 real_t solution_f = NaN<config_t>, infeasibility = NaN<config_t>,
29 nlp_error = NaN<config_t>;
30 length_t iter_count = 0;
31
32 [[nodiscard]] vec combine_bounds_multipliers() const {
33 return (-solution_z_L.array() >= solution_z_U.array())
34 .select(solution_z_L, solution_z_U);
35 }
36 } results;
37
38 IpoptAdapter(const Problem &problem);
39 IpoptAdapter(Problem &&) = delete;
40
41 /// @name Functions required by Ipopt
42 /// @{
43
44 bool get_nlp_info(Index &n, Index &m, Index &nnz_jac_g, Index &nnz_h_lag,
45 IndexStyleEnum &index_style) override;
46
47 bool get_bounds_info(Index n, Number *x_l, Number *x_u, Index m,
48 Number *g_l, Number *g_u) override;
49
50 bool get_starting_point(Index n, bool init_x, Number *x, bool init_z,
52 Number *lambda) override;
53
54 bool eval_f(Index n, const Number *x, bool new_x,
55 Number &obj_value) override;
56
57 bool eval_grad_f(Index n, const Number *x, bool new_x,
58 Number *grad_f) override;
59
60 bool eval_g(Index n, const Number *x, bool new_x, Index m,
61 Number *g) override;
62
63 bool eval_jac_g(Index n, const Number *x, bool new_x, Index m,
65 Number *values) override;
66
67 bool eval_h(Index n, const Number *x, bool new_x, Number obj_factor,
69 Index *iRow, Index *jCol, Number *values) override;
70
71 void finalize_solution(Ipopt::SolverReturn status, Index n, const Number *x,
72 const Number *z_L, const Number *z_U, Index m,
73 const Number *g, const Number *lambda,
74 Number obj_value, const Ipopt::IpoptData *ip_data,
75 Ipopt::IpoptCalculatedQuantities *ip_cq) override;
76
77 /// @}
78
79 private:
83 Sparsity orig_sparsity_jac_g = problem.get_jac_g_sparsity(),
84 orig_sparsity_hess_L = problem.get_hess_L_sparsity();
85 SparsityConv cvt_sparsity_jac_g = orig_sparsity_jac_g,
86 cvt_sparsity_hess_L = orig_sparsity_hess_L;
87};
88
89} // namespace alpaqa
Based on https://coin-or.github.io/Ipopt/INTERFACES.html.
const Problem & problem
IpoptAdapter(Problem &&)=delete
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_L_sparsity() const
[Optional] Function that returns (a view of) the sparsity pattern of the Hessian of the Lagrangian.
#define USING_ALPAQA_CONFIG(Conf)
Definition config.hpp:77
Converts one matrix storage format to another.
typename Conf::real_t real_t
Definition config.hpp:86
typename Conf::length_t length_t
Definition config.hpp:103
constexpr const auto inf
Definition config.hpp:112
typename Conf::vec vec
Definition config.hpp:88
Double-precision double configuration.
Definition config.hpp:176
Sparse coordinate list structure (COO).
Definition sparsity.hpp:56