19#include "absl/flags/flag.h"
20#include "absl/status/status.h"
21#include "absl/status/statusor.h"
22#include "absl/strings/match.h"
23#include "absl/strings/str_cat.h"
24#include "absl/strings/str_format.h"
25#include "absl/strings/str_join.h"
26#include "absl/synchronization/mutex.h"
36 LOG(WARNING) <<
status.status();
49std::function<int(
GRBenv**,
const char*,
const char*,
const char*,
int,
54std::function<int(
GRBmodel*
model,
const char* attrname,
int* valueP)>
56std::function<int(
GRBmodel*
model,
const char* attrname,
int newvalue)>
58std::function<int(
GRBmodel*
model,
const char* attrname,
int element,
61std::function<int(
GRBmodel*
model,
const char* attrname,
int element,
64std::function<int(
GRBmodel*
model,
const char* attrname,
int first,
int len,
67std::function<int(
GRBmodel*
model,
const char* attrname,
int first,
int len,
70std::function<int(
GRBmodel*
model,
const char* attrname,
int len,
int* ind,
73std::function<int(
GRBmodel*
model,
const char* attrname,
int element,
76std::function<int(
GRBmodel*
model,
const char* attrname,
int element,
79std::function<int(
GRBmodel*
model,
const char* attrname,
int first,
int len,
82std::function<int(
GRBmodel*
model,
const char* attrname,
int first,
int len,
85std::function<int(
GRBmodel*
model,
const char* attrname,
int len,
int* ind,
88std::function<int(
GRBmodel*
model,
const char* attrname,
double* valueP)>
90std::function<int(
GRBmodel*
model,
const char* attrname,
double newvalue)>
92std::function<int(
GRBmodel*
model,
const char* attrname,
int element,
95std::function<int(
GRBmodel*
model,
const char* attrname,
int element,
98std::function<int(
GRBmodel*
model,
const char* attrname,
int first,
int len,
101std::function<int(
GRBmodel*
model,
const char* attrname,
int first,
int len,
104std::function<int(
GRBmodel*
model,
const char* attrname,
int len,
int* ind,
107std::function<int(
GRBmodel*
model,
const char* attrname,
char** valueP)>
109std::function<int(
GRBmodel*
model,
const char* attrname,
const char* newvalue)>
114std::function<int(
void* cbdata,
int where,
int what,
void* resultP)>
GRBcbget =
116std::function<int(
void* cbdata,
const double*
solution,
double* objvalP)>
118std::function<int(
void* cbdata,
int cutlen,
const int* cutind,
119 const double* cutval,
char cutsense,
double cutrhs)>
121std::function<int(
void* cbdata,
int lazylen,
const int* lazyind,
122 const double* lazyval,
char lazysense,
double lazyrhs)>
124std::function<int(
GRBmodel*
model,
int* numnzP,
int* vbeg,
int* vind,
125 double* vval,
int start,
int len)>
130std::function<int(
GRBenv* env,
GRBmodel** modelP,
const char* Pname,
131 int numvars,
double* obj,
double* lb,
double* ub,
char* vtype,
134std::function<int(
GRBmodel*
model,
int numnz,
int* vind,
double* vval,
135 double obj,
double lb,
double ub,
char vtype,
136 const char* varname)>
138std::function<int(
GRBmodel*
model,
int numvars,
int numnz,
int* vbeg,
int* vind,
139 double* vval,
double* obj,
double* lb,
double* ub,
140 char* vtype,
char** varnames)>
142std::function<int(
GRBmodel*
model,
int numnz,
int* cind,
double* cval,
143 char sense,
double rhs,
const char* constrname)>
145std::function<int(
GRBmodel*
model,
int numconstrs,
int numnz,
int* cbeg,
146 int* cind,
double* cval,
char* sense,
double* rhs,
149std::function<int(
GRBmodel*
model,
int numnz,
int* cind,
double* cval,
150 double lower,
double upper,
const char* constrname)>
152std::function<int(
GRBmodel*
model,
int numsos,
int nummembers,
int* types,
153 int* beg,
int* ind,
double*
weight)>
156 const int* vars,
double constant)>
159 const int* vars,
double constant)>
170 int nvars,
const int* vars,
const double* vals,
char sense,
173std::function<int(
GRBmodel*
model,
int numlnz,
int* lind,
double* lval,
174 int numqnz,
int* qrow,
int* qcol,
double* qval,
char sense,
175 double rhs,
const char* QCname)>
177std::function<int(
GRBmodel*
model,
int numqnz,
int* qrow,
int* qcol,
187std::function<int(
GRBmodel*
model,
int cnt,
int* cind,
int* vind,
double* val)>
193 double abstol,
double reltol,
const char*
name,
194 double constant,
int lnz,
int* lind,
double* lval)>
196std::function<int(
GRBenv* env,
const char* paramname,
int* valueP)>
198std::function<int(
GRBenv* env,
const char* paramname,
double* valueP)>
200std::function<int(
GRBenv* env,
const char* paramname,
char* valueP)>
202std::function<int(
GRBenv* env,
const char* paramname,
int* valueP,
int* minP,
203 int* maxP,
int* defP)>
205std::function<int(
GRBenv* env,
const char* paramname,
double* valueP,
206 double* minP,
double* maxP,
double* defP)>
208std::function<int(
GRBenv* env,
const char* paramname,
char* valueP,
char* defP)>
214std::function<int(
GRBenv* env,
const char* paramname,
const char*
value)>
216std::function<int(
GRBenv* env,
const char* paramname,
int value)>
218std::function<int(
GRBenv* env,
const char* paramname,
double value)>
220std::function<int(
GRBenv* env,
const char* paramname,
const char*
value)>
231std::function<void(
int* majorP,
int* minorP,
int* technicalP)>
GRBversion =
242 "GRBisattravailable");
246 "GRBgetintattrelement");
248 "GRBsetintattrelement");
250 "GRBgetintattrarray");
252 "GRBsetintattrarray");
255 "GRBgetcharattrelement");
257 "GRBsetcharattrelement");
259 "GRBgetcharattrarray");
261 "GRBsetcharattrarray");
263 "GRBsetcharattrlist");
267 "GRBgetdblattrelement");
269 "GRBsetdblattrelement");
271 "GRBgetdblattrarray");
273 "GRBsetdblattrarray");
278 "GRBsetcallbackfunc");
295 "GRBaddgenconstrMax");
297 "GRBaddgenconstrMin");
299 "GRBaddgenconstrAbs");
301 "GRBaddgenconstrAnd");
304 "GRBaddgenconstrIndicator");
334 "GRBgetintparaminfo");
336 "GRBgetdblparaminfo");
338 "GRBgetstrparaminfo");
347 std::vector<std::string> potential_paths;
348 const std::vector<std::string> kGurobiVersions = {
349 "1103",
"1102",
"1101",
"1100",
"1003",
"1002",
"1001",
"1000",
"952",
"951",
350 "950",
"911",
"910",
"903",
"902",
"811",
"801",
"752"};
351 potential_paths.reserve(kGurobiVersions.size() * 3);
354 const char* gurobi_home_from_env = getenv(
"GUROBI_HOME");
355 if (gurobi_home_from_env !=
nullptr) {
356 for (
const std::string& version : kGurobiVersions) {
357 const std::string lib = version.substr(0, version.size() - 1);
359 potential_paths.push_back(
360 absl::StrCat(gurobi_home_from_env,
"\\bin\\gurobi", lib,
".dll"));
361#elif defined(__APPLE__)
362 potential_paths.push_back(
363 absl::StrCat(gurobi_home_from_env,
"/lib/libgurobi", lib,
".dylib"));
364#elif defined(__GNUC__)
365 potential_paths.push_back(
366 absl::StrCat(gurobi_home_from_env,
"/lib/libgurobi", lib,
".so"));
367 potential_paths.push_back(
368 absl::StrCat(gurobi_home_from_env,
"/lib64/libgurobi", lib,
".so"));
370 LOG(ERROR) <<
"OS Not recognized by gurobi/environment.cc."
371 <<
" You won't be able to use Gurobi.";
377 for (
const std::string& version : kGurobiVersions) {
378 const std::string lib = version.substr(0, version.size() - 1);
380 potential_paths.push_back(absl::StrCat(
"C:\\Program Files\\gurobi", version,
381 "\\win64\\bin\\gurobi", lib,
383 potential_paths.push_back(absl::StrCat(
384 "C:\\gurobi", version,
"\\win64\\bin\\gurobi", lib,
".dll"));
385 potential_paths.push_back(absl::StrCat(
"gurobi", lib,
".dll"));
386#elif defined(__APPLE__)
387 potential_paths.push_back(absl::StrCat(
388 "/Library/gurobi", version,
"/mac64/lib/libgurobi", lib,
".dylib"));
389 potential_paths.push_back(absl::StrCat(
"/Library/gurobi", version,
390 "/macos_universal2/lib/libgurobi",
392#elif defined(__GNUC__)
393 potential_paths.push_back(absl::StrCat(
394 "/opt/gurobi", version,
"/linux64/lib/libgurobi", lib,
".so"));
395 potential_paths.push_back(absl::StrCat(
396 "/opt/gurobi", version,
"/linux64/lib64/libgurobi", lib,
".so"));
397 potential_paths.push_back(
398 absl::StrCat(
"/opt/gurobi/linux64/lib/libgurobi", lib,
".so"));
399 potential_paths.push_back(
400 absl::StrCat(
"/opt/gurobi/linux64/lib64/libgurobi", lib,
".so"));
402 LOG(ERROR) <<
"OS Not recognized by gurobi/environment.cc."
403 <<
" You won't be able to use Gurobi.";
408 for (
const std::string& version :
409 {
"11.0.3",
"11.0.2",
"11.0.1",
"11.0.0",
"10.0.3",
"10.0.2",
"10.0.1",
"10.0.0",
410 "9.5.2",
"9.5.1",
"9.5.0"}) {
411 potential_paths.push_back(
412 absl::StrCat(
"/opt/gurobi/linux64/lib/libgurobi.so.", version));
415 return potential_paths;
419 std::vector<std::string> potential_paths) {
420 static std::once_flag gurobi_loading_done;
421 static absl::Status gurobi_load_status;
423 static absl::Mutex mutex;
425 absl::MutexLock lock(&mutex);
427 std::call_once(gurobi_loading_done, [&potential_paths]() {
428 const std::vector<std::string> canonical_paths =
430 potential_paths.insert(potential_paths.end(), canonical_paths.begin(),
431 canonical_paths.end());
432 for (
const std::string& path : potential_paths) {
434 LOG(INFO) <<
"Found the Gurobi library in '" << path <<
".";
441 gurobi_load_status = absl::OkStatus();
443 gurobi_load_status = absl::NotFoundError(absl::StrCat(
444 "Could not find the Gurobi shared library. Looked in: [",
445 absl::StrJoin(potential_paths,
"', '"),
446 "]. If you know where it"
447 " is, pass the full path to 'LoadGurobiDynamicLibrary()'."));
450 return gurobi_load_status;
458 if (
GRBloadenv(&env,
nullptr) != 0 || env ==
nullptr) {
459 return absl::FailedPreconditionError(
460 absl::StrCat(
"Found the Gurobi shared library, but could not create "
461 "Gurobi environment: is Gurobi licensed on this machine?",
#define RETURN_IF_ERROR(expr)
bool LibraryIsLoaded() const
std::function< T > GetFunction(const char *function_name)
bool TryToLoad(const std::string &library_name)
const std::string name
A name for logging purposes.
struct _GRBmodel GRBmodel
In SWIG mode, we don't want anything besides these top-level includes.
std::function< int(GRBmodel *model, int numnz, int *cind, double *cval, char sense, double rhs, const char *constrname)> GRBaddconstr
std::function< void(GRBenv *env)> GRBfreeenv
std::function< int(GRBmodel *model, const char *attrname, double *valueP)> GRBgetdblattr
std::function< int(GRBmodel *model, const char *attrname, int first, int len, double *values)> GRBgetdblattrarray
std::function< int(GRBmodel *model, const char *attrname, int first, int len, int *values)> GRBgetintattrarray
std::function< int(GRBmodel *model, const char *attrname, double newvalue)> GRBsetdblattr
std::function< int(GRBmodel *model, int len, int *ind)> GRBdelsos
std::function< int(GRBmodel *model, int numvars, int numnz, int *vbeg, int *vind, double *vval, double *obj, double *lb, double *ub, char *vtype, char **varnames)> GRBaddvars
std::function< int(GRBmodel *model, int(GUROBI_STDCALL *cb)(CB_ARGS), void *usrdata)> GRBsetcallbackfunc
std::function< int(GRBenv *dest, GRBenv *src)> GRBcopyparams
std::function< int(GRBmodel *model, int *numnzP, int *vbeg, int *vind, double *vval, int start, int len)> GRBgetvars
std::function< int(GRBmodel *model, const char *attrname, int len, int *ind, int *newvalues)> GRBsetintattrlist
std::function< int(GRBmodel *model, int cnt, int *cind, int *vind, double *val)> GRBchgcoeffs
std::function< int(GRBmodel *model, const char *attrname, int first, int len, char *values)> GRBgetcharattrarray
std::function< int(void *cbdata, int cutlen, const int *cutind, const double *cutval, char cutsense, double cutrhs)> GRBcbcut
std::function< int(GRBenv *env, const char *paramname, double *valueP)> GRBgetdblparam
std::function< int(GRBmodel *model, int numlnz, int *lind, double *lval, int numqnz, int *qrow, int *qcol, double *qval, char sense, double rhs, const char *QCname)> GRBaddqconstr
std::function< int(GRBmodel *model, int len, int *ind)> GRBdelvars
std::function< int(GRBmodel *model, const char *attrname, int newvalue)> GRBsetintattr
std::function< int(GRBenv *env, const char *paramname, const char *value)> GRBsetparam
std::function< int(GRBmodel *model, const char *attrname, int element, int *valueP)> GRBgetintattrelement
std::function< int(GRBenv *env, GRBmodel **modelP, const char *Pname, int numvars, double *obj, double *lb, double *ub, char *vtype, char **varnames)> GRBnewmodel
std::function< int(GRBmodel *model, int numnz, int *vind, double *vval, double obj, double lb, double ub, char vtype, const char *varname)> GRBaddvar
std::function< int(GRBmodel *model, const char *attrname, int first, int len, int *newvalues)> GRBsetintattrarray
absl::Status LoadGurobiDynamicLibrary(std::vector< std::string > potential_paths)
std::function< int(GRBmodel *model)> GRBupdatemodel
std::function< void(int *majorP, int *minorP, int *technicalP)> GRBversion
std::function< GRBenv *(GRBmodel *model)> GRBgetenv
std::function< int(GRBmodel *model, const char *attrname, int len, int *ind, char *newvalues)> GRBsetcharattrlist
bool GurobiIsCorrectlyInstalled()
std::function< int(GRBenv *env, const char *paramname, char *valueP)> GRBgetstrparam
std::function< int(GRBmodel *model, const char *attrname, int element, double *valueP)> GRBgetdblattrelement
std::function< int(GRBmodel *model, const char *attrname, int first, int len, char *newvalues)> GRBsetcharattrarray
std::function< int(GRBmodel *model)> GRBfreemodel
std::function< int(GRBmodel *model, int len, int *ind)> GRBdelqconstrs
std::function< int(void *cbdata, int lazylen, const int *lazyind, const double *lazyval, char lazysense, double lazyrhs)> GRBcblazy
std::function< int(GRBmodel *model)> GRBcomputeIIS
void LoadGurobiFunctions(DynamicLibrary *gurobi_dynamic_library)
std::function< int(void *cbdata, int where, int what, void *resultP)> GRBcbget
std::function< int(GRBenv *env, const char *paramname, int value)> GRBsetintparam
std::function< int(GRBmodel *model, const char *attrname)> GRBisattravailable
std::function< int(GRBenv *env, const char *paramname, const char *value)> GRBsetstrparam
std::function< int(GRBenv *env, const char *paramname, char *valueP, char *defP)> GRBgetstrparaminfo
std::function< int(GRBmodel *model, const char *attrname, int first, int len, double *newvalues)> GRBsetdblattrarray
std::function< int(GRBmodel *model, const char *name, int resvar, int nvars, const int *vars, double constant)> GRBaddgenconstrMin
std::function< int(GRBmodel *model, int numnz, int *cind, double *cval, double lower, double upper, const char *constrname)> GRBaddrangeconstr
std::function< int(GRBmodel *model, const char *name, int binvar, int binval, int nvars, const int *vars, const double *vals, char sense, double rhs)> GRBaddgenconstrIndicator
std::function< int(GRBmodel *model, const char *attrname, int element, char newvalue)> GRBsetcharattrelement
std::function< int(GRBmodel *model, const char *attrname, int element, int newvalue)> GRBsetintattrelement
std::function< int(GRBenv *env)> GRBresetparams
std::function< int(GRBmodel *model, const char *attrname, const char *newvalue)> GRBsetstrattr
std::function< int(GRBmodel *model)> GRBoptimize
std::function< int(GRBenv **envP, const char *logfilename)> GRBloadenv
std::function< int(GRBmodel *model, int numqnz, int *qrow, int *qcol, double *qval)> GRBaddqpterms
std::function< int(GRBenv **, const char *, const char *, const char *, int, const char *)> GRBisqp
This is the 'define' section.
std::function< int(GRBenv **envP)> GRBemptyenv
std::function< int(GRBenv *env, const char *paramname)> GRBgetparamtype
std::function< int(GRBmodel *model, int len, int *ind)> GRBdelconstrs
std::function< int(GRBmodel *model, const char *name, int resvar, int argvar)> GRBaddgenconstrAbs
std::vector< std::string > GurobiDynamicLibraryPotentialPaths()
std::function< int(GRBenv *env, int i, char **paramnameP)> GRBgetparamname
std::function< int(GRBmodel *model, const char *attrname, int *valueP)> GRBgetintattr
std::function< int(GRBmodel *model, int len, int *ind)> GRBdelgenconstrs
std::function< int(GRBmodel *model, int index, int priority, double weight, double abstol, double reltol, const char *name, double constant, int lnz, int *lind, double *lval)> GRBsetobjectiven
std::function< const char *(GRBenv *env)> GRBgeterrormsg
absl::StatusOr< GRBenv * > GetGurobiEnv()
std::function< int(GRBmodel *model, const char *filename)> GRBwrite
std::function< int(GRBenv *env, const char *paramname, double *valueP, double *minP, double *maxP, double *defP)> GRBgetdblparaminfo
std::function< int(GRBenv *env, const char *paramname, int *valueP)> GRBgetintparam
std::function< int(GRBmodel *model, const char *name, int resvar, int nvars, const int *vars)> GRBaddgenconstrAnd
std::function< int(GRBenv *env)> GRBstartenv
std::function< int(GRBmodel *model, const char *name, int resvar, int nvars, const int *vars)> GRBaddgenconstrOr
std::function< int(GRBmodel *model, int numconstrs, int numnz, int *cbeg, int *cind, double *cval, char *sense, double *rhs, char **constrnames)> GRBaddconstrs
std::function< int(GRBmodel *model, const char *attrname, int len, int *ind, double *newvalues)> GRBsetdblattrlist
std::function< int(GRBmodel *model, const char *name, int resvar, int nvars, const int *vars, double constant)> GRBaddgenconstrMax
std::function< char *(void)> GRBplatform
std::function< int(GRBenv *env, const char *paramname, int *valueP, int *minP, int *maxP, int *defP)> GRBgetintparaminfo
std::function< int(GRBmodel *model, int numsos, int nummembers, int *types, int *beg, int *ind, double *weight)> GRBaddsos
std::function< int(GRBenv *env)> GRBgetnumparams
std::function< int(GRBmodel *model, const char *attrname, int element, char *valueP)> GRBgetcharattrelement
std::function< int(GRBmodel *model, const char *attrname, char **valueP)> GRBgetstrattr
std::function< int(GRBmodel *model)> GRBdelq
std::function< int(void *cbdata, const double *solution, double *objvalP)> GRBcbsolution
std::function< void(GRBmodel *model)> GRBterminate
std::function< int(GRBenv *env, const char *paramname, double value)> GRBsetdblparam
std::function< int(GRBmodel *model, const char *attrname, int element, double newvalue)> GRBsetdblattrelement