conic_impl.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_CONIC_IMPL_HPP
27 #define CASADI_CONIC_IMPL_HPP
28 
29 #include "conic.hpp"
30 #include "function_internal.hpp"
31 #include "plugin_interface.hpp"
32 #include "im.hpp"
33 
35 namespace casadi {
36 
37  struct CASADI_EXPORT ConicMemory : public FunctionMemory {
38  // Problem data structure
40 
41  };
42 
44  class CASADI_EXPORT Conic : public FunctionInternal, public PluginInterface<Conic> {
45  public:
46  // Memory structure
48 
49  // Constructor
50  Conic(const std::string& name, const std::map<std::string, Sparsity> &st);
51 
52  // Destructor
53  ~Conic() override = 0;
54 
56 
59  size_t get_n_in() override { return CONIC_NUM_IN;}
60  size_t get_n_out() override { return CONIC_NUM_OUT;}
62 
64 
67  Sparsity get_sparsity_in(casadi_int i) override;
68  Sparsity get_sparsity_out(casadi_int i) override;
70 
72 
75  std::string get_name_in(casadi_int i) override { return conic_in(i);}
76  std::string get_name_out(casadi_int i) override { return conic_out(i);}
78 
80 
83  static const Options options_;
84  const Options& get_options() const override { return options_;}
86 
88  int eval(const double** arg, double** res, casadi_int* iw, double* w, void* mem) const final;
89 
91  virtual int solve(const double** arg, double** res,
92  casadi_int* iw, double* w, void* mem) const = 0;
93 
94  // Initialize
95  void init(const Dict& opts) override;
96 
100  int init_mem(void* mem) const override;
101 
105  void set_work(void* mem, const double**& arg, double**& res,
106  casadi_int*& iw, double*& w) const override;
107 
109  virtual void check_inputs(const double* lbx, const double* ubx,
110  const double* lba, const double* uba) const;
111 
113  virtual void generateNativeCode(std::ostream& file) const;
114 
115  // Creator function for internal class
116  typedef Conic* (*Creator)(const std::string& name,
117  const std::map<std::string, Sparsity>& st);
118 
119  // No static functions exposed
120  struct Exposed{ };
121 
123  static std::map<std::string, Plugin> solvers_;
124 
126  static const std::string infix_;
127 
129  static std::string shortname() { return "conic";}
130 
134  bool is_a(const std::string& type, bool recursive) const override;
135 
139  double get_default_in(casadi_int ind) const override;
140 
142  virtual bool integer_support() const { return false;}
143 
145  virtual bool psd_support() const { return false;}
146 
148  Dict get_stats(void* mem) const override;
149 
153  void qp_codegen_body(CodeGenerator& g) const;
154 
155  protected:
157  std::vector<bool> discrete_;
158  std::vector<bool> equality_;
159  bool print_problem_;
160 
162  Sparsity H_, A_, Q_, P_;
163 
165  casadi_int nx_;
166 
168  casadi_int na_;
169 
171  casadi_int np_;
172 
174  struct SDPToSOCPMem {
175  // Block partition vector for SOCP (block i runs from r[i] to r[i+1])
176  std::vector<casadi_int> r;
177 
178  // Tranpose of A, and corresponding mapping
179  Sparsity AT;
180  std::vector<casadi_int> A_mapping;
181 
182  // Aggregate SOCP helper constraints (lhs)
183  IM map_Q;
184 
185  // Aggregate SOCP helper constraints (rhs)
186  std::vector<casadi_int> map_P;
187 
188  // Maximum size of ind/val vectors
189  casadi_int indval_size;
190  };
191 
193  void sdp_to_socp_init(SDPToSOCPMem& mem) const;
194 
195  void serialize(SerializingStream &s, const SDPToSOCPMem& m) const;
196  void deserialize(DeserializingStream &s, SDPToSOCPMem& m);
197 
198  public:
202  void serialize_body(SerializingStream &s) const override;
206  void serialize_type(SerializingStream &s) const override;
207 
211  std::string serialize_base_function() const override { return "Conic"; }
215  static ProtoFunction* deserialize(DeserializingStream& s);
216 
217  protected:
218 
222  explicit Conic(DeserializingStream& s);
223  private:
224  void set_qp_prob();
225  };
226 
227 
228 } // namespace casadi
230 #endif // CASADI_CONIC_IMPL_HPP
CASADI_EXPORT std::vector< std::string > conic_out()
Get QP solver output scheme of QP solvers.
CASADI_EXPORT std::vector< std::string > conic_in()
Get input scheme of QP solvers.
The casadi namespace.
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.
Matrix< casadi_int > IM
Definition: im_fwd.hpp:31