highs_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_HIGHS_INTERFACE_HPP
26 #define CASADI_HIGHS_INTERFACE_HPP
27 
28 #include "casadi/core/conic_impl.hpp"
29 #include <casadi/interfaces/highs/casadi_conic_highs_export.h>
30 
31 #include <Highs.h>
32 #include "interfaces/highs_c_api.h"
33 #include <string>
34 
35 namespace casadi {
36  #include "highs_runtime.hpp"
37 }
38 
52 
53 namespace casadi {
54 
55  struct HighsMemory : public ConicMemory {
56  // Problem data structure
58 
59  };
60 
70  class HighsInterface : public Conic {
71  public:
73  static Conic* creator(const std::string& name,
74  const std::map<std::string, Sparsity>& st) {
75  return new HighsInterface(name, st);
76  }
77 
79  explicit HighsInterface(const std::string& name,
80  const std::map<std::string, Sparsity>& st);
81 
83  ~HighsInterface() override;
84 
85  // Get name of the plugin
86  const char* plugin_name() const override { return "highs";}
87 
88  // Get name of the class
89  std::string class_name() const override { return "HighsInterface";}
90 
92 
93  static const Options options_;
94  const Options& get_options() const override { return options_;}
96 
97  void set_highs_prob();
98  void set_highs_prob(CodeGenerator& g) const;
99 
101  void codegen_body(CodeGenerator& g) const override;
102 
104  void codegen_init_mem(CodeGenerator& g) const override;
105 
107  void codegen_free_mem(CodeGenerator& g) const override;
108 
110  std::string codegen_mem_type() const override { return "struct casadi_highs_data"; }
111 
112  // Initialize the solver
113  void init(const Dict& opts) override;
114 
115  // Initialize dependant read-only members of class
116  void init_dependent();
117 
119  void* alloc_mem() const override { return new HighsMemory();}
120 
122  int init_mem(void* mem) const override;
123 
125  void free_mem(void *mem) const override;
126 
128  void set_work(void* mem, const double**& arg, double**& res,
129  casadi_int*& iw, double*& w) const override;
130 
132  Dict get_stats(void* mem) const override;
133 
134  // Solve the QP
135  int solve(const double** arg, double** res,
136  casadi_int* iw, double* w, void* mem) const override;
137 
139  static const std::string meta_doc;
140 
142  Dict opts_;
143 
144  void serialize_body(SerializingStream &s) const override;
145 
147  static ProtoFunction* deserialize(DeserializingStream& s) { return new HighsInterface(s); }
148 
150  bool integer_support() const override { return true; }
151 
152  protected:
154  explicit HighsInterface(DeserializingStream& s);
155 
156  private:
157 
158  // Memory structure
160 
161  std::vector<int> colinda_, rowa_;
162  std::vector<int> colindh_, rowh_;
163  std::vector<int> integrality_;
164 
165  // Object to store options; distinct from actual solver object
166  Highs highs_;
167 
168  };
169 } // end namespace casadi
171 #endif // CASADI_HIGHS_INTERFACE_HPP
The casadi namespace.
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.