cplex_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_CPLEX_INTERFACE_HPP
26 #define CASADI_CPLEX_INTERFACE_HPP
27 
28 #include "casadi/core/conic_impl.hpp"
29 #include <casadi/interfaces/cplex/casadi_conic_cplex_export.h>
30 #include "ilcplex/cplexx.h"
31 
32 #include <string>
33 
44 
45 namespace casadi {
46 
47  struct CplexMemory : public ConicMemory {
49  bool is_warm;
50 
52  casadi_int objsen;
53 
55  std::vector<char> sense;
56 
58  std::vector<int> matcnt;
59 
61  std::vector<double> rhs;
62 
64  std::vector<double> rngval;
65 
67  std::vector<int> qmatcnt;
68 
70  std::vector<int> cstat;
71 
73  std::vector<int> rstat;
74 
76  CPXENVptr env;
77  CPXLPptr lp;
78 
79  std::vector<CPXDIM> a_row, h_row;
80  std::vector<CPXNNZ> a_colind, h_colind;
81 
82  std::vector<CPXNNZ> socp_colind;
83  std::vector<CPXDIM> socp_qind, socp_lind, socp_row;
84  std::vector<double> socp_qval, socp_lbound, socp_lval, socp_lbx;
85 
86  int return_status;
87 
89  CplexMemory();
90 
92  ~CplexMemory();
93  };
94 
103  class CplexInterface : public Conic {
104  public:
106  static Conic* creator(const std::string& name,
107  const std::map<std::string, Sparsity>& st) {
108  return new CplexInterface(name, st);
109  }
110 
112  explicit CplexInterface(const std::string& name,
113  const std::map<std::string, Sparsity>& st);
114 
116  ~CplexInterface() override;
117 
118  // Get name of the plugin
119  const char* plugin_name() const override { return "cplex";}
120 
121  // Get name of the class
122  std::string class_name() const override { return "CplexInterface";}
123 
125 
126  static const Options options_;
127  const Options& get_options() const override { return options_;}
129 
130  // Initialize the solver
131  void init(const Dict& opts) override;
132 
134  void* alloc_mem() const override { return new CplexMemory();}
135 
137  int init_mem(void* mem) const override;
138 
140  void free_mem(void *mem) const override { delete static_cast<CplexMemory*>(mem);}
141 
142  // Solve the QP
143  int solve(const double** arg, double** res,
144  casadi_int* iw, double* w, void* mem) const override;
145 
147  bool integer_support() const override { return true;}
148 
150  bool psd_support() const override { return true;}
151 
153  Dict get_stats(void* mem) const override;
154 
156  Dict opts_;
157 
160  casadi_int qp_method_;
161  bool dump_to_file_;
162  std::string dump_filename_;
163  double tol_;
164  casadi_int dep_check_;
165  bool warm_start_;
166  bool mip_start_;
168 
169  // Are we solving a mixed-integer problem?
170  bool mip_;
171  std::vector<char> ctype_;
172 
174  static const std::string meta_doc;
175 
177  SDPToSOCPMem sdp_to_socp_mem_;
178 
179  void serialize_body(SerializingStream &s) const override;
180 
182  static ProtoFunction* deserialize(DeserializingStream& s) { return new CplexInterface(s); }
183 
184  // SOS structure
185  std::vector< double > sos_weights_;
186  std::vector<casadi_int> sos_beg_;
187  std::vector<int> sos_ind_;
188  std::vector<char> sos_types_;
189 
190  protected:
192  explicit CplexInterface(DeserializingStream& s);
193  };
194 } // end namespace casadi
196 #endif // CASADI_CPLEX_INTERFACE_HPP
The casadi namespace.
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.