Skip to content

Commit

Permalink
Merge remote-tracking branch 'github/feature/variable-rhs-sts-new-con…
Browse files Browse the repository at this point in the history
…straint' into feature/enable-property-sts-constraints
  • Loading branch information
flomnes committed Jan 2, 2025
2 parents 24fda43 + d5f0bca commit 8474dbc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
25 changes: 20 additions & 5 deletions src/libs/antares/study/parts/short-term-storage/container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,14 @@ 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 @@ -157,7 +160,19 @@ bool STStorageInput::loadAdditionalConstraints(const fs::path& parentPath)
}
}

readRHS(additionalConstraints, parentPath);
// We don't want load RHS and link the STS time if the constraint is disabled
if (!additionalConstraints.enabled)
{
return true;
}

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 @@ -805,7 +805,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 @@ -817,12 +817,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 @@ -833,7 +835,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 @@ -848,7 +850,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 8474dbc

Please sign in to comment.