Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NetPosition hourly variables & constraints [ANT-2592] #2551

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/solver/optimisation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ set(RTESOLVER_OPT
include/antares/solver/optimisation/constraints/constraint_builder_utils.h
include/antares/solver/optimisation/constraints/AreaBalance.h
constraints/AreaBalance.cpp
include/antares/solver/optimisation/constraints/NetPosition.h
constraints/NetPosition.cpp
include/antares/solver/optimisation/constraints/FictitiousLoad.h
constraints/FictitiousLoad.cpp
include/antares/solver/optimisation/constraints/ShortTermStorageLevel.h
Expand Down
17 changes: 2 additions & 15 deletions src/solver/optimisation/constraints/AreaBalance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,9 @@ void AreaBalance::add(int pdt, int pays)

builder.updateHourWithinWeek(pdt);

int interco = data.IndexDebutIntercoOrigine[pays];
while (interco >= 0)
{
builder.NTCDirect(interco, 1.0);
interco = data.IndexSuivantIntercoOrigine[interco];
}

interco = data.IndexDebutIntercoExtremite[pays];
while (interco >= 0)
{
builder.NTCDirect(interco, -1.0);
interco = data.IndexSuivantIntercoExtremite[interco];
}

ExportPaliers(data.PaliersThermiquesDuPays[pays], builder);
builder.HydProd(pays, -1.0)
builder.NetPosition(pays, 1)
.HydProd(pays, -1.0)
.Pumping(pays, 1.0)
.PositiveUnsuppliedEnergy(pays, -1.0)
.NegativeUnsuppliedEnergy(pays, 1.0);
Expand Down
6 changes: 6 additions & 0 deletions src/solver/optimisation/constraints/ConstraintBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ ConstraintBuilder& ConstraintBuilder::DispatchableProduction(unsigned int index,
return *this;
}

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

ConstraintBuilder& ConstraintBuilder::NumberOfDispatchableUnits(unsigned int index, double coeff)
{
AddVariable(variableManager_.NumberOfDispatchableUnits(index, hourInWeek_), coeff);
Expand Down
13 changes: 13 additions & 0 deletions src/solver/optimisation/constraints/Group1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ AreaBalanceData Group1::GetAreaBalanceData()
.ShortTermStorage = problemeHebdo_->ShortTermStorage};
}

NetPositionData Group1::GetNetPositionData()
{
return {.CorrespondanceCntNativesCntOptim = problemeHebdo_->CorrespondanceCntNativesCntOptim,
.IndexDebutIntercoOrigine = problemeHebdo_->IndexDebutIntercoOrigine,
.IndexSuivantIntercoOrigine = problemeHebdo_->IndexSuivantIntercoOrigine,
.IndexDebutIntercoExtremite = problemeHebdo_->IndexDebutIntercoExtremite,
.IndexSuivantIntercoExtremite = problemeHebdo_->IndexSuivantIntercoExtremite};
}

