madnlp_interface.hpp
1 /*
2  * This file is part of CasADi.
3  *
4  * CasADi -- A symbolic framework for dynamic optimization.
5  * Copyright (C) 2010-2023 Joel Andersson, Joris Gillis, Moritz Diehl,
6  * KU Leuven. All rights reserved.
7  * Copyright (C) 2011-2014 Greg Horn
8  *
9  * CasADi is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 3 of the License, or (at your option) any later version.
13  *
14  * CasADi is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with CasADi; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  *
23  */
24 
25 
26 #ifndef CASADI_MADNLP_INTERFACE_HPP
27 #define CASADI_MADNLP_INTERFACE_HPP
28 
29 //#include <casadi/interfaces/madnlp/casadi_nlpsol_madnlp_export.h>
30 #include <iostream>
31 #include "casadi/core/nlpsol_impl.hpp"
32 #include "casadi/core/timing.hpp"
33 #include <libMad.h>
34 
35 namespace casadi {
36  #include "madnlp_runtime.hpp"
37 }
38 
41 #define __attribute__((visibility("default")))
45 namespace casadi {
46 
47 struct MadnlpMemory : public NlpsolMemory {
48  // Problem data structure
50 };
51 
57 class MadnlpInterface : public Nlpsol {
58  public:
59  Sparsity jacg_sp_;
60  Sparsity hesslag_sp_;
61 
62  explicit MadnlpInterface(const std::string& name, const Function& nlp);
63  ~MadnlpInterface() override;
64 
65  // Get name of the plugin
66  const char* plugin_name() const override { return "madnlp";}
67 
68  // Get name of the class
69  std::string class_name() const override { return "MadnlpInterface";}
70 
72  static Nlpsol* creator(const std::string& name, const Function& nlp) {
73  return new MadnlpInterface(name, nlp);
74  }
75 
77 
78  static const Options options_;
79  const Options& get_options() const override { return options_;}
81 
82  // Initialize the solver
83  void init(const Dict& opts) override;
84 
86  void* alloc_mem() const override { return new MadnlpMemory();}
87 
89  int init_mem(void* mem) const override;
90 
92  void free_mem(void *mem) const override;
93 
95  Dict get_stats(void* mem) const override;
96 
98  void set_work(void* mem, const double**& arg, double**& res,
99  casadi_int*& iw, double*& w) const override;
100 
101  // Solve the NLP
102  int solve(void* mem) const override;
103 
105  bool exact_hessian_;
106 
108  Dict opts_;
109 
111  static const std::string meta_doc;
112 
113  // Options
114 
116  ConvexifyData convexify_data_;
117 
119  bool convexify_;
120 
121  void set_madnlp_prob();
122  void set_madnlp_prob(CodeGenerator& g) const;
123 
125  void codegen_body(CodeGenerator& g) const override;
126 
128  void codegen_declarations(CodeGenerator& g) const override;
129 
131  void codegen_init_mem(CodeGenerator& g) const override;
132 
134  void codegen_free_mem(CodeGenerator& g) const override;
135 
137  std::string codegen_mem_type() const override { return "struct casadi_madnlp_data"; }
138 
140  bool codegen_needs_mem() const override { return true; }
141 
142  // /** \brief Serialize an object without type information */
143  void serialize_body(SerializingStream &s) const override;
144 
146  static ProtoFunction* deserialize(DeserializingStream& s) { return new MadnlpInterface(s); }
147 
148  protected:
150  explicit MadnlpInterface(DeserializingStream& s);
151 
152  private:
153  // Memory structure
155 
156  std::vector<libmad_int> nws_;
157  std::vector<libmad_int> ngs_;
158 
159  std::vector<libmad_int> nzj_i_;
160  std::vector<libmad_int> nzj_j_;
161  std::vector<libmad_int> nzh_i_;
162  std::vector<libmad_int> nzh_j_;
163 };
164 
165 } // namespace casadi
167 
168 #endif // CASADI_MADNLP_INTERFACE_HPP
The casadi namespace.
Definition: archiver.hpp:32
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.