From 867303486b342efc33c340065c16d7144b79b55e Mon Sep 17 00:00:00 2001 From: Jason Marechal Date: Thu, 12 Oct 2023 14:50:43 +0200 Subject: [PATCH] Create LP dir if not existing --- src/cpp/lpnamer/main/RunProblemGeneration.cpp | 25 ++++++------------- tests/cpp/lp_namer/ProblemGenerationTest.cpp | 16 ------------ 2 files changed, 7 insertions(+), 34 deletions(-) diff --git a/src/cpp/lpnamer/main/RunProblemGeneration.cpp b/src/cpp/lpnamer/main/RunProblemGeneration.cpp index 00ebc509a1..cc57681e82 100644 --- a/src/cpp/lpnamer/main/RunProblemGeneration.cpp +++ b/src/cpp/lpnamer/main/RunProblemGeneration.cpp @@ -126,22 +126,15 @@ std::vector> getXpansionProblems( problem_names); return adapter->provideProblems(solver_name, solver_log_manager); } -bool CreateDirectories( - const std::filesystem::path& xpansion_output_path, +void CreateDirectories(const std::filesystem::path& xpansion_output_path, ProblemGenerationLog::ProblemGenerationLogger* logger) { if (!std::filesystem::exists(xpansion_output_path)) { - (*logger)(LogUtils::LOGLEVEL::ERR) - << "Output directory " << xpansion_output_path << " does not exist" - << std::endl; - return false; + std::filesystem::create_directories(xpansion_output_path); + } + auto lp_path = xpansion_output_path / LP_DIRNAME; + if (!std::filesystem::exists(lp_path)) { + std::filesystem::create_directories(lp_path); } - auto xpansion_output_dir = - xpansion_output_path.parent_path() / - (xpansion_output_path.stem().string() + "-Xpansion"); - std::filesystem::create_directories(xpansion_output_dir); - std::filesystem::create_directories(xpansion_output_dir / LP_DIRNAME); - - return true; } void RunProblemGeneration( @@ -154,11 +147,7 @@ void RunProblemGeneration( const std::filesystem::path& weights_file, bool unnamed_problems) { (*logger)(LogUtils::LOGLEVEL::INFO) << "Launching Problem Generation" << std::endl; - if (!CreateDirectories( - xpansion_output_dir, logger.get())) { - throw LogUtils::XpansionError( - "Error creating LP directory", LOGLOCATION); - } + CreateDirectories(xpansion_output_dir, logger.get()); validateMasterFormulation(master_formulation, logger); std::string solver_name = "CBC"; // TODO Use solver selected by user diff --git a/tests/cpp/lp_namer/ProblemGenerationTest.cpp b/tests/cpp/lp_namer/ProblemGenerationTest.cpp index 18f16faf46..d5558b40a5 100644 --- a/tests/cpp/lp_namer/ProblemGenerationTest.cpp +++ b/tests/cpp/lp_namer/ProblemGenerationTest.cpp @@ -45,20 +45,4 @@ TEST(InitializationTest, FoldersAreEmpty) { ArchiveIOGeneralException); EXPECT_FALSE(std::filesystem::exists(simulationDirectory / "garbage.txt")); -} - -TEST(InitializationTest, ErrorIfSimulationPathDoesNotExists) { - auto workingDirectory = - std::filesystem::temp_directory_path() / std::tmpnam(nullptr); - auto simulationDirectory = workingDirectory / "output" / "simulation"; - auto logger = emptyLogger(); - - EXPECT_THROW( - RunProblemGeneration(simulationDirectory, "integer", "", "", logger, - simulationDirectory / "logs.txt", "", false), - LogUtils::XpansionError); - auto lp = (simulationDirectory.parent_path() / - (simulationDirectory.filename().string() + "-Xpansion")) / - "lp"; - EXPECT_FALSE(std::filesystem::exists(lp)); } \ No newline at end of file