FictitiousLoadData Group1::GetFictitiousLoadData()
{
return {.CorrespondanceCntNativesCntOptim = problemeHebdo_->CorrespondanceCntNativesCntOptim,
Expand Down Expand Up @@ -79,6 +88,9 @@ void Group1::BuildConstraints()
auto areaBalanceData = GetAreaBalanceData();
AreaBalance areaBalance(builder_, areaBalanceData);

auto netPositionData = GetNetPositionData();
NetPosition netPosition(builder_, netPositionData);

auto fictitiousLoadData = GetFictitiousLoadData();
FictitiousLoad fictitiousLoad(builder_, fictitiousLoadData);

Expand Down Expand Up @@ -116,6 +128,7 @@ void Group1::BuildConstraints()
for (uint32_t pays = 0; pays < problemeHebdo_->NombreDePays; pays++)
{
areaBalance.add(pdt, pays);
netPosition.add(pdt, pays);
fictitiousLoad.add(pdt, pays);
shortTermStorageLevel.add(pdt, pays);
shortTermStorageCostVariationInjectionBackward.add(pdt, pays);
Expand Down
47 changes: 47 additions & 0 deletions src/solver/optimisation/constraints/NetPosition.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
** 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/NetPosition.h"

void NetPosition::add(int pdt, int pays)
{
int interco = data.IndexDebutIntercoOrigine[pays];
while (interco >= 0)
{
builder.NTCDirect(interco, 1.0);
interco = data.IndexSuivantIntercoOrigine[interco];
}

interco = data.IndexDebutIntercoExtremite[pays];
while (interco >= 0)
{
builder.NTCDirect(interco, -1.0);
interco = data.IndexSuivantIntercoExtremite[interco];
}

ConstraintNamer namer(builder.data.NomDesContraintes);
namer.UpdateTimeStep(builder.data.weekInTheYear * 168 + pdt);
namer.UpdateArea(builder.data.NomsDesPays[pays]);
namer.NetPosition(builder.data.nombreDeContraintes);

builder.NetPosition(pays, -1.0);
builder.equalTo().build();
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ class ConstraintBuilder
int offset = 0,
int delta = 0);

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

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

ConstraintBuilder& HydProdDown(unsigned int index, double coeff);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "ConstraintGroup.h"
#include "FictitiousLoad.h"
#include "FlowDissociation.h"
#include "NetPosition.h"
#include "ShortTermStorageLevel.h"

class Group1: public ConstraintGroup
Expand All @@ -36,6 +37,7 @@ class Group1: public ConstraintGroup

private:
AreaBalanceData GetAreaBalanceData();
NetPositionData GetNetPositionData();
FictitiousLoadData GetFictitiousLoadData();
ShortTermStorageData GetShortTermStorageData();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
** 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 "ConstraintBuilder.h"

struct NetPositionData
{
std::vector<CORRESPONDANCES_DES_CONTRAINTES>& CorrespondanceCntNativesCntOptim;
const std::vector<int>& IndexDebutIntercoOrigine;
const std::vector<int>& IndexSuivantIntercoOrigine;
const std::vector<int>& IndexDebutIntercoExtremite;
const std::vector<int>& IndexSuivantIntercoExtremite;
};

/*!
* represent 'Net Position' constraint type
*/

class NetPosition: public ConstraintFactory
{
public:
NetPosition(ConstraintBuilder& builder, NetPositionData& data):
ConstraintFactory(builder),
data(data)
{
}

/*!
* @brief Add variables to the constraint and update constraints Matrix
* @param pdt : timestep
* @param pays : area
*/

void add(int pdt, int pays);

private:
NetPositionData& data;
};
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class VariableNamer: public Namer
void PositiveUnsuppliedEnergy(unsigned int variable);
void NegativeUnsuppliedEnergy(unsigned int variable);
void AreaBalance(unsigned int variable);
void NetPosition(unsigned int variable);

private:
void SetAreaVariableName(unsigned int variable,
Expand All @@ -133,6 +134,7 @@ class ConstraintNamer: public Namer
const std::string& origin,
const std::string& destination);

void NetPosition(unsigned int variable);
void AreaBalance(unsigned int constraint);
void FictiveLoads(unsigned int constraint);
void HydroPower(unsigned int constraint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ void OPT_ConstruireLaListeDesVariablesOptimiseesDuProblemeLineaire(PROBLEME_HEBD
NombreDeVariables++;
}

// NetPosition
ProblemeAResoudre->TypeDeVariable[NombreDeVariables] = VARIABLE_NON_BORNEE;
variableManager.NetPosition(pays, pdt) = NombreDeVariables;
variableNamer.NetPosition(NombreDeVariables);
NombreDeVariables++;

for (const auto& storage: problemeHebdo->ShortTermStorage[pays])
{
const int clusterGlobalIndex = storage.clusterGlobalIndex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,13 @@ int OPT_DecompteDesVariablesEtDesContraintesDuProblemeAOptimiser(PROBLEME_HEBDO*
}
}

// NetPosition
for (uint32_t pays = 0; pays < problemeHebdo->NombreDePays; pays++)
{
ProblemeAResoudre->NombreDeVariables += nombreDePasDeTempsPourUneOptimisation;
ProblemeAResoudre->NombreDeContraintes += nombreDePasDeTempsPourUneOptimisation;
}

if (problemeHebdo->OptimisationAvecCoutsDeDemarrage)
{
OPT_DecompteDesVariablesEtDesContraintesCoutsDeDemarrage(problemeHebdo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,14 @@ void OPT_InitialiserLesBornesDesVariablesDuProblemeLineaire(PROBLEME_HEBDO* prob
AdresseOuPlacerLaValeurDesVariablesOptimisees[var] = adresseDuResultat;
}
}
for (uint32_t pays = 0; pays < problemeHebdo->NombreDePays; pays++)
{
int var = problemeHebdo->CorrespondanceVarNativesVarOptim[pdtHebdo]
.NumeroDeVariableNetPosition[pays];
double* adresseDuResultat = &(
problemeHebdo->ResultatsHoraires[pays].NetPositionHoraire[pdtHebdo]);
AdresseOuPlacerLaValeurDesVariablesOptimisees[var] = adresseDuResultat;
}
}

setBoundsForUnsuppliedEnergy(problemeHebdo,
Expand Down
10 changes: 10 additions & 0 deletions src/solver/optimisation/opt_rename_problem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ void VariableNamer::ShortTermStorageCostVariationWithdrawal(unsigned int variabl
SetShortTermStorageVariableName(variable, "CostVariationWithdrawal", shortTermStorageName);
}

void VariableNamer::NetPosition(unsigned int constraint)
{
SetAreaElementNameHour(constraint, "NetPositionVariable");
}

void VariableNamer::HydProd(unsigned int variable)
{
SetAreaElementNameHour(variable, "HydProd");
Expand Down Expand Up @@ -275,6 +280,11 @@ void ConstraintNamer::AreaBalance(unsigned int constraint)
SetAreaElementNameHour(constraint, "AreaBalance");
}

void ConstraintNamer::NetPosition(unsigned int constraint)
{
SetAreaElementNameHour(constraint, "NetPositionConstraint");
}

void ConstraintNamer::FictiveLoads(unsigned int constraint)
{
SetAreaElementNameHour(constraint, "FictiveLoads");
Expand Down
9 changes: 9 additions & 0 deletions src/solver/optimisation/variables/VariableManagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,15 @@ int& VariableManager::ShortTermStorageCostVariationWithdrawal(unsigned int index
.SIM_ShortTermStorage.CostVariationWithdrawal[index];
}

int& VariableManager::NetPosition(unsigned int index,
unsigned int hourInWeek,
int offset,
int delta)
{
auto pdt = GetShiftedTimeStep(offset, delta, hourInWeek);
return CorrespondanceVarNativesVarOptim_[pdt].NumeroDeVariableNetPosition[index];
}

int& VariableManager::HydProd(unsigned int index, unsigned int hourInWeek, int offset, int delta)
{
auto pdt = GetShiftedTimeStep(offset, delta, hourInWeek);
Expand Down
2 changes: 2 additions & 0 deletions src/solver/optimisation/variables/VariableManagement.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ class VariableManager
int offset = 0,
int delta = 0);

int& NetPosition(unsigned int index, unsigned int hourInWeek, int offset = 0, int delta = 0);

int& HydProd(unsigned int index, unsigned int hourInWeek, int offset = 0, int delta = 0);

int& HydProdDown(unsigned int index, unsigned int hourInWeek, int offset = 0, int delta = 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ struct CORRESPONDANCES_DES_VARIABLES

std::vector<int> NumeroDeVariableDuPalierThermique;

std::vector<int> NumeroDeVariableNetPosition;
std::vector<int> NumeroDeVariablesDeLaProdHyd;

std::vector<int> NumeroDeVariablesDePompage;
Expand Down Expand Up @@ -438,6 +439,8 @@ struct RESULTATS_HORAIRES
std::vector<double> CoutsMarginauxHoraires;
std::vector<PRODUCTION_THERMIQUE_OPTIMALE> ProductionThermique; // index is pdtHebdo

std::vector<double> NetPositionHoraire;

std::vector<::ShortTermStorage::RESULTS> ShortTermStorage;
};

Expand Down
4 changes: 4 additions & 0 deletions src/solver/simulation/sim_alloc_probleme_hebdo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ void SIM_AllocationProblemePasDeTemps(PROBLEME_HEBDO& problem,

variablesMapping.NumeroDeVariableDuPalierThermique
.assign(study.runtime.thermalPlantTotalCount, 0);
variablesMapping.NumeroDeVariableNetPosition.assign(nbPays, 0);
variablesMapping.NumeroDeVariablesDeLaProdHyd.assign(nbPays, 0);
variablesMapping.NumeroDeVariablesDePompage.assign(nbPays, 0);
variablesMapping.NumeroDeVariablesDeNiveau.assign(nbPays, 0);
Expand Down Expand Up @@ -397,6 +398,9 @@ void SIM_AllocateAreas(PROBLEME_HEBDO& problem,

problem.ResultatsHoraires[k].TurbinageHoraire.assign(NombreDePasDeTemps, 0.);
problem.ResultatsHoraires[k].PompageHoraire.assign(NombreDePasDeTemps, 0.);

problem.ResultatsHoraires[k].NetPositionHoraire.assign(NombreDePasDeTemps, 0.);

problem.ResultatsHoraires[k].CoutsMarginauxHoraires.assign(NombreDePasDeTemps, 0.);
problem.ResultatsHoraires[k].niveauxHoraires.assign(NombreDePasDeTemps, 0.);
problem.ResultatsHoraires[k].valeurH2oHoraire.assign(NombreDePasDeTemps, 0.);
Expand Down
Loading