mosek_interface.hpp
1 /*
2  * This file is part of CasADi.
3  *
4  * CasADi -- A symbolic framework for dynamic optimization.
5  * Copyright (C) 2010-2026 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 #ifndef CASADI_MOSEK_INTERFACE_HPP
26 #define CASADI_MOSEK_INTERFACE_HPP
27 
28 #include "casadi/core/conic_impl.hpp"
29 #include <casadi/interfaces/mosek/casadi_conic_mosek_export.h>
30 
31 #include <mosek.h>
32 #include <string>
33 
34 namespace casadi {
35  #include "mosek_runtime.hpp"
36 }
37 
52 
53 namespace casadi {
54 
55  struct MosekMemory : public ConicMemory {
56  // Problem data structure
58  };
59 
68  class MosekInterface : public Conic {
69  public:
71  static Conic* creator(const std::string& name,
72  const std::map<std::string, Sparsity>& st) {
73  return new MosekInterface(name, st);
74  }
75 
77  explicit MosekInterface(const std::string& name,
78  const std::map<std::string, Sparsity>& st);
79 
81  ~MosekInterface() override;
82 
83  // Get name of the plugin
84  const char* plugin_name() const override { return "mosek";}
85 
86  // Get name of the class
87  std::string class_name() const override { return "MosekInterface";}
88 
90 
91  static const Options options_;
92  const Options& get_options() const override { return options_;}
94 
95  void set_mosek_prob();
96  void set_mosek_prob(CodeGenerator& g) const;
97 
99  void codegen_body(CodeGenerator& g) const override;
100 
102  void codegen_init_mem(CodeGenerator& g) const override;
103 
105  void codegen_free_mem(CodeGenerator& g) const override;
106 
108  std::string codegen_mem_type() const override { return "struct casadi_mosek_data"; }
109 
111  bool codegen_needs_mem() const override { return true; }
112 
113  // Initialize the solver
114  void init(const Dict& opts) override;
115 
116  // Initialize dependant read-only members of class
117  void init_dependent();
118 
120  void* alloc_mem() const override { return new MosekMemory();}
121 
123  int init_mem(void* mem) const override;
124 
126  void free_mem(void *mem) const override;
127 
129  void set_work(void* mem, const double**& arg, double**& res,
130  casadi_int*& iw, double*& w) const override;
131 
133  Dict get_stats(void* mem) const override;
134 
135  // Solve the QP
136  int solve(const double** arg, double** res,
137  casadi_int* iw, double* w, void* mem) const override;
138 
140  static const std::string meta_doc;
141 
143  Dict opts_;
144 
145  void serialize_body(SerializingStream &s) const override;
146 
148  static ProtoFunction* deserialize(DeserializingStream& s) { return new MosekInterface(s); }
149 
151  bool integer_support() const override { return true; }
152 
154  bool psd_support() const override { return true; }
155 
156  protected:
158  explicit MosekInterface(DeserializingStream& s);
159 
160  private:
161 
162  // Memory structure
164 
165  // Linear constraint matrix in CSC form (as int, since Mosek takes int)
166  std::vector<int> colinda_, rowa_;
167 
168  // Lower-triangular triplet form of the symmetric Hessian H_.
169  // qobj_nz_idx_[k] gives the H_ nz index for the k-th triplet.
170  std::vector<int> qobj_row_, qobj_col_;
171  std::vector<int> qobj_nz_idx_;
172 
173  // Per-column type ('I' for integer/discrete, 'C' for continuous).
174  // Empty if no discrete variables.
175  std::vector<char> coltype_;
176 
177  // SOCP support: precomputed mapping between CasADi's Q/P input pair and
178  // per-cone constraint blocks. Populated when Q_.nnz() > 0.
179  bool has_socp_;
181  // Backing storage for socp_ (must outlive socp_)
182  std::vector<casadi_int> socp_r_;
183  std::vector<casadi_int> socp_mq_colind_, socp_mq_row_, socp_mq_data_;
184  std::vector<casadi_int> socp_map_P_;
185 
186  // Build socp_ from the result of Conic::sdp_to_socp_init
187  void build_socp_config();
188  };
189 } // end namespace casadi
191 #endif // CASADI_MOSEK_INTERFACE_HPP
The casadi namespace.
Definition: archiver.hpp:32
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.