Skip to content

Commit

Permalink
Merge branch 'feature/reserve_model_lot2_scalian' into feature/reserv…
Browse files Browse the repository at this point in the history
…e_model_lot3_scalian
  • Loading branch information
bencamus committed Nov 28, 2024
2 parents 1a3fe6e + d8e5806 commit c566d33
Show file tree
Hide file tree
Showing 12 changed files with 107 additions and 93 deletions.
28 changes: 17 additions & 11 deletions src/libs/antares/study/area/list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -913,9 +913,8 @@ static bool AreaListLoadFromFolderSingleArea(Study& study,

// Reserves
{
buffer.clear() << study.folderInput << SEP << "reserves" << SEP << area.id << SEP
<< "reserves.ini";
if (ini.open(buffer, false))
fs::path reserves = study.folderInput / "reserves" / area.id.to<std::string>() / "reserves.ini";
if (ini.open(reserves, false))
{
ini.each(
[&](const IniFile::Section& section)
Expand Down Expand Up @@ -1109,9 +1108,11 @@ static bool AreaListLoadFromFolderSingleArea(Study& study,
studyVersion,
study.usedByTheSolver);

buffer.clear() << study.folderInput << SEP << "hydro" << SEP << "common" << SEP << area.id
<< SEP << "reserves.ini";
ret = area.hydro.loadReserveParticipations(area, buffer) && ret;
fs::path reservesHydro = study.folderInput / "hydro" / "common" / area.id.to<std::string>() / "reserves.ini";
if (study.parameters.unitCommitment.ucMode != UnitCommitmentMode::ucHeuristicFast)
{
area.hydro.loadReserveParticipations(area, reservesHydro);
}
}

// Wind
Expand Down Expand Up @@ -1143,10 +1144,12 @@ static bool AreaListLoadFromFolderSingleArea(Study& study,
if (study.usedByTheSolver && study.parameters.mode == SimulationMode::Adequacy)
{
area.thermal.list.enableMustrunForEveryone();
}
buffer.clear() << study.folderInput << SEP << "thermal" << SEP << "clusters" << SEP
<< area.id << SEP << "reserves.ini";
ret = area.thermal.list.loadReserveParticipations(area, buffer) && ret;
}
fs::path reservesThermal = study.folderInput / "thermal" / "clusters" / area.id.to<std::string>() / "reserves.ini";
if (study.parameters.unitCommitment.ucMode != UnitCommitmentMode::ucHeuristicFast)
{
area.thermal.list.loadReserveParticipations(area, reservesThermal);
}
}

// Short term storage
Expand All @@ -1160,7 +1163,10 @@ static bool AreaListLoadFromFolderSingleArea(Study& study,

fs::path reservesPath = study.folderInput / "st-storage" / "clusters"
/ area.id.to<std::string>() / "reserves.ini";
ret = area.shortTermStorage.loadReserveParticipations(area, reservesPath) && ret;
if (study.parameters.unitCommitment.ucMode != UnitCommitmentMode::ucHeuristicFast)
{
area.shortTermStorage.loadReserveParticipations(area, reservesPath);
}
}

// Renewable cluster list
Expand Down
6 changes: 6 additions & 0 deletions src/libs/antares/study/include/antares/study/area/area.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ class BiMap
}
return -1; // Return -1 if value is not found
}

// Function to return the size of the bimap
int size()
{
return key_to_value.size();
}
};

namespace Antares
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class ClusterList
/// @param area Reference to area
/// @param file File to read the reserve participations entries
/// @return false if the file opening failed, true otherwise
bool loadReserveParticipations(Area& area, const AnyString& folder);
bool loadReserveParticipations(Area& area, const std::filesystem::path& file);

bool saveDataSeriesToFolder(const AnyString& folder) const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class PartHydro

uint count() const;

bool loadReserveParticipations(Area& area, const AnyString& file);
bool loadReserveParticipations(Area& area, const std::filesystem::path& file);

void addReserveParticipation(const std::string& reserveName,
const LTStorageClusterReserveParticipation& participation);
Expand Down
2 changes: 1 addition & 1 deletion src/libs/antares/study/parts/common/cluster_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ bool ClusterList<ClusterT>::loadDataSeriesFromFolder(Study& s, const std::filesy
}

template<class ClusterT>
bool ClusterList<ClusterT>::loadReserveParticipations(Area& area, const AnyString& file)
bool ClusterList<ClusterT>::loadReserveParticipations(Area& area, const std::filesystem::path& file)
{
IniFile ini;
if (!ini.open(file, false))
Expand Down
2 changes: 1 addition & 1 deletion src/libs/antares/study/parts/hydro/container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ bool PartHydro::CheckDailyMaxEnergy(const AnyString& areaName)
return ret;
}

