Skip to content

Commit

Permalink
Fixed bugs in indexes of reserves participations
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvmara committed Jul 1, 2024
1 parent 502207c commit 5c27d68
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 54 deletions.
4 changes: 2 additions & 2 deletions src/solver/optimisation/constraints/PMaxReserve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ void PMaxReserve::add(int pays, int reserve, int cluster, int pdt, bool isUpRese
= capacityReservation.AllReservesParticipation[cluster];

int globalClusterIdx = data.thermalClusters[pays]
.NumeroDuPalierDansLEnsembleDesPaliersThermiques[cluster];
.NumeroDuPalierDansLEnsembleDesPaliersThermiques[reserveParticipation.clusterIdInArea];

builder.updateHourWithinWeek(pdt)
.RunningClusterReserveParticipation(globalClusterIdx, 1.0)
.RunningClusterReserveParticipation(reserveParticipation.indexClusterParticipation, 1.0)
.NumberOfDispatchableUnits(globalClusterIdx, -reserveParticipation.maxPower)
.lessThan();

Expand Down
38 changes: 28 additions & 10 deletions src/solver/optimisation/constraints/POutBounds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ void POutBounds::add(int pays, int cluster, int pdt)
.NumeroDeContrainteDesContraintesDePuissanceMaxDuPalier[cluster]
= -1;

int globalClusterIdx
= data.thermalClusters[pays].NumeroDuPalierDansLEnsembleDesPaliersThermiques[cluster];

if (!data.Simulation)
{
// 17 ter
Expand All @@ -20,8 +23,6 @@ void POutBounds::add(int pays, int cluster, int pdt)
// P_down : Minimal power output demanded from cluster θ
// P_up : Maximal power output from cluster θ

int globalClusterIdx
= data.thermalClusters[pays].NumeroDuPalierDansLEnsembleDesPaliersThermiques[cluster];

// 17 ter (1) : Sum(P^on_re-) - P <= - P_down
{
Expand All @@ -33,8 +34,14 @@ void POutBounds::add(int pays, int cluster, int pdt)
for (const auto& reserveParticipations :
capacityReservation.AllReservesParticipation)
{
if (reserveParticipations.maxPower != CLUSTER_NOT_PARTICIPATING)
builder.RunningClusterReserveParticipation(globalClusterIdx, 1);
if ((reserveParticipations.maxPower != CLUSTER_NOT_PARTICIPATING)
&& (data.thermalClusters[pays]
.NumeroDuPalierDansLEnsembleDesPaliersThermiques[reserveParticipations
.clusterIdInArea]
== globalClusterIdx))
{
builder.RunningClusterReserveParticipation(reserveParticipations.indexClusterParticipation, 1);
}
}
}

Expand Down Expand Up @@ -67,8 +74,12 @@ void POutBounds::add(int pays, int cluster, int pdt)
for (const auto& reserveParticipations :
capacityReservation.AllReservesParticipation)
{
if (reserveParticipations.maxPower != CLUSTER_NOT_PARTICIPATING)
builder.RunningClusterReserveParticipation(globalClusterIdx, 1);
if ((reserveParticipations.maxPower != CLUSTER_NOT_PARTICIPATING)
&& (data.thermalClusters[pays]
.NumeroDuPalierDansLEnsembleDesPaliersThermiques[reserveParticipations
.clusterIdInArea]
== globalClusterIdx))
builder.RunningClusterReserveParticipation(reserveParticipations.indexClusterParticipation, 1);
}
}

Expand All @@ -95,15 +106,22 @@ void POutBounds::add(int pays, int cluster, int pdt)
{
// Lambda that count the number of reserves that the cluster is participating to
auto countReservesFromCluster
= [cluster](const std::vector<CAPACITY_RESERVATION>& reservations)
= [cluster](const std::vector<CAPACITY_RESERVATION>& reservations,
int globalClusterIdx,
int pays,
ReserveData data)
{
int counter = 0;
for (const auto& capacityReservation : reservations)
{
for (const auto& reserveParticipations :
capacityReservation.AllReservesParticipation)
{
if (reserveParticipations.maxPower != CLUSTER_NOT_PARTICIPATING)
if ((reserveParticipations.maxPower != CLUSTER_NOT_PARTICIPATING)
&& (data.thermalClusters[pays]
.NumeroDuPalierDansLEnsembleDesPaliersThermiques[reserveParticipations
.clusterIdInArea]
== globalClusterIdx))
counter++;
}
}
Expand All @@ -112,9 +130,9 @@ void POutBounds::add(int pays, int cluster, int pdt)

int nbConstraintsToAdd
= countReservesFromCluster(
data.areaReserves.thermalAreaReserves[pays].areaCapacityReservationsUp)
data.areaReserves.thermalAreaReserves[pays].areaCapacityReservationsUp, globalClusterIdx, pays, data)
+ countReservesFromCluster(
data.areaReserves.thermalAreaReserves[pays].areaCapacityReservationsDown);
data.areaReserves.thermalAreaReserves[pays].areaCapacityReservationsDown, globalClusterIdx, pays, data);

builder.data.NbTermesContraintesPourLesReserves += 2 * (nbConstraintsToAdd + 1);

Expand Down
30 changes: 19 additions & 11 deletions src/solver/optimisation/constraints/POutCapacityThreasholds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

void POutCapacityThreasholds::add(int pays, int cluster, int pdt)
{
int globalClusterIdx
= data.thermalClusters[pays].NumeroDuPalierDansLEnsembleDesPaliersThermiques[cluster];

if (!data.Simulation)
{
// 17 bis
Expand All @@ -14,9 +17,6 @@ void POutCapacityThreasholds::add(int pays, int cluster, int pdt)
// P^on_re+ : Participation of running units in cluster θ to Up reserves
// P : Power output from cluster θ

int globalClusterIdx = data.thermalClusters[pays]
.NumeroDuPalierDansLEnsembleDesPaliersThermiques[cluster];

// 17 bis (1) : l * M + Sum(P^on_re-) - P <= 0
{
builder.updateHourWithinWeek(pdt);
Expand All @@ -27,8 +27,10 @@ void POutCapacityThreasholds::add(int pays, int cluster, int pdt)
for (const auto& reserveParticipations :
capacityReservation.AllReservesParticipation)
{
if (reserveParticipations.maxPower != CLUSTER_NOT_PARTICIPATING)
builder.RunningClusterReserveParticipation(globalClusterIdx, 1);
if ((reserveParticipations.maxPower != CLUSTER_NOT_PARTICIPATING)
&& (data.thermalClusters[pays]
.NumeroDuPalierDansLEnsembleDesPaliersThermiques[reserveParticipations.clusterIdInArea] == globalClusterIdx))
builder.RunningClusterReserveParticipation(reserveParticipations.indexClusterParticipation, 1);
}
}

Expand Down Expand Up @@ -61,8 +63,10 @@ void POutCapacityThreasholds::add(int pays, int cluster, int pdt)
for (const auto& reserveParticipations :
capacityReservation.AllReservesParticipation)
{
if (reserveParticipations.maxPower != CLUSTER_NOT_PARTICIPATING)
builder.RunningClusterReserveParticipation(globalClusterIdx, 1);
if ((reserveParticipations.maxPower != CLUSTER_NOT_PARTICIPATING)
&& (data.thermalClusters[pays]
.NumeroDuPalierDansLEnsembleDesPaliersThermiques[reserveParticipations.clusterIdInArea] == globalClusterIdx))
builder.RunningClusterReserveParticipation(reserveParticipations.indexClusterParticipation, 1);
}
}

Expand All @@ -88,15 +92,19 @@ void POutCapacityThreasholds::add(int pays, int cluster, int pdt)
{
// Lambda that count the number of reserves that the cluster is participating to
auto countReservesFromCluster
= [cluster](const std::vector<CAPACITY_RESERVATION>& reservations)
= [cluster](const std::vector<CAPACITY_RESERVATION>& reservations, int globalClusterIdx, int pays, ReserveData data)
{
int counter = 0;
for (const auto& capacityReservation : reservations)
{
for (const auto& reserveParticipations :
capacityReservation.AllReservesParticipation)
{
if (reserveParticipations.maxPower != CLUSTER_NOT_PARTICIPATING)
if ((reserveParticipations.maxPower != CLUSTER_NOT_PARTICIPATING)
&& (data.thermalClusters[pays]
.NumeroDuPalierDansLEnsembleDesPaliersThermiques[reserveParticipations
.clusterIdInArea]
== globalClusterIdx))
counter++;
}
}
Expand All @@ -105,9 +113,9 @@ void POutCapacityThreasholds::add(int pays, int cluster, int pdt)

int nbConstraintsToAdd
= countReservesFromCluster(
data.areaReserves.thermalAreaReserves[pays].areaCapacityReservationsUp)
data.areaReserves.thermalAreaReserves[pays].areaCapacityReservationsUp, globalClusterIdx, pays, data)
+ countReservesFromCluster(
data.areaReserves.thermalAreaReserves[pays].areaCapacityReservationsDown);
data.areaReserves.thermalAreaReserves[pays].areaCapacityReservationsDown, globalClusterIdx, pays, data);

builder.data.NbTermesContraintesPourLesReserves += 2*(nbConstraintsToAdd+2);

Expand Down
6 changes: 3 additions & 3 deletions src/solver/optimisation/constraints/PRunningUnits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ void PRunningUnits::add(int pays, int reserve, int cluster, int pdt, bool isUpRe
= capacityReservation.AllReservesParticipation[cluster];

int globalClusterIdx = data.thermalClusters[pays]
.NumeroDuPalierDansLEnsembleDesPaliersThermiques[cluster];
.NumeroDuPalierDansLEnsembleDesPaliersThermiques[reserveParticipation.clusterIdInArea];

builder.updateHourWithinWeek(pdt)
.RunningClusterReserveParticipation(globalClusterIdx, 1.0)
.ClusterReserveParticipation(globalClusterIdx, -1.0)
.RunningClusterReserveParticipation(reserveParticipation.indexClusterParticipation, 1.0)
.ClusterReserveParticipation(reserveParticipation.indexClusterParticipation, -1.0)
.equalTo();

ConstraintNamer namer(builder.data.NomDesContraintes);
Expand Down
22 changes: 14 additions & 8 deletions src/solver/optimisation/constraints/ReserveParticipationGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,19 @@ void ReserveParticipationGroup::BuildConstraints()
// 24
reserveSatisfaction.add(pays, reserve, pdt, true);

uint32_t cluster = 0;
uint32_t cluster_participation = 0;
for (const auto& clusterReserveParticipation :
areaReserveUp.AllReservesParticipation)
{
if (clusterReserveParticipation.maxPower >= 0)
{
// 16 bis
pMaxReserve.add(pays, reserve, cluster, pdt, true);
pMaxReserve.add(pays, reserve, cluster_participation, pdt, true);

// 17 quater
pRunningUnits.add(pays, reserve, cluster, pdt, true);
pRunningUnits.add(pays, reserve, cluster_participation, pdt, true);
}
cluster++;
cluster_participation++;
}
reserve++;
}
Expand All @@ -90,19 +90,25 @@ void ReserveParticipationGroup::BuildConstraints()
// 24
reserveSatisfaction.add(pays, reserve, pdt, false);

uint32_t cluster = 0;
uint32_t cluster_participation = 0;
for (const auto& clusterReserveParticipation :
areaReserveDown.AllReservesParticipation)
{
if (clusterReserveParticipation.maxPower >= 0)
{
// 16 bis
pMaxReserve.add(pays, reserve, cluster, pdt, false);
pMaxReserve.add(pays,
reserve, cluster_participation,
pdt,
false);

// 17 quater
pRunningUnits.add(pays, reserve, cluster, pdt, false);
pRunningUnits.add(pays,
reserve, cluster_participation,
pdt,
false);
}
cluster++;
cluster_participation++;
}
reserve++;
}
Expand Down
6 changes: 2 additions & 4 deletions src/solver/optimisation/constraints/ReserveSatisfaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,15 @@ void ReserveSatisfaction::add(int pays, int reserve, int pdt, bool isUpReserve)
{
if (capacityReservation.AllReservesParticipation[cluster].maxPower != CLUSTER_NOT_PARTICIPATING)
builder.RunningClusterReserveParticipation(
data.thermalClusters[pays]
.NumeroDuPalierDansLEnsembleDesPaliersThermiques[cluster],
capacityReservation.AllReservesParticipation[cluster].indexClusterParticipation,
1);
}

builder.InternalUnsatisfiedReserve(capacityReservation.globalReserveIndex, 1)
.InternalExcessReserve(capacityReservation.globalReserveIndex, -1)
.equalTo();
data.CorrespondanceCntNativesCntOptim[pdt]
.NumeroDeContrainteDesContraintesDeBesoinEnReserves[capacityReservation
.globalReserveIndex]
.NumeroDeContrainteDesContraintesDeBesoinEnReserves[capacityReservation.globalReserveIndex]
= builder.data.nombreDeContraintes;
ConstraintNamer namer(builder.data.NomDesContraintes);
const int hourInTheYear = builder.data.weekInTheYear * 168 + pdt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class PMaxReserve : private ConstraintFactory
* @brief Add variables to the constraint and update constraints Matrix
* @param pays : area
* @param reserve : capacity reservation
* @param cluster : global index of the cluster
* @param cluster : local index of the cluster
* @param pdt : timestep
* @param isUpReserve : true if ReserveUp, false if ReserveDown
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ struct RESERVE_PARTICIPATION
float participationCost = CLUSTER_NOT_PARTICIPATING;
int indexClusterParticipation = 0;
std::string clusterName;
int clusterIdInArea;
};

