[MPSolver] Add lazy constraints support in XPRESS interface]
This commit is contained in:
committed by
Corentin Le Molgat
parent
f204b720b8
commit
9d8573a21a
@@ -233,7 +233,7 @@ class XpressMPCallbackContext : public MPCallbackContext {
|
||||
};
|
||||
void AddLazyConstraint(const LinearRange& lazy_constraint) override {
|
||||
LOG(WARNING)
|
||||
<< "AddLazyConstraint is not implemented yet in XPRESS interface";
|
||||
<< "AddLazyConstraint inside Callback is not implemented yet in XPRESS interface";
|
||||
};
|
||||
double SuggestSolution(
|
||||
const absl::flat_hash_map<const MPVariable*, double>& solution) override;
|
||||
@@ -1541,7 +1541,7 @@ void XpressInterface::ExtractNewConstraints() {
|
||||
unique_ptr<char[]> sense(new char[chunk]);
|
||||
unique_ptr<double[]> rhs(new double[chunk]);
|
||||
unique_ptr<double[]> rngval(new double[chunk]);
|
||||
|
||||
std::vector<int> delayedRows;
|
||||
// Loop over the new constraints, collecting rows for up to
|
||||
// CHUNK constraints into the arrays so that adding constraints
|
||||
// is faster.
|
||||
@@ -1575,12 +1575,19 @@ void XpressInterface::ExtractNewConstraints() {
|
||||
++nextNz;
|
||||
}
|
||||
}
|
||||
if (ct->is_lazy()) {
|
||||
delayedRows.push_back(offset + c);
|
||||
}
|
||||
}
|
||||
if (nextRow > 0) {
|
||||
CHECK_STATUS(XPRSaddrows(mLp, nextRow, nextNz, sense.get(), rhs.get(),
|
||||
rngval.get(), rmatbeg.get(), rmatind.get(),
|
||||
rmatval.get()));
|
||||
}
|
||||
if (!delayedRows.empty()) {
|
||||
CHECK_STATUS(XPRSloaddelayedrows(
|
||||
mLp, static_cast<int>(delayedRows.size()), delayedRows.data()));
|
||||
}
|
||||
}
|
||||
} catch (...) {
|
||||
// Undo all changes in case of error.
|
||||
|
||||
@@ -92,6 +92,7 @@ std::function<int(XPRSprob prob, char rowtype[], int first, int last)> XPRSgetro
|
||||
std::function<int(XPRSprob prob, char coltype[], int first, int last)> XPRSgetcoltype = nullptr;
|
||||
std::function<int(XPRSprob prob, int nbounds, const int colind[], const char bndtype[], const double bndval[])> XPRSchgbounds = nullptr;
|
||||
std::function<int(XPRSprob prob, int length, const double solval[], const int colind[], const char* name)> XPRSaddmipsol = nullptr;
|
||||
std::function<int(XPRSprob prob, int nrows, const int rowind[])> XPRSloaddelayedrows = nullptr;
|
||||
std::function<int(XPRSprob prob, double x[], double slack[], double duals[], double djs[])> XPRSgetlpsol = nullptr;
|
||||
std::function<int(XPRSprob prob, double x[], double slack[])> XPRSgetmipsol = nullptr;
|
||||
std::function<int(XPRSprob prob, int ncols, const int colind[], const double objcoef[])> XPRSchgobj = nullptr;
|
||||
@@ -167,6 +168,7 @@ void LoadXpressFunctions(DynamicLibrary* xpress_dynamic_library) {
|
||||
xpress_dynamic_library->GetFunction(&XPRSgetcoltype, "XPRSgetcoltype");
|
||||
xpress_dynamic_library->GetFunction(&XPRSchgbounds, "XPRSchgbounds");
|
||||
xpress_dynamic_library->GetFunction(&XPRSaddmipsol, "XPRSaddmipsol");
|
||||
xpress_dynamic_library->GetFunction(&XPRSloaddelayedrows, "XPRSloaddelayedrows");
|
||||
xpress_dynamic_library->GetFunction(&XPRSgetlpsol, "XPRSgetlpsol");
|
||||
xpress_dynamic_library->GetFunction(&XPRSgetmipsol, "XPRSgetmipsol");
|
||||
xpress_dynamic_library->GetFunction(&XPRSchgobj, "XPRSchgobj");
|
||||
|
||||
@@ -525,6 +525,7 @@ OR_DLL extern std::function<int(XPRSprob prob, char rowtype[], int first, int la
|
||||
OR_DLL extern std::function<int(XPRSprob prob, char coltype[], int first, int last)> XPRSgetcoltype;
|
||||
extern std::function<int(XPRSprob prob, int nbounds, const int colind[], const char bndtype[], const double bndval[])> XPRSchgbounds;
|
||||
extern std::function<int(XPRSprob prob, int length, const double solval[], const int colind[], const char* name)> XPRSaddmipsol;
|
||||
extern std::function<int(XPRSprob prob, int nrows, const int rowind[])> XPRSloaddelayedrows;
|
||||
extern std::function<int(XPRSprob prob, double x[], double slack[], double duals[], double djs[])> XPRSgetlpsol;
|
||||
extern std::function<int(XPRSprob prob, double x[], double slack[])> XPRSgetmipsol;
|
||||
extern std::function<int(XPRSprob prob, int ncols, const int colind[], const double objcoef[])> XPRSchgobj;
|
||||
|
||||
Reference in New Issue
Block a user