diff --git a/src/libs/antares/study/parts/short-term-storage/container.cpp b/src/libs/antares/study/parts/short-term-storage/container.cpp index 31c25fdfdf..f26aff9929 100644 --- a/src/libs/antares/study/parts/short-term-storage/container.cpp +++ b/src/libs/antares/study/parts/short-term-storage/container.cpp @@ -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) @@ -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; diff --git a/src/tests/src/libs/antares/study/short-term-storage-input/short-term-storage-input-output.cpp b/src/tests/src/libs/antares/study/short-term-storage-input/short-term-storage-input-output.cpp index 583027c95b..0a6f355375 100644 --- a/src/tests/src/libs/antares/study/short-term-storage-input/short-term-storage-input-output.cpp +++ b/src/tests/src/libs/antares/study/short-term-storage-input/short-term-storage-input-output.cpp @@ -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"; @@ -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); } @@ -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"; @@ -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);