From c0ec60a8ad19ca73a6353926e2e192ef0d305868 Mon Sep 17 00:00:00 2001 From: CAMUS Benjamin Date: Fri, 29 Nov 2024 17:57:44 +0100 Subject: [PATCH] fix bugs related to the implementation of reserves lot 3 v2 --- src/libs/antares/study/area/list.cpp | 10 +- ...STStockEnergyLevelReserveParticipation.cpp | 95 +++++++++++-------- .../STStockLevelReserveParticipation.cpp | 4 +- .../solver/optimisation/opt_rename_problem.h | 2 +- .../opt_gestion_second_membre_reserves.cpp | 33 +++---- .../optimisation/opt_rename_problem.cpp | 4 +- 6 files changed, 81 insertions(+), 67 deletions(-) diff --git a/src/libs/antares/study/area/list.cpp b/src/libs/antares/study/area/list.cpp index bcbb60c4ac..f572b99449 100644 --- a/src/libs/antares/study/area/list.cpp +++ b/src/libs/antares/study/area/list.cpp @@ -927,7 +927,7 @@ static bool AreaListLoadFromFolderSingleArea(Study& study, tmp = p->key; tmp.toLower(); - if (tmp == "max_activation_ratio_up") + if (tmp == "max-energy-activation-ratio-up") { if (!p->value.to(area.allCapacityReservations.maxGlobalEnergyActivationRatioUp)) { @@ -935,7 +935,7 @@ static bool AreaListLoadFromFolderSingleArea(Study& study, << area.name << ": invalid maximum energy activation ratio for UP reserves"; } } - else if (tmp == "max_activation_ratio_down") + else if (tmp == "max-energy-activation-ratio-down") { if (!p->value.to(area.allCapacityReservations.maxGlobalEnergyActivationRatioDown)) { @@ -943,7 +943,7 @@ static bool AreaListLoadFromFolderSingleArea(Study& study, << area.name << ": invalid maximum energy activation ratio for DOWN reserves"; } } - else if (tmp == "max_activation_duration_up") + else if (tmp == "max-activation-duration-up") { if (!p->value.to(area.allCapacityReservations.maxGlobalActivationDurationUp)) { @@ -951,7 +951,7 @@ static bool AreaListLoadFromFolderSingleArea(Study& study, << area.name << ": invalid maximum energy activation duration for UP reserves"; } } - else if (tmp == "max_activation_duration_down") + else if (tmp == "max-activation-duration-down") { if (!p->value.to(area.allCapacityReservations.maxGlobalActivationDurationDown)) { @@ -995,7 +995,7 @@ static bool AreaListLoadFromFolderSingleArea(Study& study, << section.name; } } - else if (tmp == "max-activation-ratio") + else if (tmp == "max-power-activation-ratio") { if (!p->value.to(tmpCapacityReservation.maxActivationRatio)) { diff --git a/src/solver/optimisation/constraints/STStockEnergyLevelReserveParticipation.cpp b/src/solver/optimisation/constraints/STStockEnergyLevelReserveParticipation.cpp index df111f3e81..066e844671 100644 --- a/src/solver/optimisation/constraints/STStockEnergyLevelReserveParticipation.cpp +++ b/src/solver/optimisation/constraints/STStockEnergyLevelReserveParticipation.cpp @@ -7,53 +7,66 @@ void STStockEnergyLevelReserveParticipation::add(int pays, int cluster, int rese = isUpReserve ? data.areaReserves[pays].areaCapacityReservationsUp[reserve] : data.areaReserves[pays].areaCapacityReservationsDown[reserve]; - if (!data.Simulation) + if (capacityReservation.maxActivationDuration > 0) { - // 15 (h) (1) - // Participation of down reserves requires a sufficient level of stock - // Sum(P_{res,t_st} * R_{min,res} +/- J_res * R_{lambda,t_st}) <= n_min * R_up - // R_t : stock level at time t - // P_{res,t_st} : power participation for reserve down res at time t_st - // R_{min,res} : max power participation ratio - // R_up : max stock level + if (!data.Simulation) { - float sign = isUpReserve ? -1. : 1.; + // 15 (h) (1) + // Participation of down reserves requires a sufficient level of stock + // Sum(P_{res,t_st} * R_{min,res} +/- J_res * R_{lambda,t_st}) <= n_min * R_up + // R_t : stock level at time t + // P_{res,t_st} : power participation for reserve down res at time t_st + // R_{min,res} : max power participation ratio + // R_up : max stock level + { + float sign = isUpReserve ? -1. : 1.; - RESERVE_PARTICIPATION_STSTORAGE& reserveParticipation - = capacityReservation.AllSTStorageReservesParticipation[cluster]; + RESERVE_PARTICIPATION_STSTORAGE& reserveParticipation + = capacityReservation.AllSTStorageReservesParticipation[cluster]; - builder.updateHourWithinWeek(pdt); + builder.updateHourWithinWeek(pdt); - for (int t=0; t < capacityReservation.maxActivationDuration; t++) - { - builder.STStorageClusterReserveDownParticipation( - reserveParticipation.globalIndexClusterParticipation, - capacityReservation.maxActivationRatio, - t, builder.data.NombreDePasDeTempsPourUneOptimisation); - builder.ShortTermStorageLevel(globalClusterIdx, sign * capacityReservation.maxEnergyActivationRatio, - t, builder.data.NombreDePasDeTempsPourUneOptimisation); - } + for (int t=0; t < capacityReservation.maxActivationDuration; t++) + { + if (isUpReserve) + { + builder.STStorageClusterReserveUpParticipation( + reserveParticipation.globalIndexClusterParticipation, + capacityReservation.maxActivationRatio, + t, builder.data.NombreDePasDeTempsPourUneOptimisation); + } + else + { + builder.STStorageClusterReserveDownParticipation( + reserveParticipation.globalIndexClusterParticipation, + capacityReservation.maxActivationRatio, + t, builder.data.NombreDePasDeTempsPourUneOptimisation); + } + builder.ShortTermStorageLevel(globalClusterIdx, sign * capacityReservation.maxEnergyActivationRatio, + t, builder.data.NombreDePasDeTempsPourUneOptimisation); + } + + builder.lessThan(); + + data.CorrespondanceCntNativesCntOptim[pdt] + .NumeroDeContrainteDesContraintesSTStockEnergyLevelReserveParticipation + [reserveParticipation.globalIndexClusterParticipation] + = builder.data.nombreDeContraintes; - builder.lessThan(); - - data.CorrespondanceCntNativesCntOptim[pdt] - .NumeroDeContrainteDesContraintesSTStockEnergyLevelReserveParticipation - [reserveParticipation.globalIndexClusterParticipation] - = builder.data.nombreDeContraintes; - - ConstraintNamer namer(builder.data.NomDesContraintes); - const int hourInTheYear = builder.data.weekInTheYear * 168 + pdt; - namer.UpdateTimeStep(hourInTheYear); - namer.UpdateArea(builder.data.NomsDesPays[pays]); - namer.STEnergyStockLevelReserveParticipationDown(builder.data.nombreDeContraintes, - reserveParticipation.clusterName, - capacityReservation.reserveName); - builder.build(); + ConstraintNamer namer(builder.data.NomDesContraintes); + const int hourInTheYear = builder.data.weekInTheYear * 168 + pdt; + namer.UpdateTimeStep(hourInTheYear); + namer.UpdateArea(builder.data.NomsDesPays[pays]); + namer.STEnergyStockLevelReserveParticipation(builder.data.nombreDeContraintes, + reserveParticipation.clusterName, + capacityReservation.reserveName); + builder.build(); + } + } + else + { + builder.data.NbTermesContraintesPourLesReserves += 2 * capacityReservation.maxActivationDuration; + builder.data.nombreDeContraintes += 1; } - } - else - { - builder.data.NbTermesContraintesPourLesReserves += 2 * capacityReservation.maxActivationDuration; - builder.data.nombreDeContraintes += 1; } } \ No newline at end of file diff --git a/src/solver/optimisation/constraints/STStockLevelReserveParticipation.cpp b/src/solver/optimisation/constraints/STStockLevelReserveParticipation.cpp index 0bb982a088..a4ebd46fd0 100644 --- a/src/solver/optimisation/constraints/STStockLevelReserveParticipation.cpp +++ b/src/solver/optimisation/constraints/STStockLevelReserveParticipation.cpp @@ -46,7 +46,7 @@ void STStockLevelReserveParticipation::add(int pays, int cluster, int pdt) // 15 (g) (2) // Participation of up reserves requires a sufficient level of stock - // R_t - Sum(P_{res} * R_{min,res}) >= R_down + // -R_t + Sum(P_{res} * R_{min,res}) <= -R_down // R_t : stock level at time t // P_{res} : power participation for reserve up res // R_{min,res} : max power participation ratio @@ -61,7 +61,7 @@ void STStockLevelReserveParticipation::add(int pays, int cluster, int pdt) RESERVE_PARTICIPATION_STSTORAGE reserveParticipations = capacityReservation.AllSTStorageReservesParticipation[cluster]; builder.STStorageClusterReserveUpParticipation( reserveParticipations.globalIndexClusterParticipation, - -capacityReservation.maxActivationRatio); + capacityReservation.maxActivationRatio); } } if (builder.NumberOfVariables() > 0) diff --git a/src/solver/optimisation/include/antares/solver/optimisation/opt_rename_problem.h b/src/solver/optimisation/include/antares/solver/optimisation/opt_rename_problem.h index 6da8f953da..72d8a5fe84 100644 --- a/src/solver/optimisation/include/antares/solver/optimisation/opt_rename_problem.h +++ b/src/solver/optimisation/include/antares/solver/optimisation/opt_rename_problem.h @@ -232,7 +232,7 @@ class ConstraintNamer: public Namer void STPumpingCapacityThreasholdsDown(unsigned int constraint, const std::string& clusterName); void STStockLevelReserveParticipationUp(unsigned int constraint, const std::string& clusterName); void STStockLevelReserveParticipationDown(unsigned int constraint, const std::string& clusterName); - void STEnergyStockLevelReserveParticipationDown(unsigned int constraint, const std::string& clusterName, const std::string& reserveName); + void STEnergyStockLevelReserveParticipation(unsigned int constraint, const std::string& clusterName, const std::string& reserveName); void STGlobalEnergyStockLevelReserveParticipationDown(unsigned int constraint, const std::string& clusterName); void STGlobalEnergyStockLevelReserveParticipationUp(unsigned int constraint, const std::string& clusterName); diff --git a/src/solver/optimisation/opt_gestion_second_membre_reserves.cpp b/src/solver/optimisation/opt_gestion_second_membre_reserves.cpp index 53d5d842fa..a0f6ffa8d7 100644 --- a/src/solver/optimisation/opt_gestion_second_membre_reserves.cpp +++ b/src/solver/optimisation/opt_gestion_second_membre_reserves.cpp @@ -172,11 +172,12 @@ void OPT_InitialiserLeSecondMembreDuProblemeLineaireReserves(PROBLEME_HEBDO* pro [reserveParticipation.globalIndexClusterParticipation]; if (cnt >= 0) { - auto variableManager = VariableManagerFromProblemHebdo(problemeHebdo); - std::vector& Xmin = problemeHebdo->ProblemeAResoudre->Xmin; - int clusterGlobalIndex = problemeHebdo->ShortTermStorage[pays][reserveParticipation.clusterIdInArea].clusterGlobalIndex; - int varLevel = variableManager.ShortTermStorageLevel(clusterGlobalIndex, pdtJour); - double level_min = Xmin[varLevel]; + int weekFirstHour = problemeHebdo->weekInTheYear * 168; + auto& cluster = problemeHebdo->ShortTermStorage[pays][reserveParticipation.clusterIdInArea]; + int hourInTheYear = weekFirstHour + pdtHebdo; + double level_min = cluster.reservoirCapacity + * cluster.series->lowerRuleCurve[hourInTheYear]; + SecondMembre[cnt] = -areaReserveUp.maxEnergyActivationRatio * areaReserveUp.maxActivationDuration * level_min; AdresseOuPlacerLaValeurDesCoutsMarginaux[cnt] = nullptr; } @@ -214,11 +215,11 @@ void OPT_InitialiserLeSecondMembreDuProblemeLineaireReserves(PROBLEME_HEBDO* pro [reserveParticipation.globalIndexClusterParticipation]; if (cnt >= 0) { - auto variableManager = VariableManagerFromProblemHebdo(problemeHebdo); - std::vector& Xmax = problemeHebdo->ProblemeAResoudre->Xmax; - int clusterGlobalIndex = problemeHebdo->ShortTermStorage[pays][reserveParticipation.clusterIdInArea].clusterGlobalIndex; - int varLevel = variableManager.ShortTermStorageLevel(clusterGlobalIndex, pdtJour); - double level_max = Xmax[varLevel]; + int weekFirstHour = problemeHebdo->weekInTheYear * 168; + auto& cluster = problemeHebdo->ShortTermStorage[pays][reserveParticipation.clusterIdInArea]; + int hourInTheYear = weekFirstHour + pdtHebdo; + double level_max = cluster.reservoirCapacity + * cluster.series->upperRuleCurve[hourInTheYear]; SecondMembre[cnt] = areaReserveDown.maxEnergyActivationRatio * areaReserveDown.maxActivationDuration * level_max; AdresseOuPlacerLaValeurDesCoutsMarginaux[cnt] = nullptr; } @@ -260,12 +261,12 @@ void OPT_InitialiserLeSecondMembreDuProblemeLineaireReserves(PROBLEME_HEBDO* pro AdresseOuPlacerLaValeurDesCoutsMarginaux[cnt] = nullptr; } - auto variableManager = VariableManagerFromProblemHebdo(problemeHebdo); - int varLevel = variableManager.ShortTermStorageLevel(globalClusterIdx, pdtJour); - std::vector& Xmax = problemeHebdo->ProblemeAResoudre->Xmax; - double level_max = Xmax[varLevel]; - std::vector& Xmin = problemeHebdo->ProblemeAResoudre->Xmin; - double level_min = Xmin[varLevel]; + int weekFirstHour = problemeHebdo->weekInTheYear * 168; + int hourInTheYear = weekFirstHour + pdtHebdo; + double level_max = cluster.reservoirCapacity + * cluster.series->upperRuleCurve[hourInTheYear]; + double level_min = cluster.reservoirCapacity + * cluster.series->lowerRuleCurve[hourInTheYear]; cnt = CorrespondanceCntNativesCntOptim .NumeroDeContrainteDesContraintesSTStockLevelReserveParticipationDown diff --git a/src/solver/optimisation/opt_rename_problem.cpp b/src/solver/optimisation/opt_rename_problem.cpp index 15749cd488..ba5940c751 100644 --- a/src/solver/optimisation/opt_rename_problem.cpp +++ b/src/solver/optimisation/opt_rename_problem.cpp @@ -648,9 +648,9 @@ void ConstraintNamer::STStockLevelReserveParticipationDown(unsigned int constrai SetSTStorageClusterElementName(constraint, "STStockLevelReserveParticipationDown", clusterName); } -void ConstraintNamer::STEnergyStockLevelReserveParticipationDown(unsigned int constraint, const std::string& clusterName, const std::string& reserveName) +void ConstraintNamer::STEnergyStockLevelReserveParticipation(unsigned int constraint, const std::string& clusterName, const std::string& reserveName) { - SetSTStorageClusterAndReserveElementName(constraint, "STEnergyStockLevelReserveParticipationDown", clusterName, reserveName); + SetSTStorageClusterAndReserveElementName(constraint, "STEnergyStockLevelReserveParticipation", clusterName, reserveName); } void ConstraintNamer::STGlobalEnergyStockLevelReserveParticipationDown(unsigned int constraint, const std::string& clusterName)