From f100200599c2abbe18319e2ddfc87cc0c1705679 Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Fri, 20 Dec 2024 11:36:07 +0100 Subject: [PATCH] update --- .../parts/short-term-storage/container.cpp | 32 +++++++++++-------- .../ShortTermStorageCumulation.cpp | 15 +++++---- .../opt_decompte_variables_et_contraintes.cpp | 6 +++- ...opt_gestion_second_membre_cas_lineaire.cpp | 29 +++++++++++++---- .../simulation/sim_calcul_economique.cpp | 2 +- 5 files changed, 56 insertions(+), 28 deletions(-) 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 897c234550..5dee3106dc 100644 --- a/src/libs/antares/study/parts/short-term-storage/container.cpp +++ b/src/libs/antares/study/parts/short-term-storage/container.cpp @@ -88,8 +88,8 @@ bool STStorageInput::LoadConstraintsFromIniFile(const fs::path& parent_path) for (auto* section = ini.firstSection; section; section = section->next) { - AdditionalConstraints constraint; - constraint.name = section->name.c_str(); + AdditionalConstraints additional_constraints; + additional_constraints.name = section->name.c_str(); for (auto* property = section->firstProperty; property; property = property->next) { const std::string key = property->key; @@ -100,15 +100,15 @@ bool STStorageInput::LoadConstraintsFromIniFile(const fs::path& parent_path) // TODO do i have to transform the name to id? TransformNameIntoID std::string clusterName; value.to(clusterName); - constraint.cluster_id = transformNameIntoID(clusterName); + additional_constraints.cluster_id = transformNameIntoID(clusterName); } else if (key == "variable") { - value.to(constraint.variable); + value.to(additional_constraints.variable); } else if (key == "operator") { - value.to(constraint.operatorType); + value.to(additional_constraints.operatorType); } else if (key == "hours") { @@ -129,6 +129,7 @@ bool STStorageInput::LoadConstraintsFromIniFile(const fs::path& parent_path) 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 @@ -142,17 +143,20 @@ bool STStorageInput::LoadConstraintsFromIniFile(const fs::path& parent_path) int hourVal = std::stoi(hour); hourSet.insert(hourVal); } - - constraint.hours.push_back(hourSet); // Add this group to the `hours` vector + // Add this group to the `hours` vec + additional_constraints.constraints.push_back( + {.hours = hourSet, .localIndex = localIndex}); + ++localIndex; } } // try to read the rhs - loadFile(parent_path / ("rhs_" + constraint.name + ".txt"), constraint.rhs); - fillIfEmpty(constraint.rhs, 0.0); + loadFile(parent_path / ("rhs_" + additional_constraints.name + ".txt"), + additional_constraints.rhs); + fillIfEmpty(additional_constraints.rhs, 0.0); } - if (auto [ok, error_msg] = constraint.validate(); !ok) + if (auto [ok, error_msg] = additional_constraints.validate(); !ok) { logs.error() << "Invalid constraint in section: " << section->name; logs.error() << error_msg; @@ -161,8 +165,10 @@ bool STStorageInput::LoadConstraintsFromIniFile(const fs::path& parent_path) auto it = std::find_if(storagesByIndex.begin(), storagesByIndex.end(), - [&constraint](const STStorageCluster& cluster) - { return cluster.id == constraint.cluster_id; }); + [&additional_constraints](const STStorageCluster& cluster) + { + return cluster.id == additional_constraints.cluster_id; + }); if (it == storagesByIndex.end()) { logs.warning() << " from file " << pathIni; @@ -172,7 +178,7 @@ bool STStorageInput::LoadConstraintsFromIniFile(const fs::path& parent_path) } else { - it->additional_constraints.push_back(constraint); + it->additional_constraints.push_back(additional_constraints); } } diff --git a/src/solver/optimisation/constraints/ShortTermStorageCumulation.cpp b/src/solver/optimisation/constraints/ShortTermStorageCumulation.cpp index f00d39d56e..bf6cf51f94 100644 --- a/src/solver/optimisation/constraints/ShortTermStorageCumulation.cpp +++ b/src/solver/optimisation/constraints/ShortTermStorageCumulation.cpp @@ -138,18 +138,19 @@ void ShortTermStorageCumulation::add(int pays) // var = injectionEfficiency * injection - withdrawalEfficiency * withdrawal for Netting auto constraintHelper = cumulationConstraintFromVariable( additional_constraints.variable); - for (auto& constraint: additional_constraints.constraints) + for (const auto& [hours, globalIndex, localIndex]: additional_constraints.constraints) { - namer.ShortTermStorageCumulation(constraintHelper->name() +, - builder.data.nombreDeContraintes, - storage.name, - additional_constraints.name); + namer.ShortTermStorageCumulation( + constraintHelper->name() + std::to_string(localIndex), + builder.data.nombreDeContraintes, + storage.name, + additional_constraints.name); const auto index = storage.clusterGlobalIndex; data.CorrespondanceCntNativesCntOptimHebdomadaires - .ShortTermStorageCumulation[additional_constraints.globalIndex] + .ShortTermStorageCumulation[globalIndex] = builder.data.nombreDeContraintes; - for (const auto& hour: additional_constraints.hours) + for (const auto& hour: hours) { builder.updateHourWithinWeek(hour - 1); constraintHelper->build(builder, index, storage); diff --git a/src/solver/optimisation/opt_decompte_variables_et_contraintes.cpp b/src/solver/optimisation/opt_decompte_variables_et_contraintes.cpp index 79c29c58ab..7de6203d69 100644 --- a/src/solver/optimisation/opt_decompte_variables_et_contraintes.cpp +++ b/src/solver/optimisation/opt_decompte_variables_et_contraintes.cpp @@ -247,7 +247,11 @@ int OPT_DecompteDesVariablesEtDesContraintesDuProblemeAOptimiser(PROBLEME_HEBDO* } if (!storage.additional_constraints.empty()) { - ProblemeAResoudre->NombreDeContraintes += storage.additional_constraints.size(); + for (const auto& additional_constraints: storage.additional_constraints) + { + ProblemeAResoudre->NombreDeContraintes += additional_constraints.constraints + .size(); + } } } } diff --git a/src/solver/optimisation/opt_gestion_second_membre_cas_lineaire.cpp b/src/solver/optimisation/opt_gestion_second_membre_cas_lineaire.cpp index c04d416f00..c3d0d16f95 100644 --- a/src/solver/optimisation/opt_gestion_second_membre_cas_lineaire.cpp +++ b/src/solver/optimisation/opt_gestion_second_membre_cas_lineaire.cpp @@ -19,6 +19,8 @@ ** along with Antares_Simulator. If not, see . */ +#include + #include "antares/solver/simulation/sim_structure_probleme_economique.h" double OPT_SommeDesPminThermiques(const PROBLEME_HEBDO*, int, uint); @@ -47,17 +49,32 @@ static void shortTermStorageCumulationRHS( const std::vector<::ShortTermStorage::AREA_INPUT>& shortTermStorageInput, int numberOfAreas, std::vector& SecondMembre, - const CORRESPONDANCES_DES_CONTRAINTES_HEBDOMADAIRES& CorrespondancesDesContraintesHebdomadaires) + const CORRESPONDANCES_DES_CONTRAINTES_HEBDOMADAIRES& CorrespondancesDesContraintesHebdomadaires, + int weekFirstHour) { for (int areaIndex = 0; areaIndex < numberOfAreas; areaIndex++) { for (auto& storage: shortTermStorageInput[areaIndex]) { - for (const auto& constraint: storage.additional_constraints) + for (const auto& additional_constraints: storage.additional_constraints) { - int cnt = CorrespondancesDesContraintesHebdomadaires + for (const auto& constraint: additional_constraints.constraints) + { + const int cnt = CorrespondancesDesContraintesHebdomadaires .ShortTermStorageCumulation[constraint.globalIndex]; - SecondMembre[cnt] = constraint.rhs; + + SecondMembre[cnt] = std::accumulate(constraint.hours.begin(), + constraint.hours.end(), + 0.0, + [weekFirstHour, &additional_constraints + ]( + const double sum, + const int hour) + { + return sum + additional_constraints.rhs[ + weekFirstHour + hour - 1]; + }); + } } } } @@ -395,11 +412,11 @@ void OPT_InitialiserLeSecondMembreDuProblemeLineaire(PROBLEME_HEBDO* problemeHeb } } } - shortTermStorageCumulationRHS(problemeHebdo->ShortTermStorage, problemeHebdo->NombreDePays, ProblemeAResoudre->SecondMembre, - problemeHebdo->CorrespondanceCntNativesCntOptimHebdomadaires); + problemeHebdo->CorrespondanceCntNativesCntOptimHebdomadaires, + weekFirstHour); if (problemeHebdo->OptimisationAvecCoutsDeDemarrage) { OPT_InitialiserLeSecondMembreDuProblemeLineaireCoutsDeDemarrage(problemeHebdo, diff --git a/src/solver/simulation/sim_calcul_economique.cpp b/src/solver/simulation/sim_calcul_economique.cpp index cdecaaa1cd..ace517889e 100644 --- a/src/solver/simulation/sim_calcul_economique.cpp +++ b/src/solver/simulation/sim_calcul_economique.cpp @@ -63,7 +63,7 @@ static void importShortTermStorages( toInsert.additional_constraints = st.additional_constraints; for (auto& additional_constraints: toInsert.additional_constraints) { - for (auto& [_, globalIndex]: additional_constraints.constraints) + for (auto& [_, globalIndex,__]: additional_constraints.constraints) { globalIndex = clusterCumulativeConstraintGlobalIndex; ++clusterCumulativeConstraintGlobalIndex;