Merge pull request #4030 from rte-france/fix/xpress-starting-basis-on-gmain

improve performance of Xpress interface and fix bug
This commit is contained in:
Laurent Perron
2023-12-26 16:54:27 +01:00
committed by GitHub
2 changed files with 27 additions and 3 deletions

View File

@@ -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()),
@@ -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;

View File

@@ -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");