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 CASADI_CONIC_CPLEX_EXPORT 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 
87 
89  CplexMemory();
90 
92  ~CplexMemory();
93  };
94 
103  class CASADI_CONIC_CPLEX_EXPORT 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 
157 
160  casadi_int qp_method_;
162  std::string dump_filename_;
163  double tol_;
164  casadi_int dep_check_;
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 
178 
179  void serialize_body(SerializingStream &s) const override;
180 
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
Internal class.
Definition: conic_impl.hpp:44
'cplex' plugin for Conic
bool psd_support() const override
Can psd constraints be treated.
static const Options options_
Options.
void * alloc_mem() const override
Create memory block.
std::vector< double > sos_weights_
SDPToSOCPMem sdp_to_socp_mem_
SDP to SOCP conversion memory.
std::vector< char > sos_types_
void free_mem(void *mem) const override
Free memory block.
std::vector< casadi_int > sos_beg_
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize with type disambiguation.
static const std::string meta_doc
A documentation string.
static Conic * creator(const std::string &name, const std::map< std::string, Sparsity > &st)
Create a new QP Solver.
std::vector< int > sos_ind_
const char * plugin_name() const override
const Options & get_options() const override
Options.
bool integer_support() const override
Can discrete variables be treated.
std::vector< char > ctype_
std::string class_name() const override
Readable name of the internal class.
Dict opts_
All CPLEX options.
Helper class for Serialization.
Base class for FunctionInternal and LinsolInternal.
Helper class for Serialization.
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
std::vector< CPXDIM > socp_lind
casadi_int objsen
Nature of problem (always minimization)
std::vector< char > sense
Determines relation >,<, = in the linear constraints.
std::vector< CPXDIM > a_row
std::vector< int > rstat
Storage for basis info of slack variables.
std::vector< double > rhs
Right-hand side of constraints.
bool is_warm
Indicates if we have to warm-start.
std::vector< int > matcnt
Coefficients of matrix A (constraint Jacobian)
std::vector< CPXNNZ > socp_colind
CPXENVptr env
CPLEX environment.
std::vector< double > rngval
Range of constraints.
std::vector< int > cstat
Storage for basis info of primal variables.
std::vector< double > socp_lbound
std::vector< CPXNNZ > a_colind
std::vector< int > qmatcnt
Coefficients of matrix H (objective Hessian)
Options metadata for a class.
Definition: options.hpp:40