From 54d88cb23aaec9e9f04c0bb77f46b9142c8f39ef Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Wed, 2 Oct 2024 15:08:59 +0200 Subject: [PATCH 01/16] Remove Sirius direct call : all developments in one --- .github/workflows/ubuntu.yml | 30 +++---- .github/workflows/windows-vcpkg.yml | 46 +++++----- .../InfoCollection/StudyInfoCollector.cpp | 16 +--- .../infoCollection/StudyInfoCollector.h | 1 - .../antares/checks/checkLoadedInputData.cpp | 13 +-- .../antares/checks/checkLoadedInputData.h | 1 - .../antares/optimization-options/options.h | 2 - src/libs/antares/study/parameters.cpp | 8 +- src/solver/application/application.cpp | 1 - src/solver/misc/options.cpp | 31 +++---- .../opt_appel_solveur_lineaire.cpp | 85 ++++++------------- .../opt_liberation_problemes_simplexe.cpp | 8 +- .../antares/solver/simulation/solver.hxx | 43 +++++----- .../include/antares/solver/utils/mps_utils.h | 5 +- src/solver/utils/mps_utils.cpp | 11 +-- src/tests/CMakeLists.txt | 2 +- .../end-to-end/simple_study/simple-study.cpp | 2 - .../actions_on_study/study_run.py | 9 +- src/tests/run-study-tests/conftest.py | 11 +-- src/tests/run-study-tests/fixtures.py | 4 +- src/tests/run-study-tests/readme.md | 9 +- src/ui/simulator/application/study.cpp | 4 +- src/ui/simulator/application/study.h | 4 +- src/ui/simulator/windows/simulation/run.cpp | 6 +- 24 files changed, 126 insertions(+), 226 deletions(-) diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 2c73097adb..ecc3d2f51c 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -150,14 +150,14 @@ jobs: run: | git submodule update --init --remote --recursive src/tests/resources/Antares_Simulator_Tests_NR - - name: Run named mps tests - if: ${{ env.RUN_SIMPLE_TESTS == 'true' && !cancelled() }} - uses: ./.github/workflows/run-tests - with: - simtest-tag: ${{ env.SIMTEST }} - batch-name: valid-named-mps - os: ${{ env.os }} - variant: "named-mps" + #- name: Run named mps tests + # if: ${{ env.RUN_SIMPLE_TESTS == 'true' && !cancelled() }} + # uses: ./.github/workflows/run-tests + # with: + # simtest-tag: ${{ env.SIMTEST }} + # batch-name: valid-named-mps + # os: ${{ env.os }} + # variant: "named-mps" - name: Run unfeasibility-related tests if: ${{ env.RUN_SIMPLE_TESTS == 'true' && !cancelled() }} @@ -240,13 +240,13 @@ jobs: with: feature: "features/short_tests.feature" - - name: Run mps tests - if: ${{ env.RUN_SIMPLE_TESTS == 'true' && !cancelled() }} - uses: ./.github/workflows/run-tests - with: - simtest-tag: ${{ env.SIMTEST }} - batch-name: valid-mps - os: ${{ env.os }} + # - name: Run mps tests + # if: ${{ env.RUN_SIMPLE_TESTS == 'true' && !cancelled() }} + # uses: ./.github/workflows/run-tests + # with: + # simtest-tag: ${{ env.SIMTEST }} + # batch-name: valid-mps + # os: ${{ env.os }} - name: Run tests for adequacy patch (CSR) if: ${{ env.RUN_SIMPLE_TESTS == 'true' && !cancelled() }} diff --git a/.github/workflows/windows-vcpkg.yml b/.github/workflows/windows-vcpkg.yml index 5fb4b19603..3923e18af7 100644 --- a/.github/workflows/windows-vcpkg.yml +++ b/.github/workflows/windows-vcpkg.yml @@ -110,6 +110,14 @@ jobs: - name: Install pip dependencies if necessary run: pip install -r src/tests/examples/requirements.txt + - name: Init submodule Antares_Simulator_Tests + run: | + git submodule update --init --remote src/tests/resources/Antares_Simulator_Tests + + - name: Init submodule Antares_Simulator_Tests_NR + run: | + git submodule update --init --remote src/tests/resources/Antares_Simulator_Tests_NR + - name: Enable git longpaths run: git config --system core.longpaths true @@ -144,22 +152,14 @@ jobs: run: | echo "SIMTEST=${{ fromJson(env.SIMTEST_JSON).version }}" >> $GITHUB_ENV - - name: Init submodule Antares_Simulator_Tests - run: | - git submodule update --init --remote src/tests/resources/Antares_Simulator_Tests - - - name: Init submodule Antares_Simulator_Tests_NR - run: | - git submodule update --init --remote src/tests/resources/Antares_Simulator_Tests_NR - - - name: Run named mps tests - if: ${{ env.RUN_SIMPLE_TESTS == 'true' && ! cancelled() }} - uses: ./.github/workflows/run-tests - with: - simtest-tag: ${{ env.SIMTEST }} - batch-name: valid-named-mps - os: ${{ env.os }} - variant: "named-mps" + # - name: Run named mps tests + # if: ${{ env.RUN_SIMPLE_TESTS == 'true' && ! cancelled() }} + # uses: ./.github/workflows/run-tests + # with: + # simtest-tag: ${{ env.SIMTEST }} + # batch-name: valid-named-mps + # os: ${{ env.os }} + # variant: "named-mps" - name: Run unfeasibility-related tests if: ${{ env.RUN_SIMPLE_TESTS == 'true' && ! cancelled() }} @@ -250,13 +250,13 @@ jobs: with: feature: "features/short_tests.feature" - - name: Run mps tests - if: ${{ env.RUN_SIMPLE_TESTS == 'true' && !cancelled() }} - uses: ./.github/workflows/run-tests - with: - simtest-tag: ${{ env.SIMTEST }} - batch-name: valid-mps - os: ${{ env.os }} + # - name: Run mps tests + # if: ${{ env.RUN_SIMPLE_TESTS == 'true' && !cancelled() }} + # uses: ./.github/workflows/run-tests + # with: + # simtest-tag: ${{ env.SIMTEST }} + # batch-name: valid-mps + # os: ${{ env.os }} - name: Run parallel tests if: ${{ env.RUN_EXTENDED_TESTS == 'true' && !cancelled() }} diff --git a/src/libs/antares/InfoCollection/StudyInfoCollector.cpp b/src/libs/antares/InfoCollection/StudyInfoCollector.cpp index fe72e57d10..6920167f9b 100644 --- a/src/libs/antares/InfoCollection/StudyInfoCollector.cpp +++ b/src/libs/antares/InfoCollection/StudyInfoCollector.cpp @@ -45,7 +45,6 @@ void StudyInfoCollector::toFileContent(FileContent& file_content) unitCommitmentModeToFileContent(file_content); maxNbYearsInParallelToFileContent(file_content); solverVersionToFileContent(file_content); - ORToolsUsed(file_content); ORToolsSolver(file_content); } @@ -144,21 +143,10 @@ void StudyInfoCollector::solverVersionToFileContent(FileContent& file_content) file_content.addItemToSection("study", "antares version", version); } -void StudyInfoCollector::ORToolsUsed(FileContent& file_content) -{ - const bool& ortoolsUsed = study_.parameters.optOptions.ortoolsUsed; - file_content.addItemToSection("study", "ortools used", ortoolsUsed ? "true" : "false"); -} - void StudyInfoCollector::ORToolsSolver(FileContent& file_content) { - const bool& ortoolsUsed = study_.parameters.optOptions.ortoolsUsed; - std::string ortoolsSolver = "none"; - if (ortoolsUsed) - { - ortoolsSolver = study_.parameters.optOptions.ortoolsSolver; - } - file_content.addItemToSection("study", "ortools solver", ortoolsSolver); + std::string solverName = study_.parameters.optOptions.ortoolsSolver; + file_content.addItemToSection("study", "ortools solver", solverName); } // Collecting data optimization problem diff --git a/src/libs/antares/InfoCollection/include/antares/infoCollection/StudyInfoCollector.h b/src/libs/antares/InfoCollection/include/antares/infoCollection/StudyInfoCollector.h index 96f83b38af..9449bde84b 100644 --- a/src/libs/antares/InfoCollection/include/antares/infoCollection/StudyInfoCollector.h +++ b/src/libs/antares/InfoCollection/include/antares/infoCollection/StudyInfoCollector.h @@ -51,7 +51,6 @@ class StudyInfoCollector void maxNbYearsInParallelToFileContent(FileContent& file_content); void solverVersionToFileContent(FileContent& file_content); - void ORToolsUsed(FileContent& file_content); void ORToolsSolver(FileContent& file_content); // Member data diff --git a/src/libs/antares/checks/checkLoadedInputData.cpp b/src/libs/antares/checks/checkLoadedInputData.cpp index b62408b050..faf1515b0f 100644 --- a/src/libs/antares/checks/checkLoadedInputData.cpp +++ b/src/libs/antares/checks/checkLoadedInputData.cpp @@ -30,21 +30,12 @@ namespace Antares::Check { void checkOrtoolsUsage(Antares::Data::UnitCommitmentMode ucMode, - bool ortoolsUsed, const std::string& solverName) { using namespace Antares::Data; - if (ucMode == UnitCommitmentMode::ucMILP) + if (ucMode == UnitCommitmentMode::ucMILP && solverName == "sirius") { - if (!ortoolsUsed) - { - throw Error::IncompatibleMILPWithoutOrtools(); - } - - if (solverName == "sirius") - { - throw Error::IncompatibleMILPOrtoolsSolver(); - } + throw Error::IncompatibleMILPOrtoolsSolver(); } } diff --git a/src/libs/antares/checks/include/antares/checks/checkLoadedInputData.h b/src/libs/antares/checks/include/antares/checks/checkLoadedInputData.h index 62352390bc..4286bf78b1 100644 --- a/src/libs/antares/checks/include/antares/checks/checkLoadedInputData.h +++ b/src/libs/antares/checks/include/antares/checks/checkLoadedInputData.h @@ -25,7 +25,6 @@ namespace Antares::Check { void checkOrtoolsUsage(Antares::Data::UnitCommitmentMode ucMode, - bool ortoolsUsed, const std::string& solverName); void checkStudyVersion(const AnyString& optStudyFolder); diff --git a/src/libs/antares/optimization-options/include/antares/optimization-options/options.h b/src/libs/antares/optimization-options/include/antares/optimization-options/options.h index 893c1b1c21..6edc4cec9f 100644 --- a/src/libs/antares/optimization-options/include/antares/optimization-options/options.h +++ b/src/libs/antares/optimization-options/include/antares/optimization-options/options.h @@ -27,8 +27,6 @@ namespace Antares::Solver::Optimization struct OptimizationOptions { - //! Force ortools use - bool ortoolsUsed = false; //! The solver name, sirius is the default std::string ortoolsSolver = "sirius"; bool solverLogs = false; diff --git a/src/libs/antares/study/parameters.cpp b/src/libs/antares/study/parameters.cpp index 72be2dd7b4..2f56be31d4 100644 --- a/src/libs/antares/study/parameters.cpp +++ b/src/libs/antares/study/parameters.cpp @@ -1230,7 +1230,6 @@ bool Parameters::loadFromINI(const IniFile& ini, const StudyVersion& version) void Parameters::handleOptimizationOptions(const StudyLoadOptions& options) { // Options only set from the command-line - optOptions.ortoolsUsed = options.optOptions.ortoolsUsed; optOptions.ortoolsSolver = options.optOptions.ortoolsSolver; optOptions.solverParameters = options.optOptions.solverParameters; @@ -1730,12 +1729,7 @@ void Parameters::prepareForSimulation(const StudyLoadOptions& options) logs.info() << " :: ignoring hurdle costs"; } - // Indicate ortools solver used - if (options.optOptions.ortoolsUsed) - { - logs.info() << " :: ortools solver " << options.optOptions.ortoolsSolver - << " used for problem resolution"; - } + logs.info() << " :: solver " << options.optOptions.ortoolsSolver << " is used for problem resolution"; // indicated that Problems will be named if (namedProblems) diff --git a/src/solver/application/application.cpp b/src/solver/application/application.cpp index 346c67496a..f28078bf01 100644 --- a/src/solver/application/application.cpp +++ b/src/solver/application/application.cpp @@ -278,7 +278,6 @@ void Application::postParametersChecks() const { // Some more checks require the existence of pParameters, hence of a study. // Their execution is delayed up to this point. checkOrtoolsUsage(pParameters->unitCommitment.ucMode, - pParameters->optOptions.ortoolsUsed, pParameters->optOptions.ortoolsSolver); checkSimplexRangeHydroPricing(pParameters->simplexOptimizationRange, diff --git a/src/solver/misc/options.cpp b/src/solver/misc/options.cpp index 960b0dda6c..49193b59b0 100644 --- a/src/solver/misc/options.cpp +++ b/src/solver/misc/options.cpp @@ -76,19 +76,11 @@ std::unique_ptr CreateParser(Settings& settings, StudyLoad "force-parallel", "Override the max number of years computed simultaneously"); - // add option for ortools use - // --use-ortools - parser->addFlag(options.optOptions.ortoolsUsed, - ' ', - "use-ortools", - "Use ortools library to launch solver"); - //--ortools-solver parser->add(options.optOptions.ortoolsSolver, ' ', - "ortools-solver", - "Ortools solver used for simulation (only available with use-ortools " - "option)\nAvailable solver list : " + "solver", + "Solver used for simulation\nAvailable solver list : " + availableOrToolsSolversString()); //--xpress-parameters @@ -266,18 +258,15 @@ void checkAndCorrectSettingsAndOptions(Settings& settings, Data::StudyLoadOption void checkOrtoolsSolver(const Antares::Solver::Optimization::OptimizationOptions& optOptions) { - if (optOptions.ortoolsUsed) - { - const std::string& solverName = optOptions.ortoolsSolver; - const std::list availableSolverList = getAvailableOrtoolsSolverName(); + const std::string& solverName = optOptions.ortoolsSolver; + const std::list availableSolverList = getAvailableOrtoolsSolverName(); - // Check if solver is available - bool found = (std::find(availableSolverList.begin(), availableSolverList.end(), solverName) - != availableSolverList.end()); - if (!found) - { - throw Error::InvalidSolver(optOptions.ortoolsSolver, availableOrToolsSolversString()); - } + // Check if solver is available + bool found = (std::find(availableSolverList.begin(), availableSolverList.end(), solverName) + != availableSolverList.end()); + if (!found) + { + throw Error::InvalidSolver(optOptions.ortoolsSolver, availableOrToolsSolversString()); } } diff --git a/src/solver/optimisation/opt_appel_solveur_lineaire.cpp b/src/solver/optimisation/opt_appel_solveur_lineaire.cpp index 94eae39fc8..02658175c4 100644 --- a/src/solver/optimisation/opt_appel_solveur_lineaire.cpp +++ b/src/solver/optimisation/opt_appel_solveur_lineaire.cpp @@ -85,8 +85,7 @@ static SimplexResult OPT_TryToCallSimplex(const OptimizationOptions& options, IResultWriter& writer) { const auto& ProblemeAResoudre = problemeHebdo->ProblemeAResoudre; - auto ProbSpx = (PROBLEME_SPX*)(ProblemeAResoudre->ProblemesSpx[(int)NumIntervalle]); - auto solver = (MPSolver*)(ProblemeAResoudre->ProblemesSpx[(int)NumIntervalle]); + auto solver = (MPSolver*)(ProblemeAResoudre->ProblemesSpx[NumIntervalle]); const int opt = optimizationNumber - 1; assert(opt >= 0 && opt < 2); @@ -94,11 +93,10 @@ static SimplexResult OPT_TryToCallSimplex(const OptimizationOptions& options, TIME_MEASURE timeMeasure; if (!PremierPassage) { - ProbSpx = nullptr; solver = nullptr; } - if (ProbSpx == nullptr && solver == nullptr) + if (solver == nullptr) { Probleme.Contexte = SIMPLEXE_SEUL; Probleme.BaseDeDepartFournie = NON_SPX; @@ -107,17 +105,13 @@ static SimplexResult OPT_TryToCallSimplex(const OptimizationOptions& options, { if (problemeHebdo->ReinitOptimisation) { - if (options.ortoolsUsed && solver) + if (solver != nullptr) { ORTOOLS_LibererProbleme(solver); } - else if (ProbSpx != nullptr) - { - SPX_LibererProbleme(ProbSpx); - } + ProblemeAResoudre->ProblemesSpx[NumIntervalle] = nullptr; - ProbSpx = nullptr; solver = nullptr; Probleme.Contexte = SIMPLEXE_SEUL; Probleme.BaseDeDepartFournie = NON_SPX; @@ -128,31 +122,19 @@ static SimplexResult OPT_TryToCallSimplex(const OptimizationOptions& options, Probleme.BaseDeDepartFournie = UTILISER_LA_BASE_DU_PROBLEME_SPX; TimeMeasurement updateMeasure; - if (options.ortoolsUsed) - { - ORTOOLS_ModifierLeVecteurCouts(solver, - ProblemeAResoudre->CoutLineaire.data(), - ProblemeAResoudre->NombreDeVariables); - ORTOOLS_ModifierLeVecteurSecondMembre(solver, - ProblemeAResoudre->SecondMembre.data(), - ProblemeAResoudre->Sens.data(), - ProblemeAResoudre->NombreDeContraintes); - ORTOOLS_CorrigerLesBornes(solver, - ProblemeAResoudre->Xmin.data(), - ProblemeAResoudre->Xmax.data(), - ProblemeAResoudre->TypeDeVariable.data(), - ProblemeAResoudre->NombreDeVariables); - } - else - { - SPX_ModifierLeVecteurCouts(ProbSpx, - ProblemeAResoudre->CoutLineaire.data(), - ProblemeAResoudre->NombreDeVariables); - SPX_ModifierLeVecteurSecondMembre(ProbSpx, - ProblemeAResoudre->SecondMembre.data(), - ProblemeAResoudre->Sens.data(), - ProblemeAResoudre->NombreDeContraintes); - } + + ORTOOLS_ModifierLeVecteurCouts( + solver, ProblemeAResoudre->CoutLineaire.data(), ProblemeAResoudre->NombreDeVariables); + ORTOOLS_ModifierLeVecteurSecondMembre(solver, + ProblemeAResoudre->SecondMembre.data(), + ProblemeAResoudre->Sens.data(), + ProblemeAResoudre->NombreDeContraintes); + ORTOOLS_CorrigerLesBornes(solver, + ProblemeAResoudre->Xmin.data(), + ProblemeAResoudre->Xmax.data(), + ProblemeAResoudre->TypeDeVariable.data(), + ProblemeAResoudre->NombreDeVariables); + updateMeasure.tick(); timeMeasure.updateTime = updateMeasure.duration_ms(); optimizationStatistics.addUpdateTime(timeMeasure.updateTime); @@ -201,40 +183,27 @@ static SimplexResult OPT_TryToCallSimplex(const OptimizationOptions& options, Probleme.NombreDeContraintesCoupes = 0; - if (options.ortoolsUsed) - { - solver = ORTOOLS_ConvertIfNeeded(options.ortoolsSolver, &Probleme, solver); - } + solver = ORTOOLS_ConvertIfNeeded(options.ortoolsSolver, &Probleme, solver); const std::string filename = createMPSfilename(optPeriodStringGenerator, optimizationNumber); mpsWriterFactory mps_writer_factory(problemeHebdo->ExportMPS, problemeHebdo->exportMPSOnError, optimizationNumber, &Probleme, - options.ortoolsUsed, solver); auto mps_writer = mps_writer_factory.create(); mps_writer->runIfNeeded(writer, filename); TimeMeasurement measure; - if (options.ortoolsUsed) + + const bool keepBasis = (optimizationNumber == PREMIERE_OPTIMISATION); + solver = ORTOOLS_Simplexe(&Probleme, solver, keepBasis, options); + if (solver != nullptr) { - const bool keepBasis = (optimizationNumber == PREMIERE_OPTIMISATION); - solver = ORTOOLS_Simplexe(&Probleme, solver, keepBasis, options); - if (solver != nullptr) - { - ProblemeAResoudre->ProblemesSpx[NumIntervalle] = (void*)solver; - } - } - else - { - ProbSpx = SPX_Simplexe(&Probleme, ProbSpx); - if (ProbSpx != nullptr) - { - ProblemeAResoudre->ProblemesSpx[NumIntervalle] = (void*)ProbSpx; - } + ProblemeAResoudre->ProblemesSpx[NumIntervalle] = (void*)solver; } + measure.tick(); timeMeasure.solveTime = measure.duration_ms(); optimizationStatistics.addSolveTime(timeMeasure.solveTime); @@ -244,14 +213,10 @@ static SimplexResult OPT_TryToCallSimplex(const OptimizationOptions& options, { if (ProblemeAResoudre->ExistenceDUneSolution != SPX_ERREUR_INTERNE) { - if (options.ortoolsUsed && solver) + if (solver != nullptr) { ORTOOLS_LibererProbleme(solver); } - else if (ProbSpx != nullptr) - { - SPX_LibererProbleme(ProbSpx); - } logs.info() << " Solver: Standard resolution failed"; logs.info() << " Solver: Retry in safe mode"; // second trial w/o scaling diff --git a/src/solver/optimisation/opt_liberation_problemes_simplexe.cpp b/src/solver/optimisation/opt_liberation_problemes_simplexe.cpp index b1df3a06c9..9278d0f2a0 100644 --- a/src/solver/optimisation/opt_liberation_problemes_simplexe.cpp +++ b/src/solver/optimisation/opt_liberation_problemes_simplexe.cpp @@ -52,19 +52,13 @@ void OPT_LiberationProblemesSimplexe(const OptimizationOptions& options, { for (int numIntervalle = 0; numIntervalle < nbIntervalles; numIntervalle++) { - auto ProbSpx = (PROBLEME_SPX*)(ProblemeAResoudre->ProblemesSpx[numIntervalle]); auto solver = (MPSolver*)(ProblemeAResoudre->ProblemesSpx[numIntervalle]); - if (options.ortoolsUsed && solver) + if (solver != NULL) { ORTOOLS_LibererProbleme(solver); solver = nullptr; } - else if (ProbSpx) - { - SPX_LibererProbleme(ProbSpx); - ProbSpx = nullptr; - } } } } diff --git a/src/solver/simulation/include/antares/solver/simulation/solver.hxx b/src/solver/simulation/include/antares/solver/simulation/solver.hxx index c8ca4775df..9fe8f55691 100644 --- a/src/solver/simulation/include/antares/solver/simulation/solver.hxx +++ b/src/solver/simulation/include/antares/solver/simulation/solver.hxx @@ -51,7 +51,7 @@ public: randomNumbers& pRandomForParallelYears, bool pPerformCalculations, Data::Study& pStudy, - Variable::State& pState, + std::vector& pStates, bool pYearByYear, Benchmarking::DurationCollector& durationCollector, IResultWriter& resultWriter, @@ -65,14 +65,13 @@ public: randomForParallelYears(pRandomForParallelYears), performCalculations(pPerformCalculations), study(pStudy), - state(pState), + states(pStates), yearByYear(pYearByYear), pDurationCollector(durationCollector), pResultWriter(resultWriter), simulationObserver_(simulationObserver), hydroManagement(study.areas, study.parameters, study.calendar, resultWriter) { - scratchmap = study.areas.buildScratchMap(numSpace); } yearJob(const yearJob&) = delete; @@ -89,13 +88,12 @@ private: randomNumbers& randomForParallelYears; bool performCalculations; Data::Study& study; - Variable::State& state; + std::vector& states; bool yearByYear; Benchmarking::DurationCollector& pDurationCollector; IResultWriter& pResultWriter; std::reference_wrapper simulationObserver_; HydroManagement hydroManagement; - Antares::Data::Area::ScratchMap scratchmap; private: /* @@ -147,17 +145,18 @@ public: // 1 - Applying random levels for current year auto randomReservoirLevel = randomForCurrentYear.pReservoirLevels; - // 2 - Preparing the Time-series numbers - // removed + // Getting the scratchMap associated to the current year + Antares::Data::Area::ScratchMap scratchmap = study.areas.buildScratchMap(numSpace); // 3 - Preparing data related to Clusters in 'must-run' mode simulation_->prepareClustersInMustRunMode(scratchmap, y); // 4 - Hydraulic ventilation - pDurationCollector("hydro_ventilation") << [this, &randomReservoirLevel] + pDurationCollector("hydro_ventilation") << [this, &scratchmap, &randomReservoirLevel] { hydroManagement.makeVentilation(randomReservoirLevel.data(), y, scratchmap); }; // Updating the state + auto& state = states[numSpace]; state.year = y; // 5 - Resetting all variables for the output @@ -1016,20 +1015,20 @@ void ISimulation::loopThroughYears(uint firstYear, // continue; auto task = std::make_shared>( - this, - y, - batch.yearFailed, - batch.isFirstPerformedYearOfASet, - pFirstSetParallelWithAPerformedYearWasRun, - numSpace, - randomForParallelYears, - performCalculations, - study, - state[numSpace], - pYearByYear, - pDurationCollector, - pResultWriter, - simulationObserver_.get()); + this, + y, + batch.yearFailed, + batch.isFirstPerformedYearOfASet, + pFirstSetParallelWithAPerformedYearWasRun, + numSpace, + randomForParallelYears, + performCalculations, + study, + state, + pYearByYear, + pDurationCollector, + pResultWriter, + simulationObserver_.get()); results.add(Concurrency::AddTask(*pQueueService, task)); } // End loop over years of the current set of parallel years diff --git a/src/solver/utils/include/antares/solver/utils/mps_utils.h b/src/solver/utils/include/antares/solver/utils/mps_utils.h index 0afe5901ff..abd9ba2451 100644 --- a/src/solver/utils/include/antares/solver/utils/mps_utils.h +++ b/src/solver/utils/include/antares/solver/utils/mps_utils.h @@ -57,6 +57,9 @@ class I_MPS_writer uint current_optim_number_ = 0; }; +// Caution : this class should be removed if we want Sirius behind or-tools +// But we want to keep the way we write MPS files for a named problem, +// so we keep it for now. class fullMPSwriter final: public I_MPS_writer { public: @@ -98,7 +101,6 @@ class mpsWriterFactory bool exportMPSOnError, const int current_optim_number, PROBLEME_SIMPLEXE_NOMME* named_splx_problem, - bool ortoolsUsed, MPSolver* solver); std::unique_ptr create(); @@ -113,7 +115,6 @@ class mpsWriterFactory Data::mpsExportStatus export_mps_; bool export_mps_on_error_; PROBLEME_SIMPLEXE_NOMME* named_splx_problem_ = nullptr; - bool ortools_used_; MPSolver* solver_ = nullptr; uint current_optim_number_; }; diff --git a/src/solver/utils/mps_utils.cpp b/src/solver/utils/mps_utils.cpp index 06b86f9a7c..02d023c5f5 100644 --- a/src/solver/utils/mps_utils.cpp +++ b/src/solver/utils/mps_utils.cpp @@ -163,12 +163,10 @@ mpsWriterFactory::mpsWriterFactory(Data::mpsExportStatus exportMPS, bool exportMPSOnError, const int current_optim_number, PROBLEME_SIMPLEXE_NOMME* named_splx_problem, - bool ortoolsUsed, MPSolver* solver): export_mps_(exportMPS), export_mps_on_error_(exportMPSOnError), named_splx_problem_(named_splx_problem), - ortools_used_(ortoolsUsed), solver_(solver), current_optim_number_(current_optim_number) { @@ -211,12 +209,5 @@ std::unique_ptr mpsWriterFactory::createOnOptimizationError() std::unique_ptr mpsWriterFactory::createFullmpsWriter() { - if (ortools_used_) - { - return std::make_unique(solver_, current_optim_number_); - } - else - { - return std::make_unique(named_splx_problem_, current_optim_number_); - } + return std::make_unique(solver_, current_optim_number_); } diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index 2babe91fab..881a346514 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -67,7 +67,7 @@ if(Python3_Interpreter_FOUND) add_test( NAME milp-cbc - COMMAND Python3::Interpreter -m pytest -m json --solver-path=$ --use-ortools --ortools-solver coin + COMMAND Python3::Interpreter -m pytest -m json --solver-path=$ --solver coin WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/run-study-tests" ) diff --git a/src/tests/end-to-end/simple_study/simple-study.cpp b/src/tests/end-to-end/simple_study/simple-study.cpp index 2664dc97d0..dbc29c2ae4 100644 --- a/src/tests/end-to-end/simple_study/simple-study.cpp +++ b/src/tests/end-to-end/simple_study/simple-study.cpp @@ -201,7 +201,6 @@ BOOST_FIXTURE_TEST_CASE(milp_two_mc_single_unit_single_scenario, StudyFixture) // Use OR-Tools / COIN for MILP auto& p = study->parameters; p.unitCommitment.ucMode = ucMILP; - p.optOptions.ortoolsUsed = true; p.optOptions.ortoolsSolver = "coin"; simulation->create(); @@ -230,7 +229,6 @@ BOOST_FIXTURE_TEST_CASE(milp_two_mc_two_unit_single_scenario, StudyFixture) // Use OR-Tools / COIN for MILP auto& p = study->parameters; p.unitCommitment.ucMode = ucMILP; - p.optOptions.ortoolsUsed = true; p.optOptions.ortoolsSolver = "coin"; simulation->create(); diff --git a/src/tests/run-study-tests/actions_on_study/study_run.py b/src/tests/run-study-tests/actions_on_study/study_run.py index 8867aafda5..a174149bd3 100644 --- a/src/tests/run-study-tests/actions_on_study/study_run.py +++ b/src/tests/run-study-tests/actions_on_study/study_run.py @@ -4,11 +4,10 @@ from utils.assertions import check class study_run: - def __init__(self, study_path, solver_path, use_ortools, ortools_solver, named_mps_problems, parallel): + def __init__(self, study_path, solver_path, solver_name, named_mps_problems, parallel): self.study_path = study_path self.solver_path = solver_path - self.use_ortools = use_ortools - self.ortools_solver = ortools_solver + self.solverName = solver_name self.named_mps_problems = named_mps_problems self.parallel = parallel self.raise_exception_on_failure = True @@ -23,9 +22,7 @@ def run(self): solver_full_path = str(Path(self.solver_path).resolve()) command = [solver_full_path, "-i", str(self.study_path)] - if self.use_ortools: - command.append('--use-ortools') - command.append('--ortools-solver=' + self.ortools_solver) + command.append('--solver=' + self.solverName) if self.named_mps_problems: command.append('--named-mps-problems') if self.parallel: diff --git a/src/tests/run-study-tests/conftest.py b/src/tests/run-study-tests/conftest.py index f38b048ca0..f6ff052810 100644 --- a/src/tests/run-study-tests/conftest.py +++ b/src/tests/run-study-tests/conftest.py @@ -1,20 +1,15 @@ import pytest def pytest_addoption(parser): - parser.addoption("--use-ortools", action="store_true", default=False) - parser.addoption("--ortools-solver", action="store", default="sirius") + parser.addoption("--solver", action="store", default="sirius") parser.addoption("--solver-path", action="store") parser.addoption("--named-mps-problems", action="store_true", default=False) parser.addoption("--force-parallel", action="store_true", default=False) parser.addoption("--ts-generator", action="store_true", default=False) @pytest.fixture() -def ortools_solver(request): - return request.config.getoption("--ortools-solver") - -@pytest.fixture() -def use_ortools(request): - return request.config.getoption("--use-ortools") +def solver_name(request): + return request.config.getoption("--solver") @pytest.fixture() def solver_path(request): diff --git a/src/tests/run-study-tests/fixtures.py b/src/tests/run-study-tests/fixtures.py index 5f4945f379..7245fe09c7 100644 --- a/src/tests/run-study-tests/fixtures.py +++ b/src/tests/run-study-tests/fixtures.py @@ -40,8 +40,8 @@ def resultsRemover(study_path): return results_remover(study_path) @pytest.fixture -def simulation(study_path, solver_path, use_ortools, ortools_solver, named_mps_problems, parallel): - return study_run(study_path, solver_path, use_ortools, ortools_solver, named_mps_problems, parallel) +def simulation(study_path, solver_path, solver_name, named_mps_problems, parallel): + return study_run(study_path, solver_path, solver_name, named_mps_problems, parallel) @pytest.fixture(autouse=True) def check_runner(simulation, resultsRemover): diff --git a/src/tests/run-study-tests/readme.md b/src/tests/run-study-tests/readme.md index d2536dab64..3eb4d27ebb 100644 --- a/src/tests/run-study-tests/readme.md +++ b/src/tests/run-study-tests/readme.md @@ -5,8 +5,11 @@ Here is an automatic testing python script system. This program performs the following : 1. Searches for all studies in a given directory 2. From each study, retrieves the specifications to make checks on the simulation results of that study (see items below) -3. Runs a simlulation on each study -4. Given the results of the simulation on a study, makes the checks retrieved at step 2 on these results (for instance : make sure current results and reference resuts are identical, check for existence or content of output files,...) +3. Runs a simulation on each study +4. Given the results of the simulation on a study, makes the checks retrieved at step 2 on these results. + Examples : + - make sure current results and reference resuts are identical + - check for existence or even content of output files Note that each study found is supposed to contain the definition of checks performed by scripts after the simulation on the study is completed. So, each study is supposed to contain a file **check-config.json** for that purpose. This file is build manually for each study. @@ -42,7 +45,7 @@ In the following, we comment the content of this script. Lines of this scripts a ## Fixtures **pytest** comes with the notion of **fixture**. Fixtures allow executing a piece of code just before a test runs. -To take bebefit of a fixture, a test needs to be given this fixture as argument. +To take benefit of a fixture, a test needs to be given this fixture as argument. Fixture themselves can also be given arguments, we'll see how we do it (in the context of the current testing system) when we talk about **parametrization**. Fixtures return a result to be used in the test. Let's look at a simple test : diff --git a/src/ui/simulator/application/study.cpp b/src/ui/simulator/application/study.cpp index c71e4de6ca..23a1fcd957 100644 --- a/src/ui/simulator/application/study.cpp +++ b/src/ui/simulator/application/study.cpp @@ -1091,7 +1091,7 @@ void RunSimulationOnTheStudy(Data::Study::Ptr study, Solver::Feature features, bool preproOnly, bool useOrtools, - const std::string& ortoolsSolver) + const std::string& solverName) { if (!study) // A valid study would be better { @@ -1212,7 +1212,7 @@ void RunSimulationOnTheStudy(Data::Study::Ptr study, cmd << " --use-ortools"; // add solver name for ortools - cmd << " --ortools-solver=" << ortoolsSolver; + cmd << " --ortools-solver=" << solverName; } // Go go go ! diff --git a/src/ui/simulator/application/study.h b/src/ui/simulator/application/study.h index 569de2e9e4..4cb7b878da 100644 --- a/src/ui/simulator/application/study.h +++ b/src/ui/simulator/application/study.h @@ -114,7 +114,7 @@ bool CheckIfInsideAStudyFolder(const AnyString& path, bool quiet = false); ** \param simuComments Comments for the simulation ** \param ignoreWarnings True if warnings can be silently ignored ** \param useOrtools True if ortools must be used by antares-solver -** \param ortoolsSolver Ortools solver used in case of ortools use by antares-solver +** \param solverName Solver used */ void RunSimulationOnTheStudy(Data::Study::Ptr study, const YString& simuName, @@ -123,7 +123,7 @@ void RunSimulationOnTheStudy(Data::Study::Ptr study, Solver::Feature features = Solver::standard, bool preproOnly = false, bool useOrtools = false, - const std::string& ortoolsSolver = "sirius"); + const std::string& solverName = "sirius"); /*! ** \brief Update the state of controls diff --git a/src/ui/simulator/windows/simulation/run.cpp b/src/ui/simulator/windows/simulation/run.cpp index e32fb55101..8be0054bd9 100644 --- a/src/ui/simulator/windows/simulation/run.cpp +++ b/src/ui/simulator/windows/simulation/run.cpp @@ -323,10 +323,10 @@ Run::Run(wxWindow* parent, bool preproOnly) : = Antares::Component::CreateLabel(pBigDaddy, wxT("Ortools solver : ")); pOrtoolsSolverCombox = new wxComboBox(pBigDaddy, wxID_ANY); - std::list ortoolsSolverList = getAvailableOrtoolsSolverName(); - for (const std::string& ortoolsSolver : ortoolsSolverList) + std::list solverList = getAvailableOrtoolsSolverName(); + for (const std::string& solverName : solverList) { - pOrtoolsSolverCombox->Append(ortoolsSolver); + pOrtoolsSolverCombox->Append(solverName); } // Ortools solver selection visibility From 4fb354415f6e90c33a8f78a29f4c66784069b0e2 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Wed, 2 Oct 2024 15:53:55 +0200 Subject: [PATCH 02/16] Remove Sirius direct call : more tests on CI --- .github/workflows/ubuntu.yml | 10 +++++----- .github/workflows/windows-vcpkg.yml | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index ecc3d2f51c..367b617408 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -257,7 +257,7 @@ jobs: os: ${{ env.os }} - name: Run parallel tests - if: ${{ env.RUN_EXTENDED_TESTS == 'true' && !cancelled() }} + if: ${{ env.RUN_SIMPLE_TESTS == 'true' && !cancelled() }} uses: ./.github/workflows/run-tests with: simtest-tag: ${{ env.SIMTEST }} @@ -275,7 +275,7 @@ jobs: variant: "tsgenerator" - name: Run medium-tests - if: ${{ env.RUN_EXTENDED_TESTS == 'true' && !cancelled() }} + if: ${{ env.RUN_SIMPLE_TESTS == 'true' && !cancelled() }} uses: ./.github/workflows/run-tests with: simtest-tag: ${{ env.SIMTEST }} @@ -288,7 +288,7 @@ jobs: feature: "features/medium_tests.feature" - name: Run long-tests-1 - if: ${{ env.RUN_EXTENDED_TESTS == 'true' && !cancelled() }} + if: ${{ env.RUN_SIMPLE_TESTS == 'true' && !cancelled() }} uses: ./.github/workflows/run-tests with: simtest-tag: ${{ env.SIMTEST }} @@ -296,7 +296,7 @@ jobs: os: ${{ env.os }} - name: Run long-tests-2 - if: ${{ env.RUN_EXTENDED_TESTS == 'true' && !cancelled() }} + if: ${{ env.RUN_SIMPLE_TESTS == 'true' && !cancelled() }} uses: ./.github/workflows/run-tests with: simtest-tag: ${{ env.SIMTEST }} @@ -304,7 +304,7 @@ jobs: os: ${{ env.os }} - name: Run long-tests-3 - if: ${{ env.RUN_EXTENDED_TESTS == 'true' && !cancelled() }} + if: ${{ env.RUN_SIMPLE_TESTS == 'true' && !cancelled() }} uses: ./.github/workflows/run-tests with: simtest-tag: ${{ env.SIMTEST }} diff --git a/.github/workflows/windows-vcpkg.yml b/.github/workflows/windows-vcpkg.yml index 3923e18af7..4ff7637091 100644 --- a/.github/workflows/windows-vcpkg.yml +++ b/.github/workflows/windows-vcpkg.yml @@ -259,7 +259,7 @@ jobs: # os: ${{ env.os }} - name: Run parallel tests - if: ${{ env.RUN_EXTENDED_TESTS == 'true' && !cancelled() }} + if: ${{ env.RUN_SIMPLE_TESTS == 'true' && !cancelled() }} uses: ./.github/workflows/run-tests with: simtest-tag: ${{ env.SIMTEST }} @@ -277,7 +277,7 @@ jobs: variant: "tsgenerator" - name: Run medium-tests - if: ${{ env.RUN_EXTENDED_TESTS == 'true' && !cancelled() }} + if: ${{ env.RUN_SIMPLE_TESTS == 'true' && !cancelled() }} uses: ./.github/workflows/run-tests with: simtest-tag: ${{ env.SIMTEST }} @@ -290,7 +290,7 @@ jobs: feature: "features/medium_tests.feature" - name: Run long-tests-1 - if: ${{ env.RUN_EXTENDED_TESTS == 'true' && !cancelled() }} + if: ${{ env.RUN_SIMPLE_TESTS == 'true' && !cancelled() }} uses: ./.github/workflows/run-tests with: simtest-tag: ${{ env.SIMTEST }} @@ -298,7 +298,7 @@ jobs: os: ${{ env.os }} - name: Run long-tests-2 - if: ${{ env.RUN_EXTENDED_TESTS == 'true' && !cancelled() }} + if: ${{ env.RUN_SIMPLE_TESTS == 'true' && !cancelled() }} uses: ./.github/workflows/run-tests with: simtest-tag: ${{ env.SIMTEST }} @@ -306,7 +306,7 @@ jobs: os: ${{ env.os }} - name: Run long-tests-3 - if: ${{ env.RUN_EXTENDED_TESTS == 'true' && !cancelled() }} + if: ${{ env.RUN_SIMPLE_TESTS == 'true' && !cancelled() }} uses: ./.github/workflows/run-tests with: simtest-tag: ${{ env.SIMTEST }} From 1bb4a6cb10e5358b2192f6be1af3324435532395 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Wed, 2 Oct 2024 15:59:39 +0200 Subject: [PATCH 03/16] Remove Sirius direct call : clang format --- .../antares/checks/checkLoadedInputData.cpp | 3 +- .../antares/checks/checkLoadedInputData.h | 3 +- src/libs/antares/study/parameters.cpp | 3 +- src/solver/application/application.cpp | 3 +- .../opt_appel_solveur_lineaire.cpp | 19 +++++++------ .../antares/solver/simulation/solver.hxx | 28 +++++++++---------- 6 files changed, 29 insertions(+), 30 deletions(-) diff --git a/src/libs/antares/checks/checkLoadedInputData.cpp b/src/libs/antares/checks/checkLoadedInputData.cpp index faf1515b0f..29dc084bab 100644 --- a/src/libs/antares/checks/checkLoadedInputData.cpp +++ b/src/libs/antares/checks/checkLoadedInputData.cpp @@ -29,8 +29,7 @@ namespace Antares::Check { -void checkOrtoolsUsage(Antares::Data::UnitCommitmentMode ucMode, - const std::string& solverName) +void checkOrtoolsUsage(Antares::Data::UnitCommitmentMode ucMode, const std::string& solverName) { using namespace Antares::Data; if (ucMode == UnitCommitmentMode::ucMILP && solverName == "sirius") diff --git a/src/libs/antares/checks/include/antares/checks/checkLoadedInputData.h b/src/libs/antares/checks/include/antares/checks/checkLoadedInputData.h index 4286bf78b1..846ef8e3c9 100644 --- a/src/libs/antares/checks/include/antares/checks/checkLoadedInputData.h +++ b/src/libs/antares/checks/include/antares/checks/checkLoadedInputData.h @@ -24,8 +24,7 @@ namespace Antares::Check { -void checkOrtoolsUsage(Antares::Data::UnitCommitmentMode ucMode, - const std::string& solverName); +void checkOrtoolsUsage(Antares::Data::UnitCommitmentMode ucMode, const std::string& solverName); void checkStudyVersion(const AnyString& optStudyFolder); diff --git a/src/libs/antares/study/parameters.cpp b/src/libs/antares/study/parameters.cpp index 2f56be31d4..61111f18ae 100644 --- a/src/libs/antares/study/parameters.cpp +++ b/src/libs/antares/study/parameters.cpp @@ -1729,7 +1729,8 @@ void Parameters::prepareForSimulation(const StudyLoadOptions& options) logs.info() << " :: ignoring hurdle costs"; } - logs.info() << " :: solver " << options.optOptions.ortoolsSolver << " is used for problem resolution"; + logs.info() << " :: solver " << options.optOptions.ortoolsSolver + << " is used for problem resolution"; // indicated that Problems will be named if (namedProblems) diff --git a/src/solver/application/application.cpp b/src/solver/application/application.cpp index f28078bf01..df6e17c1e9 100644 --- a/src/solver/application/application.cpp +++ b/src/solver/application/application.cpp @@ -277,8 +277,7 @@ void Application::startSimulation(Data::StudyLoadOptions& options) void Application::postParametersChecks() const { // Some more checks require the existence of pParameters, hence of a study. // Their execution is delayed up to this point. - checkOrtoolsUsage(pParameters->unitCommitment.ucMode, - pParameters->optOptions.ortoolsSolver); + checkOrtoolsUsage(pParameters->unitCommitment.ucMode, pParameters->optOptions.ortoolsSolver); checkSimplexRangeHydroPricing(pParameters->simplexOptimizationRange, pParameters->hydroPricing.hpMode); diff --git a/src/solver/optimisation/opt_appel_solveur_lineaire.cpp b/src/solver/optimisation/opt_appel_solveur_lineaire.cpp index 02658175c4..c5f45015ec 100644 --- a/src/solver/optimisation/opt_appel_solveur_lineaire.cpp +++ b/src/solver/optimisation/opt_appel_solveur_lineaire.cpp @@ -123,17 +123,18 @@ static SimplexResult OPT_TryToCallSimplex(const OptimizationOptions& options, TimeMeasurement updateMeasure; - ORTOOLS_ModifierLeVecteurCouts( - solver, ProblemeAResoudre->CoutLineaire.data(), ProblemeAResoudre->NombreDeVariables); + ORTOOLS_ModifierLeVecteurCouts(solver, + ProblemeAResoudre->CoutLineaire.data(), + ProblemeAResoudre->NombreDeVariables); ORTOOLS_ModifierLeVecteurSecondMembre(solver, - ProblemeAResoudre->SecondMembre.data(), - ProblemeAResoudre->Sens.data(), - ProblemeAResoudre->NombreDeContraintes); + ProblemeAResoudre->SecondMembre.data(), + ProblemeAResoudre->Sens.data(), + ProblemeAResoudre->NombreDeContraintes); ORTOOLS_CorrigerLesBornes(solver, - ProblemeAResoudre->Xmin.data(), - ProblemeAResoudre->Xmax.data(), - ProblemeAResoudre->TypeDeVariable.data(), - ProblemeAResoudre->NombreDeVariables); + ProblemeAResoudre->Xmin.data(), + ProblemeAResoudre->Xmax.data(), + ProblemeAResoudre->TypeDeVariable.data(), + ProblemeAResoudre->NombreDeVariables); updateMeasure.tick(); timeMeasure.updateTime = updateMeasure.duration_ms(); diff --git a/src/solver/simulation/include/antares/solver/simulation/solver.hxx b/src/solver/simulation/include/antares/solver/simulation/solver.hxx index 9fe8f55691..6b948a4b9a 100644 --- a/src/solver/simulation/include/antares/solver/simulation/solver.hxx +++ b/src/solver/simulation/include/antares/solver/simulation/solver.hxx @@ -1015,20 +1015,20 @@ void ISimulation::loopThroughYears(uint firstYear, // continue; auto task = std::make_shared>( - this, - y, - batch.yearFailed, - batch.isFirstPerformedYearOfASet, - pFirstSetParallelWithAPerformedYearWasRun, - numSpace, - randomForParallelYears, - performCalculations, - study, - state, - pYearByYear, - pDurationCollector, - pResultWriter, - simulationObserver_.get()); + this, + y, + batch.yearFailed, + batch.isFirstPerformedYearOfASet, + pFirstSetParallelWithAPerformedYearWasRun, + numSpace, + randomForParallelYears, + performCalculations, + study, + state, + pYearByYear, + pDurationCollector, + pResultWriter, + simulationObserver_.get()); results.add(Concurrency::AddTask(*pQueueService, task)); } // End loop over years of the current set of parallel years From 8b5f1ccf6a13c60f48001e79c23c4e797e9d0ee3 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Fri, 4 Oct 2024 10:39:57 +0200 Subject: [PATCH 04/16] Remove Sirius direct call : cucumber is adapted to current changes (CI just failed on cucumber step) --- src/tests/cucumber/features/steps/simulator_utils.py | 4 +--- src/tests/cucumber/features/steps/steps.py | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/tests/cucumber/features/steps/simulator_utils.py b/src/tests/cucumber/features/steps/simulator_utils.py index 91da69a5ad..a124ab93f0 100644 --- a/src/tests/cucumber/features/steps/simulator_utils.py +++ b/src/tests/cucumber/features/steps/simulator_utils.py @@ -36,9 +36,7 @@ def activate_simu_outputs(context): def build_antares_solver_command(context): command = [SOLVER_PATH, "-i", str(context.study_path)] - if context.use_ortools: - command.append('--use-ortools') - command.append('--ortools-solver=' + context.ortools_solver) + command.append('--solver=' + context.ortools_solver) if context.named_mps_problems: command.append('--named-mps-problems') if context.parallel: diff --git a/src/tests/cucumber/features/steps/steps.py b/src/tests/cucumber/features/steps/steps.py index f49bed8868..e3c69c9cf3 100644 --- a/src/tests/cucumber/features/steps/steps.py +++ b/src/tests/cucumber/features/steps/steps.py @@ -12,7 +12,6 @@ def study_path_is(context, string): @when('I run antares simulator') def run_antares(context): - context.use_ortools = True context.ortools_solver = "sirius" context.named_mps_problems = False context.parallel = False From 27fc92e4a00b69640c7a6668f7fbf7154f595614 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Fri, 4 Oct 2024 17:21:05 +0200 Subject: [PATCH 05/16] Trial to simplify solver call : solver ptr a bit more clear --- .../optimisation/opt_appel_solveur_lineaire.cpp | 17 +++++++---------- .../opt_liberation_problemes_simplexe.cpp | 1 - .../antares/solver/utils/ortools_wrapper.h | 5 ++--- src/solver/utils/ortools_utils.cpp | 17 +++++------------ 4 files changed, 14 insertions(+), 26 deletions(-) diff --git a/src/solver/optimisation/opt_appel_solveur_lineaire.cpp b/src/solver/optimisation/opt_appel_solveur_lineaire.cpp index c5f45015ec..2b82e81448 100644 --- a/src/solver/optimisation/opt_appel_solveur_lineaire.cpp +++ b/src/solver/optimisation/opt_appel_solveur_lineaire.cpp @@ -91,10 +91,6 @@ static SimplexResult OPT_TryToCallSimplex(const OptimizationOptions& options, assert(opt >= 0 && opt < 2); OptimizationStatistics& optimizationStatistics = problemeHebdo->optimizationStatistics[opt]; TIME_MEASURE timeMeasure; - if (!PremierPassage) - { - solver = nullptr; - } if (solver == nullptr) { @@ -105,14 +101,11 @@ static SimplexResult OPT_TryToCallSimplex(const OptimizationOptions& options, { if (problemeHebdo->ReinitOptimisation) { - if (solver != nullptr) - { - ORTOOLS_LibererProbleme(solver); - } + + ORTOOLS_LibererProbleme(solver); ProblemeAResoudre->ProblemesSpx[NumIntervalle] = nullptr; - solver = nullptr; Probleme.Contexte = SIMPLEXE_SEUL; Probleme.BaseDeDepartFournie = NON_SPX; } @@ -184,7 +177,11 @@ static SimplexResult OPT_TryToCallSimplex(const OptimizationOptions& options, Probleme.NombreDeContraintesCoupes = 0; - solver = ORTOOLS_ConvertIfNeeded(options.ortoolsSolver, &Probleme, solver); + if (solver == nullptr) + { + solver = ORTOOLS_Convert(options.ortoolsSolver, &Probleme); + } + const std::string filename = createMPSfilename(optPeriodStringGenerator, optimizationNumber); mpsWriterFactory mps_writer_factory(problemeHebdo->ExportMPS, diff --git a/src/solver/optimisation/opt_liberation_problemes_simplexe.cpp b/src/solver/optimisation/opt_liberation_problemes_simplexe.cpp index 9278d0f2a0..4a58919ea7 100644 --- a/src/solver/optimisation/opt_liberation_problemes_simplexe.cpp +++ b/src/solver/optimisation/opt_liberation_problemes_simplexe.cpp @@ -57,7 +57,6 @@ void OPT_LiberationProblemesSimplexe(const OptimizationOptions& options, if (solver != NULL) { ORTOOLS_LibererProbleme(solver); - solver = nullptr; } } } diff --git a/src/solver/utils/include/antares/solver/utils/ortools_wrapper.h b/src/solver/utils/include/antares/solver/utils/ortools_wrapper.h index 4f688dda4a..b7cc799db6 100644 --- a/src/solver/utils/include/antares/solver/utils/ortools_wrapper.h +++ b/src/solver/utils/include/antares/solver/utils/ortools_wrapper.h @@ -34,9 +34,8 @@ MPSolver* ORTOOLS_Simplexe(Antares::Optimization::PROBLEME_SIMPLEXE_NOMME* Probl bool keepBasis, const Antares::Solver::Optimization::OptimizationOptions& options); -MPSolver* ORTOOLS_ConvertIfNeeded(const std::string& solverName, - const Antares::Optimization::PROBLEME_SIMPLEXE_NOMME* Probleme, - MPSolver* solver); +MPSolver* ORTOOLS_Convert(const std::string& solverName, + const Antares::Optimization::PROBLEME_SIMPLEXE_NOMME* Probleme); void ORTOOLS_ModifierLeVecteurCouts(MPSolver* ProbSpx, const double* costs, int nbVar); void ORTOOLS_ModifierLeVecteurSecondMembre(MPSolver* ProbSpx, diff --git a/src/solver/utils/ortools_utils.cpp b/src/solver/utils/ortools_utils.cpp index 2cc81b80fa..2c7b9ac39e 100644 --- a/src/solver/utils/ortools_utils.cpp +++ b/src/solver/utils/ortools_utils.cpp @@ -329,19 +329,11 @@ bool solveAndManageStatus(MPSolver* solver, int& resultStatus, const MPSolverPar return resultStatus == OUI_SPX; } -MPSolver* ORTOOLS_ConvertIfNeeded(const std::string& solverName, - const Antares::Optimization::PROBLEME_SIMPLEXE_NOMME* Probleme, - MPSolver* solver) +MPSolver* ORTOOLS_Convert(const std::string& solverName, + const Antares::Optimization::PROBLEME_SIMPLEXE_NOMME* Probleme) { - if (solver == nullptr) - { - Antares::Optimization::ProblemSimplexeNommeConverter converter(solverName, Probleme); - return converter.Convert(); - } - else - { - return solver; - } + Antares::Optimization::ProblemSimplexeNommeConverter converter(solverName, Probleme); + return converter.Convert(); } MPSolver* ORTOOLS_Simplexe(Antares::Optimization::PROBLEME_SIMPLEXE_NOMME* Probleme, @@ -435,6 +427,7 @@ void ORTOOLS_CorrigerLesBornes(MPSolver* solver, void ORTOOLS_LibererProbleme(MPSolver* solver) { delete solver; + solver = nullptr; } const std::map OrtoolsUtils::solverMap = { From a4f1d8010d33418c3d88b855bc0646546b496006 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Fri, 4 Oct 2024 19:12:56 +0200 Subject: [PATCH 06/16] Trial to simplify solver call : crash correction --- src/solver/utils/include/antares/solver/utils/ortools_wrapper.h | 2 +- src/solver/utils/ortools_utils.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/solver/utils/include/antares/solver/utils/ortools_wrapper.h b/src/solver/utils/include/antares/solver/utils/ortools_wrapper.h index b7cc799db6..75a0b16bbd 100644 --- a/src/solver/utils/include/antares/solver/utils/ortools_wrapper.h +++ b/src/solver/utils/include/antares/solver/utils/ortools_wrapper.h @@ -47,6 +47,6 @@ void ORTOOLS_CorrigerLesBornes(MPSolver* ProbSpx, const double* bMax, const int* typeVar, int nbVar); -void ORTOOLS_LibererProbleme(MPSolver* ProbSpx); +void ORTOOLS_LibererProbleme(MPSolver*& ProbSpx); #endif diff --git a/src/solver/utils/ortools_utils.cpp b/src/solver/utils/ortools_utils.cpp index 2c7b9ac39e..f4a2f16b5d 100644 --- a/src/solver/utils/ortools_utils.cpp +++ b/src/solver/utils/ortools_utils.cpp @@ -424,7 +424,7 @@ void ORTOOLS_CorrigerLesBornes(MPSolver* solver, } } -void ORTOOLS_LibererProbleme(MPSolver* solver) +void ORTOOLS_LibererProbleme(MPSolver*& solver) { delete solver; solver = nullptr; From c8d58966d866e4d51915778587672e5d1a68793d Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Fri, 4 Oct 2024 17:29:21 +0200 Subject: [PATCH 07/16] Trial to simplify solver call : omission in previous commit corrected --- src/solver/optimisation/opt_appel_solveur_lineaire.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/solver/optimisation/opt_appel_solveur_lineaire.cpp b/src/solver/optimisation/opt_appel_solveur_lineaire.cpp index 2b82e81448..6f0898e87d 100644 --- a/src/solver/optimisation/opt_appel_solveur_lineaire.cpp +++ b/src/solver/optimisation/opt_appel_solveur_lineaire.cpp @@ -211,10 +211,7 @@ static SimplexResult OPT_TryToCallSimplex(const OptimizationOptions& options, { if (ProblemeAResoudre->ExistenceDUneSolution != SPX_ERREUR_INTERNE) { - if (solver != nullptr) - { - ORTOOLS_LibererProbleme(solver); - } + ORTOOLS_LibererProbleme(solver); logs.info() << " Solver: Standard resolution failed"; logs.info() << " Solver: Retry in safe mode"; // second trial w/o scaling From 343f2d8105385e47bcdf5ff913591c6b83a4942a Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Mon, 7 Oct 2024 13:19:28 +0200 Subject: [PATCH 08/16] Trial to simplify solver call : correct a crash on infeasible problems --- src/solver/optimisation/opt_appel_solveur_lineaire.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/solver/optimisation/opt_appel_solveur_lineaire.cpp b/src/solver/optimisation/opt_appel_solveur_lineaire.cpp index 6f0898e87d..33b874997a 100644 --- a/src/solver/optimisation/opt_appel_solveur_lineaire.cpp +++ b/src/solver/optimisation/opt_appel_solveur_lineaire.cpp @@ -212,6 +212,7 @@ static SimplexResult OPT_TryToCallSimplex(const OptimizationOptions& options, if (ProblemeAResoudre->ExistenceDUneSolution != SPX_ERREUR_INTERNE) { ORTOOLS_LibererProbleme(solver); + ProblemeAResoudre->ProblemesSpx[NumIntervalle] = nullptr; logs.info() << " Solver: Standard resolution failed"; logs.info() << " Solver: Retry in safe mode"; // second trial w/o scaling From 91de738066797a2279ab1b4998f1611c12a73c02 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Mon, 7 Oct 2024 13:35:08 +0200 Subject: [PATCH 09/16] Trial to simplify solver call : try to improve solver liberation --- src/solver/optimisation/opt_appel_solveur_lineaire.cpp | 5 ++--- .../optimisation/opt_liberation_problemes_simplexe.cpp | 2 +- .../utils/include/antares/solver/utils/ortools_wrapper.h | 2 +- src/solver/utils/ortools_utils.cpp | 4 ++-- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/solver/optimisation/opt_appel_solveur_lineaire.cpp b/src/solver/optimisation/opt_appel_solveur_lineaire.cpp index 33b874997a..641bff477a 100644 --- a/src/solver/optimisation/opt_appel_solveur_lineaire.cpp +++ b/src/solver/optimisation/opt_appel_solveur_lineaire.cpp @@ -102,8 +102,7 @@ static SimplexResult OPT_TryToCallSimplex(const OptimizationOptions& options, if (problemeHebdo->ReinitOptimisation) { - ORTOOLS_LibererProbleme(solver); - + solver = ORTOOLS_LibererProbleme(solver); ProblemeAResoudre->ProblemesSpx[NumIntervalle] = nullptr; Probleme.Contexte = SIMPLEXE_SEUL; @@ -211,7 +210,7 @@ static SimplexResult OPT_TryToCallSimplex(const OptimizationOptions& options, { if (ProblemeAResoudre->ExistenceDUneSolution != SPX_ERREUR_INTERNE) { - ORTOOLS_LibererProbleme(solver); + solver = ORTOOLS_LibererProbleme(solver); ProblemeAResoudre->ProblemesSpx[NumIntervalle] = nullptr; logs.info() << " Solver: Standard resolution failed"; diff --git a/src/solver/optimisation/opt_liberation_problemes_simplexe.cpp b/src/solver/optimisation/opt_liberation_problemes_simplexe.cpp index 4a58919ea7..27a4a9174c 100644 --- a/src/solver/optimisation/opt_liberation_problemes_simplexe.cpp +++ b/src/solver/optimisation/opt_liberation_problemes_simplexe.cpp @@ -56,7 +56,7 @@ void OPT_LiberationProblemesSimplexe(const OptimizationOptions& options, if (solver != NULL) { - ORTOOLS_LibererProbleme(solver); + solver = ORTOOLS_LibererProbleme(solver); } } } diff --git a/src/solver/utils/include/antares/solver/utils/ortools_wrapper.h b/src/solver/utils/include/antares/solver/utils/ortools_wrapper.h index 75a0b16bbd..1c5cf3d175 100644 --- a/src/solver/utils/include/antares/solver/utils/ortools_wrapper.h +++ b/src/solver/utils/include/antares/solver/utils/ortools_wrapper.h @@ -47,6 +47,6 @@ void ORTOOLS_CorrigerLesBornes(MPSolver* ProbSpx, const double* bMax, const int* typeVar, int nbVar); -void ORTOOLS_LibererProbleme(MPSolver*& ProbSpx); +MPSolver* ORTOOLS_LibererProbleme(MPSolver* ProbSpx); #endif diff --git a/src/solver/utils/ortools_utils.cpp b/src/solver/utils/ortools_utils.cpp index f4a2f16b5d..2e50974db4 100644 --- a/src/solver/utils/ortools_utils.cpp +++ b/src/solver/utils/ortools_utils.cpp @@ -424,10 +424,10 @@ void ORTOOLS_CorrigerLesBornes(MPSolver* solver, } } -void ORTOOLS_LibererProbleme(MPSolver*& solver) +MPSolver* ORTOOLS_LibererProbleme(MPSolver* solver) { delete solver; - solver = nullptr; + return nullptr; } const std::map OrtoolsUtils::solverMap = { From ef66d4ca3f5a1cc08841e7f1b9c88114b386f050 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Mon, 7 Oct 2024 13:58:24 +0200 Subject: [PATCH 10/16] Trial to simplify solver call : towards more improvement on solver liberation --- .../optimisation/opt_appel_solveur_lineaire.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/solver/optimisation/opt_appel_solveur_lineaire.cpp b/src/solver/optimisation/opt_appel_solveur_lineaire.cpp index 641bff477a..3b9bfa9aaf 100644 --- a/src/solver/optimisation/opt_appel_solveur_lineaire.cpp +++ b/src/solver/optimisation/opt_appel_solveur_lineaire.cpp @@ -92,19 +92,12 @@ static SimplexResult OPT_TryToCallSimplex(const OptimizationOptions& options, OptimizationStatistics& optimizationStatistics = problemeHebdo->optimizationStatistics[opt]; TIME_MEASURE timeMeasure; - if (solver == nullptr) - { - Probleme.Contexte = SIMPLEXE_SEUL; - Probleme.BaseDeDepartFournie = NON_SPX; - } - else + if (solver != nullptr) { if (problemeHebdo->ReinitOptimisation) { - solver = ORTOOLS_LibererProbleme(solver); ProblemeAResoudre->ProblemesSpx[NumIntervalle] = nullptr; - Probleme.Contexte = SIMPLEXE_SEUL; Probleme.BaseDeDepartFournie = NON_SPX; } @@ -212,6 +205,8 @@ static SimplexResult OPT_TryToCallSimplex(const OptimizationOptions& options, { solver = ORTOOLS_LibererProbleme(solver); ProblemeAResoudre->ProblemesSpx[NumIntervalle] = nullptr; + Probleme.Contexte = SIMPLEXE_SEUL; + Probleme.BaseDeDepartFournie = NON_SPX; logs.info() << " Solver: Standard resolution failed"; logs.info() << " Solver: Retry in safe mode"; // second trial w/o scaling From 59348c7529129b30626e67b1cb71f910d01d8d40 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Mon, 7 Oct 2024 14:34:14 +0200 Subject: [PATCH 11/16] Trial to simplify solver call : improve solvers passing among all runs (from week to week) --- .../optimisation/opt_structure_probleme_a_resoudre.h | 3 ++- src/solver/optimisation/opt_appel_solveur_lineaire.cpp | 8 +------- .../optimisation/opt_liberation_problemes_simplexe.cpp | 2 +- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/solver/optimisation/include/antares/solver/optimisation/opt_structure_probleme_a_resoudre.h b/src/solver/optimisation/include/antares/solver/optimisation/opt_structure_probleme_a_resoudre.h index 7641c23d4e..a606c85e6c 100644 --- a/src/solver/optimisation/include/antares/solver/optimisation/opt_structure_probleme_a_resoudre.h +++ b/src/solver/optimisation/include/antares/solver/optimisation/opt_structure_probleme_a_resoudre.h @@ -29,6 +29,7 @@ #include "opt_constants.h" +using namespace operations_research; /*--------------------------------------------------------------------------------------*/ /* Le probleme a resoudre */ @@ -90,7 +91,7 @@ struct PROBLEME_ANTARES_A_RESOUDRE matrice de base reguliere, et dans ce cas il n'y a pas de solution */ - std::vector ProblemesSpx; + std::vector ProblemesSpx; std::vector PositionDeLaVariable; /* Vecteur a passer au Simplexe pour recuperer la base optimale */ diff --git a/src/solver/optimisation/opt_appel_solveur_lineaire.cpp b/src/solver/optimisation/opt_appel_solveur_lineaire.cpp index 3b9bfa9aaf..e1df6c423b 100644 --- a/src/solver/optimisation/opt_appel_solveur_lineaire.cpp +++ b/src/solver/optimisation/opt_appel_solveur_lineaire.cpp @@ -85,7 +85,7 @@ static SimplexResult OPT_TryToCallSimplex(const OptimizationOptions& options, IResultWriter& writer) { const auto& ProblemeAResoudre = problemeHebdo->ProblemeAResoudre; - auto solver = (MPSolver*)(ProblemeAResoudre->ProblemesSpx[NumIntervalle]); + MPSolver*& solver = ProblemeAResoudre->ProblemesSpx[NumIntervalle]; const int opt = optimizationNumber - 1; assert(opt >= 0 && opt < 2); @@ -97,7 +97,6 @@ static SimplexResult OPT_TryToCallSimplex(const OptimizationOptions& options, if (problemeHebdo->ReinitOptimisation) { solver = ORTOOLS_LibererProbleme(solver); - ProblemeAResoudre->ProblemesSpx[NumIntervalle] = nullptr; Probleme.Contexte = SIMPLEXE_SEUL; Probleme.BaseDeDepartFournie = NON_SPX; } @@ -189,10 +188,6 @@ static SimplexResult OPT_TryToCallSimplex(const OptimizationOptions& options, const bool keepBasis = (optimizationNumber == PREMIERE_OPTIMISATION); solver = ORTOOLS_Simplexe(&Probleme, solver, keepBasis, options); - if (solver != nullptr) - { - ProblemeAResoudre->ProblemesSpx[NumIntervalle] = (void*)solver; - } measure.tick(); timeMeasure.solveTime = measure.duration_ms(); @@ -204,7 +199,6 @@ static SimplexResult OPT_TryToCallSimplex(const OptimizationOptions& options, if (ProblemeAResoudre->ExistenceDUneSolution != SPX_ERREUR_INTERNE) { solver = ORTOOLS_LibererProbleme(solver); - ProblemeAResoudre->ProblemesSpx[NumIntervalle] = nullptr; Probleme.Contexte = SIMPLEXE_SEUL; Probleme.BaseDeDepartFournie = NON_SPX; diff --git a/src/solver/optimisation/opt_liberation_problemes_simplexe.cpp b/src/solver/optimisation/opt_liberation_problemes_simplexe.cpp index 27a4a9174c..8c983baefc 100644 --- a/src/solver/optimisation/opt_liberation_problemes_simplexe.cpp +++ b/src/solver/optimisation/opt_liberation_problemes_simplexe.cpp @@ -52,7 +52,7 @@ void OPT_LiberationProblemesSimplexe(const OptimizationOptions& options, { for (int numIntervalle = 0; numIntervalle < nbIntervalles; numIntervalle++) { - auto solver = (MPSolver*)(ProblemeAResoudre->ProblemesSpx[numIntervalle]); + MPSolver*& solver = ProblemeAResoudre->ProblemesSpx[numIntervalle]; if (solver != NULL) { From e36b6dd4db18b69ae88993338c1b00c7809d2a43 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Mon, 7 Oct 2024 16:02:21 +0200 Subject: [PATCH 12/16] Trial to simplify solver call : avoid code duplication in resetting solver --- src/solver/optimisation/opt_appel_solveur_lineaire.cpp | 6 ++---- src/solver/utils/ortools_utils.cpp | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/solver/optimisation/opt_appel_solveur_lineaire.cpp b/src/solver/optimisation/opt_appel_solveur_lineaire.cpp index e1df6c423b..ad5e274531 100644 --- a/src/solver/optimisation/opt_appel_solveur_lineaire.cpp +++ b/src/solver/optimisation/opt_appel_solveur_lineaire.cpp @@ -97,8 +97,6 @@ static SimplexResult OPT_TryToCallSimplex(const OptimizationOptions& options, if (problemeHebdo->ReinitOptimisation) { solver = ORTOOLS_LibererProbleme(solver); - Probleme.Contexte = SIMPLEXE_SEUL; - Probleme.BaseDeDepartFournie = NON_SPX; } else { @@ -170,6 +168,8 @@ static SimplexResult OPT_TryToCallSimplex(const OptimizationOptions& options, if (solver == nullptr) { + Probleme.Contexte = SIMPLEXE_SEUL; + Probleme.BaseDeDepartFournie = NON_SPX; solver = ORTOOLS_Convert(options.ortoolsSolver, &Probleme); } @@ -199,8 +199,6 @@ static SimplexResult OPT_TryToCallSimplex(const OptimizationOptions& options, if (ProblemeAResoudre->ExistenceDUneSolution != SPX_ERREUR_INTERNE) { solver = ORTOOLS_LibererProbleme(solver); - Probleme.Contexte = SIMPLEXE_SEUL; - Probleme.BaseDeDepartFournie = NON_SPX; logs.info() << " Solver: Standard resolution failed"; logs.info() << " Solver: Retry in safe mode"; // second trial w/o scaling diff --git a/src/solver/utils/ortools_utils.cpp b/src/solver/utils/ortools_utils.cpp index 2e50974db4..f9fe97c16a 100644 --- a/src/solver/utils/ortools_utils.cpp +++ b/src/solver/utils/ortools_utils.cpp @@ -342,8 +342,8 @@ MPSolver* ORTOOLS_Simplexe(Antares::Optimization::PROBLEME_SIMPLEXE_NOMME* Probl const OptimizationOptions& options) { MPSolverParameters params; - setGenericParameters( - params); // Keep generic params for default settings working for all solvers + // Keep generic params for default settings working for all solvers + setGenericParameters(params); if (options.solverLogs) // May be overriden by log level if set as specific parameters { solver->EnableOutput(); From c2ab57535d30a39f82dc764942129ef39a39dde2 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Mon, 7 Oct 2024 17:22:09 +0200 Subject: [PATCH 13/16] Trial to simplify solver call : no need to import basic status into class PROBLEME_SIMPLEXE_NOMME --- .../solver/optimisation/opt_structure_probleme_a_resoudre.h | 3 --- src/solver/optimisation/opt_appel_solveur_lineaire.cpp | 1 - src/solver/utils/include/antares/solver/utils/named_problem.h | 4 ++-- src/solver/utils/named_problem.cpp | 4 +--- 4 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/solver/optimisation/include/antares/solver/optimisation/opt_structure_probleme_a_resoudre.h b/src/solver/optimisation/include/antares/solver/optimisation/opt_structure_probleme_a_resoudre.h index a606c85e6c..f6b7b4caf4 100644 --- a/src/solver/optimisation/include/antares/solver/optimisation/opt_structure_probleme_a_resoudre.h +++ b/src/solver/optimisation/include/antares/solver/optimisation/opt_structure_probleme_a_resoudre.h @@ -107,9 +107,6 @@ struct PROBLEME_ANTARES_A_RESOUDRE std::vector NomDesContraintes; std::vector VariablesEntieres; // true = int, false = continuous - - // PIMPL is used to break dependency to OR-Tools' linear_solver.h (big header) - Antares::Optimization::BasisStatus basisStatus; }; #endif /* __SOLVER_OPTIMISATION_STRUCTURE_PROBLEME_A_RESOUDRE_H__ */ diff --git a/src/solver/optimisation/opt_appel_solveur_lineaire.cpp b/src/solver/optimisation/opt_appel_solveur_lineaire.cpp index ad5e274531..e3682c141e 100644 --- a/src/solver/optimisation/opt_appel_solveur_lineaire.cpp +++ b/src/solver/optimisation/opt_appel_solveur_lineaire.cpp @@ -228,7 +228,6 @@ bool OPT_AppelDuSimplexe(const OptimizationOptions& options, Optimization::PROBLEME_SIMPLEXE_NOMME Probleme(ProblemeAResoudre->NomDesVariables, ProblemeAResoudre->NomDesContraintes, ProblemeAResoudre->VariablesEntieres, - ProblemeAResoudre->basisStatus, problemeHebdo->NamedProblems, options.solverLogs); diff --git a/src/solver/utils/include/antares/solver/utils/named_problem.h b/src/solver/utils/include/antares/solver/utils/named_problem.h index 2df99e7749..8589f433bf 100644 --- a/src/solver/utils/include/antares/solver/utils/named_problem.h +++ b/src/solver/utils/include/antares/solver/utils/named_problem.h @@ -27,6 +27,7 @@ #include "spx_definition_arguments.h" #include "spx_fonctions.h" +#include "basis_status.h" namespace Antares { @@ -40,7 +41,6 @@ struct PROBLEME_SIMPLEXE_NOMME: public PROBLEME_SIMPLEXE PROBLEME_SIMPLEXE_NOMME(const std::vector& NomDesVariables, const std::vector& NomDesContraintes, const std::vector& VariablesEntieres, - BasisStatus& basisStatus, bool UseNamedProblems, bool SolverLogs); @@ -51,7 +51,7 @@ struct PROBLEME_SIMPLEXE_NOMME: public PROBLEME_SIMPLEXE public: const std::vector& VariablesEntieres; - BasisStatus& basisStatus; + BasisStatus basisStatus; bool isMIP() const; bool basisExists() const; diff --git a/src/solver/utils/named_problem.cpp b/src/solver/utils/named_problem.cpp index cd23fa6e10..921fa89b5d 100644 --- a/src/solver/utils/named_problem.cpp +++ b/src/solver/utils/named_problem.cpp @@ -29,14 +29,12 @@ namespace Antares::Optimization PROBLEME_SIMPLEXE_NOMME::PROBLEME_SIMPLEXE_NOMME(const std::vector& NomDesVariables, const std::vector& NomDesContraintes, const std::vector& VariablesEntieres, - BasisStatus& basisStatus, bool UseNamedProblems, bool SolverLogs): NomDesVariables(NomDesVariables), NomDesContraintes(NomDesContraintes), useNamedProblems_(UseNamedProblems), - VariablesEntieres(VariablesEntieres), - basisStatus(basisStatus) + VariablesEntieres(VariablesEntieres) { AffichageDesTraces = SolverLogs ? OUI_SPX : NON_SPX; } From 1b4ebd08e68b1bb0416b9611b16bd38ccd503441 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Mon, 7 Oct 2024 17:29:34 +0200 Subject: [PATCH 14/16] Trial to simplify solver call : for solver, case SPX_ERREUR_INTERNE is impossible --- .../opt_appel_solveur_lineaire.cpp | 22 ++++++------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/src/solver/optimisation/opt_appel_solveur_lineaire.cpp b/src/solver/optimisation/opt_appel_solveur_lineaire.cpp index e3682c141e..2be23cf680 100644 --- a/src/solver/optimisation/opt_appel_solveur_lineaire.cpp +++ b/src/solver/optimisation/opt_appel_solveur_lineaire.cpp @@ -196,23 +196,15 @@ static SimplexResult OPT_TryToCallSimplex(const OptimizationOptions& options, ProblemeAResoudre->ExistenceDUneSolution = Probleme.ExistenceDUneSolution; if (ProblemeAResoudre->ExistenceDUneSolution != OUI_SPX && PremierPassage) { - if (ProblemeAResoudre->ExistenceDUneSolution != SPX_ERREUR_INTERNE) - { - solver = ORTOOLS_LibererProbleme(solver); + solver = ORTOOLS_LibererProbleme(solver); - logs.info() << " Solver: Standard resolution failed"; - logs.info() << " Solver: Retry in safe mode"; // second trial w/o scaling - logs.debug() << " solver: resetting"; - - return {.success = false, - .timeMeasure = timeMeasure, - .mps_writer_factory = mps_writer_factory}; - } + logs.info() << " Solver: Standard resolution failed"; + logs.info() << " Solver: Retry in safe mode"; // second trial w/o scaling + logs.debug() << " solver: resetting"; - else - { - throw FatalError("Internal error: insufficient memory"); - } + return {.success = false, + .timeMeasure = timeMeasure, + .mps_writer_factory = mps_writer_factory}; } return {.success = true, .timeMeasure = timeMeasure, .mps_writer_factory = mps_writer_factory}; } From 15851b6b46dbc124b754faaac4e8dee709489456 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Mon, 7 Oct 2024 18:16:41 +0200 Subject: [PATCH 15/16] Trial to simplify solver call : trial to remove status transfers between MPSolver and PROBLEME_SIMPLEXE_NOMME, possibly useless --- src/solver/utils/ortools_utils.cpp | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/solver/utils/ortools_utils.cpp b/src/solver/utils/ortools_utils.cpp index f9fe97c16a..84761d3baf 100644 --- a/src/solver/utils/ortools_utils.cpp +++ b/src/solver/utils/ortools_utils.cpp @@ -349,21 +349,10 @@ MPSolver* ORTOOLS_Simplexe(Antares::Optimization::PROBLEME_SIMPLEXE_NOMME* Probl solver->EnableOutput(); } TuneSolverSpecificOptions(solver, options.ortoolsSolver, options.solverParameters); - const bool warmStart = solverSupportsWarmStart(solver->ProblemType()); - // Provide an initial simplex basis, if any - if (warmStart && Probleme->basisExists()) - { - Probleme->basisStatus.setStartingBasis(solver); - } if (solveAndManageStatus(solver, Probleme->ExistenceDUneSolution, params)) { extract_from_MPSolver(solver, Probleme); - // Save the final simplex basis for next resolutions - if (warmStart && keepBasis) - { - Probleme->basisStatus.extractBasis(solver); - } } return solver; From 668ce025d6304a3a205c348fa1de7e56f7998cbe Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Tue, 8 Oct 2024 10:21:41 +0200 Subject: [PATCH 16/16] [skip ci] Revert "Trial to simplify solver call : trial to remove status transfers between MPSolver and PROBLEME_SIMPLEXE_NOMME, possibly useless" --- src/solver/utils/ortools_utils.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/solver/utils/ortools_utils.cpp b/src/solver/utils/ortools_utils.cpp index 84761d3baf..f9fe97c16a 100644 --- a/src/solver/utils/ortools_utils.cpp +++ b/src/solver/utils/ortools_utils.cpp @@ -349,10 +349,21 @@ MPSolver* ORTOOLS_Simplexe(Antares::Optimization::PROBLEME_SIMPLEXE_NOMME* Probl solver->EnableOutput(); } TuneSolverSpecificOptions(solver, options.ortoolsSolver, options.solverParameters); + const bool warmStart = solverSupportsWarmStart(solver->ProblemType()); + // Provide an initial simplex basis, if any + if (warmStart && Probleme->basisExists()) + { + Probleme->basisStatus.setStartingBasis(solver); + } if (solveAndManageStatus(solver, Probleme->ExistenceDUneSolution, params)) { extract_from_MPSolver(solver, Probleme); + // Save the final simplex basis for next resolutions + if (warmStart && keepBasis) + { + Probleme->basisStatus.extractBasis(solver); + } } return solver;