Skip to content

Commit

Permalink
first version of the implementation de reserve lot 3
Browse files Browse the repository at this point in the history
  • Loading branch information
bencamus committed Oct 31, 2024
1 parent 2387087 commit 6613609
Show file tree
Hide file tree
Showing 21 changed files with 858 additions and 68 deletions.
68 changes: 6 additions & 62 deletions src/libs/antares/study/area/list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -954,77 +954,21 @@ static bool AreaListLoadFromFolderSingleArea(Study& study,
<< section.name;
}
}
else if (tmp == "type")
{
if (p->value == "up")
type = 0;
else if (p->value == "down")
type = 1;
else
logs.warning()
<< area.name << ": invalid type for reserve " << section.name;
}
else
logs.warning()
<< area.name << ": invalid key " << tmp << " in file " << buffer;
}
fs::path filePath = study.folderInput / "reserves" / area.id.to<std::string>()
/ (file_name + ".txt");
ret = tmpCapacityReservation.need.loadFromFile(filePath, false) && ret;
if (type == 0)
area.allCapacityReservations.areaCapacityReservationsUp.emplace(
section.name, tmpCapacityReservation);
else if (type == 1)
area.allCapacityReservations.areaCapacityReservationsDown.emplace(
section.name, tmpCapacityReservation);
else
logs.warning()
<< area.name << ": invalid type for reserve " << section.name;
}
});
}
}

