superscs_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_SUPERSCS_INTERFACE_HPP
27 #define CASADI_SUPERSCS_INTERFACE_HPP
28 
29 #include "casadi/core/conic_impl.hpp"
30 #include <casadi/interfaces/superscs/casadi_conic_superscs_export.h>
31 
32 #include <scs_parser.h>
33 
47 namespace casadi {
48 
49  struct CASADI_CONIC_SUPERSCS_EXPORT SuperscsMemory : public ConicMemory {
50 
51  ScsSolution* sol;
52  ScsData data;
53 
54  ScsInfo * info;
55  ScsCone cone;
56  ScsAMatrix A;
57  ScsSettings settings;
58 
60 
61  std::vector<casadi_int> at_colind, at_row, q;
62  std::vector<double> ldl_d, ldl_l, ldl_w, F_res, g;
63 
66 
68  ~SuperscsMemory();
69  };
70 
77  class CASADI_CONIC_SUPERSCS_EXPORT SuperscsInterface : public Conic {
78  public:
80  explicit SuperscsInterface(const std::string& name,
81  const std::map<std::string, Sparsity>& st);
82 
84  static Conic* creator(const std::string& name,
85  const std::map<std::string, Sparsity>& st) {
86  return new SuperscsInterface(name, st);
87  }
88 
90  ~SuperscsInterface() override;
91 
92  // Get name of the plugin
93  const char* plugin_name() const override { return "superscs";}
94 
95  // Get name of the class
96  std::string class_name() const override { return "SuperscsInterface";}
97 
99 
100  static const Options options_;
101  const Options& get_options() const override { return options_;}
103 
105  void init(const Dict& opts) override;
106 
108  void* alloc_mem() const override { return new SuperscsMemory();}
109 
111  int init_mem(void* mem) const override;
112 
114  void free_mem(void *mem) const override { delete static_cast<SuperscsMemory*>(mem);}
115 
117  int solve(const double** arg, double** res,
118  casadi_int* iw, double* w, void* mem) const override;
119 
121  bool integer_support() const override { return true;}
122 
124  bool psd_support() const override { return true;}
125 
127  static const std::string meta_doc;
128 
130  Dict get_stats(void* mem) const override;
131 
134 
137 
139 
140  std::vector<casadi_int> lookup_;
141 
142  // Symbolic of H
143  std::vector<casadi_int> Hp_;
145 
147 
148  ScsSettings settings_;
149 
150  // Socp perturbation
151  std::vector<casadi_int> perturb_;
152 
153  void serialize_body(SerializingStream &s) const override;
154 
157 
158  protected:
161  };
162 
163 } // namespace casadi
164 
166 #endif // CASADI_SUPERSCS_INTERFACE_HPP
Internal class.
Definition: conic_impl.hpp:44
Helper class for Serialization.
Function object.
Definition: function.hpp:60
Base class for FunctionInternal and LinsolInternal.
Helper class for Serialization.
General sparsity class.
Definition: sparsity.hpp:106
'superscs' plugin for Conic
void free_mem(void *mem) const override
Free memory block.
std::vector< casadi_int > lookup_
const Options & get_options() const override
Options.
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize with type disambiguation.
static const std::string meta_doc
A documentation string.
const char * plugin_name() const override
bool integer_support() const override
Can discrete variables be treated.
std::string class_name() const override
Readable name of the internal class.
void * alloc_mem() const override
Create memory block.
static Conic * creator(const std::string &name, const std::map< std::string, Sparsity > &st)
Create a new QP Solver.
std::vector< casadi_int > perturb_
bool psd_support() const override
Can psd constraints be treated.
SDPToSOCPMem sdp_to_socp_mem_
SDP to SOCP conversion memory.
Dict opts_
Superscs options.
static const Options options_
Options.
std::vector< casadi_int > Hp_
The casadi namespace.
Definition: archiver.cpp:28
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.
SDP to SOCP conversion memory.
Definition: conic_impl.hpp:178
Options metadata for a class.
Definition: options.hpp:40
std::vector< double > F_res
std::vector< casadi_int > at_colind