alpaqa pantr
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, infeasibility, nlp_error;
28 } results;
29
30 IpoptAdapter(const Problem &problem);
31 IpoptAdapter(Problem &&) = delete;
32
33 /// @name Functions required by Ipopt
34 /// @{
35
36 bool get_nlp_info(Index &n, Index &m, Index &nnz_jac_g, Index &nnz_h_lag,
37 IndexStyleEnum &index_style) override;
38
39 bool get_bounds_info(Index n, Number *x_l, Number *x_u, Index m,
40 Number *g_l, Number *g_u) override;
41
42 bool get_starting_point(Index n, bool init_x, Number *x, bool init_z,
43 Number *z_L, Number *z_U, Index m, bool init_lambda,
44 Number *lambda) override;
45
46 bool eval_f(Index n, const Number *x, bool new_x,
47 Number &obj_value) override;
48
49 bool eval_grad_f(Index n, const Number *x, bool new_x,
50 Number *grad_f) override;
51
52 bool eval_g(Index n, const Number *x, bool new_x, Index m,
53 Number *g) override;
54
55 bool eval_jac_g(Index n, const Number *x, bool new_x, Index m,
56 Index nele_jac, Index *iRow, Index *jCol,
57 Number *values) override;
58
59 bool eval_h(Index n, const Number *x, bool new_x, Number obj_factor,
60 Index m, const Number *lambda, bool new_lambda, Index nele_hess,
61 Index *iRow, Index *jCol, Number *values) override;
62
63 void finalize_solution(Ipopt::SolverReturn status, Index n, const Number *x,
64 const Number *z_L, const Number *z_U, Index m,
65 const Number *g, const Number *lambda,
66 Number obj_value, const Ipopt::IpoptData *ip_data,
67 Ipopt::IpoptCalculatedQuantities *ip_cq) override;
68
69 /// @}
70
71 private:
72 struct Sparsity {
73 indexvec inner_idx, outer_ptr;
74 } sparsity_J, sparsity_H;
75
76 static void set_sparsity(Index n, Index m, Index nele, Index *iRow,
77 Index *jCol, const Sparsity &sp);
78};
79
80} // 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:42
typename Conf::indexvec indexvec
Definition: config.hpp:64
typename Conf::real_t real_t
Definition: config.hpp:51
typename Conf::length_t length_t
Definition: config.hpp:62
typename Conf::vec vec
Definition: config.hpp:52