Skip to content

Commit c0070c2

Browse files
authored
Merge pull request #4910 from rte-france/feature/mpsolver_xpr_lazy
[MPSolver] Add lazy constraints support in XPRESS interface]
2 parents a12f870 + 6573a83 commit c0070c2

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

ortools/linear_solver/xpress_interface.cc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ class XpressMPCallbackContext : public MPCallbackContext {
233233
};
234234
void AddLazyConstraint(const LinearRange& lazy_constraint) override {
235235
LOG(WARNING)
236-
<< "AddLazyConstraint is not implemented yet in XPRESS interface";
236+
<< "AddLazyConstraint inside Callback is not implemented yet in XPRESS interface";
237237
};
238238
double SuggestSolution(
239239
const absl::flat_hash_map<const MPVariable*, double>& solution) override;
@@ -1541,7 +1541,7 @@ void XpressInterface::ExtractNewConstraints() {
15411541
unique_ptr<char[]> sense(new char[chunk]);
15421542
unique_ptr<double[]> rhs(new double[chunk]);
15431543
unique_ptr<double[]> rngval(new double[chunk]);
1544-
1544+
std::vector<int> delayedRows;
15451545
// Loop over the new constraints, collecting rows for up to
15461546
// CHUNK constraints into the arrays so that adding constraints
15471547
// is faster.
@@ -1575,12 +1575,19 @@ void XpressInterface::ExtractNewConstraints() {
15751575
++nextNz;
15761576
}
15771577
}
1578+
if (ct->is_lazy()) {
1579+
delayedRows.push_back(offset + c);
1580+
}
15781581
}
15791582
if (nextRow > 0) {
15801583
CHECK_STATUS(XPRSaddrows(mLp, nextRow, nextNz, sense.get(), rhs.get(),
15811584
rngval.get(), rmatbeg.get(), rmatind.get(),
15821585
rmatval.get()));
15831586
}
1587+
if (!delayedRows.empty()) {
1588+
CHECK_STATUS(XPRSloaddelayedrows(
1589+
mLp, static_cast<int>(delayedRows.size()), delayedRows.data()));
1590+
}
15841591
}
15851592
} catch (...) {
15861593
// Undo all changes in case of error.

ortools/third_party_solvers/xpress_environment.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ std::function<int(XPRSprob prob, char rowtype[], int first, int last)> XPRSgetro
9292
std::function<int(XPRSprob prob, char coltype[], int first, int last)> XPRSgetcoltype = nullptr;
9393
std::function<int(XPRSprob prob, int nbounds, const int colind[], const char bndtype[], const double bndval[])> XPRSchgbounds = nullptr;
9494
std::function<int(XPRSprob prob, int length, const double solval[], const int colind[], const char* name)> XPRSaddmipsol = nullptr;
95+
std::function<int(XPRSprob prob, int nrows, const int rowind[])> XPRSloaddelayedrows = nullptr;
9596
std::function<int(XPRSprob prob, double x[], double slack[], double duals[], double djs[])> XPRSgetlpsol = nullptr;
9697
std::function<int(XPRSprob prob, double x[], double slack[])> XPRSgetmipsol = nullptr;
9798
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) {
167168
xpress_dynamic_library->GetFunction(&XPRSgetcoltype, "XPRSgetcoltype");
168169
xpress_dynamic_library->GetFunction(&XPRSchgbounds, "XPRSchgbounds");
169170
xpress_dynamic_library->GetFunction(&XPRSaddmipsol, "XPRSaddmipsol");
171+
xpress_dynamic_library->GetFunction(&XPRSloaddelayedrows, "XPRSloaddelayedrows");
170172
xpress_dynamic_library->GetFunction(&XPRSgetlpsol, "XPRSgetlpsol");
171173
xpress_dynamic_library->GetFunction(&XPRSgetmipsol, "XPRSgetmipsol");
172174
xpress_dynamic_library->GetFunction(&XPRSchgobj, "XPRSchgobj");

ortools/third_party_solvers/xpress_environment.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,7 @@ OR_DLL extern std::function<int(XPRSprob prob, char rowtype[], int first, int la
525525
OR_DLL extern std::function<int(XPRSprob prob, char coltype[], int first, int last)> XPRSgetcoltype;
526526
extern std::function<int(XPRSprob prob, int nbounds, const int colind[], const char bndtype[], const double bndval[])> XPRSchgbounds;
527527
extern std::function<int(XPRSprob prob, int length, const double solval[], const int colind[], const char* name)> XPRSaddmipsol;
528+
extern std::function<int(XPRSprob prob, int nrows, const int rowind[])> XPRSloaddelayedrows;
528529
extern std::function<int(XPRSprob prob, double x[], double slack[], double duals[], double djs[])> XPRSgetlpsol;
529530
extern std::function<int(XPRSprob prob, double x[], double slack[])> XPRSgetmipsol;
530531
extern std::function<int(XPRSprob prob, int ncols, const int colind[], const double objcoef[])> XPRSchgobj;

0 commit comments

Comments
 (0)