Skip to content

Commit

Permalink
on malformed rhs file
Browse files Browse the repository at this point in the history
  • Loading branch information
a-zakir committed Jan 2, 2025
1 parent 5c4a438 commit d5f0bca
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
19 changes: 13 additions & 6 deletions src/libs/antares/study/parts/short-term-storage/container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,13 @@ static void loadHours(const std::string& hoursStr, AdditionalConstraints& additi
}
}

static void readRHS(AdditionalConstraints& additionalConstraints,
const fs::path& parentPath)
static bool readRHS(AdditionalConstraints& additionalConstraints,
const fs::path& rhsPath)
{
loadFile(parentPath / ("rhs_" + additionalConstraints.name + ".txt"),
additionalConstraints.rhs);
fillIfEmpty(additionalConstraints.rhs, 0.0);
const auto ret = loadFile(rhsPath,
additionalConstraints.rhs);
if (ret) { fillIfEmpty(additionalConstraints.rhs, 0.0); }
return ret;
}

bool STStorageInput::loadAdditionalConstraints(const fs::path& parentPath)
Expand Down Expand Up @@ -154,7 +155,13 @@ bool STStorageInput::loadAdditionalConstraints(const fs::path& parentPath)
}
}

readRHS(additionalConstraints, parentPath);
if (const auto rhsPath = parentPath / (
"rhs_" + additionalConstraints.name
+ ".txt"); !readRHS(additionalConstraints, rhsPath))
{
logs.error() << "Error while reading rhs file: " << rhsPath;
return false;
}
if (auto [ok, error_msg] = additionalConstraints.validate(); !ok)
{
logs.error() << "Invalid constraint in section: " << section->name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ BOOST_AUTO_TEST_CASE(loadAdditionalConstraints_MalformedRhsFile)

std::ofstream iniFile(testPath / "additional-constraints.ini");
iniFile << "[constraint1]\n";
iniFile << "cluster=ClusterA\n";
iniFile << "cluster=cluster1\n";
iniFile << "variable=injection\n";
iniFile << "operator=less\n";
iniFile << "hours=[1,2,3]\n";
Expand All @@ -816,12 +816,14 @@ BOOST_AUTO_TEST_CASE(loadAdditionalConstraints_MalformedRhsFile)

ShortTermStorage::STStorageInput storageInput;
ShortTermStorage::STStorageCluster cluster;
cluster.id = "ClusterA";
cluster.id = "cluster1";
storageInput.storagesByIndex.push_back(cluster);

bool result = storageInput.loadAdditionalConstraints(testPath);
BOOST_CHECK_EQUAL(result, false);

/*"Error while reading rhs file: " << "rhs_" << additionalConstraints.name
<<
".txt";*/
std::filesystem::remove_all(testPath);
}

Expand All @@ -832,7 +834,7 @@ BOOST_AUTO_TEST_CASE(loadAdditionalConstraints_IncompleteRhsFile)

std::ofstream iniFile(testPath / "additional-constraints.ini");
iniFile << "[constraint1]\n";
iniFile << "cluster=ClusterA\n";
iniFile << "cluster=cluster1\n";
iniFile << "variable=injection\n";
iniFile << "operator=less\n";
iniFile << "hours=[1,2,3]\n";
Expand All @@ -847,7 +849,7 @@ BOOST_AUTO_TEST_CASE(loadAdditionalConstraints_IncompleteRhsFile)

ShortTermStorage::STStorageInput storageInput;
ShortTermStorage::STStorageCluster cluster;
cluster.id = "ClusterA";
cluster.id = "cluster1";
storageInput.storagesByIndex.push_back(cluster);

bool result = storageInput.loadAdditionalConstraints(testPath);
Expand Down

0 comments on commit d5f0bca

Please sign in to comment.