alpaqa 1.0.0a10
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>
5
6#include <IpTNLP.hpp>
7
8namespace alpaqa {
9
10/// Based on https://coin-or.github.io/Ipopt/INTERFACES.html
11class IPOPT_ADAPTER_EXPORT IpoptAdapter : public Ipopt::TNLP {
12 public:
20 using Index = Ipopt::Index;
21 using Number = Ipopt::Number;
22
23 struct Results {
24 Ipopt::SolverReturn status = Ipopt::SolverReturn::UNASSIGNED;
25 vec solution_x, solution_z_L, solution_z_U, solution_y, solution_g;
26 real_t solution_f = NaN<config_t>, infeasibility = NaN<config_t>,
27 nlp_error = NaN<config_t>;
28 length_t iter_count = 0;
29 } results;
30
31 IpoptAdapter(const Problem &problem);
32 IpoptAdapter(Problem &&) = delete;
33
34 /// @name Functions required by Ipopt
35 /// @{
36
37 bool get_nlp_info(Index &n, Index &m, Index &nnz_jac_g, Index &nnz_h_lag,
38 IndexStyleEnum &index_style) override;
39
40 bool get_bounds_info(Index n, Number *x_l, Number *x_u, Index m,
41 Number *g_l, Number *g_u) override;
42
43 bool get_starting_point(Index n, bool init_x, Number *x, bool init_z,
44 Number *z_L, Number *z_U, Index m, bool init_lambda,
45 Number *lambda) override;
46
47 bool eval_f(Index n, const Number *x, bool new_x,
48 Number &obj_value) override;
49
50 bool eval_grad_f(Index n, const Number *x, bool new_x,
51 Number *grad_f) override;
52
53 bool eval_g(Index n, const Number *x, bool new_x, Index m,
54 Number *g) override;
55
56 bool eval_jac_g(Index n, const Number *x, bool new_x, Index m,
57 Index nele_jac, Index *iRow, Index *jCol,
58 Number *values) override;
59
60 bool eval_h(Index n, const Number *x, bool new_x, Number obj_factor,
61 Index m, const Number *lambda, bool new_lambda, Index nele_hess,
62 Index *iRow, Index *jCol, Number *values) override;
63
64 void finalize_solution(Ipopt::SolverReturn status, Index n, const Number *x,
65 const Number *z_L, const Number *z_U, Index m,
66 const Number *g, const Number *lambda,
67 Number obj_value, const Ipopt::IpoptData *ip_data,
68 Ipopt::IpoptCalculatedQuantities *ip_cq) override;
69
70 /// @}
71
72 private:
73 struct Sparsity {
75 indexvec inner_idx, outer_ptr;
76 } sparsity_J, sparsity_H;
77
78 static void set_sparsity(Index n, Index m, Index nele, Index *iRow,
79 Index *jCol, const Sparsity &sp);
80};
81
82} // namespace alpaqa
Based on https://coin-or.github.io/Ipopt/INTERFACES.html.
Ipopt::Number Number
const Problem & problem
IpoptAdapter(Problem &&)=delete
#define USING_ALPAQA_CONFIG(Conf)
Definition: config.hpp:54
typename Conf::indexvec indexvec
Definition: config.hpp:76
typename Conf::real_t real_t
Definition: config.hpp:63
typename Conf::length_t length_t
Definition: config.hpp:74
typename Conf::vec vec
Definition: config.hpp:64
Double-precision double configuration.
Definition: config.hpp:127