25#include "absl/base/call_once.h"
26#include "absl/base/const_init.h"
27#include "absl/status/status.h"
28#include "absl/strings/str_cat.h"
29#include "absl/strings/str_join.h"
30#include "absl/synchronization/mutex.h"
37#define STRINGIFY2(X) #X
38#define STRINGIFY(X) STRINGIFY2(X)
50std::function<int(
const char* path)>
XPRSinit =
nullptr;
85std::function<int(
XPRSprob prob,
int nrows,
int ncoefs,
const char rowtype[],
const double rhs[],
const double rng[],
const int start[],
const int colind[],
const double rowcoef[])>
XPRSaddrows =
nullptr;
86std::function<int(
XPRSprob prob,
int nrows,
int ncoefs,
const char rowtype[],
const double rhs[],
const double rng[],
const XPRSint64 start[],
const int colind[],
const double rowcoef[])>
XPRSaddrows64 =
nullptr;
88std::function<int(
XPRSprob prob,
int ncols,
int ncoefs,
const double objcoef[],
const int start[],
const int rowind[],
const double rowcoef[],
const double lb[],
const double ub[])>
XPRSaddcols =
nullptr;
89std::function<int(
XPRSprob prob,
int ncols,
const int colind[],
const double objcoef[],
int priority,
double weight)>
XPRSaddobj =
nullptr;
90std::function<int(
XPRSprob prob,
int row,
int ncoefs,
const int rowqcol1[],
int const rowqcol2[],
const double rowqcoef[])>
XPRSaddqmatrix64 =
nullptr;
91std::function<int(
XPRSprob prob,
int type,
const char names[],
int first,
int last)>
XPRSaddnames =
nullptr;
105std::function<int(
XPRSprob prob,
int nbounds,
const int colind[],
const char bndtype[],
const double bndval[])>
XPRSchgbounds =
nullptr;
106std::function<int(
XPRSprob prob,
int length,
const double solval[],
const int colind[],
const char* name)>
XPRSaddmipsol =
nullptr;
108std::function<int(
XPRSprob prob,
int nrows,
const int rowind[],
const int colind[],
const int complement[])>
XPRSsetindicators =
nullptr;
109std::function<int(
XPRSprob prob,
int ndirs,
const int colind[],
const int priority[],
const char dir[],
const double uppseudo[],
const double downpseudo[])>
XPRSloaddirs;
110std::function<int(
XPRSprob prob,
double x[],
double slack[],
double duals[],
double djs[])>
XPRSgetlpsol =
nullptr;
112std::function<int(
XPRSprob prob,
int ncols,
const int colind[],
const double objcoef[])>
XPRSchgobj =
nullptr;
114std::function<int(
XPRSprob prob,
int ncoefs,
const int rowind[],
const int colind[],
const double rowcoef[])>
XPRSchgmcoef =
nullptr;
116std::function<int(
XPRSprob prob,
int ncoefs,
const int objqcol1[],
const int objqcol2[],
const double objqcoef[])>
XPRSchgmqobj =
nullptr;
117std::function<int(
XPRSprob prob,
int nrows,
const int rowind[],
const double rhs[])>
XPRSchgrhs =
nullptr;
233 LOG(ERROR) <<
"XpressInterface : Xpress banner :\n" << banner <<
"\n";
235 LOG(WARNING) <<
"XpressInterface : Xpress banner :\n" << banner <<
"\n";
240 std::vector<std::string> potential_paths;
243 const char* xpressdir_from_env = getenv(
"XPRESSDIR");
244 if (xpressdir_from_env !=
nullptr) {
245 LOG(INFO) <<
"Environment variable XPRESSDIR = " << xpressdir_from_env;
247 potential_paths.push_back(
248 absl::StrCat(xpressdir_from_env,
"\\bin\\xprs.dll"));
249#elif defined(__APPLE__)
250 potential_paths.push_back(
251 absl::StrCat(xpressdir_from_env,
"/lib/libxprs.dylib"));
252#elif defined(__GNUC__)
253 potential_paths.push_back(
254 absl::StrCat(xpressdir_from_env,
"/lib/libxprs.so"));
256 LOG(ERROR) <<
"OS Not recognized by xpress_environment.cc."
257 <<
" You won't be able to use Xpress.";
260 LOG(WARNING) <<
"Environment variable XPRESSDIR undefined.";
265 potential_paths.push_back(absl::StrCat(
"C:\\xpressmp\\bin\\xprs.dll"));
266 potential_paths.push_back(
267 absl::StrCat(
"C:\\Program Files\\xpressmp\\bin\\xprs.dll"));
268#elif defined(__APPLE__)
269 potential_paths.push_back(
270 absl::StrCat(
"/Library/xpressmp/lib/libxprs.dylib"));
271#elif defined(__GNUC__)
272 potential_paths.push_back(absl::StrCat(
"/opt/xpressmp/lib/libxprs.so"));
274 LOG(ERROR) <<
"OS Not recognized by xpress_environment.cc."
275 <<
" You won't be able to use Xpress.";
277 return potential_paths;
281 static std::string* xpress_lib_path =
new std::string;
282 static absl::once_flag xpress_loading_done;
283 static absl::Status* xpress_load_status =
new absl::Status;
285 static absl::Mutex mutex(absl::kConstInit);
287 absl::MutexLock lock(mutex);
289 absl::call_once(xpress_loading_done, []() {
290 const std::vector<std::string> canonical_paths =
292 for (
const std::string& path : canonical_paths) {
294 LOG(INFO) <<
"Found the Xpress library in " << path <<
".";
295 xpress_lib_path->clear();
296 std::filesystem::path p(path);
298 xpress_lib_path->append(p.string());
304 LOG(INFO) <<
"Loading all Xpress functions";
307 int major = -1, minor = -1, build = -1;
310 *xpress_load_status =
312 <<
"Xpress optimizer library too old, need at least version "
316 <<
"Xpress optimizer library version " << major
317 <<
" too old, need at least version "
320 *xpress_load_status = absl::OkStatus();
322 *xpress_load_status = absl::NotFoundError(
323 absl::StrCat(
"Could not find the Xpress shared library. Looked in: [",
324 absl::StrJoin(canonical_paths,
"', '"),
325 "]. Please check environment variable XPRESSDIR"));
329 xpresspath.append(*xpress_lib_path);
330 return *xpress_load_status;
337 std::string xpress_lib_dir;
340 LOG(WARNING) << status <<
"\n";
346 if (xpress_oem_license_key == 0) {
359 LOG(WARNING) <<
"Optimizer version: " << version
360 <<
" (OR-Tools was compiled with version " <<
XPVERSION
371 LOG(WARNING) <<
"XpressInterface : Initialising xpress-MP with OEM key "
372 << xpress_oem_license_key;
377 char slicmsg[256] =
"";
382 DLOG(INFO) <<
"XpressInterface : First message from XPRSLicense : "
386 nvalue = xpress_oem_license_key - ((nvalue * nvalue) / 19);
390 DLOG(INFO) <<
"XpressInterface : Second message from XPRSLicense : "
396 <<
"XpressInterface : Optimizer development software detected";
398 }
else if (ierr != 0) {
402 LOG(ERROR) <<
"XpressInterface : " << errmsg;
411 LOG(ERROR) <<
"XPRSinit returned code : " << code <<
"\n";
417 LOG(WARNING) <<
"XpressInterface: Xpress found at " << xpress_lib_dir <<
"\n";
421 LOG(ERROR) <<
"XpressInterface : License error : " << errmsg
422 <<
" (XPRSinit returned code " << code <<
"). \n";
424 <<
"|_Your Xpress installation should have set the env var XPAUTH_PATH"
425 " to the full path of your licence file\n";
429 <<
"XpressInterface : Initialising xpress-MP with default parameters";
434 if (correctlyInstalled) {
437 return correctlyInstalled;
bool LibraryIsLoaded() const
std::function< T > GetFunction(const char *function_name)
bool TryToLoad(const absl::string_view library_name)
std::function< int(XPRSprob prob, int objidx)> XPRSdelobj
std::function< int(XPRSprob prob, void(XPRS_CC *f_intsol)(XPRSprob cbprob, void *cbdata), void *p, int priority)> XPRSaddcbintsol
std::function< int(XPRSprob prob, int(XPRS_CC *f_checktime)(XPRSprob cbprob, void *cbdata), void *p)> XPRSremovecbchecktime
std::function< int(XPRSprob prob, int control)> XPRSsetdefaultcontrol
std::function< int(XPRSprob prob, int nrows, const int rowind[], const char rowtype[])> XPRSchgrowtype
std::function< int(XPRSprob prob, int objidx, const double solution[], double *p_objval)> XPRScalcobjn
std::function< int(char *banner)> XPRSgetbanner
absl::Status LoadXpressDynamicLibrary(std::string &xpresspath)
std::function< int(XPRSprob prob, int(XPRS_CC *f_checktime)(XPRSprob cbprob, void *cbdata), void *p, int priority)> XPRSaddcbchecktime
std::function< int(XPRSprob prob, int nrows, const int rowind[])> XPRSloaddelayedrows
std::function< int(XPRSprob prob, char rowtype[], int first, int last)> XPRSgetrowtype
std::function< int(XPRSprob prob, int attrib, int *p_value)> XPRSgetintattrib
std::function< int(XPRSprob prob, int ndirs, const int colind[], const int priority[], const char dir[], const double uppseudo[], const double downpseudo[])> XPRSloaddirs
std::function< int(XPRSprob prob, int ncoefs, const int objqcol1[], const int objqcol2[], const double objqcoef[])> XPRSchgmqobj
std::function< int(XPRSprob prob, void(XPRS_CC *f_message)(XPRSprob cbprob, void *cbdata, const char *msg, int msglen, int msgtype), void *p)> XPRSremovecbmessage
std::function< int(XPRSprob prob, char coltype[], int first, int last)> XPRSgetcoltype
std::function< int(XPRSprob prob, int attrib, double *p_value)> XPRSgetdblattrib
std::function< int(XPRSprob prob, int *status, double djs[], int first, int last)> XPRSgetredcosts
std::function< int(XPRSprob prob, const char *filename, const char *flags)> XPRSwriteprob
std::function< int(XPRSprob prob, void(XPRS_CC *f_message)(XPRSprob cbprob, void *cbdata, const char *msg, int msglen, int msgtype), void *p, int priority)> XPRSaddcbmessage
std::function< int(XPRSprob prob, double rhs[], int first, int last)> XPRSgetrhs
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
bool initXpressEnv(bool verbose, int xpress_oem_license_key)
init XPRESS environment.
void LoadXpressFunctions(DynamicLibrary *xpress_dynamic_library)
std::function< int(XPRSprob prob, int length, const double solval[], const int colind[], const char *name)> XPRSaddmipsol
std::function< int(XPRSprob prob, double x[], double slack[])> XPRSgetmipsol
std::function< int(XPRSprob prob, int nbounds, const int colind[], const char bndtype[], const double bndval[])> XPRSchgbounds
std::function< int(XPRSprob prob, int row, int col, double *p_coef)> XPRSgetcoef
std::function< int(XPRSprob prob, const int rowstat[], const int colstat[])> XPRSloadbasis
std::function< int(XPRSprob prob, int row, int col, double coef)> XPRSchgcoef
std::function< int(XPRSprob prob, int nrows, const int rowind[])> XPRSdelrows
std::function< int(XPRSprob prob, int type, char names[], int first, int last)> XPRSgetnames
std::function< int(XPRSprob prob, int ncols, const int colind[])> XPRSdelcols
std::function< int(XPRSprob prob, int control, double *p_value)> XPRSgetdblcontrol
std::function< int(XPRSprob prob, int objidx, int control, int value)> XPRSsetobjintcontrol
std::function< int(XPRSprob prob, double lb[], int first, int last)> XPRSgetlb
std::function< int(XPRSprob prob, const char *flags, int *solvestatus, int *solstatus)> XPRSoptimize
std::function< int(XPRSprob prob, int control, int *p_value)> XPRSgetintcontrol
std::function< int(XPRSprob prob, void(XPRS_CC *f_intsol)(XPRSprob cbprob, void *cbdata), void *p)> XPRSremovecbintsol
std::function< int(XPRSprob prob, int ncols, const int colind[], const char coltype[])> XPRSchgcoltype
std::function< int(XPRSprob prob, int nrows, const int rowind[], const int colind[], const int complement[])> XPRSsetindicators
std::function< int(char *version)> XPRSgetversion
std::function< int(XPRSprob prob, const char *name, int *p_id, int *p_type)> XPRSgetcontrolinfo
std::function< int(XPRSprob prob, double x[], double slack[], double duals[], double djs[])> XPRSgetlpsol
std::function< int(XPRSprob prob, int control, XPRSint64 *p_value)> XPRSgetintcontrol64
std::function< int(XPRSprob prob)> XPRSpostsolve
std::function< int(XPRSprob prob, double objcoef[], int first, int last)> XPRSgetobj
std::function< int(XPRSprob prob, int nrows, const int rowind[], const double rng[])> XPRSchgrhsrange
std::function< int(XPRSprob prob, int type, const char names[], int first, int last)> XPRSaddnames
std::function< int(XPRSprob prob, int ncoefs, const int rowind[], const int colind[], const double rowcoef[])> XPRSchgmcoef
void log_full_license_error(int code, const std::string &xpress_lib_dir)
std::function< int(void)> XPRSfree
std::function< int(XPRSprob prob, int reason)> XPRSinterrupt
bool XpressIsCorrectlyInstalled()
std::function< int(char *buffer, int maxbytes)> XPRSgetlicerrmsg
std::function< int(XPRSprob prob, const char *filename)> XPRSsaveas
void log_message_about_XPRSinit_argument()
std::function< int(XPRSprob prob, int nsets, XPRSint64 nelems, const char settype[], const XPRSint64 start[], const int colind[], const double refval[])> XPRSaddsets64
std::function< int(XPRSprob prob, int control, int value)> XPRSsetintcontrol
std::function< int(XPRSprob prob, int nrows, int ncoefs, const char rowtype[], const double rhs[], const double rng[], const int start[], const int colind[], const double rowcoef[])> XPRSaddrows
std::function< int(XPRSprob prob, char *errmsg)> XPRSgetlasterror
std::function< int(XPRSprob prob, int attrib, char *value, int maxbytes, int *p_nbytes)> XPRSgetstringattrib
std::function< int(XPRSprob prob)> XPRSdestroyprob
std::function< int(XPRSprob prob, int control, double value)> XPRSsetdblcontrol
std::function< int(XPRSprob prob, XPRSint64 ncoefs, const int rowind[], const int colind[], const double rowcoef[])> XPRSchgmcoef64
std::function< int(XPRSprob prob, int *status, double x[], int first, int last)> XPRSgetsolution
std::function< int(XPRSprob prob, double rng[], int first, int last)> XPRSgetrhsrange
std::function< int(XPRSprob prob, double ub[], int first, int last)> XPRSgetub
void printXpressBanner(bool error)
std::function< int(int *p_major, int *p_minor, int *p_build)> XPRSgetversionnumbers
std::function< int(int *p_i, char *p_c)> XPRSlicense
std::function< int(XPRSprob prob, int control, const char *value)> XPRSsetstrcontrol
std::function< int(XPRSprob prob, int ncols, int ncoefs, const double objcoef[], const int start[], const int rowind[], const double rowcoef[], const double lb[], const double ub[])> XPRSaddcols
std::function< int(XPRSprob prob, int control, char *value, int maxbytes, int *p_nbytes)> XPRSgetstringcontrol
std::function< int(XPRSprob prob, int row, int ncoefs, const int rowqcol1[], int const rowqcol2[], const double rowqcoef[])> XPRSaddqmatrix64
std::function< int(XPRSprob prob, int ncols, const int colind[], const double objcoef[], int priority, double weight)> XPRSaddobj
std::function< int(XPRSprob prob, const char *flags)> XPRSmipoptimize
std::function< int(XPRSprob prob, int nrows, int ncoefs, const char rowtype[], const double rhs[], const double rng[], const XPRSint64 start[], const int colind[], const double rowcoef[])> XPRSaddrows64
std::function< int(XPRSprob prob, int nrows, const int rowind[], const double rhs[])> XPRSchgrhs
std::function< int(XPRSprob prob, int objidx, int attrib, double *p_value)> XPRSgetobjdblattrib
std::function< int(XPRSprob prob, int objidx, int control, double value)> XPRSsetobjdblcontrol
std::function< int(XPRSprob prob, int ncols, const int colind[], const double objcoef[])> XPRSchgobj
std::function< int(XPRSprob prob, int *status, double duals[], int first, int last)> XPRSgetduals
std::vector< std::string > XpressDynamicLibraryPotentialPaths()
std::function< int(XPRSprob *p_prob)> XPRScreateprob
std::function< int(XPRSprob prob, const char *flags)> XPRSlpoptimize
std::function< int(XPRSprob prob, int control, XPRSint64 value)> XPRSsetintcontrol64
std::function< int(XPRSprob prob, int objsense)> XPRSchgobjsense
std::function< int(const char *path)> XPRSinit
std::function< int(XPRSprob prob, const char *probname)> XPRSsetprobname
std::function< int(XPRSprob prob, int rowstat[], int colstat[])> XPRSgetbasis
#define XPRS_MAXBANNERLENGTH
struct xo_prob_struct * XPRSprob