Skip to content

Commit

Permalink
Adding the first constraint (16bis) and counting the number of reserv…
Browse files Browse the repository at this point in the history
…ation constraints in the problem
  • Loading branch information
sylvmara committed Apr 8, 2024
1 parent 70ea5bd commit 28208e6
Show file tree
Hide file tree
Showing 27 changed files with 578 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ class Cluster
//! \brief Returns participating cost for a reserve if participating, -1 otherwise
float reserveCost(std::string name);

//! \brief Returns the number of reserves linked to this cluster
unsigned int reservesCount();


protected:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ class ThermalClusterList : public ClusterList<ThermalCluster>
unsigned int enabledAndMustRunCount() const;
unsigned int enabledAndNotMustRunCount() const;

unsigned int reservesCount() const;

private:
// Give a special index to enbled and not must-run THERMAL clusters
void rebuildIndex() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class StudyRuntimeInfos
//! Total
uint thermalPlantTotalCount;
uint thermalPlantTotalCountMustRun;
uint capacityReservationCount = 0;

uint shortTermStorageCount = 0;

Expand Down
4 changes: 4 additions & 0 deletions src/libs/antares/study/parts/common/cluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ float Cluster::reserveCost(std::string name)
return -1;
}

unsigned int Cluster::reservesCount(){
return clusterReservesParticipations.size();
}

