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;
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 int start[],
const int collen[],
const int rowind[],
const double rowcoef[],
const double lb[],
const double ub[])>
XPRSloadlp =
nullptr;
66std::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;
75std::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;
77std::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;
78std::function<int(
XPRSprob prob,
int type,
const char names[],
int first,
int last)>
XPRSaddnames =
nullptr;
90std::function<int(
XPRSprob prob,
int nbounds,
const int colind[],
const char bndtype[],
const double bndval[])>
XPRSchgbounds =
nullptr;
91std::function<int(
XPRSprob prob,
int length,
const double solval[],
const int colind[],
const char* name)>
XPRSaddmipsol =
nullptr;
92std::function<int(
XPRSprob prob,
double x[],
double slack[],
double duals[],
double djs[])>
XPRSgetlpsol =
nullptr;
94std::function<int(
XPRSprob prob,
int ncols,
const int colind[],
const double objcoef[])>
XPRSchgobj =
nullptr;
96std::function<int(
XPRSprob prob,
int ncoefs,
const int rowind[],
const int colind[],
const double rowcoef[])>
XPRSchgmcoef =
nullptr;
98std::function<int(
XPRSprob prob,
int ncoefs,
const int objqcol1[],
const int objqcol2[],
const double objqcoef[])>
XPRSchgmqobj =
nullptr;
99std::function<int(
XPRSprob prob,
int nrows,
const int rowind[],
const double rhs[])>
XPRSchgrhs =
nullptr;
186 LOG(ERROR) <<
"XpressInterface : Xpress banner :\n" << banner <<
"\n";
188 LOG(WARNING) <<
"XpressInterface : Xpress banner :\n" << banner <<
"\n";
193 std::vector<std::string> potential_paths;
196 const char* xpressdir_from_env = getenv(
"XPRESSDIR");
197 if (xpressdir_from_env !=
nullptr) {
198 LOG(INFO) <<
"Environment variable XPRESSDIR = " << xpressdir_from_env;
200 potential_paths.push_back(
201 absl::StrCat(xpressdir_from_env,
"\\bin\\xprs.dll"));
202#elif defined(__APPLE__)
203 potential_paths.push_back(
204 absl::StrCat(xpressdir_from_env,
"/lib/libxprs.dylib"));
205#elif defined(__GNUC__)
206 potential_paths.push_back(
207 absl::StrCat(xpressdir_from_env,
"/lib/libxprs.so"));
209 LOG(ERROR) <<
"OS Not recognized by xpress/environment.cc."
210 <<
" You won't be able to use Xpress.";
213 LOG(WARNING) <<
"Environment variable XPRESSDIR undefined.";
218 potential_paths.push_back(absl::StrCat(
"C:\\xpressmp\\bin\\xprs.dll"));
219 potential_paths.push_back(
220 absl::StrCat(
"C:\\Program Files\\xpressmp\\bin\\xprs.dll"));
221#elif defined(__APPLE__)
222 potential_paths.push_back(
223 absl::StrCat(
"/Library/xpressmp/lib/libxprs.dylib"));
224#elif defined(__GNUC__)
225 potential_paths.push_back(absl::StrCat(
"/opt/xpressmp/lib/libxprs.so"));
227 LOG(ERROR) <<
"OS Not recognized by xpress/environment.cc."
228 <<
" You won't be able to use Xpress.";
230 return potential_paths;
234 static std::string xpress_lib_path;
235 static std::once_flag xpress_loading_done;
236 static absl::Status xpress_load_status;
238 static absl::Mutex mutex(absl::kConstInit);
240 absl::MutexLock lock(&mutex);
242 std::call_once(xpress_loading_done, []() {
243 const std::vector<std::string> canonical_paths =
245 for (
const std::string& path : canonical_paths) {
247 LOG(INFO) <<
"Found the Xpress library in " << path <<
".";
248 xpress_lib_path.clear();
249 std::filesystem::path p(path);
251 xpress_lib_path.append(p.string());
257 LOG(INFO) <<
"Loading all Xpress functions";
259 xpress_load_status = absl::OkStatus();
261 xpress_load_status = absl::NotFoundError(
262 absl::StrCat(
"Could not find the Xpress shared library. Looked in: [",
263 absl::StrJoin(canonical_paths,
"', '"),
264 "]. Please check environment variable XPRESSDIR"));
268 xpresspath.append(xpress_lib_path);
269 return xpress_load_status;
276 std::string xpress_lib_dir;
279 LOG(WARNING) << status <<
"\n";
285 if (xpress_oem_license_key == 0) {
298 LOG(WARNING) <<
"Optimizer version: " << version
299 <<
" (OR-Tools was compiled with version " <<
XPVERSION
310 LOG(WARNING) <<
"XpressInterface : Initialising xpress-MP with OEM key "
311 << xpress_oem_license_key <<
"\n";
316 char slicmsg[256] =
"";
321 VLOG(0) <<
"XpressInterface : First message from XPRSLicense : "
325 nvalue = xpress_oem_license_key - ((nvalue * nvalue) / 19);
329 VLOG(0) <<
"XpressInterface : Second message from XPRSLicense : "
335 <<
"XpressInterface : Optimizer development software detected\n";
337 }
else if (ierr != 0) {
341 LOG(ERROR) <<
"XpressInterface : " << errmsg <<
"\n";
350 LOG(ERROR) <<
"XPRSinit returned code : " << code <<
"\n";
356 LOG(WARNING) <<
"XpressInterface: Xpress found at " << xpress_lib_dir <<
"\n";
360 LOG(ERROR) <<
"XpressInterface : License error : " << errmsg
361 <<
" (XPRSinit returned code " << code <<
"). \n";
363 <<
"|_Your Xpress installation should have set the env var XPAUTH_PATH"
364 " to the full path of your licence file\n";
368 <<
"XpressInterface : Initialising xpress-MP with default parameters";
373 if (correctlyInstalled) {
376 return correctlyInstalled;
bool LibraryIsLoaded() const
std::function< T > GetFunction(const char *function_name)
bool TryToLoad(const std::string &library_name)
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, 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, 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, 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(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 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)> 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)
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, 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
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, const char *probname)> XPRSsetprobname
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.