From 52da6259bdb12474bedecf6bbdfc827f9d86018d Mon Sep 17 00:00:00 2001 From: Jason Marechal Date: Thu, 14 Nov 2024 10:44:12 +0100 Subject: [PATCH] Fix tests --- .../test_lpnamer_01/user/expansion/settings.ini | 1 - src/cpp/lpnamer/main/ProblemGeneration.cpp | 8 ++++++-- .../antares-xpansion/lpnamer/main/ProblemGeneration.h | 2 ++ tests/cpp/lp_namer/ProblemGenerationExeOptionsTest.cpp | 5 +++++ tests/end_to_end/cucumber/features/SolverE2E.feature | 10 +++++++++- tests/end_to_end/cucumber/features/steps/steps.py | 4 +++- 6 files changed, 25 insertions(+), 5 deletions(-) diff --git a/data_test/tests_lpnamer/tests_integer/test_lpnamer_01/user/expansion/settings.ini b/data_test/tests_lpnamer/tests_integer/test_lpnamer_01/user/expansion/settings.ini index e9ea56cbf..5ebe01bdd 100644 --- a/data_test/tests_lpnamer/tests_integer/test_lpnamer_01/user/expansion/settings.ini +++ b/data_test/tests_lpnamer/tests_integer/test_lpnamer_01/user/expansion/settings.ini @@ -1,5 +1,4 @@ uc_type = expansion_fast master = integer optimality_gap = 10 -solver = Xpress additional-constraints = contraintes.txt \ No newline at end of file diff --git a/src/cpp/lpnamer/main/ProblemGeneration.cpp b/src/cpp/lpnamer/main/ProblemGeneration.cpp index b6d2e0391..8fd74a4de 100644 --- a/src/cpp/lpnamer/main/ProblemGeneration.cpp +++ b/src/cpp/lpnamer/main/ProblemGeneration.cpp @@ -117,8 +117,7 @@ std::filesystem::path ProblemGeneration::updateProblems() { auto weights_file = options_.WeightsFile(); auto unnamed_problems = options_.UnnamedProblems(); - SettingsReader settingsReader(study_dir / "user/expansion/settings.ini", logger.get()); - solver_name_ = settingsReader.Solver(); + set_solver(study_dir, logger.get()); RunProblemGeneration(xpansion_output_dir, master_formulation, additionalConstraintFilename_l, archive_path, logger, @@ -336,6 +335,11 @@ void ProblemGeneration::RunProblemGeneration( << "Problem Generation ran in: " << format_time_str(problem_generation_timer.elapsed()) << std::endl; } +void ProblemGeneration::set_solver(std::filesystem::path study_dir, ProblemGenerationLog::ProblemGenerationLogger* logger) { + SettingsReader settingsReader(study_dir / "user/expansion/settings.ini", logger); + solver_name_ = settingsReader.Solver(); +} + std::shared_ptr InstantiateZipReader( const std::filesystem::path& antares_archive_path) { auto reader = std::make_shared(antares_archive_path); diff --git a/src/cpp/lpnamer/main/include/antares-xpansion/lpnamer/main/ProblemGeneration.h b/src/cpp/lpnamer/main/include/antares-xpansion/lpnamer/main/ProblemGeneration.h index 1a66180c8..e74caa310 100644 --- a/src/cpp/lpnamer/main/include/antares-xpansion/lpnamer/main/ProblemGeneration.h +++ b/src/cpp/lpnamer/main/include/antares-xpansion/lpnamer/main/ProblemGeneration.h @@ -49,6 +49,8 @@ class ProblemGeneration { const std::vector& mpsList, std::filesystem::path& lpDir_, std::shared_ptr reader, const Antares::Solver::LpsFromAntares& lps); + virtual void set_solver(std::filesystem::path study_dir, ProblemGenerationLog::ProblemGenerationLogger* logger); + Antares::Solver::LpsFromAntares lps_; std::optional mode_; virtual std::filesystem::path performAntaresSimulation(); diff --git a/tests/cpp/lp_namer/ProblemGenerationExeOptionsTest.cpp b/tests/cpp/lp_namer/ProblemGenerationExeOptionsTest.cpp index f1f1292be..61d5534d8 100644 --- a/tests/cpp/lp_namer/ProblemGenerationExeOptionsTest.cpp +++ b/tests/cpp/lp_namer/ProblemGenerationExeOptionsTest.cpp @@ -53,6 +53,11 @@ class ProblemGenerationSpyAndMock : public ProblemGeneration { std::filesystem::path performAntaresSimulation() override { return options_.StudyPath() / "simulation"; } + void set_solver( + std::filesystem::path study_dir, + ProblemGenerationLog::ProblemGenerationLogger* logger) override { + + } public: std::filesystem::path xpansion_output_dir_; diff --git a/tests/end_to_end/cucumber/features/SolverE2E.feature b/tests/end_to_end/cucumber/features/SolverE2E.feature index 5c03e39fe..a9d62d34f 100644 --- a/tests/end_to_end/cucumber/features/SolverE2E.feature +++ b/tests/end_to_end/cucumber/features/SolverE2E.feature @@ -9,4 +9,12 @@ Feature: When I run antares-xpansion with the benders method and 1 proc(s) Then the simulation succeeds And Simulator has been launched with solver "Xpress" - And Benders has been launched with solver "Xpress" \ No newline at end of file + And Benders has been launched with solver "Xpress" + + Scenario: + Given the study path is "examples/SmallTestFiveCandidatesWithWeights" + And solver is "Cbc" + When I run antares-xpansion with the benders method and 1 proc(s) + Then the simulation succeeds + And Simulator has been launched with solver "Sirius" + And Benders has been launched with solver "Coin" \ No newline at end of file diff --git a/tests/end_to_end/cucumber/features/steps/steps.py b/tests/end_to_end/cucumber/features/steps/steps.py index 04d8d7d17..5f2729425 100644 --- a/tests/end_to_end/cucumber/features/steps/steps.py +++ b/tests/end_to_end/cucumber/features/steps/steps.py @@ -244,4 +244,6 @@ def check_simulator_solver(context, string): @then('Benders has been launched with solver "{string}"') def check_benders_solver(context, string): - assert context.options_data["SOLVER_NAME"].upper() == string.upper() \ No newline at end of file + solver_in_benders = context.options_data["SOLVER_NAME"] + print(f"Solver in benders: {solver_in_benders}\n") + assert solver_in_benders.upper() == string.upper() \ No newline at end of file