clarabel_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 #ifndef CASADI_CLARABEL_INTERFACE_HPP
26 #define CASADI_CLARABEL_INTERFACE_HPP
27 
28 #include "casadi/core/conic_impl.hpp"
29 #include <casadi/interfaces/clarabel/casadi_conic_clarabel_export.h>
30 #include <Clarabel.h>
31 #include <string>
32 
33 namespace casadi {
34  #include "clarabel_runtime.hpp"
35 }
36 
47 
48 namespace casadi {
49 
50  struct ClarabelMemory : public ConicMemory {
51  // Problem data structure (Clarabel-specific)
53  };
54 
62  class ClarabelInterface : public Conic {
63  public:
65  static Conic* creator(const std::string& name,
66  const std::map<std::string, Sparsity>& st) {
67  return new ClarabelInterface(name, st);
68  }
69 
71  explicit ClarabelInterface(const std::string& name,
72  const std::map<std::string, Sparsity>& st);
73 
75  ~ClarabelInterface() override;
76 
78  const char* plugin_name() const override { return "clarabel"; }
79 
81  std::string class_name() const override { return "ClarabelInterface"; }
82 
84  static const Options options_;
85  const Options& get_options() const override { return options_; }
86 
87  void set_clarabel_prob();
88  void set_clarabel_prob(CodeGenerator& g) const;
89 
91  void codegen_body(CodeGenerator& g) const override;
92 
94  void codegen_init_mem(CodeGenerator& g) const override;
95 
97  void codegen_free_mem(CodeGenerator& g) const override;
98 
100  std::string codegen_mem_type() const override { return "struct casadi_clarabel_data"; }
101 
103  bool codegen_needs_mem() const override { return true; }
104 
106  void init(const Dict& opts) override;
107 
109  void init_dependent();
110 
112  void* alloc_mem() const override { return new ClarabelMemory(); }
113 
115  int init_mem(void* mem) const override;
116 
118  void free_mem(void* mem) const override;
119 
121  void set_work(void* mem, const double**& arg, double**& res,
122  casadi_int*& iw, double*& w) const override;
123 
125  Dict get_stats(void* mem) const override;
126 
128  int solve(const double** arg, double** res,
129  casadi_int* iw, double* w, void* mem) const override;
130 
132  static const std::string meta_doc;
133 
135  Dict opts_;
136 
137  void serialize_body(SerializingStream &s) const override;
138 
140  static ProtoFunction* deserialize(DeserializingStream& s) { return new ClarabelInterface(s); }
141 
143  bool integer_support() const override { return false; }
144 
145  protected:
147  explicit ClarabelInterface(DeserializingStream& s);
148 
149  private:
150  // Problem data (constructed from the CasADi QP data)
152 
153  // Sparsity information for the quadratic cost (P) and constraints (A)
154  std::vector<int> colindp_, rowp_;
155  std::vector<int> colinda_, rowa_;
156 
157  // The underlying QP data from CasADi
160  };
161 } // end namespace casadi
163 #endif // CASADI_CLARABEL_INTERFACE_HPP
The casadi namespace.
Definition: archiver.hpp:32
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.