From 24e8d5b2c5eb643cc5e609a8d6ec5d4c3de8e7d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Omn=C3=A8s?= Date: Tue, 10 Jan 2023 17:19:57 +0100 Subject: [PATCH] Restore warm start for OR-Tools+XPRESS (#1079) --- src/solver/utils/named_problem.h | 1 - src/solver/utils/ortools_utils.cpp | 22 +++++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/solver/utils/named_problem.h b/src/solver/utils/named_problem.h index 59a338b0cb..c83fa7d32d 100644 --- a/src/solver/utils/named_problem.h +++ b/src/solver/utils/named_problem.h @@ -26,7 +26,6 @@ struct PROBLEME_SIMPLEXE_NOMME : public PROBLEME_SIMPLEXE bool isMIP() const; bool basisExists() const; - mutable bool solverSupportsWarmStart = false; }; } // namespace Optimization } // namespace Antares diff --git a/src/solver/utils/ortools_utils.cpp b/src/solver/utils/ortools_utils.cpp index c18ce82db9..b6b4552ec1 100644 --- a/src/solver/utils/ortools_utils.cpp +++ b/src/solver/utils/ortools_utils.cpp @@ -116,6 +116,20 @@ static void tuneSolverSpecificOptions(MPSolver* solver) } } +static bool solverSupportsWarmStart(const MPSolver* solver) +{ + if (!solver) + return false; + + switch (solver->ProblemType()) + { + case MPSolver::XPRESS_LINEAR_PROGRAMMING: + return true; + default: + return false; + } +} + namespace Antares { namespace Optimization @@ -286,8 +300,9 @@ MPSolver* ORTOOLS_Simplexe(Antares::Optimization::PROBLEME_SIMPLEXE_NOMME* Probl bool keepBasis) { MPSolverParameters params; + bool warmStart = solverSupportsWarmStart(solver); // Provide an initial simplex basis, if any - if (Probleme->basisExists() && !Probleme->isMIP() && Probleme->solverSupportsWarmStart) + if (warmStart && Probleme->basisExists() && !Probleme->isMIP()) { solver->SetStartingLpBasisInt(Probleme->StatutDesVariables, Probleme->StatutDesContraintes); } @@ -296,7 +311,7 @@ MPSolver* ORTOOLS_Simplexe(Antares::Optimization::PROBLEME_SIMPLEXE_NOMME* Probl { extract_from_MPSolver(solver, Probleme); // Save the final simplex basis for next resolutions - if (keepBasis && !Probleme->isMIP() && Probleme->solverSupportsWarmStart) + if (warmStart && keepBasis && !Probleme->isMIP()) { solver->GetFinalLpBasisInt(Probleme->StatutDesVariables, Probleme->StatutDesContraintes); @@ -388,8 +403,5 @@ MPSolver* MPSolverFactory(const Antares::Optimization::PROBLEME_SIMPLEXE_NOMME* AntaresSolverEmergencyShutdown(); } - if (solverName == "xpress") - probleme->solverSupportsWarmStart = true; - return solver; }