Skip to content

Commit

Permalink
Create LP dir if not existing
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonMarechal25 committed Oct 24, 2023
1 parent 5405b51 commit 8673034
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 34 deletions.
25 changes: 7 additions & 18 deletions src/cpp/lpnamer/main/RunProblemGeneration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,22 +126,15 @@ std::vector<std::shared_ptr<Problem>> 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(
Expand All @@ -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<std::runtime_error>(
"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

Expand Down
16 changes: 0 additions & 16 deletions tests/cpp/lp_namer/ProblemGenerationTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::runtime_error>);
auto lp = (simulationDirectory.parent_path() /
(simulationDirectory.filename().string() + "-Xpansion")) /
"lp";
EXPECT_FALSE(std::filesystem::exists(lp));
}

0 comments on commit 8673034

Please sign in to comment.