25#include "absl/status/status.h"
26#include "absl/strings/str_cat.h"
27#include "absl/strings/str_join.h"
28#include "absl/synchronization/mutex.h"
34#define STRINGIFY2(X) #X
35#define STRINGIFY(X) STRINGIFY2(X)
45std::function<int(
const char* path)>
XPRSinit =
nullptr;
64std::function<int(
XPRSprob prob,
const char* probname,
int ncols,
int nrows,
const char rowtype[],
const double rhs[],
const double rng[],
const double objcoef[],
const int start[],
const int collen[],
const int rowind[],
const double rowcoef[],
const double lb[],
const double ub[])>
XPRSloadlp =
nullptr;
65std::function<int(
XPRSprob prob,
const char* probname,
int ncols,
int nrows,
const char rowtype[],
const double rhs[],
const double rng[],
const double objcoef[],
const XPRSint64 start[],
const int collen[],
const int rowind[],
const double rowcoef[],
const double lb[],
const double ub[])>
XPRSloadlp64 =
nullptr;
72std::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;
74std::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;
75std::function<int(
XPRSprob prob,
int type,
const char names[],
int first,
int last)>
XPRSaddnames =
nullptr;
87std::function<int(
XPRSprob prob,
int nbounds,
const int colind[],
const char bndtype[],
const double bndval[])>
XPRSchgbounds =
nullptr;
89std::function<int(
XPRSprob prob,
double x[],
double slack[],
double duals[],
double djs[])>
XPRSgetlpsol =
nullptr;
91std::function<int(
XPRSprob prob,
int ncols,
const int colind[],
const double objcoef[])>
XPRSchgobj =
nullptr;
93std::function<int(
XPRSprob prob,
int ncoefs,
const int rowind[],
const int colind[],
const double rowcoef[])>
XPRSchgmcoef =
nullptr;
94std::function<int(
XPRSprob prob,
int nrows,
const int rowind[],
const double rhs[])>
XPRSchgrhs =
nullptr;
174 LOG(ERROR) <<
"XpressInterface : Xpress banner :\n" << banner <<
"\n";
176 LOG(WARNING) <<
"XpressInterface : Xpress banner :\n" << banner <<
"\n";
181 std::vector<std::string> potential_paths;
184 const char* xpressdir_from_env = getenv(
"XPRESSDIR");
185 if (xpressdir_from_env !=
nullptr) {
186 LOG(INFO) <<
"Environment variable XPRESSDIR = " << xpressdir_from_env;
188 potential_paths.push_back(
189 absl::StrCat(xpressdir_from_env,
"\\bin\\xprs.dll"));
190#elif defined(__APPLE__)
191 potential_paths.push_back(
192 absl::StrCat(xpressdir_from_env,
"/lib/libxprs.dylib"));
193#elif defined(__GNUC__)
194 potential_paths.push_back(
195 absl::StrCat(xpressdir_from_env,
"/lib/libxprs.so"));
197 LOG(ERROR) <<
"OS Not recognized by xpress/environment.cc."
198 <<
" You won't be able to use Xpress.";
201 LOG(WARNING) <<
"Environment variable XPRESSDIR undefined.";
206 potential_paths.push_back(absl::StrCat(
"C:\\xpressmp\\bin\\xprs.dll"));
207 potential_paths.push_back(
208 absl::StrCat(
"C:\\Program Files\\xpressmp\\bin\\xprs.dll"));
209#elif defined(__APPLE__)
210 potential_paths.push_back(
211 absl::StrCat(
"/Library/xpressmp/lib/libxprs.dylib"));
212#elif defined(__GNUC__)
213 potential_paths.push_back(absl::StrCat(
"/opt/xpressmp/lib/libxprs.so"));
215 LOG(ERROR) <<
"OS Not recognized by xpress/environment.cc."
216 <<
" You won't be able to use Xpress.";
218 return potential_paths;
222 static std::string xpress_lib_path;
223 static std::once_flag xpress_loading_done;
224 static absl::Status xpress_load_status;
226 static absl::Mutex mutex(absl::kConstInit);
228 absl::MutexLock lock(&mutex);
230 std::call_once(xpress_loading_done, []() {
231 const std::vector<std::string> canonical_paths =
233 for (
const std::string& path : canonical_paths) {
235 LOG(INFO) <<
"Found the Xpress library in " << path <<
".";
236 xpress_lib_path.clear();
237 std::filesystem::path p(path);
239 xpress_lib_path.append(p.string());
245 LOG(INFO) <<
"Loading all Xpress functions";
247 xpress_load_status = absl::OkStatus();
249 xpress_load_status = absl::NotFoundError(
250 absl::StrCat(
"Could not find the Xpress shared library. Looked in: [",
251 absl::StrJoin(canonical_paths,
"', '"),
252 "]. Please check environment variable XPRESSDIR"));
256 xpresspath.append(xpress_lib_path);
257 return xpress_load_status;
264 std::string xpress_lib_dir;
267 LOG(WARNING) <<
status <<
"\n";
273 if (xpress_oem_license_key == 0) {
286 LOG(WARNING) <<
"Optimizer version: " << version
287 <<
" (OR-Tools was compiled with version " <<
XPVERSION
298 LOG(WARNING) <<
"XpressInterface : Initialising xpress-MP with OEM key "
299 << xpress_oem_license_key <<
"\n";
304 char slicmsg[256] =
"";
309 VLOG(0) <<
"XpressInterface : First message from XPRSLicense : "
313 nvalue = xpress_oem_license_key - ((nvalue * nvalue) / 19);
317 VLOG(0) <<
"XpressInterface : Second message from XPRSLicense : "
323 <<
"XpressInterface : Optimizer development software detected\n";
325 }
else if (ierr != 0) {
329 LOG(ERROR) <<
"XpressInterface : " << errmsg <<
"\n";
338 LOG(ERROR) <<
"XPRSinit returned code : " << code <<
"\n";
344 LOG(WARNING) <<
"XpressInterface: Xpress found at " << xpress_lib_dir <<
"\n";
348 LOG(ERROR) <<
"XpressInterface : License error : " << errmsg
349 <<
" (XPRSinit returned code " << code <<
"). \n";
351 <<
"|_Your Xpress installation should have set the env var XPAUTH_PATH"
352 " to the full path of your licence file\n";
356 <<
"XpressInterface : Initialising xpress-MP with default parameters";
361 if (correctlyInstalled) {
364 return correctlyInstalled;
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.
In SWIG mode, we don't want anything besides these top-level includes.
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, double lb[], int first, int last)> XPRSgetlb
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
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, 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 row, int col, double *p_coef)> XPRSgetcoef
std::function< int(XPRSprob prob, int control, XPRSint64 *p_value)> XPRSgetintcontrol64
std::function< int(XPRSprob prob, const char *probname, int ncols, int nrows, const char rowtype[], const double rhs[], const double rng[], const double objcoef[], const XPRSint64 start[], const int collen[], const int rowind[], const double rowcoef[], const double lb[], const double ub[])> XPRSloadlp64
std::function< int(XPRSprob prob, double rng[], int first, int last)> XPRSgetrhsrange
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, char rowtype[], int first, int last)> XPRSgetrowtype
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 rhs[], int first, int last)> XPRSgetrhs
std::function< int(XPRSprob prob, double x[], double slack[], double duals[], double djs[])> XPRSgetlpsol
std::function< int(XPRSprob prob)> XPRSpostsolve
std::function< int(XPRSprob prob, int control, int *p_value)> XPRSgetintcontrol
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(XPRSprob prob, const char *probname, int ncols, int nrows, const char rowtype[], const double rhs[], const double rng[], const double objcoef[], const int start[], const int collen[], const int rowind[], const double rowcoef[], const double lb[], const double ub[])> XPRSloadlp
std::function< int(void)> XPRSfree
std::function< int(XPRSprob prob, int control, double *p_value)> XPRSgetdblcontrol
std::function< int(XPRSprob prob, int reason)> XPRSinterrupt
bool XpressIsCorrectlyInstalled()
std::function< int(char *buffer, int maxbytes)> XPRSgetlicerrmsg
std::function< int(XPRSprob prob, int attrib, double *p_value)> XPRSgetdblattrib
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, int attrib, int *p_value)> XPRSgetintattrib
std::function< int(XPRSprob prob, char *errmsg)> XPRSgetlasterror
std::function< int(XPRSprob prob)> XPRSdestroyprob
std::function< int(XPRSprob prob, char coltype[], int first, int last)> XPRSgetcoltype
std::function< int(XPRSprob prob, int control, double value)> XPRSsetdblcontrol
std::function< int(XPRSprob prob, double objcoef[], int first, int last)> XPRSgetobj
std::function< int(XPRSprob prob, double ub[], int first, int last)> XPRSgetub
void printXpressBanner(bool error)
clang-format on
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, const char *flags)> XPRSmipoptimize
std::function< int(XPRSprob prob, int control, char *value, int maxbytes, int *p_nbytes)> XPRSgetstringcontrol
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::vector< std::string > XpressDynamicLibraryPotentialPaths()
std::function< int(XPRSprob *p_prob)> XPRScreateprob
This is the 'define' section.
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, int rowstat[], int colstat[])> XPRSgetbasis
#define XPRS_MAXBANNERLENGTH
struct xo_prob_struct * XPRSprob
Initial version of this code was provided by RTE.