struct CAPACITY_RESERVATION
Expand Down
30 changes: 15 additions & 15 deletions src/solver/simulation/sim_calcul_economique.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,16 +335,15 @@ void SIM_InitialisationProblemeHebdo(Data::Study& study,
for (auto cluster : area.thermal.list.each_enabled_and_not_mustrun())
{
RESERVE_PARTICIPATION reserveParticipation;
if (cluster->isParticipatingInReserve(key))
{
reserveParticipation.maxPower = cluster->reserveMaxPower(key);
reserveParticipation.participationCost = cluster->reserveCost(key);
reserveParticipation.clusterName = cluster->name();
reserveParticipation.indexClusterParticipation
= globalClusterParticipationIndex++;
areaCapacityReservationsUp.AllReservesParticipation.push_back(
reserveParticipation);
}
reserveParticipation.maxPower = cluster->reserveMaxPower(key);
reserveParticipation.participationCost = cluster->reserveCost(key);
reserveParticipation.clusterName = cluster->name();
reserveParticipation.clusterIdInArea = cluster->index;
reserveParticipation.indexClusterParticipation
= globalClusterParticipationIndex;
globalClusterParticipationIndex++;
areaCapacityReservationsUp.AllReservesParticipation.push_back(
reserveParticipation);
}

areaReserves.areaCapacityReservationsUp.push_back(areaCapacityReservationsUp);
Expand All @@ -367,16 +366,17 @@ void SIM_InitialisationProblemeHebdo(Data::Study& study,
for (auto cluster : area.thermal.list.each_enabled_and_not_mustrun())
{
RESERVE_PARTICIPATION reserveParticipation;
if (cluster->isParticipatingInReserve(key))
{
//if (cluster->isParticipatingInReserve(key))
//{
reserveParticipation.maxPower = cluster->reserveMaxPower(key);
reserveParticipation.participationCost = cluster->reserveCost(key);
reserveParticipation.clusterName = cluster->name();
reserveParticipation.indexClusterParticipation
= globalClusterParticipationIndex++;
reserveParticipation.clusterIdInArea = cluster->index;
reserveParticipation.indexClusterParticipation = globalClusterParticipationIndex;
globalClusterParticipationIndex++;
areaCapacityReservationsDown.AllReservesParticipation.push_back(
reserveParticipation);
}
//}
}

areaReserves.areaCapacityReservationsDown.push_back(areaCapacityReservationsDown);
Expand Down

0 comments on commit 5c27d68

Please sign in to comment.