// Reserves
{
buffer.clear() << study.folderInput << SEP << "reserves" << SEP << area.id << SEP
<< "reserves.ini";
if (ini.open(buffer, false))
{
ini.each(
[&](const IniFile::Section& section)
{
if (area.allCapacityReservations.contains(section.name))
{
logs.warning() << area.name << ": reserve name already exists for reserve "
<< section.name;
}
else
{
CapacityReservation tmpCapacityReservation;
std::string file_name = AllCapacityReservations::toFilename(section.name);
int type = -1;
for (auto* p = section.firstProperty; p; p = p->next)
{
CString<30, false> tmp;
tmp = p->key;
tmp.toLower();

if (tmp == "failure-cost")
else if (tmp == "max-activation-ratio")
{
if (!p->value.to<float>(tmpCapacityReservation.failureCost))
if (!p->value.to<float>(tmpCapacityReservation.maxActivationRatio))
{
logs.warning()
<< area.name << ": invalid failure cost for reserve "
<< area.name << ": invalid maximum activation ratio for reserve "
<< section.name;
}
}
else if (tmp == "spillage-cost")
else if (tmp == "max-activation-duration")
{
if (!p->value.to<float>(tmpCapacityReservation.spillageCost))
if (!p->value.to<int>(tmpCapacityReservation.maxActivationHours))
{
logs.warning()
<< area.name << ": invalid spillage cost for reserve "
<< area.name << ": invalid maximum activation duration for reserve "
<< section.name;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@
/// @brief Represents an area capacity reservation using it's name, it's failure cost and it's spillage cost
struct CapacityReservation
{
CapacityReservation() : failureCost(0), spillageCost(0), need(timeseriesNumbers) {}
CapacityReservation() : failureCost(0), spillageCost(0), need(timeseriesNumbers), maxActivationRatio(1.), maxActivationHours(0) {}
float failureCost;
float spillageCost;
float maxActivationRatio;
int maxActivationHours;
Antares::Data::TimeSeries need;

private:
Expand Down
4 changes: 4 additions & 0 deletions src/solver/optimisation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ set(RTESOLVER_OPT
constraints/STReserveUpParticipation.cpp
include/antares/solver/optimisation/constraints/STReserveDownParticipation.h
constraints/STReserveDownParticipation.cpp
include/antares/solver/optimisation/constraints/STStockLevelReserveParticipation.h
constraints/STStockLevelReserveParticipation.cpp
include/antares/solver/optimisation/constraints/LTTurbiningMaxReserve.h
constraints/LTTurbiningMaxReserve.cpp
include/antares/solver/optimisation/constraints/LTPumpingMaxReserve.h
Expand All @@ -162,6 +164,8 @@ set(RTESOLVER_OPT
constraints/LTTurbiningCapacityThreasholds.cpp
include/antares/solver/optimisation/constraints/LTPumpingCapacityThreasholds.h
constraints/LTPumpingCapacityThreasholds.cpp
include/antares/solver/optimisation/constraints/LTStockLevelReserveParticipation.h
constraints/LTStockLevelReserveParticipation.cpp
include/antares/solver/optimisation/ProblemMatrixEssential.h
ProblemMatrixEssential.cpp
include/antares/solver/optimisation/LinearProblemMatrixStartUpCosts.h
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once
#include "ConstraintBuilder.h"

/*
* represent 'LTPumpingCapacityThreasholds' Constraint type
*/
class LTPumpingCapacityThreasholds : private ConstraintFactory
{
public:
LTPumpingCapacityThreasholds(ConstraintBuilder& builder, ReserveData& data) :
ConstraintFactory(builder), data(data)
{
}

/*!
* @brief Add variables to the constraint and update constraints Matrix
* @param pays : area
* @param cluster : global index of the cluster
* @param pdt : timestep
*/
void add(int pays, int cluster, int pdt);

private:
ReserveData& data;
};

Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#include "antares/solver/optimisation/constraints/LTStockLevelReserveParticipation.h"

void LTStockLevelReserveParticipation::add(int pays, int cluster, int pdt)
{
int globalClusterIdx = data.longTermStorageOfArea[pays].GlobalHydroIndex;

if (!data.Simulation)
{
// 15 (r) (1)
// Participation of down reserves requires a sufficient level of stock
// R_t + Sum(P_{res,t_st} * R_{min,res}) <= 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
{
builder.updateHourWithinWeek(pdt).HydroLevel(pays, 1.);

for (const auto& capacityReservation : data.areaReserves[pays].areaCapacityReservationsDown)
{
int t_max = pdt + capacityReservation.maxActivationDuration;
if (t_max > builder.data.NombreDePasDeTempsPourUneOptimisation)
t_max = builder.data.NombreDePasDeTempsPourUneOptimisation;

for (int t=pdt; t < t_max; t++)
{
builder.updateHourWithinWeek(t);
for (const auto& reserveParticipations : capacityReservation.AllLTStorageReservesParticipation)
{
builder.LTStorageClusterReserveDownParticipation(
reserveParticipations.globalIndexClusterParticipation,
capacityReservation.maxActivationRatio);
}
}
}
builder.lessThan();
data.CorrespondanceCntNativesCntOptim[pdt]
.NumeroDeContrainteDesContraintesLTStockLevelReserveParticipationDown
[globalClusterIdx]
= 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.LTStockLevelReserveParticipationDown(builder.data.nombreDeContraintes,
"LongTermStorage");
builder.build();
}

// 15 (r) (2)
// Participation of up reserves requires a sufficient level of stock
// R_t - Sum(P_{res,t_st} * R_{min,res}) >= R_down
// R_t : stock level at time t
// P_{res,t_st} : power participation for reserve up res at time t_st
// R_{min,res} : max power participation ratio
// R_down : min stock level
{
builder.updateHourWithinWeek(pdt).HydroLevel(pays, 1.);

for (const auto& capacityReservation : data.areaReserves[pays].areaCapacityReservationsUp)
{
int t_max = pdt + capacityReservation.maxActivationDuration;
if (t_max > builder.data.NombreDePasDeTempsPourUneOptimisation)
t_max = builder.data.NombreDePasDeTempsPourUneOptimisation;

for (int t=pdt; t < t_max; t++)
{
builder.updateHourWithinWeek(t);
for (const auto& reserveParticipations : capacityReservation.AllLTStorageReservesParticipation)
{
builder.LTStorageClusterReserveUpParticipation(
reserveParticipations.globalIndexClusterParticipation,
-capacityReservation.maxActivationRatio);
}
}
}
builder.greaterThan();
data.CorrespondanceCntNativesCntOptim[pdt]
.NumeroDeContrainteDesContraintesLTStockLevelReserveParticipationUp
[globalClusterIdx]
= 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.LTStockLevelReserveParticipationUp(builder.data.nombreDeContraintes,
"LongTermStorage");
builder.build();
}
}
else
{
// Lambda that count the number of reserveParticipations
auto countReservesParticipations = [](const std::vector<CAPACITY_RESERVATION>& reservations, int time, int time_max)
{
int counter = 0;
for (const auto& capacityReservation: reservations)
{
int n_t = capacityReservation.maxActivationDuration;
if (time + n_t > time_max)
n_t = time_max - time;
counter += capacityReservation.AllLTStorageReservesParticipation.size() * n_t;
}
return counter;
};

int nbTermsUp = countReservesParticipations(
data.areaReserves[pays].areaCapacityReservationsUp, pdt, builder.data.NombreDePasDeTempsPourUneOptimisation);
int nbTermsDown = countReservesParticipations(
data.areaReserves[pays].areaCapacityReservationsDown, pdt, builder.data.NombreDePasDeTempsPourUneOptimisation);

builder.data.NbTermesContraintesPourLesReserves += (nbTermsUp + 1) + (nbTermsDown + 1);
builder.data.nombreDeContraintes += 2;
}
}
10 changes: 10 additions & 0 deletions src/solver/optimisation/constraints/ReserveParticipationGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
#include "antares/solver/optimisation/constraints/LTReserveDownParticipation.h"
#include "antares/solver/optimisation/constraints/LTTurbiningCapacityThreasholds.h"
#include "antares/solver/optimisation/constraints/LTPumpingCapacityThreasholds.h"
#include "antares/solver/optimisation/constraints/LTStockLevelReserveParticipation.h"
#include "antares/solver/optimisation/constraints/STStockLevelReserveParticipation.h"



ReserveParticipationGroup::ReserveParticipationGroup(PROBLEME_HEBDO* problemeHebdo,
Expand Down Expand Up @@ -281,6 +284,8 @@ void ReserveParticipationGroup::BuildConstraints()
STPumpingCapacityThreasholds STPumpingCapacityThreasholds(builder_, data);
LTTurbiningCapacityThreasholds LTTurbiningCapacityThreasholds(builder_, data);
LTPumpingCapacityThreasholds LTPumpingCapacityThreasholds(builder_, data);
LTStockLevelReserveParticipation LTStockLevelReserveParticipation(builder_, data);
STStockLevelReserveParticipation STStockLevelReserveParticipation(builder_, data);

for (int pdt = 0; pdt < problemeHebdo_->NombreDePasDeTempsPourUneOptimisation; pdt++)
{
Expand All @@ -307,6 +312,8 @@ void ReserveParticipationGroup::BuildConstraints()
STTurbiningCapacityThreasholds.add(pays, cluster, pdt);
// 15 (n)
STPumpingCapacityThreasholds.add(pays, cluster, pdt);
// 15 (r)
STStockLevelReserveParticipation.add(pays, cluster, pdt);
}

// Long Term Storage Clusters
Expand All @@ -328,6 +335,9 @@ void ReserveParticipationGroup::BuildConstraints()
LTTurbiningCapacityThreasholds.add(pays, 0, pdt);
// 15 (d)
LTPumpingCapacityThreasholds.add(pays, 0, pdt);
// 15 (r)
LTStockLevelReserveParticipation.add(pays, 0, pdt);

}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#pragma once
Loading

0 comments on commit 6613609

Please sign in to comment.