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"
35 if (!status.ok() || status.value() ==
nullptr) {
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)>
155std::function<int(
GRBmodel* model,
const char* name,
int resvar,
int nvars,
156 const int* vars,
double constant)>
158std::function<int(
GRBmodel* model,
const char* name,
int resvar,
int nvars,
159 const int* vars,
double constant)>
161std::function<int(
GRBmodel* model,
const char* name,
int resvar,
int argvar)>
163std::function<int(
GRBmodel* model,
const char* name,
int resvar,
int nvars,
166std::function<int(
GRBmodel* model,
const char* name,
int resvar,
int nvars,
169std::function<int(
GRBmodel* model,
const char* name,
int binvar,
int binval,
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)>
192std::function<int(
GRBmodel* model,
int index,
int priority,
double weight,
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)>
233std::function<void(
int* majorP,
int* minorP,
int* technicalP)>
GRBversion =
244 "GRBisattravailable");
248 "GRBgetintattrelement");
250 "GRBsetintattrelement");
252 "GRBgetintattrarray");
254 "GRBsetintattrarray");
257 "GRBgetcharattrelement");
259 "GRBsetcharattrelement");
261 "GRBgetcharattrarray");
263 "GRBsetcharattrarray");
265 "GRBsetcharattrlist");
269 "GRBgetdblattrelement");
271 "GRBsetdblattrelement");
273 "GRBgetdblattrarray");
275 "GRBsetdblattrarray");
280 "GRBsetcallbackfunc");
297 "GRBaddgenconstrMax");
299 "GRBaddgenconstrMin");
301 "GRBaddgenconstrAbs");
303 "GRBaddgenconstrAnd");
306 "GRBaddgenconstrIndicator");
336 "GRBgetintparaminfo");
338 "GRBgetdblparaminfo");
340 "GRBgetstrparaminfo");
344 "GRBdiscardmultiobjenvs");
352 std::vector<std::string> potential_paths;
353 const std::vector<std::string> kGurobiVersions = {
354 "1201",
"1200",
"1103",
"1102",
"1101",
"1100",
"1003",
355 "1002",
"1001",
"1000",
"952",
"951",
"950",
"911",
356 "910",
"903",
"902",
"811",
"801",
"752"};
357 potential_paths.reserve(kGurobiVersions.size() * 3);
360 const char* gurobi_home_from_env = getenv(
"GUROBI_HOME");
361 if (gurobi_home_from_env !=
nullptr) {
362 for (
const std::string& version : kGurobiVersions) {
363 const std::string lib = version.substr(0, version.size() - 1);
365 potential_paths.push_back(
366 absl::StrCat(gurobi_home_from_env,
"\\bin\\gurobi", lib,
".dll"));
367#elif defined(__APPLE__)
368 potential_paths.push_back(
369 absl::StrCat(gurobi_home_from_env,
"/lib/libgurobi", lib,
".dylib"));
370#elif defined(__GNUC__)
371 potential_paths.push_back(
372 absl::StrCat(gurobi_home_from_env,
"/lib/libgurobi", lib,
".so"));
373 potential_paths.push_back(
374 absl::StrCat(gurobi_home_from_env,
"/lib64/libgurobi", lib,
".so"));
376 LOG(ERROR) <<
"OS Not recognized by gurobi/environment.cc."
377 <<
" You won't be able to use Gurobi.";
383 for (
const std::string& version : kGurobiVersions) {
384 const std::string lib = version.substr(0, version.size() - 1);
386 potential_paths.push_back(absl::StrCat(
"C:\\Program Files\\gurobi", version,
387 "\\win64\\bin\\gurobi", lib,
389 potential_paths.push_back(absl::StrCat(
390 "C:\\gurobi", version,
"\\win64\\bin\\gurobi", lib,
".dll"));
391 potential_paths.push_back(absl::StrCat(
"gurobi", lib,
".dll"));
392#elif defined(__APPLE__)
393 potential_paths.push_back(absl::StrCat(
394 "/Library/gurobi", version,
"/mac64/lib/libgurobi", lib,
".dylib"));
395 potential_paths.push_back(absl::StrCat(
"/Library/gurobi", version,
396 "/macos_universal2/lib/libgurobi",
398#elif defined(__GNUC__)
399 potential_paths.push_back(absl::StrCat(
400 "/opt/gurobi", version,
"/linux64/lib/libgurobi", lib,
".so"));
401 potential_paths.push_back(absl::StrCat(
402 "/opt/gurobi", version,
"/linux64/lib64/libgurobi", lib,
".so"));
403 potential_paths.push_back(
404 absl::StrCat(
"/opt/gurobi/linux64/lib/libgurobi", lib,
".so"));
405 potential_paths.push_back(
406 absl::StrCat(
"/opt/gurobi/linux64/lib64/libgurobi", lib,
".so"));
408 LOG(ERROR) <<
"OS Not recognized by gurobi/environment.cc."
409 <<
" You won't be able to use Gurobi.";
414 for (
const std::string& version :
415 {
"12.0.1",
"12.0.0",
"11.0.3",
"11.0.2",
"11.0.1",
"11.0.0",
"10.0.3",
416 "10.0.2",
"10.0.1",
"10.0.0",
"9.5.2",
"9.5.1",
"9.5.0"}) {
417 potential_paths.push_back(
418 absl::StrCat(
"/opt/gurobi/linux64/lib/libgurobi.so.", version));
421 return potential_paths;
425 std::vector<std::string> potential_paths) {
426 static std::once_flag gurobi_loading_done;
427 static absl::Status gurobi_load_status;
429 static absl::Mutex mutex;
431 absl::MutexLock lock(&mutex);
433 std::call_once(gurobi_loading_done, [&potential_paths]() {
434 const std::vector<std::string> canonical_paths =
436 potential_paths.insert(potential_paths.end(), canonical_paths.begin(),
437 canonical_paths.end());
438 for (
const std::string& path : potential_paths) {
440 LOG(INFO) <<
"Found the Gurobi library in '" << path <<
".";
447 gurobi_load_status = absl::OkStatus();
449 gurobi_load_status = absl::NotFoundError(absl::StrCat(
450 "Could not find the Gurobi shared library. Looked in: [",
451 absl::StrJoin(potential_paths,
"', '"),
452 "]. If you know where it"
453 " is, pass the full path to 'LoadGurobiDynamicLibrary()'."));
456 return gurobi_load_status;
464 if (
GRBloadenv(&env,
nullptr) != 0 || env ==
nullptr) {
465 return absl::FailedPreconditionError(
466 absl::StrCat(
"Found the Gurobi shared library, but could not create "
467 "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)
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
Select next search node to expand Select next item_i to add this new search node to the search Generate a new search node where item_i is not in the knapsack Check validity of this new partial solution(using propagators) - If valid
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< GRBenv *(GRBmodel *model)> GRBdiscardmultiobjenvs
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< GRBenv *(GRBmodel *model, int num)> GRBgetmultiobjenv
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