bool PartHydro::loadReserveParticipations(Area& area, const AnyString& file)
bool PartHydro::loadReserveParticipations(Area& area, const std::filesystem::path& file)
{
IniFile ini;
if (!ini.open(file, false))
Expand Down
12 changes: 8 additions & 4 deletions src/solver/optimisation/constraints/POutBounds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,20 @@ void POutBounds::add(int pays, int cluster, int pdt)
return counter;
};

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

int nbTermsToAdd
= countReservesParticipations(
data.areaReserves[pays].areaCapacityReservationsUp)
+ countReservesParticipations(
data.areaReserves[pays].areaCapacityReservationsDown);

builder.data.NbTermesContraintesPourLesReserves
+= (nbTermsUp + 1) * (nbTermsUp > 0) + (nbTermsDown + 1) * (nbTermsDown > 0);


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

builder.data.nombreDeContraintes += 2;
builder.data.nombreDeContraintes += (nbTermsUp > 0) + (nbTermsDown > 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void POutCapacityThreasholds::add(int pays, int cluster, int pdt)
data.areaReserves[pays].areaCapacityReservationsDown);

builder.data.NbTermesContraintesPourLesReserves
+= (nbTermsUp + 1) * (nbTermsUp > 0) + (nbTermsDown + 1) * (nbTermsDown > 0);
+= (nbTermsUp + 2) * (nbTermsUp > 0) + (nbTermsDown + 2) * (nbTermsDown > 0);

builder.data.nombreDeContraintes += (nbTermsUp > 0) + (nbTermsDown > 0);
}
Expand Down
130 changes: 65 additions & 65 deletions src/solver/optimisation/constraints/ReserveSatisfaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,84 +5,84 @@ void ReserveSatisfaction::add(int pays, int reserve, int pdt, bool isUpReserve)
CAPACITY_RESERVATION capacityReservation
= isUpReserve ? data.areaReserves[pays].areaCapacityReservationsUp[reserve]
: data.areaReserves[pays].areaCapacityReservationsDown[reserve];

