diff --git a/src/libs/antares/study/include/antares/study/parts/short-term-storage/AdditionalConstraints.h b/src/libs/antares/study/include/antares/study/parts/short-term-storage/AdditionalConstraints.h index 3a1b5f20f8..de800f5ac0 100644 --- a/src/libs/antares/study/include/antares/study/parts/short-term-storage/AdditionalConstraints.h +++ b/src/libs/antares/study/include/antares/study/parts/short-term-storage/AdditionalConstraints.h @@ -43,9 +43,9 @@ struct AdditionalConstraints std::string operatorType; // TODO a lot unused entries // std::array rhs = {}; - std::vector rhs = {}; + std::vector rhs; - std::vector constraints = {}; + std::vector constraints; struct ValidateResult { 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 91ae9a93fc..fc6623bf29 100644 --- a/src/libs/antares/study/parts/short-term-storage/container.cpp +++ b/src/libs/antares/study/parts/short-term-storage/container.cpp @@ -19,8 +19,6 @@ ** along with Antares_Simulator. If not, see . */ -#include "antares/study/parts/short-term-storage/container.h" - #include #include #include @@ -30,6 +28,7 @@ #include #include +#include "antares/study/parts/short-term-storage/container.h" #define SEP Yuni::IO::Separator @@ -76,6 +75,46 @@ bool STStorageInput::createSTStorageClustersFromIniFile(const fs::path& path) return true; } +static void loadHours(const std::string& hoursStr, AdditionalConstraints& additional_constraints) +{ + // + // std::stringstream ss(value.c_str()); + // std::string hour; + // while (std::getline(ss, hour, ',')) + // { + // int hourVal = std::stoi(hour); + // constraint.hours.insert(hourVal); + // } + + // Split the `hours` field into multiple groups + std::regex groupRegex(R"(\[(.*?)\])"); + // Match each group enclosed in square brackets + auto groupsBegin = std::sregex_iterator(hoursStr.begin(), hoursStr.end(), groupRegex); + auto groupsEnd = std::sregex_iterator(); + unsigned int localIndex = 0; + for (auto it = groupsBegin; it != groupsEnd; ++it) + { + // Extract the contents of the square brackets + std::string group = (*it)[1].str(); + std::stringstream ss(group); + std::string hour; + std::set hourSet; + + while (std::getline(ss, hour, ',')) + { + int hourVal = std::stoi(hour); + hourSet.insert(hourVal); + } + if (!hourSet.empty()) + { + // Add this group to the `hours` vec + additional_constraints.constraints.push_back( + {.hours = hourSet, .localIndex = localIndex}); + ++localIndex; + } + } +} + bool STStorageInput::LoadConstraintsFromIniFile(const fs::path& parent_path) { IniFile ini; @@ -112,45 +151,7 @@ bool STStorageInput::LoadConstraintsFromIniFile(const fs::path& parent_path) } else if (key == "hours") { - // - // std::stringstream ss(value.c_str()); - // std::string hour; - // while (std::getline(ss, hour, ',')) - // { - // int hourVal = std::stoi(hour); - // constraint.hours.insert(hourVal); - // } - - // Split the `hours` field into multiple groups - std::string hoursStr = value.c_str(); - std::regex groupRegex(R"(\[(.*?)\])"); - // Match each group enclosed in square brackets - auto groupsBegin = std::sregex_iterator(hoursStr.begin(), - hoursStr.end(), - groupRegex); - auto groupsEnd = std::sregex_iterator(); - unsigned int localIndex = 0; - for (auto it = groupsBegin; it != groupsEnd; ++it) - { - // Extract the contents of the square brackets - std::string group = (*it)[1].str(); - std::stringstream ss(group); - std::string hour; - std::set hourSet; - - while (std::getline(ss, hour, ',')) - { - int hourVal = std::stoi(hour); - hourSet.insert(hourVal); - } - if (!hourSet.empty()) - { - // Add this group to the `hours` vec - additional_constraints.constraints.push_back( - {.hours = hourSet, .localIndex = localIndex}); - ++localIndex; - } - } + loadHours(value.c_str(), additional_constraints); } }