Skip to content

Commit

Permalink
Merge pull request #4030 from rte-france/fix/xpress-starting-basis-on…
Browse files Browse the repository at this point in the history
…-gmain

improve performance of Xpress interface and fix bug
  • Loading branch information
lperron authored Dec 26, 2023
2 parents 505ceba + 46ffc70 commit c1b29b9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
5 changes: 2 additions & 3 deletions ortools/linear_solver/xpress_interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -840,8 +840,7 @@ XpressInterface::XpressInterface(MPSolver* const solver, bool mip)
mLp(nullptr),
mMip(mip),
supportIncrementalExtraction(false),
slowUpdates(static_cast<SlowUpdates>(SlowSetObjectiveCoefficient |
SlowClearObjective)),
slowUpdates(SlowClearObjective),
mapStringControls_(getMapStringControls()),
mapDoubleControls_(getMapDoubleControls()),
mapIntegerControls_(getMapIntControls()),
Expand Down Expand Up @@ -1728,7 +1727,7 @@ void XpressInterface::SetLpAlgorithm(int value) {
std::vector<int> XpressBasisStatusesFrom(
const std::vector<MPSolver::BasisStatus>& statuses) {
std::vector<int> result;
result.reserve(statuses.size());
result.resize(statuses.size());
std::transform(statuses.cbegin(), statuses.cend(), result.begin(),
MPSolverToXpressBasisStatus);
return result;
Expand Down
25 changes: 25 additions & 0 deletions ortools/linear_solver/xpress_interface_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,31 @@ TEST(XpressInterface, LpStartingBasis) {
EXPECT_LT(iterWithBasis, 10);
}

TEST(XpressInterface, LpStartingBasisNoIterationsIfBasisIsProvided) {
UNITTEST_INIT_LP();
buildLargeLp(solver, 1000);
// First, we record the number of iterations without an initial basis
solver.Solve();

// Then, we retrieve the final basis
std::vector<MPSolver::BasisStatus> varStatus, constrStatus;
for (auto* var : solver.variables()) {
varStatus.push_back(var->basis_status());
}
for (auto* constr : solver.constraints()) {
constrStatus.push_back(constr->basis_status());
}

MPSolver solver_BasisProvided("XPRESS_LP", MPSolver::XPRESS_LINEAR_PROGRAMMING);
buildLargeLp(solver_BasisProvided, 1000);
solver_BasisProvided.SetStartingLpBasis(varStatus, constrStatus);
solver_BasisProvided.Solve();
const auto iterWithBasis = solver_BasisProvided.iterations();
// ...and finally check that no iteration has been performed
EXPECT_EQ(iterWithBasis, 0);
}


TEST(XpressInterface, NumVariables) {
UNITTEST_INIT_MIP();
MPVariable* x1 = solver.MakeNumVar(-1., 5.1, "x1");
Expand Down

0 comments on commit c1b29b9

Please sign in to comment.