1#ifndef ZONOOPT_SCIP_API_HPP_
2#define ZONOOPT_SCIP_API_HPP_
16 #define ZONOOPT_SCIP_GET_SYMBOL GetProcAddress
20 #define ZONOOPT_SCIP_GET_SYMBOL dlsym
36 static constexpr int SCIP_OKAY = 1;
39 static constexpr int SCIP_VARTYPE_BINARY = 0;
40 static constexpr int SCIP_VARTYPE_INTEGER = 1;
41 static constexpr int SCIP_VARTYPE_IMPLINT = 2;
42 static constexpr int SCIP_VARTYPE_CONTINUOUS = 3;
48 static constexpr int SCIP_STATUS_OPTIMAL = 1;
49 static constexpr int SCIP_STATUS_INFEASIBLE = 2;
50 static constexpr int SCIP_STATUS_UNBOUNDED = 3;
51 static constexpr int SCIP_STATUS_INFORUNBD = 4;
59 static constexpr int MIN_SCIP_MAJOR = 10;
62 using ScipPtr =
void*;
64 using ConsPtr =
void*;
66 using SparseSolPtr =
void*;
68 using LibPtr = std::shared_ptr<void>;
71 typedef int (*SCIPcreate_t)(ScipPtr*);
72 typedef int (*SCIPfree_t)(ScipPtr*);
73 typedef int (*SCIPincludeDefaultPlugins_t)(ScipPtr);
74 typedef int (*SCIPcreateProbBasic_t)(ScipPtr,
const char*);
75 typedef int (*SCIPfreeProb_t)(ScipPtr);
76 typedef int (*SCIPsetMessagehdlrQuiet_t)(ScipPtr,
unsigned int);
77 typedef double (*SCIPinfinity_t)(ScipPtr);
79 typedef int (*SCIPcreateVarBasic_t)(ScipPtr, VarPtr*,
const char*, double, double, double, int);
80 typedef int (*SCIPaddVar_t)(ScipPtr, VarPtr);
81 typedef int (*SCIPreleaseVar_t)(ScipPtr, VarPtr*);
82 typedef int (*SCIPchgVarType_t)(ScipPtr, VarPtr, int,
unsigned int*);
84 typedef int (*SCIPcreateConsBasicLinear_t)(ScipPtr, ConsPtr*,
const char*, int, VarPtr*,
double*, double, double);
85 typedef int (*SCIPcreateConsBasicQuadraticNonlinear_t)(ScipPtr, ConsPtr*,
const char*,
86 int, VarPtr*,
double*,
87 int, VarPtr*, VarPtr*,
double*,
89 typedef int (*SCIPaddCons_t)(ScipPtr, ConsPtr);
90 typedef int (*SCIPreleaseCons_t)(ScipPtr, ConsPtr*);
92 typedef int (*SCIPsolve_t)(ScipPtr);
93 typedef int (*SCIPfreeTransform_t)(ScipPtr);
94 typedef long long (*SCIPgetNTotalNodes_t)(ScipPtr);
95 typedef double (*SCIPgetGap_t)(ScipPtr);
96 typedef double (*SCIPgetDualbound_t)(ScipPtr);
97 typedef int (*SCIPgetStatus_t)(ScipPtr);
98 typedef SolPtr (*SCIPgetBestSol_t)(ScipPtr);
99 typedef int (*SCIPgetNSols_t)(ScipPtr);
100 typedef SolPtr*(*SCIPgetSols_t)(ScipPtr);
101 typedef double (*SCIPgetSolVal_t)(ScipPtr, SolPtr, VarPtr);
102 typedef double (*SCIPgetSolOrigObj_t)(ScipPtr, SolPtr);
103 typedef double (*SCIPgetSolvingTime_t)(ScipPtr);
105 typedef int (*SCIPsetBoolParam_t)(ScipPtr,
const char*,
unsigned int);
106 typedef int (*SCIPsetIntParam_t)(ScipPtr,
const char*, int);
107 typedef int (*SCIPsetLongintParam_t)(ScipPtr,
const char*,
long long);
108 typedef int (*SCIPsetRealParam_t)(ScipPtr,
const char*, double);
109 typedef int (*SCIPsetCharParam_t)(ScipPtr,
const char*, char);
110 typedef int (*SCIPsetStringParam_t)(ScipPtr,
const char*,
const char*);
112 typedef int (*SCIPmajorVersion_t)();
113 typedef int (*SCIPminorVersion_t)();
114 typedef int (*SCIPtechVersion_t)();
120 typedef int (*SCIPcount_t)(ScipPtr);
121 typedef void (*SCIPgetCountedSparseSols_t)(ScipPtr, VarPtr**,
int*, SparseSolPtr**,
int*);
122 typedef long long* (*SCIPsparseSolGetLbs_t)(SparseSolPtr);
123 typedef int (*SCIPsparseSolGetNVars_t)(SparseSolPtr);
126 SCIPcreate_t SCIPcreate =
nullptr;
127 SCIPfree_t SCIPfree =
nullptr;
128 SCIPincludeDefaultPlugins_t SCIPincludeDefaultPlugins =
nullptr;
129 SCIPcreateProbBasic_t SCIPcreateProbBasic =
nullptr;
130 SCIPfreeProb_t SCIPfreeProb =
nullptr;
131 SCIPsetMessagehdlrQuiet_t SCIPsetMessagehdlrQuiet =
nullptr;
132 SCIPinfinity_t SCIPinfinity =
nullptr;
134 SCIPcreateVarBasic_t SCIPcreateVarBasic =
nullptr;
135 SCIPaddVar_t SCIPaddVar =
nullptr;
136 SCIPreleaseVar_t SCIPreleaseVar =
nullptr;
137 SCIPchgVarType_t SCIPchgVarType =
nullptr;
139 SCIPcreateConsBasicLinear_t SCIPcreateConsBasicLinear =
nullptr;
140 SCIPcreateConsBasicQuadraticNonlinear_t SCIPcreateConsBasicQuadraticNonlinear =
nullptr;
141 SCIPaddCons_t SCIPaddCons =
nullptr;
142 SCIPreleaseCons_t SCIPreleaseCons =
nullptr;
144 SCIPsolve_t SCIPsolve =
nullptr;
145 SCIPfreeTransform_t SCIPfreeTransform =
nullptr;
146 SCIPgetNTotalNodes_t SCIPgetNTotalNodes =
nullptr;
147 SCIPgetGap_t SCIPgetGap =
nullptr;
148 SCIPgetDualbound_t SCIPgetDualbound =
nullptr;
149 SCIPgetStatus_t SCIPgetStatus =
nullptr;
150 SCIPgetBestSol_t SCIPgetBestSol =
nullptr;
151 SCIPgetNSols_t SCIPgetNSols =
nullptr;
152 SCIPgetSols_t SCIPgetSols =
nullptr;
153 SCIPgetSolVal_t SCIPgetSolVal =
nullptr;
154 SCIPgetSolOrigObj_t SCIPgetSolOrigObj =
nullptr;
155 SCIPgetSolvingTime_t SCIPgetSolvingTime =
nullptr;
157 SCIPsetBoolParam_t SCIPsetBoolParam =
nullptr;
158 SCIPsetIntParam_t SCIPsetIntParam =
nullptr;
159 SCIPsetLongintParam_t SCIPsetLongintParam =
nullptr;
160 SCIPsetRealParam_t SCIPsetRealParam =
nullptr;
161 SCIPsetCharParam_t SCIPsetCharParam =
nullptr;
162 SCIPsetStringParam_t SCIPsetStringParam =
nullptr;
164 SCIPmajorVersion_t SCIPmajorVersion =
nullptr;
165 SCIPminorVersion_t SCIPminorVersion =
nullptr;
166 SCIPtechVersion_t SCIPtechVersion =
nullptr;
168 SCIPcount_t SCIPcount =
nullptr;
169 SCIPgetCountedSparseSols_t SCIPgetCountedSparseSols =
nullptr;
170 SCIPsparseSolGetLbs_t SCIPsparseSolGetLbs =
nullptr;
171 SCIPsparseSolGetNVars_t SCIPsparseSolGetNVars =
nullptr;
174 static SCIPApi& instance();
177 bool is_available()
const {
return _lib_ptr !=
nullptr; }
181 const std::string& unavailable_reason()
const {
return _unavailable_reason; }
193 Scip(ScipPtr p, LibPtr lib);
195 Scip(
const Scip&) =
delete;
196 Scip& operator=(
const Scip&) =
delete;
197 Scip(Scip&& other)
noexcept;
198 Scip& operator=(Scip&& other)
noexcept;
200 ScipPtr get()
const {
return _ptr; }
201 explicit operator bool()
const {
return _ptr !=
nullptr; }
204 ScipPtr _ptr =
nullptr;
214 std::string _unavailable_reason;
216 ~SCIPApi() =
default;
217 SCIPApi(
const SCIPApi&) =
delete;
218 SCIPApi& operator=(
const SCIPApi&) =
delete;
221 ZonoOptScipLibHandle load_library_from_path(
const std::string& path,
const std::vector<std::string>& names);
void * ZonoOptScipLibHandle
Definition SCIPApi.hpp:19
Definition ZonoOpt.hpp:58