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 "madnlp_c.h"
34 
35 extern "C" {
36  int init_julia(int, char**);
37  void shutdown_julia(int);
38 }
39 
40 
41 namespace casadi {
42  #include "madnlp_runtime.hpp"
43 }
44 
47 #define CASADI_NLPSOL_MADNLP_EXPORT __attribute__((visibility("default")))
51 namespace casadi {
52 
53 struct CASADI_NLPSOL_MADNLP_EXPORT MadnlpMemory : public NlpsolMemory {
54  // Problem data structure
56 };
57 
63 class CASADI_NLPSOL_MADNLP_EXPORT MadnlpInterface : public Nlpsol {
64  public:
68 
69  explicit MadnlpInterface(const std::string& name, const Function& nlp);
70  ~MadnlpInterface() override;
71 
72  // Get name of the plugin
73  const char* plugin_name() const override { return "madnlp";}
74 
75  // Get name of the class
76  std::string class_name() const override { return "MadnlpInterface";}
77 
79  static Nlpsol* creator(const std::string& name, const Function& nlp) {
80  return new MadnlpInterface(name, nlp);
81  }
82 
84 
85  static const Options options_;
86  const Options& get_options() const override { return options_;}
88 
89  // Initialize the solver
90  void init(const Dict& opts) override;
91 
93  void* alloc_mem() const override { return new MadnlpMemory();}
94 
96  int init_mem(void* mem) const override;
97 
99  void free_mem(void *mem) const override;
100 
102  Dict get_stats(void* mem) const override;
103 
105  void set_work(void* mem, const double**& arg, double**& res,
106  casadi_int*& iw, double*& w) const override;
107 
108  // Solve the NLP
109  int solve(void* mem) const override;
110 
113 
116 
118  static const std::string meta_doc;
119 
120  // Options
121 
124 
127 
128  void set_madnlp_prob();
129  void set_madnlp_prob(CodeGenerator& g) const;
130 
132  void codegen_body(CodeGenerator& g) const override;
133 
135  void codegen_declarations(CodeGenerator& g) const override;
136 
138  void codegen_init_mem(CodeGenerator& g) const override;
139 
141  void codegen_free_mem(CodeGenerator& g) const override;
142 
144  std::string codegen_mem_type() const override { return "struct casadi_madnlp_data"; }
145 
147  void serialize_body(SerializingStream &s) const override;
148 
151 
152  protected:
155 
156  private:
157  // Memory structure
159 
160  std::vector<madnlp_int> nws_;
161  std::vector<madnlp_int> ngs_;
162 
163  std::vector<madnlp_int> nzj_i_;
164  std::vector<madnlp_int> nzj_j_;
165  std::vector<madnlp_int> nzh_i_;
166  std::vector<madnlp_int> nzh_j_;
167 };
168 
169 } // namespace casadi
171 
172 #endif // CASADI_MADNLP_INTERFACE_HPP
Helper class for C code generation.
Helper class for Serialization.
Function object.
Definition: function.hpp:60
'madnlp' plugin for Nlpsol
const Options & get_options() const override
Options.
static const Options options_
Options.
std::string class_name() const override
Get type name.
void * alloc_mem() const override
Create memory block.
static Nlpsol * creator(const std::string &name, const Function &nlp)
Create a new NLP Solver.
std::string codegen_mem_type() const override
Thread-local memory object type.
static const std::string meta_doc
A documentation string.
const char * plugin_name() const override
bool exact_hessian_
Exact Hessian?
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize into MX.
Dict opts_
All MADNLP options.
ConvexifyData convexify_data_
Data for convexification.
NLP solver storage class.
Definition: nlpsol_impl.hpp:59
Base class for FunctionInternal and LinsolInternal.
Helper class for Serialization.
General sparsity class.
Definition: sparsity.hpp:106
The casadi namespace.
Definition: archiver.cpp:28
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.
casadi_madnlp_data< double > d
Integrator memory.
Definition: nlpsol_impl.hpp:40
Options metadata for a class.
Definition: options.hpp:40