2929#include " absl/strings/str_join.h"
3030#include " absl/synchronization/mutex.h"
3131#include " ortools/base/logging.h"
32+ #include " ortools/base/status_builder.h"
3233#include " ortools/third_party_solvers/dynamic_library.h"
3334
3435namespace operations_research {
@@ -52,34 +53,44 @@ std::function<int(char* buffer, int maxbytes)> XPRSgetlicerrmsg = nullptr;
5253std::function<int (int * p_i, char * p_c)> XPRSlicense = nullptr ;
5354std::function<int (char * banner)> XPRSgetbanner = nullptr ;
5455std::function<int (char * version)> XPRSgetversion = nullptr ;
56+ std::function<int (int *p_major, int *p_minor, int *p_build)> XPRSgetversionnumbers = nullptr ;
5557std::function<int (XPRSprob prob, const char * probname)> XPRSsetprobname = nullptr ;
5658std::function<int (XPRSprob prob, int control)> XPRSsetdefaultcontrol = nullptr ;
5759std::function<int (XPRSprob prob, int reason)> XPRSinterrupt = nullptr ;
5860std::function<int (XPRSprob prob, int control, int value)> XPRSsetintcontrol = nullptr ;
5961std::function<int (XPRSprob prob, int control, XPRSint64 value)> XPRSsetintcontrol64 = nullptr ;
6062std::function<int (XPRSprob prob, int control, double value)> XPRSsetdblcontrol = nullptr ;
6163std::function<int (XPRSprob prob, int control, const char * value)> XPRSsetstrcontrol = nullptr ;
64+ std::function<int (XPRSprob prob, int objidx, int control, int value)> XPRSsetobjintcontrol = nullptr ;
65+ std::function<int (XPRSprob prob, int objidx, int control, double value)> XPRSsetobjdblcontrol = nullptr ;
6266std::function<int (XPRSprob prob, int control, int * p_value)> XPRSgetintcontrol = nullptr ;
6367std::function<int (XPRSprob prob, int control, XPRSint64* p_value)> XPRSgetintcontrol64 = nullptr ;
6468std::function<int (XPRSprob prob, int control, double * p_value)> XPRSgetdblcontrol = nullptr ;
6569std::function<int (XPRSprob prob, int control, char * value, int maxbytes, int * p_nbytes)> XPRSgetstringcontrol = nullptr ;
6670std::function<int (XPRSprob prob, int attrib, int * p_value)> XPRSgetintattrib = nullptr ;
6771std::function<int (XPRSprob prob, int attrib, char * value, int maxbytes, int * p_nbytes)> XPRSgetstringattrib = nullptr ;
6872std::function<int (XPRSprob prob, int attrib, double * p_value)> XPRSgetdblattrib = nullptr ;
73+ std::function<int (XPRSprob prob, int objidx, int attrib, double * p_value)> XPRSgetobjdblattrib = nullptr ;
74+ std::function<int (XPRSprob prob, int objidx, const double solution[], double * p_objval)> XPRScalcobjn = nullptr ;
6975std::function<int (XPRSprob prob, const char * name, int * p_id, int * p_type)> XPRSgetcontrolinfo = nullptr ;
7076std::function<int (XPRSprob prob, double objcoef[], int first, int last)> XPRSgetobj = nullptr ;
7177std::function<int (XPRSprob prob, double rhs[], int first, int last)> XPRSgetrhs = nullptr ;
7278std::function<int (XPRSprob prob, double rng[], int first, int last)> XPRSgetrhsrange = nullptr ;
7379std::function<int (XPRSprob prob, double lb[], int first, int last)> XPRSgetlb = nullptr ;
7480std::function<int (XPRSprob prob, double ub[], int first, int last)> XPRSgetub = nullptr ;
7581std::function<int (XPRSprob prob, int row, int col, double * p_coef)> XPRSgetcoef = nullptr ;
82+ std::function<int (XPRSprob prob, int * status, double x[], int first, int last)> XPRSgetsolution = nullptr ;
7683std::function<int (XPRSprob prob, int * status, double duals[], int first, int last)> XPRSgetduals = nullptr ;
7784std::function<int (XPRSprob prob, int * status, double djs[], int first, int last)> XPRSgetredcosts = nullptr ;
7885std::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 ;
86+ 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 = nullptr ;
7987std::function<int (XPRSprob prob, int nrows, const int rowind[])> XPRSdelrows = nullptr ;
8088std::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 ;
89+ std::function<int (XPRSprob prob, int ncols, const int colind[], const double objcoef[], int priority, double weight)> XPRSaddobj = nullptr ;
90+ std::function<int (XPRSprob prob, int row, int ncoefs, const int rowqcol1[], int const rowqcol2[], const double rowqcoef[])> XPRSaddqmatrix64 = nullptr ;
8191std::function<int (XPRSprob prob, int type, const char names[], int first, int last)> XPRSaddnames = nullptr ;
8292std::function<int (XPRSprob prob, int type, char names[], int first, int last)> XPRSgetnames = nullptr ;
93+ std::function<int (XPRSprob prob, int nsets, XPRSint64 nelems, const char settype[], const XPRSint64 start[], const int colind[], const double refval[])> XPRSaddsets64 = nullptr ;
8394std::function<int (XPRSprob prob, int ncols, const int colind[])> XPRSdelcols = nullptr ;
8495std::function<int (XPRSprob prob, int ncols, const int colind[], const char coltype[])> XPRSchgcoltype = nullptr ;
8596std::function<int (XPRSprob prob, const int rowstat[], const int colstat[])> XPRSloadbasis = nullptr ;
@@ -88,11 +99,14 @@ std::function<int(XPRSprob prob, int objsense)> XPRSchgobjsense = nullptr;
8899std::function<int (XPRSprob prob, char * errmsg)> XPRSgetlasterror = nullptr ;
89100std::function<int (XPRSprob prob, int rowstat[], int colstat[])> XPRSgetbasis = nullptr ;
90101std::function<int (XPRSprob prob, const char * filename, const char * flags)> XPRSwriteprob = nullptr ;
102+ std::function<int (XPRSprob prob, const char * filename)> XPRSsaveas = nullptr ;
91103std::function<int (XPRSprob prob, char rowtype[], int first, int last)> XPRSgetrowtype = nullptr ;
92104std::function<int (XPRSprob prob, char coltype[], int first, int last)> XPRSgetcoltype = nullptr ;
93105std::function<int (XPRSprob prob, int nbounds, const int colind[], const char bndtype[], const double bndval[])> XPRSchgbounds = nullptr ;
94106std::function<int (XPRSprob prob, int length, const double solval[], const int colind[], const char * name)> XPRSaddmipsol = nullptr ;
95107std::function<int (XPRSprob prob, int nrows, const int rowind[])> XPRSloaddelayedrows = nullptr ;
108+ std::function<int (XPRSprob prob, int nrows, const int rowind[], const int colind[], const int complement[])> XPRSsetindicators = nullptr ;
109+ std::function<int (XPRSprob prob, int ndirs, const int colind[], const int priority[], const char dir[], const double uppseudo[], const double downpseudo[])> XPRSloaddirs;
96110std::function<int (XPRSprob prob, double x[], double slack[], double duals[], double djs[])> XPRSgetlpsol = nullptr ;
97111std::function<int (XPRSprob prob, double x[], double slack[])> XPRSgetmipsol = nullptr ;
98112std::function<int (XPRSprob prob, int ncols, const int colind[], const double objcoef[])> XPRSchgobj = nullptr ;
@@ -107,6 +121,9 @@ std::function<int(XPRSprob prob, int objidx)> XPRSdelobj = nullptr;
107121std::function<int (XPRSprob prob, void (XPRS_CC *f_intsol)(XPRSprob cbprob, void * cbdata), void * p, int priority)> XPRSaddcbintsol = nullptr ;
108122std::function<int (XPRSprob prob, void (XPRS_CC *f_intsol)(XPRSprob cbprob, void * cbdata), void * p)> XPRSremovecbintsol = nullptr ;
109123std::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 = nullptr ;
124+ std::function<int (XPRSprob prob, void (XPRS_CC *f_message)(XPRSprob cbprob, void * cbdata, const char * msg, int msglen, int msgtype), void * p)> XPRSremovecbmessage = nullptr ;
125+ std::function<int (XPRSprob prob, int (XPRS_CC *f_checktime)(XPRSprob cbprob, void * cbdata), void * p, int priority)> XPRSaddcbchecktime = nullptr ;
126+ std::function<int (XPRSprob prob, int (XPRS_CC *f_checktime)(XPRSprob cbprob, void * cbdata), void * p)> XPRSremovecbchecktime = nullptr ;
110127std::function<int (XPRSprob prob, const char * flags)> XPRSlpoptimize = nullptr ;
111128std::function<int (XPRSprob prob, const char * flags)> XPRSmipoptimize = nullptr ;
112129std::function<int (XPRSprob prob, const char * flags, int * solvestatus, int * solstatus)> XPRSoptimize = nullptr ;
@@ -129,33 +146,45 @@ void LoadXpressFunctions(DynamicLibrary* xpress_dynamic_library) {
129146 xpress_dynamic_library->GetFunction (&XPRSlicense, " XPRSlicense" );
130147 xpress_dynamic_library->GetFunction (&XPRSgetbanner, " XPRSgetbanner" );
131148 xpress_dynamic_library->GetFunction (&XPRSgetversion, " XPRSgetversion" );
149+ xpress_dynamic_library->GetFunction (&XPRSgetversionnumbers, " XPRSgetversionnumbers" );
132150 xpress_dynamic_library->GetFunction (&XPRSsetprobname, " XPRSsetprobname" );
133151 xpress_dynamic_library->GetFunction (&XPRSsetdefaultcontrol, " XPRSsetdefaultcontrol" );
134152 xpress_dynamic_library->GetFunction (&XPRSinterrupt, " XPRSinterrupt" );
135153 xpress_dynamic_library->GetFunction (&XPRSsetintcontrol, " XPRSsetintcontrol" );
136154 xpress_dynamic_library->GetFunction (&XPRSsetintcontrol64, " XPRSsetintcontrol64" );
137155 xpress_dynamic_library->GetFunction (&XPRSsetdblcontrol, " XPRSsetdblcontrol" );
138156 xpress_dynamic_library->GetFunction (&XPRSsetstrcontrol, " XPRSsetstrcontrol" );
157+ xpress_dynamic_library->GetFunction (&XPRSsetobjintcontrol, " XPRSsetobjintcontrol" );
158+ xpress_dynamic_library->GetFunction (&XPRSsetobjdblcontrol, " XPRSsetobjdblcontrol" );
139159 xpress_dynamic_library->GetFunction (&XPRSgetintcontrol, " XPRSgetintcontrol" );
140160 xpress_dynamic_library->GetFunction (&XPRSgetintcontrol64, " XPRSgetintcontrol64" );
141161 xpress_dynamic_library->GetFunction (&XPRSgetdblcontrol, " XPRSgetdblcontrol" );
142162 xpress_dynamic_library->GetFunction (&XPRSgetstringcontrol, " XPRSgetstringcontrol" );
143163 xpress_dynamic_library->GetFunction (&XPRSgetintattrib, " XPRSgetintattrib" );
144164 xpress_dynamic_library->GetFunction (&XPRSgetstringattrib, " XPRSgetstringattrib" );
145165 xpress_dynamic_library->GetFunction (&XPRSgetdblattrib, " XPRSgetdblattrib" );
166+ xpress_dynamic_library->GetFunction (&XPRSgetobjdblattrib, " XPRSgetobjdblattrib" );
167+ xpress_dynamic_library->GetFunction (&XPRScalcobjn, " XPRScalcobjn" );
168+ xpress_dynamic_library->GetFunction (&XPRSgetcontrolinfo, " XPRSgetcontrolinfo" );
146169 xpress_dynamic_library->GetFunction (&XPRSgetobj, " XPRSgetobj" );
147170 xpress_dynamic_library->GetFunction (&XPRSgetrhs, " XPRSgetrhs" );
148171 xpress_dynamic_library->GetFunction (&XPRSgetrhsrange, " XPRSgetrhsrange" );
149172 xpress_dynamic_library->GetFunction (&XPRSgetlb, " XPRSgetlb" );
150173 xpress_dynamic_library->GetFunction (&XPRSgetub, " XPRSgetub" );
151174 xpress_dynamic_library->GetFunction (&XPRSgetcoef, " XPRSgetcoef" );
175+ xpress_dynamic_library->GetFunction (&XPRSgetsolution, " XPRSgetsolution" );
152176 xpress_dynamic_library->GetFunction (&XPRSgetduals, " XPRSgetduals" );
153177 xpress_dynamic_library->GetFunction (&XPRSgetredcosts, " XPRSgetredcosts" );
154178 xpress_dynamic_library->GetFunction (&XPRSaddrows, " XPRSaddrows" );
179+ xpress_dynamic_library->GetFunction (&XPRSaddrows64, " XPRSaddrows64" );
155180 xpress_dynamic_library->GetFunction (&XPRSdelrows, " XPRSdelrows" );
181+ xpress_dynamic_library->GetFunction (&XPRSdelobj, " XPRSdelobj" );
156182 xpress_dynamic_library->GetFunction (&XPRSaddcols, " XPRSaddcols" );
183+ xpress_dynamic_library->GetFunction (&XPRSaddobj, " XPRSaddobj" );
184+ xpress_dynamic_library->GetFunction (&XPRSaddqmatrix64, " XPRSaddqmatrix64" );
157185 xpress_dynamic_library->GetFunction (&XPRSaddnames, " XPRSaddnames" );
158186 xpress_dynamic_library->GetFunction (&XPRSgetnames, " XPRSgetnames" );
187+ xpress_dynamic_library->GetFunction (&XPRSaddsets64, " XPRSaddsets64" );
159188 xpress_dynamic_library->GetFunction (&XPRSdelcols, " XPRSdelcols" );
160189 xpress_dynamic_library->GetFunction (&XPRSchgcoltype, " XPRSchgcoltype" );
161190 xpress_dynamic_library->GetFunction (&XPRSloadbasis, " XPRSloadbasis" );
@@ -164,11 +193,14 @@ void LoadXpressFunctions(DynamicLibrary* xpress_dynamic_library) {
164193 xpress_dynamic_library->GetFunction (&XPRSgetlasterror, " XPRSgetlasterror" );
165194 xpress_dynamic_library->GetFunction (&XPRSgetbasis, " XPRSgetbasis" );
166195 xpress_dynamic_library->GetFunction (&XPRSwriteprob, " XPRSwriteprob" );
196+ xpress_dynamic_library->GetFunction (&XPRSsaveas, " XPRSsaveas" );
167197 xpress_dynamic_library->GetFunction (&XPRSgetrowtype, " XPRSgetrowtype" );
168198 xpress_dynamic_library->GetFunction (&XPRSgetcoltype, " XPRSgetcoltype" );
169199 xpress_dynamic_library->GetFunction (&XPRSchgbounds, " XPRSchgbounds" );
170200 xpress_dynamic_library->GetFunction (&XPRSaddmipsol, " XPRSaddmipsol" );
171201 xpress_dynamic_library->GetFunction (&XPRSloaddelayedrows, " XPRSloaddelayedrows" );
202+ xpress_dynamic_library->GetFunction (&XPRSsetindicators, " XPRSsetindicators" );
203+ xpress_dynamic_library->GetFunction (&XPRSloaddirs, " XPRSloaddirs" );
172204 xpress_dynamic_library->GetFunction (&XPRSgetlpsol, " XPRSgetlpsol" );
173205 xpress_dynamic_library->GetFunction (&XPRSgetmipsol, " XPRSgetmipsol" );
174206 xpress_dynamic_library->GetFunction (&XPRSchgobj, " XPRSchgobj" );
@@ -183,6 +215,9 @@ void LoadXpressFunctions(DynamicLibrary* xpress_dynamic_library) {
183215 xpress_dynamic_library->GetFunction (&XPRSaddcbintsol, " XPRSaddcbintsol" );
184216 xpress_dynamic_library->GetFunction (&XPRSremovecbintsol, " XPRSremovecbintsol" );
185217 xpress_dynamic_library->GetFunction (&XPRSaddcbmessage, " XPRSaddcbmessage" );
218+ xpress_dynamic_library->GetFunction (&XPRSremovecbmessage, " XPRSremovecbmessage" );
219+ xpress_dynamic_library->GetFunction (&XPRSaddcbchecktime, " XPRSaddcbchecktime" );
220+ xpress_dynamic_library->GetFunction (&XPRSremovecbchecktime, " XPRSremovecbchecktime" );
186221 xpress_dynamic_library->GetFunction (&XPRSlpoptimize, " XPRSlpoptimize" );
187222 xpress_dynamic_library->GetFunction (&XPRSmipoptimize, " XPRSmipoptimize" );
188223 xpress_dynamic_library->GetFunction (&XPRSoptimize, " XPRSoptimize" );
@@ -268,7 +303,21 @@ absl::Status LoadXpressDynamicLibrary(std::string& xpresspath) {
268303 if (xpress_library->LibraryIsLoaded ()) {
269304 LOG (INFO) << " Loading all Xpress functions" ;
270305 LoadXpressFunctions (xpress_library);
271- *xpress_load_status = absl::OkStatus ();
306+ // Make sure the library we just loaded is recent enough.
307+ int major = -1 , minor = -1 , build = -1 ;
308+ if (!XPRSgetversionnumbers ||
309+ XPRSgetversionnumbers (&major, &minor, &build) != 0 )
310+ *xpress_load_status =
311+ util::StatusBuilder (absl::StatusCode::kNotFound )
312+ << " Xpress optimizer library too old, need at least version "
313+ << XPVERSION;
314+ else if (major < XPVERSION)
315+ *xpress_load_status = util::StatusBuilder (absl::StatusCode::kNotFound )
316+ << " Xpress optimizer library version " << major
317+ << " too old, need at least version "
318+ << XPVERSION;
319+ else
320+ *xpress_load_status = absl::OkStatus ();
272321 } else {
273322 *xpress_load_status = absl::NotFoundError (
274323 absl::StrCat (" Could not find the Xpress shared library. Looked in: [" ,
0 commit comments