void Cluster::invalidateArea()
{
if (parentArea)
Expand Down
10 changes: 10 additions & 0 deletions src/libs/antares/study/parts/thermal/cluster_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "antares/study/study.h"
#include <antares/utils/utils.h>
#include <ranges>
#include <numeric>

namespace // anonymous
{
Expand Down Expand Up @@ -87,6 +88,15 @@ unsigned int ThermalClusterList::enabledAndMustRunCount() const
return std::ranges::count_if(allClusters_, [](auto c) { return c->isEnabled() && c->isMustRun(); });
}

unsigned int ThermalClusterList::reservesCount() const
{
return std::accumulate(allClusters_.begin(),
allClusters_.end(),
0,
[](int total, const std::shared_ptr<ThermalCluster> cluster)
{ return total + cluster->reservesCount(); });
}

bool ThermalClusterList::loadFromFolder(Study& study, const AnyString& folder, Area* area)
{
assert(area && "A parent area is required");
Expand Down
1 change: 1 addition & 0 deletions src/libs/antares/study/runtime/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ static void StudyRuntimeInfosInitializeAllAreas(Study& study, StudyRuntimeInfos&
// statistics
r.thermalPlantTotalCount += area.thermal.list.enabledAndNotMustRunCount();
r.thermalPlantTotalCountMustRun += area.thermal.list.enabledAndMustRunCount();
r.capacityReservationCount += area.thermal.list.reservesCount();

r.shortTermStorageCount += area.shortTermStorage.count();
}
Expand Down
5 changes: 5 additions & 0 deletions src/solver/optimisation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ set(RTESOLVER_OPT
opt_decompte_variables_et_contraintes_couts_demarrage.cpp
opt_init_minmax_groupes_couts_demarrage.cpp
opt_nombre_min_groupes_demarres_couts_demarrage.cpp
opt_construction_variables_reserves_thermiques.cpp
include/antares/solver/optimisation/opt_export_structure.h
opt_export_structure.cpp
include/antares/solver/optimisation/base_weekly_optimization.h
Expand Down Expand Up @@ -126,6 +127,8 @@ set(RTESOLVER_OPT
constraints/NbDispUnitsMinBoundSinceMinUpTime.cpp
include/antares/solver/optimisation/constraints/MinDownTime.h
constraints/MinDownTime.cpp
include/antares/solver/optimisation/constraints/PMaxReserve.h
constraints/PMaxReserve.cpp

include/antares/solver/optimisation/ProblemMatrixEssential.h
ProblemMatrixEssential.cpp
Expand Down Expand Up @@ -156,6 +159,8 @@ set(RTESOLVER_OPT
constraints/FinalStockGroup.cpp
include/antares/solver/optimisation/constraints/AbstractStartUpCostsGroup.h
constraints/AbstractStartUpCostsGroup.cpp
include/antares/solver/optimisation/constraints/ReserveParticipationGroup.h
constraints/ReserveParticipationGroup.cpp
include/antares/solver/optimisation/constraints/PMinMaxDispatchableGenerationGroup.h
constraints/PMinMaxDispatchableGenerationGroup.cpp
include/antares/solver/optimisation/constraints/ConsistenceNumberOfDispatchableUnitsGroup.h
Expand Down
6 changes: 4 additions & 2 deletions src/solver/optimisation/LinearProblemMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ LinearProblemMatrix::LinearProblemMatrix(PROBLEME_HEBDO* problemeHebdo,
minMaxHydroPowerGroup_(problemeHebdo, builder),
maxPumpingGroup_(problemeHebdo, builder),
areaHydroLevelGroup_(problemeHebdo, builder),
finalStockGroup_(problemeHebdo, builder)
finalStockGroup_(problemeHebdo, builder),
reserveParticipationGroup_(problemeHebdo, builder)
{
constraintgroups_ = {&group1_,
&bindingConstraintDayGroup_,
Expand All @@ -49,7 +50,8 @@ LinearProblemMatrix::LinearProblemMatrix(PROBLEME_HEBDO* problemeHebdo,
&minMaxHydroPowerGroup_,
&maxPumpingGroup_,
&areaHydroLevelGroup_,
&finalStockGroup_};
&finalStockGroup_,
&reserveParticipationGroup_};
}

void LinearProblemMatrix::Run()
Expand Down
16 changes: 16 additions & 0 deletions src/solver/optimisation/constraints/ConstraintBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,22 @@ ConstraintBuilder& ConstraintBuilder::DispatchableProduction(unsigned int index,
return *this;
}

ConstraintBuilder& ConstraintBuilder::ClusterReserveUpParticipation(unsigned int index,
double coeff,
int offset,
int delta){
AddVariable(variableManager_.ClusterReserveUpParticipation(index, hourInWeek_, offset, delta), coeff);
return *this;
}

ConstraintBuilder& ConstraintBuilder::ClusterReserveDownParticipation(unsigned int index,
double coeff,
int offset,
int delta){
AddVariable(variableManager_.ClusterReserveDownParticipation(index, hourInWeek_, offset, delta), coeff);
return *this;
}

ConstraintBuilder& ConstraintBuilder::NumberOfDispatchableUnits(unsigned int index, double coeff)
{
AddVariable(variableManager_.NumberOfDispatchableUnits(index, hourInWeek_), coeff);
Expand Down
40 changes: 40 additions & 0 deletions src/solver/optimisation/constraints/PMaxReserve.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include "antares/solver/optimisation/constraints/PMaxReserve.h"

void PMaxReserve::add(int pays, int reserve, int cluster, int pdt, bool isUpReserve)
{
if (!data.Simulation)
{
// 16 bis
// constraint : P - M * B <= 0

CAPACITY_RESERVATION capacityReservation
= isUpReserve
? data.areaReserves.thermalAreaReserves[pays].areaCapacityReservationsUp[reserve]
: data.areaReserves.thermalAreaReserves[pays].areaCapacityReservationsDown[reserve];

RESERVE_PARTICIPATION reserveParticipation
= capacityReservation.AllReservesParticipation[cluster];

builder.updateHourWithinWeek(pdt)
.DispatchableProduction(cluster, 1.0)
.NumberOfDispatchableUnits(cluster, -reserveParticipation.maxPower)
.lessThan();

if (builder.NumberOfVariables() > 0)
{
ConstraintNamer namer(builder.data.NomDesContraintes);
const int hourInTheYear = builder.data.weekInTheYear * 168 + pdt;
namer.UpdateTimeStep(hourInTheYear);
namer.UpdateArea(builder.data.NomsDesPays[pays]);
namer.PMaxReserve(builder.data.nombreDeContraintes,
reserveParticipation.clusterName,
capacityReservation.reserveName);
}
builder.build();
}
else
{
builder.data.NbTermesContraintesPourLesReserves += 1;
builder.data.nombreDeContraintes++;
}
}
80 changes: 80 additions & 0 deletions src/solver/optimisation/constraints/ReserveParticipationGroup.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
** Copyright 2007-2024, RTE (https://www.rte-france.com)
** See AUTHORS.txt
** SPDX-License-Identifier: MPL-2.0
** This file is part of Antares-Simulator,
** Adequacy and Performance assessment for interconnected energy networks.
**
** Antares_Simulator is free software: you can redistribute it and/or modify
** it under the terms of the Mozilla Public Licence 2.0 as published by
** the Mozilla Foundation, either version 2 of the License, or
** (at your option) any later version.
**
** Antares_Simulator is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** Mozilla Public Licence 2.0 for more details.
**
** You should have received a copy of the Mozilla Public Licence 2.0
** along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>.
*/

#include "antares/solver/optimisation/constraints/ReserveParticipationGroup.h"

PMaxReserveData ReserveParticipationGroup::GetPMaxReserveDataFromProblemHebdo()
{
return {.Simulation = simulation_, .areaReserves = problemeHebdo_->allReserves};
}

/**
* @brief build MinDownTime constraints with
* respect to default order
*/
void ReserveParticipationGroup::BuildConstraints()
{
auto data = GetPMaxReserveDataFromProblemHebdo();
PMaxReserve pMaxReserve(builder_, data);

for (int pdt = 0; pdt < problemeHebdo_->NombreDePasDeTempsPourUneOptimisation; pdt++)
{
// Adding constraints for ReservesUp and ReservesDown
for (uint32_t pays = 0; pays < problemeHebdo_->NombreDePays; pays++)
{
auto areaReservesUp
= data.areaReserves.thermalAreaReserves[pays].areaCapacityReservationsUp;
uint32_t reserve = 0;
for (const auto& areaReserveUp : areaReservesUp)
{
uint32_t cluster = 0;
for (const auto& clusterReserveParticipation :
areaReserveUp.AllReservesParticipation)
{
if (clusterReserveParticipation.maxPower >= 0)
{
pMaxReserve.add(pays, reserve, cluster, pdt, true);
}
cluster++;
}
reserve++;
}

auto areaReservesDown
= data.areaReserves.thermalAreaReserves[pays].areaCapacityReservationsDown;
reserve = 0;
for (const auto& areaReserveDown : areaReservesDown)
{
uint32_t cluster = 0;
for (const auto& clusterReserveParticipation :
areaReserveDown.AllReservesParticipation)
{
if (clusterReserveParticipation.maxPower >= 0)
{
pMaxReserve.add(pays, reserve, cluster, pdt, false);
}
cluster++;
}
reserve++;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ ConstraintBuilderData NewGetConstraintBuilderFromProblemHebdoAndProblemAResoudre
problemeHebdo->NomsDesPays,
problemeHebdo->weekInTheYear,
problemeHebdo->NombreDePasDeTemps,
problemeHebdo->NbTermesContraintesPourLesCoutsDeDemarrage};
problemeHebdo->NbTermesContraintesPourLesCoutsDeDemarrage,
problemeHebdo->NbTermesContraintesPourLesReserves};
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "constraints/MaxPumpingGroup.h"
#include "constraints/AreaHydroLevelGroup.h"
#include "constraints/FinalStockGroup.h"
#include "constraints/ReserveParticipationGroup.h"

#include <antares/study/study.h>

Expand All @@ -54,4 +55,6 @@ class LinearProblemMatrix : public ProblemMatrixEssential
MaxPumpingGroup maxPumpingGroup_;
AreaHydroLevelGroup areaHydroLevelGroup_;
FinalStockGroup finalStockGroup_;
ReserveParticipationGroup reserveParticipationGroup_;

};
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class ConstraintBuilderData
const uint32_t& weekInTheYear;
const uint32_t& NombreDePasDeTemps;
uint32_t& NbTermesContraintesPourLesCoutsDeDemarrage;
uint32_t& NbTermesContraintesPourLesReserves;
};

/*! \verbatim
Expand Down Expand Up @@ -100,6 +101,16 @@ class ConstraintBuilder
int offset = 0,
int delta = 0);

ConstraintBuilder& ClusterReserveUpParticipation(unsigned int index,
double coeff,
int offset = 0,
int delta = 0);

ConstraintBuilder& ClusterReserveDownParticipation(unsigned int index,
double coeff,
int offset = 0,
int delta = 0);

ConstraintBuilder& NumberOfDispatchableUnits(unsigned int index, double coeff);

ConstraintBuilder& NumberStoppingDispatchableUnits(unsigned int index, double coeff);
Expand Down Expand Up @@ -279,4 +290,10 @@ struct StartUpCostsData
{
const std::vector<PALIERS_THERMIQUES>& PaliersThermiquesDuPays;
bool Simulation;
};

struct ReserveParticipationData
{
bool Simulation;
ALL_AREA_RESERVES& areaReserves;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#pragma once
#include "ConstraintBuilder.h"

struct PMaxReserveData
{
bool Simulation;
ALL_AREA_RESERVES& areaReserves;
};

/*!
* represent 'ReserveParticipation' Constraint type
*/
class PMaxReserve : private ConstraintFactory
{
public:
PMaxReserve(ConstraintBuilder& builder, PMaxReserveData& data) :
ConstraintFactory(builder), data(data)
{
}

/*!
* @brief Add variables to the constraint and update constraints Matrix
* @param pays : area
* @param reserve : capacity reservation
* @param isUpReserve : true if ReserveUp, false if ReserveDown
* @param cluster : global index of the cluster
* @param pdt : timestep
*/
void add(int pays, int reserve, int cluster, int pdt, bool isUpReserve);

private:
PMaxReserveData& data;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2007-2024, RTE (https://www.rte-france.com)
* See AUTHORS.txt
* SPDX-License-Identifier: MPL-2.0
* This file is part of Antares-Simulator,
* Adequacy and Performance assessment for interconnected energy networks.
*
* Antares_Simulator is free software: you can redistribute it and/or modify
* it under the terms of the Mozilla Public Licence 2.0 as published by
* the Mozilla Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* Antares_Simulator is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Mozilla Public Licence 2.0 for more details.
*
* You should have received a copy of the Mozilla Public Licence 2.0
* along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>.
*/

#pragma once
#include "ConstraintGroup.h"
#include "PMaxReserve.h"

/**
* @brief Group of MinDownTime constraints
*
*/

class ReserveParticipationGroup : public ConstraintGroup
{
public:
using ConstraintGroup::ConstraintGroup;

void BuildConstraints() override;

private:
bool simulation_ = false;
PMaxReserveData GetPMaxReserveDataFromProblemHebdo();
};
Loading

0 comments on commit 28208e6

Please sign in to comment.