if (!data.Simulation)
int nbTermes = capacityReservation.AllThermalReservesParticipation.size()
+ capacityReservation.AllSTStorageReservesParticipation.size()
+ capacityReservation.AllLTStorageReservesParticipation.size();
if (nbTermes)
{
// 24
if (!data.Simulation)
{
// 24

// Sum(P_θ) + Sum(P_B) + Sum(P_H) = S + J^+ -J^-
// P_θ : Participation power from thermal cluster θ to the reserve res
// P_B : Participation power from Short Term Storage cluster B to the reserve res
// P_H : Participation power from Long Term Storage to the reserve res
// S : Internal reserve res need for the area (second membre)
// J^+ : Amount of internal excess reserve for the reserve res
// J^- : Amount of internal unsatisfied reserve for the reserve res
// Sum(P_θ) + Sum(P_B) + Sum(P_H) = S + J^+ -J^-
// P_θ : Participation power from thermal cluster θ to the reserve res
// P_B : Participation power from Short Term Storage cluster B to the reserve res
// P_H : Participation power from Long Term Storage to the reserve res
// S : Internal reserve res need for the area (second membre)
// J^+ : Amount of internal excess reserve for the reserve res
// J^- : Amount of internal unsatisfied reserve for the reserve res

builder.updateHourWithinWeek(pdt);

// Thermal clusters reserve participation
for (auto& [clusterId, reserveParticipation] : capacityReservation.AllThermalReservesParticipation)
{
builder.ThermalClusterReserveParticipation(
reserveParticipation.globalIndexClusterParticipation,
1);
}
builder.updateHourWithinWeek(pdt);

// Short Term Storage clusters reserve participation
for (auto& [clusterId, reserveParticipation] : capacityReservation.AllSTStorageReservesParticipation)
{
if (isUpReserve)
{
builder.STStorageClusterReserveUpParticipation(
reserveParticipation.globalIndexClusterParticipation,
1);
}
else
// Thermal clusters reserve participation
for (auto& [clusterId, reserveParticipation] : capacityReservation.AllThermalReservesParticipation)
{
builder.STStorageClusterReserveDownParticipation(
reserveParticipation.globalIndexClusterParticipation,
1);
builder.ThermalClusterReserveParticipation(
reserveParticipation.globalIndexClusterParticipation,
1);
}
}

// Long Term Storage clusters reserve participation
for (auto& reserveParticipation: capacityReservation.AllLTStorageReservesParticipation)
{
if (isUpReserve)
// Short Term Storage clusters reserve participation
for (auto& [clusterId, reserveParticipation] : capacityReservation.AllSTStorageReservesParticipation)
{
builder.LTStorageClusterReserveUpParticipation(
reserveParticipation.globalIndexClusterParticipation,
1);
if (isUpReserve)
{
builder.STStorageClusterReserveUpParticipation(
reserveParticipation.globalIndexClusterParticipation,
1);
}
else
{
builder.STStorageClusterReserveDownParticipation(
reserveParticipation.globalIndexClusterParticipation,
1);
}
}
else

// Long Term Storage clusters reserve participation
for (auto& reserveParticipation : capacityReservation.AllLTStorageReservesParticipation)
{
builder.LTStorageClusterReserveDownParticipation(
reserveParticipation.globalIndexClusterParticipation,
1);
if (isUpReserve)
{
builder.LTStorageClusterReserveUpParticipation(
reserveParticipation.globalIndexClusterParticipation,
1);
}
else
{
builder.LTStorageClusterReserveDownParticipation(
reserveParticipation.globalIndexClusterParticipation,
1);
}
}
}

builder.InternalUnsatisfiedReserve(capacityReservation.globalReserveIndex, 1)
.InternalExcessReserve(capacityReservation.globalReserveIndex, -1)
.equalTo();
data.CorrespondanceCntNativesCntOptim[pdt]
.NumeroDeContrainteDesContraintesDeBesoinEnReserves[capacityReservation
.globalReserveIndex]
= 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.ReserveSatisfaction(builder.data.nombreDeContraintes,
capacityReservation.reserveName);
builder.build();
}
else
{
int nbTermes = capacityReservation.AllThermalReservesParticipation.size()
+ capacityReservation.AllSTStorageReservesParticipation.size()
+ capacityReservation.AllLTStorageReservesParticipation.size();
if (nbTermes)
builder.InternalUnsatisfiedReserve(capacityReservation.globalReserveIndex, 1)
.InternalExcessReserve(capacityReservation.globalReserveIndex, -1)
.equalTo();
data.CorrespondanceCntNativesCntOptim[pdt]
.NumeroDeContrainteDesContraintesDeBesoinEnReserves[capacityReservation
.globalReserveIndex]
= 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.ReserveSatisfaction(builder.data.nombreDeContraintes,
capacityReservation.reserveName);
builder.build();
}
else
{
builder.data.NbTermesContraintesPourLesReserves += 2 + nbTermes;
builder.data.nombreDeContraintes += 1;
Expand Down
3 changes: 1 addition & 2 deletions src/solver/optimisation/opt_rename_problem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,7 @@ void VariableNamer::NumberOfOffUnitsParticipatingToReserve(unsigned int variable
const std::string& clusterName,
const std::string& reserveName)
{
SetThermalClusterReserveElementName(
variable, "NumberOfOffUnitsParticipatingToReserve", clusterName);
SetThermalClusterAndReserveElementName(variable, "NumberOfOffUnitsParticipatingToReserve", clusterName, reserveName);
}

void VariableNamer::NumberStoppingDispatchableUnits(unsigned int variable,
Expand Down
7 changes: 3 additions & 4 deletions src/solver/simulation/sim_alloc_probleme_hebdo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,10 @@ void SIM_AllocationProblemePasDeTemps(PROBLEME_HEBDO& problem,
study.runtime.thermalPlantTotalCount * study.runtime.capacityReservationCount, -1);
problem.CorrespondanceCntNativesCntOptim[k]
.NumeroDeContrainteDesContraintesDePuissanceMinDuPalier.assign(
study.runtime.thermalPlantTotalCount, 0);
study.runtime.thermalPlantTotalCount, -1);
problem.CorrespondanceCntNativesCntOptim[k]
.NumeroDeContrainteDesContraintesDePuissanceMaxDuPalier.assign(
study.runtime.thermalPlantTotalCount, 0);
study.runtime.thermalPlantTotalCount, -1);

problem.CorrespondanceCntNativesCntOptim[k]
.NumeroDeContrainteDesContraintesSTStorageClusterMaxWithdrawParticipation.assign(
Expand Down Expand Up @@ -536,8 +536,7 @@ void SIM_AllocateAreas(PROBLEME_HEBDO& problem,
nbReserves, 0.);
problem.ResultatsHoraires[k].Reserves[j].CoutsMarginauxHoraires.assign(nbReserves, 0.);
problem.ResultatsHoraires[k].HydroUsage[j].reserveParticipationOfCluster.assign(
1, // For the moment only one hydro cluster per area
0.);
nbLTStorageReserveParticipations, 0.);
}
// Short term storage results
const unsigned long nbShortTermStorage = study.areas.byIndex[k]->shortTermStorage.count();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class ReserveParticipationByLTStorage
pSize = 0;
for (int areaIndex = 0; areaIndex < study->areas.size(); areaIndex++)
{
pSize += study->areas[areaIndex]->allCapacityReservations.size();
pSize += study->areas[areaIndex]->hydro.reserveParticipationsCount();
}
if (pSize)
{
Expand Down Expand Up @@ -224,4 +224,4 @@ void localBuildAnnualSurveyReport(SurveyResults& results,
} // namespace Solver
} // namespace Antares

#endif // __SOLVER_VARIABLE_ECONOMY_ReserveParticipationByLTStorage_H__
#endif // __SOLVER_VARIABLE_ECONOMY_ReserveParticipationByLTStorage_H__

0 comments on commit c566d33

Please sign in to comment.