Skip to content

Commit

Permalink
fix bugs related to the implementation of reserves lot 3 v2
Browse files Browse the repository at this point in the history
  • Loading branch information
bencamus committed Nov 29, 2024
1 parent c566d33 commit c0ec60a
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 67 deletions.
10 changes: 5 additions & 5 deletions src/libs/antares/study/area/list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -927,31 +927,31 @@ 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<float>(area.allCapacityReservations.maxGlobalEnergyActivationRatioUp))
{
logs.warning()
<< 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<float>(area.allCapacityReservations.maxGlobalEnergyActivationRatioDown))
{
logs.warning()
<< 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<int>(area.allCapacityReservations.maxGlobalActivationDurationUp))
{
logs.warning()
<< 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<int>(area.allCapacityReservations.maxGlobalActivationDurationDown))
{
Expand Down Expand Up @@ -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<float>(tmpCapacityReservation.maxActivationRatio))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
33 changes: 17 additions & 16 deletions src/solver/optimisation/opt_gestion_second_membre_reserves.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,12 @@ void OPT_InitialiserLeSecondMembreDuProblemeLineaireReserves(PROBLEME_HEBDO* pro
[reserveParticipation.globalIndexClusterParticipation];
if (cnt >= 0)
{
auto variableManager = VariableManagerFromProblemHebdo(problemeHebdo);
std::vector<double>& 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;
}
Expand Down Expand Up @@ -214,11 +215,11 @@ void OPT_InitialiserLeSecondMembreDuProblemeLineaireReserves(PROBLEME_HEBDO* pro
[reserveParticipation.globalIndexClusterParticipation];
if (cnt >= 0)
{
auto variableManager = VariableManagerFromProblemHebdo(problemeHebdo);
std::vector<double>& 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;
}
Expand Down Expand Up @@ -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<double>& Xmax = problemeHebdo->ProblemeAResoudre->Xmax;
double level_max = Xmax[varLevel];
std::vector<double>& 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
Expand Down
4 changes: 2 additions & 2 deletions src/solver/optimisation/opt_rename_problem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c0ec60a

Please sign in to comment.