diff --git a/data_test/tests_lpnamer/tests_integer/test_lpnamer_01/output/economy/interco.txt b/data_test/tests_lpnamer/SmallTestFiveCandidates/output/simulation/interco-1-1.txt similarity index 100% rename from data_test/tests_lpnamer/tests_integer/test_lpnamer_01/output/economy/interco.txt rename to data_test/tests_lpnamer/SmallTestFiveCandidates/output/simulation/interco-1-1.txt diff --git a/data_test/tests_lpnamer/tests_integer/test_lpnamer_01/output/economy/area.txt b/data_test/tests_lpnamer/tests_integer/test_lpnamer_01/output/economy/area-01.txt similarity index 100% rename from data_test/tests_lpnamer/tests_integer/test_lpnamer_01/output/economy/area.txt rename to data_test/tests_lpnamer/tests_integer/test_lpnamer_01/output/economy/area-01.txt diff --git a/data_test/tests_lpnamer/tests_integer/test_lpnamer_01/output/economy/interco-01.txt b/data_test/tests_lpnamer/tests_integer/test_lpnamer_01/output/economy/interco-01.txt new file mode 100644 index 000000000..9ee2d6512 --- /dev/null +++ b/data_test/tests_lpnamer/tests_integer/test_lpnamer_01/output/economy/interco-01.txt @@ -0,0 +1,7 @@ +0 0 1 +1 0 3 +2 0 5 +3 1 2 +4 1 4 +5 2 6 +6 2 7 diff --git a/data_test/tests_lpnamer/tests_integer/test_one_link_one_candidate_1week/output/economy/area.txt b/data_test/tests_lpnamer/tests_integer/test_one_link_one_candidate_1week/output/economy/area-01.txt similarity index 100% rename from data_test/tests_lpnamer/tests_integer/test_one_link_one_candidate_1week/output/economy/area.txt rename to data_test/tests_lpnamer/tests_integer/test_one_link_one_candidate_1week/output/economy/area-01.txt diff --git a/data_test/tests_lpnamer/tests_integer/test_one_link_one_candidate_1week/output/economy/interco.txt b/data_test/tests_lpnamer/tests_integer/test_one_link_one_candidate_1week/output/economy/interco-01.txt similarity index 100% rename from data_test/tests_lpnamer/tests_integer/test_one_link_one_candidate_1week/output/economy/interco.txt rename to data_test/tests_lpnamer/tests_integer/test_one_link_one_candidate_1week/output/economy/interco-01.txt diff --git a/data_test/tests_lpnamer/tests_integer/test_one_link_two_candidates_1week/output/economy/area.txt b/data_test/tests_lpnamer/tests_integer/test_one_link_two_candidates_1week/output/economy/area-01.txt similarity index 100% rename from data_test/tests_lpnamer/tests_integer/test_one_link_two_candidates_1week/output/economy/area.txt rename to data_test/tests_lpnamer/tests_integer/test_one_link_two_candidates_1week/output/economy/area-01.txt diff --git a/data_test/tests_lpnamer/tests_integer/test_one_link_two_candidates_1week/output/economy/interco.txt b/data_test/tests_lpnamer/tests_integer/test_one_link_two_candidates_1week/output/economy/interco-01.txt similarity index 100% rename from data_test/tests_lpnamer/tests_integer/test_one_link_two_candidates_1week/output/economy/interco.txt rename to data_test/tests_lpnamer/tests_integer/test_one_link_two_candidates_1week/output/economy/interco-01.txt diff --git a/data_test/tests_lpnamer/tests_integer/test_one_link_two_candidates_simple_prob/output/economy/area.txt b/data_test/tests_lpnamer/tests_integer/test_one_link_two_candidates_simple_prob/output/economy/area-01.txt similarity index 100% rename from data_test/tests_lpnamer/tests_integer/test_one_link_two_candidates_simple_prob/output/economy/area.txt rename to data_test/tests_lpnamer/tests_integer/test_one_link_two_candidates_simple_prob/output/economy/area-01.txt diff --git a/data_test/tests_lpnamer/tests_integer/test_one_link_two_candidates_simple_prob/output/economy/interco.txt b/data_test/tests_lpnamer/tests_integer/test_one_link_two_candidates_simple_prob/output/economy/interco-01.txt similarity index 100% rename from data_test/tests_lpnamer/tests_integer/test_one_link_two_candidates_simple_prob/output/economy/interco.txt rename to data_test/tests_lpnamer/tests_integer/test_one_link_two_candidates_simple_prob/output/economy/interco-01.txt diff --git a/data_test/tests_lpnamer/tests_integer/test_one_link_two_candidates_simple_prob_hurdle_cost/output/economy/area.txt b/data_test/tests_lpnamer/tests_integer/test_one_link_two_candidates_simple_prob_hurdle_cost/output/economy/area-01.txt similarity index 100% rename from data_test/tests_lpnamer/tests_integer/test_one_link_two_candidates_simple_prob_hurdle_cost/output/economy/area.txt rename to data_test/tests_lpnamer/tests_integer/test_one_link_two_candidates_simple_prob_hurdle_cost/output/economy/area-01.txt diff --git a/data_test/tests_lpnamer/tests_integer/test_one_link_two_candidates_simple_prob_hurdle_cost/output/economy/interco.txt b/data_test/tests_lpnamer/tests_integer/test_one_link_two_candidates_simple_prob_hurdle_cost/output/economy/interco-01.txt similarity index 100% rename from data_test/tests_lpnamer/tests_integer/test_one_link_two_candidates_simple_prob_hurdle_cost/output/economy/interco.txt rename to data_test/tests_lpnamer/tests_integer/test_one_link_two_candidates_simple_prob_hurdle_cost/output/economy/interco-01.txt diff --git a/data_test/tests_lpnamer/tests_integer/test_one_link_two_candidates_simple_prob_null_profile/output/economy/area.txt b/data_test/tests_lpnamer/tests_integer/test_one_link_two_candidates_simple_prob_null_profile/output/economy/area-01.txt similarity index 100% rename from data_test/tests_lpnamer/tests_integer/test_one_link_two_candidates_simple_prob_null_profile/output/economy/area.txt rename to data_test/tests_lpnamer/tests_integer/test_one_link_two_candidates_simple_prob_null_profile/output/economy/area-01.txt diff --git a/data_test/tests_lpnamer/tests_integer/test_one_link_two_candidates_simple_prob_null_profile/output/economy/interco.txt b/data_test/tests_lpnamer/tests_integer/test_one_link_two_candidates_simple_prob_null_profile/output/economy/interco-01.txt similarity index 100% rename from data_test/tests_lpnamer/tests_integer/test_one_link_two_candidates_simple_prob_null_profile/output/economy/interco.txt rename to data_test/tests_lpnamer/tests_integer/test_one_link_two_candidates_simple_prob_null_profile/output/economy/interco-01.txt diff --git a/data_test/tests_lpnamer/tests_relaxed/SmallTestSixCandidatesWithAlreadyInstalledCapacity-relaxed/output/economy/area.txt b/data_test/tests_lpnamer/tests_relaxed/SmallTestSixCandidatesWithAlreadyInstalledCapacity-relaxed/output/economy/area-01.txt similarity index 100% rename from data_test/tests_lpnamer/tests_relaxed/SmallTestSixCandidatesWithAlreadyInstalledCapacity-relaxed/output/economy/area.txt rename to data_test/tests_lpnamer/tests_relaxed/SmallTestSixCandidatesWithAlreadyInstalledCapacity-relaxed/output/economy/area-01.txt diff --git a/data_test/tests_lpnamer/tests_relaxed/SmallTestSixCandidatesWithAlreadyInstalledCapacity-relaxed/output/economy/interco.txt b/data_test/tests_lpnamer/tests_relaxed/SmallTestSixCandidatesWithAlreadyInstalledCapacity-relaxed/output/economy/interco-01.txt similarity index 100% rename from data_test/tests_lpnamer/tests_relaxed/SmallTestSixCandidatesWithAlreadyInstalledCapacity-relaxed/output/economy/interco.txt rename to data_test/tests_lpnamer/tests_relaxed/SmallTestSixCandidatesWithAlreadyInstalledCapacity-relaxed/output/economy/interco-01.txt diff --git a/data_test/tests_lpnamer/tests_relaxed/test_one_link_one_candidate-relaxed/output/economy/area.txt b/data_test/tests_lpnamer/tests_relaxed/test_one_link_one_candidate-relaxed/output/economy/area-01.txt similarity index 100% rename from data_test/tests_lpnamer/tests_relaxed/test_one_link_one_candidate-relaxed/output/economy/area.txt rename to data_test/tests_lpnamer/tests_relaxed/test_one_link_one_candidate-relaxed/output/economy/area-01.txt diff --git a/data_test/tests_lpnamer/tests_relaxed/test_one_link_one_candidate-relaxed/output/economy/interco.txt b/data_test/tests_lpnamer/tests_relaxed/test_one_link_one_candidate-relaxed/output/economy/interco-01.txt similarity index 100% rename from data_test/tests_lpnamer/tests_relaxed/test_one_link_one_candidate-relaxed/output/economy/interco.txt rename to data_test/tests_lpnamer/tests_relaxed/test_one_link_one_candidate-relaxed/output/economy/interco-01.txt diff --git a/src/cpp/lpnamer/input_reader/LpFilesExtractor.cpp b/src/cpp/lpnamer/input_reader/LpFilesExtractor.cpp index 0fce4b0a3..7ef7666d5 100644 --- a/src/cpp/lpnamer/input_reader/LpFilesExtractor.cpp +++ b/src/cpp/lpnamer/input_reader/LpFilesExtractor.cpp @@ -1,54 +1,200 @@ #include "LpFilesExtractor.h" +#include #include #include "ArchiveReader.h" void LpFilesExtractor::ExtractFiles() const { - auto archive_reader = ArchiveReader(antares_archive_path_); + auto [vect_area_files, vect_interco_files] = getFiles(); + + checkProperNumberOfAreaFiles(vect_area_files); + produceAreatxtFile(vect_area_files); + + checkProperNumberOfIntercoFiles(vect_interco_files); + produceIntercotxtFile(vect_interco_files); +} + +/** + * @brief This method is used to get the files from the simulation directory. + * + * The patterns it looks for are "area*.txt" and "interco*.txt". + * + * @return A pair of vectors containing the paths of the files. The first vector contains the paths of the "area*.txt" files and the second vector contains the paths of the "interco*.txt" files. + */ +LpFilesExtractor::areaAndIntercoPaths LpFilesExtractor::getFiles() const{ + std::vector vect_area_files; + std::vector vect_interco_files; + switch (this->mode_) { + case SimulationInputMode::ARCHIVE: { + return getFilesFromArchive(); + } + case SimulationInputMode::ANTARES_API: + [[fallthrough]]; + case SimulationInputMode::FILE: { + auto dit = std::filesystem::directory_iterator(this->simulation_dir_); + std::ranges::for_each( + dit, [&vect_area_files, &vect_interco_files](const auto& entry) { + if (entry.path().extension() == ".txt") { + if (entry.path().filename().string().starts_with("area")) { + vect_area_files.push_back(entry.path()); + } + if (entry.path().filename().string().starts_with("interco")) { + vect_interco_files.push_back(entry.path()); + } + } + }); + } break; + case SimulationInputMode::UNKOWN: + throw LogUtils::XpansionError( + "SimulationInputMode is unknown", LOGLOCATION); + default: + throw LogUtils::XpansionError( + "SimulationInputMode is not supported:", LOGLOCATION); + } + return std::pair(vect_area_files, vect_interco_files); +} + +/** + * @brief This method is used to extract files from an archive. + * + * The patterns it looks for are "area*.txt", "interco*.txt", and "ts-numbers*". The extracted files are stored in the `xpansion_output_dir_` directory. + * + * @return A pair of vectors containing the paths of the extracted files. The first vector contains the paths of the "area*.txt" files and the second vector contains the paths of the "interco*.txt" files. + */ +LpFilesExtractor::areaAndIntercoPaths LpFilesExtractor::getFilesFromArchive() const { + std::vector vect_area_files; + std::vector vect_interco_files; + auto archive_reader = ArchiveReader(this->antares_archive_path_); archive_reader.Open(); - const auto vect_area_files = - archive_reader.ExtractPattern("area*.txt", "", xpansion_output_dir_); + vect_area_files = + archive_reader.ExtractPattern("area*.txt", "", this->xpansion_output_dir_); + + vect_interco_files = archive_reader.ExtractPattern("interco*.txt", "", + this->xpansion_output_dir_); + + archive_reader.ExtractPattern("ts-numbers*", "", this->xpansion_output_dir_); + return std::pair(vect_area_files, vect_interco_files); +} + + +/** + * @brief This method checks if the number of area files is correct. + * + * We should have only one file named "area*.txt". + * + * @param vect_area_files + */ +void LpFilesExtractor::checkProperNumberOfAreaFiles( + const std::vector& vect_area_files) const { if (auto num_areas_file = vect_area_files.size(); num_areas_file == 0) { std::ostringstream msg; auto log_location = LOGLOCATION; msg << "No area*.txt file found" << std::endl; - (*logger_)(LogUtils::LOGLEVEL::FATAL) - << log_location << msg.str(); + (*this->logger_)(LogUtils::LOGLEVEL::FATAL) << log_location << msg.str(); throw ErrorWithAreaFile(msg.str(), log_location); } else if (num_areas_file > 1) { std::ostringstream msg; auto log_location = LOGLOCATION; msg << "More than one area*.txt file found" << std::endl; - (*logger_)(LogUtils::LOGLEVEL::FATAL) - << log_location << msg.str(); + (*this->logger_)(LogUtils::LOGLEVEL::FATAL) << log_location << msg.str(); throw ErrorWithAreaFile(msg.str(), log_location); } - std::filesystem::rename(vect_area_files[0], - xpansion_output_dir_ / "area.txt"); +} - const auto vect_interco_files = - archive_reader.ExtractPattern("interco*.txt", "", xpansion_output_dir_); +/** + * @brief This method is used to produce the "area.txt" file from "area*.txt" + * + * In archive mode the file is just rename. Otherwise, the file is copied from + * the simulation directory to the `xpansion_output_dir_` directory. + * + * @param vect_area_files + */ +void LpFilesExtractor::produceAreatxtFile( + const std::vector& vect_area_files) const { + switch (this->mode_) { + case SimulationInputMode::ANTARES_API: + [[fallthrough]]; + case SimulationInputMode::FILE: + try { + std::filesystem::rename(vect_area_files[0], + this->xpansion_output_dir_ / "area.txt"); + } catch (const std::filesystem::filesystem_error& e) { + auto log_location = LOGLOCATION; + (*this->logger_)(LogUtils::LOGLEVEL::FATAL) << log_location << e.what(); + throw; + } + break; + case SimulationInputMode::ARCHIVE: + std::filesystem::rename(vect_area_files[0], + this->xpansion_output_dir_ / "area.txt"); + break; + case SimulationInputMode::UNKOWN: + throw LogUtils::XpansionError( + "SimulationInputMode is unknown", LOGLOCATION); + default: + throw LogUtils::XpansionError( + "SimulationInputMode is not supported:", LOGLOCATION); + } +} - if (auto num_intercos_file = vect_interco_files.size(); - num_intercos_file == 0) { +/** + * @brief This method checks if the number of interco files is correct. + * + * We should have only one file named "interco*.txt". + * + * @param vect_interco_files + */ +void LpFilesExtractor::checkProperNumberOfIntercoFiles( + const std::vector& vect_interco_files) const { + if (auto num_interco_file = vect_interco_files.size(); + num_interco_file == 0) { std::ostringstream msg; msg << "No interco*.txt file found" << std::endl; auto log_location = LOGLOCATION; - (*logger_)(LogUtils::LOGLEVEL::FATAL) - << log_location << msg.str(); + (*this->logger_)(LogUtils::LOGLEVEL::FATAL) << log_location << msg.str(); throw ErrorWithIntercosFile(msg.str(), log_location); - } else if (num_intercos_file > 1) { + } else if (num_interco_file > 1) { std::ostringstream msg; auto log_location = LOGLOCATION; msg << "More than one interco*.txt file found" << std::endl; - (*logger_)(LogUtils::LOGLEVEL::FATAL) - << log_location << msg.str(); + (*this->logger_)(LogUtils::LOGLEVEL::FATAL) << log_location << msg.str(); throw ErrorWithIntercosFile(msg.str(), log_location); } - std::filesystem::rename(vect_interco_files[0], - xpansion_output_dir_ / "interco.txt"); - archive_reader.ExtractPattern("ts-numbers*", "", xpansion_output_dir_); - archive_reader.Close(); - archive_reader.Delete(); -} \ No newline at end of file +} + +/** + * @brief This method is used to produce the "interco.txt" file from "interco*.txt" + * + * In archive mode the file is just rename. Otherwise, the file is copied from + * the simulation directory to the `xpansion_output_dir_` directory. + * + * @param vect_interco_files + */ +void LpFilesExtractor::produceIntercotxtFile( + const std::vector& vect_interco_files) const { + switch (this->mode_) { + case SimulationInputMode::ANTARES_API: + [[fallthrough]]; + case SimulationInputMode::FILE: + try { + std::filesystem::rename(vect_interco_files[0], + this->xpansion_output_dir_ / "interco.txt"); + } catch (const std::filesystem::filesystem_error& e) { + auto log_location = LOGLOCATION; + (*this->logger_)(LogUtils::LOGLEVEL::FATAL) << log_location << e.what(); + throw; + } + break; + case SimulationInputMode::ARCHIVE: + std::filesystem::rename(vect_interco_files[0], + this->xpansion_output_dir_ / "interco.txt"); + break; + case SimulationInputMode::UNKOWN: + throw LogUtils::XpansionError( + "SimulationInputMode is unknown", LOGLOCATION); + default: + throw LogUtils::XpansionError( + "SimulationInputMode is not supported:", LOGLOCATION); + } +} diff --git a/src/cpp/lpnamer/input_reader/LpFilesExtractor.h b/src/cpp/lpnamer/input_reader/LpFilesExtractor.h index 5f66533b2..fc1b36be5 100644 --- a/src/cpp/lpnamer/input_reader/LpFilesExtractor.h +++ b/src/cpp/lpnamer/input_reader/LpFilesExtractor.h @@ -1,24 +1,32 @@ #ifndef SRC_CPP_LPNAMER_INPUTREADER_LP_FILES_EXTRACTOR_H #define SRC_CPP_LPNAMER_INPUTREADER_LP_FILES_EXTRACTOR_H #include +#include #include "LogUtils.h" #include "ProblemGenerationLogger.h" +#include "SimulationInputMode.h" class LpFilesExtractor { private: - std::filesystem::path antares_archive_path_; - std::filesystem::path xpansion_output_dir_; + const std::filesystem::path antares_archive_path_; + const std::filesystem::path xpansion_output_dir_; ProblemGenerationLog::ProblemGenerationLoggerSharedPointer logger_; + const SimulationInputMode mode_; + const std::filesystem::path& simulation_dir_; public: explicit LpFilesExtractor( - const std::filesystem::path& antares_archive_path, - const std::filesystem::path& xpansion_output_dir, - ProblemGenerationLog::ProblemGenerationLoggerSharedPointer logger) - : antares_archive_path_(antares_archive_path), - xpansion_output_dir_(xpansion_output_dir), - logger_(logger) {} + std::filesystem::path antares_archive_path, + std::filesystem::path xpansion_output_dir, + ProblemGenerationLog::ProblemGenerationLoggerSharedPointer logger, + SimulationInputMode mode = SimulationInputMode::UNKOWN, + const std::filesystem::path& simulation_dir = {}) + : antares_archive_path_(std::move(antares_archive_path)), + xpansion_output_dir_(std::move(xpansion_output_dir)), + logger_(std::move(logger)), + mode_(mode), + simulation_dir_(simulation_dir) {} void ExtractFiles() const; class ErrorWithAreaFile : public LogUtils::XpansionError { @@ -27,5 +35,16 @@ class LpFilesExtractor { class ErrorWithIntercosFile : public LogUtils::XpansionError { using LogUtils::XpansionError::XpansionError; }; + private: + using areaAndIntercoPaths = std::pair, std::vector>; + [[nodiscard]] areaAndIntercoPaths getFiles() const; + [[nodiscard]] areaAndIntercoPaths getFilesFromArchive() const; + void checkProperNumberOfAreaFiles( + const std::vector& vect_area_files) const; + void produceAreatxtFile(const std::vector& vect_area_files) const; + void checkProperNumberOfIntercoFiles( + const std::vector& vect_interco_files) const; + void produceIntercotxtFile( + const std::vector& vect_interco_files) const; }; #endif // SRC_CPP_LPNAMER_INPUTREADER_LP_FILES_EXTRACTOR_H diff --git a/src/cpp/lpnamer/main/ProblemGeneration.cpp b/src/cpp/lpnamer/main/ProblemGeneration.cpp index fcb5c77f2..135e56465 100644 --- a/src/cpp/lpnamer/main/ProblemGeneration.cpp +++ b/src/cpp/lpnamer/main/ProblemGeneration.cpp @@ -1,11 +1,9 @@ -// -// Created by marechaljas on 27/10/23. -// #include "include/ProblemGeneration.h" #include #include +#include #include "ActiveLinks.h" #include "AdditionalConstraints.h" @@ -28,6 +26,7 @@ #include "Version.h" #include "WeightsFileReader.h" #include "WeightsFileWriter.h" +#include "XpansionProblemsFromAntaresProvider.h" #include "ZipProblemsProviderAdapter.h" #include "config.h" @@ -44,20 +43,46 @@ void CreateDirectories(const std::filesystem::path& output_path) { } ProblemGeneration::ProblemGeneration(ProblemGenerationOptions& options) - : options_(options) {} + : options_(options) { + if (!options_.StudyPath().empty()) { + mode_ = SimulationInputMode::ANTARES_API; + } else if (!options_.XpansionOutputDir().empty()) { + mode_ = SimulationInputMode::FILE; + } else if (!options_.ArchivePath().empty()) { + mode_ = SimulationInputMode::ARCHIVE; + } +} + std::filesystem::path ProblemGeneration::updateProblems() { - const auto xpansion_output_dir = options_.XpansionOutputDir(); + using namespace std::string_literals; + std::filesystem::path xpansion_output_dir; const auto archive_path = options_.ArchivePath(); - auto deduced_xpansion_output_dir = - options_.deduceXpansionDirIfEmpty(xpansion_output_dir, archive_path); + if (mode_ == SimulationInputMode::ARCHIVE) { + xpansion_output_dir = + options_.deduceXpansionDirIfEmpty(xpansion_output_dir, archive_path); + } + + if (mode_ == SimulationInputMode::ANTARES_API) { + throw std::runtime_error("SimulationInputMode API Not implemented yet"); + } + + if (mode_ == SimulationInputMode::FILE) { + simulation_dir_ = options_.XpansionOutputDir(); // Legacy naming. + // options_.XpansionOutputDir() point in fact to a simulation output from + // antares + } + + if (mode_ == SimulationInputMode::ANTARES_API || mode_ == SimulationInputMode::FILE) { + xpansion_output_dir = simulation_dir_; + } const auto log_file_path = - deduced_xpansion_output_dir / "lp" / "ProblemGenerationLog.txt"; + xpansion_output_dir / "lp"s / "ProblemGenerationLog.txt"s; - CreateDirectories(deduced_xpansion_output_dir); + CreateDirectories(xpansion_output_dir); // Ca ou -Xpansion ? auto logger = ProblemGenerationLog::BuildLogger(log_file_path, std::cout, - "Problem Generation"); + "Problem Generation"s); auto master_formulation = options_.MasterFormulation(); auto additionalConstraintFilename_l = @@ -65,9 +90,10 @@ std::filesystem::path ProblemGeneration::updateProblems() { auto weights_file = options_.WeightsFile(); auto unnamed_problems = options_.UnnamedProblems(); - RunProblemGeneration(deduced_xpansion_output_dir, master_formulation, - additionalConstraintFilename_l, archive_path, logger, log_file_path, weights_file, unnamed_problems); - return deduced_xpansion_output_dir; + RunProblemGeneration(xpansion_output_dir, master_formulation, + additionalConstraintFilename_l, archive_path, logger, + log_file_path, weights_file, unnamed_problems); + return xpansion_output_dir; } std::shared_ptr InstantiateZipReader( @@ -96,7 +122,8 @@ void ProblemGeneration::ExtractUtilsFiles( const std::filesystem::path& xpansion_output_dir, ProblemGenerationLog::ProblemGenerationLoggerSharedPointer logger) { auto utils_files_extractor = - LpFilesExtractor(antares_archive_path, xpansion_output_dir, logger); + LpFilesExtractor(antares_archive_path, xpansion_output_dir, + std::move(logger), mode_, simulation_dir_); utils_files_extractor.ExtractFiles(); } @@ -127,22 +154,32 @@ void validateMasterFormulation( } } -std::vector> getXpansionProblems( +std::vector> ProblemGeneration::getXpansionProblems( SolverLogManager& solver_log_manager, const std::string& solver_name, const std::vector& mpsList, std::filesystem::path& lpDir_, - std::shared_ptr& reader, bool with_archive = true) { + std::shared_ptr& reader, bool with_archive = true + ) { std::vector problem_names; std::transform(mpsList.begin(), mpsList.end(), std::back_inserter(problem_names), [](ProblemData const& data) { return data._problem_mps; }); - if (with_archive) { - auto adapter = std::make_shared(lpDir_, reader, - problem_names); - return adapter->provideProblems(solver_name, solver_log_manager); - } else { - auto adapter = - std::make_shared(lpDir_, problem_names); - return adapter->provideProblems(solver_name, solver_log_manager); + switch (mode_) { + case SimulationInputMode::FILE: { + auto adapter = + std::make_unique(lpDir_, problem_names); + return adapter->provideProblems(solver_name, solver_log_manager); + } + case SimulationInputMode::ARCHIVE: { + auto adapter = std::make_unique( + lpDir_, reader, problem_names); + return adapter->provideProblems(solver_name, solver_log_manager); + } + case SimulationInputMode::ANTARES_API: { + throw std::runtime_error("SimulationInputMode API Not implemented yet"); + } + default: + // TODO : log + return {}; } } @@ -167,8 +204,7 @@ void ProblemGeneration::RunProblemGeneration( logger); } - if (!antares_archive_path.empty()) - ExtractUtilsFiles(antares_archive_path, xpansion_output_dir, logger); + ExtractUtilsFiles(antares_archive_path, xpansion_output_dir, logger); std::vector links = getLinks(xpansion_output_dir, logger); @@ -187,6 +223,8 @@ void ProblemGeneration::RunProblemGeneration( antares_version < first_version_without_variables_files; (*logger)(LogUtils::LOGLEVEL::INFO) << "rename problems: " << std::boolalpha << rename_problems << std::endl; + + auto files_mapper = FilesMapper(antares_archive_path, xpansion_output_dir); auto mpsList = files_mapper.MpsAndVariablesFilesVect(); @@ -199,14 +237,21 @@ void ProblemGeneration::RunProblemGeneration( : InstantiateZipReader(antares_archive_path); /* Main stuff */ - std::vector> xpansion_problems = getXpansionProblems(solver_log_manager, solver_name, mpsList, lpDir_, - reader, !antares_archive_path.empty()); + std::vector> xpansion_problems = + getXpansionProblems(solver_log_manager, solver_name, mpsList, lpDir_, + reader, !antares_archive_path.empty() + ); std::vector, ProblemData>> problems_and_data; for (int i = 0; i < xpansion_problems.size(); ++i) { - xpansion_problems.at(i)->_name = mpsList.at(i)._problem_mps; - problems_and_data.emplace_back(xpansion_problems.at(i), mpsList.at(i)); + if (mode_ == SimulationInputMode::ANTARES_API) { + ProblemData data{xpansion_problems.at(i)->_name, {}}; + problems_and_data.emplace_back(xpansion_problems.at(i), data); + } else { + xpansion_problems.at(i)->_name = mpsList.at(i)._problem_mps; + problems_and_data.emplace_back(xpansion_problems.at(i), mpsList.at(i)); + } } auto mps_file_writer = std::make_shared(lpDir_); std::for_each( @@ -214,27 +259,39 @@ void ProblemGeneration::RunProblemGeneration( [&](const auto& problem_and_data) { const auto& [problem, data] = problem_and_data; std::shared_ptr variables_provider; - if (antares_archive_path.empty()) { - variables_provider = std::make_shared( - data, links, logger, lpDir_); - } else { - if (rename_problems) { - variables_provider = std::make_shared( - reader, data, links, logger); - } else { + switch (mode_) { + case SimulationInputMode::FILE: + variables_provider = std::make_shared( + data, links, logger, lpDir_); + break; + case SimulationInputMode::ARCHIVE: + if (rename_problems) { + variables_provider = std::make_shared( + reader, data, links, logger); + } else { + variables_provider = + std::make_shared( + problem, links, logger); + } + break; + case SimulationInputMode::ANTARES_API: variables_provider = std::make_shared( problem, links, logger); - } + break; + default: + (*logger)(LogUtils::LOGLEVEL::ERR) << "Undefined mode"; + break; } linkProblemsGenerator.treat(data._problem_mps, couplings, problem.get(), variables_provider.get(), mps_file_writer.get()); }); - reader->Close(); - reader->Delete(); - + if (mode_ == SimulationInputMode::ARCHIVE) { + reader->Close(); + reader->Delete(); + } MasterGeneration master_generation( xpansion_output_dir, links, additionalConstraints, couplings, master_formulation, solver_name, logger, solver_log_manager); diff --git a/src/cpp/lpnamer/main/ProblemGenerationExeOptions.cpp b/src/cpp/lpnamer/main/ProblemGenerationExeOptions.cpp index 95c882271..b746b8278 100644 --- a/src/cpp/lpnamer/main/ProblemGenerationExeOptions.cpp +++ b/src/cpp/lpnamer/main/ProblemGenerationExeOptions.cpp @@ -1,5 +1,6 @@ #include "ProblemGenerationExeOptions.h" namespace po = boost::program_options; +using namespace std::string_literals; ProblemGenerationExeOptions::ProblemGenerationExeOptions() : OptionsParser("Problem Generation exe") { @@ -8,6 +9,7 @@ ProblemGenerationExeOptions::ProblemGenerationExeOptions() "antares-xpansion study output")( "archive,a", po::value(&archive_path_), "antares-xpansion study zip")( + "study", po::value(&study_path_), "antares study")( "formulation,f", po::value(&master_formulation_)->default_value("relaxed"), "master formulation (relaxed or integer)")( @@ -21,50 +23,47 @@ ProblemGenerationExeOptions::ProblemGenerationExeOptions() "use this option if unnamed problems are provided"); } void ProblemGenerationExeOptions::Parse(unsigned int argc, - const char *const *argv) { + const char* const* argv) { OptionsParser::Parse(argc, argv); auto log_location = LOGLOCATION; - using namespace std::string_literals; - if (!XpansionOutputDir().empty() && !ArchivePath().empty()) { - auto msg = "Giving both archive and output options is not permitted"s; + checkMandatoryOptions(log_location); +} + +auto ProblemGenerationExeOptions::exclusiveMandatoryParameters() const { + return std::vector{this->XpansionOutputDir().string(), + this->ArchivePath().string(), + this->StudyPath().string()}; +} + +namespace { +auto notEmpty = [](auto k) { return !k.empty(); }; +} +void ProblemGenerationExeOptions::checkMandatoryOptions( + const std::string& log_location) const { + auto args = exclusiveMandatoryParameters(); + auto count = std::ranges::count_if(args, notEmpty); + if (count > 1) { + auto msg = "Only one of [archive, output, study] parameters is accepted"s; throw ProblemGenerationOptions::ConflictingParameters(msg, log_location); } - if (XpansionOutputDir().empty() && ArchivePath().empty()) { - auto msg = "Both output directory and archive path are empty"s; + if (count == 0) { + auto msg = + "Need to give at least on of [OutputDir, Archive, Study] options"s; throw ProblemGenerationOptions::MissingParameters(msg, log_location); } } -std::filesystem::path ProblemGenerationExeOptions::deduceArchivePathIfEmpty( - const std::filesystem::path& xpansion_output_dir, - const std::filesystem::path& archive_path) const { - if (archive_path.empty() && !xpansion_output_dir.empty()) { - if (xpansion_output_dir.string().find("-Xpansion") == std::string::npos) { - auto log_location = LOGLOCATION; - auto msg = - "Archive path is missing and output path does not contains" - " \"-Xpansion\" suffixe. Can't deduce archive file name."; - throw MismatchedParameters(msg, log_location); - } - auto deduced_archive_path = xpansion_output_dir; - auto dir_name = deduced_archive_path.stem().string(); - dir_name = dir_name.substr(0, dir_name.find("-Xpansion")); - deduced_archive_path = - deduced_archive_path.replace_filename(dir_name).replace_extension( - ".zip"); - return deduced_archive_path; - } - return archive_path; -} - std::filesystem::path ProblemGenerationExeOptions::deduceXpansionDirIfEmpty( std::filesystem::path xpansion_output_dir, const std::filesystem::path& archive_path) const { if (xpansion_output_dir.empty() && !archive_path.empty()) { auto deduced_dir = archive_path; deduced_dir = deduced_dir.replace_filename( - deduced_dir.stem().replace_extension("").string() + "-Xpansion"); + deduced_dir.stem().replace_extension("").string() + "-Xpansion"s); return deduced_dir; } return xpansion_output_dir; -} \ No newline at end of file +} +std::filesystem::path ProblemGenerationExeOptions::StudyPath() const { + return study_path_; +} diff --git a/src/cpp/lpnamer/main/include/ProblemGeneration.h b/src/cpp/lpnamer/main/include/ProblemGeneration.h index f9ac5618f..8aded3546 100644 --- a/src/cpp/lpnamer/main/include/ProblemGeneration.h +++ b/src/cpp/lpnamer/main/include/ProblemGeneration.h @@ -7,16 +7,23 @@ #include #include +#include "../../input_reader/MpsTxtWriter.h" +#include "../../model/Problem.h" +#include "../../model/SimulationInputMode.h" +#include "ArchiveReader.h" #include "ProblemGenerationExeOptions.h" #include "ProblemGenerationLogger.h" #include "ProblemGenerationOptions.h" +#include "multisolver_interface/SolverAbstract.h" class ProblemGeneration { public: explicit ProblemGeneration(ProblemGenerationOptions& options); + virtual ~ProblemGeneration() = default; std::filesystem::path updateProblems(); ProblemGenerationOptions& options_; + private: virtual void RunProblemGeneration( const std::filesystem::path& xpansion_output_dir, const std::string& master_formulation, @@ -26,7 +33,6 @@ class ProblemGeneration { const std::filesystem::path& log_file_path, const std::filesystem::path& weights_file, bool unnamed_problems); - private: void ProcessWeights( const std::filesystem::path& xpansion_output_dir, const std::filesystem::path& antares_archive_path, @@ -36,4 +42,10 @@ class ProblemGeneration { const std::filesystem::path& antares_archive_path, const std::filesystem::path& xpansion_output_dir, ProblemGenerationLog::ProblemGenerationLoggerSharedPointer logger); + std::vector> getXpansionProblems( + SolverLogManager& solver_log_manager, const std::string& solver_name, + const std::vector& mpsList, std::filesystem::path& lpDir_, + std::shared_ptr& reader, bool with_archive); + SimulationInputMode mode_ = SimulationInputMode::UNKOWN; + std::filesystem::path simulation_dir_; }; diff --git a/src/cpp/lpnamer/main/include/ProblemGenerationExeOptions.h b/src/cpp/lpnamer/main/include/ProblemGenerationExeOptions.h index 9f05cdc21..d623817f5 100644 --- a/src/cpp/lpnamer/main/include/ProblemGenerationExeOptions.h +++ b/src/cpp/lpnamer/main/include/ProblemGenerationExeOptions.h @@ -13,33 +13,44 @@ class ProblemGenerationExeOptions : public OptionsParser, std::string master_formulation_; std::string additional_constraintFilename_l_; std::filesystem::path archive_path_; - std::filesystem::path weights_file_ = ""; + std::filesystem::path weights_file_; std::vector active_years_; - bool unnamed_problems_; + bool unnamed_problems_ = false; + std::filesystem::path study_path_; public: ProblemGenerationExeOptions(); - virtual ~ProblemGenerationExeOptions() = default; - std::filesystem::path XpansionOutputDir() const { + ~ProblemGenerationExeOptions() override = default; + [[nodiscard]] std::filesystem::path XpansionOutputDir() const override { return xpansion_output_dir_; } - std::string MasterFormulation() const { return master_formulation_; } - std::string AdditionalConstraintsFilename() const { + [[nodiscard]] std::string MasterFormulation() const override { + return master_formulation_; + } + [[nodiscard]] std::string AdditionalConstraintsFilename() const override { return additional_constraintFilename_l_; } - std::filesystem::path ArchivePath() const { return archive_path_; } - std::filesystem::path WeightsFile() const { return weights_file_; } - std::vector ActiveYears() const { return active_years_; } - bool UnnamedProblems() const { return unnamed_problems_; } + [[nodiscard]] std::filesystem::path ArchivePath() const override { + return archive_path_; + } + [[nodiscard]] std::filesystem::path WeightsFile() const override { + return weights_file_; + } + [[nodiscard]] std::vector ActiveYears() const override { + return active_years_; + } + [[nodiscard]] bool UnnamedProblems() const override { + return unnamed_problems_; + } void Parse(unsigned int argc, const char *const *argv) override; [[nodiscard]] std::filesystem::path deduceXpansionDirIfEmpty( std::filesystem::path xpansion_output_dir, const std::filesystem::path& archive_path) const override; - [[nodiscard]] std::filesystem::path deduceArchivePathIfEmpty( - const std::filesystem::path& xpansion_output_dir, - const std::filesystem::path& archive_path) const override; + [[nodiscard]] std::filesystem::path StudyPath() const override; + void checkMandatoryOptions(const std::string& log_location) const; + [[nodiscard]] auto exclusiveMandatoryParameters() const; }; #endif // ANTARES_XPANSION_SRC_CPP_LPNAMER_MAIN_INCLUDE_PROBLEMGENERATIONEXEOPTIONS_H diff --git a/src/cpp/lpnamer/main/include/ProblemGenerationOptions.h b/src/cpp/lpnamer/main/include/ProblemGenerationOptions.h index 338ead38d..c649f7334 100644 --- a/src/cpp/lpnamer/main/include/ProblemGenerationOptions.h +++ b/src/cpp/lpnamer/main/include/ProblemGenerationOptions.h @@ -20,9 +20,7 @@ class ProblemGenerationOptions { [[nodiscard]] virtual std::filesystem::path deduceXpansionDirIfEmpty( std::filesystem::path xpansion_output_dir, const std::filesystem::path& archive_path) const = 0; - [[nodiscard]] virtual std::filesystem::path deduceArchivePathIfEmpty( - const std::filesystem::path& xpansion_output_dir, - const std::filesystem::path& archive_path) const = 0; + [[nodiscard]] virtual std::filesystem::path StudyPath() const = 0; class ConflictingParameters : public LogUtils::XpansionError { diff --git a/src/cpp/lpnamer/model/CMakeLists.txt b/src/cpp/lpnamer/model/CMakeLists.txt index 3132f73da..fdb2c8225 100644 --- a/src/cpp/lpnamer/model/CMakeLists.txt +++ b/src/cpp/lpnamer/model/CMakeLists.txt @@ -13,11 +13,16 @@ add_library (lp_namer_model STATIC ${CMAKE_CURRENT_SOURCE_DIR}/ActiveLinks.h ${CMAKE_CURRENT_SOURCE_DIR}/LinkProfile.cpp ${CMAKE_CURRENT_SOURCE_DIR}/LinkProfile.h - ${CMAKE_CURRENT_SOURCE_DIR}/Problem.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Problem.h - ${CMAKE_CURRENT_SOURCE_DIR}/ProblemNameParser.h ${CMAKE_CURRENT_SOURCE_DIR}/ProblemNameParser.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/ChronicleMapReader.h ${CMAKE_CURRENT_SOURCE_DIR}/ChronicleMapReader.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/ChronicleMapProvider.h ${CMAKE_CURRENT_SOURCE_DIR}/ChronicleMapProvider.cpp - ) + ${CMAKE_CURRENT_SOURCE_DIR}/Problem.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/Problem.h + ${CMAKE_CURRENT_SOURCE_DIR}/ProblemNameParser.h + ${CMAKE_CURRENT_SOURCE_DIR}/ProblemNameParser.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/ChronicleMapReader.h + ${CMAKE_CURRENT_SOURCE_DIR}/ChronicleMapReader.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/ChronicleMapProvider.h + ${CMAKE_CURRENT_SOURCE_DIR}/ChronicleMapProvider.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/SimulationInputMode.h +) target_include_directories (lp_namer_model PUBLIC diff --git a/src/cpp/lpnamer/model/SimulationInputMode.h b/src/cpp/lpnamer/model/SimulationInputMode.h new file mode 100644 index 000000000..e7b4c9d62 --- /dev/null +++ b/src/cpp/lpnamer/model/SimulationInputMode.h @@ -0,0 +1,12 @@ +// +// Created by marechaljas on 22/01/24. +// + +#pragma once + +enum class SimulationInputMode { + ANTARES_API, + FILE, + ARCHIVE, + UNKOWN, +}; \ No newline at end of file diff --git a/tests/cpp/lp_namer/LpFilesExtractorTest.cpp b/tests/cpp/lp_namer/LpFilesExtractorTest.cpp index 5bac136d3..6dbac8a21 100644 --- a/tests/cpp/lp_namer/LpFilesExtractorTest.cpp +++ b/tests/cpp/lp_namer/LpFilesExtractorTest.cpp @@ -21,8 +21,8 @@ class LpFilesExtractorTest : public ::testing::Test { }; TEST_F(LpFilesExtractorTest, IfNoAreaFileIsInAntaresArchive) { - auto lp_files_extractor = LpFilesExtractor( - EMPTY_ARCHIVE, std::filesystem::temp_directory_path(), logger_); + auto lp_files_extractor = LpFilesExtractor(EMPTY_ARCHIVE, std::filesystem::temp_directory_path(), + logger_, SimulationInputMode::ARCHIVE); std::ostringstream expectedErrorString; expectedErrorString << "No area*.txt file found" << std::endl; @@ -35,7 +35,8 @@ TEST_F(LpFilesExtractorTest, IfNoAreaFileIsInAntaresArchive) { } TEST_F(LpFilesExtractorTest, IfMoreThanOneAreaFileFoundInAntaresArchive) { auto lp_files_extractor = LpFilesExtractor( - TWO_AREAS_FILES_ARCHIVE, std::filesystem::temp_directory_path(), logger_); + TWO_AREAS_FILES_ARCHIVE, std::filesystem::temp_directory_path(), logger_, + SimulationInputMode::ARCHIVE); std::ostringstream expectedErrorString; expectedErrorString << "More than one area*.txt file found" << std::endl; @@ -47,8 +48,9 @@ TEST_F(LpFilesExtractorTest, IfMoreThanOneAreaFileFoundInAntaresArchive) { } } TEST_F(LpFilesExtractorTest, IfNoIntercoFileIsInAntaresArchive) { - auto lp_files_extractor = LpFilesExtractor( - ONE_AREA_0_INTERCO, std::filesystem::temp_directory_path(), logger_); + auto out_dir = std::filesystem::temp_directory_path() / std::tmpnam(nullptr); + std::filesystem::create_directory(out_dir); + auto lp_files_extractor = LpFilesExtractor(ONE_AREA_0_INTERCO, out_dir, logger_, SimulationInputMode::ARCHIVE); std::ostringstream expectedErrorString; expectedErrorString << "No interco*.txt file found" << std::endl; @@ -60,9 +62,11 @@ TEST_F(LpFilesExtractorTest, IfNoIntercoFileIsInAntaresArchive) { } } TEST_F(LpFilesExtractorTest, IfMoreThanOneIntercoFileFoundInAntaresArchive) { - auto lp_files_extractor = - LpFilesExtractor(THREE_INTERCOS_FILES_ARCHIVE, - std::filesystem::temp_directory_path(), logger_); + auto out_dir = std::filesystem::temp_directory_path() / std::tmpnam(nullptr); + std::filesystem::create_directory(out_dir); + auto lp_files_extractor = LpFilesExtractor(THREE_INTERCOS_FILES_ARCHIVE, + out_dir, logger_, + SimulationInputMode::ARCHIVE); std::ostringstream expectedErrorString; expectedErrorString << "More than one interco*.txt file found" << std::endl; diff --git a/tests/cpp/lp_namer/ProblemGenerationExeOptionsTest.cpp b/tests/cpp/lp_namer/ProblemGenerationExeOptionsTest.cpp index 2340bfc17..730e8a865 100644 --- a/tests/cpp/lp_namer/ProblemGenerationExeOptionsTest.cpp +++ b/tests/cpp/lp_namer/ProblemGenerationExeOptionsTest.cpp @@ -7,7 +7,10 @@ namespace po = boost::program_options; -class ProblemGenerationExeOptionsTest : public ::testing::Test { +class ProblemGenerationExeOptionsTest + : public testing::TestWithParam< + std::tuple, + std::pair>> { public: ProblemGenerationExeOptions problem_generation_options_parser_; @@ -45,6 +48,8 @@ class ProblemGenerationSpyAndMock : public ProblemGeneration { weights_file_ = weights_file; unnamed_problems_ = unnamed_problems; } + + public: std::filesystem::path xpansion_output_dir_; std::string master_formulation_; std::string additionalConstraintFilename_l_; @@ -65,25 +70,62 @@ TEST_F(ProblemGenerationExeOptionsTest, MasterFormulationDefaultValue) { std::string("relaxed")); } -TEST_F(ProblemGenerationExeOptionsTest, - OutputAndArchiveParameters_mutually_exclusives) { +// Base case: an empty tuple +template +auto flattenPairs(const std::tuple& tuple) { + return tuple; // Return the original tuple for the base case +} + +// Terminal case : only a pair +template +auto flattenPairs(const std::pair& pair) { + return std::tuple(pair.first, pair.second); +} + +// Recursive case: process the first pair and concatenate it with the flattened +// rest of the tuple f({ pair(A, B), pair(C, D), pair(E, F) }) +// => f( pair(A,B) ) + f( { pair(C, D), pair(E, F) }) +// => f( pair(A,B) ) + f( pair(C, D) ) + f ({ pair(E, F) }) +// => f( pair(A,B) ) + f( pair(C, D) ) + f ( pair(E, F) ) + f ( {} ) +template +auto flattenPairs(const std::pair& pair, const Ts&... rest) { + return std::tuple_cat(std::tuple(pair.first, pair.second), + flattenPairs(rest...)); +} + +auto cases() { + using namespace std::string_literals; + return ::testing::Combine( + ::testing::Values(std::pair("--archive"s, "archive.zip"s), + std::pair("--output"s, "output-Xpansion"s), + std::pair("--study"s, "the_study"s)), + ::testing::Values(std::pair("--archive"s, "archive.zip"s), + std::pair("--output"s, "output-Xpansion"s), + std::pair("--study"s, "the_study"s))); +} +TEST_P(ProblemGenerationExeOptionsTest, Parameters_mutually_exclusives) { auto test_root = std::filesystem::temp_directory_path() / std::tmpnam(nullptr); auto archive = std::string(tmpnam(nullptr)) + "study.zip"; auto output_path = test_root / "study-Xpansion"; + auto params = GetParam(); + if (std::get<0>(params) == std::get<1>(params)) { + GTEST_SKIP() << "Same parameters"; + } + auto tuple = + std::apply([](auto... args) { return flattenPairs(args...); }, params); EXPECT_THROW( - parseOptions("--archive", archive, "--output", output_path.string()), + std::apply([&, this](auto... args) { parseOptions(args...); }, tuple), ProblemGenerationOptions::ConflictingParameters); - ProblemGenerationSpyAndMock pbg(problem_generation_options_parser_); - pbg.updateProblems(); - - EXPECT_EQ(pbg.archive_path_, archive); - EXPECT_EQ(pbg.xpansion_output_dir_, output_path); - EXPECT_TRUE(std::filesystem::exists(output_path)); - EXPECT_TRUE(std::filesystem::exists(output_path / "lp")); + EXPECT_THROW( + parseOptions("--archive", archive, "--output", output_path.string(), + "--study", test_root.string()), + ProblemGenerationOptions::ConflictingParameters); } +INSTANTIATE_TEST_SUITE_P(ConflictingOptions, ProblemGenerationExeOptionsTest, + cases()); TEST_F(ProblemGenerationExeOptionsTest, OutputAndArchiveParameters_deduceOuputFromArchive) { @@ -104,22 +146,21 @@ TEST_F(ProblemGenerationExeOptionsTest, EXPECT_TRUE(std::filesystem::exists(output_path / "lp")); } -TEST_F(ProblemGenerationExeOptionsTest, use_only_output_option) { +TEST_F(ProblemGenerationExeOptionsTest, + ValuesAndXpansionDirExistsWhenUsingOutputOption) { auto test_root = std::filesystem::temp_directory_path() / std::tmpnam(nullptr); - auto archive = test_root / "study.zip"; - auto output_path = test_root / "study-Xpansion"; + auto simulation_path = test_root / "study"; - parseOptions("--output", output_path.string()); + parseOptions("--output", simulation_path.string()); ProblemGenerationSpyAndMock pbg(problem_generation_options_parser_); pbg.updateProblems(); EXPECT_TRUE(problem_generation_options_parser_.ArchivePath().empty()); EXPECT_TRUE(pbg.archive_path_.empty()); - EXPECT_EQ(pbg.xpansion_output_dir_, output_path); - EXPECT_TRUE(std::filesystem::exists(output_path)); - EXPECT_TRUE(std::filesystem::exists(output_path / "lp")); + EXPECT_EQ(pbg.xpansion_output_dir_, simulation_path.string()); + EXPECT_TRUE(std::filesystem::exists(pbg.xpansion_output_dir_ / "lp")); } TEST_F(ProblemGenerationExeOptionsTest, @@ -128,4 +169,19 @@ TEST_F(ProblemGenerationExeOptionsTest, std::filesystem::temp_directory_path() / std::tmpnam(nullptr); EXPECT_THROW(parseOptions(), ProblemGenerationOptions::MissingParameters); -} \ No newline at end of file +} + +TEST_F(ProblemGenerationExeOptionsTest, study) { + GTEST_SKIP() << "Unimplemented"; + auto test_root = + std::filesystem::temp_directory_path() / std::tmpnam(nullptr); + + parseOptions("--study", test_root.string()); + + ProblemGenerationSpyAndMock pbg(problem_generation_options_parser_); + pbg.updateProblems(); + + EXPECT_TRUE(problem_generation_options_parser_.ArchivePath().empty()); + EXPECT_TRUE(pbg.archive_path_.empty()); + EXPECT_TRUE(std::filesystem::exists(pbg.xpansion_output_dir_)); +} diff --git a/tests/cpp/lp_namer/StudyUpdateTest.cc b/tests/cpp/lp_namer/StudyUpdateTest.cc index c81db12dd..b3608848d 100644 --- a/tests/cpp/lp_namer/StudyUpdateTest.cc +++ b/tests/cpp/lp_namer/StudyUpdateTest.cc @@ -200,19 +200,19 @@ TEST_F(StudyUpdateTest, computeNewCapacities) { {"peak", 1000}, {"transmission_line", 0}}; ASSERT_EQ(studyupdater.computeNewCapacities(investissments, _links[1], 0), - std::make_pair(0., 250.)); + std::pair(0., 250.)); ASSERT_EQ(studyupdater.computeNewCapacities(investissments, _links[1], 1), - std::make_pair(500., 750.)); + std::pair(500., 750.)); ASSERT_EQ(studyupdater.computeNewCapacities(investissments, _links[1], 2), - std::make_pair(1000., 1000.)); + std::pair(1000., 1000.)); // link 0 : area1 - area2 has an already installed capacity of 100 ASSERT_EQ(studyupdater.computeNewCapacities(investissments, _links[0], 0), - std::make_pair(100., 100.)); + std::pair(100., 100.)); ASSERT_EQ(studyupdater.computeNewCapacities(investissments, _links[0], 1), - std::make_pair(100., 100.)); + std::pair(100., 100.)); ASSERT_EQ(studyupdater.computeNewCapacities(investissments, _links[0], 2), - std::make_pair(100., 100.)); + std::pair(100., 100.)); } TEST_F(StudyUpdateTest, no_computed_investment_for_candidate_peak) { diff --git a/tests/cpp/solvers_interface/catch2.hpp b/tests/cpp/solvers_interface/catch2.hpp index 7073a8136..daffae36b 100644 --- a/tests/cpp/solvers_interface/catch2.hpp +++ b/tests/cpp/solvers_interface/catch2.hpp @@ -5810,9 +5810,9 @@ struct ITagAliasRegistry { namespace Catch { class TestSpecParser { - enum Mode { None, Name, QuotedName, Tag, EscapedName }; - Mode m_mode = None; - Mode lastMode = None; + enum SimulationInputMode { None, Name, QuotedName, Tag, EscapedName }; + SimulationInputMode m_mode = None; + SimulationInputMode lastMode = None; bool m_exclusion = false; std::size_t m_pos = 0; std::size_t m_realPatternPos = 0; @@ -5832,7 +5832,7 @@ class TestSpecParser { private: bool visitChar(char c); - void startNewMode(Mode mode); + void startNewMode(SimulationInputMode mode); bool processNoneChar(char c); void processNameChar(char c); bool processOtherChar(char c); @@ -7641,7 +7641,7 @@ Estimate bootstrap(double confidence_level, Iterator first, double jack_mean = mean(jack.begin(), jack.end()); double sum_squares, sum_cubes; std::tie(sum_squares, sum_cubes) = - std::accumulate(jack.begin(), jack.end(), std::make_pair(0., 0.), + std::accumulate(jack.begin(), jack.end(), std::pair(0., 0.), [jack_mean](std::pair sqcb, double x) -> std::pair { auto d = jack_mean - x; @@ -11895,7 +11895,7 @@ std::size_t listTags(Config const& config) { auto countIt = tagCounts.find(lcaseTagName); if (countIt == tagCounts.end()) countIt = - tagCounts.insert(std::make_pair(lcaseTagName, TagInfo())).first; + tagCounts.insert(std::pair(lcaseTagName, TagInfo())).first; countIt->second.add(tagName); } } @@ -14493,7 +14493,7 @@ void TagAliasRegistry::add(std::string const& alias, std::string const& tag, << lineInfo); CATCH_ENFORCE( - m_registry.insert(std::make_pair(alias, TagAlias(tag, lineInfo))).second, + m_registry.insert(std::pair(alias, TagAlias(tag, lineInfo))).second, "error: tag alias, '" << alias << "' already registered.\n" << "\tFirst seen at: " << find(alias)->lineInfo << "\n" @@ -15204,7 +15204,7 @@ bool TestSpecParser::processOtherChar(char c) { endMode(); return true; } -void TestSpecParser::startNewMode(Mode mode) { m_mode = mode; } +void TestSpecParser::startNewMode(SimulationInputMode mode) { m_mode = mode; } void TestSpecParser::endMode() { switch (m_mode) { case Name: diff --git a/tests/end_to_end/lpnamer/test_lpnamerEndToEnd.py b/tests/end_to_end/lpnamer/test_lpnamerEndToEnd.py index a9b590926..3cd8e5cb0 100644 --- a/tests/end_to_end/lpnamer/test_lpnamerEndToEnd.py +++ b/tests/end_to_end/lpnamer/test_lpnamerEndToEnd.py @@ -119,9 +119,9 @@ def test_lp_multiple_candidates(install_dir, test_dir, master_mode, option_mode, @pytest.mark.parametrize("study_dir", test_data_study_option) @pytest.mark.parametrize("master_mode", ["integer"]) @pytest.mark.parametrize("option_mode", [OptionType.STUDY]) +@pytest.mark.skip(reason="study option not implemented yet") def test_lp_with_study_option(install_dir, study_dir, master_mode, option_mode, setup_study, tmp_path): - assert True - #launch_and_compare_lp_with_reference_study(install_dir, master_mode, setup_study) + launch_and_compare_lp_with_reference_study(install_dir, master_mode, setup_study) def launch_and_compare_lp_with_reference_output(install_dir, master_mode, test_dir):