From 6ab2a54ea618817a0255a6013abbe91c467e5383 Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Tue, 12 Sep 2023 13:10:29 +0200 Subject: [PATCH] problemHebdo removed from contraintBuilder --- src/solver/optimisation/AreaBalance.cpp | 29 +++--- src/solver/optimisation/AreaBalance.h | 20 +++- .../optimisation/BindingConstraintHour.h | 3 +- src/solver/optimisation/FictitiousLoad.cpp | 20 ++-- src/solver/optimisation/FictitiousLoad.h | 9 +- .../optimisation/ShortTermStorageLevel.cpp | 21 ++-- .../optimisation/ShortTermStorageLevel.h | 9 +- .../csr_quadratic_problem.cpp | 53 ++++++---- .../optimisation/constraint_builder.cpp | 50 +++++----- src/solver/optimisation/constraint_builder.h | 88 ++++++++++++----- ...nstruction_contraintes_couts_demarrage.cpp | 14 +-- ...n_matrice_des_contraintes_cas_lineaire.cpp | 96 +++++++++++-------- ...atrice_des_contraintes_cas_quadratique.cpp | 36 +++++-- src/solver/optimisation/opt_fonctions.h | 1 + .../simulation/adequacy_patch_runtime_data.h | 3 +- 15 files changed, 273 insertions(+), 179 deletions(-) diff --git a/src/solver/optimisation/AreaBalance.cpp b/src/solver/optimisation/AreaBalance.cpp index 94cce06921..80382ecf62 100644 --- a/src/solver/optimisation/AreaBalance.cpp +++ b/src/solver/optimisation/AreaBalance.cpp @@ -20,49 +20,44 @@ static void shortTermStorageBalance(const ::ShortTermStorage::AREA_INPUT& shortT } // Constraint definitions -void AreaBalance::add(int pdt, - int pays, - std::vector& NumeroDeContrainteDesBilansPays, - std::vector& InjectionVariable, - std::vector& WithdrawalVariable) +void AreaBalance::add(int pdt, int pays, AreaBalanceData& data) { /** can be done without this --- keep it for now**/ - NumeroDeContrainteDesBilansPays[pays] = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; + data.NumeroDeContrainteDesBilansPays[pays] = builder.data.nombreDeContraintes; /******/ // TODO improve this { - ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, - problemeHebdo->NamedProblems); - namer.UpdateTimeStep(problemeHebdo->weekInTheYear * 168 + pdt); - namer.UpdateArea(problemeHebdo->NomsDesPays[pays]); - namer.AreaBalance(problemeHebdo->ProblemeAResoudre->NombreDeContraintes); + ConstraintNamer namer(builder.data.NomDesContraintes, builder.data.NamedProblems); + namer.UpdateTimeStep(builder.data.weekInTheYear * 168 + pdt); + namer.UpdateArea(builder.data.NomsDesPays[pays]); + namer.AreaBalance(builder.data.nombreDeContraintes); } builder.updateHourWithinWeek(pdt); - int interco = problemeHebdo->IndexDebutIntercoOrigine[pays]; + int interco = data.IndexDebutIntercoOrigine[pays]; while (interco >= 0) { builder.include(Variable::NTCDirect(interco), 1.0); - interco = problemeHebdo->IndexSuivantIntercoOrigine[interco]; + interco = data.IndexSuivantIntercoOrigine[interco]; } - interco = problemeHebdo->IndexDebutIntercoExtremite[pays]; + interco = data.IndexDebutIntercoExtremite[pays]; while (interco >= 0) { builder.include(Variable::NTCDirect(interco), -1.0); - interco = problemeHebdo->IndexSuivantIntercoExtremite[interco]; + interco = data.IndexSuivantIntercoExtremite[interco]; } - exportPaliers(*problemeHebdo, builder, pays); + exportPaliers(data.PaliersThermiquesDuPays, builder); builder.include(Variable::HydProd(pays), -1.0) .include(Variable::Pumping(pays), 1.0) .include(Variable::PositiveUnsuppliedEnergy(pays), -1.0) .include(Variable::NegativeUnsuppliedEnergy(pays), 1.0); shortTermStorageBalance( - problemeHebdo->ShortTermStorage[pays], builder, InjectionVariable, WithdrawalVariable); + data.ShortTermStorage[pays], builder, data.InjectionVariable, data.WithdrawalVariable); builder.equalTo(); builder.build(); diff --git a/src/solver/optimisation/AreaBalance.h b/src/solver/optimisation/AreaBalance.h index 618ba0bbbe..16c79d8156 100644 --- a/src/solver/optimisation/AreaBalance.h +++ b/src/solver/optimisation/AreaBalance.h @@ -1,14 +1,24 @@ #pragma once #include "constraint_builder.h" +struct AreaBalanceData +{ + std::vector& NumeroDeContrainteDesBilansPays; + std::vector& InjectionVariable; + std::vector& WithdrawalVariable; + + const std::vector& IndexDebutIntercoOrigine; + const std::vector& IndexSuivantIntercoOrigine; + const std::vector& IndexDebutIntercoExtremite; + const std::vector& IndexSuivantIntercoExtremite; + const PALIERS_THERMIQUES& PaliersThermiquesDuPays; + const std::vector<::ShortTermStorage::AREA_INPUT>& ShortTermStorage; +}; + class AreaBalance : private Constraint { public: using Constraint::Constraint; - void add(int pdt, - int pays, - std::vector& NumeroDeContrainteDesBilansPays, - std::vector& InjectionVariable, - std::vector& WithdrawalVariable); + void add(int pdt, int pays, AreaBalanceData& data); }; \ No newline at end of file diff --git a/src/solver/optimisation/BindingConstraintHour.h b/src/solver/optimisation/BindingConstraintHour.h index 51cc8bbd5c..68cf6258d1 100644 --- a/src/solver/optimisation/BindingConstraintHour.h +++ b/src/solver/optimisation/BindingConstraintHour.h @@ -1,9 +1,10 @@ #pragma once #include "constraint_builder.h" + struct BindingConstraintHourData : public BindingConstraintData { std::vector& NumeroDeContrainteDesContraintesCouplantes; -} +}; class BindingConstraintHour : private Constraint { diff --git a/src/solver/optimisation/FictitiousLoad.cpp b/src/solver/optimisation/FictitiousLoad.cpp index 25c2ecee8c..01a2647804 100644 --- a/src/solver/optimisation/FictitiousLoad.cpp +++ b/src/solver/optimisation/FictitiousLoad.cpp @@ -1,29 +1,25 @@ #include "FictitiousLoad.h" -void FictitiousLoad::add(int pdt, - int pays, - std::vector& NumeroDeContraintePourEviterLesChargesFictives) +void FictitiousLoad::add(int pdt, int pays, FictitiousLoadData& data) { /** can be done without this --- keep it for now**/ - NumeroDeContraintePourEviterLesChargesFictives[pays] - = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; + data.NumeroDeContraintePourEviterLesChargesFictives[pays] = builder.data.nombreDeContraintes; /******/ // TODO improve this { - ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, - problemeHebdo->NamedProblems); + ConstraintNamer namer(builder.data.NomDesContraintes, builder.data.NamedProblems); - namer.UpdateTimeStep(problemeHebdo->weekInTheYear * 168 + pdt); - namer.UpdateArea(problemeHebdo->NomsDesPays[pays]); - namer.FictiveLoads(problemeHebdo->ProblemeAResoudre->NombreDeContraintes); + namer.UpdateTimeStep(builder.data.weekInTheYear * 168 + pdt); + namer.UpdateArea(builder.data.NomsDesPays[pays]); + namer.FictiveLoads(builder.data.nombreDeContraintes); } builder.updateHourWithinWeek(pdt); - exportPaliers(*problemeHebdo, builder, pays); - auto coeff = problemeHebdo->DefaillanceNegativeUtiliserHydro[pays] ? -1 : 0; + exportPaliers(data.PaliersThermiquesDuPays, builder); + auto coeff = data.DefaillanceNegativeUtiliserHydro[pays] ? -1 : 0; builder.include(Variable::HydProd(pays), coeff) .include(Variable::NegativeUnsuppliedEnergy(pays), 1.0); diff --git a/src/solver/optimisation/FictitiousLoad.h b/src/solver/optimisation/FictitiousLoad.h index f981e1755c..a62812cecd 100644 --- a/src/solver/optimisation/FictitiousLoad.h +++ b/src/solver/optimisation/FictitiousLoad.h @@ -1,10 +1,15 @@ #pragma once #include "constraint_builder.h" - +struct FictitiousLoadData +{ + std::vector& NumeroDeContraintePourEviterLesChargesFictives; + const PALIERS_THERMIQUES& PaliersThermiquesDuPays; + const std::vector& DefaillanceNegativeUtiliserHydro; +}; class FictitiousLoad : private Constraint { public: using Constraint::Constraint; - void add(int pdt, int pays, std::vector& NumeroDeContraintePourEviterLesChargesFictives); + void add(int pdt, int pays, FictitiousLoadData& data); }; diff --git a/src/solver/optimisation/ShortTermStorageLevel.cpp b/src/solver/optimisation/ShortTermStorageLevel.cpp index 442640f376..ededb07ff7 100644 --- a/src/solver/optimisation/ShortTermStorageLevel.cpp +++ b/src/solver/optimisation/ShortTermStorageLevel.cpp @@ -1,32 +1,27 @@ #include "ShortTermStorageLevel.h" -void ShortTermStorageLevel::add(int pdt, - int pays, - std::vector& ShortTermStorageLevelConstraint) +void ShortTermStorageLevel::add(int pdt, int pays, ShortTermStorageLevelData& data) { // TODO improve this - ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, - problemeHebdo->NamedProblems); - const int hourInTheYear = problemeHebdo->weekInTheYear * 168 + pdt; + ConstraintNamer namer(builder.data.NomDesContraintes, builder.data.NamedProblems); + const int hourInTheYear = builder.data.weekInTheYear * 168 + pdt; namer.UpdateTimeStep(hourInTheYear); - namer.UpdateArea(problemeHebdo->NomsDesPays[pays]); + namer.UpdateArea(builder.data.NomsDesPays[pays]); builder.updateHourWithinWeek(pdt); - for (const auto& storage : problemeHebdo->ShortTermStorage[pays]) + for (const auto& storage : data.ShortTermStorage[pays]) { // L[h] - L[h-1] - efficiency * injection[h] + withdrawal[h] = inflows[h] - namer.ShortTermStorageLevel(problemeHebdo->ProblemeAResoudre->NombreDeContraintes, - storage.name); + namer.ShortTermStorageLevel(builder.data.nombreDeContraintes, storage.name); const auto index = storage.clusterGlobalIndex; - ShortTermStorageLevelConstraint[index] - = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; + data.ShortTermStorageLevelConstraint[index] = builder.data.nombreDeContraintes; builder.include(Variable::ShortTermStorageLevel(index), 1.0) .include(Variable::ShortTermStorageLevel(index), -1.0, -1, true, - problemeHebdo->NombreDePasDeTempsPourUneOptimisation) + builder.data.NombreDePasDeTempsPourUneOptimisation) .include(Variable::ShortTermStorageInjection(index), -1.0 * storage.efficiency) .include(Variable::ShortTermStorageWithdrawal(index), 1.0) .equalTo() diff --git a/src/solver/optimisation/ShortTermStorageLevel.h b/src/solver/optimisation/ShortTermStorageLevel.h index 0d910674cb..a44ddc15b2 100644 --- a/src/solver/optimisation/ShortTermStorageLevel.h +++ b/src/solver/optimisation/ShortTermStorageLevel.h @@ -1,10 +1,15 @@ #pragma once #include "constraint_builder.h" +struct ShortTermStorageLevelData +{ + std::vector& ShortTermStorageLevelConstraint; + const std::vector<::ShortTermStorage::AREA_INPUT>& ShortTermStorage; +}; + class ShortTermStorageLevel : private Constraint { public: using Constraint::Constraint; - void add(int pdt, int pays, - std::vector & ShortTermStorageLevelConstraint); + void add(int pdt, int pays, ShortTermStorageLevelData& data); }; diff --git a/src/solver/optimisation/adequacy_patch_csr/csr_quadratic_problem.cpp b/src/solver/optimisation/adequacy_patch_csr/csr_quadratic_problem.cpp index 6427811dd8..ca00b6a93f 100644 --- a/src/solver/optimisation/adequacy_patch_csr/csr_quadratic_problem.cpp +++ b/src/solver/optimisation/adequacy_patch_csr/csr_quadratic_problem.cpp @@ -35,60 +35,77 @@ #include "sim_structure_probleme_economique.h" #include "../constraint_builder.h" #include "../opt_rename_problem.h" +#include "adequacy_patch_runtime_data.h" + using namespace Antares::Data; namespace Antares::Solver::Optimization { +struct CsrFlowDissociationData +{ + std::map& numberOfConstraintCsrFlowDissociation; + const int NombreDInterconnexions; + + const std::vector& originAreaMode; + const std::vector& extremityAreaMode; + const std::vector& PaysOrigineDeLInterconnexion; + const std::vector& PaysExtremiteDeLInterconnexion; +}; class CsrFlowDissociation : private Constraint { public: using Constraint::Constraint; - void add(int hour, std::map& numberOfConstraintCsrFlowDissociation) + void add(int hour, CsrFlowDissociationData& data) { builder.updateHourWithinWeek(hour); - const CORRESPONDANCES_DES_VARIABLES& CorrespondanceVarNativesVarOptim - = problemeHebdo->CorrespondanceVarNativesVarOptim[hour]; - ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, - problemeHebdo->NamedProblems); + ConstraintNamer namer(builder.data.NomDesContraintes, builder.data.NamedProblems); namer.UpdateTimeStep(hour); // constraint: Flow = Flow_direct - Flow_indirect (+ loop flow) for links between nodes // of type 2. - for (uint32_t interco = 0; interco < problemeHebdo->NombreDInterconnexions; interco++) + for (uint32_t interco = 0; interco < data.NombreDInterconnexions; interco++) { - if (problemeHebdo->adequacyPatchRuntimeData->originAreaMode[interco] + if (data.originAreaMode[interco] == Antares::Data::AdequacyPatch::physicalAreaInsideAdqPatch - && problemeHebdo->adequacyPatchRuntimeData->extremityAreaMode[interco] + && data.extremityAreaMode[interco] == Antares::Data::AdequacyPatch::physicalAreaInsideAdqPatch) { builder.include(Variable::NTCDirect(interco), 1.0) .include(Variable::IntercoDirectCost(interco), -1.0) .include(Variable::IntercoIndirectCost(interco), 1.0); - numberOfConstraintCsrFlowDissociation[interco] - = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; + data.numberOfConstraintCsrFlowDissociation[interco] + = builder.data.nombreDeContraintes; const auto& origin - = problemeHebdo - ->NomsDesPays[problemeHebdo->PaysOrigineDeLInterconnexion[interco]]; + = builder.data.NomsDesPays[data.PaysOrigineDeLInterconnexion[interco]]; const auto& destination - = problemeHebdo - ->NomsDesPays[problemeHebdo->PaysExtremiteDeLInterconnexion[interco]]; - namer.CsrFlowDissociation( - problemeHebdo->ProblemeAResoudre->NombreDeContraintes, origin, destination); + = builder.data.NomsDesPays[data.PaysExtremiteDeLInterconnexion[interco]]; + namer.CsrFlowDissociation(builder.data.nombreDeContraintes, origin, destination); builder.build(); } } } }; + void CsrQuadraticProblem::setConstraintsOnFlows(std::vector& Pi, std::vector& Colonne) { int hour = hourlyCsrProblem_.triggeredHour; //!\ TODO not associated problemHebdo && probleamAressoudre - CsrFlowDissociation csrFlowDissociation(problemeHebdo_); - csrFlowDissociation.add(hour, hourlyCsrProblem_.numberOfConstraintCsrFlowDissociation); + auto builder = GetConstraintBuilderFromProblemHebdoAndProblemAResoudre(problemeHebdo_, + &problemeAResoudre_); + CsrFlowDissociation csrFlowDissociation(builder); + CsrFlowDissociationData csrFlowDissociationData + = {hourlyCsrProblem_.numberOfConstraintCsrFlowDissociation, + problemeHebdo_->NombreDInterconnexions, + problemeHebdo_->adequacyPatchRuntimeData->originAreaMode, + problemeHebdo_->adequacyPatchRuntimeData->extremityAreaMode, + problemeHebdo_->PaysOrigineDeLInterconnexion, + problemeHebdo_->PaysExtremiteDeLInterconnexion}; + + csrFlowDissociation.add(hour, csrFlowDissociationData); } void CsrQuadraticProblem::setNodeBalanceConstraints(std::vector& Pi, std::vector& Colonne) diff --git a/src/solver/optimisation/constraint_builder.cpp b/src/solver/optimisation/constraint_builder.cpp index 83424087f6..d43437636b 100644 --- a/src/solver/optimisation/constraint_builder.cpp +++ b/src/solver/optimisation/constraint_builder.cpp @@ -2,8 +2,8 @@ void ConstraintBuilder::build() { - std::vector& Pi = problemeAResoudre->Pi; - std::vector& Colonne = problemeAResoudre->Colonne; + std::vector& Pi = data.Pi; + std::vector& Colonne = data.Colonne; // TODO check operator_ if (nombreDeTermes_ > 0) { @@ -19,7 +19,7 @@ int ConstraintBuilder::getVariableIndex(const Variable::Variant& variable, int delta) const { int pdt = hourInWeek_ + shift; - const int nbTimeSteps = problemeHebdo->NombreDePasDeTempsPourUneOptimisation; + const int nbTimeSteps = data.NombreDePasDeTempsPourUneOptimisation; // if (wrap) // { // pdt %= nbTimeSteps; @@ -42,9 +42,9 @@ int ConstraintBuilder::getVariableIndex(const Variable::Variant& variable, pdt = (pdt + delta) % nbTimeSteps; } } - const Variable::Visitor visitor(varNative[pdt], - problemeHebdo->NumeroDeVariableStockFinal, - problemeHebdo->NumeroDeVariableDeTrancheDeStock); + const Variable::Visitor visitor(data.CorrespondanceVarNativesVarOptim[pdt], + data.NumeroDeVariableStockFinal, + data.NumeroDeVariableDeTrancheDeStock); return std::visit(visitor, variable); } @@ -54,8 +54,8 @@ ConstraintBuilder& ConstraintBuilder::include(Variable::Variant var, bool wrap, int delta) { - std::vector& Pi = problemeAResoudre->Pi; - std::vector& Colonne = problemeAResoudre->Colonne; + std::vector& Pi = data.Pi; + std::vector& Colonne = data.Colonne; int varIndex = getVariableIndex(var, shift, wrap, delta); if (varIndex >= 0) { @@ -68,30 +68,26 @@ ConstraintBuilder& ConstraintBuilder::include(Variable::Variant var, void ConstraintBuilder::OPT_ChargerLaContrainteDansLaMatriceDesContraintes() { - int& nombreDeContraintes = problemeAResoudre->NombreDeContraintes; - int& nombreDeTermesDansLaMatriceDeContrainte - = problemeAResoudre->NombreDeTermesDansLaMatriceDesContraintes; - std::vector& Pi = problemeAResoudre->Pi; - std::vector& Colonne = problemeAResoudre->Colonne; + int& nombreDeContraintes = data.nombreDeContraintes; + int& nombreDeTermesDansLaMatriceDeContrainte = data.nombreDeTermesDansLaMatriceDeContrainte; + std::vector& Pi = data.Pi; + std::vector& Colonne = data.Colonne; - problemeAResoudre->IndicesDebutDeLigne[nombreDeContraintes] - = nombreDeTermesDansLaMatriceDeContrainte; + data.IndicesDebutDeLigne[nombreDeContraintes] = nombreDeTermesDansLaMatriceDeContrainte; for (int i = 0; i < nombreDeTermes_; i++) { - problemeAResoudre - ->CoefficientsDeLaMatriceDesContraintes[nombreDeTermesDansLaMatriceDeContrainte] - = Pi[i]; - problemeAResoudre->IndicesColonnes[nombreDeTermesDansLaMatriceDeContrainte] = Colonne[i]; + data.CoefficientsDeLaMatriceDesContraintes[nombreDeTermesDansLaMatriceDeContrainte] = Pi[i]; + data.IndicesColonnes[nombreDeTermesDansLaMatriceDeContrainte] = Colonne[i]; nombreDeTermesDansLaMatriceDeContrainte++; if (nombreDeTermesDansLaMatriceDeContrainte - == problemeAResoudre->NombreDeTermesAllouesDansLaMatriceDesContraintes) + == data.NombreDeTermesAllouesDansLaMatriceDesContraintes) { OPT_AugmenterLaTailleDeLaMatriceDesContraintes(); } } - problemeAResoudre->NombreDeTermesDesLignes[nombreDeContraintes] = nombreDeTermes_; + data.NombreDeTermesDesLignes[nombreDeContraintes] = nombreDeTermes_; - problemeAResoudre->Sens[nombreDeContraintes] = operator_; + data.Sens[nombreDeContraintes] = operator_; nombreDeContraintes++; return; @@ -99,17 +95,17 @@ void ConstraintBuilder::OPT_ChargerLaContrainteDansLaMatriceDesContraintes() void ConstraintBuilder::OPT_AugmenterLaTailleDeLaMatriceDesContraintes() { - int NbTermes = problemeAResoudre->NombreDeTermesAllouesDansLaMatriceDesContraintes; - NbTermes += problemeAResoudre->IncrementDAllocationMatriceDesContraintes; + int NbTermes = data.NombreDeTermesAllouesDansLaMatriceDesContraintes; + NbTermes += data.IncrementDAllocationMatriceDesContraintes; logs.info(); logs.info() << " Expected Number of Non-zero terms in Problem Matrix : increased to : " << NbTermes; logs.info(); - problemeAResoudre->CoefficientsDeLaMatriceDesContraintes.resize(NbTermes); + data.CoefficientsDeLaMatriceDesContraintes.resize(NbTermes); - problemeAResoudre->IndicesColonnes.resize(NbTermes); + data.IndicesColonnes.resize(NbTermes); - problemeAResoudre->NombreDeTermesAllouesDansLaMatriceDesContraintes = NbTermes; + data.NombreDeTermesAllouesDansLaMatriceDesContraintes = NbTermes; } \ No newline at end of file diff --git a/src/solver/optimisation/constraint_builder.h b/src/solver/optimisation/constraint_builder.h index bc0ad22014..6be1dce6df 100644 --- a/src/solver/optimisation/constraint_builder.h +++ b/src/solver/optimisation/constraint_builder.h @@ -242,15 +242,32 @@ class Visitor }; } // namespace Variable +struct ConstraintBuilderData +{ + std::vector& Pi; + std::vector& Colonne; + int& nombreDeContraintes; + int& nombreDeTermesDansLaMatriceDeContrainte; + std::vector& IndicesDebutDeLigne; + std::vector& CoefficientsDeLaMatriceDesContraintes; + std::vector& IndicesColonnes; + int& NombreDeTermesAllouesDansLaMatriceDesContraintes; // TODO Check if ref is needed + std::vector& NombreDeTermesDesLignes; + std::string& Sens; + int& IncrementDAllocationMatriceDesContraintes; + const std::vector& CorrespondanceVarNativesVarOptim; + const int NombreDePasDeTempsPourUneOptimisation; + const std::vector& NumeroDeVariableStockFinal; + const std::vector>& NumeroDeVariableDeTrancheDeStock; + std::vector& NomDesContraintes; + const bool NamedProblems; + const std::vector NomsDesPays; + const uint32_t weekInTheYear; +}; class ConstraintBuilder { public: - ConstraintBuilder( - const PROBLEME_HEBDO* problemeHebdo, - const std::vector& CorrespondanceVarNativesVarOptim) : - problemeHebdo(problemeHebdo), - problemeAResoudre(problemeHebdo->ProblemeAResoudre), - varNative(CorrespondanceVarNativesVarOptim) + ConstraintBuilder(ConstraintBuilderData& data) : data(data) { } @@ -304,18 +321,18 @@ class ConstraintBuilder return nombreDeTermes_; } +public: + ConstraintBuilderData& data; + private: void OPT_ChargerLaContrainteDansLaMatriceDesContraintes(); void OPT_AugmenterLaTailleDeLaMatriceDesContraintes(); - const PROBLEME_HEBDO* problemeHebdo; - PROBLEME_ANTARES_A_RESOUDRE* problemeAResoudre; - const std::vector& varNative; unsigned int hourInWeek_ = 0; char operator_; - double rhs_ = 0; + // double rhs_ = 0; int nombreDeTermes_ = 0; // ConstraintNamer ConstraintNameManager; }; @@ -323,24 +340,17 @@ class ConstraintBuilder class Constraint { public: - explicit Constraint(const PROBLEME_HEBDO* problemeHebdo) : - problemeHebdo(problemeHebdo), - builder(*problemeHebdo, problemeHebdo->CorrespondanceVarNativesVarOptim) + explicit Constraint(ConstraintBuilder& builder) : builder(builder) { } - - const PROBLEME_HEBDO* problemeHebdo; // TODO remove - ConstraintBuilder builder; + ConstraintBuilder& builder; }; // #TODO move this function to a suitable place // Helper functions -inline void exportPaliers(const PROBLEME_HEBDO& problemeHebdo, - ConstraintBuilder& constraintBuilder, - int pays) +inline void exportPaliers(const PALIERS_THERMIQUES& PaliersThermiquesDuPays, + ConstraintBuilder& constraintBuilder) { - const PALIERS_THERMIQUES& PaliersThermiquesDuPays = problemeHebdo.PaliersThermiquesDuPays[pays]; - for (int index = 0; index < PaliersThermiquesDuPays.NombreDePaliersThermiques; index++) { const int palier @@ -363,4 +373,38 @@ struct BindingConstraintData const std::vector& OffsetTemporelSurLePalierDispatch; const char SensDeLaContrainteCouplante; const char* NomDeLaContrainteCouplante; -}; \ No newline at end of file +}; + +inline ConstraintBuilder GetConstraintBuilderFromProblemHebdoAndProblemAResoudre( + const PROBLEME_HEBDO* problemeHebdo, + PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre) +{ + ConstraintBuilderData data{ProblemeAResoudre->Pi, + ProblemeAResoudre->Colonne, + ProblemeAResoudre->NombreDeContraintes, + ProblemeAResoudre->NombreDeTermesDansLaMatriceDesContraintes, + ProblemeAResoudre->IndicesDebutDeLigne, + ProblemeAResoudre->CoefficientsDeLaMatriceDesContraintes, + ProblemeAResoudre->IndicesColonnes, + ProblemeAResoudre->NombreDeTermesAllouesDansLaMatriceDesContraintes, + ProblemeAResoudre->NombreDeTermesDesLignes, + ProblemeAResoudre->Sens, + ProblemeAResoudre->IncrementDAllocationMatriceDesContraintes, + problemeHebdo->CorrespondanceVarNativesVarOptim, + problemeHebdo->NombreDePasDeTempsPourUneOptimisation, + problemeHebdo->NumeroDeVariableStockFinal, + problemeHebdo->NumeroDeVariableDeTrancheDeStock, + ProblemeAResoudre->NomDesContraintes, + problemeHebdo->NamedProblems, + problemeHebdo->NomsDesPays, + problemeHebdo->weekInTheYear}; + + return ConstraintBuilder(data); +} + +inline ConstraintBuilder GetConstraintBuilderFromProblemHebdo(PROBLEME_HEBDO* problemeHebdo) +{ + PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre = problemeHebdo->ProblemeAResoudre.get(); + return GetConstraintBuilderFromProblemHebdoAndProblemAResoudre(problemeHebdo, + ProblemeAResoudre); +} diff --git a/src/solver/optimisation/opt_construction_contraintes_couts_demarrage.cpp b/src/solver/optimisation/opt_construction_contraintes_couts_demarrage.cpp index 9945b8e909..dafafcf8e2 100644 --- a/src/solver/optimisation/opt_construction_contraintes_couts_demarrage.cpp +++ b/src/solver/optimisation/opt_construction_contraintes_couts_demarrage.cpp @@ -46,7 +46,7 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( bool Simulation) { PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre = problemeHebdo->ProblemeAResoudre.get(); - + ConstraintBuilder builder(GetConstraintBuilderFromProblemHebdo(problemeHebdo)); int nombreDePasDeTempsPourUneOptimisation = problemeHebdo->NombreDePasDeTempsPourUneOptimisation; @@ -62,8 +62,8 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( constraintNamer.UpdateArea(problemeHebdo->NomsDesPays[pays]); for (int index = 0; index < PaliersThermiquesDuPays.NombreDePaliersThermiques; index++) { - PMaxDispatchableGeneration pMaxDispatchableGeneration(problemeHebdo); - PMinDispatchableGeneration pMinDispatchableGeneration(problemeHebdo); + PMaxDispatchableGeneration pMaxDispatchableGeneration(builder); + PMinDispatchableGeneration pMinDispatchableGeneration(builder); const int palier = PaliersThermiquesDuPays.NumeroDuPalierDansLEnsembleDesPaliersThermiques[index]; @@ -92,7 +92,7 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) { - ConsistenceNODU consistenceNODU(problemeHebdo); + ConsistenceNODU consistenceNODU(builder); consistenceNODU.add(pays, palier, index, pdt, Simulation); nbTermesContraintesPourLesCoutsDeDemarrage += consistenceNODU.nbTermesContraintesPourLesCoutsDeDemarrage; @@ -104,7 +104,7 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( { const PALIERS_THERMIQUES& PaliersThermiquesDuPays = problemeHebdo->PaliersThermiquesDuPays[pays]; - NbUnitsOutageLessThanNbUnitsStop nbUnitsOutageLessThanNbUnitsStop(problemeHebdo); + NbUnitsOutageLessThanNbUnitsStop nbUnitsOutageLessThanNbUnitsStop(builder); constraintNamer.UpdateArea(problemeHebdo->NomsDesPays[pays]); for (int index = 0; index < PaliersThermiquesDuPays.NombreDePaliersThermiques; index++) @@ -125,7 +125,7 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( { const PALIERS_THERMIQUES& PaliersThermiquesDuPays = problemeHebdo->PaliersThermiquesDuPays[pays]; - NbDispUnitsMinBoundSinceMinUpTime nbDispUnitsMinBoundSinceMinUpTime(problemeHebdo); + NbDispUnitsMinBoundSinceMinUpTime nbDispUnitsMinBoundSinceMinUpTime(builder); constraintNamer.UpdateArea(problemeHebdo->NomsDesPays[pays]); for (int index = 0; index < PaliersThermiquesDuPays.NombreDePaliersThermiques; index++) { @@ -149,7 +149,7 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( { const PALIERS_THERMIQUES& PaliersThermiquesDuPays = problemeHebdo->PaliersThermiquesDuPays[pays]; - MinDownTime minDownTime(problemeHebdo); + MinDownTime minDownTime(builder); for (int index = 0; index < PaliersThermiquesDuPays.NombreDePaliersThermiques; index++) { const int palier diff --git a/src/solver/optimisation/opt_construction_matrice_des_contraintes_cas_lineaire.cpp b/src/solver/optimisation/opt_construction_matrice_des_contraintes_cas_lineaire.cpp index d214cbf281..b2560940b5 100644 --- a/src/solver/optimisation/opt_construction_matrice_des_contraintes_cas_lineaire.cpp +++ b/src/solver/optimisation/opt_construction_matrice_des_contraintes_cas_lineaire.cpp @@ -170,29 +170,29 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro ProblemeAResoudre->NombreDeTermesDansLaMatriceDesContraintes = 0; ConstraintNamer constraintNamer(ProblemeAResoudre->NomDesContraintes, problemeHebdo->NamedProblems); + ConstraintBuilder builder(GetConstraintBuilderFromProblemHebdo(problemeHebdo)); - AreaBalance areaBalance(problemeHebdo); - FictitiousLoad fictitiousLoad(problemeHebdo); - ShortTermStorageLevel shortTermStorageLevel(problemeHebdo); - FlowDissociation flowDissociation(problemeHebdo); - BindingConstraintHour bindingConstraintHour(problemeHebdo); - BindingConstraintDay bindingConstraintDay(problemeHebdo); - BindingConstraintWeek bindingConstraintWeek(problemeHebdo); - HydroPower hydroPower(problemeHebdo); - HydroPowerSmoothingUsingVariationSum hydroPowerSmoothingUsingVariationSum(problemeHebdo); - HydroPowerSmoothingUsingVariationMaxDown hydroPowerSmoothingUsingVariationMaxDown( - problemeHebdo); - HydroPowerSmoothingUsingVariationMaxUp hydroPowerSmoothingUsingVariationMaxUp(problemeHebdo); + AreaBalance areaBalance(builder); + FictitiousLoad fictitiousLoad(builder); + ShortTermStorageLevel shortTermStorageLevel(builder); + FlowDissociation flowDissociation(builder); + BindingConstraintHour bindingConstraintHour(builder); + BindingConstraintDay bindingConstraintDay(builder); + BindingConstraintWeek bindingConstraintWeek(builder); + HydroPower hydroPower(builder); + HydroPowerSmoothingUsingVariationSum hydroPowerSmoothingUsingVariationSum(builder); + HydroPowerSmoothingUsingVariationMaxDown hydroPowerSmoothingUsingVariationMaxDown(builder); + HydroPowerSmoothingUsingVariationMaxUp hydroPowerSmoothingUsingVariationMaxUp(builder); - MinHydroPower minHydroPower(problemeHebdo); - MaxHydroPower maxHydroPower(problemeHebdo); + MinHydroPower minHydroPower(builder); + MaxHydroPower maxHydroPower(builder); - MaxPumping maxPumping(problemeHebdo); + MaxPumping maxPumping(builder); - AreaHydroLevel areaHydroLevel(problemeHebdo); + AreaHydroLevel areaHydroLevel(builder); - FinalStockEquivalent finalStockEquivalent(problemeHebdo); - FinalStockExpression finalStockExpression(problemeHebdo); + FinalStockEquivalent finalStockEquivalent(builder); + FinalStockExpression finalStockExpression(builder); for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) { @@ -204,20 +204,31 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro for (uint32_t pays = 0; pays < problemeHebdo->NombreDePays; pays++) { - areaBalance.add( - pdt, - pays, + AreaBalanceData areaBalanceData{ CorrespondanceCntNativesCntOptim.NumeroDeContrainteDesBilansPays, CorrespondanceVarNativesVarOptim.SIM_ShortTermStorage.InjectionVariable, - CorrespondanceVarNativesVarOptim.SIM_ShortTermStorage.WithdrawalVariable); - - fictitiousLoad.add( - pdt, - pays, - CorrespondanceCntNativesCntOptim.NumeroDeContraintePourEviterLesChargesFictives); - - shortTermStorageLevel.add( - pdt, pays, CorrespondanceCntNativesCntOptim.ShortTermStorageLevelConstraint); + CorrespondanceVarNativesVarOptim.SIM_ShortTermStorage.WithdrawalVariable, + problemeHebdo->IndexDebutIntercoOrigine, + problemeHebdo->IndexSuivantIntercoOrigine, + problemeHebdo->IndexDebutIntercoExtremite, + problemeHebdo->IndexSuivantIntercoExtremite, + problemeHebdo->PaliersThermiquesDuPays[pays], + problemeHebdo->ShortTermStorage}; + + areaBalance.add(pdt, pays, areaBalanceData); + + FictitiousLoadData fictitiousLoadData + = {CorrespondanceCntNativesCntOptim.NumeroDeContraintePourEviterLesChargesFictives, + problemeHebdo->PaliersThermiquesDuPays[pays], + problemeHebdo->DefaillanceNegativeUtiliserHydro}; + + fictitiousLoad.add(pdt, pays, fictitiousLoadData); + + ShortTermStorageLevelData shortTermStorageLevelData = { + CorrespondanceCntNativesCntOptim.ShortTermStorageLevelConstraint, + problemeHebdo->ShortTermStorage, + }; + shortTermStorageLevel.add(pdt, pays, shortTermStorageLevelData); } for (uint32_t interco = 0; interco < problemeHebdo->NombreDInterconnexions; interco++) @@ -232,18 +243,17 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro for (uint32_t cntCouplante = 0; cntCouplante < problemeHebdo->NombreDeContraintesCouplantes; cntCouplante++) { - bindingConstraintHour.add( - pdt, - cntCouplante, - GetBindingConstraintHourDataFromProblemHebdo(problemeHebdo, cntCouplante, pdt)); + auto data + = GetBindingConstraintHourDataFromProblemHebdo(problemeHebdo, cntCouplante, pdt); + bindingConstraintHour.add(pdt, cntCouplante, data); } } for (uint32_t cntCouplante = 0; cntCouplante < problemeHebdo->NombreDeContraintesCouplantes; cntCouplante++) { - bindingConstraintDay.add( - cntCouplante, GetBindingConstraintDayDataFromProblemHebdo(problemeHebdo, cntCouplante)); + auto data = GetBindingConstraintDayDataFromProblemHebdo(problemeHebdo, cntCouplante); + bindingConstraintDay.add(cntCouplante, data); } if (nombreDePasDeTempsPourUneOptimisation > nombreDePasDeTempsDUneJournee) @@ -251,15 +261,15 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro for (uint32_t cntCouplante = 0; cntCouplante < problemeHebdo->NombreDeContraintesCouplantes; cntCouplante++) { - bindingConstraintWeek.add( - cntCouplante, - GetBindingConstraintWeekDataFromProblemHebdo(problemeHebdo, cntCouplante)); + auto data = GetBindingConstraintWeekDataFromProblemHebdo(problemeHebdo, cntCouplante); + bindingConstraintWeek.add(cntCouplante, data); } } for (uint32_t pays = 0; pays < problemeHebdo->NombreDePays; pays++) { - hydroPower.add(pays, GetHydroPowerDataFromProblemHebdo(problemeHebdo, pays)); + auto data = GetHydroPowerDataFromProblemHebdo(problemeHebdo, pays); + hydroPower.add(pays, data); } if (problemeHebdo->TypeDeLissageHydraulique == LISSAGE_HYDRAULIQUE_SUR_SOMME_DES_VARIATIONS) @@ -291,9 +301,11 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro for (uint32_t pays = 0; pays < problemeHebdo->NombreDePays; pays++) { - minHydroPower.add(pays, GetMinHydroPowerDataFromProblemHebdo(problemeHebdo, pays)); + auto minHydroPowerData = GetMinHydroPowerDataFromProblemHebdo(problemeHebdo, pays); + minHydroPower.add(pays, minHydroPowerData); - maxHydroPower.add(pays, GetMaxHydroPowerDataFromProblemHebdo(problemeHebdo, pays)); + auto maxHydroPowerData = GetMaxHydroPowerDataFromProblemHebdo(problemeHebdo, pays); + maxHydroPower.add(pays, maxHydroPowerData); } for (uint32_t pays = 0; pays < problemeHebdo->NombreDePays; pays++) diff --git a/src/solver/optimisation/opt_construction_matrice_des_contraintes_cas_quadratique.cpp b/src/solver/optimisation/opt_construction_matrice_des_contraintes_cas_quadratique.cpp index 1cce001a05..608ddd25df 100644 --- a/src/solver/optimisation/opt_construction_matrice_des_contraintes_cas_quadratique.cpp +++ b/src/solver/optimisation/opt_construction_matrice_des_contraintes_cas_quadratique.cpp @@ -32,30 +32,39 @@ #include "../simulation/sim_extern_variables_globales.h" #include "opt_fonctions.h" #include "constraint_builder.h" + +struct ExchangeBalanceData +{ + const std::vector& IndexDebutIntercoOrigine; + const std::vector& IndexSuivantIntercoOrigine; + const std::vector& IndexDebutIntercoExtremite; + const std::vector& IndexSuivantIntercoExtremite; + std::vector& NumeroDeContrainteDeSoldeDEchange; +}; + class ExchangeBalance : private Constraint { public: using Constraint::Constraint; - void add(uint32_t pays) + void add(uint32_t pays, ExchangeBalanceData& data) { builder.updateHourWithinWeek(0); - int interco = problemeHebdo->IndexDebutIntercoOrigine[pays]; + int interco = data.IndexDebutIntercoOrigine[pays]; while (interco >= 0) { builder.include(Variable::IntercoDirectCost(interco), 1.0); - interco = problemeHebdo->IndexSuivantIntercoOrigine[interco]; + interco = data.IndexSuivantIntercoOrigine[interco]; } - interco = problemeHebdo->IndexDebutIntercoExtremite[pays]; + interco = data.IndexDebutIntercoExtremite[pays]; while (interco >= 0) { builder.include(Variable::IntercoDirectCost(interco), -1.0); - interco = problemeHebdo->IndexSuivantIntercoExtremite[interco]; + interco = data.IndexSuivantIntercoExtremite[interco]; } - problemeHebdo->NumeroDeContrainteDeSoldeDEchange[pays] - = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; + data.NumeroDeContrainteDeSoldeDEchange[pays] = builder.data.nombreDeContraintes; builder.build(); } }; @@ -63,7 +72,6 @@ class ExchangeBalance : private Constraint void OPT_ConstruireLaMatriceDesContraintesDuProblemeQuadratique(PROBLEME_HEBDO* problemeHebdo) { PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre = problemeHebdo->ProblemeAResoudre.get(); - std::vector Pi(ProblemeAResoudre->NombreDeVariables, 0.); std::vector Colonne(ProblemeAResoudre->NombreDeVariables, 0); @@ -71,10 +79,18 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeQuadratique(PROBLEME_HEBDO* ProblemeAResoudre->NombreDeTermesDansLaMatriceDesContraintes = 0; const CORRESPONDANCES_DES_VARIABLES& correspondanceVarNativesVarOptim = problemeHebdo->CorrespondanceVarNativesVarOptim[0]; - ExchangeBalance exchangeBalance(problemeHebdo); + ConstraintBuilder builder(GetConstraintBuilderFromProblemHebdo(problemeHebdo)); + + ExchangeBalance exchangeBalance(builder); + + ExchangeBalanceData data = {problemeHebdo->IndexDebutIntercoOrigine, + problemeHebdo->IndexSuivantIntercoOrigine, + problemeHebdo->IndexDebutIntercoExtremite, + problemeHebdo->IndexSuivantIntercoExtremite, + problemeHebdo->NumeroDeContrainteDeSoldeDEchange}; for (uint32_t pays = 0; pays < problemeHebdo->NombreDePays - 1; pays++) { - exchangeBalance.add(pays); + exchangeBalance.add(pays, data); } } diff --git a/src/solver/optimisation/opt_fonctions.h b/src/solver/optimisation/opt_fonctions.h index fd5292e24c..e097e4d0ae 100644 --- a/src/solver/optimisation/opt_fonctions.h +++ b/src/solver/optimisation/opt_fonctions.h @@ -34,6 +34,7 @@ #include "antares/study/parameters/adq-patch-params.h" #include "opt_structure_probleme_a_resoudre.h" #include +#include "constraint_builder.h" using AdqPatchParams = Antares::Data::AdequacyPatch::AdqPatchParams; using OptimizationOptions = Antares::Solver::Optimization::OptimizationOptions; diff --git a/src/solver/simulation/adequacy_patch_runtime_data.h b/src/solver/simulation/adequacy_patch_runtime_data.h index 62971f28a3..573e8b6e47 100644 --- a/src/solver/simulation/adequacy_patch_runtime_data.h +++ b/src/solver/simulation/adequacy_patch_runtime_data.h @@ -31,10 +31,11 @@ #include #include +using adqPatchParamsMode = Antares::Data::AdequacyPatch::AdequacyPatchMode; + class AdequacyPatchRuntimeData { private: - using adqPatchParamsMode = Antares::Data::AdequacyPatch::AdequacyPatchMode; std::vector> csrTriggeredHoursPerArea_; public: