26#include "absl/base/call_once.h"
27#include "absl/base/const_init.h"
28#include "absl/status/status.h"
29#include "absl/strings/str_cat.h"
30#include "absl/strings/str_join.h"
31#include "absl/synchronization/mutex.h"
37#define STRINGIFY2(X) #X
38#define STRINGIFY(X) STRINGIFY2(X)
50std::function<int(
const char* path)>
XPRSinit =
nullptr;
79std::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;
81std::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;
82std::function<int(
XPRSprob prob,
int type,
const char names[],
int first,
int last)>
XPRSaddnames =
nullptr;
94std::function<int(
XPRSprob prob,
int nbounds,
const int colind[],
const char bndtype[],
const double bndval[])>
XPRSchgbounds =
nullptr;
95std::function<int(
XPRSprob prob,
int length,
const double solval[],
const int colind[],
const char* name)>
XPRSaddmipsol =
nullptr;
96std::function<int(
XPRSprob prob,
double x[],
double slack[],
double duals[],
double djs[])>
XPRSgetlpsol =
nullptr;
98std::function<int(
XPRSprob prob,
int ncols,
const int colind[],
const double objcoef[])>
XPRSchgobj =
nullptr;
100std::function<int(
XPRSprob prob,
int ncoefs,
const int rowind[],
const int colind[],
const double rowcoef[])>
XPRSchgmcoef =
nullptr;
102std::function<int(
XPRSprob prob,
int ncoefs,
const int objqcol1[],
const int objqcol2[],
const double objqcoef[])>
XPRSchgmqobj =
nullptr;
103std::function<int(
XPRSprob prob,
int nrows,
const int rowind[],
const double rhs[])>
XPRSchgrhs =
nullptr;
197 LOG(ERROR) <<
"XpressInterface : Xpress banner :\n" << banner <<
"\n";
199 LOG(WARNING) <<
"XpressInterface : Xpress banner :\n" << banner <<
"\n";
204 std::vector<std::string> potential_paths;
207 const char* xpressdir_from_env = getenv(
"XPRESSDIR");
208 if (xpressdir_from_env !=
nullptr) {
209 LOG(INFO) <<
"Environment variable XPRESSDIR = " << xpressdir_from_env;
211 potential_paths.push_back(
212 absl::StrCat(xpressdir_from_env,
"\\bin\\xprs.dll"));
213#elif defined(__APPLE__)
214 potential_paths.push_back(
215 absl::StrCat(xpressdir_from_env,
"/lib/libxprs.dylib"));
216#elif defined(__GNUC__)
217 potential_paths.push_back(
218 absl::StrCat(xpressdir_from_env,
"/lib/libxprs.so"));
220 LOG(ERROR) <<
"OS Not recognized by xpress/environment.cc."
221 <<
" You won't be able to use Xpress.";
224 LOG(WARNING) <<
"Environment variable XPRESSDIR undefined.";
229 potential_paths.push_back(absl::StrCat(
"C:\\xpressmp\\bin\\xprs.dll"));
230 potential_paths.push_back(
231 absl::StrCat(
"C:\\Program Files\\xpressmp\\bin\\xprs.dll"));
232#elif defined(__APPLE__)
233 potential_paths.push_back(
234 absl::StrCat(
"/Library/xpressmp/lib/libxprs.dylib"));
235#elif defined(__GNUC__)
236 potential_paths.push_back(absl::StrCat(
"/opt/xpressmp/lib/libxprs.so"));
238 LOG(ERROR) <<
"OS Not recognized by xpress/environment.cc."
239 <<
" You won't be able to use Xpress.";
241 return potential_paths;
245 static std::string* xpress_lib_path =
new std::string;
246 static absl::once_flag xpress_loading_done;
247 static absl::Status* xpress_load_status =
new absl::Status;
249 static absl::Mutex mutex(absl::kConstInit);
251 absl::MutexLock lock(&mutex);
253 absl::call_once(xpress_loading_done, []() {
254 const std::vector<std::string> canonical_paths =
256 for (
const std::string& path : canonical_paths) {
258 LOG(INFO) <<
"Found the Xpress library in " << path <<
".";
259 xpress_lib_path->clear();
260 std::filesystem::path p(path);
262 xpress_lib_path->append(p.string());
268 LOG(INFO) <<
"Loading all Xpress functions";
270 *xpress_load_status = absl::OkStatus();
272 *xpress_load_status = absl::NotFoundError(
273 absl::StrCat(
"Could not find the Xpress shared library. Looked in: [",
274 absl::StrJoin(canonical_paths,
"', '"),
275 "]. Please check environment variable XPRESSDIR"));
279 xpresspath.append(*xpress_lib_path);
280 return *xpress_load_status;
287 std::string xpress_lib_dir;
290 LOG(WARNING) << status <<
"\n";
296 if (xpress_oem_license_key == 0) {
309 LOG(WARNING) <<
"Optimizer version: " << version
310 <<
" (OR-Tools was compiled with version " <<
XPVERSION
321 LOG(WARNING) <<
"XpressInterface : Initialising xpress-MP with OEM key "
322 << xpress_oem_license_key;
327 char slicmsg[256] =
"";
332 DLOG(INFO) <<
"XpressInterface : First message from XPRSLicense : "
336 nvalue = xpress_oem_license_key - ((nvalue * nvalue) / 19);
340 DLOG(INFO) <<
"XpressInterface : Second message from XPRSLicense : "
346 <<
"XpressInterface : Optimizer development software detected";
348 }
else if (ierr != 0) {
352 LOG(ERROR) <<
"XpressInterface : " << errmsg;
361 LOG(ERROR) <<
"XPRSinit returned code : " << code <<
"\n";
367 LOG(WARNING) <<
"XpressInterface: Xpress found at " << xpress_lib_dir <<
"\n";
371 LOG(ERROR) <<
"XpressInterface : License error : " << errmsg
372 <<
" (XPRSinit returned code " << code <<
"). \n";
374 <<
"|_Your Xpress installation should have set the env var XPAUTH_PATH"
375 " to the full path of your licence file\n";
379 <<
"XpressInterface : Initialising xpress-MP with default parameters";
384 if (correctlyInstalled) {
387 return correctlyInstalled;
bool LibraryIsLoaded() const
std::function< T > GetFunction(const char *function_name)
bool TryToLoad(const absl::string_view library_name)
In SWIG mode, we don't want anything besides these top-level includes.
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 control)> XPRSsetdefaultcontrol
std::function< int(XPRSprob prob, int nrows, const int rowind[], const char rowtype[])> XPRSchgrowtype
std::function< int(char *banner)> XPRSgetbanner
absl::Status LoadXpressDynamicLibrary(std::string &xpresspath)
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 ncoefs, const int objqcol1[], const int objqcol2[], const double objqcoef[])> XPRSchgmqobj
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
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, 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(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
void log_message_about_XPRSinit_argument()
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, 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_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, const char *flags)> XPRSmipoptimize
std::function< int(XPRSprob prob, int nrows, const int rowind[], const double rhs[])> XPRSchgrhs
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
Copyright 2019-2023 RTE.
#define XPRS_CC
NOLINTEND(runtime/int)