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 CASADI_NLPSOL_CCOPT_EXPORT __attribute__((visibility("default")))
45 namespace casadi {
46 
47 struct CASADI_NLPSOL_CCOPT_EXPORT MadmpecMemory : public NlpsolMemory {
48  // Problem data structure
50 };
51 
57 class CASADI_NLPSOL_CCOPT_EXPORT MadmpecInterface : public Nlpsol {
58  public:
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 
106 
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 
123 
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 
156 
157  protected:
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
Helper class for C code generation.
Helper class for Serialization.
Function object.
Definition: function.hpp:60
'ccopt' plugin for Nlpsol
bool exact_hessian_
Exact Hessian?
std::vector< libmad_int > cctypes_
ConvexifyData convexify_data_
Data for convexification.
Dict opts_
All CCOPT options.
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize into MX.
static Nlpsol * creator(const std::string &name, const Function &nlp)
Create a new NLP Solver.
const Options & get_options() const override
Options.
void * alloc_mem() const override
Create memory block.
std::vector< libmad_int > ind_cc1_
Complementarity.
const char * plugin_name() const override
static const Options options_
Options.
static const std::string meta_doc
A documentation string.
std::string codegen_mem_type() const override
Thread-local memory object type.
bool codegen_needs_mem() const override
Is thread-local memory object needed?
std::vector< libmad_int > ind_cc2_
std::string class_name() const override
Get type name.
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_ccopt_data< double > d
Integrator memory.
Definition: nlpsol_impl.hpp:40
Options metadata for a class.
Definition: options.hpp:40