alpaqa 1.0.0a17
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:
23 using Index = Ipopt::Index;
24 using Number = Ipopt::Number;
25
26 struct Results {
27 Ipopt::SolverReturn status = Ipopt::SolverReturn::UNASSIGNED;
28 vec solution_x, solution_z_L, solution_z_U, solution_y, solution_g;
29 real_t solution_f = NaN<config_t>, infeasibility = NaN<config_t>,
30 nlp_error = NaN<config_t>;
31 length_t iter_count = 0;
32 } results;
33
34 IpoptAdapter(const Problem &problem);
35 IpoptAdapter(Problem &&) = delete;
36
37 /// @name Functions required by Ipopt
38 /// @{
39
40 bool get_nlp_info(Index &n, Index &m, Index &nnz_jac_g, Index &nnz_h_lag,
41 IndexStyleEnum &index_style) override;
42
43 bool get_bounds_info(Index n, Number *x_l, Number *x_u, Index m,
44 Number *g_l, Number *g_u) override;
45
46 bool get_starting_point(Index n, bool init_x, Number *x, bool init_z,
48 Number *lambda) override;
49
50 bool eval_f(Index n, const Number *x, bool new_x,
51 Number &obj_value) override;
52
53 bool eval_grad_f(Index n, const Number *x, bool new_x,
54 Number *grad_f) override;
55
56 bool eval_g(Index n, const Number *x, bool new_x, Index m,
57 Number *g) override;
58
59 bool eval_jac_g(Index n, const Number *x, bool new_x, Index m,
61 Number *values) override;
62
63 bool eval_h(Index n, const Number *x, bool new_x, Number obj_factor,
65 Index *iRow, Index *jCol, Number *values) override;
66
67 void finalize_solution(Ipopt::SolverReturn status, Index n, const Number *x,
68 const Number *z_L, const Number *z_U, Index m,
69 const Number *g, const Number *lambda,
70 Number obj_value, const Ipopt::IpoptData *ip_data,
71 Ipopt::IpoptCalculatedQuantities *ip_cq) override;
72
73 /// @}
74
75 private:
79 Sparsity orig_sparsity_jac_g = problem.get_jac_g_sparsity(),
80 orig_sparsity_hess_L = problem.get_hess_L_sparsity();
81 SparsityConv cvt_sparsity_jac_g = orig_sparsity_jac_g,
82 cvt_sparsity_hess_L = orig_sparsity_hess_L;
83};
84
85} // 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:174
Sparse coordinate list structure (COO).
Definition sparsity.hpp:56