ccopt_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_CCOPT_INTERFACE_HPP
27 #define CASADI_CCOPT_INTERFACE_HPP
28 
29 //#include <casadi/interfaces/ccopt/casadi_nlpsol_ccopt_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 "ccopt_runtime.hpp"
37 }
38 
41 #define __attribute__((visibility("default")))
45 namespace casadi {
46 
47 struct MadmpecMemory : public NlpsolMemory {
48  // Problem data structure
50 };
51 
57 class MadmpecInterface : public Nlpsol {
58  public:
59  Sparsity jacg_sp_;
60  Sparsity hesslag_sp_;
61 
62  explicit MadmpecInterface(const std::string& name, const Function& nlp);
63  ~MadmpecInterface() override;
64 
65  // Get name of the plugin
66  const char* plugin_name() const override { return "ccopt";}
67 
68  // Get name of the class
69  std::string class_name() const override { return "MadmpecInterface";}
70 
72  static Nlpsol* creator(const std::string& name, const Function& nlp) {
73  return new MadmpecInterface(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 MadmpecMemory();}
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  Dict mpcc_opts_;
110 
112  std::vector<libmad_int> ind_cc1_;
113  std::vector<libmad_int> ind_cc2_;
114  std::vector<libmad_int> cctypes_;
115 
117  static const std::string meta_doc;
118 
119  // Options
120 
122  ConvexifyData convexify_data_;
123 
125  bool convexify_;
126 
127  void set_ccopt_prob();
128  void set_ccopt_prob(CodeGenerator& g) const;
129 
130  void codegen_options(CodeGenerator& g, const Dict& dict,
131  const std::string& field) const;
132 
134  void codegen_body(CodeGenerator& g) const override;
135 
137  void codegen_declarations(CodeGenerator& g) const override;
138 
140  void codegen_init_mem(CodeGenerator& g) const override;
141 
143  void codegen_free_mem(CodeGenerator& g) const override;
144 
146  std::string codegen_mem_type() const override { return "struct casadi_ccopt_data"; }
147 
149  bool codegen_needs_mem() const override { return true; }
150 
151  // /** \brief Serialize an object without type information */
152  void serialize_body(SerializingStream &s) const override;
153 
155  static ProtoFunction* deserialize(DeserializingStream& s) { return new MadmpecInterface(s); }
156 
157  protected:
159  explicit MadmpecInterface(DeserializingStream& s);
160 
161  private:
162  // Memory structure
164 
165  std::vector<libmad_int> nws_;
166  std::vector<libmad_int> ngs_;
167 };
168 
169 } // namespace casadi
171 
172 #endif // CASADI_CCOPT_INTERFACE_HPP
The casadi namespace.
Definition: archiver.hpp:32
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.