From 433b799c1909231312918cf3ac17d513cacf9e60 Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Sat, 2 Sep 2023 20:19:58 +0200 Subject: [PATCH 01/43] start --- src/solver/optimisation/AreaBalance.cpp | 97 ++++ src/solver/optimisation/AreaBalance.h | 8 + src/solver/optimisation/AreaHydroLevel.cpp | 31 ++ src/solver/optimisation/AreaHydroLevel.h | 8 + .../optimisation/BindingConstraintDay.cpp | 80 ++++ .../optimisation/BindingConstraintDay.h | 8 + .../optimisation/BindingConstraintHour.cpp | 60 +++ .../optimisation/BindingConstraintHour.h | 8 + .../optimisation/BindingConstraintWeek.cpp | 60 +++ .../optimisation/BindingConstraintWeek.h | 8 + src/solver/optimisation/CMakeLists.txt | 40 ++ src/solver/optimisation/FictitiousLoad.cpp | 66 +++ src/solver/optimisation/FictitiousLoad.h | 9 + .../optimisation/FinalStockEquivalent.cpp | 21 + .../optimisation/FinalStockEquivalent.h | 8 + .../optimisation/FinalStockExpression.cpp | 21 + .../optimisation/FinalStockExpression.h | 9 + src/solver/optimisation/FlowDissociation.cpp | 45 ++ src/solver/optimisation/FlowDissociation.h | 8 + src/solver/optimisation/HydroPower.cpp | 45 ++ src/solver/optimisation/HydroPower.h | 8 + ...droPowerSmoothingUsingVariationMaxDown.cpp | 30 ++ ...HydroPowerSmoothingUsingVariationMaxDown.h | 8 + ...HydroPowerSmoothingUsingVariationMaxUp.cpp | 30 ++ .../HydroPowerSmoothingUsingVariationMaxUp.h | 8 + .../HydroPowerSmoothingUsingVariationSum.cpp | 38 ++ .../HydroPowerSmoothingUsingVariationSum.h | 8 + src/solver/optimisation/MaxHydroPower.cpp | 32 ++ src/solver/optimisation/MaxHydroPower.h | 8 + src/solver/optimisation/MaxPumping.cpp | 26 ++ src/solver/optimisation/MaxPumping.h | 8 + src/solver/optimisation/MinHydroPower.cpp | 32 ++ src/solver/optimisation/MinHydroPower.h | 8 + .../optimisation/ShortTermStorageLevel.cpp | 41 ++ .../optimisation/ShortTermStorageLevel.h | 7 + .../optimisation/constraint_builder.cpp | 20 + src/solver/optimisation/constraint_builder.h | 442 ++++++++++++++++++ ...n_matrice_des_contraintes_cas_lineaire.cpp | 149 +++--- 38 files changed, 1471 insertions(+), 72 deletions(-) create mode 100644 src/solver/optimisation/AreaBalance.cpp create mode 100644 src/solver/optimisation/AreaBalance.h create mode 100644 src/solver/optimisation/AreaHydroLevel.cpp create mode 100644 src/solver/optimisation/AreaHydroLevel.h create mode 100644 src/solver/optimisation/BindingConstraintDay.cpp create mode 100644 src/solver/optimisation/BindingConstraintDay.h create mode 100644 src/solver/optimisation/BindingConstraintHour.cpp create mode 100644 src/solver/optimisation/BindingConstraintHour.h create mode 100644 src/solver/optimisation/BindingConstraintWeek.cpp create mode 100644 src/solver/optimisation/BindingConstraintWeek.h create mode 100644 src/solver/optimisation/FictitiousLoad.cpp create mode 100644 src/solver/optimisation/FictitiousLoad.h create mode 100644 src/solver/optimisation/FinalStockEquivalent.cpp create mode 100644 src/solver/optimisation/FinalStockEquivalent.h create mode 100644 src/solver/optimisation/FinalStockExpression.cpp create mode 100644 src/solver/optimisation/FinalStockExpression.h create mode 100644 src/solver/optimisation/FlowDissociation.cpp create mode 100644 src/solver/optimisation/FlowDissociation.h create mode 100644 src/solver/optimisation/HydroPower.cpp create mode 100644 src/solver/optimisation/HydroPower.h create mode 100644 src/solver/optimisation/HydroPowerSmoothingUsingVariationMaxDown.cpp create mode 100644 src/solver/optimisation/HydroPowerSmoothingUsingVariationMaxDown.h create mode 100644 src/solver/optimisation/HydroPowerSmoothingUsingVariationMaxUp.cpp create mode 100644 src/solver/optimisation/HydroPowerSmoothingUsingVariationMaxUp.h create mode 100644 src/solver/optimisation/HydroPowerSmoothingUsingVariationSum.cpp create mode 100644 src/solver/optimisation/HydroPowerSmoothingUsingVariationSum.h create mode 100644 src/solver/optimisation/MaxHydroPower.cpp create mode 100644 src/solver/optimisation/MaxHydroPower.h create mode 100644 src/solver/optimisation/MaxPumping.cpp create mode 100644 src/solver/optimisation/MaxPumping.h create mode 100644 src/solver/optimisation/MinHydroPower.cpp create mode 100644 src/solver/optimisation/MinHydroPower.h create mode 100644 src/solver/optimisation/ShortTermStorageLevel.cpp create mode 100644 src/solver/optimisation/ShortTermStorageLevel.h create mode 100644 src/solver/optimisation/constraint_builder.cpp create mode 100644 src/solver/optimisation/constraint_builder.h diff --git a/src/solver/optimisation/AreaBalance.cpp b/src/solver/optimisation/AreaBalance.cpp new file mode 100644 index 0000000000..58fd519202 --- /dev/null +++ b/src/solver/optimisation/AreaBalance.cpp @@ -0,0 +1,97 @@ +#include "AreaBalance.h" + +static void shortTermStorageBalance( + const ::ShortTermStorage::AREA_INPUT& shortTermStorageInput, + ConstraintBuilder& constraintBuilder, + const CORRESPONDANCES_DES_VARIABLES& CorrespondanceVarNativesVarOptim) +{ + for (const auto& storage : shortTermStorageInput) + { + unsigned index = storage.clusterGlobalIndex; + if (const int varInjection + = CorrespondanceVarNativesVarOptim.SIM_ShortTermStorage.InjectionVariable[index]; + varInjection >= 0) + { + constraintBuilder.include(Variable::ShortTermStorageInjection(index), 1.0); + } + if (const int varWithdrawal + = CorrespondanceVarNativesVarOptim.SIM_ShortTermStorage.WithdrawalVariable[index]; + varWithdrawal >= 0) + { + constraintBuilder.include(Variable::ShortTermStorageWithdrawal(index), -1.0); + } + } +} + +// Constraint definitions +void AreaBalance::add(int pdt, int pays) +{ + /** can be done without this --- keep it for now**/ + CORRESPONDANCES_DES_VARIABLES& CorrespondanceVarNativesVarOptim + = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt]; + CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim + = problemeHebdo->CorrespondanceCntNativesCntOptim[pdt]; + CorrespondanceCntNativesCntOptim.NumeroDeContrainteDesBilansPays[pays] + = problemeHebdo->ProblemeAResoudre->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); + } + + builder.updateHourWithinWeek(pdt); + + int interco = problemeHebdo->IndexDebutIntercoOrigine[pays]; + while (interco >= 0) + { + builder.include(Variable::NTCDirect(interco), 1.0); + interco = problemeHebdo->IndexSuivantIntercoOrigine[interco]; + } + + interco = problemeHebdo->IndexDebutIntercoExtremite[pays]; + while (interco >= 0) + { + builder.include(Variable::NTCDirect(interco), -1.0); + interco = problemeHebdo->IndexSuivantIntercoExtremite[interco]; + } + + exportPaliers(*problemeHebdo, builder, pays); + 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, CorrespondanceVarNativesVarOptim); + + // { + // const CONSOMMATIONS_ABATTUES& ConsommationsAbattues + // = problemeHebdo->ConsommationsAbattues[pdtHebdo]; + // double rhs = -ConsommationsAbattues.ConsommationAbattueDuPays[pays]; + // bool reserveJm1 = (problemeHebdo->YaDeLaReserveJmoins1); + // bool opt1 = (optimizationNumber == PREMIERE_OPTIMISATION); + // if (reserveJm1 && opt1) + // { + // rhs -= problemeHebdo->ReserveJMoins1[pays].ReserveHoraireJMoins1[pdtHebdo]; + // } + // /* check !*/ + // double* adresseDuResultat + // = &(problemeHebdo->ResultatsHoraires[pays].CoutsMarginauxHoraires[pdtHebdo]); + + // std::vector& AdresseOuPlacerLaValeurDesCoutsMarginaux + // = problemeHebdo->ProblemeAResoudre->AdresseOuPlacerLaValeurDesCoutsMarginaux; + + // int cnt = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; + + // AdresseOuPlacerLaValeurDesCoutsMarginaux[cnt] = adresseDuResultat; + + // } + /*check! */ + builder.equalTo(); + builder.build(); +} diff --git a/src/solver/optimisation/AreaBalance.h b/src/solver/optimisation/AreaBalance.h new file mode 100644 index 0000000000..b768622216 --- /dev/null +++ b/src/solver/optimisation/AreaBalance.h @@ -0,0 +1,8 @@ +#pragma once +#include "constraint_builder.h" +struct AreaBalance : public Constraint +{ + using Constraint::Constraint; + + void add(int pdt, int pays); +}; \ No newline at end of file diff --git a/src/solver/optimisation/AreaHydroLevel.cpp b/src/solver/optimisation/AreaHydroLevel.cpp new file mode 100644 index 0000000000..1479832b76 --- /dev/null +++ b/src/solver/optimisation/AreaHydroLevel.cpp @@ -0,0 +1,31 @@ +#include "AreaHydroLevel.h" + +void AreaHydroLevel::add(int pays, int pdt) +{ + const auto& CorrespondanceVarNativesVarOptim + = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt]; + CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim + = problemeHebdo->CorrespondanceCntNativesCntOptim[pdt]; + CorrespondanceCntNativesCntOptim.NumeroDeContrainteDesNiveauxPays[pays] + = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; + + builder.updateHourWithinWeek(pdt).include(Variable::HydroLevel(pays), 1.0); + if (pdt > 0) + { + builder.updateHourWithinWeek(pdt - 1).include(Variable::HydroLevel(pays), -1.0); + } + ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, + problemeHebdo->NamedProblems); + + namer.UpdateArea(problemeHebdo->NomsDesPays[pays]); + namer.UpdateTimeStep(problemeHebdo->weekInTheYear * 168 + pdt); + namer.AreaHydroLevel(problemeHebdo->ProblemeAResoudre->NombreDeContraintes); + + builder.updateHourWithinWeek(pdt) + .include(Variable::HydProd(pays), 1.0) + .include(Variable::Pumping(pays), + -problemeHebdo->CaracteristiquesHydrauliques[pays].PumpingRatio) + .include(Variable::Overflow(pays), 1.) + .equalTo() + .build(); +} \ No newline at end of file diff --git a/src/solver/optimisation/AreaHydroLevel.h b/src/solver/optimisation/AreaHydroLevel.h new file mode 100644 index 0000000000..dca2322ab1 --- /dev/null +++ b/src/solver/optimisation/AreaHydroLevel.h @@ -0,0 +1,8 @@ +#pragma once +#include "constraint_builder.h" + +struct AreaHydroLevel : public Constraint +{ + using Constraint::Constraint; + void add(int pays, int pdt); +}; \ No newline at end of file diff --git a/src/solver/optimisation/BindingConstraintDay.cpp b/src/solver/optimisation/BindingConstraintDay.cpp new file mode 100644 index 0000000000..76401017c3 --- /dev/null +++ b/src/solver/optimisation/BindingConstraintDay.cpp @@ -0,0 +1,80 @@ +#include "BindingConstraintDay.h" + +void BindingConstraintDay::add(int cntCouplante) +{ + const CONTRAINTES_COUPLANTES& MatriceDesContraintesCouplantes + = problemeHebdo->MatriceDesContraintesCouplantes[cntCouplante]; + if (MatriceDesContraintesCouplantes.TypeDeContrainteCouplante != CONTRAINTE_JOURNALIERE) + return; + + const int nbInterco + = MatriceDesContraintesCouplantes.NombreDInterconnexionsDansLaContrainteCouplante; + const int nbClusters + = MatriceDesContraintesCouplantes.NombreDePaliersDispatchDansLaContrainteCouplante; + + const int NombreDePasDeTempsPourUneOptimisation + = problemeHebdo->NombreDePasDeTempsPourUneOptimisation; // TODO + const int NombreDePasDeTempsDUneJournee = problemeHebdo->NombreDePasDeTempsDUneJournee; + for (int pdtDebut = 0; pdtDebut < NombreDePasDeTempsPourUneOptimisation; + pdtDebut += NombreDePasDeTempsDUneJournee) + { + for (int index = 0; index < nbInterco; index++) + { + int interco = MatriceDesContraintesCouplantes.NumeroDeLInterconnexion[index]; + double poids = MatriceDesContraintesCouplantes.PoidsDeLInterconnexion[index]; + int offset = MatriceDesContraintesCouplantes.OffsetTemporelSurLInterco[index]; + + for (int pdt = pdtDebut; pdt < pdtDebut + NombreDePasDeTempsDUneJournee; pdt++) + { + builder.updateHourWithinWeek(pdt); + builder.include(Variable::NTCDirect(interco), + poids, + offset, + true, + problemeHebdo->NombreDePasDeTemps); + } + } + + for (int index = 0; index < nbClusters; index++) + { + int pays = MatriceDesContraintesCouplantes.PaysDuPalierDispatch[index]; + const PALIERS_THERMIQUES& PaliersThermiquesDuPays + = problemeHebdo->PaliersThermiquesDuPays[pays]; + const int palier + = PaliersThermiquesDuPays.NumeroDuPalierDansLEnsembleDesPaliersThermiques + [MatriceDesContraintesCouplantes.NumeroDuPalierDispatch[index]]; + double poids = MatriceDesContraintesCouplantes.PoidsDuPalierDispatch[index]; + int offset = MatriceDesContraintesCouplantes.OffsetTemporelSurLePalierDispatch[index]; + + for (int pdt = pdtDebut; pdt < pdtDebut + NombreDePasDeTempsDUneJournee; pdt++) + { + builder.updateHourWithinWeek(pdt); + builder.include(Variable::DispatchableProduction(palier), + poids, + offset, + true, + problemeHebdo->NombreDePasDeTemps); + } + } + // TODO probably wrong from the 2nd week, check + const int jour = problemeHebdo->NumeroDeJourDuPasDeTemps[pdtDebut]; + + std::vector& AdresseOuPlacerLaValeurDesCoutsMarginaux + = problemeHebdo->ProblemeAResoudre->AdresseOuPlacerLaValeurDesCoutsMarginaux; + // int cnt = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; + // AdresseOuPlacerLaValeurDesCoutsMarginaux[cnt] + // = problemeHebdo->ResultatsContraintesCouplantes[cntCouplante].variablesDuales.data() + // + jour; + // double rhs = MatriceDesContraintesCouplantes.SecondMembreDeLaContrainteCouplante[jour]; + char op = MatriceDesContraintesCouplantes.SensDeLaContrainteCouplante; + builder.operatorRHS(op); + { + ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, + problemeHebdo->NamedProblems); + namer.UpdateTimeStep(jour); + namer.BindingConstraintDay(problemeHebdo->ProblemeAResoudre->NombreDeContraintes, + MatriceDesContraintesCouplantes.NomDeLaContrainteCouplante); + } + builder.build(); + } +} diff --git a/src/solver/optimisation/BindingConstraintDay.h b/src/solver/optimisation/BindingConstraintDay.h new file mode 100644 index 0000000000..18244c6a46 --- /dev/null +++ b/src/solver/optimisation/BindingConstraintDay.h @@ -0,0 +1,8 @@ +#pragma once +#include "constraint_builder.h" + +struct BindingConstraintDay : public Constraint +{ + using Constraint::Constraint; + void add(int cntCouplante); +}; diff --git a/src/solver/optimisation/BindingConstraintHour.cpp b/src/solver/optimisation/BindingConstraintHour.cpp new file mode 100644 index 0000000000..64d67cd1f3 --- /dev/null +++ b/src/solver/optimisation/BindingConstraintHour.cpp @@ -0,0 +1,60 @@ +#include "BindingConstraintHour.h" + +void BindingConstraintHour::add(int pdt, int cntCouplante) +{ + const CONTRAINTES_COUPLANTES& MatriceDesContraintesCouplantes + = problemeHebdo->MatriceDesContraintesCouplantes[cntCouplante]; + if (MatriceDesContraintesCouplantes.TypeDeContrainteCouplante != CONTRAINTE_HORAIRE) + return; + + builder.updateHourWithinWeek(pdt); + // Links + const int nbInterco + = MatriceDesContraintesCouplantes.NombreDInterconnexionsDansLaContrainteCouplante; + for (int index = 0; index < nbInterco; index++) + { + const int interco = MatriceDesContraintesCouplantes.NumeroDeLInterconnexion[index]; + const double poids = MatriceDesContraintesCouplantes.PoidsDeLInterconnexion[index]; + const int offset = MatriceDesContraintesCouplantes.OffsetTemporelSurLInterco[index]; + builder.include( + Variable::NTCDirect(interco), poids, offset, true, problemeHebdo->NombreDePasDeTemps); + } + + // Thermal clusters + const int nbClusters + = MatriceDesContraintesCouplantes.NombreDePaliersDispatchDansLaContrainteCouplante; + for (int index = 0; index < nbClusters; index++) + { + const int pays = MatriceDesContraintesCouplantes.PaysDuPalierDispatch[index]; + const PALIERS_THERMIQUES& PaliersThermiquesDuPays + = problemeHebdo->PaliersThermiquesDuPays[pays]; + const int palier = PaliersThermiquesDuPays.NumeroDuPalierDansLEnsembleDesPaliersThermiques + [MatriceDesContraintesCouplantes.NumeroDuPalierDispatch[index]]; + const double poids = MatriceDesContraintesCouplantes.PoidsDuPalierDispatch[index]; + const int offset = MatriceDesContraintesCouplantes.OffsetTemporelSurLePalierDispatch[index]; + builder.include(Variable::DispatchableProduction(palier), + poids, + offset, + true, + problemeHebdo->NombreDePasDeTemps); + } + + // std::vector& AdresseOuPlacerLaValeurDesCoutsMarginaux + // = problemeHebdo->ProblemeAResoudre->AdresseOuPlacerLaValeurDesCoutsMarginaux; + // int cnt = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; + + // double rhs = MatriceDesContraintesCouplantes.SecondMembreDeLaContrainteCouplante[pdtHebdo]; + // AdresseOuPlacerLaValeurDesCoutsMarginaux[cnt] + // = problemeHebdo->ResultatsContraintesCouplantes[cntCouplante].variablesDuales.data() + // + pdtHebdo; + char op = MatriceDesContraintesCouplantes.SensDeLaContrainteCouplante; + builder.operatorRHS(op); + { + ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, + problemeHebdo->NamedProblems); + namer.UpdateTimeStep(problemeHebdo->weekInTheYear * 168 + pdt); + namer.BindingConstraintHour(problemeHebdo->ProblemeAResoudre->NombreDeContraintes, + MatriceDesContraintesCouplantes.NomDeLaContrainteCouplante); + } + builder.build(); +} diff --git a/src/solver/optimisation/BindingConstraintHour.h b/src/solver/optimisation/BindingConstraintHour.h new file mode 100644 index 0000000000..315e588976 --- /dev/null +++ b/src/solver/optimisation/BindingConstraintHour.h @@ -0,0 +1,8 @@ +#pragma once +#include "constraint_builder.h" + +struct BindingConstraintHour : public Constraint +{ + using Constraint::Constraint; + void add(int pdt, int cntCouplante); +}; diff --git a/src/solver/optimisation/BindingConstraintWeek.cpp b/src/solver/optimisation/BindingConstraintWeek.cpp new file mode 100644 index 0000000000..0556d8320b --- /dev/null +++ b/src/solver/optimisation/BindingConstraintWeek.cpp @@ -0,0 +1,60 @@ +#include "BindingConstraintWeek.h" + +void BindingConstraintWeek::add(int cntCouplante) +{ + const CONTRAINTES_COUPLANTES& MatriceDesContraintesCouplantes + = problemeHebdo->MatriceDesContraintesCouplantes[cntCouplante]; + if (MatriceDesContraintesCouplantes.TypeDeContrainteCouplante != CONTRAINTE_HEBDOMADAIRE) + return; + + const int nbInterco + = MatriceDesContraintesCouplantes.NombreDInterconnexionsDansLaContrainteCouplante; + const int nbClusters + = MatriceDesContraintesCouplantes.NombreDePaliersDispatchDansLaContrainteCouplante; + + const int NombreDePasDeTempsPourUneOptimisation + = problemeHebdo->NombreDePasDeTempsPourUneOptimisation; + + for (int pdt = 0; pdt < NombreDePasDeTempsPourUneOptimisation; pdt++) + { + builder.updateHourWithinWeek(pdt); + for (int index = 0; index < nbInterco; index++) + { + int interco = MatriceDesContraintesCouplantes.NumeroDeLInterconnexion[index]; + double poids = MatriceDesContraintesCouplantes.PoidsDeLInterconnexion[index]; + int offset = MatriceDesContraintesCouplantes.OffsetTemporelSurLInterco[index]; + + builder.include( + Variable::NTCDirect(interco), poids, offset, true, problemeHebdo->NombreDePasDeTemps); + } + + for (int index = 0; index < nbClusters; index++) + { + int pays = MatriceDesContraintesCouplantes.PaysDuPalierDispatch[index]; + const PALIERS_THERMIQUES& PaliersThermiquesDuPays + = problemeHebdo->PaliersThermiquesDuPays[pays]; + const int palier + = PaliersThermiquesDuPays.NumeroDuPalierDansLEnsembleDesPaliersThermiques + [MatriceDesContraintesCouplantes.NumeroDuPalierDispatch[index]]; + double poids = MatriceDesContraintesCouplantes.PoidsDuPalierDispatch[index]; + int offset = MatriceDesContraintesCouplantes.OffsetTemporelSurLePalierDispatch[index]; + builder.include(Variable::DispatchableProduction(palier), + poids, + offset, + true, + problemeHebdo->NombreDePasDeTemps); + } + } + char op = MatriceDesContraintesCouplantes.SensDeLaContrainteCouplante; + builder.operatorRHS(op); + + // Name + { + ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, + problemeHebdo->NamedProblems); + namer.UpdateTimeStep(problemeHebdo->weekInTheYear); + namer.BindingConstraintWeek(problemeHebdo->ProblemeAResoudre->NombreDeContraintes, + MatriceDesContraintesCouplantes.NomDeLaContrainteCouplante); + } + builder.build(); +} \ No newline at end of file diff --git a/src/solver/optimisation/BindingConstraintWeek.h b/src/solver/optimisation/BindingConstraintWeek.h new file mode 100644 index 0000000000..26488d29eb --- /dev/null +++ b/src/solver/optimisation/BindingConstraintWeek.h @@ -0,0 +1,8 @@ +#pragma once +#include "constraint_builder.h" + +struct BindingConstraintWeek : public Constraint +{ + using Constraint::Constraint; + void add(int cntCouplante); +}; \ No newline at end of file diff --git a/src/solver/optimisation/CMakeLists.txt b/src/solver/optimisation/CMakeLists.txt index 05f5e5a352..b4e5f5a42e 100644 --- a/src/solver/optimisation/CMakeLists.txt +++ b/src/solver/optimisation/CMakeLists.txt @@ -70,6 +70,46 @@ set(RTESOLVER_OPT opt_period_string_generator_base.h opt_rename_problem.h opt_rename_problem.cpp + + constraint_builder.cpp + constraint_builder.h + + AreaBalance.h + AreaBalance.cpp + FictitiousLoad.h + FictitiousLoad.cpp + ShortTermStorageLevel.h + ShortTermStorageLevel.cpp + FlowDissociation.h + FlowDissociation.cpp + BindingConstraintHour.h + BindingConstraintHour.cpp + BindingConstraintDay.h + BindingConstraintDay.cpp + BindingConstraintWeek.h + BindingConstraintWeek.cpp + HydroPower.h + HydroPower.cpp + HydroPowerSmoothingUsingVariationSum.h + HydroPowerSmoothingUsingVariationSum.cpp + HydroPowerSmoothingUsingVariationMaxDown.h + HydroPowerSmoothingUsingVariationMaxDown.cpp + HydroPowerSmoothingUsingVariationMaxUp.h + HydroPowerSmoothingUsingVariationMaxUp.cpp + MinHydroPower.h + MinHydroPower.cpp + MaxHydroPower.h + MaxHydroPower.cpp + MaxPumping.h + MaxPumping.cpp + AreaHydroLevel.h + AreaHydroLevel.cpp + FinalStockEquivalent.h + FinalStockEquivalent.cpp + FinalStockExpression.h + FinalStockExpression.cpp + + ) diff --git a/src/solver/optimisation/FictitiousLoad.cpp b/src/solver/optimisation/FictitiousLoad.cpp new file mode 100644 index 0000000000..b3330ba3ef --- /dev/null +++ b/src/solver/optimisation/FictitiousLoad.cpp @@ -0,0 +1,66 @@ + +#include "FictitiousLoad.h" + +void FictitiousLoad::add(int pdt, int pays) +{ + /** can be done without this --- keep it for now**/ + CORRESPONDANCES_DES_VARIABLES& CorrespondanceVarNativesVarOptim + = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt]; + CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim + = problemeHebdo->CorrespondanceCntNativesCntOptim[pdt]; + CorrespondanceCntNativesCntOptim.NumeroDeContraintePourEviterLesChargesFictives[pays] + = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; + + /******/ + + // TODO improve this + { + ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, + problemeHebdo->NamedProblems); + + namer.UpdateTimeStep(problemeHebdo->weekInTheYear * 168 + pdt); + namer.UpdateArea(problemeHebdo->NomsDesPays[pays]); + namer.FictiveLoads(problemeHebdo->ProblemeAResoudre->NombreDeContraintes); + } + + builder.updateHourWithinWeek(pdt); + exportPaliers(*problemeHebdo, builder, pays); + builder.include(Variable::HydProd(pays), -problemeHebdo->DefaillanceNegativeUtiliserHydro[pays]) + .include(Variable::NegativeUnsuppliedEnergy(pays), 1.0); + + { + // double rhs = 0; + // // Private members ? + // const ALL_MUST_RUN_GENERATION& AllMustRunGeneration + // = problemeHebdo->AllMustRunGeneration[pdtHebdo]; + // const CONSOMMATIONS_ABATTUES& ConsommationsAbattues + // = problemeHebdo->ConsommationsAbattues[pdtHebdo]; + // const std::vector& DefaillanceNegativeUtiliserConsoAbattue + // = problemeHebdo->DefaillanceNegativeUtiliserConsoAbattue; + // const std::vector& DefaillanceNegativeUtiliserPMinThermique + // = problemeHebdo->DefaillanceNegativeUtiliserPMinThermique; + + // double MaxAllMustRunGeneration = 0.0; + + // if (AllMustRunGeneration.AllMustRunGenerationOfArea[pays] > 0.0) + // MaxAllMustRunGeneration = AllMustRunGeneration.AllMustRunGenerationOfArea[pays]; + + // double MaxMoinsConsommationBrute = 0.0; + // if (-(ConsommationsAbattues.ConsommationAbattueDuPays[pays] + // + AllMustRunGeneration.AllMustRunGenerationOfArea[pays]) + // > 0.0) + // MaxMoinsConsommationBrute = -(ConsommationsAbattues.ConsommationAbattueDuPays[pays] + // + + // AllMustRunGeneration.AllMustRunGenerationOfArea[pays]); + + // rhs = DefaillanceNegativeUtiliserConsoAbattue[pays] + // * (MaxAllMustRunGeneration + MaxMoinsConsommationBrute); + + // if (DefaillanceNegativeUtiliserPMinThermique[pays] == 0) + // { + // rhs -= OPT_SommeDesPminThermiques(problemeHebdo, pays, pdtHebdo); + // } + builder.lessThan(); + } + builder.build(); +} diff --git a/src/solver/optimisation/FictitiousLoad.h b/src/solver/optimisation/FictitiousLoad.h new file mode 100644 index 0000000000..9a9cdf411e --- /dev/null +++ b/src/solver/optimisation/FictitiousLoad.h @@ -0,0 +1,9 @@ + +#pragma once +#include "constraint_builder.h" + +struct FictitiousLoad : public Constraint +{ + using Constraint::Constraint; + void add(int pdt, int pays); +}; diff --git a/src/solver/optimisation/FinalStockEquivalent.cpp b/src/solver/optimisation/FinalStockEquivalent.cpp new file mode 100644 index 0000000000..01b9674d64 --- /dev/null +++ b/src/solver/optimisation/FinalStockEquivalent.cpp @@ -0,0 +1,21 @@ +#include "FinalStockEquivalent.h" + +void FinalStockEquivalent::add(int pays) +{ + const auto pdt = problemeHebdo->NombreDePasDeTempsPourUneOptimisation - 1; + problemeHebdo->NumeroDeContrainteEquivalenceStockFinal[pays] + = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; + + ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, + problemeHebdo->NamedProblems); + + namer.UpdateArea(problemeHebdo->NomsDesPays[pays]); + namer.UpdateTimeStep(problemeHebdo->weekInTheYear * 168 + pdt); + namer.FinalStockEquivalent(problemeHebdo->ProblemeAResoudre->NombreDeContraintes); + + builder.updateHourWithinWeek(pdt) + .include(Variable::FinalStorage(pays), 1.0) + .include(Variable::HydroLevel(pays), -1.0) + .equalTo() + .build(); +} diff --git a/src/solver/optimisation/FinalStockEquivalent.h b/src/solver/optimisation/FinalStockEquivalent.h new file mode 100644 index 0000000000..529788da24 --- /dev/null +++ b/src/solver/optimisation/FinalStockEquivalent.h @@ -0,0 +1,8 @@ +#pragma once +#include "constraint_builder.h" + +struct FinalStockEquivalent : public Constraint +{ + using Constraint::Constraint; + void add(int pays); +}; diff --git a/src/solver/optimisation/FinalStockExpression.cpp b/src/solver/optimisation/FinalStockExpression.cpp new file mode 100644 index 0000000000..87505f34b0 --- /dev/null +++ b/src/solver/optimisation/FinalStockExpression.cpp @@ -0,0 +1,21 @@ +#include "FinalStockExpression.h" + +void FinalStockExpression::add(int pays) +{ + problemeHebdo->NumeroDeContrainteExpressionStockFinal[pays] + = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; + + const auto pdt = problemeHebdo->NombreDePasDeTempsPourUneOptimisation - 1; + builder.updateHourWithinWeek(pdt).include(Variable::FinalStorage(pays), -1.0); + for (int layerindex = 0; layerindex < 100; layerindex++) + { + builder.include(Variable::LayerStorage(pays, layerindex), 1.0); + } + ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, + problemeHebdo->NamedProblems); + + namer.UpdateArea(problemeHebdo->NomsDesPays[pays]); + namer.UpdateTimeStep(problemeHebdo->weekInTheYear * 168 + pdt); + namer.FinalStockExpression(problemeHebdo->ProblemeAResoudre->NombreDeContraintes); + builder.equalTo().build(); +} diff --git a/src/solver/optimisation/FinalStockExpression.h b/src/solver/optimisation/FinalStockExpression.h new file mode 100644 index 0000000000..bfb8858a74 --- /dev/null +++ b/src/solver/optimisation/FinalStockExpression.h @@ -0,0 +1,9 @@ +#pragma once + +#include "constraint_builder.h" + +struct FinalStockExpression : public Constraint +{ + using Constraint::Constraint; + void add(int pays); +}; diff --git a/src/solver/optimisation/FlowDissociation.cpp b/src/solver/optimisation/FlowDissociation.cpp new file mode 100644 index 0000000000..efd33a73cd --- /dev/null +++ b/src/solver/optimisation/FlowDissociation.cpp @@ -0,0 +1,45 @@ +#include "FlowDissociation.h" + +void FlowDissociation::add(int pdt, int interco) +{ + if (const COUTS_DE_TRANSPORT& CoutDeTransport = problemeHebdo->CoutDeTransport[interco]; + CoutDeTransport.IntercoGereeAvecDesCouts) + { + /** can be done without this --- keep it for now**/ + CORRESPONDANCES_DES_VARIABLES& CorrespondanceVarNativesVarOptim + = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt]; + CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim + = problemeHebdo->CorrespondanceCntNativesCntOptim[pdt]; + CorrespondanceCntNativesCntOptim.NumeroDeContrainteDeDissociationDeFlux[interco] + = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; + /******/ + + // TODO improve this + + { + const auto origin + = problemeHebdo->NomsDesPays[problemeHebdo->PaysOrigineDeLInterconnexion[interco]]; + const auto destination + = problemeHebdo->NomsDesPays[problemeHebdo->PaysExtremiteDeLInterconnexion[interco]]; + ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, + problemeHebdo->NamedProblems); + namer.UpdateTimeStep(problemeHebdo->weekInTheYear * 168 + pdt); + namer.FlowDissociation( + problemeHebdo->ProblemeAResoudre->NombreDeContraintes, origin, destination); + } + + builder.updateHourWithinWeek(pdt); + builder.include(Variable::NTCDirect(interco), 1.0) + .include(Variable::IntercoDirectCost(interco), -1.0) + .include(Variable::IntercoIndirectCost(interco), 1.0); + + // if (CoutDeTransport.IntercoGereeAvecLoopFlow) + // builder.equalTo( + // problemeHebdo->ValeursDeNTC[pdtHebdo].ValeurDeLoopFlowOrigineVersExtremite[interco]); + // else + // builder.equalTo(0.); + builder.equalTo(); + + builder.build(); + } +} diff --git a/src/solver/optimisation/FlowDissociation.h b/src/solver/optimisation/FlowDissociation.h new file mode 100644 index 0000000000..377a72f6cb --- /dev/null +++ b/src/solver/optimisation/FlowDissociation.h @@ -0,0 +1,8 @@ +#pragma once +#include "constraint_builder.h" + +struct FlowDissociation : public Constraint +{ + using Constraint::Constraint; + void add(int pdt, int interco); +}; diff --git a/src/solver/optimisation/HydroPower.cpp b/src/solver/optimisation/HydroPower.cpp new file mode 100644 index 0000000000..e6dfad59f9 --- /dev/null +++ b/src/solver/optimisation/HydroPower.cpp @@ -0,0 +1,45 @@ +#include "HydroPower.h" + +void HydroPower::add(int pays) +{ + bool presenceHydro + = problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDHydrauliqueModulable; + bool TurbEntreBornes = problemeHebdo->CaracteristiquesHydrauliques[pays].TurbinageEntreBornes; + if (!presenceHydro || TurbEntreBornes) + return; + + const int NombreDePasDeTempsPourUneOptimisation + = problemeHebdo->NombreDePasDeTempsPourUneOptimisation; + + if (bool presencePompage + = problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDePompageModulable) + { + problemeHebdo->NumeroDeContrainteEnergieHydraulique[pays] + = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; + + const double pumpingRatio = problemeHebdo->CaracteristiquesHydrauliques[pays].PumpingRatio; + for (int pdt = 0; pdt < NombreDePasDeTempsPourUneOptimisation; pdt++) + { + builder.updateHourWithinWeek(pdt); + builder.include(Variable::HydProd(pays), 1.0) + .include(Variable::Pumping(pays), -pumpingRatio); + } + } + else + { + for (int pdt = 0; pdt < NombreDePasDeTempsPourUneOptimisation; pdt++) + { + builder.updateHourWithinWeek(pdt); + builder.include(Variable::HydProd(pays), 1.0); + } + } + builder.equalTo(); + { + ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, + problemeHebdo->NamedProblems); + namer.UpdateArea(problemeHebdo->NomsDesPays[pays]); + namer.UpdateTimeStep(problemeHebdo->weekInTheYear); + namer.HydroPower(problemeHebdo->ProblemeAResoudre->NombreDeContraintes); + } + builder.build(); +} diff --git a/src/solver/optimisation/HydroPower.h b/src/solver/optimisation/HydroPower.h new file mode 100644 index 0000000000..f3221b6c90 --- /dev/null +++ b/src/solver/optimisation/HydroPower.h @@ -0,0 +1,8 @@ +#pragma once +#include "constraint_builder.h" + +struct HydroPower : public Constraint +{ + using Constraint::Constraint; + void add(int pays); +}; diff --git a/src/solver/optimisation/HydroPowerSmoothingUsingVariationMaxDown.cpp b/src/solver/optimisation/HydroPowerSmoothingUsingVariationMaxDown.cpp new file mode 100644 index 0000000000..99a3d97bbb --- /dev/null +++ b/src/solver/optimisation/HydroPowerSmoothingUsingVariationMaxDown.cpp @@ -0,0 +1,30 @@ +#include "HydroPowerSmoothingUsingVariationMaxDown.h" + +void HydroPowerSmoothingUsingVariationMaxDown::add(int pays, int pdt) +{ + if (!problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDHydrauliqueModulable) + { + return; + } + + const int nombreDePasDeTempsPourUneOptimisation + = problemeHebdo->NombreDePasDeTempsPourUneOptimisation; + + const auto& CorrespondanceVarNativesVarOptim + = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt]; + int nombreDeTermes = 0; + + ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, + problemeHebdo->NamedProblems); + namer.UpdateArea(problemeHebdo->NomsDesPays[pays]); + namer.UpdateTimeStep(problemeHebdo->weekInTheYear * 168 + pdt); + namer.HydroPowerSmoothingUsingVariationMaxDown( + problemeHebdo->ProblemeAResoudre->NombreDeContraintes); + + builder.updateHourWithinWeek(pdt) + .include(Variable::HydProd(pays), 1.0) + .updateHourWithinWeek(0) + .include(Variable::HydProdDown(pays), -1.0) + .lessThan() + .build(); +} \ No newline at end of file diff --git a/src/solver/optimisation/HydroPowerSmoothingUsingVariationMaxDown.h b/src/solver/optimisation/HydroPowerSmoothingUsingVariationMaxDown.h new file mode 100644 index 0000000000..e348b8539d --- /dev/null +++ b/src/solver/optimisation/HydroPowerSmoothingUsingVariationMaxDown.h @@ -0,0 +1,8 @@ +#pragma once +#include "constraint_builder.h" + +struct HydroPowerSmoothingUsingVariationMaxDown : public Constraint +{ + using Constraint::Constraint; + void add(int pays, int pdt); +}; \ No newline at end of file diff --git a/src/solver/optimisation/HydroPowerSmoothingUsingVariationMaxUp.cpp b/src/solver/optimisation/HydroPowerSmoothingUsingVariationMaxUp.cpp new file mode 100644 index 0000000000..e89fa2a7b4 --- /dev/null +++ b/src/solver/optimisation/HydroPowerSmoothingUsingVariationMaxUp.cpp @@ -0,0 +1,30 @@ +#include "HydroPowerSmoothingUsingVariationMaxUp.h" + +void HydroPowerSmoothingUsingVariationMaxUp::add(int pays, int pdt) +{ + if (!problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDHydrauliqueModulable) + { + return; + } + + const int nombreDePasDeTempsPourUneOptimisation + = problemeHebdo->NombreDePasDeTempsPourUneOptimisation; + + const auto& CorrespondanceVarNativesVarOptim + = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt]; + int nombreDeTermes = 0; + + ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, + problemeHebdo->NamedProblems); + namer.UpdateArea(problemeHebdo->NomsDesPays[pays]); + namer.UpdateTimeStep(problemeHebdo->weekInTheYear * 168 + pdt); + namer.HydroPowerSmoothingUsingVariationMaxUp( + problemeHebdo->ProblemeAResoudre->NombreDeContraintes); + + builder.updateHourWithinWeek(pdt) + .include(Variable::HydProd(pays), 1.0) + .updateHourWithinWeek(0) + .include(Variable::HydProdUp(pays), -1.0) + .greaterThan() + .build(); +} \ No newline at end of file diff --git a/src/solver/optimisation/HydroPowerSmoothingUsingVariationMaxUp.h b/src/solver/optimisation/HydroPowerSmoothingUsingVariationMaxUp.h new file mode 100644 index 0000000000..b6cf0d2ef2 --- /dev/null +++ b/src/solver/optimisation/HydroPowerSmoothingUsingVariationMaxUp.h @@ -0,0 +1,8 @@ +#pragma once +#include "constraint_builder.h" + +struct HydroPowerSmoothingUsingVariationMaxUp : public Constraint +{ + using Constraint::Constraint; + void add(int pays, int pdt); +}; \ No newline at end of file diff --git a/src/solver/optimisation/HydroPowerSmoothingUsingVariationSum.cpp b/src/solver/optimisation/HydroPowerSmoothingUsingVariationSum.cpp new file mode 100644 index 0000000000..29813fcf74 --- /dev/null +++ b/src/solver/optimisation/HydroPowerSmoothingUsingVariationSum.cpp @@ -0,0 +1,38 @@ +#include "HydroPowerSmoothingUsingVariationSum.h" + +void HydroPowerSmoothingUsingVariationSum::add(int pays) +{ + if (!problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDHydrauliqueModulable) + { + return; + } + + const int nombreDePasDeTempsPourUneOptimisation + = problemeHebdo->NombreDePasDeTempsPourUneOptimisation; + for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) + { + const auto& CorrespondanceVarNativesVarOptim + = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt]; + int nombreDeTermes = 0; + + int pdt1 = pdt + 1; + if (pdt1 >= nombreDePasDeTempsPourUneOptimisation) + pdt1 = 0; + ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, + problemeHebdo->NamedProblems); + namer.UpdateArea(problemeHebdo->NomsDesPays[pays]); + namer.UpdateTimeStep(problemeHebdo->weekInTheYear * 168 + pdt); + namer.HydroPowerSmoothingUsingVariationSum( + problemeHebdo->ProblemeAResoudre->NombreDeContraintes); + + builder.updateHourWithinWeek(pdt) + .include(Variable::HydProd(pays), 1.0) + .updateHourWithinWeek(pdt1) /* /!\ Re-check*/ + .include(Variable::HydProd(pays), -1.0) + .updateHourWithinWeek(pdt) /* /!\ Re-check*/ + .include(Variable::HydProdDown(pays), -1.0) + .include(Variable::HydProdUp(pays), 1.0) + .equalTo() + .build(); + } +} \ No newline at end of file diff --git a/src/solver/optimisation/HydroPowerSmoothingUsingVariationSum.h b/src/solver/optimisation/HydroPowerSmoothingUsingVariationSum.h new file mode 100644 index 0000000000..bcef480118 --- /dev/null +++ b/src/solver/optimisation/HydroPowerSmoothingUsingVariationSum.h @@ -0,0 +1,8 @@ + +#pragma once +#include "constraint_builder.h" +struct HydroPowerSmoothingUsingVariationSum : public Constraint +{ + using Constraint::Constraint; + void add(int pays); +}; \ No newline at end of file diff --git a/src/solver/optimisation/MaxHydroPower.cpp b/src/solver/optimisation/MaxHydroPower.cpp new file mode 100644 index 0000000000..cdf0d0eb77 --- /dev/null +++ b/src/solver/optimisation/MaxHydroPower.cpp @@ -0,0 +1,32 @@ +#include "MaxHydroPower.h" + +void MaxHydroPower::add(int pays) +{ + bool presenceHydro + = problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDHydrauliqueModulable; + bool TurbEntreBornes = problemeHebdo->CaracteristiquesHydrauliques[pays].TurbinageEntreBornes; + if (presenceHydro + && (TurbEntreBornes + || problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDePompageModulable)) + { + problemeHebdo->NumeroDeContrainteMaxEnergieHydraulique[pays] + = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; + + const int NombreDePasDeTempsPourUneOptimisation + = problemeHebdo->NombreDePasDeTempsPourUneOptimisation; + + for (int pdt = 0; pdt < NombreDePasDeTempsPourUneOptimisation; pdt++) + { + builder.updateHourWithinWeek(pdt); + builder.include(Variable::HydProd(pays), 1.0); + } + + ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, + problemeHebdo->NamedProblems); + namer.UpdateArea(problemeHebdo->NomsDesPays[pays]); + namer.UpdateTimeStep(problemeHebdo->weekInTheYear); + namer.MaxHydroPower(problemeHebdo->ProblemeAResoudre->NombreDeContraintes); + + builder.lessThan().build(); + } +} \ No newline at end of file diff --git a/src/solver/optimisation/MaxHydroPower.h b/src/solver/optimisation/MaxHydroPower.h new file mode 100644 index 0000000000..339a904cf0 --- /dev/null +++ b/src/solver/optimisation/MaxHydroPower.h @@ -0,0 +1,8 @@ +#pragma once +#include "constraint_builder.h" + +struct MaxHydroPower : public Constraint +{ + using Constraint::Constraint; + void add(int pays); +}; \ No newline at end of file diff --git a/src/solver/optimisation/MaxPumping.cpp b/src/solver/optimisation/MaxPumping.cpp new file mode 100644 index 0000000000..2a37007d21 --- /dev/null +++ b/src/solver/optimisation/MaxPumping.cpp @@ -0,0 +1,26 @@ +#include "MaxPumping.h" + +void MaxPumping::add(int pays) +{ + if (problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDePompageModulable) + { + problemeHebdo->NumeroDeContrainteMaxPompage[pays] + = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; + + const int NombreDePasDeTempsPourUneOptimisation + = problemeHebdo->NombreDePasDeTempsPourUneOptimisation; + + for (int pdt = 0; pdt < NombreDePasDeTempsPourUneOptimisation; pdt++) + { + builder.updateHourWithinWeek(pdt); + builder.include(Variable::Pumping(pays), 1.0); + } + + ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, + problemeHebdo->NamedProblems); + namer.UpdateArea(problemeHebdo->NomsDesPays[pays]); + namer.UpdateTimeStep(problemeHebdo->weekInTheYear); + namer.MaxPumping(problemeHebdo->ProblemeAResoudre->NombreDeContraintes); + builder.lessThan().build(); + } +} \ No newline at end of file diff --git a/src/solver/optimisation/MaxPumping.h b/src/solver/optimisation/MaxPumping.h new file mode 100644 index 0000000000..274e5a1807 --- /dev/null +++ b/src/solver/optimisation/MaxPumping.h @@ -0,0 +1,8 @@ +#pragma once +#include "constraint_builder.h" + +struct MaxPumping : public Constraint +{ + using Constraint::Constraint; + void add(int pays); +}; \ No newline at end of file diff --git a/src/solver/optimisation/MinHydroPower.cpp b/src/solver/optimisation/MinHydroPower.cpp new file mode 100644 index 0000000000..435c76cfea --- /dev/null +++ b/src/solver/optimisation/MinHydroPower.cpp @@ -0,0 +1,32 @@ +#include "MinHydroPower.h" + +void MinHydroPower::add(int pays) +{ + bool presenceHydro + = problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDHydrauliqueModulable; + bool TurbEntreBornes = problemeHebdo->CaracteristiquesHydrauliques[pays].TurbinageEntreBornes; + if (presenceHydro + && (TurbEntreBornes + || problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDePompageModulable)) + { + problemeHebdo->NumeroDeContrainteMinEnergieHydraulique[pays] + = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; + + const int NombreDePasDeTempsPourUneOptimisation + = problemeHebdo->NombreDePasDeTempsPourUneOptimisation; + + ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, + problemeHebdo->NamedProblems); + namer.UpdateArea(problemeHebdo->NomsDesPays[pays]); + namer.UpdateTimeStep(problemeHebdo->weekInTheYear); + namer.MinHydroPower(problemeHebdo->ProblemeAResoudre->NombreDeContraintes); + for (int pdt = 0; pdt < NombreDePasDeTempsPourUneOptimisation; pdt++) + { + builder.updateHourWithinWeek(pdt); + builder.include(Variable::HydProd(pays), 1.0); + } + // const double rhs = problemeHebdo->CaracteristiquesHydrauliques[pays] + // .MinEnergieHydrauParIntervalleOptimise[NumeroDeLIntervalle]; + builder.greaterThan().build(); + } +} diff --git a/src/solver/optimisation/MinHydroPower.h b/src/solver/optimisation/MinHydroPower.h new file mode 100644 index 0000000000..50fd96e3e4 --- /dev/null +++ b/src/solver/optimisation/MinHydroPower.h @@ -0,0 +1,8 @@ +#pragma once +#include "constraint_builder.h" + +struct MinHydroPower : public Constraint +{ + using Constraint::Constraint; + void add(int pays); +}; diff --git a/src/solver/optimisation/ShortTermStorageLevel.cpp b/src/solver/optimisation/ShortTermStorageLevel.cpp new file mode 100644 index 0000000000..5fb9838e57 --- /dev/null +++ b/src/solver/optimisation/ShortTermStorageLevel.cpp @@ -0,0 +1,41 @@ +#include "ShortTermStorageLevel.h" + +void ShortTermStorageLevel::add(int pdt, int pays) +{ + // TODO improve this + ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, + problemeHebdo->NamedProblems); + /** can be done without this --- keep it for now**/ + CORRESPONDANCES_DES_VARIABLES& CorrespondanceVarNativesVarOptim + = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt]; + CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim + = problemeHebdo->CorrespondanceCntNativesCntOptim[pdt]; + + /******/ + + const int hourInTheYear = problemeHebdo->weekInTheYear * 168 + pdt; + namer.UpdateTimeStep(hourInTheYear); + namer.UpdateArea(problemeHebdo->NomsDesPays[pays]); + + builder.updateHourWithinWeek(pdt); + for (const auto& storage : problemeHebdo->ShortTermStorage[pays]) + { + // L[h] - L[h-1] - efficiency * injection[h] + withdrawal[h] = inflows[h] + namer.ShortTermStorageLevel(problemeHebdo->ProblemeAResoudre->NombreDeContraintes, + storage.name); + const auto index = storage.clusterGlobalIndex; + CorrespondanceCntNativesCntOptim.ShortTermStorageLevelConstraint[index] + = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; + + builder.include(Variable::ShortTermStorageLevel(index), 1.0) + .include(Variable::ShortTermStorageLevel(index), + -1.0, + -1, + true, + problemeHebdo->NombreDePasDeTempsPourUneOptimisation) + .include(Variable::ShortTermStorageInjection(index), -1.0 * storage.efficiency) + .include(Variable::ShortTermStorageWithdrawal(index), 1.0) + .equalTo() + .build(); + } +} diff --git a/src/solver/optimisation/ShortTermStorageLevel.h b/src/solver/optimisation/ShortTermStorageLevel.h new file mode 100644 index 0000000000..35eb41fc8d --- /dev/null +++ b/src/solver/optimisation/ShortTermStorageLevel.h @@ -0,0 +1,7 @@ +#pragma once +#include "constraint_builder.h" +struct ShortTermStorageLevel : public Constraint +{ + using Constraint::Constraint; + void add(int pdt, int pays); +}; diff --git a/src/solver/optimisation/constraint_builder.cpp b/src/solver/optimisation/constraint_builder.cpp new file mode 100644 index 0000000000..af7cf18562 --- /dev/null +++ b/src/solver/optimisation/constraint_builder.cpp @@ -0,0 +1,20 @@ +#include "constraint_builder.h" + +void ConstraintBuilder::build() +{ + std::vector& Pi = problemeAResoudre.Pi; + std::vector& Colonne = problemeAResoudre.Colonne; + // TODO check operator_ + if (nombreDeTermes_ > 0) + { + // // RHS + // { + // const int idx = problemeAResoudre.NombreDeContraintes; + // problemeAResoudre.SecondMembre[idx] = rhs_; + // } + // Matrix + OPT_ChargerLaContrainteDansLaMatriceDesContraintes( + &problemeAResoudre, Pi, Colonne, nombreDeTermes_, operator_); + } + nombreDeTermes_ = 0; +} diff --git a/src/solver/optimisation/constraint_builder.h b/src/solver/optimisation/constraint_builder.h new file mode 100644 index 0000000000..0bb4ceabaf --- /dev/null +++ b/src/solver/optimisation/constraint_builder.h @@ -0,0 +1,442 @@ +#pragma once + +#include +#include "opt_structure_probleme_a_resoudre.h" +#include "opt_rename_problem.h" +#include "opt_fonctions.h" + +// TODO remove relative include +#include "../simulation/sim_structure_probleme_economique.h" + +#include +#include + +namespace Variable +{ +struct SingleIndex +{ + SingleIndex(unsigned index) : index(index) + { + } + unsigned index; +}; + +struct DispatchableProduction : public SingleIndex +{ + using SingleIndex::SingleIndex; +}; +struct NODU : public SingleIndex +{ + using SingleIndex::SingleIndex; +}; +struct NumberStoppingDispatchableUnits : public SingleIndex +{ + using SingleIndex::SingleIndex; +}; +struct NumberStartingDispatchableUnits : public SingleIndex +{ + using SingleIndex::SingleIndex; +}; +struct NumberBreakingDownDispatchableUnits : public SingleIndex +{ + using SingleIndex::SingleIndex; +}; + +struct NTCDirect : public SingleIndex +{ + using SingleIndex::SingleIndex; +}; +struct IntercoDirectCost : public SingleIndex +{ + using SingleIndex::SingleIndex; +}; +struct IntercoIndirectCost : public SingleIndex +{ + using SingleIndex::SingleIndex; +}; + +struct ShortTermStorageInjection : public SingleIndex +{ + using SingleIndex::SingleIndex; +}; +struct ShortTermStorageWithdrawal : public SingleIndex +{ + using SingleIndex::SingleIndex; +}; +struct ShortTermStorageLevel : public SingleIndex +{ + using SingleIndex::SingleIndex; +}; + +struct HydProd : public SingleIndex +{ + using SingleIndex::SingleIndex; +}; +struct HydProdDown : public SingleIndex +{ + using SingleIndex::SingleIndex; +}; +struct HydProdUp : public SingleIndex +{ + using SingleIndex::SingleIndex; +}; +struct Pumping : public SingleIndex +{ + using SingleIndex::SingleIndex; +}; +struct HydroLevel : public SingleIndex +{ + using SingleIndex::SingleIndex; +}; +struct Overflow : public SingleIndex +{ + using SingleIndex::SingleIndex; +}; +struct FinalStorage : public SingleIndex +{ + using SingleIndex::SingleIndex; +}; +struct PositiveUnsuppliedEnergy : public SingleIndex +{ + using SingleIndex::SingleIndex; +}; +struct NegativeUnsuppliedEnergy : public SingleIndex +{ + using SingleIndex::SingleIndex; +}; + +struct LayerStorage +{ + LayerStorage(unsigned area, unsigned layer) : area(area), layer(layer) + { + } + unsigned area, layer; +}; + +using Variant = std::variant; + +class Visitor +{ +public: + Visitor(const CORRESPONDANCES_DES_VARIABLES& nativeOptimVar, + const std::vector& NumeroDeVariableStockFinal, + const std::vector>& NumeroDeVariableDeTrancheDeStock) : + nativeOptimVar(nativeOptimVar), + NumeroDeVariableStockFinal(NumeroDeVariableStockFinal), + NumeroDeVariableDeTrancheDeStock(NumeroDeVariableDeTrancheDeStock) + { + } + + int operator()(const DispatchableProduction& v) const + { + return nativeOptimVar.NumeroDeVariableDuPalierThermique[v.index]; + } + int operator()(const NODU& v) const + { + return nativeOptimVar.NumeroDeVariableDuNombreDeGroupesEnMarcheDuPalierThermique[v.index]; + } + int operator()(const NumberStoppingDispatchableUnits& v) const + { + return nativeOptimVar + .NumeroDeVariableDuNombreDeGroupesQuiSArretentDuPalierThermique[v.index]; + } + int operator()(const NumberStartingDispatchableUnits& v) const + { + return nativeOptimVar + .NumeroDeVariableDuNombreDeGroupesQuiDemarrentDuPalierThermique[v.index]; + } + int operator()(const NumberBreakingDownDispatchableUnits& v) const + { + return nativeOptimVar + .NumeroDeVariableDuNombreDeGroupesQuiTombentEnPanneDuPalierThermique[v.index]; + } + int operator()(const NTCDirect& v) const + { + return nativeOptimVar.NumeroDeVariableDeLInterconnexion[v.index]; + } + int operator()(const IntercoDirectCost& v) const + { + return nativeOptimVar.NumeroDeVariableCoutOrigineVersExtremiteDeLInterconnexion[v.index]; + } + int operator()(const IntercoIndirectCost& v) const + { + return nativeOptimVar.NumeroDeVariableCoutExtremiteVersOrigineDeLInterconnexion[v.index]; + } + int operator()(const ShortTermStorageInjection& v) const + { + return nativeOptimVar.SIM_ShortTermStorage.InjectionVariable[v.index]; + } + int operator()(const ShortTermStorageWithdrawal& v) const + { + return nativeOptimVar.SIM_ShortTermStorage.WithdrawalVariable[v.index]; + } + int operator()(const ShortTermStorageLevel& v) const + { + return nativeOptimVar.SIM_ShortTermStorage.LevelVariable[v.index]; + } + int operator()(const HydProd& v) const + { + return nativeOptimVar.NumeroDeVariablesDeLaProdHyd[v.index]; + } + int operator()(const HydProdDown& v) const + { + return nativeOptimVar.NumeroDeVariablesVariationHydALaBaisse[v.index]; + } + int operator()(const HydProdUp& v) const + { + return nativeOptimVar.NumeroDeVariablesVariationHydALaHausse[v.index]; + } + int operator()(const Pumping& v) const + { + return nativeOptimVar.NumeroDeVariablesDePompage[v.index]; + } + int operator()(const HydroLevel& v) const + { + return nativeOptimVar.NumeroDeVariablesDeNiveau[v.index]; + } + int operator()(const Overflow& v) const + { + return nativeOptimVar.NumeroDeVariablesDeDebordement[v.index]; + } + int operator()(const FinalStorage& v) const + { + return NumeroDeVariableStockFinal[v.index]; + } + int operator()(const LayerStorage& v) const + { + return NumeroDeVariableDeTrancheDeStock[v.area][v.layer]; + } + int operator()(const PositiveUnsuppliedEnergy& v) const + { + return nativeOptimVar.NumeroDeVariableDefaillancePositive[v.index]; + } + int operator()(const NegativeUnsuppliedEnergy& v) const + { + return nativeOptimVar.NumeroDeVariableDefaillanceNegative[v.index]; + } + +private: + const CORRESPONDANCES_DES_VARIABLES& nativeOptimVar; + const std::vector& NumeroDeVariableStockFinal; + const std::vector>& NumeroDeVariableDeTrancheDeStock; +}; +} // namespace Variable + +// enum class Constraint { +// FlowDissociation, +// AreaBalance, +// FictiveLoads, +// HydroPower, +// HydroPowerSmoothingUsingVariationSum, +// HydroPowerSmoothingUsingVariationMaxDown, +// HydroPowerSmoothingUsingVariationMaxUp, +// MinHydroPower, +// MaxHydroPower, +// MaxPumping, +// AreaHydroLevel, +// FinalStockEquivalent, +// FinalStockExpression, +// NbUnitsOutageLessThanNbUnitsStop, +// NbDispUnitsMinBoundSinceMinUpTime, +// MinDownTime, +// PMaxDispatchableGeneration, +// PMinDispatchableGeneration, +// ConsistenceNODU, +// ShortTermStorageLevel, +// BindingConstraintHour, +// BindingConstraintDay, +// BindingConstraintWeek +// }; + +class ConstraintBuilder +{ +public: + ConstraintBuilder( + PROBLEME_HEBDO& problemeHebdo, + const std::vector& CorrespondanceVarNativesVarOptim) : + problemeHebdo(problemeHebdo), + problemeAResoudre(*problemeHebdo.ProblemeAResoudre), + varNative(CorrespondanceVarNativesVarOptim) + { + } + + ConstraintBuilder& updateHourWithinWeek(unsigned hour) + { + hourInWeek_ = hour; + return *this; + } + +private: + int getVariableIndex(const Variable::Variant& variable, int shift, bool wrap, int delta) const + { + int pdt = hourInWeek_ + shift; + const int nbTimeSteps = problemeHebdo.NombreDePasDeTempsPourUneOptimisation; + // if (wrap) + // { + // pdt %= nbTimeSteps; + // if (pdt < 0) + // pdt += problemeHebdo.NombreDePasDeTemps; + // } + // if (pdt < 0 || pdt >= nbTimeSteps) + // { + // return -1; + // } + + if (wrap) + { + if (shift >= 0) + { + pdt = (pdt) % nbTimeSteps; + } + else + { + pdt = (pdt + delta) % nbTimeSteps; + } + } + const Variable::Visitor visitor(varNative[pdt], + problemeHebdo.NumeroDeVariableStockFinal, + problemeHebdo.NumeroDeVariableDeTrancheDeStock); + return std::visit(visitor, variable); + } + +public: + ConstraintBuilder& include(Variable::Variant var, + double coeff, + int shift = 0, + bool wrap = false, + int delta = 0) + { + std::vector& Pi = problemeAResoudre.Pi; + std::vector& Colonne = problemeAResoudre.Colonne; + int varIndex = getVariableIndex(var, shift, wrap, delta); + if (varIndex >= 0) + { + Pi[nombreDeTermes_] = coeff; + Colonne[nombreDeTermes_] = varIndex; + nombreDeTermes_++; + } + return *this; + } + + ConstraintBuilder& operatorRHS(char op) + { + if (op == '<' || op == '=' || op == '>') + { + operator_ = op; + } + else + throw std::runtime_error("Invalid operator"); + + return *this; + } + // ConstraintBuilder& operatorRHS(char op, double rhs) + // { + // if (op == '<' || op == '=' || op == '>') + // { + // operator_ = op; + // rhs_ = rhs; + // } + // else + // throw std::runtime_error("Invalid operator"); + + // return *this; + // } + + ConstraintBuilder& equalTo() + { + operator_ = '='; + return *this; + } + ConstraintBuilder& lessThan() + { + operator_ = '<'; + return *this; + } + ConstraintBuilder& greaterThan() + { + operator_ = '>'; + return *this; + } + + // ConstraintBuilder& equalTo(double rhs) + // { + // operator_ = '='; + // rhs_ = rhs; + // return *this; + // } + // ConstraintBuilder& lessThan(double rhs) + // { + // operator_ = '<'; + // rhs_ = rhs; + // return *this; + // } + // ConstraintBuilder& greaterThan(double rhs) + // { + // operator_ = '>'; + // rhs_ = rhs; + // return *this; + // } + + void build(); + +private: + PROBLEME_HEBDO& problemeHebdo; + PROBLEME_ANTARES_A_RESOUDRE& problemeAResoudre; + const std::vector& varNative; + + unsigned int hourInWeek_ = 0; + + char operator_; + double rhs_ = 0; + int nombreDeTermes_ = 0; +}; + +class Constraint +{ +public: + Constraint(PROBLEME_HEBDO* problemeHebdo) : + problemeHebdo(problemeHebdo), + builder(*problemeHebdo, problemeHebdo->CorrespondanceVarNativesVarOptim) + { + } + +protected: + PROBLEME_HEBDO* problemeHebdo; // TODO remove + ConstraintBuilder builder; +}; + +// #TODO move this function to a suitable place +// Helper functions +inline void exportPaliers(const PROBLEME_HEBDO& problemeHebdo, + ConstraintBuilder& constraintBuilder, + int pays) +{ + const PALIERS_THERMIQUES& PaliersThermiquesDuPays = problemeHebdo.PaliersThermiquesDuPays[pays]; + + for (int index = 0; index < PaliersThermiquesDuPays.NombreDePaliersThermiques; index++) + { + const int palier + = PaliersThermiquesDuPays.NumeroDuPalierDansLEnsembleDesPaliersThermiques[index]; + constraintBuilder.include(Variable::DispatchableProduction(palier), -1.0); + } +} 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 d52fc1dbc2..a144429b7f 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 @@ -30,6 +30,7 @@ #include "opt_fonctions.h" #include "opt_rename_problem.h" #include "sim_structure_probleme_economique.h" +#include "AreaBalance.h" #include @@ -182,83 +183,87 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim = problemeHebdo->CorrespondanceCntNativesCntOptim[pdt]; + AreaBalance areaBalance(problemeHebdo); for (uint32_t pays = 0; pays < problemeHebdo->NombreDePays; pays++) { int nombreDeTermes = 0; - - int interco = problemeHebdo->IndexDebutIntercoOrigine[pays]; + areaBalance.add(pdt, pays); + // int interco = problemeHebdo->IndexDebutIntercoOrigine[pays]; constraintNamer.UpdateArea(problemeHebdo->NomsDesPays[pays]); - while (interco >= 0) - { - var = CorrespondanceVarNativesVarOptim.NumeroDeVariableDeLInterconnexion[interco]; - if (var >= 0) - { - Pi[nombreDeTermes] = 1.0; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } - interco = problemeHebdo->IndexSuivantIntercoOrigine[interco]; - } - interco = problemeHebdo->IndexDebutIntercoExtremite[pays]; - while (interco >= 0) - { - var = CorrespondanceVarNativesVarOptim.NumeroDeVariableDeLInterconnexion[interco]; - if (var >= 0) - { - Pi[nombreDeTermes] = -1.0; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } - interco = problemeHebdo->IndexSuivantIntercoExtremite[interco]; - } - - exportPaliers( - *problemeHebdo, CorrespondanceVarNativesVarOptim, pays, nombreDeTermes, Pi, Colonne); - - var = CorrespondanceVarNativesVarOptim.NumeroDeVariablesDeLaProdHyd[pays]; - if (var >= 0) - { - Pi[nombreDeTermes] = -1.0; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } - - var = CorrespondanceVarNativesVarOptim.NumeroDeVariablesDePompage[pays]; - if (var >= 0) - { - Pi[nombreDeTermes] = 1.0; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } - - var = CorrespondanceVarNativesVarOptim.NumeroDeVariableDefaillancePositive[pays]; - if (var >= 0) - { - Pi[nombreDeTermes] = -1.0; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } - var = CorrespondanceVarNativesVarOptim.NumeroDeVariableDefaillanceNegative[pays]; - if (var >= 0) - { - Pi[nombreDeTermes] = 1.0; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } - - shortTermStorageBalance(problemeHebdo->ShortTermStorage[pays], - CorrespondanceVarNativesVarOptim, - nombreDeTermes, - Pi, - Colonne); - - CorrespondanceCntNativesCntOptim.NumeroDeContrainteDesBilansPays[pays] - = ProblemeAResoudre->NombreDeContraintes; - - constraintNamer.AreaBalance(ProblemeAResoudre->NombreDeContraintes); - OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '='); + // while (interco >= 0) + // { + // var = + // CorrespondanceVarNativesVarOptim.NumeroDeVariableDeLInterconnexion[interco]; if + // (var >= 0) + // { + // Pi[nombreDeTermes] = 1.0; + // Colonne[nombreDeTermes] = var; + // nombreDeTermes++; + // } + // interco = problemeHebdo->IndexSuivantIntercoOrigine[interco]; + // } + // interco = problemeHebdo->IndexDebutIntercoExtremite[pays]; + // while (interco >= 0) + // { + // var = + // CorrespondanceVarNativesVarOptim.NumeroDeVariableDeLInterconnexion[interco]; if + // (var >= 0) + // { + // Pi[nombreDeTermes] = -1.0; + // Colonne[nombreDeTermes] = var; + // nombreDeTermes++; + // } + // interco = problemeHebdo->IndexSuivantIntercoExtremite[interco]; + // } + + // exportPaliers( + // *problemeHebdo, CorrespondanceVarNativesVarOptim, pays, nombreDeTermes, Pi, + // Colonne); + + // var = CorrespondanceVarNativesVarOptim.NumeroDeVariablesDeLaProdHyd[pays]; + // if (var >= 0) + // { + // Pi[nombreDeTermes] = -1.0; + // Colonne[nombreDeTermes] = var; + // nombreDeTermes++; + // } + + // var = CorrespondanceVarNativesVarOptim.NumeroDeVariablesDePompage[pays]; + // if (var >= 0) + // { + // Pi[nombreDeTermes] = 1.0; + // Colonne[nombreDeTermes] = var; + // nombreDeTermes++; + // } + + // var = CorrespondanceVarNativesVarOptim.NumeroDeVariableDefaillancePositive[pays]; + // if (var >= 0) + // { + // Pi[nombreDeTermes] = -1.0; + // Colonne[nombreDeTermes] = var; + // nombreDeTermes++; + // } + // var = CorrespondanceVarNativesVarOptim.NumeroDeVariableDefaillanceNegative[pays]; + // if (var >= 0) + // { + // Pi[nombreDeTermes] = 1.0; + // Colonne[nombreDeTermes] = var; + // nombreDeTermes++; + // } + + // shortTermStorageBalance(problemeHebdo->ShortTermStorage[pays], + // CorrespondanceVarNativesVarOptim, + // nombreDeTermes, + // Pi, + // Colonne); + + // CorrespondanceCntNativesCntOptim.NumeroDeContrainteDesBilansPays[pays] + // = ProblemeAResoudre->NombreDeContraintes; + + // constraintNamer.AreaBalance(ProblemeAResoudre->NombreDeContraintes); + // OPT_ChargerLaContrainteDansLaMatriceDesContraintes( + // ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '='); nombreDeTermes = 0; exportPaliers( From bca6733f9703542a25c03dbf387dd63157bc32a1 Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Sat, 2 Sep 2023 20:27:16 +0200 Subject: [PATCH 02/43] add FictitiousLoad --- ...n_matrice_des_contraintes_cas_lineaire.cpp | 48 ++++++++++--------- 1 file changed, 26 insertions(+), 22 deletions(-) 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 a144429b7f..e4154fa6b0 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 @@ -31,6 +31,7 @@ #include "opt_rename_problem.h" #include "sim_structure_probleme_economique.h" #include "AreaBalance.h" +#include "FictitiousLoad.h" #include @@ -184,6 +185,7 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro = problemeHebdo->CorrespondanceCntNativesCntOptim[pdt]; AreaBalance areaBalance(problemeHebdo); + FictitiousLoad fictitiousLoad(problemeHebdo); for (uint32_t pays = 0; pays < problemeHebdo->NombreDePays; pays++) { int nombreDeTermes = 0; @@ -264,32 +266,34 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro // constraintNamer.AreaBalance(ProblemeAResoudre->NombreDeContraintes); // OPT_ChargerLaContrainteDansLaMatriceDesContraintes( // ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '='); - nombreDeTermes = 0; + // nombreDeTermes = 0; - exportPaliers( - *problemeHebdo, CorrespondanceVarNativesVarOptim, pays, nombreDeTermes, Pi, Colonne); - var = CorrespondanceVarNativesVarOptim.NumeroDeVariablesDeLaProdHyd[pays]; - if (var >= 0) - { - Pi[nombreDeTermes] = -problemeHebdo->DefaillanceNegativeUtiliserHydro[pays]; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } + // exportPaliers( + // *problemeHebdo, CorrespondanceVarNativesVarOptim, pays, nombreDeTermes, Pi, + // Colonne); + // var = CorrespondanceVarNativesVarOptim.NumeroDeVariablesDeLaProdHyd[pays]; + // if (var >= 0) + // { + // Pi[nombreDeTermes] = -problemeHebdo->DefaillanceNegativeUtiliserHydro[pays]; + // Colonne[nombreDeTermes] = var; + // nombreDeTermes++; + // } - var = CorrespondanceVarNativesVarOptim.NumeroDeVariableDefaillanceNegative[pays]; - if (var >= 0) - { - Pi[nombreDeTermes] = 1.0; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } + // var = CorrespondanceVarNativesVarOptim.NumeroDeVariableDefaillanceNegative[pays]; + // if (var >= 0) + // { + // Pi[nombreDeTermes] = 1.0; + // Colonne[nombreDeTermes] = var; + // nombreDeTermes++; + // } - CorrespondanceCntNativesCntOptim.NumeroDeContraintePourEviterLesChargesFictives[pays] - = ProblemeAResoudre->NombreDeContraintes; + // CorrespondanceCntNativesCntOptim.NumeroDeContraintePourEviterLesChargesFictives[pays] + // = ProblemeAResoudre->NombreDeContraintes; - constraintNamer.FictiveLoads(ProblemeAResoudre->NombreDeContraintes); - OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '<'); + // constraintNamer.FictiveLoads(ProblemeAResoudre->NombreDeContraintes); + // OPT_ChargerLaContrainteDansLaMatriceDesContraintes( + // ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '<'); + fictitiousLoad.add(pdt, pays); // Short term storage shortTermStorageLevels(problemeHebdo->ShortTermStorage[pays], ProblemeAResoudre, From adbd3631af1ef30ba90797429b6b023f51da5f25 Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Sat, 2 Sep 2023 20:32:20 +0200 Subject: [PATCH 03/43] shortTermStorageLevel --- ...n_matrice_des_contraintes_cas_lineaire.cpp | 257 +++++++++--------- 1 file changed, 131 insertions(+), 126 deletions(-) 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 e4154fa6b0..daf459422c 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 @@ -32,128 +32,131 @@ #include "sim_structure_probleme_economique.h" #include "AreaBalance.h" #include "FictitiousLoad.h" +#include "ShortTermStorageLevel.h" #include using namespace Antares::Data; -void exportPaliers(const PROBLEME_HEBDO& problemeHebdo, - const CORRESPONDANCES_DES_VARIABLES& CorrespondanceVarNativesVarOptim, - int pays, - int& nombreDeTermes, - std::vector& Pi, - std::vector& Colonne) -{ - const PALIERS_THERMIQUES& PaliersThermiquesDuPays = problemeHebdo.PaliersThermiquesDuPays[pays]; - - for (int index = 0; index < PaliersThermiquesDuPays.NombreDePaliersThermiques; index++) - { - const int palier - = PaliersThermiquesDuPays.NumeroDuPalierDansLEnsembleDesPaliersThermiques[index]; - int var = CorrespondanceVarNativesVarOptim.NumeroDeVariableDuPalierThermique[palier]; - if (var >= 0) - { - Pi[nombreDeTermes] = -1.0; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } - } -} - -static void shortTermStorageBalance( - const ::ShortTermStorage::AREA_INPUT& shortTermStorageInput, - const CORRESPONDANCES_DES_VARIABLES& CorrespondanceVarNativesVarOptim, - int& nombreDeTermes, - std::vector& Pi, - std::vector& Colonne) -{ - for (const auto& storage : shortTermStorageInput) - { - const int clusterGlobalIndex = storage.clusterGlobalIndex; - if (const int varInjection = CorrespondanceVarNativesVarOptim.SIM_ShortTermStorage - .InjectionVariable[clusterGlobalIndex]; - varInjection >= 0) - { - Pi[nombreDeTermes] = 1.0; - Colonne[nombreDeTermes] = varInjection; - nombreDeTermes++; - } - - if (const int varWithdrawal = CorrespondanceVarNativesVarOptim.SIM_ShortTermStorage - .WithdrawalVariable[clusterGlobalIndex]; - varWithdrawal >= 0) - { - Pi[nombreDeTermes] = -1.0; - Colonne[nombreDeTermes] = varWithdrawal; - nombreDeTermes++; - } - } -} - -static void shortTermStorageLevels( - const ::ShortTermStorage::AREA_INPUT& shortTermStorageInput, - PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre, - CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim, - std::vector& CorrespondanceVarNativesVarOptim, - std::vector& Pi, - std::vector& Colonne, - int nombreDePasDeTempsPourUneOptimisation, - int pdt, - ConstraintNamer& constraintNamer) -{ - const auto& VarOptimCurrent = CorrespondanceVarNativesVarOptim[pdt]; - // Cycle over the simulation period - const int timestepPrevious - = (pdt - 1 + nombreDePasDeTempsPourUneOptimisation) % nombreDePasDeTempsPourUneOptimisation; - const auto& VarOptimPrevious = CorrespondanceVarNativesVarOptim[timestepPrevious]; - for (auto& storage : shortTermStorageInput) - { - int nombreDeTermes = 0; - const int clusterGlobalIndex = storage.clusterGlobalIndex; - // L[h] - L[h-1] - efficiency * injection[h] + withdrawal[h] = inflows[h] - if (const int varLevel - = VarOptimCurrent.SIM_ShortTermStorage.LevelVariable[clusterGlobalIndex]; - varLevel >= 0) - { - Pi[nombreDeTermes] = 1.0; - Colonne[nombreDeTermes] = varLevel; - nombreDeTermes++; - } - - if (const int varLevel_previous - = VarOptimPrevious.SIM_ShortTermStorage.LevelVariable[clusterGlobalIndex]; - varLevel_previous >= 0) - { - Pi[nombreDeTermes] = -1.0; - Colonne[nombreDeTermes] = varLevel_previous; - nombreDeTermes++; - } - - if (const int varInjection - = VarOptimCurrent.SIM_ShortTermStorage.InjectionVariable[clusterGlobalIndex]; - varInjection >= 0) - { - Pi[nombreDeTermes] = -1.0 * storage.efficiency; - Colonne[nombreDeTermes] = varInjection; - nombreDeTermes++; - } - - if (const int varWithdrawal - = VarOptimCurrent.SIM_ShortTermStorage.WithdrawalVariable[clusterGlobalIndex]; - varWithdrawal >= 0) - { - Pi[nombreDeTermes] = 1.0; - Colonne[nombreDeTermes] = varWithdrawal; - nombreDeTermes++; - } - CorrespondanceCntNativesCntOptim.ShortTermStorageLevelConstraint[clusterGlobalIndex] - = ProblemeAResoudre->NombreDeContraintes; - - constraintNamer.ShortTermStorageLevel(ProblemeAResoudre->NombreDeContraintes, storage.name); - OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '='); - } -} +// // void exportPaliers(const PROBLEME_HEBDO& problemeHebdo, +// // const CORRESPONDANCES_DES_VARIABLES& CorrespondanceVarNativesVarOptim, +// // int pays, +// // int& nombreDeTermes, +// // std::vector& Pi, +// // std::vector& Colonne) +// // { +// // const PALIERS_THERMIQUES& PaliersThermiquesDuPays = +// // problemeHebdo.PaliersThermiquesDuPays[pays]; + +// // for (int index = 0; index < PaliersThermiquesDuPays.NombreDePaliersThermiques; index++) +// // { +// // const int palier +// // = PaliersThermiquesDuPays.NumeroDuPalierDansLEnsembleDesPaliersThermiques[index]; +// // int var = CorrespondanceVarNativesVarOptim.NumeroDeVariableDuPalierThermique[palier]; +// // if (var >= 0) +// // { +// // Pi[nombreDeTermes] = -1.0; +// // Colonne[nombreDeTermes] = var; +// // nombreDeTermes++; +// // } +// // } +// // } + +// static void shortTermStorageBalance( +// const ::ShortTermStorage::AREA_INPUT& shortTermStorageInput, +// const CORRESPONDANCES_DES_VARIABLES& CorrespondanceVarNativesVarOptim, +// int& nombreDeTermes, +// std::vector& Pi, +// std::vector& Colonne) +// { +// for (const auto& storage : shortTermStorageInput) +// { +// const int clusterGlobalIndex = storage.clusterGlobalIndex; +// if (const int varInjection = CorrespondanceVarNativesVarOptim.SIM_ShortTermStorage +// .InjectionVariable[clusterGlobalIndex]; +// varInjection >= 0) +// { +// Pi[nombreDeTermes] = 1.0; +// Colonne[nombreDeTermes] = varInjection; +// nombreDeTermes++; +// } + +// if (const int varWithdrawal = CorrespondanceVarNativesVarOptim.SIM_ShortTermStorage +// .WithdrawalVariable[clusterGlobalIndex]; +// varWithdrawal >= 0) +// { +// Pi[nombreDeTermes] = -1.0; +// Colonne[nombreDeTermes] = varWithdrawal; +// nombreDeTermes++; +// } +// } +// } + +// static void shortTermStorageLevels( +// const ::ShortTermStorage::AREA_INPUT& shortTermStorageInput, +// PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre, +// CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim, +// std::vector& CorrespondanceVarNativesVarOptim, +// std::vector& Pi, +// std::vector& Colonne, +// int nombreDePasDeTempsPourUneOptimisation, +// int pdt, +// ConstraintNamer& constraintNamer) +// { +// const auto& VarOptimCurrent = CorrespondanceVarNativesVarOptim[pdt]; +// // Cycle over the simulation period +// const int timestepPrevious +// = (pdt - 1 + nombreDePasDeTempsPourUneOptimisation) % +// nombreDePasDeTempsPourUneOptimisation; +// const auto& VarOptimPrevious = CorrespondanceVarNativesVarOptim[timestepPrevious]; +// for (auto& storage : shortTermStorageInput) +// { +// int nombreDeTermes = 0; +// const int clusterGlobalIndex = storage.clusterGlobalIndex; +// // L[h] - L[h-1] - efficiency * injection[h] + withdrawal[h] = inflows[h] +// if (const int varLevel +// = VarOptimCurrent.SIM_ShortTermStorage.LevelVariable[clusterGlobalIndex]; +// varLevel >= 0) +// { +// Pi[nombreDeTermes] = 1.0; +// Colonne[nombreDeTermes] = varLevel; +// nombreDeTermes++; +// } + +// if (const int varLevel_previous +// = VarOptimPrevious.SIM_ShortTermStorage.LevelVariable[clusterGlobalIndex]; +// varLevel_previous >= 0) +// { +// Pi[nombreDeTermes] = -1.0; +// Colonne[nombreDeTermes] = varLevel_previous; +// nombreDeTermes++; +// } + +// if (const int varInjection +// = VarOptimCurrent.SIM_ShortTermStorage.InjectionVariable[clusterGlobalIndex]; +// varInjection >= 0) +// { +// Pi[nombreDeTermes] = -1.0 * storage.efficiency; +// Colonne[nombreDeTermes] = varInjection; +// nombreDeTermes++; +// } + +// if (const int varWithdrawal +// = VarOptimCurrent.SIM_ShortTermStorage.WithdrawalVariable[clusterGlobalIndex]; +// varWithdrawal >= 0) +// { +// Pi[nombreDeTermes] = 1.0; +// Colonne[nombreDeTermes] = varWithdrawal; +// nombreDeTermes++; +// } +// CorrespondanceCntNativesCntOptim.ShortTermStorageLevelConstraint[clusterGlobalIndex] +// = ProblemeAResoudre->NombreDeContraintes; + +// constraintNamer.ShortTermStorageLevel(ProblemeAResoudre->NombreDeContraintes, +// storage.name); OPT_ChargerLaContrainteDansLaMatriceDesContraintes( +// ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '='); +// } +// } void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* problemeHebdo, Solver::IResultWriter& writer) { @@ -186,6 +189,7 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro AreaBalance areaBalance(problemeHebdo); FictitiousLoad fictitiousLoad(problemeHebdo); + ShortTermStorageLevel shortTermStorageLevel(problemeHebdo); for (uint32_t pays = 0; pays < problemeHebdo->NombreDePays; pays++) { int nombreDeTermes = 0; @@ -295,15 +299,16 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro // ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '<'); fictitiousLoad.add(pdt, pays); // Short term storage - shortTermStorageLevels(problemeHebdo->ShortTermStorage[pays], - ProblemeAResoudre, - CorrespondanceCntNativesCntOptim, - problemeHebdo->CorrespondanceVarNativesVarOptim, - Pi, - Colonne, - nombreDePasDeTempsPourUneOptimisation, - pdt, - constraintNamer); + // shortTermStorageLevels(problemeHebdo->ShortTermStorage[pays], + // ProblemeAResoudre, + // CorrespondanceCntNativesCntOptim, + // problemeHebdo->CorrespondanceVarNativesVarOptim, + // Pi, + // Colonne, + // nombreDePasDeTempsPourUneOptimisation, + // pdt, + // constraintNamer); + shortTermStorageLevel.add(pdt, pays); } for (uint32_t interco = 0; interco < problemeHebdo->NombreDInterconnexions; interco++) From 79136ac9bbb7b5b6b1bde0d5b0cf1b07b316e48a Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Sat, 2 Sep 2023 20:42:19 +0200 Subject: [PATCH 04/43] flowDissociation --- ...n_matrice_des_contraintes_cas_lineaire.cpp | 83 ++++++++++--------- 1 file changed, 44 insertions(+), 39 deletions(-) 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 daf459422c..7e384c064d 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 @@ -33,6 +33,7 @@ #include "AreaBalance.h" #include "FictitiousLoad.h" #include "ShortTermStorageLevel.h" +#include "FlowDissociation.h" #include @@ -190,6 +191,8 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro AreaBalance areaBalance(problemeHebdo); FictitiousLoad fictitiousLoad(problemeHebdo); ShortTermStorageLevel shortTermStorageLevel(problemeHebdo); + FlowDissociation flowDissociation(problemeHebdo); + for (uint32_t pays = 0; pays < problemeHebdo->NombreDePays; pays++) { int nombreDeTermes = 0; @@ -313,46 +316,48 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro for (uint32_t interco = 0; interco < problemeHebdo->NombreDInterconnexions; interco++) { - if (problemeHebdo->CoutDeTransport[interco].IntercoGereeAvecDesCouts) - { - int nombreDeTermes = 0; - var = CorrespondanceVarNativesVarOptim.NumeroDeVariableDeLInterconnexion[interco]; - if (var >= 0) - { - Pi[nombreDeTermes] = 1.0; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } - var = CorrespondanceVarNativesVarOptim - .NumeroDeVariableCoutOrigineVersExtremiteDeLInterconnexion[interco]; - if (var >= 0) - { - Pi[nombreDeTermes] = -1.0; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } - var = CorrespondanceVarNativesVarOptim - .NumeroDeVariableCoutExtremiteVersOrigineDeLInterconnexion[interco]; - if (var >= 0) - { - Pi[nombreDeTermes] = 1.0; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } + flowDissociation.add(pdt, interco); + // if (problemeHebdo->CoutDeTransport[interco].IntercoGereeAvecDesCouts) + // { + // int nombreDeTermes = 0; + // var = + // CorrespondanceVarNativesVarOptim.NumeroDeVariableDeLInterconnexion[interco]; if + // (var >= 0) + // { + // Pi[nombreDeTermes] = 1.0; + // Colonne[nombreDeTermes] = var; + // nombreDeTermes++; + // } + // var = CorrespondanceVarNativesVarOptim + // .NumeroDeVariableCoutOrigineVersExtremiteDeLInterconnexion[interco]; + // if (var >= 0) + // { + // Pi[nombreDeTermes] = -1.0; + // Colonne[nombreDeTermes] = var; + // nombreDeTermes++; + // } + // var = CorrespondanceVarNativesVarOptim + // .NumeroDeVariableCoutExtremiteVersOrigineDeLInterconnexion[interco]; + // if (var >= 0) + // { + // Pi[nombreDeTermes] = 1.0; + // Colonne[nombreDeTermes] = var; + // nombreDeTermes++; + // } - CorrespondanceCntNativesCntOptim.NumeroDeContrainteDeDissociationDeFlux[interco] - = ProblemeAResoudre->NombreDeContraintes; - const auto origin - = problemeHebdo - ->NomsDesPays[problemeHebdo->PaysOrigineDeLInterconnexion[interco]]; - const auto destination - = problemeHebdo - ->NomsDesPays[problemeHebdo->PaysExtremiteDeLInterconnexion[interco]]; - constraintNamer.FlowDissociation( - ProblemeAResoudre->NombreDeContraintes, origin, destination); - OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '='); - } + // CorrespondanceCntNativesCntOptim.NumeroDeContrainteDeDissociationDeFlux[interco] + // = ProblemeAResoudre->NombreDeContraintes; + // const auto origin + // = problemeHebdo + // ->NomsDesPays[problemeHebdo->PaysOrigineDeLInterconnexion[interco]]; + // const auto destination + // = problemeHebdo + // ->NomsDesPays[problemeHebdo->PaysExtremiteDeLInterconnexion[interco]]; + // constraintNamer.FlowDissociation( + // ProblemeAResoudre->NombreDeContraintes, origin, destination); + // OPT_ChargerLaContrainteDansLaMatriceDesContraintes( + // ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '='); + // } } for (uint32_t cntCouplante = 0; cntCouplante < problemeHebdo->NombreDeContraintesCouplantes; From 60ea81cf332fee9aa5273f4d93e275cfed486975 Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Sat, 2 Sep 2023 22:12:04 +0200 Subject: [PATCH 05/43] bindingConstraintHour --- ...n_matrice_des_contraintes_cas_lineaire.cpp | 153 +++++++++--------- 1 file changed, 78 insertions(+), 75 deletions(-) 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 7e384c064d..3588dfd739 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 @@ -34,6 +34,7 @@ #include "FictitiousLoad.h" #include "ShortTermStorageLevel.h" #include "FlowDissociation.h" +#include "BindingConstraintHour.h" #include @@ -192,6 +193,7 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro FictitiousLoad fictitiousLoad(problemeHebdo); ShortTermStorageLevel shortTermStorageLevel(problemeHebdo); FlowDissociation flowDissociation(problemeHebdo); + BindingConstraintHour bindingConstraintHour(problemeHebdo); for (uint32_t pays = 0; pays < problemeHebdo->NombreDePays; pays++) { @@ -363,90 +365,91 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro for (uint32_t cntCouplante = 0; cntCouplante < problemeHebdo->NombreDeContraintesCouplantes; cntCouplante++) { - const CONTRAINTES_COUPLANTES& MatriceDesContraintesCouplantes - = problemeHebdo->MatriceDesContraintesCouplantes[cntCouplante]; + bindingConstraintHour.add(pdt, cntCouplante); + // const CONTRAINTES_COUPLANTES& MatriceDesContraintesCouplantes + // = problemeHebdo->MatriceDesContraintesCouplantes[cntCouplante]; - if (MatriceDesContraintesCouplantes.TypeDeContrainteCouplante != CONTRAINTE_HORAIRE) - continue; + // if (MatriceDesContraintesCouplantes.TypeDeContrainteCouplante != CONTRAINTE_HORAIRE) + // continue; - int nbInterco - = MatriceDesContraintesCouplantes.NombreDInterconnexionsDansLaContrainteCouplante; - int nombreDeTermes = 0; - for (int index = 0; index < nbInterco; index++) - { - int interco = MatriceDesContraintesCouplantes.NumeroDeLInterconnexion[index]; - double poids = MatriceDesContraintesCouplantes.PoidsDeLInterconnexion[index]; - int Offset = MatriceDesContraintesCouplantes.OffsetTemporelSurLInterco[index]; - int pdt1; + // int nbInterco + // = MatriceDesContraintesCouplantes.NombreDInterconnexionsDansLaContrainteCouplante; + // int nombreDeTermes = 0; + // for (int index = 0; index < nbInterco; index++) + // { + // int interco = MatriceDesContraintesCouplantes.NumeroDeLInterconnexion[index]; + // double poids = MatriceDesContraintesCouplantes.PoidsDeLInterconnexion[index]; + // int Offset = MatriceDesContraintesCouplantes.OffsetTemporelSurLInterco[index]; + // int pdt1; - if (Offset >= 0) - { - pdt1 = (pdt + Offset) % nombreDePasDeTempsPourUneOptimisation; - } - else - { - pdt1 = (pdt + Offset + problemeHebdo->NombreDePasDeTemps) - % nombreDePasDeTempsPourUneOptimisation; - } + // if (Offset >= 0) + // { + // pdt1 = (pdt + Offset) % nombreDePasDeTempsPourUneOptimisation; + // } + // else + // { + // pdt1 = (pdt + Offset + problemeHebdo->NombreDePasDeTemps) + // % nombreDePasDeTempsPourUneOptimisation; + // } - var = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt1] - .NumeroDeVariableDeLInterconnexion[interco]; + // var = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt1] + // .NumeroDeVariableDeLInterconnexion[interco]; - if (var >= 0) - { - Pi[nombreDeTermes] = poids; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } - } + // if (var >= 0) + // { + // Pi[nombreDeTermes] = poids; + // Colonne[nombreDeTermes] = var; + // nombreDeTermes++; + // } + // } - int nbClusters - = MatriceDesContraintesCouplantes.NombreDePaliersDispatchDansLaContrainteCouplante; - for (int index = 0; index < nbClusters; index++) - { - int pays = MatriceDesContraintesCouplantes.PaysDuPalierDispatch[index]; - const PALIERS_THERMIQUES& PaliersThermiquesDuPays - = problemeHebdo->PaliersThermiquesDuPays[pays]; - const int palier - = PaliersThermiquesDuPays.NumeroDuPalierDansLEnsembleDesPaliersThermiques - [MatriceDesContraintesCouplantes.NumeroDuPalierDispatch[index]]; - double poids = MatriceDesContraintesCouplantes.PoidsDuPalierDispatch[index]; - int Offset - = MatriceDesContraintesCouplantes.OffsetTemporelSurLePalierDispatch[index]; - int pdt1; - if (Offset >= 0) - { - pdt1 = (pdt + Offset) % nombreDePasDeTempsPourUneOptimisation; - } - else - { - pdt1 = (pdt + Offset + problemeHebdo->NombreDePasDeTemps) - % nombreDePasDeTempsPourUneOptimisation; - } + // int nbClusters + // = MatriceDesContraintesCouplantes.NombreDePaliersDispatchDansLaContrainteCouplante; + // for (int index = 0; index < nbClusters; index++) + // { + // int pays = MatriceDesContraintesCouplantes.PaysDuPalierDispatch[index]; + // const PALIERS_THERMIQUES& PaliersThermiquesDuPays + // = problemeHebdo->PaliersThermiquesDuPays[pays]; + // const int palier + // = PaliersThermiquesDuPays.NumeroDuPalierDansLEnsembleDesPaliersThermiques + // [MatriceDesContraintesCouplantes.NumeroDuPalierDispatch[index]]; + // double poids = MatriceDesContraintesCouplantes.PoidsDuPalierDispatch[index]; + // int Offset + // = MatriceDesContraintesCouplantes.OffsetTemporelSurLePalierDispatch[index]; + // int pdt1; + // if (Offset >= 0) + // { + // pdt1 = (pdt + Offset) % nombreDePasDeTempsPourUneOptimisation; + // } + // else + // { + // pdt1 = (pdt + Offset + problemeHebdo->NombreDePasDeTemps) + // % nombreDePasDeTempsPourUneOptimisation; + // } - var = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt1] - .NumeroDeVariableDuPalierThermique[palier]; + // var = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt1] + // .NumeroDeVariableDuPalierThermique[palier]; - if (var >= 0) - { - Pi[nombreDeTermes] = poids; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } - } - CorrespondanceCntNativesCntOptim - .NumeroDeContrainteDesContraintesCouplantes[cntCouplante] - = ProblemeAResoudre->NombreDeContraintes; + // if (var >= 0) + // { + // Pi[nombreDeTermes] = poids; + // Colonne[nombreDeTermes] = var; + // nombreDeTermes++; + // } + // } + // CorrespondanceCntNativesCntOptim + // .NumeroDeContrainteDesContraintesCouplantes[cntCouplante] + // = ProblemeAResoudre->NombreDeContraintes; - constraintNamer.BindingConstraintHour( - ProblemeAResoudre->NombreDeContraintes, - MatriceDesContraintesCouplantes.NomDeLaContrainteCouplante); - OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - ProblemeAResoudre, - Pi, - Colonne, - nombreDeTermes, - MatriceDesContraintesCouplantes.SensDeLaContrainteCouplante); + // constraintNamer.BindingConstraintHour( + // ProblemeAResoudre->NombreDeContraintes, + // MatriceDesContraintesCouplantes.NomDeLaContrainteCouplante); + // OPT_ChargerLaContrainteDansLaMatriceDesContraintes( + // ProblemeAResoudre, + // Pi, + // Colonne, + // nombreDeTermes, + // MatriceDesContraintesCouplantes.SensDeLaContrainteCouplante); } } From e4298f983e55f27c2aa03fcbc5240686c9e0a3ba Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Sun, 3 Sep 2023 12:07:13 +0200 Subject: [PATCH 06/43] ghost --- .../optimisation/BindingConstraintHour.cpp | 43 ++++- .../optimisation/constraint_builder.cpp | 53 ++++++ src/solver/optimisation/constraint_builder.h | 46 +---- ...n_matrice_des_contraintes_cas_lineaire.cpp | 160 +++++++++--------- 4 files changed, 174 insertions(+), 128 deletions(-) diff --git a/src/solver/optimisation/BindingConstraintHour.cpp b/src/solver/optimisation/BindingConstraintHour.cpp index 64d67cd1f3..e98ec5e755 100644 --- a/src/solver/optimisation/BindingConstraintHour.cpp +++ b/src/solver/optimisation/BindingConstraintHour.cpp @@ -4,6 +4,11 @@ void BindingConstraintHour::add(int pdt, int cntCouplante) { const CONTRAINTES_COUPLANTES& MatriceDesContraintesCouplantes = problemeHebdo->MatriceDesContraintesCouplantes[cntCouplante]; + CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim + = problemeHebdo->CorrespondanceCntNativesCntOptim[pdt]; + CorrespondanceCntNativesCntOptim.NumeroDeContrainteDesContraintesCouplantes[cntCouplante] + = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; + if (MatriceDesContraintesCouplantes.TypeDeContrainteCouplante != CONTRAINTE_HORAIRE) return; @@ -16,8 +21,19 @@ void BindingConstraintHour::add(int pdt, int cntCouplante) const int interco = MatriceDesContraintesCouplantes.NumeroDeLInterconnexion[index]; const double poids = MatriceDesContraintesCouplantes.PoidsDeLInterconnexion[index]; const int offset = MatriceDesContraintesCouplantes.OffsetTemporelSurLInterco[index]; - builder.include( - Variable::NTCDirect(interco), poids, offset, true, problemeHebdo->NombreDePasDeTemps); + int pdt1; + if (offset >= 0) + { + pdt1 = (pdt + offset) % problemeHebdo->NombreDePasDeTempsPourUneOptimisation; + } + else + { + pdt1 = (pdt + offset + problemeHebdo->NombreDePasDeTemps) + % problemeHebdo->NombreDePasDeTempsPourUneOptimisation; + } + + builder.updateHourWithinWeek(pdt1).include( + Variable::NTCDirect(interco), poids, 0, false, problemeHebdo->NombreDePasDeTemps); } // Thermal clusters @@ -32,11 +48,23 @@ void BindingConstraintHour::add(int pdt, int cntCouplante) [MatriceDesContraintesCouplantes.NumeroDuPalierDispatch[index]]; const double poids = MatriceDesContraintesCouplantes.PoidsDuPalierDispatch[index]; const int offset = MatriceDesContraintesCouplantes.OffsetTemporelSurLePalierDispatch[index]; - builder.include(Variable::DispatchableProduction(palier), - poids, - offset, - true, - problemeHebdo->NombreDePasDeTemps); + int pdt1; + + if (offset >= 0) + { + pdt1 = (pdt + offset) % problemeHebdo->NombreDePasDeTempsPourUneOptimisation; + } + else + { + pdt1 = (pdt + offset + problemeHebdo->NombreDePasDeTemps) + % problemeHebdo->NombreDePasDeTempsPourUneOptimisation; + } + + builder.updateHourWithinWeek(pdt1).include(Variable::DispatchableProduction(palier), + poids, + 0, + false, + problemeHebdo->NombreDePasDeTemps); } // std::vector& AdresseOuPlacerLaValeurDesCoutsMarginaux @@ -47,6 +75,7 @@ void BindingConstraintHour::add(int pdt, int cntCouplante) // AdresseOuPlacerLaValeurDesCoutsMarginaux[cnt] // = problemeHebdo->ResultatsContraintesCouplantes[cntCouplante].variablesDuales.data() // + pdtHebdo; + char op = MatriceDesContraintesCouplantes.SensDeLaContrainteCouplante; builder.operatorRHS(op); { diff --git a/src/solver/optimisation/constraint_builder.cpp b/src/solver/optimisation/constraint_builder.cpp index af7cf18562..30551d3c28 100644 --- a/src/solver/optimisation/constraint_builder.cpp +++ b/src/solver/optimisation/constraint_builder.cpp @@ -18,3 +18,56 @@ void ConstraintBuilder::build() } nombreDeTermes_ = 0; } + +int ConstraintBuilder::getVariableIndex(const Variable::Variant& variable, + int shift, + bool wrap, + int delta) const +{ + int pdt = hourInWeek_ + shift; + const int nbTimeSteps = problemeHebdo.NombreDePasDeTempsPourUneOptimisation; + // if (wrap) + // { + // pdt %= nbTimeSteps; + // if (pdt < 0) + // pdt += problemeHebdo.NombreDePasDeTemps; + // } + // if (pdt < 0 || pdt >= nbTimeSteps) + // { + // return -1; + // } + + if (wrap) + { + if (shift >= 0) + { + pdt = (pdt) % nbTimeSteps; + } + else + { + pdt = (pdt + delta) % nbTimeSteps; + } + } + const Variable::Visitor visitor(varNative[pdt], + problemeHebdo.NumeroDeVariableStockFinal, + problemeHebdo.NumeroDeVariableDeTrancheDeStock); + return std::visit(visitor, variable); +} + +ConstraintBuilder& ConstraintBuilder::include(Variable::Variant var, + double coeff, + int shift, + bool wrap, + int delta) +{ + std::vector& Pi = problemeAResoudre.Pi; + std::vector& Colonne = problemeAResoudre.Colonne; + int varIndex = getVariableIndex(var, shift, wrap, delta); + if (varIndex >= 0) + { + Pi[nombreDeTermes_] = coeff; + Colonne[nombreDeTermes_] = varIndex; + nombreDeTermes_++; + } + return *this; +} \ No newline at end of file diff --git a/src/solver/optimisation/constraint_builder.h b/src/solver/optimisation/constraint_builder.h index 0bb4ceabaf..d537843001 100644 --- a/src/solver/optimisation/constraint_builder.h +++ b/src/solver/optimisation/constraint_builder.h @@ -287,56 +287,14 @@ class ConstraintBuilder } private: - int getVariableIndex(const Variable::Variant& variable, int shift, bool wrap, int delta) const - { - int pdt = hourInWeek_ + shift; - const int nbTimeSteps = problemeHebdo.NombreDePasDeTempsPourUneOptimisation; - // if (wrap) - // { - // pdt %= nbTimeSteps; - // if (pdt < 0) - // pdt += problemeHebdo.NombreDePasDeTemps; - // } - // if (pdt < 0 || pdt >= nbTimeSteps) - // { - // return -1; - // } - - if (wrap) - { - if (shift >= 0) - { - pdt = (pdt) % nbTimeSteps; - } - else - { - pdt = (pdt + delta) % nbTimeSteps; - } - } - const Variable::Visitor visitor(varNative[pdt], - problemeHebdo.NumeroDeVariableStockFinal, - problemeHebdo.NumeroDeVariableDeTrancheDeStock); - return std::visit(visitor, variable); - } + int getVariableIndex(const Variable::Variant& variable, int shift, bool wrap, int delta) const; public: ConstraintBuilder& include(Variable::Variant var, double coeff, int shift = 0, bool wrap = false, - int delta = 0) - { - std::vector& Pi = problemeAResoudre.Pi; - std::vector& Colonne = problemeAResoudre.Colonne; - int varIndex = getVariableIndex(var, shift, wrap, delta); - if (varIndex >= 0) - { - Pi[nombreDeTermes_] = coeff; - Colonne[nombreDeTermes_] = varIndex; - nombreDeTermes_++; - } - return *this; - } + int delta = 0); ConstraintBuilder& operatorRHS(char op) { 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 3588dfd739..1c3b91ea92 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 @@ -361,95 +361,101 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro // ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '='); // } } - for (uint32_t cntCouplante = 0; cntCouplante < problemeHebdo->NombreDeContraintesCouplantes; cntCouplante++) { bindingConstraintHour.add(pdt, cntCouplante); - // const CONTRAINTES_COUPLANTES& MatriceDesContraintesCouplantes - // = problemeHebdo->MatriceDesContraintesCouplantes[cntCouplante]; - - // if (MatriceDesContraintesCouplantes.TypeDeContrainteCouplante != CONTRAINTE_HORAIRE) - // continue; - - // int nbInterco - // = MatriceDesContraintesCouplantes.NombreDInterconnexionsDansLaContrainteCouplante; - // int nombreDeTermes = 0; - // for (int index = 0; index < nbInterco; index++) - // { - // int interco = MatriceDesContraintesCouplantes.NumeroDeLInterconnexion[index]; - // double poids = MatriceDesContraintesCouplantes.PoidsDeLInterconnexion[index]; - // int Offset = MatriceDesContraintesCouplantes.OffsetTemporelSurLInterco[index]; - // int pdt1; + // const CONTRAINTES_COUPLANTES& MatriceDesContraintesCouplantes + // = problemeHebdo->MatriceDesContraintesCouplantes[cntCouplante]; - // if (Offset >= 0) - // { - // pdt1 = (pdt + Offset) % nombreDePasDeTempsPourUneOptimisation; - // } - // else - // { - // pdt1 = (pdt + Offset + problemeHebdo->NombreDePasDeTemps) - // % nombreDePasDeTempsPourUneOptimisation; - // } + // if (MatriceDesContraintesCouplantes.TypeDeContrainteCouplante != + // CONTRAINTE_HORAIRE) + // continue; - // var = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt1] - // .NumeroDeVariableDeLInterconnexion[interco]; - - // if (var >= 0) - // { - // Pi[nombreDeTermes] = poids; - // Colonne[nombreDeTermes] = var; - // nombreDeTermes++; - // } - // } - - // int nbClusters - // = MatriceDesContraintesCouplantes.NombreDePaliersDispatchDansLaContrainteCouplante; - // for (int index = 0; index < nbClusters; index++) - // { - // int pays = MatriceDesContraintesCouplantes.PaysDuPalierDispatch[index]; - // const PALIERS_THERMIQUES& PaliersThermiquesDuPays - // = problemeHebdo->PaliersThermiquesDuPays[pays]; - // const int palier - // = PaliersThermiquesDuPays.NumeroDuPalierDansLEnsembleDesPaliersThermiques - // [MatriceDesContraintesCouplantes.NumeroDuPalierDispatch[index]]; - // double poids = MatriceDesContraintesCouplantes.PoidsDuPalierDispatch[index]; - // int Offset - // = MatriceDesContraintesCouplantes.OffsetTemporelSurLePalierDispatch[index]; - // int pdt1; - // if (Offset >= 0) - // { - // pdt1 = (pdt + Offset) % nombreDePasDeTempsPourUneOptimisation; - // } - // else + // int nbInterco + // = + // MatriceDesContraintesCouplantes.NombreDInterconnexionsDansLaContrainteCouplante; + // int nombreDeTermes = 0; + // for (int index = 0; index < nbInterco; index++) // { - // pdt1 = (pdt + Offset + problemeHebdo->NombreDePasDeTemps) - // % nombreDePasDeTempsPourUneOptimisation; + // int interco = MatriceDesContraintesCouplantes.NumeroDeLInterconnexion[index]; + // double poids = MatriceDesContraintesCouplantes.PoidsDeLInterconnexion[index]; + // int Offset = + // MatriceDesContraintesCouplantes.OffsetTemporelSurLInterco[index]; int pdt1; + + // if (Offset >= 0) + // { + // pdt1 = (pdt + Offset) % nombreDePasDeTempsPourUneOptimisation; + // } + // else + // { + // pdt1 = (pdt + Offset + problemeHebdo->NombreDePasDeTemps) + // % nombreDePasDeTempsPourUneOptimisation; + // } + // logs.info() << " BindingConstraintHour::add:1:: pdt1 =" << pdt1 << "\n"; + + // var = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt1] + // .NumeroDeVariableDeLInterconnexion[interco]; + // logs.info() << "varIndex: " << var << "\n"; + + // if (var >= 0) + // { + // Pi[nombreDeTermes] = poids; + // Colonne[nombreDeTermes] = var; + // nombreDeTermes++; + // } // } - // var = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt1] - // .NumeroDeVariableDuPalierThermique[palier]; - - // if (var >= 0) + // int nbClusters + // = + // MatriceDesContraintesCouplantes.NombreDePaliersDispatchDansLaContrainteCouplante; + // for (int index = 0; index < nbClusters; index++) // { - // Pi[nombreDeTermes] = poids; - // Colonne[nombreDeTermes] = var; - // nombreDeTermes++; + // int pays = MatriceDesContraintesCouplantes.PaysDuPalierDispatch[index]; + // const PALIERS_THERMIQUES& PaliersThermiquesDuPays + // = problemeHebdo->PaliersThermiquesDuPays[pays]; + // const int palier + // = PaliersThermiquesDuPays.NumeroDuPalierDansLEnsembleDesPaliersThermiques + // [MatriceDesContraintesCouplantes.NumeroDuPalierDispatch[index]]; + // double poids = MatriceDesContraintesCouplantes.PoidsDuPalierDispatch[index]; + // int Offset + // = MatriceDesContraintesCouplantes.OffsetTemporelSurLePalierDispatch[index]; + // int pdt1; + // if (Offset >= 0) + // { + // pdt1 = (pdt + Offset) % nombreDePasDeTempsPourUneOptimisation; + // } + // else + // { + // pdt1 = (pdt + Offset + problemeHebdo->NombreDePasDeTemps) + // % nombreDePasDeTempsPourUneOptimisation; + // } + // logs.info() << " BindingConstraintHour::add:2:: pdt1 =" << pdt1 << "\n"; + + // var = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt1] + // .NumeroDeVariableDuPalierThermique[palier]; + // logs.info() << "varIndex: " << var << "\n"; + + // if (var >= 0) + // { + // Pi[nombreDeTermes] = poids; + // Colonne[nombreDeTermes] = var; + // nombreDeTermes++; + // } // } - // } - // CorrespondanceCntNativesCntOptim - // .NumeroDeContrainteDesContraintesCouplantes[cntCouplante] - // = ProblemeAResoudre->NombreDeContraintes; + // CorrespondanceCntNativesCntOptim + // .NumeroDeContrainteDesContraintesCouplantes[cntCouplante] + // = ProblemeAResoudre->NombreDeContraintes; - // constraintNamer.BindingConstraintHour( - // ProblemeAResoudre->NombreDeContraintes, - // MatriceDesContraintesCouplantes.NomDeLaContrainteCouplante); - // OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - // ProblemeAResoudre, - // Pi, - // Colonne, - // nombreDeTermes, - // MatriceDesContraintesCouplantes.SensDeLaContrainteCouplante); + // constraintNamer.BindingConstraintHour( + // ProblemeAResoudre->NombreDeContraintes, + // MatriceDesContraintesCouplantes.NomDeLaContrainteCouplante); + // OPT_ChargerLaContrainteDansLaMatriceDesContraintes( + // ProblemeAResoudre, + // Pi, + // Colonne, + // nombreDeTermes, + // MatriceDesContraintesCouplantes.SensDeLaContrainteCouplante); } } From c96df9c7c520dd7f9a763a80e6870f15ed08b664 Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Sun, 3 Sep 2023 13:07:14 +0200 Subject: [PATCH 07/43] this is not only about constraint builder --- .../optimisation/BindingConstraintWeek.cpp | 72 ++++++-- ...n_matrice_des_contraintes_cas_lineaire.cpp | 173 +++++++++--------- 2 files changed, 140 insertions(+), 105 deletions(-) diff --git a/src/solver/optimisation/BindingConstraintWeek.cpp b/src/solver/optimisation/BindingConstraintWeek.cpp index 0556d8320b..4e334dea66 100644 --- a/src/solver/optimisation/BindingConstraintWeek.cpp +++ b/src/solver/optimisation/BindingConstraintWeek.cpp @@ -4,6 +4,9 @@ void BindingConstraintWeek::add(int cntCouplante) { const CONTRAINTES_COUPLANTES& MatriceDesContraintesCouplantes = problemeHebdo->MatriceDesContraintesCouplantes[cntCouplante]; + int semaine = problemeHebdo->weekInTheYear; + CORRESPONDANCES_DES_CONTRAINTES_HEBDOMADAIRES& CorrespondanceCntNativesCntOptimHebdomadaires + = problemeHebdo->CorrespondanceCntNativesCntOptimHebdomadaires; if (MatriceDesContraintesCouplantes.TypeDeContrainteCouplante != CONTRAINTE_HEBDOMADAIRE) return; @@ -15,18 +18,28 @@ void BindingConstraintWeek::add(int cntCouplante) const int NombreDePasDeTempsPourUneOptimisation = problemeHebdo->NombreDePasDeTempsPourUneOptimisation; - for (int pdt = 0; pdt < NombreDePasDeTempsPourUneOptimisation; pdt++) + for (int index = 0; index < nbInterco; index++) { - builder.updateHourWithinWeek(pdt); - for (int index = 0; index < nbInterco; index++) + int interco = MatriceDesContraintesCouplantes.NumeroDeLInterconnexion[index]; + double poids = MatriceDesContraintesCouplantes.PoidsDeLInterconnexion[index]; + int offset = MatriceDesContraintesCouplantes.OffsetTemporelSurLInterco[index]; + for (int pdt = 0; pdt < problemeHebdo->NombreDePasDeTempsPourUneOptimisation; pdt++) { - int interco = MatriceDesContraintesCouplantes.NumeroDeLInterconnexion[index]; - double poids = MatriceDesContraintesCouplantes.PoidsDeLInterconnexion[index]; - int offset = MatriceDesContraintesCouplantes.OffsetTemporelSurLInterco[index]; - - builder.include( - Variable::NTCDirect(interco), poids, offset, true, problemeHebdo->NombreDePasDeTemps); + builder.updateHourWithinWeek(pdt); + int pdt1; + if (offset >= 0) + { + pdt1 = (pdt + offset) % problemeHebdo->NombreDePasDeTempsPourUneOptimisation; + } + else + { + pdt1 = (pdt + offset + problemeHebdo->NombreDePasDeTemps) + % problemeHebdo->NombreDePasDeTempsPourUneOptimisation; + } + builder.updateHourWithinWeek(pdt1).include( + Variable::NTCDirect(interco), poids, 0, false, problemeHebdo->NombreDePasDeTemps); } + } for (int index = 0; index < nbClusters; index++) { @@ -38,23 +51,42 @@ void BindingConstraintWeek::add(int cntCouplante) [MatriceDesContraintesCouplantes.NumeroDuPalierDispatch[index]]; double poids = MatriceDesContraintesCouplantes.PoidsDuPalierDispatch[index]; int offset = MatriceDesContraintesCouplantes.OffsetTemporelSurLePalierDispatch[index]; - builder.include(Variable::DispatchableProduction(palier), - poids, - offset, - true, - problemeHebdo->NombreDePasDeTemps); + for (int pdt = 0; pdt < problemeHebdo->NombreDePasDeTempsPourUneOptimisation; pdt++) + { + int pdt1; + + builder.updateHourWithinWeek(pdt); // useless? + if (offset >= 0) + { + pdt1 = (pdt + offset) % problemeHebdo->NombreDePasDeTempsPourUneOptimisation; + } + else + { + pdt1 = (pdt + offset + problemeHebdo->NombreDePasDeTemps) + % problemeHebdo->NombreDePasDeTempsPourUneOptimisation; + } + + builder.updateHourWithinWeek(pdt1).include(Variable::DispatchableProduction(palier), + poids, + offset, + false, + problemeHebdo->NombreDePasDeTemps); + } } - } + char op = MatriceDesContraintesCouplantes.SensDeLaContrainteCouplante; builder.operatorRHS(op); + CorrespondanceCntNativesCntOptimHebdomadaires + .NumeroDeContrainteDesContraintesCouplantes[cntCouplante] + = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; // Name { - ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, - problemeHebdo->NamedProblems); - namer.UpdateTimeStep(problemeHebdo->weekInTheYear); - namer.BindingConstraintWeek(problemeHebdo->ProblemeAResoudre->NombreDeContraintes, - MatriceDesContraintesCouplantes.NomDeLaContrainteCouplante); + ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, + problemeHebdo->NamedProblems); + namer.UpdateTimeStep(semaine); + namer.BindingConstraintWeek(problemeHebdo->ProblemeAResoudre->NombreDeContraintes, + MatriceDesContraintesCouplantes.NomDeLaContrainteCouplante); } builder.build(); } \ No newline at end of file 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 1c3b91ea92..83cb1c7867 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 @@ -35,6 +35,7 @@ #include "ShortTermStorageLevel.h" #include "FlowDissociation.h" #include "BindingConstraintHour.h" +#include "BindingConstraintWeek.h" #include @@ -181,6 +182,7 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro ConstraintNamer constraintNamer(ProblemeAResoudre->NomDesContraintes, problemeHebdo->NamedProblems); + BindingConstraintWeek bindingConstraintWeek(problemeHebdo); for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) { int timeStepInYear = problemeHebdo->weekInTheYear * 168 + pdt; @@ -568,99 +570,100 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro { int semaine = problemeHebdo->weekInTheYear; CORRESPONDANCES_DES_CONTRAINTES_HEBDOMADAIRES& CorrespondanceCntNativesCntOptimHebdomadaires - = problemeHebdo->CorrespondanceCntNativesCntOptimHebdomadaires; + = problemeHebdo->CorrespondanceCntNativesCntOptimHebdomadaires; for (uint32_t cntCouplante = 0; cntCouplante < problemeHebdo->NombreDeContraintesCouplantes; cntCouplante++) { - const CONTRAINTES_COUPLANTES& MatriceDesContraintesCouplantes - = problemeHebdo->MatriceDesContraintesCouplantes[cntCouplante]; - if (MatriceDesContraintesCouplantes.TypeDeContrainteCouplante - != CONTRAINTE_HEBDOMADAIRE) - continue; - - int nbInterco - = MatriceDesContraintesCouplantes.NombreDInterconnexionsDansLaContrainteCouplante; - int nombreDeTermes = 0; - for (int index = 0; index < nbInterco; index++) - { - int interco = MatriceDesContraintesCouplantes.NumeroDeLInterconnexion[index]; - double poids = MatriceDesContraintesCouplantes.PoidsDeLInterconnexion[index]; - int Offset = MatriceDesContraintesCouplantes.OffsetTemporelSurLInterco[index]; - for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) - { - int pdt1; - if (Offset >= 0) - { - pdt1 = (pdt + Offset) % nombreDePasDeTempsPourUneOptimisation; - } - else - { - pdt1 = (pdt + Offset + problemeHebdo->NombreDePasDeTemps) - % nombreDePasDeTempsPourUneOptimisation; - } + bindingConstraintWeek.add(cntCouplante); + // const CONTRAINTES_COUPLANTES& MatriceDesContraintesCouplantes + // = problemeHebdo->MatriceDesContraintesCouplantes[cntCouplante]; + // if (MatriceDesContraintesCouplantes.TypeDeContrainteCouplante + // != CONTRAINTE_HEBDOMADAIRE) + // continue; + + // int nbInterco + // = MatriceDesContraintesCouplantes.NombreDInterconnexionsDansLaContrainteCouplante; + // int nombreDeTermes = 0; + // for (int index = 0; index < nbInterco; index++) + // { + // int interco = MatriceDesContraintesCouplantes.NumeroDeLInterconnexion[index]; + // double poids = MatriceDesContraintesCouplantes.PoidsDeLInterconnexion[index]; + // int Offset = MatriceDesContraintesCouplantes.OffsetTemporelSurLInterco[index]; + // for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) + // { + // int pdt1; + // if (Offset >= 0) + // { + // pdt1 = (pdt + Offset) % nombreDePasDeTempsPourUneOptimisation; + // } + // else + // { + // pdt1 = (pdt + Offset + problemeHebdo->NombreDePasDeTemps) + // % nombreDePasDeTempsPourUneOptimisation; + // } - var = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt1] - .NumeroDeVariableDeLInterconnexion[interco]; - if (var >= 0) - { - Pi[nombreDeTermes] = poids; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } - } - } + // var = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt1] + // .NumeroDeVariableDeLInterconnexion[interco]; + // if (var >= 0) + // { + // Pi[nombreDeTermes] = poids; + // Colonne[nombreDeTermes] = var; + // nombreDeTermes++; + // } + // } + // } - int nbClusters - = MatriceDesContraintesCouplantes.NombreDePaliersDispatchDansLaContrainteCouplante; - for (int index = 0; index < nbClusters; index++) - { - int pays = MatriceDesContraintesCouplantes.PaysDuPalierDispatch[index]; - const PALIERS_THERMIQUES& PaliersThermiquesDuPays - = problemeHebdo->PaliersThermiquesDuPays[pays]; - const int palier - = PaliersThermiquesDuPays.NumeroDuPalierDansLEnsembleDesPaliersThermiques - [MatriceDesContraintesCouplantes.NumeroDuPalierDispatch[index]]; - double poids = MatriceDesContraintesCouplantes.PoidsDuPalierDispatch[index]; - int Offset - = MatriceDesContraintesCouplantes.OffsetTemporelSurLePalierDispatch[index]; - for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) - { - int pdt1; - if (Offset >= 0) - { - pdt1 = (pdt + Offset) % nombreDePasDeTempsPourUneOptimisation; - } - else - { - pdt1 = (pdt + Offset + problemeHebdo->NombreDePasDeTemps) - % nombreDePasDeTempsPourUneOptimisation; - } + // int nbClusters + // = MatriceDesContraintesCouplantes.NombreDePaliersDispatchDansLaContrainteCouplante; + // for (int index = 0; index < nbClusters; index++) + // { + // int pays = MatriceDesContraintesCouplantes.PaysDuPalierDispatch[index]; + // const PALIERS_THERMIQUES& PaliersThermiquesDuPays + // = problemeHebdo->PaliersThermiquesDuPays[pays]; + // const int palier + // = PaliersThermiquesDuPays.NumeroDuPalierDansLEnsembleDesPaliersThermiques + // [MatriceDesContraintesCouplantes.NumeroDuPalierDispatch[index]]; + // double poids = MatriceDesContraintesCouplantes.PoidsDuPalierDispatch[index]; + // int Offset + // = MatriceDesContraintesCouplantes.OffsetTemporelSurLePalierDispatch[index]; + // for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) + // { + // int pdt1; + // if (Offset >= 0) + // { + // pdt1 = (pdt + Offset) % nombreDePasDeTempsPourUneOptimisation; + // } + // else + // { + // pdt1 = (pdt + Offset + problemeHebdo->NombreDePasDeTemps) + // % nombreDePasDeTempsPourUneOptimisation; + // } - var = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt1] - .NumeroDeVariableDuPalierThermique[palier]; - if (var >= 0) - { - Pi[nombreDeTermes] = poids; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } - } - } + // var = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt1] + // .NumeroDeVariableDuPalierThermique[palier]; + // if (var >= 0) + // { + // Pi[nombreDeTermes] = poids; + // Colonne[nombreDeTermes] = var; + // nombreDeTermes++; + // } + // } + // } - CorrespondanceCntNativesCntOptimHebdomadaires - .NumeroDeContrainteDesContraintesCouplantes[cntCouplante] - = ProblemeAResoudre->NombreDeContraintes; + // CorrespondanceCntNativesCntOptimHebdomadaires + // .NumeroDeContrainteDesContraintesCouplantes[cntCouplante] + // = ProblemeAResoudre->NombreDeContraintes; - constraintNamer.UpdateTimeStep(semaine); - constraintNamer.BindingConstraintWeek( - ProblemeAResoudre->NombreDeContraintes, - MatriceDesContraintesCouplantes.NomDeLaContrainteCouplante); - OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - ProblemeAResoudre, - Pi, - Colonne, - nombreDeTermes, - MatriceDesContraintesCouplantes.SensDeLaContrainteCouplante); + // constraintNamer.UpdateTimeStep(semaine); + // constraintNamer.BindingConstraintWeek( + // ProblemeAResoudre->NombreDeContraintes, + // MatriceDesContraintesCouplantes.NomDeLaContrainteCouplante); + // OPT_ChargerLaContrainteDansLaMatriceDesContraintes( + // ProblemeAResoudre, + // Pi, + // Colonne, + // nombreDeTermes, + // MatriceDesContraintesCouplantes.SensDeLaContrainteCouplante); } } From 1af5ead7eb91f276bd36237f6a3a81dd28697384 Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Sun, 3 Sep 2023 13:24:23 +0200 Subject: [PATCH 08/43] pay attention to the time step --- .../optimisation/BindingConstraintDay.cpp | 55 +++-- ...n_matrice_des_contraintes_cas_lineaire.cpp | 203 +++++++++--------- 2 files changed, 143 insertions(+), 115 deletions(-) diff --git a/src/solver/optimisation/BindingConstraintDay.cpp b/src/solver/optimisation/BindingConstraintDay.cpp index 76401017c3..a276616453 100644 --- a/src/solver/optimisation/BindingConstraintDay.cpp +++ b/src/solver/optimisation/BindingConstraintDay.cpp @@ -15,9 +15,13 @@ void BindingConstraintDay::add(int cntCouplante) const int NombreDePasDeTempsPourUneOptimisation = problemeHebdo->NombreDePasDeTempsPourUneOptimisation; // TODO const int NombreDePasDeTempsDUneJournee = problemeHebdo->NombreDePasDeTempsDUneJournee; - for (int pdtDebut = 0; pdtDebut < NombreDePasDeTempsPourUneOptimisation; - pdtDebut += NombreDePasDeTempsDUneJournee) + int pdtDebut = 0; + while (pdtDebut < NombreDePasDeTempsPourUneOptimisation) { + int jour = problemeHebdo->NumeroDeJourDuPasDeTemps[pdtDebut]; + CORRESPONDANCES_DES_CONTRAINTES_JOURNALIERES& CorrespondanceCntNativesCntOptimJournalieres + = problemeHebdo->CorrespondanceCntNativesCntOptimJournalieres[jour]; + for (int index = 0; index < nbInterco; index++) { int interco = MatriceDesContraintesCouplantes.NumeroDeLInterconnexion[index]; @@ -26,12 +30,18 @@ void BindingConstraintDay::add(int cntCouplante) for (int pdt = pdtDebut; pdt < pdtDebut + NombreDePasDeTempsDUneJournee; pdt++) { - builder.updateHourWithinWeek(pdt); - builder.include(Variable::NTCDirect(interco), - poids, - offset, - true, - problemeHebdo->NombreDePasDeTemps); + int pdt1; + if (offset >= 0) + { + pdt1 = (pdt + offset) % problemeHebdo->NombreDePasDeTempsPourUneOptimisation; + } + else + { + pdt1 = (pdt + offset + problemeHebdo->NombreDePasDeTemps) + % problemeHebdo->NombreDePasDeTempsPourUneOptimisation; + } + builder.updateHourWithinWeek(pdt1).include( + Variable::NTCDirect(interco), poids, 0, false, problemeHebdo->NombreDePasDeTemps); } } @@ -48,16 +58,30 @@ void BindingConstraintDay::add(int cntCouplante) for (int pdt = pdtDebut; pdt < pdtDebut + NombreDePasDeTempsDUneJournee; pdt++) { - builder.updateHourWithinWeek(pdt); - builder.include(Variable::DispatchableProduction(palier), - poids, - offset, - true, - problemeHebdo->NombreDePasDeTemps); + int pdt1; + if (offset >= 0) + { + pdt1 = (pdt + offset) % problemeHebdo->NombreDePasDeTempsPourUneOptimisation; + } + else + { + pdt1 = (pdt + offset + problemeHebdo->NombreDePasDeTemps) + % problemeHebdo->NombreDePasDeTempsPourUneOptimisation; + } + + builder.updateHourWithinWeek(pdt1).include(Variable::DispatchableProduction(palier), + poids, + 0, + false, + problemeHebdo->NombreDePasDeTemps); } } + + CorrespondanceCntNativesCntOptimJournalieres + .NumeroDeContrainteDesContraintesCouplantes[cntCouplante] + = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; // TODO probably wrong from the 2nd week, check - const int jour = problemeHebdo->NumeroDeJourDuPasDeTemps[pdtDebut]; + // const int jour = problemeHebdo->NumeroDeJourDuPasDeTemps[pdtDebut]; std::vector& AdresseOuPlacerLaValeurDesCoutsMarginaux = problemeHebdo->ProblemeAResoudre->AdresseOuPlacerLaValeurDesCoutsMarginaux; @@ -76,5 +100,6 @@ void BindingConstraintDay::add(int cntCouplante) MatriceDesContraintesCouplantes.NomDeLaContrainteCouplante); } builder.build(); + pdtDebut += problemeHebdo->NombreDePasDeTempsDUneJournee; } } 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 83cb1c7867..44db6c0032 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 @@ -35,6 +35,7 @@ #include "ShortTermStorageLevel.h" #include "FlowDissociation.h" #include "BindingConstraintHour.h" +#include "BindingConstraintDay.h" #include "BindingConstraintWeek.h" #include @@ -182,6 +183,7 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro ConstraintNamer constraintNamer(ProblemeAResoudre->NomDesContraintes, problemeHebdo->NamedProblems); + BindingConstraintDay bindingConstraintDay(problemeHebdo); BindingConstraintWeek bindingConstraintWeek(problemeHebdo); for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) { @@ -464,106 +466,107 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro for (uint32_t cntCouplante = 0; cntCouplante < problemeHebdo->NombreDeContraintesCouplantes; cntCouplante++) { - const CONTRAINTES_COUPLANTES& MatriceDesContraintesCouplantes - = problemeHebdo->MatriceDesContraintesCouplantes[cntCouplante]; - if (MatriceDesContraintesCouplantes.TypeDeContrainteCouplante != CONTRAINTE_JOURNALIERE) - continue; - - int nbInterco - = MatriceDesContraintesCouplantes.NombreDInterconnexionsDansLaContrainteCouplante; - int nbClusters - = MatriceDesContraintesCouplantes.NombreDePaliersDispatchDansLaContrainteCouplante; - int pdtDebut = 0; - while (pdtDebut < nombreDePasDeTempsPourUneOptimisation) - { - int jour = problemeHebdo->NumeroDeJourDuPasDeTemps[pdtDebut]; - CORRESPONDANCES_DES_CONTRAINTES_JOURNALIERES& - CorrespondanceCntNativesCntOptimJournalieres - = problemeHebdo->CorrespondanceCntNativesCntOptimJournalieres[jour]; - int nombreDeTermes = 0; - - for (int index = 0; index < nbInterco; index++) - { - int interco = MatriceDesContraintesCouplantes.NumeroDeLInterconnexion[index]; - double poids = MatriceDesContraintesCouplantes.PoidsDeLInterconnexion[index]; - int Offset = MatriceDesContraintesCouplantes.OffsetTemporelSurLInterco[index]; - - for (int pdt = pdtDebut; pdt < pdtDebut + nombreDePasDeTempsDUneJournee; pdt++) - { - int pdt1; - if (Offset >= 0) - { - pdt1 = (pdt + Offset) % nombreDePasDeTempsPourUneOptimisation; - } - else - { - pdt1 = (pdt + Offset + problemeHebdo->NombreDePasDeTemps) - % nombreDePasDeTempsPourUneOptimisation; - } - - var = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt1] - .NumeroDeVariableDeLInterconnexion[interco]; - if (var >= 0) - { - Pi[nombreDeTermes] = poids; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } - } - } - - for (int index = 0; index < nbClusters; index++) - { - int pays = MatriceDesContraintesCouplantes.PaysDuPalierDispatch[index]; - const PALIERS_THERMIQUES& PaliersThermiquesDuPays - = problemeHebdo->PaliersThermiquesDuPays[pays]; - const int palier - = PaliersThermiquesDuPays.NumeroDuPalierDansLEnsembleDesPaliersThermiques - [MatriceDesContraintesCouplantes.NumeroDuPalierDispatch[index]]; - double poids = MatriceDesContraintesCouplantes.PoidsDuPalierDispatch[index]; - int Offset - = MatriceDesContraintesCouplantes.OffsetTemporelSurLePalierDispatch[index]; - - for (int pdt = pdtDebut; pdt < pdtDebut + nombreDePasDeTempsDUneJournee; pdt++) - { - int pdt1; - if (Offset >= 0) - { - pdt1 = (pdt + Offset) % nombreDePasDeTempsPourUneOptimisation; - } - else - { - pdt1 = (pdt + Offset + problemeHebdo->NombreDePasDeTemps) - % nombreDePasDeTempsPourUneOptimisation; - } - - var = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt1] - .NumeroDeVariableDuPalierThermique[palier]; - if (var >= 0) - { - Pi[nombreDeTermes] = poids; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } - } - } - - CorrespondanceCntNativesCntOptimJournalieres - .NumeroDeContrainteDesContraintesCouplantes[cntCouplante] - = ProblemeAResoudre->NombreDeContraintes; - - constraintNamer.UpdateTimeStep(jour); - constraintNamer.BindingConstraintDay( - ProblemeAResoudre->NombreDeContraintes, - MatriceDesContraintesCouplantes.NomDeLaContrainteCouplante); - OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - ProblemeAResoudre, - Pi, - Colonne, - nombreDeTermes, - MatriceDesContraintesCouplantes.SensDeLaContrainteCouplante); - pdtDebut += nombreDePasDeTempsDUneJournee; - } + bindingConstraintDay.add(cntCouplante); + // const CONTRAINTES_COUPLANTES& MatriceDesContraintesCouplantes + // = problemeHebdo->MatriceDesContraintesCouplantes[cntCouplante]; + // if (MatriceDesContraintesCouplantes.TypeDeContrainteCouplante != CONTRAINTE_JOURNALIERE) + // continue; + + // int nbInterco + // = MatriceDesContraintesCouplantes.NombreDInterconnexionsDansLaContrainteCouplante; + // int nbClusters + // = MatriceDesContraintesCouplantes.NombreDePaliersDispatchDansLaContrainteCouplante; + // int pdtDebut = 0; + // while (pdtDebut < nombreDePasDeTempsPourUneOptimisation) + // { + // int jour = problemeHebdo->NumeroDeJourDuPasDeTemps[pdtDebut]; + // CORRESPONDANCES_DES_CONTRAINTES_JOURNALIERES& + // CorrespondanceCntNativesCntOptimJournalieres + // = problemeHebdo->CorrespondanceCntNativesCntOptimJournalieres[jour]; + // int nombreDeTermes = 0; + + // for (int index = 0; index < nbInterco; index++) + // { + // int interco = MatriceDesContraintesCouplantes.NumeroDeLInterconnexion[index]; + // double poids = MatriceDesContraintesCouplantes.PoidsDeLInterconnexion[index]; + // int Offset = MatriceDesContraintesCouplantes.OffsetTemporelSurLInterco[index]; + + // for (int pdt = pdtDebut; pdt < pdtDebut + nombreDePasDeTempsDUneJournee; pdt++) + // { + // int pdt1; + // if (Offset >= 0) + // { + // pdt1 = (pdt + Offset) % nombreDePasDeTempsPourUneOptimisation; + // } + // else + // { + // pdt1 = (pdt + Offset + problemeHebdo->NombreDePasDeTemps) + // % nombreDePasDeTempsPourUneOptimisation; + // } + + // var = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt1] + // .NumeroDeVariableDeLInterconnexion[interco]; + // if (var >= 0) + // { + // Pi[nombreDeTermes] = poids; + // Colonne[nombreDeTermes] = var; + // nombreDeTermes++; + // } + // } + // } + + // for (int index = 0; index < nbClusters; index++) + // { + // int pays = MatriceDesContraintesCouplantes.PaysDuPalierDispatch[index]; + // const PALIERS_THERMIQUES& PaliersThermiquesDuPays + // = problemeHebdo->PaliersThermiquesDuPays[pays]; + // const int palier + // = PaliersThermiquesDuPays.NumeroDuPalierDansLEnsembleDesPaliersThermiques + // [MatriceDesContraintesCouplantes.NumeroDuPalierDispatch[index]]; + // double poids = MatriceDesContraintesCouplantes.PoidsDuPalierDispatch[index]; + // int Offset + // = MatriceDesContraintesCouplantes.OffsetTemporelSurLePalierDispatch[index]; + + // for (int pdt = pdtDebut; pdt < pdtDebut + nombreDePasDeTempsDUneJournee; pdt++) + // { + // int pdt1; + // if (Offset >= 0) + // { + // pdt1 = (pdt + Offset) % nombreDePasDeTempsPourUneOptimisation; + // } + // else + // { + // pdt1 = (pdt + Offset + problemeHebdo->NombreDePasDeTemps) + // % nombreDePasDeTempsPourUneOptimisation; + // } + + // var = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt1] + // .NumeroDeVariableDuPalierThermique[palier]; + // if (var >= 0) + // { + // Pi[nombreDeTermes] = poids; + // Colonne[nombreDeTermes] = var; + // nombreDeTermes++; + // } + // } + // } + + // CorrespondanceCntNativesCntOptimJournalieres + // .NumeroDeContrainteDesContraintesCouplantes[cntCouplante] + // = ProblemeAResoudre->NombreDeContraintes; + + // constraintNamer.UpdateTimeStep(jour); + // constraintNamer.BindingConstraintDay( + // ProblemeAResoudre->NombreDeContraintes, + // MatriceDesContraintesCouplantes.NomDeLaContrainteCouplante); + // OPT_ChargerLaContrainteDansLaMatriceDesContraintes( + // ProblemeAResoudre, + // Pi, + // Colonne, + // nombreDeTermes, + // MatriceDesContraintesCouplantes.SensDeLaContrainteCouplante); + // pdtDebut += nombreDePasDeTempsDUneJournee; + // } } if (nombreDePasDeTempsPourUneOptimisation > nombreDePasDeTempsDUneJournee) From 1d3398993ecaa073afb85082f1ec25c333c0c74e Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Sun, 3 Sep 2023 14:13:11 +0200 Subject: [PATCH 09/43] specific issue --- src/solver/optimisation/HydroPower.cpp | 58 +++++---- ...n_matrice_des_contraintes_cas_lineaire.cpp | 119 +++++++++--------- 2 files changed, 93 insertions(+), 84 deletions(-) diff --git a/src/solver/optimisation/HydroPower.cpp b/src/solver/optimisation/HydroPower.cpp index e6dfad59f9..50a24d48c8 100644 --- a/src/solver/optimisation/HydroPower.cpp +++ b/src/solver/optimisation/HydroPower.cpp @@ -5,41 +5,47 @@ void HydroPower::add(int pays) bool presenceHydro = problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDHydrauliqueModulable; bool TurbEntreBornes = problemeHebdo->CaracteristiquesHydrauliques[pays].TurbinageEntreBornes; - if (!presenceHydro || TurbEntreBornes) - return; const int NombreDePasDeTempsPourUneOptimisation = problemeHebdo->NombreDePasDeTempsPourUneOptimisation; - - if (bool presencePompage - = problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDePompageModulable) + if (presenceHydro && !TurbEntreBornes) { + if (bool presencePompage + = problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDePompageModulable) + { + problemeHebdo->NumeroDeContrainteEnergieHydraulique[pays] + = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; + + const double pumpingRatio + = problemeHebdo->CaracteristiquesHydrauliques[pays].PumpingRatio; + for (int pdt = 0; pdt < NombreDePasDeTempsPourUneOptimisation; pdt++) + { + builder.updateHourWithinWeek(pdt); + builder.include(Variable::HydProd(pays), 1.0) + .include(Variable::Pumping(pays), -pumpingRatio); + } + } + else + { + for (int pdt = 0; pdt < NombreDePasDeTempsPourUneOptimisation; pdt++) + { + builder.updateHourWithinWeek(pdt); + builder.include(Variable::HydProd(pays), 1.0); + } + } problemeHebdo->NumeroDeContrainteEnergieHydraulique[pays] = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; - const double pumpingRatio = problemeHebdo->CaracteristiquesHydrauliques[pays].PumpingRatio; - for (int pdt = 0; pdt < NombreDePasDeTempsPourUneOptimisation; pdt++) + builder.equalTo(); { - builder.updateHourWithinWeek(pdt); - builder.include(Variable::HydProd(pays), 1.0) - .include(Variable::Pumping(pays), -pumpingRatio); + ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, + problemeHebdo->NamedProblems); + namer.UpdateArea(problemeHebdo->NomsDesPays[pays]); + namer.UpdateTimeStep(problemeHebdo->weekInTheYear); + namer.HydroPower(problemeHebdo->ProblemeAResoudre->NombreDeContraintes); } + builder.build(); } else - { - for (int pdt = 0; pdt < NombreDePasDeTempsPourUneOptimisation; pdt++) - { - builder.updateHourWithinWeek(pdt); - builder.include(Variable::HydProd(pays), 1.0); - } - } - builder.equalTo(); - { - ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, - problemeHebdo->NamedProblems); - namer.UpdateArea(problemeHebdo->NomsDesPays[pays]); - namer.UpdateTimeStep(problemeHebdo->weekInTheYear); - namer.HydroPower(problemeHebdo->ProblemeAResoudre->NombreDeContraintes); - } - builder.build(); + problemeHebdo->NumeroDeContrainteEnergieHydraulique[pays] = -1; } 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 44db6c0032..f980012c09 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 @@ -37,6 +37,7 @@ #include "BindingConstraintHour.h" #include "BindingConstraintDay.h" #include "BindingConstraintWeek.h" +#include "HydroPower.h" #include @@ -185,6 +186,7 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro BindingConstraintDay bindingConstraintDay(problemeHebdo); BindingConstraintWeek bindingConstraintWeek(problemeHebdo); + HydroPower hydroPower(problemeHebdo); for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) { int timeStepInYear = problemeHebdo->weekInTheYear * 168 + pdt; @@ -672,66 +674,67 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro for (uint32_t pays = 0; pays < problemeHebdo->NombreDePays; pays++) { - constraintNamer.UpdateArea(problemeHebdo->NomsDesPays[pays]); - bool presenceHydro - = problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDHydrauliqueModulable; - bool TurbEntreBornes - = problemeHebdo->CaracteristiquesHydrauliques[pays].TurbinageEntreBornes; - bool presencePompage - = problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDePompageModulable; - - int nombreDeTermes = 0; - if (presenceHydro && !TurbEntreBornes) - { - if (presencePompage) - { - for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) - { - var = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt] - .NumeroDeVariablesDeLaProdHyd[pays]; + hydroPower.add(pays); + // constraintNamer.UpdateArea(problemeHebdo->NomsDesPays[pays]); + // bool presenceHydro + // = problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDHydrauliqueModulable; + // bool TurbEntreBornes + // = problemeHebdo->CaracteristiquesHydrauliques[pays].TurbinageEntreBornes; + // bool presencePompage + // = problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDePompageModulable; + + // int nombreDeTermes = 0; + // if (presenceHydro && !TurbEntreBornes) + // { + // if (presencePompage) + // { + // for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) + // { + // var = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt] + // .NumeroDeVariablesDeLaProdHyd[pays]; - if (var >= 0) - { - Pi[nombreDeTermes] = 1.0; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } - var = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt] - .NumeroDeVariablesDePompage[pays]; - if (var >= 0) - { - Pi[nombreDeTermes] - = problemeHebdo->CaracteristiquesHydrauliques[pays].PumpingRatio; - Pi[nombreDeTermes] *= -1.0; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } - } - } - else - { - for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) - { - var = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt] - .NumeroDeVariablesDeLaProdHyd[pays]; - if (var >= 0) - { - Pi[nombreDeTermes] = 1.0; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } - } - } + // if (var >= 0) + // { + // Pi[nombreDeTermes] = 1.0; + // Colonne[nombreDeTermes] = var; + // nombreDeTermes++; + // } + // var = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt] + // .NumeroDeVariablesDePompage[pays]; + // if (var >= 0) + // { + // Pi[nombreDeTermes] + // = problemeHebdo->CaracteristiquesHydrauliques[pays].PumpingRatio; + // Pi[nombreDeTermes] *= -1.0; + // Colonne[nombreDeTermes] = var; + // nombreDeTermes++; + // } + // } + // } + // else + // { + // for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) + // { + // var = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt] + // .NumeroDeVariablesDeLaProdHyd[pays]; + // if (var >= 0) + // { + // Pi[nombreDeTermes] = 1.0; + // Colonne[nombreDeTermes] = var; + // nombreDeTermes++; + // } + // } + // } - problemeHebdo->NumeroDeContrainteEnergieHydraulique[pays] - = ProblemeAResoudre->NombreDeContraintes; - constraintNamer.UpdateTimeStep(problemeHebdo->weekInTheYear); - constraintNamer.HydroPower(ProblemeAResoudre->NombreDeContraintes); - OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '='); - } - else - problemeHebdo->NumeroDeContrainteEnergieHydraulique[pays] = -1; + // problemeHebdo->NumeroDeContrainteEnergieHydraulique[pays] + // = ProblemeAResoudre->NombreDeContraintes; + // constraintNamer.UpdateTimeStep(problemeHebdo->weekInTheYear); + // constraintNamer.HydroPower(ProblemeAResoudre->NombreDeContraintes); + // OPT_ChargerLaContrainteDansLaMatriceDesContraintes( + // ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '='); + // } + // else + // problemeHebdo->NumeroDeContrainteEnergieHydraulique[pays] = -1; } if (problemeHebdo->TypeDeLissageHydraulique == LISSAGE_HYDRAULIQUE_SUR_SOMME_DES_VARIATIONS) From 3f9f115b128e78e35d6207ff679cc20cbce38ca9 Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Sun, 3 Sep 2023 14:20:28 +0200 Subject: [PATCH 10/43] bug free --- ...n_matrice_des_contraintes_cas_lineaire.cpp | 103 ++++++++++-------- 1 file changed, 56 insertions(+), 47 deletions(-) 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 f980012c09..f5939e1c6c 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 @@ -38,6 +38,9 @@ #include "BindingConstraintDay.h" #include "BindingConstraintWeek.h" #include "HydroPower.h" +#include "HydroPowerSmoothingUsingVariationSum.h" +#include "HydroPowerSmoothingUsingVariationMaxDown.h" +#include "HydroPowerSmoothingUsingVariationMaxUp.h" #include @@ -187,6 +190,11 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro BindingConstraintDay bindingConstraintDay(problemeHebdo); BindingConstraintWeek bindingConstraintWeek(problemeHebdo); HydroPower hydroPower(problemeHebdo); + HydroPowerSmoothingUsingVariationSum hydroPowerSmoothingUsingVariationSum(problemeHebdo); + HydroPowerSmoothingUsingVariationMaxDown hydroPowerSmoothingUsingVariationMaxDown( + problemeHebdo); + HydroPowerSmoothingUsingVariationMaxUp hydroPowerSmoothingUsingVariationMaxUp(problemeHebdo); + for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) { int timeStepInYear = problemeHebdo->weekInTheYear * 168 + pdt; @@ -744,57 +752,58 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro if (!problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDHydrauliqueModulable) continue; - constraintNamer.UpdateArea(problemeHebdo->NomsDesPays[pays]); - for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) - { - int timeStepInYear = problemeHebdo->weekInTheYear * 168 + pdt; - constraintNamer.UpdateTimeStep(timeStepInYear); - const auto& CorrespondanceVarNativesVarOptim - = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt]; - int nombreDeTermes = 0; - var = CorrespondanceVarNativesVarOptim.NumeroDeVariablesDeLaProdHyd[pays]; - if (var >= 0) - { - Pi[nombreDeTermes] = 1.0; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } - int pdt1 = pdt + 1; - if (pdt1 >= nombreDePasDeTempsPourUneOptimisation) - pdt1 = 0; + hydroPowerSmoothingUsingVariationSum.add(pays); + // constraintNamer.UpdateArea(problemeHebdo->NomsDesPays[pays]); + // for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) + // { + // int timeStepInYear = problemeHebdo->weekInTheYear * 168 + pdt; + // constraintNamer.UpdateTimeStep(timeStepInYear); + // const auto& CorrespondanceVarNativesVarOptim + // = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt]; + // int nombreDeTermes = 0; + // var = CorrespondanceVarNativesVarOptim.NumeroDeVariablesDeLaProdHyd[pays]; + // if (var >= 0) + // { + // Pi[nombreDeTermes] = 1.0; + // Colonne[nombreDeTermes] = var; + // nombreDeTermes++; + // } + // int pdt1 = pdt + 1; + // if (pdt1 >= nombreDePasDeTempsPourUneOptimisation) + // pdt1 = 0; - if (int var1 = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt1] - .NumeroDeVariablesDeLaProdHyd[pays]; - var1 >= 0) - { - Pi[nombreDeTermes] = -1.0; - Colonne[nombreDeTermes] = var1; - nombreDeTermes++; - } + // if (int var1 = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt1] + // .NumeroDeVariablesDeLaProdHyd[pays]; + // var1 >= 0) + // { + // Pi[nombreDeTermes] = -1.0; + // Colonne[nombreDeTermes] = var1; + // nombreDeTermes++; + // } - if (int var2 = CorrespondanceVarNativesVarOptim - .NumeroDeVariablesVariationHydALaBaisse[pays]; - var2 >= 0) - { - Pi[nombreDeTermes] = -1.0; - Colonne[nombreDeTermes] = var2; - nombreDeTermes++; - } + // if (int var2 = CorrespondanceVarNativesVarOptim + // .NumeroDeVariablesVariationHydALaBaisse[pays]; + // var2 >= 0) + // { + // Pi[nombreDeTermes] = -1.0; + // Colonne[nombreDeTermes] = var2; + // nombreDeTermes++; + // } - if (int var3 = CorrespondanceVarNativesVarOptim - .NumeroDeVariablesVariationHydALaHausse[pays]; - var3 >= 0) - { - Pi[nombreDeTermes] = 1.0; - Colonne[nombreDeTermes] = var3; - nombreDeTermes++; - } + // if (int var3 = CorrespondanceVarNativesVarOptim + // .NumeroDeVariablesVariationHydALaHausse[pays]; + // var3 >= 0) + // { + // Pi[nombreDeTermes] = 1.0; + // Colonne[nombreDeTermes] = var3; + // nombreDeTermes++; + // } - constraintNamer.HydroPowerSmoothingUsingVariationSum( - ProblemeAResoudre->NombreDeContraintes); - OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '='); - } + // constraintNamer.HydroPowerSmoothingUsingVariationSum( + // ProblemeAResoudre->NombreDeContraintes); + // OPT_ChargerLaContrainteDansLaMatriceDesContraintes( + // ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '='); + // } } } else if (problemeHebdo->TypeDeLissageHydraulique == LISSAGE_HYDRAULIQUE_SUR_VARIATION_MAX) From 7b2406e5b27b42c764fbe9a4338176779d899f56 Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Sun, 3 Sep 2023 14:25:18 +0200 Subject: [PATCH 11/43] smooth green? --- ...n_matrice_des_contraintes_cas_lineaire.cpp | 95 ++++++++++--------- 1 file changed, 49 insertions(+), 46 deletions(-) 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 f5939e1c6c..ff6ea2b851 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 @@ -816,52 +816,55 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro constraintNamer.UpdateArea(problemeHebdo->NomsDesPays[pays]); for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) { - int timeStepInYear = problemeHebdo->weekInTheYear * 168 + pdt; - constraintNamer.UpdateTimeStep(timeStepInYear); - const auto& CorrespondanceVarNativesVarOptim - = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt]; - int nombreDeTermes = 0; - var = CorrespondanceVarNativesVarOptim.NumeroDeVariablesDeLaProdHyd[pays]; - if (var >= 0) - { - Pi[nombreDeTermes] = 1.0; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } - int var1 = problemeHebdo->CorrespondanceVarNativesVarOptim[0] - .NumeroDeVariablesVariationHydALaBaisse[pays]; - if (var1 >= 0) - { - Pi[nombreDeTermes] = -1.0; - Colonne[nombreDeTermes] = var1; - nombreDeTermes++; - } - - constraintNamer.HydroPowerSmoothingUsingVariationMaxDown( - ProblemeAResoudre->NombreDeContraintes); - OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '<'); - - nombreDeTermes = 0; - if (var >= 0) - { - Pi[nombreDeTermes] = 1.0; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } - var1 = problemeHebdo->CorrespondanceVarNativesVarOptim[0] - .NumeroDeVariablesVariationHydALaHausse[pays]; - if (var1 >= 0) - { - Pi[nombreDeTermes] = -1.0; - Colonne[nombreDeTermes] = var1; - nombreDeTermes++; - } - - constraintNamer.HydroPowerSmoothingUsingVariationMaxUp( - ProblemeAResoudre->NombreDeContraintes); - OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '>'); + hydroPowerSmoothingUsingVariationMaxDown.add(pays, pdt); + hydroPowerSmoothingUsingVariationMaxUp.add(pays, pdt); + + // int timeStepInYear = problemeHebdo->weekInTheYear * 168 + pdt; + // constraintNamer.UpdateTimeStep(timeStepInYear); + // const auto& CorrespondanceVarNativesVarOptim + // = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt]; + // int nombreDeTermes = 0; + // var = CorrespondanceVarNativesVarOptim.NumeroDeVariablesDeLaProdHyd[pays]; + // if (var >= 0) + // { + // Pi[nombreDeTermes] = 1.0; + // Colonne[nombreDeTermes] = var; + // nombreDeTermes++; + // } + // int var1 = problemeHebdo->CorrespondanceVarNativesVarOptim[0] + // .NumeroDeVariablesVariationHydALaBaisse[pays]; + // if (var1 >= 0) + // { + // Pi[nombreDeTermes] = -1.0; + // Colonne[nombreDeTermes] = var1; + // nombreDeTermes++; + // } + + // constraintNamer.HydroPowerSmoothingUsingVariationMaxDown( + // ProblemeAResoudre->NombreDeContraintes); + // OPT_ChargerLaContrainteDansLaMatriceDesContraintes( + // ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '<'); + + // nombreDeTermes = 0; + // if (var >= 0) + // { + // Pi[nombreDeTermes] = 1.0; + // Colonne[nombreDeTermes] = var; + // nombreDeTermes++; + // } + // var1 = problemeHebdo->CorrespondanceVarNativesVarOptim[0] + // .NumeroDeVariablesVariationHydALaHausse[pays]; + // if (var1 >= 0) + // { + // Pi[nombreDeTermes] = -1.0; + // Colonne[nombreDeTermes] = var1; + // nombreDeTermes++; + // } + + // constraintNamer.HydroPowerSmoothingUsingVariationMaxUp( + // ProblemeAResoudre->NombreDeContraintes); + // OPT_ChargerLaContrainteDansLaMatriceDesContraintes( + // ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '>'); } } } From 3b0c0d51da1877a2754f76e4f470521919daaf4b Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Sun, 3 Sep 2023 14:34:50 +0200 Subject: [PATCH 12/43] M&M --- src/solver/optimisation/MaxHydroPower.cpp | 4 + src/solver/optimisation/MinHydroPower.cpp | 5 + ...n_matrice_des_contraintes_cas_lineaire.cpp | 120 +++++++++--------- 3 files changed, 72 insertions(+), 57 deletions(-) diff --git a/src/solver/optimisation/MaxHydroPower.cpp b/src/solver/optimisation/MaxHydroPower.cpp index cdf0d0eb77..4a75208469 100644 --- a/src/solver/optimisation/MaxHydroPower.cpp +++ b/src/solver/optimisation/MaxHydroPower.cpp @@ -20,6 +20,8 @@ void MaxHydroPower::add(int pays) builder.updateHourWithinWeek(pdt); builder.include(Variable::HydProd(pays), 1.0); } + problemeHebdo->NumeroDeContrainteMaxEnergieHydraulique[pays] + = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, problemeHebdo->NamedProblems); @@ -29,4 +31,6 @@ void MaxHydroPower::add(int pays) builder.lessThan().build(); } + else + problemeHebdo->NumeroDeContrainteMaxEnergieHydraulique[pays] = -1; } \ No newline at end of file diff --git a/src/solver/optimisation/MinHydroPower.cpp b/src/solver/optimisation/MinHydroPower.cpp index 435c76cfea..a3472397e4 100644 --- a/src/solver/optimisation/MinHydroPower.cpp +++ b/src/solver/optimisation/MinHydroPower.cpp @@ -27,6 +27,11 @@ void MinHydroPower::add(int pays) } // const double rhs = problemeHebdo->CaracteristiquesHydrauliques[pays] // .MinEnergieHydrauParIntervalleOptimise[NumeroDeLIntervalle]; + + problemeHebdo->NumeroDeContrainteMinEnergieHydraulique[pays] + = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; builder.greaterThan().build(); } + else + problemeHebdo->NumeroDeContrainteMinEnergieHydraulique[pays] = -1; } 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 ff6ea2b851..c967ca47f8 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 @@ -41,6 +41,8 @@ #include "HydroPowerSmoothingUsingVariationSum.h" #include "HydroPowerSmoothingUsingVariationMaxDown.h" #include "HydroPowerSmoothingUsingVariationMaxUp.h" +#include "MinHydroPower.h" +#include "MaxHydroPower.h" #include @@ -195,6 +197,9 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro problemeHebdo); HydroPowerSmoothingUsingVariationMaxUp hydroPowerSmoothingUsingVariationMaxUp(problemeHebdo); + MinHydroPower minHydroPower(problemeHebdo); + MaxHydroPower maxHydroPower(problemeHebdo); + for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) { int timeStepInYear = problemeHebdo->weekInTheYear * 168 + pdt; @@ -871,65 +876,66 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro for (uint32_t pays = 0; pays < problemeHebdo->NombreDePays; pays++) { - const bool presenceHydro - = problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDHydrauliqueModulable; - const bool presencePompage - = problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDePompageModulable; - const bool TurbEntreBornes - = problemeHebdo->CaracteristiquesHydrauliques[pays].TurbinageEntreBornes; - constraintNamer.UpdateArea(problemeHebdo->NomsDesPays[pays]); - if (presenceHydro && (TurbEntreBornes || presencePompage)) - { - int nombreDeTermes = 0; - for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) - { - var = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt] - .NumeroDeVariablesDeLaProdHyd[pays]; - if (var >= 0) - { - Pi[nombreDeTermes] = 1.0; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } - } - - problemeHebdo->NumeroDeContrainteMinEnergieHydraulique[pays] - = ProblemeAResoudre->NombreDeContraintes; - constraintNamer.UpdateTimeStep(problemeHebdo->weekInTheYear); - constraintNamer.MinHydroPower(ProblemeAResoudre->NombreDeContraintes); - OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '>'); - } - else - problemeHebdo->NumeroDeContrainteMinEnergieHydraulique[pays] = -1; + minHydroPower.add(pays); + // const bool presenceHydro + // = problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDHydrauliqueModulable; + // const bool presencePompage + // = problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDePompageModulable; + // const bool TurbEntreBornes + // = problemeHebdo->CaracteristiquesHydrauliques[pays].TurbinageEntreBornes; + // constraintNamer.UpdateArea(problemeHebdo->NomsDesPays[pays]); + // if (presenceHydro && (TurbEntreBornes || presencePompage)) + // { + // int nombreDeTermes = 0; + // for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) + // { + // var = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt] + // .NumeroDeVariablesDeLaProdHyd[pays]; + // if (var >= 0) + // { + // Pi[nombreDeTermes] = 1.0; + // Colonne[nombreDeTermes] = var; + // nombreDeTermes++; + // } + // } - if (presenceHydro - && (TurbEntreBornes - || problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDePompageModulable)) - { - int nombreDeTermes = 0; - for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) - { - constraintNamer.UpdateTimeStep(problemeHebdo->weekInTheYear * 168 + pdt); - var = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt] - .NumeroDeVariablesDeLaProdHyd[pays]; - if (var >= 0) - { - Pi[nombreDeTermes] = 1.0; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } - } + // problemeHebdo->NumeroDeContrainteMinEnergieHydraulique[pays] + // = ProblemeAResoudre->NombreDeContraintes; + // constraintNamer.UpdateTimeStep(problemeHebdo->weekInTheYear); + // constraintNamer.MinHydroPower(ProblemeAResoudre->NombreDeContraintes); + // OPT_ChargerLaContrainteDansLaMatriceDesContraintes( + // ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '>'); + // } + // else + // problemeHebdo->NumeroDeContrainteMinEnergieHydraulique[pays] = -1; + maxHydroPower.add(pays); + // if (presenceHydro + // && (TurbEntreBornes + // || problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDePompageModulable)) + // { + // int nombreDeTermes = 0; + // for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) + // { + // constraintNamer.UpdateTimeStep(problemeHebdo->weekInTheYear * 168 + pdt); + // var = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt] + // .NumeroDeVariablesDeLaProdHyd[pays]; + // if (var >= 0) + // { + // Pi[nombreDeTermes] = 1.0; + // Colonne[nombreDeTermes] = var; + // nombreDeTermes++; + // } + // } - problemeHebdo->NumeroDeContrainteMaxEnergieHydraulique[pays] - = ProblemeAResoudre->NombreDeContraintes; - constraintNamer.UpdateTimeStep(problemeHebdo->weekInTheYear); - constraintNamer.MaxHydroPower(ProblemeAResoudre->NombreDeContraintes); - OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '<'); - } - else - problemeHebdo->NumeroDeContrainteMaxEnergieHydraulique[pays] = -1; + // problemeHebdo->NumeroDeContrainteMaxEnergieHydraulique[pays] + // = ProblemeAResoudre->NombreDeContraintes; + // constraintNamer.UpdateTimeStep(problemeHebdo->weekInTheYear); + // constraintNamer.MaxHydroPower(ProblemeAResoudre->NombreDeContraintes); + // OPT_ChargerLaContrainteDansLaMatriceDesContraintes( + // ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '<'); + // } + // else + // problemeHebdo->NumeroDeContrainteMaxEnergieHydraulique[pays] = -1; } for (uint32_t pays = 0; pays < problemeHebdo->NombreDePays; pays++) From bcc63e784ea9827ec1650ef26e76f05c6c2561a6 Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Sun, 3 Sep 2023 14:39:25 +0200 Subject: [PATCH 13/43] Max Pumping ok? --- src/solver/optimisation/MaxPumping.cpp | 5 +- ...n_matrice_des_contraintes_cas_lineaire.cpp | 52 ++++++++++--------- 2 files changed, 32 insertions(+), 25 deletions(-) diff --git a/src/solver/optimisation/MaxPumping.cpp b/src/solver/optimisation/MaxPumping.cpp index 2a37007d21..f3d688858d 100644 --- a/src/solver/optimisation/MaxPumping.cpp +++ b/src/solver/optimisation/MaxPumping.cpp @@ -15,7 +15,8 @@ void MaxPumping::add(int pays) builder.updateHourWithinWeek(pdt); builder.include(Variable::Pumping(pays), 1.0); } - + problemeHebdo->NumeroDeContrainteMaxPompage[pays] + = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, problemeHebdo->NamedProblems); namer.UpdateArea(problemeHebdo->NomsDesPays[pays]); @@ -23,4 +24,6 @@ void MaxPumping::add(int pays) namer.MaxPumping(problemeHebdo->ProblemeAResoudre->NombreDeContraintes); builder.lessThan().build(); } + else + problemeHebdo->NumeroDeContrainteMaxPompage[pays] = -1; } \ No newline at end of file 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 c967ca47f8..eba79a7429 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 @@ -43,6 +43,7 @@ #include "HydroPowerSmoothingUsingVariationMaxUp.h" #include "MinHydroPower.h" #include "MaxHydroPower.h" +#include "MaxPumping.h" #include @@ -200,6 +201,8 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro MinHydroPower minHydroPower(problemeHebdo); MaxHydroPower maxHydroPower(problemeHebdo); + MaxPumping maxPumping(problemeHebdo); + for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) { int timeStepInYear = problemeHebdo->weekInTheYear * 168 + pdt; @@ -940,32 +943,33 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro for (uint32_t pays = 0; pays < problemeHebdo->NombreDePays; pays++) { - constraintNamer.UpdateArea(problemeHebdo->NomsDesPays[pays]); - if (problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDePompageModulable) - { - int nombreDeTermes = 0; - for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) - { - var = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt] - .NumeroDeVariablesDePompage[pays]; - if (var >= 0) - { - Pi[nombreDeTermes] = 1.0; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } - } + maxPumping.add(pays); + // constraintNamer.UpdateArea(problemeHebdo->NomsDesPays[pays]); + // if (problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDePompageModulable) + // { + // int nombreDeTermes = 0; + // for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) + // { + // var = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt] + // .NumeroDeVariablesDePompage[pays]; + // if (var >= 0) + // { + // Pi[nombreDeTermes] = 1.0; + // Colonne[nombreDeTermes] = var; + // nombreDeTermes++; + // } + // } - problemeHebdo->NumeroDeContrainteMaxPompage[pays] - = ProblemeAResoudre->NombreDeContraintes; + // problemeHebdo->NumeroDeContrainteMaxPompage[pays] + // = ProblemeAResoudre->NombreDeContraintes; - constraintNamer.UpdateTimeStep(problemeHebdo->weekInTheYear); - constraintNamer.MaxPumping(ProblemeAResoudre->NombreDeContraintes); - OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '<'); - } - else - problemeHebdo->NumeroDeContrainteMaxPompage[pays] = -1; + // constraintNamer.UpdateTimeStep(problemeHebdo->weekInTheYear); + // constraintNamer.MaxPumping(ProblemeAResoudre->NombreDeContraintes); + // OPT_ChargerLaContrainteDansLaMatriceDesContraintes( + // ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '<'); + // } + // else + // problemeHebdo->NumeroDeContrainteMaxPompage[pays] = -1; } for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) From a2de6d72e84715d9df08f8e6fc820e6227f64a57 Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Sun, 3 Sep 2023 14:45:20 +0200 Subject: [PATCH 14/43] Area Hydro Level (_-_) --- src/solver/optimisation/AreaHydroLevel.cpp | 41 ++++--- ...n_matrice_des_contraintes_cas_lineaire.cpp | 110 +++++++++--------- 2 files changed, 80 insertions(+), 71 deletions(-) diff --git a/src/solver/optimisation/AreaHydroLevel.cpp b/src/solver/optimisation/AreaHydroLevel.cpp index 1479832b76..ab59ebe9a0 100644 --- a/src/solver/optimisation/AreaHydroLevel.cpp +++ b/src/solver/optimisation/AreaHydroLevel.cpp @@ -8,24 +8,29 @@ void AreaHydroLevel::add(int pays, int pdt) = problemeHebdo->CorrespondanceCntNativesCntOptim[pdt]; CorrespondanceCntNativesCntOptim.NumeroDeContrainteDesNiveauxPays[pays] = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; - - builder.updateHourWithinWeek(pdt).include(Variable::HydroLevel(pays), 1.0); - if (pdt > 0) + if (problemeHebdo->CaracteristiquesHydrauliques[pays].SuiviNiveauHoraire) { - builder.updateHourWithinWeek(pdt - 1).include(Variable::HydroLevel(pays), -1.0); - } - ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, - problemeHebdo->NamedProblems); + builder.updateHourWithinWeek(pdt).include(Variable::HydroLevel(pays), 1.0); + if (pdt > 0) + { + builder.updateHourWithinWeek(pdt - 1).include(Variable::HydroLevel(pays), -1.0); + } + ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, + problemeHebdo->NamedProblems); - namer.UpdateArea(problemeHebdo->NomsDesPays[pays]); - namer.UpdateTimeStep(problemeHebdo->weekInTheYear * 168 + pdt); - namer.AreaHydroLevel(problemeHebdo->ProblemeAResoudre->NombreDeContraintes); - - builder.updateHourWithinWeek(pdt) - .include(Variable::HydProd(pays), 1.0) - .include(Variable::Pumping(pays), - -problemeHebdo->CaracteristiquesHydrauliques[pays].PumpingRatio) - .include(Variable::Overflow(pays), 1.) - .equalTo() - .build(); + namer.UpdateArea(problemeHebdo->NomsDesPays[pays]); + namer.UpdateTimeStep(problemeHebdo->weekInTheYear * 168 + pdt); + namer.AreaHydroLevel(problemeHebdo->ProblemeAResoudre->NombreDeContraintes); + CorrespondanceCntNativesCntOptim.NumeroDeContrainteDesNiveauxPays[pays] + = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; + builder.updateHourWithinWeek(pdt) + .include(Variable::HydProd(pays), 1.0) + .include(Variable::Pumping(pays), + -problemeHebdo->CaracteristiquesHydrauliques[pays].PumpingRatio) + .include(Variable::Overflow(pays), 1.) + .equalTo() + .build(); + } + else + CorrespondanceCntNativesCntOptim.NumeroDeContrainteDesNiveauxPays[pays] = -1; } \ No newline at end of file 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 eba79a7429..3c32e4dda3 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 @@ -44,6 +44,7 @@ #include "MinHydroPower.h" #include "MaxHydroPower.h" #include "MaxPumping.h" +#include "AreaHydroLevel.h" #include @@ -203,6 +204,8 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro MaxPumping maxPumping(problemeHebdo); + AreaHydroLevel areaHydroLevel(problemeHebdo); + for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) { int timeStepInYear = problemeHebdo->weekInTheYear * 168 + pdt; @@ -982,66 +985,67 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro constraintNamer.UpdateTimeStep(timeStepInYear); for (uint32_t pays = 0; pays < problemeHebdo->NombreDePays; pays++) { - constraintNamer.UpdateArea(problemeHebdo->NomsDesPays[pays]); - if (problemeHebdo->CaracteristiquesHydrauliques[pays].SuiviNiveauHoraire) - { - int nombreDeTermes = 0; + areaHydroLevel.add(pays, pdt); + // constraintNamer.UpdateArea(problemeHebdo->NomsDesPays[pays]); + // if (problemeHebdo->CaracteristiquesHydrauliques[pays].SuiviNiveauHoraire) + // { + // int nombreDeTermes = 0; - var = CorrespondanceVarNativesVarOptim.NumeroDeVariablesDeNiveau[pays]; - if (var >= 0) - { - Pi[nombreDeTermes] = 1.0; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } + // var = CorrespondanceVarNativesVarOptim.NumeroDeVariablesDeNiveau[pays]; + // if (var >= 0) + // { + // Pi[nombreDeTermes] = 1.0; + // Colonne[nombreDeTermes] = var; + // nombreDeTermes++; + // } - if (pdt > 0) - { - int var1 = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt - 1] - .NumeroDeVariablesDeNiveau[pays]; - if (var1 >= 0) - { - Pi[nombreDeTermes] = -1.0; - Colonne[nombreDeTermes] = var1; - nombreDeTermes++; - } - } + // if (pdt > 0) + // { + // int var1 = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt - 1] + // .NumeroDeVariablesDeNiveau[pays]; + // if (var1 >= 0) + // { + // Pi[nombreDeTermes] = -1.0; + // Colonne[nombreDeTermes] = var1; + // nombreDeTermes++; + // } + // } - var = CorrespondanceVarNativesVarOptim.NumeroDeVariablesDeLaProdHyd[pays]; - if (var >= 0) - { - Pi[nombreDeTermes] = 1.0; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } + // var = CorrespondanceVarNativesVarOptim.NumeroDeVariablesDeLaProdHyd[pays]; + // if (var >= 0) + // { + // Pi[nombreDeTermes] = 1.0; + // Colonne[nombreDeTermes] = var; + // nombreDeTermes++; + // } - var = CorrespondanceVarNativesVarOptim.NumeroDeVariablesDePompage[pays]; - if (var >= 0) - { - Pi[nombreDeTermes] - = problemeHebdo->CaracteristiquesHydrauliques[pays].PumpingRatio; - Pi[nombreDeTermes] *= -1; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } + // var = CorrespondanceVarNativesVarOptim.NumeroDeVariablesDePompage[pays]; + // if (var >= 0) + // { + // Pi[nombreDeTermes] + // = problemeHebdo->CaracteristiquesHydrauliques[pays].PumpingRatio; + // Pi[nombreDeTermes] *= -1; + // Colonne[nombreDeTermes] = var; + // nombreDeTermes++; + // } - var = CorrespondanceVarNativesVarOptim.NumeroDeVariablesDeDebordement[pays]; - if (var >= 0) - { - Pi[nombreDeTermes] = 1.; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } + // var = CorrespondanceVarNativesVarOptim.NumeroDeVariablesDeDebordement[pays]; + // if (var >= 0) + // { + // Pi[nombreDeTermes] = 1.; + // Colonne[nombreDeTermes] = var; + // nombreDeTermes++; + // } - CorrespondanceCntNativesCntOptim.NumeroDeContrainteDesNiveauxPays[pays] - = ProblemeAResoudre->NombreDeContraintes; + // CorrespondanceCntNativesCntOptim.NumeroDeContrainteDesNiveauxPays[pays] + // = ProblemeAResoudre->NombreDeContraintes; - constraintNamer.AreaHydroLevel(ProblemeAResoudre->NombreDeContraintes); - OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '='); - } - else - CorrespondanceCntNativesCntOptim.NumeroDeContrainteDesNiveauxPays[pays] = -1; + // constraintNamer.AreaHydroLevel(ProblemeAResoudre->NombreDeContraintes); + // OPT_ChargerLaContrainteDansLaMatriceDesContraintes( + // ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '='); + // } + // else + // CorrespondanceCntNativesCntOptim.NumeroDeContrainteDesNiveauxPays[pays] = -1; } } From b7b022cb04f2ac3ac43d782fe39f4495ca99d31c Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Sun, 3 Sep 2023 14:53:44 +0200 Subject: [PATCH 15/43] finally --- .../optimisation/FinalStockEquivalent.cpp | 16 ++- .../optimisation/FinalStockExpression.cpp | 31 +++-- ...n_matrice_des_contraintes_cas_lineaire.cpp | 117 ++++++++++-------- 3 files changed, 91 insertions(+), 73 deletions(-) diff --git a/src/solver/optimisation/FinalStockEquivalent.cpp b/src/solver/optimisation/FinalStockEquivalent.cpp index 01b9674d64..d978885473 100644 --- a/src/solver/optimisation/FinalStockEquivalent.cpp +++ b/src/solver/optimisation/FinalStockEquivalent.cpp @@ -12,10 +12,16 @@ void FinalStockEquivalent::add(int pays) namer.UpdateArea(problemeHebdo->NomsDesPays[pays]); namer.UpdateTimeStep(problemeHebdo->weekInTheYear * 168 + pdt); namer.FinalStockEquivalent(problemeHebdo->ProblemeAResoudre->NombreDeContraintes); + if (problemeHebdo->CaracteristiquesHydrauliques[pays].AccurateWaterValue + && problemeHebdo->CaracteristiquesHydrauliques[pays].DirectLevelAccess) + { /* equivalence constraint : StockFinal- Niveau[T]= 0*/ - builder.updateHourWithinWeek(pdt) - .include(Variable::FinalStorage(pays), 1.0) - .include(Variable::HydroLevel(pays), -1.0) - .equalTo() - .build(); + problemeHebdo->NumeroDeContrainteEquivalenceStockFinal[pays] + = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; + builder.updateHourWithinWeek(pdt) + .include(Variable::FinalStorage(pays), 1.0) + .include(Variable::HydroLevel(pays), -1.0) + .equalTo() + .build(); + } } diff --git a/src/solver/optimisation/FinalStockExpression.cpp b/src/solver/optimisation/FinalStockExpression.cpp index 87505f34b0..611f40f18f 100644 --- a/src/solver/optimisation/FinalStockExpression.cpp +++ b/src/solver/optimisation/FinalStockExpression.cpp @@ -2,20 +2,25 @@ void FinalStockExpression::add(int pays) { - problemeHebdo->NumeroDeContrainteExpressionStockFinal[pays] - = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; - const auto pdt = problemeHebdo->NombreDePasDeTempsPourUneOptimisation - 1; - builder.updateHourWithinWeek(pdt).include(Variable::FinalStorage(pays), -1.0); - for (int layerindex = 0; layerindex < 100; layerindex++) + + if (problemeHebdo->CaracteristiquesHydrauliques[pays].AccurateWaterValue) + /* expression constraint : - StockFinal +sum (stocklayers) = 0*/ { - builder.include(Variable::LayerStorage(pays, layerindex), 1.0); - } - ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, - problemeHebdo->NamedProblems); + builder.updateHourWithinWeek(pdt).include(Variable::FinalStorage(pays), -1.0); + for (int layerindex = 0; layerindex < 100; layerindex++) + { + builder.include(Variable::LayerStorage(pays, layerindex), 1.0); + } + problemeHebdo->NumeroDeContrainteExpressionStockFinal[pays] + = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; - namer.UpdateArea(problemeHebdo->NomsDesPays[pays]); - namer.UpdateTimeStep(problemeHebdo->weekInTheYear * 168 + pdt); - namer.FinalStockExpression(problemeHebdo->ProblemeAResoudre->NombreDeContraintes); - builder.equalTo().build(); + ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, + problemeHebdo->NamedProblems); + + namer.UpdateArea(problemeHebdo->NomsDesPays[pays]); + namer.UpdateTimeStep(problemeHebdo->weekInTheYear * 168 + pdt); + namer.FinalStockExpression(problemeHebdo->ProblemeAResoudre->NombreDeContraintes); + builder.equalTo().build(); + } } 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 3c32e4dda3..d3ee5f1408 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 @@ -46,6 +46,9 @@ #include "MaxPumping.h" #include "AreaHydroLevel.h" +#include "FinalStockEquivalent.h" +#include "FinalStockExpression.h" + #include using namespace Antares::Data; @@ -206,6 +209,9 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro AreaHydroLevel areaHydroLevel(problemeHebdo); + FinalStockEquivalent finalStockEquivalent(problemeHebdo); + FinalStockExpression finalStockExpression(problemeHebdo); + for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) { int timeStepInYear = problemeHebdo->weekInTheYear * 168 + pdt; @@ -1055,65 +1061,66 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro const auto& week = problemeHebdo->weekInTheYear; constraintNamer.UpdateArea(problemeHebdo->NomsDesPays[pays]); constraintNamer.UpdateTimeStep(week * 168 + nombreDePasDeTempsPourUneOptimisation - 1); + finalStockEquivalent.add(pays); + // if (problemeHebdo->CaracteristiquesHydrauliques[pays].AccurateWaterValue + // && problemeHebdo->CaracteristiquesHydrauliques[pays].DirectLevelAccess) + // /* equivalence constraint : StockFinal- Niveau[T]= 0*/ + // { + // int nombreDeTermes = 0; + // var = problemeHebdo->NumeroDeVariableStockFinal[pays]; + // if (var >= 0) + // { + // Pi[nombreDeTermes] = 1.0; + // Colonne[nombreDeTermes] = var; + // nombreDeTermes++; + // } + // var = problemeHebdo + // ->CorrespondanceVarNativesVarOptim[nombreDePasDeTempsPourUneOptimisation - 1] + // .NumeroDeVariablesDeNiveau[pays]; + // if (var >= 0) + // { + // Pi[nombreDeTermes] = -1.0; + // Colonne[nombreDeTermes] = var; + // nombreDeTermes++; + // } + // problemeHebdo->NumeroDeContrainteEquivalenceStockFinal[pays] + // = ProblemeAResoudre->NombreDeContraintes; - if (problemeHebdo->CaracteristiquesHydrauliques[pays].AccurateWaterValue - && problemeHebdo->CaracteristiquesHydrauliques[pays].DirectLevelAccess) - /* equivalence constraint : StockFinal- Niveau[T]= 0*/ - { - int nombreDeTermes = 0; - var = problemeHebdo->NumeroDeVariableStockFinal[pays]; - if (var >= 0) - { - Pi[nombreDeTermes] = 1.0; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } - var = problemeHebdo - ->CorrespondanceVarNativesVarOptim[nombreDePasDeTempsPourUneOptimisation - 1] - .NumeroDeVariablesDeNiveau[pays]; - if (var >= 0) - { - Pi[nombreDeTermes] = -1.0; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } - problemeHebdo->NumeroDeContrainteEquivalenceStockFinal[pays] - = ProblemeAResoudre->NombreDeContraintes; + // constraintNamer.FinalStockEquivalent(ProblemeAResoudre->NombreDeContraintes); + // OPT_ChargerLaContrainteDansLaMatriceDesContraintes( + // ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '='); + // } + finalStockExpression.add(pays); + // if (problemeHebdo->CaracteristiquesHydrauliques[pays].AccurateWaterValue) + // /* expression constraint : - StockFinal +sum (stocklayers) = 0*/ + // { + // int nombreDeTermes = 0; + // var = problemeHebdo->NumeroDeVariableStockFinal[pays]; + // if (var >= 0) + // { + // Pi[nombreDeTermes] = -1.0; + // Colonne[nombreDeTermes] = var; + // nombreDeTermes++; + // } + // for (int layerindex = 0; layerindex < 100; layerindex++) + // { + // var = problemeHebdo->NumeroDeVariableDeTrancheDeStock[pays][layerindex]; - constraintNamer.FinalStockEquivalent(ProblemeAResoudre->NombreDeContraintes); - OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '='); - } - if (problemeHebdo->CaracteristiquesHydrauliques[pays].AccurateWaterValue) - /* expression constraint : - StockFinal +sum (stocklayers) = 0*/ - { - int nombreDeTermes = 0; - var = problemeHebdo->NumeroDeVariableStockFinal[pays]; - if (var >= 0) - { - Pi[nombreDeTermes] = -1.0; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } - for (int layerindex = 0; layerindex < 100; layerindex++) - { - var = problemeHebdo->NumeroDeVariableDeTrancheDeStock[pays][layerindex]; - - if (var >= 0) - { - Pi[nombreDeTermes] = 1.0; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } - } + // if (var >= 0) + // { + // Pi[nombreDeTermes] = 1.0; + // Colonne[nombreDeTermes] = var; + // nombreDeTermes++; + // } + // } - problemeHebdo->NumeroDeContrainteExpressionStockFinal[pays] - = ProblemeAResoudre->NombreDeContraintes; + // problemeHebdo->NumeroDeContrainteExpressionStockFinal[pays] + // = ProblemeAResoudre->NombreDeContraintes; - constraintNamer.FinalStockExpression(ProblemeAResoudre->NombreDeContraintes); - OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '='); - } + // constraintNamer.FinalStockExpression(ProblemeAResoudre->NombreDeContraintes); + // OPT_ChargerLaContrainteDansLaMatriceDesContraintes( + // ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '='); + // } } if (problemeHebdo->OptimisationAvecCoutsDeDemarrage) From 317bdb5b69bca28bcff1999cda64bf4e3eb4119b Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Sun, 3 Sep 2023 15:17:22 +0200 Subject: [PATCH 16/43] basic --- .../optimisation/FinalStockEquivalent.cpp | 27 ++++---- ...n_matrice_des_contraintes_cas_lineaire.cpp | 64 +++++++++---------- 2 files changed, 45 insertions(+), 46 deletions(-) diff --git a/src/solver/optimisation/FinalStockEquivalent.cpp b/src/solver/optimisation/FinalStockEquivalent.cpp index d978885473..24f13c1542 100644 --- a/src/solver/optimisation/FinalStockEquivalent.cpp +++ b/src/solver/optimisation/FinalStockEquivalent.cpp @@ -3,25 +3,24 @@ void FinalStockEquivalent::add(int pays) { const auto pdt = problemeHebdo->NombreDePasDeTempsPourUneOptimisation - 1; - problemeHebdo->NumeroDeContrainteEquivalenceStockFinal[pays] - = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; - - ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, - problemeHebdo->NamedProblems); - - namer.UpdateArea(problemeHebdo->NomsDesPays[pays]); - namer.UpdateTimeStep(problemeHebdo->weekInTheYear * 168 + pdt); - namer.FinalStockEquivalent(problemeHebdo->ProblemeAResoudre->NombreDeContraintes); if (problemeHebdo->CaracteristiquesHydrauliques[pays].AccurateWaterValue && problemeHebdo->CaracteristiquesHydrauliques[pays].DirectLevelAccess) { /* equivalence constraint : StockFinal- Niveau[T]= 0*/ problemeHebdo->NumeroDeContrainteEquivalenceStockFinal[pays] = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; - builder.updateHourWithinWeek(pdt) - .include(Variable::FinalStorage(pays), 1.0) - .include(Variable::HydroLevel(pays), -1.0) - .equalTo() - .build(); + ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, + problemeHebdo->NamedProblems); + + namer.UpdateArea(problemeHebdo->NomsDesPays[pays]); + namer.UpdateTimeStep(problemeHebdo->weekInTheYear * 168 + pdt); + namer.FinalStockEquivalent(problemeHebdo->ProblemeAResoudre->NombreDeContraintes); + + builder.updateHourWithinWeek(pdt) + .include(Variable::FinalStorage(pays), 1.0) + .updateHourWithinWeek(problemeHebdo->NombreDePasDeTempsPourUneOptimisation - 1) + .include(Variable::HydroLevel(pays), -1.0) + .equalTo() + .build(); } } 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 d3ee5f1408..96290773ea 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 @@ -1058,9 +1058,9 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro /* For each area with ad hoc properties, two possible sets of two additional constraints */ for (uint32_t pays = 0; pays < problemeHebdo->NombreDePays; pays++) { - const auto& week = problemeHebdo->weekInTheYear; - constraintNamer.UpdateArea(problemeHebdo->NomsDesPays[pays]); - constraintNamer.UpdateTimeStep(week * 168 + nombreDePasDeTempsPourUneOptimisation - 1); + // const auto& week = problemeHebdo->weekInTheYear; + // constraintNamer.UpdateArea(problemeHebdo->NomsDesPays[pays]); + // constraintNamer.UpdateTimeStep(week * 168 + nombreDePasDeTempsPourUneOptimisation - 1); finalStockEquivalent.add(pays); // if (problemeHebdo->CaracteristiquesHydrauliques[pays].AccurateWaterValue // && problemeHebdo->CaracteristiquesHydrauliques[pays].DirectLevelAccess) @@ -1090,37 +1090,37 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro // OPT_ChargerLaContrainteDansLaMatriceDesContraintes( // ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '='); // } - finalStockExpression.add(pays); - // if (problemeHebdo->CaracteristiquesHydrauliques[pays].AccurateWaterValue) - // /* expression constraint : - StockFinal +sum (stocklayers) = 0*/ - // { - // int nombreDeTermes = 0; - // var = problemeHebdo->NumeroDeVariableStockFinal[pays]; - // if (var >= 0) - // { - // Pi[nombreDeTermes] = -1.0; - // Colonne[nombreDeTermes] = var; - // nombreDeTermes++; - // } - // for (int layerindex = 0; layerindex < 100; layerindex++) - // { - // var = problemeHebdo->NumeroDeVariableDeTrancheDeStock[pays][layerindex]; - - // if (var >= 0) - // { - // Pi[nombreDeTermes] = 1.0; - // Colonne[nombreDeTermes] = var; - // nombreDeTermes++; - // } - // } + // finalStockExpression.add(pays); + if (problemeHebdo->CaracteristiquesHydrauliques[pays].AccurateWaterValue) + /* expression constraint : - StockFinal +sum (stocklayers) = 0*/ + { + int nombreDeTermes = 0; + var = problemeHebdo->NumeroDeVariableStockFinal[pays]; + if (var >= 0) + { + Pi[nombreDeTermes] = -1.0; + Colonne[nombreDeTermes] = var; + nombreDeTermes++; + } + for (int layerindex = 0; layerindex < 100; layerindex++) + { + var = problemeHebdo->NumeroDeVariableDeTrancheDeStock[pays][layerindex]; + + if (var >= 0) + { + Pi[nombreDeTermes] = 1.0; + Colonne[nombreDeTermes] = var; + nombreDeTermes++; + } + } - // problemeHebdo->NumeroDeContrainteExpressionStockFinal[pays] - // = ProblemeAResoudre->NombreDeContraintes; + problemeHebdo->NumeroDeContrainteExpressionStockFinal[pays] + = ProblemeAResoudre->NombreDeContraintes; - // constraintNamer.FinalStockExpression(ProblemeAResoudre->NombreDeContraintes); - // OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - // ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '='); - // } + constraintNamer.FinalStockExpression(ProblemeAResoudre->NombreDeContraintes); + OPT_ChargerLaContrainteDansLaMatriceDesContraintes( + ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '='); + } } if (problemeHebdo->OptimisationAvecCoutsDeDemarrage) From fcef054dd6cbd6217e73324014d3e7881e575c7c Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Sun, 3 Sep 2023 15:19:37 +0200 Subject: [PATCH 17/43] tiny --- ...n_matrice_des_contraintes_cas_lineaire.cpp | 58 +++++++++---------- 1 file changed, 29 insertions(+), 29 deletions(-) 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 96290773ea..cfd133ed4e 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 @@ -1090,37 +1090,37 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro // OPT_ChargerLaContrainteDansLaMatriceDesContraintes( // ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '='); // } - // finalStockExpression.add(pays); - if (problemeHebdo->CaracteristiquesHydrauliques[pays].AccurateWaterValue) - /* expression constraint : - StockFinal +sum (stocklayers) = 0*/ - { - int nombreDeTermes = 0; - var = problemeHebdo->NumeroDeVariableStockFinal[pays]; - if (var >= 0) - { - Pi[nombreDeTermes] = -1.0; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } - for (int layerindex = 0; layerindex < 100; layerindex++) - { - var = problemeHebdo->NumeroDeVariableDeTrancheDeStock[pays][layerindex]; - - if (var >= 0) - { - Pi[nombreDeTermes] = 1.0; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } - } + finalStockExpression.add(pays); + // if (problemeHebdo->CaracteristiquesHydrauliques[pays].AccurateWaterValue) + // /* expression constraint : - StockFinal +sum (stocklayers) = 0*/ + // { + // int nombreDeTermes = 0; + // var = problemeHebdo->NumeroDeVariableStockFinal[pays]; + // if (var >= 0) + // { + // Pi[nombreDeTermes] = -1.0; + // Colonne[nombreDeTermes] = var; + // nombreDeTermes++; + // } + // for (int layerindex = 0; layerindex < 100; layerindex++) + // { + // var = problemeHebdo->NumeroDeVariableDeTrancheDeStock[pays][layerindex]; + + // if (var >= 0) + // { + // Pi[nombreDeTermes] = 1.0; + // Colonne[nombreDeTermes] = var; + // nombreDeTermes++; + // } + // } - problemeHebdo->NumeroDeContrainteExpressionStockFinal[pays] - = ProblemeAResoudre->NombreDeContraintes; + // problemeHebdo->NumeroDeContrainteExpressionStockFinal[pays] + // = ProblemeAResoudre->NombreDeContraintes; - constraintNamer.FinalStockExpression(ProblemeAResoudre->NombreDeContraintes); - OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '='); - } + // constraintNamer.FinalStockExpression(ProblemeAResoudre->NombreDeContraintes); + // OPT_ChargerLaContrainteDansLaMatriceDesContraintes( + // ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '='); + // } } if (problemeHebdo->OptimisationAvecCoutsDeDemarrage) From 2364b3548db3c117f12966a5cbe4f965e359ecb4 Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Mon, 4 Sep 2023 10:55:19 +0200 Subject: [PATCH 18/43] clean code --- ...n_matrice_des_contraintes_cas_lineaire.cpp | 917 +----------------- 1 file changed, 1 insertion(+), 916 deletions(-) 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 cfd133ed4e..74cd53e4f0 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 @@ -45,7 +45,6 @@ #include "MaxHydroPower.h" #include "MaxPumping.h" #include "AreaHydroLevel.h" - #include "FinalStockEquivalent.h" #include "FinalStockExpression.h" @@ -53,126 +52,6 @@ using namespace Antares::Data; -// // void exportPaliers(const PROBLEME_HEBDO& problemeHebdo, -// // const CORRESPONDANCES_DES_VARIABLES& CorrespondanceVarNativesVarOptim, -// // int pays, -// // int& nombreDeTermes, -// // std::vector& Pi, -// // std::vector& Colonne) -// // { -// // const PALIERS_THERMIQUES& PaliersThermiquesDuPays = -// // problemeHebdo.PaliersThermiquesDuPays[pays]; - -// // for (int index = 0; index < PaliersThermiquesDuPays.NombreDePaliersThermiques; index++) -// // { -// // const int palier -// // = PaliersThermiquesDuPays.NumeroDuPalierDansLEnsembleDesPaliersThermiques[index]; -// // int var = CorrespondanceVarNativesVarOptim.NumeroDeVariableDuPalierThermique[palier]; -// // if (var >= 0) -// // { -// // Pi[nombreDeTermes] = -1.0; -// // Colonne[nombreDeTermes] = var; -// // nombreDeTermes++; -// // } -// // } -// // } - -// static void shortTermStorageBalance( -// const ::ShortTermStorage::AREA_INPUT& shortTermStorageInput, -// const CORRESPONDANCES_DES_VARIABLES& CorrespondanceVarNativesVarOptim, -// int& nombreDeTermes, -// std::vector& Pi, -// std::vector& Colonne) -// { -// for (const auto& storage : shortTermStorageInput) -// { -// const int clusterGlobalIndex = storage.clusterGlobalIndex; -// if (const int varInjection = CorrespondanceVarNativesVarOptim.SIM_ShortTermStorage -// .InjectionVariable[clusterGlobalIndex]; -// varInjection >= 0) -// { -// Pi[nombreDeTermes] = 1.0; -// Colonne[nombreDeTermes] = varInjection; -// nombreDeTermes++; -// } - -// if (const int varWithdrawal = CorrespondanceVarNativesVarOptim.SIM_ShortTermStorage -// .WithdrawalVariable[clusterGlobalIndex]; -// varWithdrawal >= 0) -// { -// Pi[nombreDeTermes] = -1.0; -// Colonne[nombreDeTermes] = varWithdrawal; -// nombreDeTermes++; -// } -// } -// } - -// static void shortTermStorageLevels( -// const ::ShortTermStorage::AREA_INPUT& shortTermStorageInput, -// PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre, -// CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim, -// std::vector& CorrespondanceVarNativesVarOptim, -// std::vector& Pi, -// std::vector& Colonne, -// int nombreDePasDeTempsPourUneOptimisation, -// int pdt, -// ConstraintNamer& constraintNamer) -// { -// const auto& VarOptimCurrent = CorrespondanceVarNativesVarOptim[pdt]; -// // Cycle over the simulation period -// const int timestepPrevious -// = (pdt - 1 + nombreDePasDeTempsPourUneOptimisation) % -// nombreDePasDeTempsPourUneOptimisation; -// const auto& VarOptimPrevious = CorrespondanceVarNativesVarOptim[timestepPrevious]; -// for (auto& storage : shortTermStorageInput) -// { -// int nombreDeTermes = 0; -// const int clusterGlobalIndex = storage.clusterGlobalIndex; -// // L[h] - L[h-1] - efficiency * injection[h] + withdrawal[h] = inflows[h] -// if (const int varLevel -// = VarOptimCurrent.SIM_ShortTermStorage.LevelVariable[clusterGlobalIndex]; -// varLevel >= 0) -// { -// Pi[nombreDeTermes] = 1.0; -// Colonne[nombreDeTermes] = varLevel; -// nombreDeTermes++; -// } - -// if (const int varLevel_previous -// = VarOptimPrevious.SIM_ShortTermStorage.LevelVariable[clusterGlobalIndex]; -// varLevel_previous >= 0) -// { -// Pi[nombreDeTermes] = -1.0; -// Colonne[nombreDeTermes] = varLevel_previous; -// nombreDeTermes++; -// } - -// if (const int varInjection -// = VarOptimCurrent.SIM_ShortTermStorage.InjectionVariable[clusterGlobalIndex]; -// varInjection >= 0) -// { -// Pi[nombreDeTermes] = -1.0 * storage.efficiency; -// Colonne[nombreDeTermes] = varInjection; -// nombreDeTermes++; -// } - -// if (const int varWithdrawal -// = VarOptimCurrent.SIM_ShortTermStorage.WithdrawalVariable[clusterGlobalIndex]; -// varWithdrawal >= 0) -// { -// Pi[nombreDeTermes] = 1.0; -// Colonne[nombreDeTermes] = varWithdrawal; -// nombreDeTermes++; -// } -// CorrespondanceCntNativesCntOptim.ShortTermStorageLevelConstraint[clusterGlobalIndex] -// = ProblemeAResoudre->NombreDeContraintes; - -// constraintNamer.ShortTermStorageLevel(ProblemeAResoudre->NombreDeContraintes, -// storage.name); OPT_ChargerLaContrainteDansLaMatriceDesContraintes( -// ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '='); -// } -// } - void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* problemeHebdo, Solver::IResultWriter& writer) { int var; @@ -228,265 +107,21 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro for (uint32_t pays = 0; pays < problemeHebdo->NombreDePays; pays++) { - int nombreDeTermes = 0; areaBalance.add(pdt, pays); - // int interco = problemeHebdo->IndexDebutIntercoOrigine[pays]; - constraintNamer.UpdateArea(problemeHebdo->NomsDesPays[pays]); - - // while (interco >= 0) - // { - // var = - // CorrespondanceVarNativesVarOptim.NumeroDeVariableDeLInterconnexion[interco]; if - // (var >= 0) - // { - // Pi[nombreDeTermes] = 1.0; - // Colonne[nombreDeTermes] = var; - // nombreDeTermes++; - // } - // interco = problemeHebdo->IndexSuivantIntercoOrigine[interco]; - // } - // interco = problemeHebdo->IndexDebutIntercoExtremite[pays]; - // while (interco >= 0) - // { - // var = - // CorrespondanceVarNativesVarOptim.NumeroDeVariableDeLInterconnexion[interco]; if - // (var >= 0) - // { - // Pi[nombreDeTermes] = -1.0; - // Colonne[nombreDeTermes] = var; - // nombreDeTermes++; - // } - // interco = problemeHebdo->IndexSuivantIntercoExtremite[interco]; - // } - - // exportPaliers( - // *problemeHebdo, CorrespondanceVarNativesVarOptim, pays, nombreDeTermes, Pi, - // Colonne); - - // var = CorrespondanceVarNativesVarOptim.NumeroDeVariablesDeLaProdHyd[pays]; - // if (var >= 0) - // { - // Pi[nombreDeTermes] = -1.0; - // Colonne[nombreDeTermes] = var; - // nombreDeTermes++; - // } - - // var = CorrespondanceVarNativesVarOptim.NumeroDeVariablesDePompage[pays]; - // if (var >= 0) - // { - // Pi[nombreDeTermes] = 1.0; - // Colonne[nombreDeTermes] = var; - // nombreDeTermes++; - // } - - // var = CorrespondanceVarNativesVarOptim.NumeroDeVariableDefaillancePositive[pays]; - // if (var >= 0) - // { - // Pi[nombreDeTermes] = -1.0; - // Colonne[nombreDeTermes] = var; - // nombreDeTermes++; - // } - // var = CorrespondanceVarNativesVarOptim.NumeroDeVariableDefaillanceNegative[pays]; - // if (var >= 0) - // { - // Pi[nombreDeTermes] = 1.0; - // Colonne[nombreDeTermes] = var; - // nombreDeTermes++; - // } - - // shortTermStorageBalance(problemeHebdo->ShortTermStorage[pays], - // CorrespondanceVarNativesVarOptim, - // nombreDeTermes, - // Pi, - // Colonne); - - // CorrespondanceCntNativesCntOptim.NumeroDeContrainteDesBilansPays[pays] - // = ProblemeAResoudre->NombreDeContraintes; - // constraintNamer.AreaBalance(ProblemeAResoudre->NombreDeContraintes); - // OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - // ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '='); - // nombreDeTermes = 0; - - // exportPaliers( - // *problemeHebdo, CorrespondanceVarNativesVarOptim, pays, nombreDeTermes, Pi, - // Colonne); - // var = CorrespondanceVarNativesVarOptim.NumeroDeVariablesDeLaProdHyd[pays]; - // if (var >= 0) - // { - // Pi[nombreDeTermes] = -problemeHebdo->DefaillanceNegativeUtiliserHydro[pays]; - // Colonne[nombreDeTermes] = var; - // nombreDeTermes++; - // } - - // var = CorrespondanceVarNativesVarOptim.NumeroDeVariableDefaillanceNegative[pays]; - // if (var >= 0) - // { - // Pi[nombreDeTermes] = 1.0; - // Colonne[nombreDeTermes] = var; - // nombreDeTermes++; - // } - - // CorrespondanceCntNativesCntOptim.NumeroDeContraintePourEviterLesChargesFictives[pays] - // = ProblemeAResoudre->NombreDeContraintes; - - // constraintNamer.FictiveLoads(ProblemeAResoudre->NombreDeContraintes); - // OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - // ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '<'); fictitiousLoad.add(pdt, pays); - // Short term storage - // shortTermStorageLevels(problemeHebdo->ShortTermStorage[pays], - // ProblemeAResoudre, - // CorrespondanceCntNativesCntOptim, - // problemeHebdo->CorrespondanceVarNativesVarOptim, - // Pi, - // Colonne, - // nombreDePasDeTempsPourUneOptimisation, - // pdt, - // constraintNamer); + shortTermStorageLevel.add(pdt, pays); } for (uint32_t interco = 0; interco < problemeHebdo->NombreDInterconnexions; interco++) { flowDissociation.add(pdt, interco); - // if (problemeHebdo->CoutDeTransport[interco].IntercoGereeAvecDesCouts) - // { - // int nombreDeTermes = 0; - // var = - // CorrespondanceVarNativesVarOptim.NumeroDeVariableDeLInterconnexion[interco]; if - // (var >= 0) - // { - // Pi[nombreDeTermes] = 1.0; - // Colonne[nombreDeTermes] = var; - // nombreDeTermes++; - // } - // var = CorrespondanceVarNativesVarOptim - // .NumeroDeVariableCoutOrigineVersExtremiteDeLInterconnexion[interco]; - // if (var >= 0) - // { - // Pi[nombreDeTermes] = -1.0; - // Colonne[nombreDeTermes] = var; - // nombreDeTermes++; - // } - // var = CorrespondanceVarNativesVarOptim - // .NumeroDeVariableCoutExtremiteVersOrigineDeLInterconnexion[interco]; - // if (var >= 0) - // { - // Pi[nombreDeTermes] = 1.0; - // Colonne[nombreDeTermes] = var; - // nombreDeTermes++; - // } - - // CorrespondanceCntNativesCntOptim.NumeroDeContrainteDeDissociationDeFlux[interco] - // = ProblemeAResoudre->NombreDeContraintes; - // const auto origin - // = problemeHebdo - // ->NomsDesPays[problemeHebdo->PaysOrigineDeLInterconnexion[interco]]; - // const auto destination - // = problemeHebdo - // ->NomsDesPays[problemeHebdo->PaysExtremiteDeLInterconnexion[interco]]; - // constraintNamer.FlowDissociation( - // ProblemeAResoudre->NombreDeContraintes, origin, destination); - // OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - // ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '='); - // } } for (uint32_t cntCouplante = 0; cntCouplante < problemeHebdo->NombreDeContraintesCouplantes; cntCouplante++) { bindingConstraintHour.add(pdt, cntCouplante); - // const CONTRAINTES_COUPLANTES& MatriceDesContraintesCouplantes - // = problemeHebdo->MatriceDesContraintesCouplantes[cntCouplante]; - - // if (MatriceDesContraintesCouplantes.TypeDeContrainteCouplante != - // CONTRAINTE_HORAIRE) - // continue; - - // int nbInterco - // = - // MatriceDesContraintesCouplantes.NombreDInterconnexionsDansLaContrainteCouplante; - // int nombreDeTermes = 0; - // for (int index = 0; index < nbInterco; index++) - // { - // int interco = MatriceDesContraintesCouplantes.NumeroDeLInterconnexion[index]; - // double poids = MatriceDesContraintesCouplantes.PoidsDeLInterconnexion[index]; - // int Offset = - // MatriceDesContraintesCouplantes.OffsetTemporelSurLInterco[index]; int pdt1; - - // if (Offset >= 0) - // { - // pdt1 = (pdt + Offset) % nombreDePasDeTempsPourUneOptimisation; - // } - // else - // { - // pdt1 = (pdt + Offset + problemeHebdo->NombreDePasDeTemps) - // % nombreDePasDeTempsPourUneOptimisation; - // } - // logs.info() << " BindingConstraintHour::add:1:: pdt1 =" << pdt1 << "\n"; - - // var = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt1] - // .NumeroDeVariableDeLInterconnexion[interco]; - // logs.info() << "varIndex: " << var << "\n"; - - // if (var >= 0) - // { - // Pi[nombreDeTermes] = poids; - // Colonne[nombreDeTermes] = var; - // nombreDeTermes++; - // } - // } - - // int nbClusters - // = - // MatriceDesContraintesCouplantes.NombreDePaliersDispatchDansLaContrainteCouplante; - // for (int index = 0; index < nbClusters; index++) - // { - // int pays = MatriceDesContraintesCouplantes.PaysDuPalierDispatch[index]; - // const PALIERS_THERMIQUES& PaliersThermiquesDuPays - // = problemeHebdo->PaliersThermiquesDuPays[pays]; - // const int palier - // = PaliersThermiquesDuPays.NumeroDuPalierDansLEnsembleDesPaliersThermiques - // [MatriceDesContraintesCouplantes.NumeroDuPalierDispatch[index]]; - // double poids = MatriceDesContraintesCouplantes.PoidsDuPalierDispatch[index]; - // int Offset - // = MatriceDesContraintesCouplantes.OffsetTemporelSurLePalierDispatch[index]; - // int pdt1; - // if (Offset >= 0) - // { - // pdt1 = (pdt + Offset) % nombreDePasDeTempsPourUneOptimisation; - // } - // else - // { - // pdt1 = (pdt + Offset + problemeHebdo->NombreDePasDeTemps) - // % nombreDePasDeTempsPourUneOptimisation; - // } - // logs.info() << " BindingConstraintHour::add:2:: pdt1 =" << pdt1 << "\n"; - - // var = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt1] - // .NumeroDeVariableDuPalierThermique[palier]; - // logs.info() << "varIndex: " << var << "\n"; - - // if (var >= 0) - // { - // Pi[nombreDeTermes] = poids; - // Colonne[nombreDeTermes] = var; - // nombreDeTermes++; - // } - // } - // CorrespondanceCntNativesCntOptim - // .NumeroDeContrainteDesContraintesCouplantes[cntCouplante] - // = ProblemeAResoudre->NombreDeContraintes; - - // constraintNamer.BindingConstraintHour( - // ProblemeAResoudre->NombreDeContraintes, - // MatriceDesContraintesCouplantes.NomDeLaContrainteCouplante); - // OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - // ProblemeAResoudre, - // Pi, - // Colonne, - // nombreDeTermes, - // MatriceDesContraintesCouplantes.SensDeLaContrainteCouplante); } } @@ -494,106 +129,6 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro cntCouplante++) { bindingConstraintDay.add(cntCouplante); - // const CONTRAINTES_COUPLANTES& MatriceDesContraintesCouplantes - // = problemeHebdo->MatriceDesContraintesCouplantes[cntCouplante]; - // if (MatriceDesContraintesCouplantes.TypeDeContrainteCouplante != CONTRAINTE_JOURNALIERE) - // continue; - - // int nbInterco - // = MatriceDesContraintesCouplantes.NombreDInterconnexionsDansLaContrainteCouplante; - // int nbClusters - // = MatriceDesContraintesCouplantes.NombreDePaliersDispatchDansLaContrainteCouplante; - // int pdtDebut = 0; - // while (pdtDebut < nombreDePasDeTempsPourUneOptimisation) - // { - // int jour = problemeHebdo->NumeroDeJourDuPasDeTemps[pdtDebut]; - // CORRESPONDANCES_DES_CONTRAINTES_JOURNALIERES& - // CorrespondanceCntNativesCntOptimJournalieres - // = problemeHebdo->CorrespondanceCntNativesCntOptimJournalieres[jour]; - // int nombreDeTermes = 0; - - // for (int index = 0; index < nbInterco; index++) - // { - // int interco = MatriceDesContraintesCouplantes.NumeroDeLInterconnexion[index]; - // double poids = MatriceDesContraintesCouplantes.PoidsDeLInterconnexion[index]; - // int Offset = MatriceDesContraintesCouplantes.OffsetTemporelSurLInterco[index]; - - // for (int pdt = pdtDebut; pdt < pdtDebut + nombreDePasDeTempsDUneJournee; pdt++) - // { - // int pdt1; - // if (Offset >= 0) - // { - // pdt1 = (pdt + Offset) % nombreDePasDeTempsPourUneOptimisation; - // } - // else - // { - // pdt1 = (pdt + Offset + problemeHebdo->NombreDePasDeTemps) - // % nombreDePasDeTempsPourUneOptimisation; - // } - - // var = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt1] - // .NumeroDeVariableDeLInterconnexion[interco]; - // if (var >= 0) - // { - // Pi[nombreDeTermes] = poids; - // Colonne[nombreDeTermes] = var; - // nombreDeTermes++; - // } - // } - // } - - // for (int index = 0; index < nbClusters; index++) - // { - // int pays = MatriceDesContraintesCouplantes.PaysDuPalierDispatch[index]; - // const PALIERS_THERMIQUES& PaliersThermiquesDuPays - // = problemeHebdo->PaliersThermiquesDuPays[pays]; - // const int palier - // = PaliersThermiquesDuPays.NumeroDuPalierDansLEnsembleDesPaliersThermiques - // [MatriceDesContraintesCouplantes.NumeroDuPalierDispatch[index]]; - // double poids = MatriceDesContraintesCouplantes.PoidsDuPalierDispatch[index]; - // int Offset - // = MatriceDesContraintesCouplantes.OffsetTemporelSurLePalierDispatch[index]; - - // for (int pdt = pdtDebut; pdt < pdtDebut + nombreDePasDeTempsDUneJournee; pdt++) - // { - // int pdt1; - // if (Offset >= 0) - // { - // pdt1 = (pdt + Offset) % nombreDePasDeTempsPourUneOptimisation; - // } - // else - // { - // pdt1 = (pdt + Offset + problemeHebdo->NombreDePasDeTemps) - // % nombreDePasDeTempsPourUneOptimisation; - // } - - // var = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt1] - // .NumeroDeVariableDuPalierThermique[palier]; - // if (var >= 0) - // { - // Pi[nombreDeTermes] = poids; - // Colonne[nombreDeTermes] = var; - // nombreDeTermes++; - // } - // } - // } - - // CorrespondanceCntNativesCntOptimJournalieres - // .NumeroDeContrainteDesContraintesCouplantes[cntCouplante] - // = ProblemeAResoudre->NombreDeContraintes; - - // constraintNamer.UpdateTimeStep(jour); - // constraintNamer.BindingConstraintDay( - // ProblemeAResoudre->NombreDeContraintes, - // MatriceDesContraintesCouplantes.NomDeLaContrainteCouplante); - // OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - // ProblemeAResoudre, - // Pi, - // Colonne, - // nombreDeTermes, - // MatriceDesContraintesCouplantes.SensDeLaContrainteCouplante); - // pdtDebut += nombreDePasDeTempsDUneJournee; - // } } if (nombreDePasDeTempsPourUneOptimisation > nombreDePasDeTempsDUneJournee) @@ -605,161 +140,12 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro cntCouplante++) { bindingConstraintWeek.add(cntCouplante); - // const CONTRAINTES_COUPLANTES& MatriceDesContraintesCouplantes - // = problemeHebdo->MatriceDesContraintesCouplantes[cntCouplante]; - // if (MatriceDesContraintesCouplantes.TypeDeContrainteCouplante - // != CONTRAINTE_HEBDOMADAIRE) - // continue; - - // int nbInterco - // = MatriceDesContraintesCouplantes.NombreDInterconnexionsDansLaContrainteCouplante; - // int nombreDeTermes = 0; - // for (int index = 0; index < nbInterco; index++) - // { - // int interco = MatriceDesContraintesCouplantes.NumeroDeLInterconnexion[index]; - // double poids = MatriceDesContraintesCouplantes.PoidsDeLInterconnexion[index]; - // int Offset = MatriceDesContraintesCouplantes.OffsetTemporelSurLInterco[index]; - // for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) - // { - // int pdt1; - // if (Offset >= 0) - // { - // pdt1 = (pdt + Offset) % nombreDePasDeTempsPourUneOptimisation; - // } - // else - // { - // pdt1 = (pdt + Offset + problemeHebdo->NombreDePasDeTemps) - // % nombreDePasDeTempsPourUneOptimisation; - // } - - // var = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt1] - // .NumeroDeVariableDeLInterconnexion[interco]; - // if (var >= 0) - // { - // Pi[nombreDeTermes] = poids; - // Colonne[nombreDeTermes] = var; - // nombreDeTermes++; - // } - // } - // } - - // int nbClusters - // = MatriceDesContraintesCouplantes.NombreDePaliersDispatchDansLaContrainteCouplante; - // for (int index = 0; index < nbClusters; index++) - // { - // int pays = MatriceDesContraintesCouplantes.PaysDuPalierDispatch[index]; - // const PALIERS_THERMIQUES& PaliersThermiquesDuPays - // = problemeHebdo->PaliersThermiquesDuPays[pays]; - // const int palier - // = PaliersThermiquesDuPays.NumeroDuPalierDansLEnsembleDesPaliersThermiques - // [MatriceDesContraintesCouplantes.NumeroDuPalierDispatch[index]]; - // double poids = MatriceDesContraintesCouplantes.PoidsDuPalierDispatch[index]; - // int Offset - // = MatriceDesContraintesCouplantes.OffsetTemporelSurLePalierDispatch[index]; - // for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) - // { - // int pdt1; - // if (Offset >= 0) - // { - // pdt1 = (pdt + Offset) % nombreDePasDeTempsPourUneOptimisation; - // } - // else - // { - // pdt1 = (pdt + Offset + problemeHebdo->NombreDePasDeTemps) - // % nombreDePasDeTempsPourUneOptimisation; - // } - - // var = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt1] - // .NumeroDeVariableDuPalierThermique[palier]; - // if (var >= 0) - // { - // Pi[nombreDeTermes] = poids; - // Colonne[nombreDeTermes] = var; - // nombreDeTermes++; - // } - // } - // } - - // CorrespondanceCntNativesCntOptimHebdomadaires - // .NumeroDeContrainteDesContraintesCouplantes[cntCouplante] - // = ProblemeAResoudre->NombreDeContraintes; - - // constraintNamer.UpdateTimeStep(semaine); - // constraintNamer.BindingConstraintWeek( - // ProblemeAResoudre->NombreDeContraintes, - // MatriceDesContraintesCouplantes.NomDeLaContrainteCouplante); - // OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - // ProblemeAResoudre, - // Pi, - // Colonne, - // nombreDeTermes, - // MatriceDesContraintesCouplantes.SensDeLaContrainteCouplante); } } for (uint32_t pays = 0; pays < problemeHebdo->NombreDePays; pays++) { hydroPower.add(pays); - // constraintNamer.UpdateArea(problemeHebdo->NomsDesPays[pays]); - // bool presenceHydro - // = problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDHydrauliqueModulable; - // bool TurbEntreBornes - // = problemeHebdo->CaracteristiquesHydrauliques[pays].TurbinageEntreBornes; - // bool presencePompage - // = problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDePompageModulable; - - // int nombreDeTermes = 0; - // if (presenceHydro && !TurbEntreBornes) - // { - // if (presencePompage) - // { - // for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) - // { - // var = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt] - // .NumeroDeVariablesDeLaProdHyd[pays]; - - // if (var >= 0) - // { - // Pi[nombreDeTermes] = 1.0; - // Colonne[nombreDeTermes] = var; - // nombreDeTermes++; - // } - // var = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt] - // .NumeroDeVariablesDePompage[pays]; - // if (var >= 0) - // { - // Pi[nombreDeTermes] - // = problemeHebdo->CaracteristiquesHydrauliques[pays].PumpingRatio; - // Pi[nombreDeTermes] *= -1.0; - // Colonne[nombreDeTermes] = var; - // nombreDeTermes++; - // } - // } - // } - // else - // { - // for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) - // { - // var = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt] - // .NumeroDeVariablesDeLaProdHyd[pays]; - // if (var >= 0) - // { - // Pi[nombreDeTermes] = 1.0; - // Colonne[nombreDeTermes] = var; - // nombreDeTermes++; - // } - // } - // } - - // problemeHebdo->NumeroDeContrainteEnergieHydraulique[pays] - // = ProblemeAResoudre->NombreDeContraintes; - // constraintNamer.UpdateTimeStep(problemeHebdo->weekInTheYear); - // constraintNamer.HydroPower(ProblemeAResoudre->NombreDeContraintes); - // OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - // ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '='); - // } - // else - // problemeHebdo->NumeroDeContrainteEnergieHydraulique[pays] = -1; } if (problemeHebdo->TypeDeLissageHydraulique == LISSAGE_HYDRAULIQUE_SUR_SOMME_DES_VARIATIONS) @@ -770,57 +156,6 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro continue; hydroPowerSmoothingUsingVariationSum.add(pays); - // constraintNamer.UpdateArea(problemeHebdo->NomsDesPays[pays]); - // for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) - // { - // int timeStepInYear = problemeHebdo->weekInTheYear * 168 + pdt; - // constraintNamer.UpdateTimeStep(timeStepInYear); - // const auto& CorrespondanceVarNativesVarOptim - // = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt]; - // int nombreDeTermes = 0; - // var = CorrespondanceVarNativesVarOptim.NumeroDeVariablesDeLaProdHyd[pays]; - // if (var >= 0) - // { - // Pi[nombreDeTermes] = 1.0; - // Colonne[nombreDeTermes] = var; - // nombreDeTermes++; - // } - // int pdt1 = pdt + 1; - // if (pdt1 >= nombreDePasDeTempsPourUneOptimisation) - // pdt1 = 0; - - // if (int var1 = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt1] - // .NumeroDeVariablesDeLaProdHyd[pays]; - // var1 >= 0) - // { - // Pi[nombreDeTermes] = -1.0; - // Colonne[nombreDeTermes] = var1; - // nombreDeTermes++; - // } - - // if (int var2 = CorrespondanceVarNativesVarOptim - // .NumeroDeVariablesVariationHydALaBaisse[pays]; - // var2 >= 0) - // { - // Pi[nombreDeTermes] = -1.0; - // Colonne[nombreDeTermes] = var2; - // nombreDeTermes++; - // } - - // if (int var3 = CorrespondanceVarNativesVarOptim - // .NumeroDeVariablesVariationHydALaHausse[pays]; - // var3 >= 0) - // { - // Pi[nombreDeTermes] = 1.0; - // Colonne[nombreDeTermes] = var3; - // nombreDeTermes++; - // } - - // constraintNamer.HydroPowerSmoothingUsingVariationSum( - // ProblemeAResoudre->NombreDeContraintes); - // OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - // ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '='); - // } } } else if (problemeHebdo->TypeDeLissageHydraulique == LISSAGE_HYDRAULIQUE_SUR_VARIATION_MAX) @@ -835,53 +170,6 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro { hydroPowerSmoothingUsingVariationMaxDown.add(pays, pdt); hydroPowerSmoothingUsingVariationMaxUp.add(pays, pdt); - - // int timeStepInYear = problemeHebdo->weekInTheYear * 168 + pdt; - // constraintNamer.UpdateTimeStep(timeStepInYear); - // const auto& CorrespondanceVarNativesVarOptim - // = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt]; - // int nombreDeTermes = 0; - // var = CorrespondanceVarNativesVarOptim.NumeroDeVariablesDeLaProdHyd[pays]; - // if (var >= 0) - // { - // Pi[nombreDeTermes] = 1.0; - // Colonne[nombreDeTermes] = var; - // nombreDeTermes++; - // } - // int var1 = problemeHebdo->CorrespondanceVarNativesVarOptim[0] - // .NumeroDeVariablesVariationHydALaBaisse[pays]; - // if (var1 >= 0) - // { - // Pi[nombreDeTermes] = -1.0; - // Colonne[nombreDeTermes] = var1; - // nombreDeTermes++; - // } - - // constraintNamer.HydroPowerSmoothingUsingVariationMaxDown( - // ProblemeAResoudre->NombreDeContraintes); - // OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - // ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '<'); - - // nombreDeTermes = 0; - // if (var >= 0) - // { - // Pi[nombreDeTermes] = 1.0; - // Colonne[nombreDeTermes] = var; - // nombreDeTermes++; - // } - // var1 = problemeHebdo->CorrespondanceVarNativesVarOptim[0] - // .NumeroDeVariablesVariationHydALaHausse[pays]; - // if (var1 >= 0) - // { - // Pi[nombreDeTermes] = -1.0; - // Colonne[nombreDeTermes] = var1; - // nombreDeTermes++; - // } - - // constraintNamer.HydroPowerSmoothingUsingVariationMaxUp( - // ProblemeAResoudre->NombreDeContraintes); - // OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - // ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '>'); } } } @@ -889,96 +177,13 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro for (uint32_t pays = 0; pays < problemeHebdo->NombreDePays; pays++) { minHydroPower.add(pays); - // const bool presenceHydro - // = problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDHydrauliqueModulable; - // const bool presencePompage - // = problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDePompageModulable; - // const bool TurbEntreBornes - // = problemeHebdo->CaracteristiquesHydrauliques[pays].TurbinageEntreBornes; - // constraintNamer.UpdateArea(problemeHebdo->NomsDesPays[pays]); - // if (presenceHydro && (TurbEntreBornes || presencePompage)) - // { - // int nombreDeTermes = 0; - // for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) - // { - // var = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt] - // .NumeroDeVariablesDeLaProdHyd[pays]; - // if (var >= 0) - // { - // Pi[nombreDeTermes] = 1.0; - // Colonne[nombreDeTermes] = var; - // nombreDeTermes++; - // } - // } - // problemeHebdo->NumeroDeContrainteMinEnergieHydraulique[pays] - // = ProblemeAResoudre->NombreDeContraintes; - // constraintNamer.UpdateTimeStep(problemeHebdo->weekInTheYear); - // constraintNamer.MinHydroPower(ProblemeAResoudre->NombreDeContraintes); - // OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - // ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '>'); - // } - // else - // problemeHebdo->NumeroDeContrainteMinEnergieHydraulique[pays] = -1; maxHydroPower.add(pays); - // if (presenceHydro - // && (TurbEntreBornes - // || problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDePompageModulable)) - // { - // int nombreDeTermes = 0; - // for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) - // { - // constraintNamer.UpdateTimeStep(problemeHebdo->weekInTheYear * 168 + pdt); - // var = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt] - // .NumeroDeVariablesDeLaProdHyd[pays]; - // if (var >= 0) - // { - // Pi[nombreDeTermes] = 1.0; - // Colonne[nombreDeTermes] = var; - // nombreDeTermes++; - // } - // } - - // problemeHebdo->NumeroDeContrainteMaxEnergieHydraulique[pays] - // = ProblemeAResoudre->NombreDeContraintes; - // constraintNamer.UpdateTimeStep(problemeHebdo->weekInTheYear); - // constraintNamer.MaxHydroPower(ProblemeAResoudre->NombreDeContraintes); - // OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - // ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '<'); - // } - // else - // problemeHebdo->NumeroDeContrainteMaxEnergieHydraulique[pays] = -1; } for (uint32_t pays = 0; pays < problemeHebdo->NombreDePays; pays++) { maxPumping.add(pays); - // constraintNamer.UpdateArea(problemeHebdo->NomsDesPays[pays]); - // if (problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDePompageModulable) - // { - // int nombreDeTermes = 0; - // for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) - // { - // var = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt] - // .NumeroDeVariablesDePompage[pays]; - // if (var >= 0) - // { - // Pi[nombreDeTermes] = 1.0; - // Colonne[nombreDeTermes] = var; - // nombreDeTermes++; - // } - // } - - // problemeHebdo->NumeroDeContrainteMaxPompage[pays] - // = ProblemeAResoudre->NombreDeContraintes; - - // constraintNamer.UpdateTimeStep(problemeHebdo->weekInTheYear); - // constraintNamer.MaxPumping(ProblemeAResoudre->NombreDeContraintes); - // OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - // ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '<'); - // } - // else - // problemeHebdo->NumeroDeContrainteMaxPompage[pays] = -1; } for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) @@ -992,135 +197,15 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro for (uint32_t pays = 0; pays < problemeHebdo->NombreDePays; pays++) { areaHydroLevel.add(pays, pdt); - // constraintNamer.UpdateArea(problemeHebdo->NomsDesPays[pays]); - // if (problemeHebdo->CaracteristiquesHydrauliques[pays].SuiviNiveauHoraire) - // { - // int nombreDeTermes = 0; - - // var = CorrespondanceVarNativesVarOptim.NumeroDeVariablesDeNiveau[pays]; - // if (var >= 0) - // { - // Pi[nombreDeTermes] = 1.0; - // Colonne[nombreDeTermes] = var; - // nombreDeTermes++; - // } - - // if (pdt > 0) - // { - // int var1 = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt - 1] - // .NumeroDeVariablesDeNiveau[pays]; - // if (var1 >= 0) - // { - // Pi[nombreDeTermes] = -1.0; - // Colonne[nombreDeTermes] = var1; - // nombreDeTermes++; - // } - // } - - // var = CorrespondanceVarNativesVarOptim.NumeroDeVariablesDeLaProdHyd[pays]; - // if (var >= 0) - // { - // Pi[nombreDeTermes] = 1.0; - // Colonne[nombreDeTermes] = var; - // nombreDeTermes++; - // } - - // var = CorrespondanceVarNativesVarOptim.NumeroDeVariablesDePompage[pays]; - // if (var >= 0) - // { - // Pi[nombreDeTermes] - // = problemeHebdo->CaracteristiquesHydrauliques[pays].PumpingRatio; - // Pi[nombreDeTermes] *= -1; - // Colonne[nombreDeTermes] = var; - // nombreDeTermes++; - // } - - // var = CorrespondanceVarNativesVarOptim.NumeroDeVariablesDeDebordement[pays]; - // if (var >= 0) - // { - // Pi[nombreDeTermes] = 1.; - // Colonne[nombreDeTermes] = var; - // nombreDeTermes++; - // } - - // CorrespondanceCntNativesCntOptim.NumeroDeContrainteDesNiveauxPays[pays] - // = ProblemeAResoudre->NombreDeContraintes; - - // constraintNamer.AreaHydroLevel(ProblemeAResoudre->NombreDeContraintes); - // OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - // ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '='); - // } - // else - // CorrespondanceCntNativesCntOptim.NumeroDeContrainteDesNiveauxPays[pays] = -1; } } /* For each area with ad hoc properties, two possible sets of two additional constraints */ for (uint32_t pays = 0; pays < problemeHebdo->NombreDePays; pays++) { - // const auto& week = problemeHebdo->weekInTheYear; - // constraintNamer.UpdateArea(problemeHebdo->NomsDesPays[pays]); - // constraintNamer.UpdateTimeStep(week * 168 + nombreDePasDeTempsPourUneOptimisation - 1); finalStockEquivalent.add(pays); - // if (problemeHebdo->CaracteristiquesHydrauliques[pays].AccurateWaterValue - // && problemeHebdo->CaracteristiquesHydrauliques[pays].DirectLevelAccess) - // /* equivalence constraint : StockFinal- Niveau[T]= 0*/ - // { - // int nombreDeTermes = 0; - // var = problemeHebdo->NumeroDeVariableStockFinal[pays]; - // if (var >= 0) - // { - // Pi[nombreDeTermes] = 1.0; - // Colonne[nombreDeTermes] = var; - // nombreDeTermes++; - // } - // var = problemeHebdo - // ->CorrespondanceVarNativesVarOptim[nombreDePasDeTempsPourUneOptimisation - 1] - // .NumeroDeVariablesDeNiveau[pays]; - // if (var >= 0) - // { - // Pi[nombreDeTermes] = -1.0; - // Colonne[nombreDeTermes] = var; - // nombreDeTermes++; - // } - // problemeHebdo->NumeroDeContrainteEquivalenceStockFinal[pays] - // = ProblemeAResoudre->NombreDeContraintes; - // constraintNamer.FinalStockEquivalent(ProblemeAResoudre->NombreDeContraintes); - // OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - // ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '='); - // } finalStockExpression.add(pays); - // if (problemeHebdo->CaracteristiquesHydrauliques[pays].AccurateWaterValue) - // /* expression constraint : - StockFinal +sum (stocklayers) = 0*/ - // { - // int nombreDeTermes = 0; - // var = problemeHebdo->NumeroDeVariableStockFinal[pays]; - // if (var >= 0) - // { - // Pi[nombreDeTermes] = -1.0; - // Colonne[nombreDeTermes] = var; - // nombreDeTermes++; - // } - // for (int layerindex = 0; layerindex < 100; layerindex++) - // { - // var = problemeHebdo->NumeroDeVariableDeTrancheDeStock[pays][layerindex]; - - // if (var >= 0) - // { - // Pi[nombreDeTermes] = 1.0; - // Colonne[nombreDeTermes] = var; - // nombreDeTermes++; - // } - // } - - // problemeHebdo->NumeroDeContrainteExpressionStockFinal[pays] - // = ProblemeAResoudre->NombreDeContraintes; - - // constraintNamer.FinalStockExpression(ProblemeAResoudre->NombreDeContraintes); - // OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - // ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '='); - // } } if (problemeHebdo->OptimisationAvecCoutsDeDemarrage) From 507e35539dcdcaf90525d16eec14fe6b84498738 Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Tue, 5 Sep 2023 12:13:19 +0200 Subject: [PATCH 19/43] add {PMin,PMax}DispatchableGeneration --- src/solver/optimisation/CMakeLists.txt | 74 ++++--- .../PMaxDispatchableGeneration.cpp | 41 ++++ .../optimisation/PMaxDispatchableGeneration.h | 10 + .../PMinDispatchableGeneration.cpp | 41 ++++ .../optimisation/PMinDispatchableGeneration.h | 10 + src/solver/optimisation/constraint_builder.h | 5 + ...nstruction_contraintes_couts_demarrage.cpp | 203 ++++++++++-------- 7 files changed, 254 insertions(+), 130 deletions(-) create mode 100644 src/solver/optimisation/PMaxDispatchableGeneration.cpp create mode 100644 src/solver/optimisation/PMaxDispatchableGeneration.h create mode 100644 src/solver/optimisation/PMinDispatchableGeneration.cpp create mode 100644 src/solver/optimisation/PMinDispatchableGeneration.h diff --git a/src/solver/optimisation/CMakeLists.txt b/src/solver/optimisation/CMakeLists.txt index b4e5f5a42e..4dffd3b459 100644 --- a/src/solver/optimisation/CMakeLists.txt +++ b/src/solver/optimisation/CMakeLists.txt @@ -71,44 +71,48 @@ set(RTESOLVER_OPT opt_rename_problem.h opt_rename_problem.cpp - constraint_builder.cpp - constraint_builder.h + constraint_builder.cpp + constraint_builder.h AreaBalance.h - AreaBalance.cpp - FictitiousLoad.h - FictitiousLoad.cpp - ShortTermStorageLevel.h - ShortTermStorageLevel.cpp - FlowDissociation.h - FlowDissociation.cpp - BindingConstraintHour.h - BindingConstraintHour.cpp - BindingConstraintDay.h - BindingConstraintDay.cpp - BindingConstraintWeek.h - BindingConstraintWeek.cpp - HydroPower.h - HydroPower.cpp - HydroPowerSmoothingUsingVariationSum.h - HydroPowerSmoothingUsingVariationSum.cpp - HydroPowerSmoothingUsingVariationMaxDown.h - HydroPowerSmoothingUsingVariationMaxDown.cpp - HydroPowerSmoothingUsingVariationMaxUp.h - HydroPowerSmoothingUsingVariationMaxUp.cpp - MinHydroPower.h - MinHydroPower.cpp - MaxHydroPower.h - MaxHydroPower.cpp - MaxPumping.h - MaxPumping.cpp - AreaHydroLevel.h - AreaHydroLevel.cpp - FinalStockEquivalent.h - FinalStockEquivalent.cpp - FinalStockExpression.h - FinalStockExpression.cpp + AreaBalance.cpp + FictitiousLoad.h + FictitiousLoad.cpp + ShortTermStorageLevel.h + ShortTermStorageLevel.cpp + FlowDissociation.h + FlowDissociation.cpp + BindingConstraintHour.h + BindingConstraintHour.cpp + BindingConstraintDay.h + BindingConstraintDay.cpp + BindingConstraintWeek.h + BindingConstraintWeek.cpp + HydroPower.h + HydroPower.cpp + HydroPowerSmoothingUsingVariationSum.h + HydroPowerSmoothingUsingVariationSum.cpp + HydroPowerSmoothingUsingVariationMaxDown.h + HydroPowerSmoothingUsingVariationMaxDown.cpp + HydroPowerSmoothingUsingVariationMaxUp.h + HydroPowerSmoothingUsingVariationMaxUp.cpp + MinHydroPower.h + MinHydroPower.cpp + MaxHydroPower.h + MaxHydroPower.cpp + MaxPumping.h + MaxPumping.cpp + AreaHydroLevel.h + AreaHydroLevel.cpp + FinalStockEquivalent.h + FinalStockEquivalent.cpp + FinalStockExpression.h + FinalStockExpression.cpp + PMaxDispatchableGeneration.h + PMaxDispatchableGeneration.cpp + PMinDispatchableGeneration.h + PMinDispatchableGeneration.cpp ) diff --git a/src/solver/optimisation/PMaxDispatchableGeneration.cpp b/src/solver/optimisation/PMaxDispatchableGeneration.cpp new file mode 100644 index 0000000000..854d3a100a --- /dev/null +++ b/src/solver/optimisation/PMaxDispatchableGeneration.cpp @@ -0,0 +1,41 @@ +#include "PMaxDispatchableGeneration.h" + +void PMaxDispatchableGeneration::add(int pays, + int cluster, + int clusterIndex, + int pdt, + bool Simulation) +{ + if (!Simulation) + { + const PALIERS_THERMIQUES& PaliersThermiquesDuPays + = problemeHebdo->PaliersThermiquesDuPays[pays]; + double pmaxDUnGroupeDuPalierThermique + = PaliersThermiquesDuPays.PmaxDUnGroupeDuPalierThermique[clusterIndex]; + const int DureeMinimaleDArretDUnGroupeDuPalierThermique + = PaliersThermiquesDuPays.DureeMinimaleDArretDUnGroupeDuPalierThermique[clusterIndex]; + + builder.updateHourWithinWeek(pdt) + .include(Variable::DispatchableProduction(cluster), 1.0) + .include(Variable::NODU(cluster), -pmaxDUnGroupeDuPalierThermique) + .lessThan(); + if (builder.NumberOfVariables() > 0) + { + ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, + problemeHebdo->NamedProblems); + + namer.UpdateTimeStep(problemeHebdo->weekInTheYear * 168 + pdt); + namer.UpdateArea(problemeHebdo->NomsDesPays[pays]); + + namer.PMaxDispatchableGeneration( + problemeHebdo->ProblemeAResoudre->NombreDeContraintes, + PaliersThermiquesDuPays.NomsDesPaliersThermiques[clusterIndex]); + } + builder.build(); + } + else + { + nbTermesContraintesPourLesCoutsDeDemarrage += 2; + problemeHebdo->ProblemeAResoudre->NombreDeContraintes++; + } +} \ No newline at end of file diff --git a/src/solver/optimisation/PMaxDispatchableGeneration.h b/src/solver/optimisation/PMaxDispatchableGeneration.h new file mode 100644 index 0000000000..7f80bce466 --- /dev/null +++ b/src/solver/optimisation/PMaxDispatchableGeneration.h @@ -0,0 +1,10 @@ +#pragma once +#include "constraint_builder.h" + +class PMaxDispatchableGeneration : public Constraint +{ +public: + using Constraint::Constraint; + void add(int pays, int cluster, int clusterIndex, int pdt, bool Simulation); + int nbTermesContraintesPourLesCoutsDeDemarrage = 0; +}; \ No newline at end of file diff --git a/src/solver/optimisation/PMinDispatchableGeneration.cpp b/src/solver/optimisation/PMinDispatchableGeneration.cpp new file mode 100644 index 0000000000..00d5f2adcf --- /dev/null +++ b/src/solver/optimisation/PMinDispatchableGeneration.cpp @@ -0,0 +1,41 @@ +#include "PMinDispatchableGeneration.h" + +void PMinDispatchableGeneration::add(int pays, + int cluster, + int clusterIndex, + int pdt, + bool Simulation) +{ + if (!Simulation) + { + const PALIERS_THERMIQUES& PaliersThermiquesDuPays + = problemeHebdo->PaliersThermiquesDuPays[pays]; + double pminDUnGroupeDuPalierThermique + = PaliersThermiquesDuPays.pminDUnGroupeDuPalierThermique[clusterIndex]; + + int NombreDePasDeTempsPourUneOptimisation + = problemeHebdo->NombreDePasDeTempsPourUneOptimisation; + builder.updateHourWithinWeek(pdt) + .include(Variable::DispatchableProduction(cluster), 1.0) + .include(Variable::NODU(cluster), -pminDUnGroupeDuPalierThermique) + .greaterThan(); + /*consider Adding rename constraint inside the builder*/ + if (builder.NumberOfVariables() > 0) + { + ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, + problemeHebdo->NamedProblems); + namer.UpdateArea(problemeHebdo->NomsDesPays[pays]); + + namer.UpdateTimeStep(problemeHebdo->weekInTheYear * 168 + pdt); + namer.PMinDispatchableGeneration( + problemeHebdo->ProblemeAResoudre->NombreDeContraintes, + PaliersThermiquesDuPays.NomsDesPaliersThermiques[clusterIndex]); + } + builder.build(); + } + else + { + nbTermesContraintesPourLesCoutsDeDemarrage += 2; + problemeHebdo->ProblemeAResoudre->NombreDeContraintes++; + } +} diff --git a/src/solver/optimisation/PMinDispatchableGeneration.h b/src/solver/optimisation/PMinDispatchableGeneration.h new file mode 100644 index 0000000000..a26fd7a1e2 --- /dev/null +++ b/src/solver/optimisation/PMinDispatchableGeneration.h @@ -0,0 +1,10 @@ +#pragma once +#include "constraint_builder.h" + +class PMinDispatchableGeneration : public Constraint +{ +public: + using Constraint::Constraint; + void add(int pays, int cluster, int clusterIndex, int pdt, bool Simulation); + int nbTermesContraintesPourLesCoutsDeDemarrage = 0; +}; \ No newline at end of file diff --git a/src/solver/optimisation/constraint_builder.h b/src/solver/optimisation/constraint_builder.h index d537843001..53642826c2 100644 --- a/src/solver/optimisation/constraint_builder.h +++ b/src/solver/optimisation/constraint_builder.h @@ -356,6 +356,10 @@ class ConstraintBuilder // } void build(); + int NumberOfVariables() const + { + return nombreDeTermes_; + } private: PROBLEME_HEBDO& problemeHebdo; @@ -367,6 +371,7 @@ class ConstraintBuilder char operator_; double rhs_ = 0; int nombreDeTermes_ = 0; + // ConstraintNamer ConstraintNameManager; }; class Constraint diff --git a/src/solver/optimisation/opt_construction_contraintes_couts_demarrage.cpp b/src/solver/optimisation/opt_construction_contraintes_couts_demarrage.cpp index 69f2f97f5d..cb773f918b 100644 --- a/src/solver/optimisation/opt_construction_contraintes_couts_demarrage.cpp +++ b/src/solver/optimisation/opt_construction_contraintes_couts_demarrage.cpp @@ -32,7 +32,8 @@ #include "opt_fonctions.h" #include "opt_rename_problem.h" - +#include "PMaxDispatchableGeneration.h" +#include "PMinDispatchableGeneration.h" using namespace Antares::Data; void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( @@ -56,6 +57,8 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( constraintNamer.UpdateArea(problemeHebdo->NomsDesPays[pays]); for (int index = 0; index < PaliersThermiquesDuPays.NombreDePaliersThermiques; index++) { + PMaxDispatchableGeneration pMaxDispatchableGeneration(problemeHebdo); + PMinDispatchableGeneration pMinDispatchableGeneration(problemeHebdo); double pminDUnGroupeDuPalierThermique = PaliersThermiquesDuPays.pminDUnGroupeDuPalierThermique[index]; double pmaxDUnGroupeDuPalierThermique @@ -65,100 +68,110 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) { - auto timeStepInYear = problemeHebdo->weekInTheYear * 168 + pdt; - constraintNamer.UpdateTimeStep(timeStepInYear); - CORRESPONDANCES_DES_VARIABLES& CorrespondanceVarNativesVarOptim - = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt]; - - int nombreDeTermes = 0; - - if (!Simulation) - { - int var - = CorrespondanceVarNativesVarOptim.NumeroDeVariableDuPalierThermique[palier]; - if (var >= 0) - { - Pi[nombreDeTermes] = 1.0; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } - } - else - nbTermesContraintesPourLesCoutsDeDemarrage++; - - if (!Simulation) - { - int var - = CorrespondanceVarNativesVarOptim - .NumeroDeVariableDuNombreDeGroupesEnMarcheDuPalierThermique[palier]; - if (var >= 0) - { - Pi[nombreDeTermes] = -pmaxDUnGroupeDuPalierThermique; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } - } - else - nbTermesContraintesPourLesCoutsDeDemarrage++; - - if (!Simulation) - { - if (nombreDeTermes > 0) - { - constraintNamer.PMaxDispatchableGeneration( - ProblemeAResoudre->NombreDeContraintes, - PaliersThermiquesDuPays.NomsDesPaliersThermiques[index]); - OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '<'); - } - } - else - ProblemeAResoudre->NombreDeContraintes += 1; - - nombreDeTermes = 0; - - if (!Simulation) - { - int var - = CorrespondanceVarNativesVarOptim.NumeroDeVariableDuPalierThermique[palier]; - if (var >= 0) - { - Pi[nombreDeTermes] = 1.0; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } - } - else - nbTermesContraintesPourLesCoutsDeDemarrage++; - - if (!Simulation) - { - int var - = CorrespondanceVarNativesVarOptim - .NumeroDeVariableDuNombreDeGroupesEnMarcheDuPalierThermique[palier]; - if (var >= 0) - { - Pi[nombreDeTermes] = -pminDUnGroupeDuPalierThermique; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } - } - else - nbTermesContraintesPourLesCoutsDeDemarrage++; - - if (!Simulation) - { - if (nombreDeTermes > 0) - { - constraintNamer.PMinDispatchableGeneration( - ProblemeAResoudre->NombreDeContraintes, - PaliersThermiquesDuPays.NomsDesPaliersThermiques[index]); - OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '>'); - } - } - else - ProblemeAResoudre->NombreDeContraintes += 1; + pMaxDispatchableGeneration.add(pays, palier, index, pdt, Simulation); + nbTermesContraintesPourLesCoutsDeDemarrage + += pMaxDispatchableGeneration.nbTermesContraintesPourLesCoutsDeDemarrage; + + pMinDispatchableGeneration.add(pays, palier, index, pdt, Simulation); + nbTermesContraintesPourLesCoutsDeDemarrage + += pMinDispatchableGeneration.nbTermesContraintesPourLesCoutsDeDemarrage; + + // auto timeStepInYear = problemeHebdo->weekInTheYear * 168 + pdt; + // constraintNamer.UpdateTimeStep(timeStepInYear); + // CORRESPONDANCES_DES_VARIABLES& CorrespondanceVarNativesVarOptim + // = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt]; + + // int nombreDeTermes = 0; + + // if (!Simulation) + // { + // int var + // = + // CorrespondanceVarNativesVarOptim.NumeroDeVariableDuPalierThermique[palier]; + // if (var >= 0) + // { + // Pi[nombreDeTermes] = 1.0; + // Colonne[nombreDeTermes] = var; + // nombreDeTermes++; + // } + // } + // else + // nbTermesContraintesPourLesCoutsDeDemarrage++; + + // if (!Simulation) + // { + // int var + // = CorrespondanceVarNativesVarOptim + // .NumeroDeVariableDuNombreDeGroupesEnMarcheDuPalierThermique[palier]; + // if (var >= 0) + // { + // Pi[nombreDeTermes] = -pmaxDUnGroupeDuPalierThermique; + // Colonne[nombreDeTermes] = var; + // nombreDeTermes++; + // } + // } + // else + // nbTermesContraintesPourLesCoutsDeDemarrage++; + + // if (!Simulation) + // { + // if (nombreDeTermes > 0) + // { + // constraintNamer.PMaxDispatchableGeneration( + // ProblemeAResoudre->NombreDeContraintes, + // PaliersThermiquesDuPays.NomsDesPaliersThermiques[index]); + // OPT_ChargerLaContrainteDansLaMatriceDesContraintes( + // ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '<'); + // } + // } + // else + // ProblemeAResoudre->NombreDeContraintes += 1; + + // nombreDeTermes = 0; + + // if (!Simulation) + // { + // int var + // = + // CorrespondanceVarNativesVarOptim.NumeroDeVariableDuPalierThermique[palier]; + // if (var >= 0) + // { + // Pi[nombreDeTermes] = 1.0; + // Colonne[nombreDeTermes] = var; + // nombreDeTermes++; + // } + // } + // else + // nbTermesContraintesPourLesCoutsDeDemarrage++; + + // if (!Simulation) + // { + // int var + // = CorrespondanceVarNativesVarOptim + // .NumeroDeVariableDuNombreDeGroupesEnMarcheDuPalierThermique[palier]; + // if (var >= 0) + // { + // Pi[nombreDeTermes] = -pminDUnGroupeDuPalierThermique; + // Colonne[nombreDeTermes] = var; + // nombreDeTermes++; + // } + // } + // else + // nbTermesContraintesPourLesCoutsDeDemarrage++; + + // if (!Simulation) + // { + // if (nombreDeTermes > 0) + // { + // constraintNamer.PMinDispatchableGeneration( + // ProblemeAResoudre->NombreDeContraintes, + // PaliersThermiquesDuPays.NomsDesPaliersThermiques[index]); + // OPT_ChargerLaContrainteDansLaMatriceDesContraintes( + // ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '>'); + // } + // } + // else + // ProblemeAResoudre->NombreDeContraintes += 1; } } } From 854ca389be66d98efdd48fdb4c9aeb33253e8768 Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Tue, 5 Sep 2023 12:21:03 +0200 Subject: [PATCH 20/43] clean code --- ...nstruction_contraintes_couts_demarrage.cpp | 97 ------------------- 1 file changed, 97 deletions(-) diff --git a/src/solver/optimisation/opt_construction_contraintes_couts_demarrage.cpp b/src/solver/optimisation/opt_construction_contraintes_couts_demarrage.cpp index cb773f918b..ce1cc1897e 100644 --- a/src/solver/optimisation/opt_construction_contraintes_couts_demarrage.cpp +++ b/src/solver/optimisation/opt_construction_contraintes_couts_demarrage.cpp @@ -75,103 +75,6 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( pMinDispatchableGeneration.add(pays, palier, index, pdt, Simulation); nbTermesContraintesPourLesCoutsDeDemarrage += pMinDispatchableGeneration.nbTermesContraintesPourLesCoutsDeDemarrage; - - // auto timeStepInYear = problemeHebdo->weekInTheYear * 168 + pdt; - // constraintNamer.UpdateTimeStep(timeStepInYear); - // CORRESPONDANCES_DES_VARIABLES& CorrespondanceVarNativesVarOptim - // = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt]; - - // int nombreDeTermes = 0; - - // if (!Simulation) - // { - // int var - // = - // CorrespondanceVarNativesVarOptim.NumeroDeVariableDuPalierThermique[palier]; - // if (var >= 0) - // { - // Pi[nombreDeTermes] = 1.0; - // Colonne[nombreDeTermes] = var; - // nombreDeTermes++; - // } - // } - // else - // nbTermesContraintesPourLesCoutsDeDemarrage++; - - // if (!Simulation) - // { - // int var - // = CorrespondanceVarNativesVarOptim - // .NumeroDeVariableDuNombreDeGroupesEnMarcheDuPalierThermique[palier]; - // if (var >= 0) - // { - // Pi[nombreDeTermes] = -pmaxDUnGroupeDuPalierThermique; - // Colonne[nombreDeTermes] = var; - // nombreDeTermes++; - // } - // } - // else - // nbTermesContraintesPourLesCoutsDeDemarrage++; - - // if (!Simulation) - // { - // if (nombreDeTermes > 0) - // { - // constraintNamer.PMaxDispatchableGeneration( - // ProblemeAResoudre->NombreDeContraintes, - // PaliersThermiquesDuPays.NomsDesPaliersThermiques[index]); - // OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - // ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '<'); - // } - // } - // else - // ProblemeAResoudre->NombreDeContraintes += 1; - - // nombreDeTermes = 0; - - // if (!Simulation) - // { - // int var - // = - // CorrespondanceVarNativesVarOptim.NumeroDeVariableDuPalierThermique[palier]; - // if (var >= 0) - // { - // Pi[nombreDeTermes] = 1.0; - // Colonne[nombreDeTermes] = var; - // nombreDeTermes++; - // } - // } - // else - // nbTermesContraintesPourLesCoutsDeDemarrage++; - - // if (!Simulation) - // { - // int var - // = CorrespondanceVarNativesVarOptim - // .NumeroDeVariableDuNombreDeGroupesEnMarcheDuPalierThermique[palier]; - // if (var >= 0) - // { - // Pi[nombreDeTermes] = -pminDUnGroupeDuPalierThermique; - // Colonne[nombreDeTermes] = var; - // nombreDeTermes++; - // } - // } - // else - // nbTermesContraintesPourLesCoutsDeDemarrage++; - - // if (!Simulation) - // { - // if (nombreDeTermes > 0) - // { - // constraintNamer.PMinDispatchableGeneration( - // ProblemeAResoudre->NombreDeContraintes, - // PaliersThermiquesDuPays.NomsDesPaliersThermiques[index]); - // OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - // ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '>'); - // } - // } - // else - // ProblemeAResoudre->NombreDeContraintes += 1; } } } From 3029f79dc5e2c56e9c42bd7463f7889f445f55ca Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Tue, 5 Sep 2023 14:32:28 +0200 Subject: [PATCH 21/43] ConsistenceNODU ok --- src/solver/optimisation/CMakeLists.txt | 2 + src/solver/optimisation/ConsistenceNODU.cpp | 59 ++++++ src/solver/optimisation/ConsistenceNODU.h | 10 + ...nstruction_contraintes_couts_demarrage.cpp | 175 +++++++++--------- 4 files changed, 161 insertions(+), 85 deletions(-) create mode 100644 src/solver/optimisation/ConsistenceNODU.cpp create mode 100644 src/solver/optimisation/ConsistenceNODU.h diff --git a/src/solver/optimisation/CMakeLists.txt b/src/solver/optimisation/CMakeLists.txt index 4dffd3b459..9525a498d7 100644 --- a/src/solver/optimisation/CMakeLists.txt +++ b/src/solver/optimisation/CMakeLists.txt @@ -113,6 +113,8 @@ set(RTESOLVER_OPT PMaxDispatchableGeneration.cpp PMinDispatchableGeneration.h PMinDispatchableGeneration.cpp + ConsistenceNODU.h + ConsistenceNODU.cpp ) diff --git a/src/solver/optimisation/ConsistenceNODU.cpp b/src/solver/optimisation/ConsistenceNODU.cpp new file mode 100644 index 0000000000..704c3f9d69 --- /dev/null +++ b/src/solver/optimisation/ConsistenceNODU.cpp @@ -0,0 +1,59 @@ +#include "ConsistenceNODU.h" + +void ConsistenceNODU::add(int pays, int cluster, int clusterIndex, int pdt, bool Simulation) +{ + if (!Simulation) + { + const PALIERS_THERMIQUES& PaliersThermiquesDuPays + = problemeHebdo->PaliersThermiquesDuPays[pays]; + double pminDUnGroupeDuPalierThermique + = PaliersThermiquesDuPays.pminDUnGroupeDuPalierThermique[clusterIndex]; + const int DureeMinimaleDArretDUnGroupeDuPalierThermique + = PaliersThermiquesDuPays.DureeMinimaleDArretDUnGroupeDuPalierThermique[clusterIndex]; + + int NombreDePasDeTempsPourUneOptimisation + = problemeHebdo->NombreDePasDeTempsPourUneOptimisation; + + int t1 = pdt - DureeMinimaleDArretDUnGroupeDuPalierThermique; + int Pdtmoins1 = pdt - 1; + if (Pdtmoins1 < 0) + Pdtmoins1 = NombreDePasDeTempsPourUneOptimisation + Pdtmoins1; + + CORRESPONDANCES_DES_VARIABLES& CorrespondanceVarNativesVarOptimTmoins1 + = problemeHebdo->CorrespondanceVarNativesVarOptim[Pdtmoins1]; + + if (t1 < 0) + t1 = NombreDePasDeTempsPourUneOptimisation + t1; + + const std::vector& NombreMaxDeGroupesEnMarcheDuPalierThermique + = PaliersThermiquesDuPays.PuissanceDisponibleEtCout[clusterIndex] + .NombreMaxDeGroupesEnMarcheDuPalierThermique; + double rhs = 0; // /!\ TODO check + + builder.updateHourWithinWeek(pdt) + .include(Variable::NODU(cluster), 1.0) + .updateHourWithinWeek(Pdtmoins1) + .include(Variable::NODU(cluster), -1) + .updateHourWithinWeek(pdt) + .include(Variable::NumberStartingDispatchableUnits(cluster), -1) + .include(Variable::NumberStoppingDispatchableUnits(cluster), 1) + .equalTo(); + if (builder.NumberOfVariables() > 0) + { + ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, + problemeHebdo->NamedProblems); + namer.UpdateArea(problemeHebdo->NomsDesPays[pays]); + + namer.UpdateTimeStep(problemeHebdo->weekInTheYear * 168 + pdt); + namer.ConsistenceNODU(problemeHebdo->ProblemeAResoudre->NombreDeContraintes, + PaliersThermiquesDuPays.NomsDesPaliersThermiques[clusterIndex]); + + builder.build(); + } + } + else + { + nbTermesContraintesPourLesCoutsDeDemarrage += 4; + problemeHebdo->ProblemeAResoudre->NombreDeContraintes++; + } +} diff --git a/src/solver/optimisation/ConsistenceNODU.h b/src/solver/optimisation/ConsistenceNODU.h new file mode 100644 index 0000000000..2094166efc --- /dev/null +++ b/src/solver/optimisation/ConsistenceNODU.h @@ -0,0 +1,10 @@ +#pragma once +#include "constraint_builder.h" + +class ConsistenceNODU : public Constraint +{ +public: + using Constraint::Constraint; + void add(int pays, int cluster, int clusterIndex, int pdt, bool Simulation); + int nbTermesContraintesPourLesCoutsDeDemarrage = 0; +}; \ No newline at end of file diff --git a/src/solver/optimisation/opt_construction_contraintes_couts_demarrage.cpp b/src/solver/optimisation/opt_construction_contraintes_couts_demarrage.cpp index ce1cc1897e..b68d33d3f4 100644 --- a/src/solver/optimisation/opt_construction_contraintes_couts_demarrage.cpp +++ b/src/solver/optimisation/opt_construction_contraintes_couts_demarrage.cpp @@ -34,6 +34,7 @@ #include "opt_rename_problem.h" #include "PMaxDispatchableGeneration.h" #include "PMinDispatchableGeneration.h" +#include "ConsistenceNODU.h" using namespace Antares::Data; void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( @@ -91,91 +92,95 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) { - auto timeStepInYear = problemeHebdo->weekInTheYear * 168 + pdt; - constraintNamer.UpdateTimeStep(timeStepInYear); - CORRESPONDANCES_DES_VARIABLES& CorrespondanceVarNativesVarOptim - = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt]; - - int Pdtmoins1 = pdt - 1; - if (Pdtmoins1 < 0) - Pdtmoins1 = nombreDePasDeTempsPourUneOptimisation + Pdtmoins1; - CORRESPONDANCES_DES_VARIABLES& CorrespondanceVarNativesVarOptimTmoins1 - = problemeHebdo->CorrespondanceVarNativesVarOptim[Pdtmoins1]; - - int nombreDeTermes = 0; - if (!Simulation) - { - int var - = CorrespondanceVarNativesVarOptim - .NumeroDeVariableDuNombreDeGroupesEnMarcheDuPalierThermique[palier]; - if (var >= 0) - { - Pi[nombreDeTermes] = 1.0; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } - } - else - nbTermesContraintesPourLesCoutsDeDemarrage++; - - if (!Simulation) - { - int var - = CorrespondanceVarNativesVarOptimTmoins1 - .NumeroDeVariableDuNombreDeGroupesEnMarcheDuPalierThermique[palier]; - if (var >= 0) - { - Pi[nombreDeTermes] = -1; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } - } - else - nbTermesContraintesPourLesCoutsDeDemarrage++; - - if (!Simulation) - { - int var - = CorrespondanceVarNativesVarOptim - .NumeroDeVariableDuNombreDeGroupesQuiDemarrentDuPalierThermique[palier]; - if (var >= 0) - { - Pi[nombreDeTermes] = -1; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } - } - else - nbTermesContraintesPourLesCoutsDeDemarrage++; - - if (!Simulation) - { - int var - = CorrespondanceVarNativesVarOptim - .NumeroDeVariableDuNombreDeGroupesQuiSArretentDuPalierThermique[palier]; - if (var >= 0) - { - Pi[nombreDeTermes] = 1; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } - } - else - nbTermesContraintesPourLesCoutsDeDemarrage++; - - if (!Simulation) - { - if (nombreDeTermes > 0) - { - constraintNamer.ConsistenceNODU( - ProblemeAResoudre->NombreDeContraintes, - PaliersThermiquesDuPays.NomsDesPaliersThermiques[index]); - OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '='); - } - } - else - ProblemeAResoudre->NombreDeContraintes += 1; + ConsistenceNODU consistenceNODU(problemeHebdo); + consistenceNODU.add(pays, palier, index, pdt, Simulation); + nbTermesContraintesPourLesCoutsDeDemarrage + += consistenceNODU.nbTermesContraintesPourLesCoutsDeDemarrage; + // auto timeStepInYear = problemeHebdo->weekInTheYear * 168 + pdt; + // constraintNamer.UpdateTimeStep(timeStepInYear); + // CORRESPONDANCES_DES_VARIABLES& CorrespondanceVarNativesVarOptim + // = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt]; + + // int Pdtmoins1 = pdt - 1; + // if (Pdtmoins1 < 0) + // Pdtmoins1 = nombreDePasDeTempsPourUneOptimisation + Pdtmoins1; + // CORRESPONDANCES_DES_VARIABLES& CorrespondanceVarNativesVarOptimTmoins1 + // = problemeHebdo->CorrespondanceVarNativesVarOptim[Pdtmoins1]; + + // int nombreDeTermes = 0; + // if (!Simulation) + // { + // int var + // = CorrespondanceVarNativesVarOptim + // .NumeroDeVariableDuNombreDeGroupesEnMarcheDuPalierThermique[palier]; + // if (var >= 0) + // { + // Pi[nombreDeTermes] = 1.0; + // Colonne[nombreDeTermes] = var; + // nombreDeTermes++; + // } + // } + // else + // nbTermesContraintesPourLesCoutsDeDemarrage++; + + // if (!Simulation) + // { + // int var + // = CorrespondanceVarNativesVarOptimTmoins1 + // .NumeroDeVariableDuNombreDeGroupesEnMarcheDuPalierThermique[palier]; + // if (var >= 0) + // { + // Pi[nombreDeTermes] = -1; + // Colonne[nombreDeTermes] = var; + // nombreDeTermes++; + // } + // } + // else + // nbTermesContraintesPourLesCoutsDeDemarrage++; + + // if (!Simulation) + // { + // int var + // = CorrespondanceVarNativesVarOptim + // .NumeroDeVariableDuNombreDeGroupesQuiDemarrentDuPalierThermique[palier]; + // if (var >= 0) + // { + // Pi[nombreDeTermes] = -1; + // Colonne[nombreDeTermes] = var; + // nombreDeTermes++; + // } + // } + // else + // nbTermesContraintesPourLesCoutsDeDemarrage++; + + // if (!Simulation) + // { + // int var + // = CorrespondanceVarNativesVarOptim + // .NumeroDeVariableDuNombreDeGroupesQuiSArretentDuPalierThermique[palier]; + // if (var >= 0) + // { + // Pi[nombreDeTermes] = 1; + // Colonne[nombreDeTermes] = var; + // nombreDeTermes++; + // } + // } + // else + // nbTermesContraintesPourLesCoutsDeDemarrage++; + + // if (!Simulation) + // { + // if (nombreDeTermes > 0) + // { + // constraintNamer.ConsistenceNODU( + // ProblemeAResoudre->NombreDeContraintes, + // PaliersThermiquesDuPays.NomsDesPaliersThermiques[index]); + // OPT_ChargerLaContrainteDansLaMatriceDesContraintes( + // ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '='); + // } + // } + // else + // ProblemeAResoudre->NombreDeContraintes += 1; } } } From 78dab469f6b65b9b938385aeccb869fee12caf40 Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Tue, 5 Sep 2023 15:05:10 +0200 Subject: [PATCH 22/43] NbUnitsOutageLessThanNbUnitsStop --- src/solver/optimisation/CMakeLists.txt | 2 + .../NbUnitsOutageLessThanNbUnitsStop.cpp | 58 +++++++ .../NbUnitsOutageLessThanNbUnitsStop.h | 10 ++ ...nstruction_contraintes_couts_demarrage.cpp | 144 +----------------- 4 files changed, 76 insertions(+), 138 deletions(-) create mode 100644 src/solver/optimisation/NbUnitsOutageLessThanNbUnitsStop.cpp create mode 100644 src/solver/optimisation/NbUnitsOutageLessThanNbUnitsStop.h diff --git a/src/solver/optimisation/CMakeLists.txt b/src/solver/optimisation/CMakeLists.txt index 9525a498d7..6cb2f22aa3 100644 --- a/src/solver/optimisation/CMakeLists.txt +++ b/src/solver/optimisation/CMakeLists.txt @@ -115,6 +115,8 @@ set(RTESOLVER_OPT PMinDispatchableGeneration.cpp ConsistenceNODU.h ConsistenceNODU.cpp + NbUnitsOutageLessThanNbUnitsStop.h + NbUnitsOutageLessThanNbUnitsStop.cpp ) diff --git a/src/solver/optimisation/NbUnitsOutageLessThanNbUnitsStop.cpp b/src/solver/optimisation/NbUnitsOutageLessThanNbUnitsStop.cpp new file mode 100644 index 0000000000..8efb687f22 --- /dev/null +++ b/src/solver/optimisation/NbUnitsOutageLessThanNbUnitsStop.cpp @@ -0,0 +1,58 @@ +#include "NbUnitsOutageLessThanNbUnitsStop.h" + +void NbUnitsOutageLessThanNbUnitsStop::add(int pays, + int cluster, + int clusterIndex, + int pdt, + bool Simulation) +{ + if (!Simulation) + { + const PALIERS_THERMIQUES& PaliersThermiquesDuPays + = problemeHebdo->PaliersThermiquesDuPays[pays]; + double pminDUnGroupeDuPalierThermique + = PaliersThermiquesDuPays.pminDUnGroupeDuPalierThermique[clusterIndex]; + const int DureeMinimaleDArretDUnGroupeDuPalierThermique + = PaliersThermiquesDuPays.DureeMinimaleDArretDUnGroupeDuPalierThermique[clusterIndex]; + + CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim + = problemeHebdo->CorrespondanceCntNativesCntOptim[pdt]; + CorrespondanceCntNativesCntOptim.NumeroDeContrainteDesContraintesDeDureeMinDeMarche[cluster] + = -1; + + int NombreDePasDeTempsPourUneOptimisation + = problemeHebdo->NombreDePasDeTempsPourUneOptimisation; + + int t1 = pdt - DureeMinimaleDArretDUnGroupeDuPalierThermique; + + if (t1 < 0) + t1 = NombreDePasDeTempsPourUneOptimisation + t1; + + const std::vector& NombreMaxDeGroupesEnMarcheDuPalierThermique + = PaliersThermiquesDuPays.PuissanceDisponibleEtCout[clusterIndex] + .NombreMaxDeGroupesEnMarcheDuPalierThermique; + + builder.updateHourWithinWeek(pdt) + .include(Variable::NumberBreakingDownDispatchableUnits(cluster), 1.0) + .include(Variable::NumberStoppingDispatchableUnits(cluster), -1.0) + .lessThan(); + + if (builder.NumberOfVariables() > 0) + { + ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, + problemeHebdo->NamedProblems); + namer.UpdateArea(problemeHebdo->NomsDesPays[pays]); + namer.UpdateTimeStep(problemeHebdo->weekInTheYear * 168 + pdt); + namer.NbUnitsOutageLessThanNbUnitsStop( + problemeHebdo->ProblemeAResoudre->NombreDeContraintes, + PaliersThermiquesDuPays.NomsDesPaliersThermiques[clusterIndex]); + + builder.build(); + } + } + else + { + nbTermesContraintesPourLesCoutsDeDemarrage += 4; + problemeHebdo->ProblemeAResoudre->NombreDeContraintes++; + } +} diff --git a/src/solver/optimisation/NbUnitsOutageLessThanNbUnitsStop.h b/src/solver/optimisation/NbUnitsOutageLessThanNbUnitsStop.h new file mode 100644 index 0000000000..338c74ed1b --- /dev/null +++ b/src/solver/optimisation/NbUnitsOutageLessThanNbUnitsStop.h @@ -0,0 +1,10 @@ +#pragma once +#include "constraint_builder.h" + +class NbUnitsOutageLessThanNbUnitsStop : public Constraint +{ +public: + using Constraint::Constraint; + void add(int pays, int cluster, int clusterIndex, int pdt, bool Simulation); + int nbTermesContraintesPourLesCoutsDeDemarrage = 0; +}; \ No newline at end of file diff --git a/src/solver/optimisation/opt_construction_contraintes_couts_demarrage.cpp b/src/solver/optimisation/opt_construction_contraintes_couts_demarrage.cpp index b68d33d3f4..11658f2e39 100644 --- a/src/solver/optimisation/opt_construction_contraintes_couts_demarrage.cpp +++ b/src/solver/optimisation/opt_construction_contraintes_couts_demarrage.cpp @@ -35,6 +35,8 @@ #include "PMaxDispatchableGeneration.h" #include "PMinDispatchableGeneration.h" #include "ConsistenceNODU.h" +#include "NbUnitsOutageLessThanNbUnitsStop.h" + using namespace Antares::Data; void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( @@ -96,91 +98,6 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( consistenceNODU.add(pays, palier, index, pdt, Simulation); nbTermesContraintesPourLesCoutsDeDemarrage += consistenceNODU.nbTermesContraintesPourLesCoutsDeDemarrage; - // auto timeStepInYear = problemeHebdo->weekInTheYear * 168 + pdt; - // constraintNamer.UpdateTimeStep(timeStepInYear); - // CORRESPONDANCES_DES_VARIABLES& CorrespondanceVarNativesVarOptim - // = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt]; - - // int Pdtmoins1 = pdt - 1; - // if (Pdtmoins1 < 0) - // Pdtmoins1 = nombreDePasDeTempsPourUneOptimisation + Pdtmoins1; - // CORRESPONDANCES_DES_VARIABLES& CorrespondanceVarNativesVarOptimTmoins1 - // = problemeHebdo->CorrespondanceVarNativesVarOptim[Pdtmoins1]; - - // int nombreDeTermes = 0; - // if (!Simulation) - // { - // int var - // = CorrespondanceVarNativesVarOptim - // .NumeroDeVariableDuNombreDeGroupesEnMarcheDuPalierThermique[palier]; - // if (var >= 0) - // { - // Pi[nombreDeTermes] = 1.0; - // Colonne[nombreDeTermes] = var; - // nombreDeTermes++; - // } - // } - // else - // nbTermesContraintesPourLesCoutsDeDemarrage++; - - // if (!Simulation) - // { - // int var - // = CorrespondanceVarNativesVarOptimTmoins1 - // .NumeroDeVariableDuNombreDeGroupesEnMarcheDuPalierThermique[palier]; - // if (var >= 0) - // { - // Pi[nombreDeTermes] = -1; - // Colonne[nombreDeTermes] = var; - // nombreDeTermes++; - // } - // } - // else - // nbTermesContraintesPourLesCoutsDeDemarrage++; - - // if (!Simulation) - // { - // int var - // = CorrespondanceVarNativesVarOptim - // .NumeroDeVariableDuNombreDeGroupesQuiDemarrentDuPalierThermique[palier]; - // if (var >= 0) - // { - // Pi[nombreDeTermes] = -1; - // Colonne[nombreDeTermes] = var; - // nombreDeTermes++; - // } - // } - // else - // nbTermesContraintesPourLesCoutsDeDemarrage++; - - // if (!Simulation) - // { - // int var - // = CorrespondanceVarNativesVarOptim - // .NumeroDeVariableDuNombreDeGroupesQuiSArretentDuPalierThermique[palier]; - // if (var >= 0) - // { - // Pi[nombreDeTermes] = 1; - // Colonne[nombreDeTermes] = var; - // nombreDeTermes++; - // } - // } - // else - // nbTermesContraintesPourLesCoutsDeDemarrage++; - - // if (!Simulation) - // { - // if (nombreDeTermes > 0) - // { - // constraintNamer.ConsistenceNODU( - // ProblemeAResoudre->NombreDeContraintes, - // PaliersThermiquesDuPays.NomsDesPaliersThermiques[index]); - // OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - // ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '='); - // } - // } - // else - // ProblemeAResoudre->NombreDeContraintes += 1; } } } @@ -189,6 +106,7 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( { const PALIERS_THERMIQUES& PaliersThermiquesDuPays = problemeHebdo->PaliersThermiquesDuPays[pays]; + NbUnitsOutageLessThanNbUnitsStop nbUnitsOutageLessThanNbUnitsStop(problemeHebdo); constraintNamer.UpdateArea(problemeHebdo->NomsDesPays[pays]); for (int index = 0; index < PaliersThermiquesDuPays.NombreDePaliersThermiques; index++) @@ -198,59 +116,9 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) { - auto timeStepInYear = problemeHebdo->weekInTheYear * 168 + pdt; - constraintNamer.UpdateTimeStep(timeStepInYear); - CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim - = problemeHebdo->CorrespondanceCntNativesCntOptim[pdt]; - CorrespondanceCntNativesCntOptim - .NumeroDeContrainteDesContraintesDeDureeMinDeMarche[palier] - = -1; - - int nombreDeTermes = 0; - if (!Simulation) - { - int var - = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt] - .NumeroDeVariableDuNombreDeGroupesQuiTombentEnPanneDuPalierThermique - [palier]; - if (var >= 0) - { - Pi[nombreDeTermes] = 1.0; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } - } - else - nbTermesContraintesPourLesCoutsDeDemarrage++; - - if (!Simulation) - { - int var - = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt] - .NumeroDeVariableDuNombreDeGroupesQuiSArretentDuPalierThermique[palier]; - if (var >= 0) - { - Pi[nombreDeTermes] = -1.0; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } - } - else - nbTermesContraintesPourLesCoutsDeDemarrage++; - - if (!Simulation) - { - if (nombreDeTermes > 0) - { - constraintNamer.NbUnitsOutageLessThanNbUnitsStop( - ProblemeAResoudre->NombreDeContraintes, - PaliersThermiquesDuPays.NomsDesPaliersThermiques[index]); - OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '<'); - } - } - else - ProblemeAResoudre->NombreDeContraintes += 1; + nbUnitsOutageLessThanNbUnitsStop.add(pays, palier, index, pdt, Simulation); + nbTermesContraintesPourLesCoutsDeDemarrage + += nbUnitsOutageLessThanNbUnitsStop.nbTermesContraintesPourLesCoutsDeDemarrage; } } } From 22862bda39baa150440199bf4bc9e78f7448f309 Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Tue, 5 Sep 2023 16:38:37 +0200 Subject: [PATCH 23/43] NbDispUnitsMinBoundSinceMinUpTime --- src/solver/optimisation/CMakeLists.txt | 2 + .../NbDispUnitsMinBoundSinceMinUpTime.cpp | 64 ++++++++++++++ .../NbDispUnitsMinBoundSinceMinUpTime.h | 10 +++ ...nstruction_contraintes_couts_demarrage.cpp | 86 ++----------------- 4 files changed, 81 insertions(+), 81 deletions(-) create mode 100644 src/solver/optimisation/NbDispUnitsMinBoundSinceMinUpTime.cpp create mode 100644 src/solver/optimisation/NbDispUnitsMinBoundSinceMinUpTime.h diff --git a/src/solver/optimisation/CMakeLists.txt b/src/solver/optimisation/CMakeLists.txt index 6cb2f22aa3..da148decaa 100644 --- a/src/solver/optimisation/CMakeLists.txt +++ b/src/solver/optimisation/CMakeLists.txt @@ -117,6 +117,8 @@ set(RTESOLVER_OPT ConsistenceNODU.cpp NbUnitsOutageLessThanNbUnitsStop.h NbUnitsOutageLessThanNbUnitsStop.cpp + NbDispUnitsMinBoundSinceMinUpTime.h + NbDispUnitsMinBoundSinceMinUpTime.cpp ) diff --git a/src/solver/optimisation/NbDispUnitsMinBoundSinceMinUpTime.cpp b/src/solver/optimisation/NbDispUnitsMinBoundSinceMinUpTime.cpp new file mode 100644 index 0000000000..4ac959d3fa --- /dev/null +++ b/src/solver/optimisation/NbDispUnitsMinBoundSinceMinUpTime.cpp @@ -0,0 +1,64 @@ +#include "NbDispUnitsMinBoundSinceMinUpTime.h" + +void NbDispUnitsMinBoundSinceMinUpTime::add(int pays, + int cluster, + int clusterIndex, + int pdt, + bool Simulation) +{ + const PALIERS_THERMIQUES& PaliersThermiquesDuPays + = problemeHebdo->PaliersThermiquesDuPays[pays]; + const int DureeMinimaleDeMarcheDUnGroupeDuPalierThermique + = PaliersThermiquesDuPays.DureeMinimaleDeMarcheDUnGroupeDuPalierThermique[clusterIndex]; + + CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim + = problemeHebdo->CorrespondanceCntNativesCntOptim[pdt]; + CorrespondanceCntNativesCntOptim.NumeroDeContrainteDesContraintesDeDureeMinDeMarche[cluster] + = -1; + if (!Simulation) + { + int NombreDePasDeTempsPourUneOptimisation + = problemeHebdo->NombreDePasDeTempsPourUneOptimisation; + + const std::vector& NombreMaxDeGroupesEnMarcheDuPalierThermique + = PaliersThermiquesDuPays.PuissanceDisponibleEtCout[clusterIndex] + .NombreMaxDeGroupesEnMarcheDuPalierThermique; + + builder.updateHourWithinWeek(pdt).include(Variable::NODU(cluster), 1.0); + + for (int k = pdt - DureeMinimaleDeMarcheDUnGroupeDuPalierThermique + 1; k <= pdt; k++) + { + int t1 = k; + if (t1 < 0) + t1 = NombreDePasDeTempsPourUneOptimisation + t1; + + builder.updateHourWithinWeek(t1) + .include(Variable::NumberStartingDispatchableUnits(cluster), -1.0) + .include(Variable::NumberBreakingDownDispatchableUnits(cluster), 1.0); + } + + builder.greaterThan(); + if (builder.NumberOfVariables() > 1) + { + CorrespondanceCntNativesCntOptim + .NumeroDeContrainteDesContraintesDeDureeMinDeMarche[cluster] + = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; + + ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, + problemeHebdo->NamedProblems); + namer.UpdateArea(problemeHebdo->NomsDesPays[pays]); + + namer.UpdateTimeStep(problemeHebdo->weekInTheYear * 168 + pdt); + namer.NbDispUnitsMinBoundSinceMinUpTime( + problemeHebdo->ProblemeAResoudre->NombreDeContraintes, + PaliersThermiquesDuPays.NomsDesPaliersThermiques[clusterIndex]); + builder.build(); + } + } + else + { + nbTermesContraintesPourLesCoutsDeDemarrage + += 1 + 2 * DureeMinimaleDeMarcheDUnGroupeDuPalierThermique; + problemeHebdo->ProblemeAResoudre->NombreDeContraintes++; + } +} diff --git a/src/solver/optimisation/NbDispUnitsMinBoundSinceMinUpTime.h b/src/solver/optimisation/NbDispUnitsMinBoundSinceMinUpTime.h new file mode 100644 index 0000000000..0e460618e7 --- /dev/null +++ b/src/solver/optimisation/NbDispUnitsMinBoundSinceMinUpTime.h @@ -0,0 +1,10 @@ +#pragma once +#include "constraint_builder.h" + +class NbDispUnitsMinBoundSinceMinUpTime : public Constraint +{ +public: + using Constraint::Constraint; + void add(int pays, int cluster, int clusterIndex, int pdt, bool Simulation); + int nbTermesContraintesPourLesCoutsDeDemarrage = 0; +}; \ No newline at end of file diff --git a/src/solver/optimisation/opt_construction_contraintes_couts_demarrage.cpp b/src/solver/optimisation/opt_construction_contraintes_couts_demarrage.cpp index 11658f2e39..6b9ae7c820 100644 --- a/src/solver/optimisation/opt_construction_contraintes_couts_demarrage.cpp +++ b/src/solver/optimisation/opt_construction_contraintes_couts_demarrage.cpp @@ -36,6 +36,7 @@ #include "PMinDispatchableGeneration.h" #include "ConsistenceNODU.h" #include "NbUnitsOutageLessThanNbUnitsStop.h" +#include "NbDispUnitsMinBoundSinceMinUpTime.h" using namespace Antares::Data; @@ -127,7 +128,7 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( { const PALIERS_THERMIQUES& PaliersThermiquesDuPays = problemeHebdo->PaliersThermiquesDuPays[pays]; - + NbDispUnitsMinBoundSinceMinUpTime nbDispUnitsMinBoundSinceMinUpTime(problemeHebdo); constraintNamer.UpdateArea(problemeHebdo->NomsDesPays[pays]); for (int index = 0; index < PaliersThermiquesDuPays.NombreDePaliersThermiques; index++) { @@ -140,86 +141,9 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) { - auto timeStepInYear = problemeHebdo->weekInTheYear * 168 + pdt; - constraintNamer.UpdateTimeStep(timeStepInYear); - CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim - = problemeHebdo->CorrespondanceCntNativesCntOptim[pdt]; - CorrespondanceCntNativesCntOptim - .NumeroDeContrainteDesContraintesDeDureeMinDeMarche[palier] - = -1; - - int nombreDeTermes = 0; - if (!Simulation) - { - int var - = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt] - .NumeroDeVariableDuNombreDeGroupesEnMarcheDuPalierThermique[palier]; - if (var >= 0) - { - Pi[nombreDeTermes] = 1.0; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } - } - else - nbTermesContraintesPourLesCoutsDeDemarrage++; - - for (int k = pdt - DureeMinimaleDeMarcheDUnGroupeDuPalierThermique + 1; k <= pdt; - k++) - { - int t1 = k; - if (t1 < 0) - t1 = nombreDePasDeTempsPourUneOptimisation + t1; - - if (!Simulation) - { - int var = problemeHebdo->CorrespondanceVarNativesVarOptim[t1] - .NumeroDeVariableDuNombreDeGroupesQuiDemarrentDuPalierThermique - [palier]; - if (var >= 0) - { - Pi[nombreDeTermes] = -1.0; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } - } - else - nbTermesContraintesPourLesCoutsDeDemarrage++; - - if (!Simulation) - { - int var - = problemeHebdo->CorrespondanceVarNativesVarOptim[t1] - .NumeroDeVariableDuNombreDeGroupesQuiTombentEnPanneDuPalierThermique - [palier]; - if (var >= 0) - { - Pi[nombreDeTermes] = 1.0; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } - } - else - nbTermesContraintesPourLesCoutsDeDemarrage++; - } - - if (!Simulation) - { - if (nombreDeTermes > 1) - { - CorrespondanceCntNativesCntOptim - .NumeroDeContrainteDesContraintesDeDureeMinDeMarche[palier] - = ProblemeAResoudre->NombreDeContraintes; - - constraintNamer.NbDispUnitsMinBoundSinceMinUpTime( - ProblemeAResoudre->NombreDeContraintes, - PaliersThermiquesDuPays.NomsDesPaliersThermiques[index]); - OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '>'); - } - } - else - ProblemeAResoudre->NombreDeContraintes += 1; + nbDispUnitsMinBoundSinceMinUpTime.add(pays, palier, index, pdt, Simulation); + nbTermesContraintesPourLesCoutsDeDemarrage + += nbDispUnitsMinBoundSinceMinUpTime.nbTermesContraintesPourLesCoutsDeDemarrage; } } } From afd0808c2ebf19412e19ed90df177cc744ad084f Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Tue, 5 Sep 2023 17:10:45 +0200 Subject: [PATCH 24/43] MinDownTime --- src/solver/optimisation/CMakeLists.txt | 2 + src/solver/optimisation/MinDownTime.cpp | 64 ++++++++++++++++ src/solver/optimisation/MinDownTime.h | 10 +++ ...nstruction_contraintes_couts_demarrage.cpp | 74 ++----------------- 4 files changed, 81 insertions(+), 69 deletions(-) create mode 100644 src/solver/optimisation/MinDownTime.cpp create mode 100644 src/solver/optimisation/MinDownTime.h diff --git a/src/solver/optimisation/CMakeLists.txt b/src/solver/optimisation/CMakeLists.txt index da148decaa..a92d6a0cd9 100644 --- a/src/solver/optimisation/CMakeLists.txt +++ b/src/solver/optimisation/CMakeLists.txt @@ -119,6 +119,8 @@ set(RTESOLVER_OPT NbUnitsOutageLessThanNbUnitsStop.cpp NbDispUnitsMinBoundSinceMinUpTime.h NbDispUnitsMinBoundSinceMinUpTime.cpp + MinDownTime.h + MinDownTime.cpp ) diff --git a/src/solver/optimisation/MinDownTime.cpp b/src/solver/optimisation/MinDownTime.cpp new file mode 100644 index 0000000000..152958ea59 --- /dev/null +++ b/src/solver/optimisation/MinDownTime.cpp @@ -0,0 +1,64 @@ +#include "MinDownTime.h" + +void MinDownTime::add(int pays, int cluster, int clusterIndex, int pdt, bool Simulation) +{ + const PALIERS_THERMIQUES& PaliersThermiquesDuPays + = problemeHebdo->PaliersThermiquesDuPays[pays]; + const int DureeMinimaleDArretDUnGroupeDuPalierThermique + = PaliersThermiquesDuPays.DureeMinimaleDArretDUnGroupeDuPalierThermique[clusterIndex]; + + CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim + = problemeHebdo->CorrespondanceCntNativesCntOptim[pdt]; + CorrespondanceCntNativesCntOptim.NumeroDeContrainteDesContraintesDeDureeMinDArret[cluster] = -1; + if (!Simulation) + { + double pminDUnGroupeDuPalierThermique + = PaliersThermiquesDuPays.pminDUnGroupeDuPalierThermique[clusterIndex]; + + int NombreDePasDeTempsPourUneOptimisation + = problemeHebdo->NombreDePasDeTempsPourUneOptimisation; + + const std::vector& NombreMaxDeGroupesEnMarcheDuPalierThermique + = PaliersThermiquesDuPays.PuissanceDisponibleEtCout[clusterIndex] + .NombreMaxDeGroupesEnMarcheDuPalierThermique; + + int t1 = pdt - DureeMinimaleDArretDUnGroupeDuPalierThermique; + if (t1 < 0) + t1 = NombreDePasDeTempsPourUneOptimisation + t1; + double rhs = NombreMaxDeGroupesEnMarcheDuPalierThermique[t1]; // /!\ TODO check + + builder.updateHourWithinWeek(pdt).include(Variable::NODU(cluster), 1.0); + + for (int k = pdt - DureeMinimaleDArretDUnGroupeDuPalierThermique + 1; k <= pdt; k++) + { + int t1 = k; + if (t1 < 0) + t1 = NombreDePasDeTempsPourUneOptimisation + t1; + + builder.updateHourWithinWeek(t1).include( + Variable::NumberStoppingDispatchableUnits(cluster), 1.0); + } + builder.lessThan(); + if (builder.NumberOfVariables() > 1) + { + CorrespondanceCntNativesCntOptim + .NumeroDeContrainteDesContraintesDeDureeMinDArret[cluster] + = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; + ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, + problemeHebdo->NamedProblems); + namer.UpdateArea(problemeHebdo->NomsDesPays[pays]); + + namer.UpdateTimeStep(problemeHebdo->weekInTheYear * 168 + pdt); + namer.MinDownTime(problemeHebdo->ProblemeAResoudre->NombreDeContraintes, + PaliersThermiquesDuPays.NomsDesPaliersThermiques[clusterIndex]); + + builder.build(); + } + } + else + { + nbTermesContraintesPourLesCoutsDeDemarrage + += 1 + DureeMinimaleDArretDUnGroupeDuPalierThermique; + problemeHebdo->ProblemeAResoudre->NombreDeContraintes++; + } +} diff --git a/src/solver/optimisation/MinDownTime.h b/src/solver/optimisation/MinDownTime.h new file mode 100644 index 0000000000..abbf932e21 --- /dev/null +++ b/src/solver/optimisation/MinDownTime.h @@ -0,0 +1,10 @@ +#pragma once +#include "constraint_builder.h" + +class MinDownTime : public Constraint +{ +public: + using Constraint::Constraint; + void add(int pays, int cluster, int clusterIndex, int pdt, bool Simulation); + int nbTermesContraintesPourLesCoutsDeDemarrage = 0; +}; \ No newline at end of file diff --git a/src/solver/optimisation/opt_construction_contraintes_couts_demarrage.cpp b/src/solver/optimisation/opt_construction_contraintes_couts_demarrage.cpp index 6b9ae7c820..8fab4458c5 100644 --- a/src/solver/optimisation/opt_construction_contraintes_couts_demarrage.cpp +++ b/src/solver/optimisation/opt_construction_contraintes_couts_demarrage.cpp @@ -37,6 +37,7 @@ #include "ConsistenceNODU.h" #include "NbUnitsOutageLessThanNbUnitsStop.h" #include "NbDispUnitsMinBoundSinceMinUpTime.h" +#include "MinDownTime.h" using namespace Antares::Data; @@ -152,8 +153,7 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( { const PALIERS_THERMIQUES& PaliersThermiquesDuPays = problemeHebdo->PaliersThermiquesDuPays[pays]; - - constraintNamer.UpdateArea(problemeHebdo->NomsDesPays[pays]); + MinDownTime minDownTime(problemeHebdo); for (int index = 0; index < PaliersThermiquesDuPays.NombreDePaliersThermiques; index++) { int DureeMinimaleDArretDUnGroupeDuPalierThermique @@ -163,73 +163,9 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) { - auto timeStepInYear = problemeHebdo->weekInTheYear * 168 + pdt; - constraintNamer.UpdateTimeStep(timeStepInYear); - CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim - = problemeHebdo->CorrespondanceCntNativesCntOptim[pdt]; - CorrespondanceCntNativesCntOptim - .NumeroDeContrainteDesContraintesDeDureeMinDArret[palier] - = -1; - - CORRESPONDANCES_DES_VARIABLES& CorrespondanceVarNativesVarOptim - = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt]; - - int nombreDeTermes = 0; - if (!Simulation) - { - int var - = CorrespondanceVarNativesVarOptim - .NumeroDeVariableDuNombreDeGroupesEnMarcheDuPalierThermique[palier]; - if (var >= 0) - { - Pi[nombreDeTermes] = 1.0; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } - } - else - nbTermesContraintesPourLesCoutsDeDemarrage++; - - for (int k = pdt - DureeMinimaleDArretDUnGroupeDuPalierThermique + 1; k <= pdt; k++) - { - int t1 = k; - if (t1 < 0) - t1 = nombreDePasDeTempsPourUneOptimisation + t1; - - const auto& CorrespondanceVarNativesVarOptim_t1 - = problemeHebdo->CorrespondanceVarNativesVarOptim[t1]; - if (!Simulation) - { - int var = CorrespondanceVarNativesVarOptim_t1 - .NumeroDeVariableDuNombreDeGroupesQuiSArretentDuPalierThermique - [palier]; - if (var >= 0) - { - Pi[nombreDeTermes] = 1.0; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } - } - else - nbTermesContraintesPourLesCoutsDeDemarrage++; - } - if (!Simulation) - { - if (nombreDeTermes > 1) - { - CorrespondanceCntNativesCntOptim - .NumeroDeContrainteDesContraintesDeDureeMinDArret[palier] - = ProblemeAResoudre->NombreDeContraintes; - - constraintNamer.MinDownTime( - ProblemeAResoudre->NombreDeContraintes, - PaliersThermiquesDuPays.NomsDesPaliersThermiques[index]); - OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '<'); - } - } - else - ProblemeAResoudre->NombreDeContraintes += 1; + minDownTime.add(pays, palier, index, pdt, Simulation); + nbTermesContraintesPourLesCoutsDeDemarrage + += minDownTime.nbTermesContraintesPourLesCoutsDeDemarrage; } } } From 89584b0856091a6bf652722da1335ac1b5455a6b Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Wed, 6 Sep 2023 12:53:46 +0200 Subject: [PATCH 25/43] setup Access Control --- src/solver/optimisation/AreaBalance.h | 4 +++- src/solver/optimisation/AreaHydroLevel.h | 3 ++- src/solver/optimisation/BindingConstraintDay.h | 3 ++- src/solver/optimisation/BindingConstraintHour.h | 3 ++- src/solver/optimisation/BindingConstraintWeek.h | 3 ++- src/solver/optimisation/ConsistenceNODU.h | 2 +- src/solver/optimisation/FictitiousLoad.h | 3 ++- src/solver/optimisation/FinalStockEquivalent.h | 3 ++- src/solver/optimisation/FinalStockExpression.h | 3 ++- src/solver/optimisation/FlowDissociation.h | 3 ++- src/solver/optimisation/HydroPower.h | 3 ++- .../HydroPowerSmoothingUsingVariationMaxDown.h | 3 ++- .../optimisation/HydroPowerSmoothingUsingVariationMaxUp.h | 3 ++- .../optimisation/HydroPowerSmoothingUsingVariationSum.h | 3 ++- src/solver/optimisation/MaxHydroPower.h | 3 ++- src/solver/optimisation/MaxPumping.h | 3 ++- src/solver/optimisation/MinDownTime.h | 2 +- src/solver/optimisation/MinHydroPower.h | 2 +- .../optimisation/NbDispUnitsMinBoundSinceMinUpTime.h | 2 +- src/solver/optimisation/NbUnitsOutageLessThanNbUnitsStop.h | 2 +- src/solver/optimisation/PMaxDispatchableGeneration.h | 2 +- src/solver/optimisation/PMinDispatchableGeneration.h | 2 +- src/solver/optimisation/ShortTermStorageLevel.h | 4 +++- src/solver/optimisation/constraint_builder.cpp | 7 +------ src/solver/optimisation/constraint_builder.h | 5 ++--- 25 files changed, 44 insertions(+), 32 deletions(-) diff --git a/src/solver/optimisation/AreaBalance.h b/src/solver/optimisation/AreaBalance.h index b768622216..c09900091f 100644 --- a/src/solver/optimisation/AreaBalance.h +++ b/src/solver/optimisation/AreaBalance.h @@ -1,7 +1,9 @@ #pragma once #include "constraint_builder.h" -struct AreaBalance : public Constraint + +class AreaBalance : private Constraint { +public: using Constraint::Constraint; void add(int pdt, int pays); diff --git a/src/solver/optimisation/AreaHydroLevel.h b/src/solver/optimisation/AreaHydroLevel.h index dca2322ab1..ed0a059b3e 100644 --- a/src/solver/optimisation/AreaHydroLevel.h +++ b/src/solver/optimisation/AreaHydroLevel.h @@ -1,8 +1,9 @@ #pragma once #include "constraint_builder.h" -struct AreaHydroLevel : public Constraint +class AreaHydroLevel : private Constraint { + public: using Constraint::Constraint; void add(int pays, int pdt); }; \ No newline at end of file diff --git a/src/solver/optimisation/BindingConstraintDay.h b/src/solver/optimisation/BindingConstraintDay.h index 18244c6a46..5e257b4f6f 100644 --- a/src/solver/optimisation/BindingConstraintDay.h +++ b/src/solver/optimisation/BindingConstraintDay.h @@ -1,8 +1,9 @@ #pragma once #include "constraint_builder.h" -struct BindingConstraintDay : public Constraint +class BindingConstraintDay : private Constraint { +public: using Constraint::Constraint; void add(int cntCouplante); }; diff --git a/src/solver/optimisation/BindingConstraintHour.h b/src/solver/optimisation/BindingConstraintHour.h index 315e588976..1b0eb6224b 100644 --- a/src/solver/optimisation/BindingConstraintHour.h +++ b/src/solver/optimisation/BindingConstraintHour.h @@ -1,8 +1,9 @@ #pragma once #include "constraint_builder.h" -struct BindingConstraintHour : public Constraint +class BindingConstraintHour : private Constraint { + public: using Constraint::Constraint; void add(int pdt, int cntCouplante); }; diff --git a/src/solver/optimisation/BindingConstraintWeek.h b/src/solver/optimisation/BindingConstraintWeek.h index 26488d29eb..5d1b945462 100644 --- a/src/solver/optimisation/BindingConstraintWeek.h +++ b/src/solver/optimisation/BindingConstraintWeek.h @@ -1,8 +1,9 @@ #pragma once #include "constraint_builder.h" -struct BindingConstraintWeek : public Constraint +class BindingConstraintWeek : private Constraint { +public: using Constraint::Constraint; void add(int cntCouplante); }; \ No newline at end of file diff --git a/src/solver/optimisation/ConsistenceNODU.h b/src/solver/optimisation/ConsistenceNODU.h index 2094166efc..3f61effda1 100644 --- a/src/solver/optimisation/ConsistenceNODU.h +++ b/src/solver/optimisation/ConsistenceNODU.h @@ -1,7 +1,7 @@ #pragma once #include "constraint_builder.h" -class ConsistenceNODU : public Constraint +class ConsistenceNODU : private Constraint { public: using Constraint::Constraint; diff --git a/src/solver/optimisation/FictitiousLoad.h b/src/solver/optimisation/FictitiousLoad.h index 9a9cdf411e..d2d866b5d6 100644 --- a/src/solver/optimisation/FictitiousLoad.h +++ b/src/solver/optimisation/FictitiousLoad.h @@ -2,8 +2,9 @@ #pragma once #include "constraint_builder.h" -struct FictitiousLoad : public Constraint +class FictitiousLoad : private Constraint { +public: using Constraint::Constraint; void add(int pdt, int pays); }; diff --git a/src/solver/optimisation/FinalStockEquivalent.h b/src/solver/optimisation/FinalStockEquivalent.h index 529788da24..99e51d674f 100644 --- a/src/solver/optimisation/FinalStockEquivalent.h +++ b/src/solver/optimisation/FinalStockEquivalent.h @@ -1,8 +1,9 @@ #pragma once #include "constraint_builder.h" -struct FinalStockEquivalent : public Constraint +class FinalStockEquivalent : private Constraint { + public: using Constraint::Constraint; void add(int pays); }; diff --git a/src/solver/optimisation/FinalStockExpression.h b/src/solver/optimisation/FinalStockExpression.h index bfb8858a74..30ef6490ef 100644 --- a/src/solver/optimisation/FinalStockExpression.h +++ b/src/solver/optimisation/FinalStockExpression.h @@ -2,8 +2,9 @@ #include "constraint_builder.h" -struct FinalStockExpression : public Constraint +struct FinalStockExpression : private Constraint { +public: using Constraint::Constraint; void add(int pays); }; diff --git a/src/solver/optimisation/FlowDissociation.h b/src/solver/optimisation/FlowDissociation.h index 377a72f6cb..e135b595aa 100644 --- a/src/solver/optimisation/FlowDissociation.h +++ b/src/solver/optimisation/FlowDissociation.h @@ -1,8 +1,9 @@ #pragma once #include "constraint_builder.h" -struct FlowDissociation : public Constraint +class FlowDissociation : private Constraint { +public: using Constraint::Constraint; void add(int pdt, int interco); }; diff --git a/src/solver/optimisation/HydroPower.h b/src/solver/optimisation/HydroPower.h index f3221b6c90..2fc0cfb78a 100644 --- a/src/solver/optimisation/HydroPower.h +++ b/src/solver/optimisation/HydroPower.h @@ -1,8 +1,9 @@ #pragma once #include "constraint_builder.h" -struct HydroPower : public Constraint +struct HydroPower : private Constraint { +public: using Constraint::Constraint; void add(int pays); }; diff --git a/src/solver/optimisation/HydroPowerSmoothingUsingVariationMaxDown.h b/src/solver/optimisation/HydroPowerSmoothingUsingVariationMaxDown.h index e348b8539d..4810a40009 100644 --- a/src/solver/optimisation/HydroPowerSmoothingUsingVariationMaxDown.h +++ b/src/solver/optimisation/HydroPowerSmoothingUsingVariationMaxDown.h @@ -1,8 +1,9 @@ #pragma once #include "constraint_builder.h" -struct HydroPowerSmoothingUsingVariationMaxDown : public Constraint +class HydroPowerSmoothingUsingVariationMaxDown : private Constraint { +public: using Constraint::Constraint; void add(int pays, int pdt); }; \ No newline at end of file diff --git a/src/solver/optimisation/HydroPowerSmoothingUsingVariationMaxUp.h b/src/solver/optimisation/HydroPowerSmoothingUsingVariationMaxUp.h index b6cf0d2ef2..2a47f1cfd6 100644 --- a/src/solver/optimisation/HydroPowerSmoothingUsingVariationMaxUp.h +++ b/src/solver/optimisation/HydroPowerSmoothingUsingVariationMaxUp.h @@ -1,8 +1,9 @@ #pragma once #include "constraint_builder.h" -struct HydroPowerSmoothingUsingVariationMaxUp : public Constraint +class HydroPowerSmoothingUsingVariationMaxUp : private Constraint { +public: using Constraint::Constraint; void add(int pays, int pdt); }; \ No newline at end of file diff --git a/src/solver/optimisation/HydroPowerSmoothingUsingVariationSum.h b/src/solver/optimisation/HydroPowerSmoothingUsingVariationSum.h index bcef480118..47b24008b6 100644 --- a/src/solver/optimisation/HydroPowerSmoothingUsingVariationSum.h +++ b/src/solver/optimisation/HydroPowerSmoothingUsingVariationSum.h @@ -1,8 +1,9 @@ #pragma once #include "constraint_builder.h" -struct HydroPowerSmoothingUsingVariationSum : public Constraint +class HydroPowerSmoothingUsingVariationSum : private Constraint { +public: using Constraint::Constraint; void add(int pays); }; \ No newline at end of file diff --git a/src/solver/optimisation/MaxHydroPower.h b/src/solver/optimisation/MaxHydroPower.h index 339a904cf0..91bf25f816 100644 --- a/src/solver/optimisation/MaxHydroPower.h +++ b/src/solver/optimisation/MaxHydroPower.h @@ -1,8 +1,9 @@ #pragma once #include "constraint_builder.h" -struct MaxHydroPower : public Constraint +class MaxHydroPower : private Constraint { +public: using Constraint::Constraint; void add(int pays); }; \ No newline at end of file diff --git a/src/solver/optimisation/MaxPumping.h b/src/solver/optimisation/MaxPumping.h index 274e5a1807..bd6cd43159 100644 --- a/src/solver/optimisation/MaxPumping.h +++ b/src/solver/optimisation/MaxPumping.h @@ -1,8 +1,9 @@ #pragma once #include "constraint_builder.h" -struct MaxPumping : public Constraint +class MaxPumping : private Constraint { +public: using Constraint::Constraint; void add(int pays); }; \ No newline at end of file diff --git a/src/solver/optimisation/MinDownTime.h b/src/solver/optimisation/MinDownTime.h index abbf932e21..ee29fab770 100644 --- a/src/solver/optimisation/MinDownTime.h +++ b/src/solver/optimisation/MinDownTime.h @@ -1,7 +1,7 @@ #pragma once #include "constraint_builder.h" -class MinDownTime : public Constraint +class MinDownTime : private Constraint { public: using Constraint::Constraint; diff --git a/src/solver/optimisation/MinHydroPower.h b/src/solver/optimisation/MinHydroPower.h index 50fd96e3e4..b36b9dbeba 100644 --- a/src/solver/optimisation/MinHydroPower.h +++ b/src/solver/optimisation/MinHydroPower.h @@ -1,7 +1,7 @@ #pragma once #include "constraint_builder.h" -struct MinHydroPower : public Constraint +struct MinHydroPower : private Constraint { using Constraint::Constraint; void add(int pays); diff --git a/src/solver/optimisation/NbDispUnitsMinBoundSinceMinUpTime.h b/src/solver/optimisation/NbDispUnitsMinBoundSinceMinUpTime.h index 0e460618e7..baf6edcbcf 100644 --- a/src/solver/optimisation/NbDispUnitsMinBoundSinceMinUpTime.h +++ b/src/solver/optimisation/NbDispUnitsMinBoundSinceMinUpTime.h @@ -1,7 +1,7 @@ #pragma once #include "constraint_builder.h" -class NbDispUnitsMinBoundSinceMinUpTime : public Constraint +class NbDispUnitsMinBoundSinceMinUpTime : private Constraint { public: using Constraint::Constraint; diff --git a/src/solver/optimisation/NbUnitsOutageLessThanNbUnitsStop.h b/src/solver/optimisation/NbUnitsOutageLessThanNbUnitsStop.h index 338c74ed1b..bb09468cf3 100644 --- a/src/solver/optimisation/NbUnitsOutageLessThanNbUnitsStop.h +++ b/src/solver/optimisation/NbUnitsOutageLessThanNbUnitsStop.h @@ -1,7 +1,7 @@ #pragma once #include "constraint_builder.h" -class NbUnitsOutageLessThanNbUnitsStop : public Constraint +class NbUnitsOutageLessThanNbUnitsStop : private Constraint { public: using Constraint::Constraint; diff --git a/src/solver/optimisation/PMaxDispatchableGeneration.h b/src/solver/optimisation/PMaxDispatchableGeneration.h index 7f80bce466..b088b23851 100644 --- a/src/solver/optimisation/PMaxDispatchableGeneration.h +++ b/src/solver/optimisation/PMaxDispatchableGeneration.h @@ -1,7 +1,7 @@ #pragma once #include "constraint_builder.h" -class PMaxDispatchableGeneration : public Constraint +class PMaxDispatchableGeneration : private Constraint { public: using Constraint::Constraint; diff --git a/src/solver/optimisation/PMinDispatchableGeneration.h b/src/solver/optimisation/PMinDispatchableGeneration.h index a26fd7a1e2..cad678e936 100644 --- a/src/solver/optimisation/PMinDispatchableGeneration.h +++ b/src/solver/optimisation/PMinDispatchableGeneration.h @@ -1,7 +1,7 @@ #pragma once #include "constraint_builder.h" -class PMinDispatchableGeneration : public Constraint +class PMinDispatchableGeneration : private Constraint { public: using Constraint::Constraint; diff --git a/src/solver/optimisation/ShortTermStorageLevel.h b/src/solver/optimisation/ShortTermStorageLevel.h index 35eb41fc8d..bf739a6679 100644 --- a/src/solver/optimisation/ShortTermStorageLevel.h +++ b/src/solver/optimisation/ShortTermStorageLevel.h @@ -1,7 +1,9 @@ #pragma once #include "constraint_builder.h" -struct ShortTermStorageLevel : public Constraint + +class ShortTermStorageLevel : private Constraint { +public: using Constraint::Constraint; void add(int pdt, int pays); }; diff --git a/src/solver/optimisation/constraint_builder.cpp b/src/solver/optimisation/constraint_builder.cpp index 30551d3c28..8bfa226ceb 100644 --- a/src/solver/optimisation/constraint_builder.cpp +++ b/src/solver/optimisation/constraint_builder.cpp @@ -7,12 +7,7 @@ void ConstraintBuilder::build() // TODO check operator_ if (nombreDeTermes_ > 0) { - // // RHS - // { - // const int idx = problemeAResoudre.NombreDeContraintes; - // problemeAResoudre.SecondMembre[idx] = rhs_; - // } - // Matrix + // Matrix OPT_ChargerLaContrainteDansLaMatriceDesContraintes( &problemeAResoudre, Pi, Colonne, nombreDeTermes_, operator_); } diff --git a/src/solver/optimisation/constraint_builder.h b/src/solver/optimisation/constraint_builder.h index 53642826c2..482f62d531 100644 --- a/src/solver/optimisation/constraint_builder.h +++ b/src/solver/optimisation/constraint_builder.h @@ -15,7 +15,7 @@ namespace Variable { struct SingleIndex { - SingleIndex(unsigned index) : index(index) + explicit SingleIndex(unsigned index) : index(index) { } unsigned index; @@ -377,13 +377,12 @@ class ConstraintBuilder class Constraint { public: - Constraint(PROBLEME_HEBDO* problemeHebdo) : + explicit Constraint(PROBLEME_HEBDO* problemeHebdo) : problemeHebdo(problemeHebdo), builder(*problemeHebdo, problemeHebdo->CorrespondanceVarNativesVarOptim) { } -protected: PROBLEME_HEBDO* problemeHebdo; // TODO remove ConstraintBuilder builder; }; From d7e197d54386e86906b6d1564791a705ca03bf23 Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Wed, 6 Sep 2023 14:29:02 +0200 Subject: [PATCH 26/43] remove comments --- src/solver/optimisation/AreaBalance.cpp | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/src/solver/optimisation/AreaBalance.cpp b/src/solver/optimisation/AreaBalance.cpp index 58fd519202..13ed6f662c 100644 --- a/src/solver/optimisation/AreaBalance.cpp +++ b/src/solver/optimisation/AreaBalance.cpp @@ -69,29 +69,6 @@ void AreaBalance::add(int pdt, int pays) shortTermStorageBalance( problemeHebdo->ShortTermStorage[pays], builder, CorrespondanceVarNativesVarOptim); - // { - // const CONSOMMATIONS_ABATTUES& ConsommationsAbattues - // = problemeHebdo->ConsommationsAbattues[pdtHebdo]; - // double rhs = -ConsommationsAbattues.ConsommationAbattueDuPays[pays]; - // bool reserveJm1 = (problemeHebdo->YaDeLaReserveJmoins1); - // bool opt1 = (optimizationNumber == PREMIERE_OPTIMISATION); - // if (reserveJm1 && opt1) - // { - // rhs -= problemeHebdo->ReserveJMoins1[pays].ReserveHoraireJMoins1[pdtHebdo]; - // } - // /* check !*/ - // double* adresseDuResultat - // = &(problemeHebdo->ResultatsHoraires[pays].CoutsMarginauxHoraires[pdtHebdo]); - - // std::vector& AdresseOuPlacerLaValeurDesCoutsMarginaux - // = problemeHebdo->ProblemeAResoudre->AdresseOuPlacerLaValeurDesCoutsMarginaux; - - // int cnt = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; - - // AdresseOuPlacerLaValeurDesCoutsMarginaux[cnt] = adresseDuResultat; - - // } - /*check! */ builder.equalTo(); builder.build(); } From a956ab98ebf866ad4b96f6f273521a2cf656b152 Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Wed, 6 Sep 2023 14:32:21 +0200 Subject: [PATCH 27/43] remove comments --- src/solver/optimisation/BindingConstraintDay.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/solver/optimisation/BindingConstraintDay.cpp b/src/solver/optimisation/BindingConstraintDay.cpp index a276616453..6ef3b2a6aa 100644 --- a/src/solver/optimisation/BindingConstraintDay.cpp +++ b/src/solver/optimisation/BindingConstraintDay.cpp @@ -80,16 +80,10 @@ void BindingConstraintDay::add(int cntCouplante) CorrespondanceCntNativesCntOptimJournalieres .NumeroDeContrainteDesContraintesCouplantes[cntCouplante] = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; - // TODO probably wrong from the 2nd week, check - // const int jour = problemeHebdo->NumeroDeJourDuPasDeTemps[pdtDebut]; std::vector& AdresseOuPlacerLaValeurDesCoutsMarginaux = problemeHebdo->ProblemeAResoudre->AdresseOuPlacerLaValeurDesCoutsMarginaux; - // int cnt = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; - // AdresseOuPlacerLaValeurDesCoutsMarginaux[cnt] - // = problemeHebdo->ResultatsContraintesCouplantes[cntCouplante].variablesDuales.data() - // + jour; - // double rhs = MatriceDesContraintesCouplantes.SecondMembreDeLaContrainteCouplante[jour]; + char op = MatriceDesContraintesCouplantes.SensDeLaContrainteCouplante; builder.operatorRHS(op); { From 34e9559ac436a61f5ceb189f90005323e93bd738 Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Wed, 6 Sep 2023 14:35:44 +0200 Subject: [PATCH 28/43] treat major code smells --- src/solver/optimisation/BindingConstraintHour.cpp | 9 --------- src/solver/optimisation/BindingConstraintWeek.cpp | 3 --- 2 files changed, 12 deletions(-) diff --git a/src/solver/optimisation/BindingConstraintHour.cpp b/src/solver/optimisation/BindingConstraintHour.cpp index e98ec5e755..f37b013992 100644 --- a/src/solver/optimisation/BindingConstraintHour.cpp +++ b/src/solver/optimisation/BindingConstraintHour.cpp @@ -67,15 +67,6 @@ void BindingConstraintHour::add(int pdt, int cntCouplante) problemeHebdo->NombreDePasDeTemps); } - // std::vector& AdresseOuPlacerLaValeurDesCoutsMarginaux - // = problemeHebdo->ProblemeAResoudre->AdresseOuPlacerLaValeurDesCoutsMarginaux; - // int cnt = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; - - // double rhs = MatriceDesContraintesCouplantes.SecondMembreDeLaContrainteCouplante[pdtHebdo]; - // AdresseOuPlacerLaValeurDesCoutsMarginaux[cnt] - // = problemeHebdo->ResultatsContraintesCouplantes[cntCouplante].variablesDuales.data() - // + pdtHebdo; - char op = MatriceDesContraintesCouplantes.SensDeLaContrainteCouplante; builder.operatorRHS(op); { diff --git a/src/solver/optimisation/BindingConstraintWeek.cpp b/src/solver/optimisation/BindingConstraintWeek.cpp index 4e334dea66..24f2e17db5 100644 --- a/src/solver/optimisation/BindingConstraintWeek.cpp +++ b/src/solver/optimisation/BindingConstraintWeek.cpp @@ -15,9 +15,6 @@ void BindingConstraintWeek::add(int cntCouplante) const int nbClusters = MatriceDesContraintesCouplantes.NombreDePaliersDispatchDansLaContrainteCouplante; - const int NombreDePasDeTempsPourUneOptimisation - = problemeHebdo->NombreDePasDeTempsPourUneOptimisation; - for (int index = 0; index < nbInterco; index++) { int interco = MatriceDesContraintesCouplantes.NumeroDeLInterconnexion[index]; From c81b8014abda86b8757d34bb179df8ffa79ef8f3 Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Wed, 6 Sep 2023 15:35:37 +0200 Subject: [PATCH 29/43] treat major code smells 2 --- src/solver/optimisation/ConsistenceNODU.cpp | 14 +------ src/solver/optimisation/FictitiousLoad.cpp | 38 ++----------------- .../optimisation/FinalStockExpression.h | 2 +- src/solver/optimisation/FlowDissociation.cpp | 5 --- src/solver/optimisation/HydroPower.h | 2 +- ...droPowerSmoothingUsingVariationMaxDown.cpp | 7 ---- ...HydroPowerSmoothingUsingVariationMaxUp.cpp | 7 ---- 7 files changed, 6 insertions(+), 69 deletions(-) diff --git a/src/solver/optimisation/ConsistenceNODU.cpp b/src/solver/optimisation/ConsistenceNODU.cpp index 704c3f9d69..e5d7b16bf8 100644 --- a/src/solver/optimisation/ConsistenceNODU.cpp +++ b/src/solver/optimisation/ConsistenceNODU.cpp @@ -6,15 +6,10 @@ void ConsistenceNODU::add(int pays, int cluster, int clusterIndex, int pdt, bool { const PALIERS_THERMIQUES& PaliersThermiquesDuPays = problemeHebdo->PaliersThermiquesDuPays[pays]; - double pminDUnGroupeDuPalierThermique - = PaliersThermiquesDuPays.pminDUnGroupeDuPalierThermique[clusterIndex]; - const int DureeMinimaleDArretDUnGroupeDuPalierThermique - = PaliersThermiquesDuPays.DureeMinimaleDArretDUnGroupeDuPalierThermique[clusterIndex]; int NombreDePasDeTempsPourUneOptimisation = problemeHebdo->NombreDePasDeTempsPourUneOptimisation; - int t1 = pdt - DureeMinimaleDArretDUnGroupeDuPalierThermique; int Pdtmoins1 = pdt - 1; if (Pdtmoins1 < 0) Pdtmoins1 = NombreDePasDeTempsPourUneOptimisation + Pdtmoins1; @@ -22,14 +17,6 @@ void ConsistenceNODU::add(int pays, int cluster, int clusterIndex, int pdt, bool CORRESPONDANCES_DES_VARIABLES& CorrespondanceVarNativesVarOptimTmoins1 = problemeHebdo->CorrespondanceVarNativesVarOptim[Pdtmoins1]; - if (t1 < 0) - t1 = NombreDePasDeTempsPourUneOptimisation + t1; - - const std::vector& NombreMaxDeGroupesEnMarcheDuPalierThermique - = PaliersThermiquesDuPays.PuissanceDisponibleEtCout[clusterIndex] - .NombreMaxDeGroupesEnMarcheDuPalierThermique; - double rhs = 0; // /!\ TODO check - builder.updateHourWithinWeek(pdt) .include(Variable::NODU(cluster), 1.0) .updateHourWithinWeek(Pdtmoins1) @@ -38,6 +25,7 @@ void ConsistenceNODU::add(int pays, int cluster, int clusterIndex, int pdt, bool .include(Variable::NumberStartingDispatchableUnits(cluster), -1) .include(Variable::NumberStoppingDispatchableUnits(cluster), 1) .equalTo(); + if (builder.NumberOfVariables() > 0) { ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, diff --git a/src/solver/optimisation/FictitiousLoad.cpp b/src/solver/optimisation/FictitiousLoad.cpp index b3330ba3ef..36904c1465 100644 --- a/src/solver/optimisation/FictitiousLoad.cpp +++ b/src/solver/optimisation/FictitiousLoad.cpp @@ -25,42 +25,10 @@ void FictitiousLoad::add(int pdt, int pays) builder.updateHourWithinWeek(pdt); exportPaliers(*problemeHebdo, builder, pays); - builder.include(Variable::HydProd(pays), -problemeHebdo->DefaillanceNegativeUtiliserHydro[pays]) + auto coeff = problemeHebdo->DefaillanceNegativeUtiliserHydro[pays] ? -1 : 0; + builder.include(Variable::HydProd(pays), coeff) .include(Variable::NegativeUnsuppliedEnergy(pays), 1.0); - { - // double rhs = 0; - // // Private members ? - // const ALL_MUST_RUN_GENERATION& AllMustRunGeneration - // = problemeHebdo->AllMustRunGeneration[pdtHebdo]; - // const CONSOMMATIONS_ABATTUES& ConsommationsAbattues - // = problemeHebdo->ConsommationsAbattues[pdtHebdo]; - // const std::vector& DefaillanceNegativeUtiliserConsoAbattue - // = problemeHebdo->DefaillanceNegativeUtiliserConsoAbattue; - // const std::vector& DefaillanceNegativeUtiliserPMinThermique - // = problemeHebdo->DefaillanceNegativeUtiliserPMinThermique; - - // double MaxAllMustRunGeneration = 0.0; - - // if (AllMustRunGeneration.AllMustRunGenerationOfArea[pays] > 0.0) - // MaxAllMustRunGeneration = AllMustRunGeneration.AllMustRunGenerationOfArea[pays]; - - // double MaxMoinsConsommationBrute = 0.0; - // if (-(ConsommationsAbattues.ConsommationAbattueDuPays[pays] - // + AllMustRunGeneration.AllMustRunGenerationOfArea[pays]) - // > 0.0) - // MaxMoinsConsommationBrute = -(ConsommationsAbattues.ConsommationAbattueDuPays[pays] - // + - // AllMustRunGeneration.AllMustRunGenerationOfArea[pays]); - - // rhs = DefaillanceNegativeUtiliserConsoAbattue[pays] - // * (MaxAllMustRunGeneration + MaxMoinsConsommationBrute); - - // if (DefaillanceNegativeUtiliserPMinThermique[pays] == 0) - // { - // rhs -= OPT_SommeDesPminThermiques(problemeHebdo, pays, pdtHebdo); - // } - builder.lessThan(); - } + builder.lessThan(); builder.build(); } diff --git a/src/solver/optimisation/FinalStockExpression.h b/src/solver/optimisation/FinalStockExpression.h index 30ef6490ef..39ce549ec5 100644 --- a/src/solver/optimisation/FinalStockExpression.h +++ b/src/solver/optimisation/FinalStockExpression.h @@ -2,7 +2,7 @@ #include "constraint_builder.h" -struct FinalStockExpression : private Constraint +class FinalStockExpression : private Constraint { public: using Constraint::Constraint; diff --git a/src/solver/optimisation/FlowDissociation.cpp b/src/solver/optimisation/FlowDissociation.cpp index efd33a73cd..67f7d61bf4 100644 --- a/src/solver/optimisation/FlowDissociation.cpp +++ b/src/solver/optimisation/FlowDissociation.cpp @@ -33,11 +33,6 @@ void FlowDissociation::add(int pdt, int interco) .include(Variable::IntercoDirectCost(interco), -1.0) .include(Variable::IntercoIndirectCost(interco), 1.0); - // if (CoutDeTransport.IntercoGereeAvecLoopFlow) - // builder.equalTo( - // problemeHebdo->ValeursDeNTC[pdtHebdo].ValeurDeLoopFlowOrigineVersExtremite[interco]); - // else - // builder.equalTo(0.); builder.equalTo(); builder.build(); diff --git a/src/solver/optimisation/HydroPower.h b/src/solver/optimisation/HydroPower.h index 2fc0cfb78a..565c5d0550 100644 --- a/src/solver/optimisation/HydroPower.h +++ b/src/solver/optimisation/HydroPower.h @@ -1,7 +1,7 @@ #pragma once #include "constraint_builder.h" -struct HydroPower : private Constraint +class HydroPower : private Constraint { public: using Constraint::Constraint; diff --git a/src/solver/optimisation/HydroPowerSmoothingUsingVariationMaxDown.cpp b/src/solver/optimisation/HydroPowerSmoothingUsingVariationMaxDown.cpp index 99a3d97bbb..c14dbe05ff 100644 --- a/src/solver/optimisation/HydroPowerSmoothingUsingVariationMaxDown.cpp +++ b/src/solver/optimisation/HydroPowerSmoothingUsingVariationMaxDown.cpp @@ -7,13 +7,6 @@ void HydroPowerSmoothingUsingVariationMaxDown::add(int pays, int pdt) return; } - const int nombreDePasDeTempsPourUneOptimisation - = problemeHebdo->NombreDePasDeTempsPourUneOptimisation; - - const auto& CorrespondanceVarNativesVarOptim - = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt]; - int nombreDeTermes = 0; - ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, problemeHebdo->NamedProblems); namer.UpdateArea(problemeHebdo->NomsDesPays[pays]); diff --git a/src/solver/optimisation/HydroPowerSmoothingUsingVariationMaxUp.cpp b/src/solver/optimisation/HydroPowerSmoothingUsingVariationMaxUp.cpp index e89fa2a7b4..047376c358 100644 --- a/src/solver/optimisation/HydroPowerSmoothingUsingVariationMaxUp.cpp +++ b/src/solver/optimisation/HydroPowerSmoothingUsingVariationMaxUp.cpp @@ -7,13 +7,6 @@ void HydroPowerSmoothingUsingVariationMaxUp::add(int pays, int pdt) return; } - const int nombreDePasDeTempsPourUneOptimisation - = problemeHebdo->NombreDePasDeTempsPourUneOptimisation; - - const auto& CorrespondanceVarNativesVarOptim - = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt]; - int nombreDeTermes = 0; - ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, problemeHebdo->NamedProblems); namer.UpdateArea(problemeHebdo->NomsDesPays[pays]); From 1e6505909ac218dea20c89e524e663b062bf8b77 Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Wed, 6 Sep 2023 16:23:55 +0200 Subject: [PATCH 30/43] more on major code smells --- src/solver/optimisation/MinDownTime.cpp | 8 --- src/solver/optimisation/MinHydroPower.cpp | 2 - src/solver/optimisation/MinHydroPower.h | 3 +- .../NbUnitsOutageLessThanNbUnitsStop.cpp | 14 ----- .../PMaxDispatchableGeneration.cpp | 2 - .../PMinDispatchableGeneration.cpp | 4 +- src/solver/optimisation/constraint_builder.h | 57 ------------------- ...nstruction_contraintes_couts_demarrage.cpp | 6 -- ...n_matrice_des_contraintes_cas_lineaire.cpp | 1 - 9 files changed, 3 insertions(+), 94 deletions(-) diff --git a/src/solver/optimisation/MinDownTime.cpp b/src/solver/optimisation/MinDownTime.cpp index 152958ea59..170c4179e0 100644 --- a/src/solver/optimisation/MinDownTime.cpp +++ b/src/solver/optimisation/MinDownTime.cpp @@ -12,9 +12,6 @@ void MinDownTime::add(int pays, int cluster, int clusterIndex, int pdt, bool Sim CorrespondanceCntNativesCntOptim.NumeroDeContrainteDesContraintesDeDureeMinDArret[cluster] = -1; if (!Simulation) { - double pminDUnGroupeDuPalierThermique - = PaliersThermiquesDuPays.pminDUnGroupeDuPalierThermique[clusterIndex]; - int NombreDePasDeTempsPourUneOptimisation = problemeHebdo->NombreDePasDeTempsPourUneOptimisation; @@ -22,11 +19,6 @@ void MinDownTime::add(int pays, int cluster, int clusterIndex, int pdt, bool Sim = PaliersThermiquesDuPays.PuissanceDisponibleEtCout[clusterIndex] .NombreMaxDeGroupesEnMarcheDuPalierThermique; - int t1 = pdt - DureeMinimaleDArretDUnGroupeDuPalierThermique; - if (t1 < 0) - t1 = NombreDePasDeTempsPourUneOptimisation + t1; - double rhs = NombreMaxDeGroupesEnMarcheDuPalierThermique[t1]; // /!\ TODO check - builder.updateHourWithinWeek(pdt).include(Variable::NODU(cluster), 1.0); for (int k = pdt - DureeMinimaleDArretDUnGroupeDuPalierThermique + 1; k <= pdt; k++) diff --git a/src/solver/optimisation/MinHydroPower.cpp b/src/solver/optimisation/MinHydroPower.cpp index a3472397e4..28ba696ec5 100644 --- a/src/solver/optimisation/MinHydroPower.cpp +++ b/src/solver/optimisation/MinHydroPower.cpp @@ -25,8 +25,6 @@ void MinHydroPower::add(int pays) builder.updateHourWithinWeek(pdt); builder.include(Variable::HydProd(pays), 1.0); } - // const double rhs = problemeHebdo->CaracteristiquesHydrauliques[pays] - // .MinEnergieHydrauParIntervalleOptimise[NumeroDeLIntervalle]; problemeHebdo->NumeroDeContrainteMinEnergieHydraulique[pays] = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; diff --git a/src/solver/optimisation/MinHydroPower.h b/src/solver/optimisation/MinHydroPower.h index b36b9dbeba..6423cbcdd7 100644 --- a/src/solver/optimisation/MinHydroPower.h +++ b/src/solver/optimisation/MinHydroPower.h @@ -1,8 +1,9 @@ #pragma once #include "constraint_builder.h" -struct MinHydroPower : private Constraint +class MinHydroPower : private Constraint { +public: using Constraint::Constraint; void add(int pays); }; diff --git a/src/solver/optimisation/NbUnitsOutageLessThanNbUnitsStop.cpp b/src/solver/optimisation/NbUnitsOutageLessThanNbUnitsStop.cpp index 8efb687f22..dee28fa384 100644 --- a/src/solver/optimisation/NbUnitsOutageLessThanNbUnitsStop.cpp +++ b/src/solver/optimisation/NbUnitsOutageLessThanNbUnitsStop.cpp @@ -10,8 +10,6 @@ void NbUnitsOutageLessThanNbUnitsStop::add(int pays, { const PALIERS_THERMIQUES& PaliersThermiquesDuPays = problemeHebdo->PaliersThermiquesDuPays[pays]; - double pminDUnGroupeDuPalierThermique - = PaliersThermiquesDuPays.pminDUnGroupeDuPalierThermique[clusterIndex]; const int DureeMinimaleDArretDUnGroupeDuPalierThermique = PaliersThermiquesDuPays.DureeMinimaleDArretDUnGroupeDuPalierThermique[clusterIndex]; @@ -20,18 +18,6 @@ void NbUnitsOutageLessThanNbUnitsStop::add(int pays, CorrespondanceCntNativesCntOptim.NumeroDeContrainteDesContraintesDeDureeMinDeMarche[cluster] = -1; - int NombreDePasDeTempsPourUneOptimisation - = problemeHebdo->NombreDePasDeTempsPourUneOptimisation; - - int t1 = pdt - DureeMinimaleDArretDUnGroupeDuPalierThermique; - - if (t1 < 0) - t1 = NombreDePasDeTempsPourUneOptimisation + t1; - - const std::vector& NombreMaxDeGroupesEnMarcheDuPalierThermique - = PaliersThermiquesDuPays.PuissanceDisponibleEtCout[clusterIndex] - .NombreMaxDeGroupesEnMarcheDuPalierThermique; - builder.updateHourWithinWeek(pdt) .include(Variable::NumberBreakingDownDispatchableUnits(cluster), 1.0) .include(Variable::NumberStoppingDispatchableUnits(cluster), -1.0) diff --git a/src/solver/optimisation/PMaxDispatchableGeneration.cpp b/src/solver/optimisation/PMaxDispatchableGeneration.cpp index 854d3a100a..8dd5d50f25 100644 --- a/src/solver/optimisation/PMaxDispatchableGeneration.cpp +++ b/src/solver/optimisation/PMaxDispatchableGeneration.cpp @@ -12,8 +12,6 @@ void PMaxDispatchableGeneration::add(int pays, = problemeHebdo->PaliersThermiquesDuPays[pays]; double pmaxDUnGroupeDuPalierThermique = PaliersThermiquesDuPays.PmaxDUnGroupeDuPalierThermique[clusterIndex]; - const int DureeMinimaleDArretDUnGroupeDuPalierThermique - = PaliersThermiquesDuPays.DureeMinimaleDArretDUnGroupeDuPalierThermique[clusterIndex]; builder.updateHourWithinWeek(pdt) .include(Variable::DispatchableProduction(cluster), 1.0) diff --git a/src/solver/optimisation/PMinDispatchableGeneration.cpp b/src/solver/optimisation/PMinDispatchableGeneration.cpp index 00d5f2adcf..2d0595e67b 100644 --- a/src/solver/optimisation/PMinDispatchableGeneration.cpp +++ b/src/solver/optimisation/PMinDispatchableGeneration.cpp @@ -13,13 +13,11 @@ void PMinDispatchableGeneration::add(int pays, double pminDUnGroupeDuPalierThermique = PaliersThermiquesDuPays.pminDUnGroupeDuPalierThermique[clusterIndex]; - int NombreDePasDeTempsPourUneOptimisation - = problemeHebdo->NombreDePasDeTempsPourUneOptimisation; builder.updateHourWithinWeek(pdt) .include(Variable::DispatchableProduction(cluster), 1.0) .include(Variable::NODU(cluster), -pminDUnGroupeDuPalierThermique) .greaterThan(); - /*consider Adding rename constraint inside the builder*/ + /*consider Adding naming constraint inside the builder*/ if (builder.NumberOfVariables() > 0) { ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, diff --git a/src/solver/optimisation/constraint_builder.h b/src/solver/optimisation/constraint_builder.h index 482f62d531..c912e99061 100644 --- a/src/solver/optimisation/constraint_builder.h +++ b/src/solver/optimisation/constraint_builder.h @@ -242,32 +242,6 @@ class Visitor }; } // namespace Variable -// enum class Constraint { -// FlowDissociation, -// AreaBalance, -// FictiveLoads, -// HydroPower, -// HydroPowerSmoothingUsingVariationSum, -// HydroPowerSmoothingUsingVariationMaxDown, -// HydroPowerSmoothingUsingVariationMaxUp, -// MinHydroPower, -// MaxHydroPower, -// MaxPumping, -// AreaHydroLevel, -// FinalStockEquivalent, -// FinalStockExpression, -// NbUnitsOutageLessThanNbUnitsStop, -// NbDispUnitsMinBoundSinceMinUpTime, -// MinDownTime, -// PMaxDispatchableGeneration, -// PMinDispatchableGeneration, -// ConsistenceNODU, -// ShortTermStorageLevel, -// BindingConstraintHour, -// BindingConstraintDay, -// BindingConstraintWeek -// }; - class ConstraintBuilder { public: @@ -307,18 +281,6 @@ class ConstraintBuilder return *this; } - // ConstraintBuilder& operatorRHS(char op, double rhs) - // { - // if (op == '<' || op == '=' || op == '>') - // { - // operator_ = op; - // rhs_ = rhs; - // } - // else - // throw std::runtime_error("Invalid operator"); - - // return *this; - // } ConstraintBuilder& equalTo() { @@ -336,25 +298,6 @@ class ConstraintBuilder return *this; } - // ConstraintBuilder& equalTo(double rhs) - // { - // operator_ = '='; - // rhs_ = rhs; - // return *this; - // } - // ConstraintBuilder& lessThan(double rhs) - // { - // operator_ = '<'; - // rhs_ = rhs; - // return *this; - // } - // ConstraintBuilder& greaterThan(double rhs) - // { - // operator_ = '>'; - // rhs_ = rhs; - // return *this; - // } - void build(); int NumberOfVariables() const { diff --git a/src/solver/optimisation/opt_construction_contraintes_couts_demarrage.cpp b/src/solver/optimisation/opt_construction_contraintes_couts_demarrage.cpp index 8fab4458c5..9945b8e909 100644 --- a/src/solver/optimisation/opt_construction_contraintes_couts_demarrage.cpp +++ b/src/solver/optimisation/opt_construction_contraintes_couts_demarrage.cpp @@ -64,10 +64,6 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( { PMaxDispatchableGeneration pMaxDispatchableGeneration(problemeHebdo); PMinDispatchableGeneration pMinDispatchableGeneration(problemeHebdo); - double pminDUnGroupeDuPalierThermique - = PaliersThermiquesDuPays.pminDUnGroupeDuPalierThermique[index]; - double pmaxDUnGroupeDuPalierThermique - = PaliersThermiquesDuPays.PmaxDUnGroupeDuPalierThermique[index]; const int palier = PaliersThermiquesDuPays.NumeroDuPalierDansLEnsembleDesPaliersThermiques[index]; @@ -156,8 +152,6 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( MinDownTime minDownTime(problemeHebdo); for (int index = 0; index < PaliersThermiquesDuPays.NombreDePaliersThermiques; index++) { - int DureeMinimaleDArretDUnGroupeDuPalierThermique - = PaliersThermiquesDuPays.DureeMinimaleDArretDUnGroupeDuPalierThermique[index]; const int palier = PaliersThermiquesDuPays.NumeroDuPalierDansLEnsembleDesPaliersThermiques[index]; 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 74cd53e4f0..345bb53ddf 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 @@ -133,7 +133,6 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro if (nombreDePasDeTempsPourUneOptimisation > nombreDePasDeTempsDUneJournee) { - int semaine = problemeHebdo->weekInTheYear; CORRESPONDANCES_DES_CONTRAINTES_HEBDOMADAIRES& CorrespondanceCntNativesCntOptimHebdomadaires = problemeHebdo->CorrespondanceCntNativesCntOptimHebdomadaires; for (uint32_t cntCouplante = 0; cntCouplante < problemeHebdo->NombreDeContraintesCouplantes; From 692a8a8354415e00afe1ba543d84bb2b5dd1e27b Mon Sep 17 00:00:00 2001 From: abdoulbari zakir <32519851+a-zakir@users.noreply.github.com> Date: Thu, 7 Sep 2023 09:29:43 +0200 Subject: [PATCH 31/43] update after review --- .../opt_construction_matrice_des_contraintes_cas_lineaire.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) 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 345bb53ddf..7a96da2767 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 @@ -56,8 +56,6 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro { int var; - const bool exportStructure = problemeHebdo->ExportStructure; - const bool firstWeekOfSimulation = problemeHebdo->firstWeekOfSimulation; PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre = problemeHebdo->ProblemeAResoudre.get(); @@ -214,7 +212,7 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro } // Export structure - if (exportStructure && firstWeekOfSimulation) + if (problemeHebdo->ExportStructure && problemeHebdo->firstWeekOfSimulation) { OPT_ExportInterco(writer, problemeHebdo); OPT_ExportAreaName(writer, problemeHebdo->NomsDesPays); From 7f8054d07b0169b48be35a530e04e379abca5151 Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Mon, 11 Sep 2023 10:40:19 +0200 Subject: [PATCH 32/43] about objects lifetime --- ...struction_matrice_des_contraintes_cas_lineaire.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) 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 7a96da2767..e18b4ecb99 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 @@ -71,6 +71,11 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro ConstraintNamer constraintNamer(ProblemeAResoudre->NomDesContraintes, problemeHebdo->NamedProblems); + AreaBalance areaBalance(problemeHebdo); + FictitiousLoad fictitiousLoad(problemeHebdo); + ShortTermStorageLevel shortTermStorageLevel(problemeHebdo); + FlowDissociation flowDissociation(problemeHebdo); + BindingConstraintHour bindingConstraintHour(problemeHebdo); BindingConstraintDay bindingConstraintDay(problemeHebdo); BindingConstraintWeek bindingConstraintWeek(problemeHebdo); HydroPower hydroPower(problemeHebdo); @@ -97,12 +102,6 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim = problemeHebdo->CorrespondanceCntNativesCntOptim[pdt]; - AreaBalance areaBalance(problemeHebdo); - FictitiousLoad fictitiousLoad(problemeHebdo); - ShortTermStorageLevel shortTermStorageLevel(problemeHebdo); - FlowDissociation flowDissociation(problemeHebdo); - BindingConstraintHour bindingConstraintHour(problemeHebdo); - for (uint32_t pays = 0; pays < problemeHebdo->NombreDePays; pays++) { areaBalance.add(pdt, pays); From 5a047c0a68288b574b9464c8eb360bf016dacab0 Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Mon, 11 Sep 2023 16:06:56 +0200 Subject: [PATCH 33/43] (does not compile) cut into small pieces --- src/solver/optimisation/AreaBalance.cpp | 31 ++--- src/solver/optimisation/AreaBalance.h | 6 +- src/solver/optimisation/AreaHydroLevel.cpp | 13 +- src/solver/optimisation/AreaHydroLevel.h | 2 +- .../optimisation/BindingConstraintDay.cpp | 34 +++-- .../optimisation/BindingConstraintDay.h | 8 +- .../optimisation/BindingConstraintHour.cpp | 37 +++--- .../optimisation/BindingConstraintHour.h | 6 +- .../optimisation/BindingConstraintWeek.cpp | 69 +++++------ .../optimisation/BindingConstraintWeek.h | 9 +- src/solver/optimisation/FictitiousLoad.cpp | 10 +- src/solver/optimisation/FictitiousLoad.h | 2 +- src/solver/optimisation/FlowDissociation.cpp | 16 +-- src/solver/optimisation/FlowDissociation.h | 3 +- src/solver/optimisation/HydroPower.cpp | 3 + .../optimisation/ShortTermStorageLevel.cpp | 14 +-- .../optimisation/ShortTermStorageLevel.h | 3 +- .../csr_quadratic_problem.cpp | 89 +++++++------- .../optimisation/constraint_builder.cpp | 67 ++++++++-- src/solver/optimisation/constraint_builder.h | 31 ++++- .../opt_alloc_probleme_a_optimiser.cpp | 17 --- ...n_matrice_des_contraintes_cas_lineaire.cpp | 116 +++++++++++++++--- ...atrice_des_contraintes_cas_quadratique.cpp | 62 +++++----- ...ruction_matrice_des_contraintes_outils.cpp | 29 ----- src/solver/optimisation/opt_fonctions.h | 6 - .../optimisation/opt_rename_problem.cpp | 9 ++ src/solver/optimisation/opt_rename_problem.h | 4 + 27 files changed, 397 insertions(+), 299 deletions(-) diff --git a/src/solver/optimisation/AreaBalance.cpp b/src/solver/optimisation/AreaBalance.cpp index 13ed6f662c..94cce06921 100644 --- a/src/solver/optimisation/AreaBalance.cpp +++ b/src/solver/optimisation/AreaBalance.cpp @@ -1,22 +1,18 @@ #include "AreaBalance.h" -static void shortTermStorageBalance( - const ::ShortTermStorage::AREA_INPUT& shortTermStorageInput, - ConstraintBuilder& constraintBuilder, - const CORRESPONDANCES_DES_VARIABLES& CorrespondanceVarNativesVarOptim) +static void shortTermStorageBalance(const ::ShortTermStorage::AREA_INPUT& shortTermStorageInput, + ConstraintBuilder& constraintBuilder, + std::vector& InjectionVariable, + std::vector& WithdrawalVariable) { for (const auto& storage : shortTermStorageInput) { unsigned index = storage.clusterGlobalIndex; - if (const int varInjection - = CorrespondanceVarNativesVarOptim.SIM_ShortTermStorage.InjectionVariable[index]; - varInjection >= 0) + if (const int varInjection = InjectionVariable[index]; varInjection >= 0) { constraintBuilder.include(Variable::ShortTermStorageInjection(index), 1.0); } - if (const int varWithdrawal - = CorrespondanceVarNativesVarOptim.SIM_ShortTermStorage.WithdrawalVariable[index]; - varWithdrawal >= 0) + if (const int varWithdrawal = WithdrawalVariable[index]; varWithdrawal >= 0) { constraintBuilder.include(Variable::ShortTermStorageWithdrawal(index), -1.0); } @@ -24,15 +20,14 @@ static void shortTermStorageBalance( } // Constraint definitions -void AreaBalance::add(int pdt, int pays) +void AreaBalance::add(int pdt, + int pays, + std::vector& NumeroDeContrainteDesBilansPays, + std::vector& InjectionVariable, + std::vector& WithdrawalVariable) { /** can be done without this --- keep it for now**/ - CORRESPONDANCES_DES_VARIABLES& CorrespondanceVarNativesVarOptim - = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt]; - CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim - = problemeHebdo->CorrespondanceCntNativesCntOptim[pdt]; - CorrespondanceCntNativesCntOptim.NumeroDeContrainteDesBilansPays[pays] - = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; + NumeroDeContrainteDesBilansPays[pays] = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; /******/ // TODO improve this @@ -67,7 +62,7 @@ void AreaBalance::add(int pdt, int pays) .include(Variable::NegativeUnsuppliedEnergy(pays), 1.0); shortTermStorageBalance( - problemeHebdo->ShortTermStorage[pays], builder, CorrespondanceVarNativesVarOptim); + problemeHebdo->ShortTermStorage[pays], builder, InjectionVariable, WithdrawalVariable); builder.equalTo(); builder.build(); diff --git a/src/solver/optimisation/AreaBalance.h b/src/solver/optimisation/AreaBalance.h index c09900091f..618ba0bbbe 100644 --- a/src/solver/optimisation/AreaBalance.h +++ b/src/solver/optimisation/AreaBalance.h @@ -6,5 +6,9 @@ class AreaBalance : private Constraint public: using Constraint::Constraint; - void add(int pdt, int pays); + void add(int pdt, + int pays, + std::vector& NumeroDeContrainteDesBilansPays, + std::vector& InjectionVariable, + std::vector& WithdrawalVariable); }; \ No newline at end of file diff --git a/src/solver/optimisation/AreaHydroLevel.cpp b/src/solver/optimisation/AreaHydroLevel.cpp index ab59ebe9a0..f3fa15143b 100644 --- a/src/solver/optimisation/AreaHydroLevel.cpp +++ b/src/solver/optimisation/AreaHydroLevel.cpp @@ -1,13 +1,8 @@ #include "AreaHydroLevel.h" -void AreaHydroLevel::add(int pays, int pdt) +void AreaHydroLevel::add(int pays, int pdt, std::vector& NumeroDeContrainteDesNiveauxPays) { - const auto& CorrespondanceVarNativesVarOptim - = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt]; - CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim - = problemeHebdo->CorrespondanceCntNativesCntOptim[pdt]; - CorrespondanceCntNativesCntOptim.NumeroDeContrainteDesNiveauxPays[pays] - = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; + NumeroDeContrainteDesNiveauxPays[pays] = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; if (problemeHebdo->CaracteristiquesHydrauliques[pays].SuiviNiveauHoraire) { builder.updateHourWithinWeek(pdt).include(Variable::HydroLevel(pays), 1.0); @@ -21,7 +16,7 @@ void AreaHydroLevel::add(int pays, int pdt) namer.UpdateArea(problemeHebdo->NomsDesPays[pays]); namer.UpdateTimeStep(problemeHebdo->weekInTheYear * 168 + pdt); namer.AreaHydroLevel(problemeHebdo->ProblemeAResoudre->NombreDeContraintes); - CorrespondanceCntNativesCntOptim.NumeroDeContrainteDesNiveauxPays[pays] + NumeroDeContrainteDesNiveauxPays[pays] = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; builder.updateHourWithinWeek(pdt) .include(Variable::HydProd(pays), 1.0) @@ -32,5 +27,5 @@ void AreaHydroLevel::add(int pays, int pdt) .build(); } else - CorrespondanceCntNativesCntOptim.NumeroDeContrainteDesNiveauxPays[pays] = -1; + NumeroDeContrainteDesNiveauxPays[pays] = -1; } \ No newline at end of file diff --git a/src/solver/optimisation/AreaHydroLevel.h b/src/solver/optimisation/AreaHydroLevel.h index ed0a059b3e..7a0c118bf5 100644 --- a/src/solver/optimisation/AreaHydroLevel.h +++ b/src/solver/optimisation/AreaHydroLevel.h @@ -5,5 +5,5 @@ class AreaHydroLevel : private Constraint { public: using Constraint::Constraint; - void add(int pays, int pdt); + void add(int pays, int pdt, std::vector& NumeroDeContrainteDesNiveauxPays); }; \ No newline at end of file diff --git a/src/solver/optimisation/BindingConstraintDay.cpp b/src/solver/optimisation/BindingConstraintDay.cpp index 6ef3b2a6aa..fa8f584428 100644 --- a/src/solver/optimisation/BindingConstraintDay.cpp +++ b/src/solver/optimisation/BindingConstraintDay.cpp @@ -1,16 +1,12 @@ #include "BindingConstraintDay.h" -void BindingConstraintDay::add(int cntCouplante) +void BindingConstraintDay::add(int cntCouplante, BindingConstraintDayData& data) { - const CONTRAINTES_COUPLANTES& MatriceDesContraintesCouplantes - = problemeHebdo->MatriceDesContraintesCouplantes[cntCouplante]; - if (MatriceDesContraintesCouplantes.TypeDeContrainteCouplante != CONTRAINTE_JOURNALIERE) + if (data.TypeDeContrainteCouplante != CONTRAINTE_JOURNALIERE) return; - const int nbInterco - = MatriceDesContraintesCouplantes.NombreDInterconnexionsDansLaContrainteCouplante; - const int nbClusters - = MatriceDesContraintesCouplantes.NombreDePaliersDispatchDansLaContrainteCouplante; + const int nbInterco = data.NombreDInterconnexionsDansLaContrainteCouplante; + const int nbClusters = data.NombreDePaliersDispatchDansLaContrainteCouplante; const int NombreDePasDeTempsPourUneOptimisation = problemeHebdo->NombreDePasDeTempsPourUneOptimisation; // TODO @@ -19,14 +15,14 @@ void BindingConstraintDay::add(int cntCouplante) while (pdtDebut < NombreDePasDeTempsPourUneOptimisation) { int jour = problemeHebdo->NumeroDeJourDuPasDeTemps[pdtDebut]; - CORRESPONDANCES_DES_CONTRAINTES_JOURNALIERES& CorrespondanceCntNativesCntOptimJournalieres - = problemeHebdo->CorrespondanceCntNativesCntOptimJournalieres[jour]; + auto& CorrespondanceCntNativesCntOptimJournalieres + = data.CorrespondanceCntNativesCntOptimJournalieres[jour]; for (int index = 0; index < nbInterco; index++) { - int interco = MatriceDesContraintesCouplantes.NumeroDeLInterconnexion[index]; - double poids = MatriceDesContraintesCouplantes.PoidsDeLInterconnexion[index]; - int offset = MatriceDesContraintesCouplantes.OffsetTemporelSurLInterco[index]; + int interco = data.NumeroDeLInterconnexion[index]; + double poids = data.PoidsDeLInterconnexion[index]; + int offset = data.OffsetTemporelSurLInterco[index]; for (int pdt = pdtDebut; pdt < pdtDebut + NombreDePasDeTempsDUneJournee; pdt++) { @@ -47,14 +43,14 @@ void BindingConstraintDay::add(int cntCouplante) for (int index = 0; index < nbClusters; index++) { - int pays = MatriceDesContraintesCouplantes.PaysDuPalierDispatch[index]; + int pays = data.PaysDuPalierDispatch[index]; const PALIERS_THERMIQUES& PaliersThermiquesDuPays = problemeHebdo->PaliersThermiquesDuPays[pays]; const int palier = PaliersThermiquesDuPays.NumeroDuPalierDansLEnsembleDesPaliersThermiques - [MatriceDesContraintesCouplantes.NumeroDuPalierDispatch[index]]; - double poids = MatriceDesContraintesCouplantes.PoidsDuPalierDispatch[index]; - int offset = MatriceDesContraintesCouplantes.OffsetTemporelSurLePalierDispatch[index]; + [data.NumeroDuPalierDispatch[index]]; + double poids = data.PoidsDuPalierDispatch[index]; + int offset = data.OffsetTemporelSurLePalierDispatch[index]; for (int pdt = pdtDebut; pdt < pdtDebut + NombreDePasDeTempsDUneJournee; pdt++) { @@ -84,14 +80,14 @@ void BindingConstraintDay::add(int cntCouplante) std::vector& AdresseOuPlacerLaValeurDesCoutsMarginaux = problemeHebdo->ProblemeAResoudre->AdresseOuPlacerLaValeurDesCoutsMarginaux; - char op = MatriceDesContraintesCouplantes.SensDeLaContrainteCouplante; + char op = data.SensDeLaContrainteCouplante; builder.operatorRHS(op); { ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, problemeHebdo->NamedProblems); namer.UpdateTimeStep(jour); namer.BindingConstraintDay(problemeHebdo->ProblemeAResoudre->NombreDeContraintes, - MatriceDesContraintesCouplantes.NomDeLaContrainteCouplante); + data.NomDeLaContrainteCouplante); } builder.build(); pdtDebut += problemeHebdo->NombreDePasDeTempsDUneJournee; diff --git a/src/solver/optimisation/BindingConstraintDay.h b/src/solver/optimisation/BindingConstraintDay.h index 5e257b4f6f..39a507c872 100644 --- a/src/solver/optimisation/BindingConstraintDay.h +++ b/src/solver/optimisation/BindingConstraintDay.h @@ -1,9 +1,15 @@ #pragma once #include "constraint_builder.h" +struct BindingConstraintDayData : public BindingConstraintData +{ + // std::vector&>& CorrespondanceCntNativesCntOptimJournalieres; + std::vector& + CorrespondanceCntNativesCntOptimJournalieres; +}; class BindingConstraintDay : private Constraint { public: using Constraint::Constraint; - void add(int cntCouplante); + void add(int cntCouplante, BindingConstraintDayData& data); }; diff --git a/src/solver/optimisation/BindingConstraintHour.cpp b/src/solver/optimisation/BindingConstraintHour.cpp index f37b013992..1428fb198f 100644 --- a/src/solver/optimisation/BindingConstraintHour.cpp +++ b/src/solver/optimisation/BindingConstraintHour.cpp @@ -1,26 +1,21 @@ #include "BindingConstraintHour.h" -void BindingConstraintHour::add(int pdt, int cntCouplante) +void BindingConstraintHour::add(int pdt, int cntCouplante, BindingConstraintHourData& data) { - const CONTRAINTES_COUPLANTES& MatriceDesContraintesCouplantes - = problemeHebdo->MatriceDesContraintesCouplantes[cntCouplante]; - CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim - = problemeHebdo->CorrespondanceCntNativesCntOptim[pdt]; - CorrespondanceCntNativesCntOptim.NumeroDeContrainteDesContraintesCouplantes[cntCouplante] + data.NumeroDeContrainteDesContraintesCouplantes[cntCouplante] = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; - if (MatriceDesContraintesCouplantes.TypeDeContrainteCouplante != CONTRAINTE_HORAIRE) + if (data.TypeDeContrainteCouplante != CONTRAINTE_HORAIRE) return; builder.updateHourWithinWeek(pdt); // Links - const int nbInterco - = MatriceDesContraintesCouplantes.NombreDInterconnexionsDansLaContrainteCouplante; + const int nbInterco = data.NombreDInterconnexionsDansLaContrainteCouplante; for (int index = 0; index < nbInterco; index++) { - const int interco = MatriceDesContraintesCouplantes.NumeroDeLInterconnexion[index]; - const double poids = MatriceDesContraintesCouplantes.PoidsDeLInterconnexion[index]; - const int offset = MatriceDesContraintesCouplantes.OffsetTemporelSurLInterco[index]; + const int interco = data.NumeroDeLInterconnexion[index]; + const double poids = data.PoidsDeLInterconnexion[index]; + const int offset = data.OffsetTemporelSurLInterco[index]; int pdt1; if (offset >= 0) { @@ -37,17 +32,17 @@ void BindingConstraintHour::add(int pdt, int cntCouplante) } // Thermal clusters - const int nbClusters - = MatriceDesContraintesCouplantes.NombreDePaliersDispatchDansLaContrainteCouplante; + const int nbClusters = data.NombreDePaliersDispatchDansLaContrainteCouplante; for (int index = 0; index < nbClusters; index++) { - const int pays = MatriceDesContraintesCouplantes.PaysDuPalierDispatch[index]; + const int pays = data.PaysDuPalierDispatch[index]; const PALIERS_THERMIQUES& PaliersThermiquesDuPays = problemeHebdo->PaliersThermiquesDuPays[pays]; - const int palier = PaliersThermiquesDuPays.NumeroDuPalierDansLEnsembleDesPaliersThermiques - [MatriceDesContraintesCouplantes.NumeroDuPalierDispatch[index]]; - const double poids = MatriceDesContraintesCouplantes.PoidsDuPalierDispatch[index]; - const int offset = MatriceDesContraintesCouplantes.OffsetTemporelSurLePalierDispatch[index]; + const int palier + = PaliersThermiquesDuPays + .NumeroDuPalierDansLEnsembleDesPaliersThermiques[data.NumeroDuPalierDispatch[index]]; + const double poids = data.PoidsDuPalierDispatch[index]; + const int offset = data.OffsetTemporelSurLePalierDispatch[index]; int pdt1; if (offset >= 0) @@ -67,14 +62,14 @@ void BindingConstraintHour::add(int pdt, int cntCouplante) problemeHebdo->NombreDePasDeTemps); } - char op = MatriceDesContraintesCouplantes.SensDeLaContrainteCouplante; + char op = data.SensDeLaContrainteCouplante; builder.operatorRHS(op); { ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, problemeHebdo->NamedProblems); namer.UpdateTimeStep(problemeHebdo->weekInTheYear * 168 + pdt); namer.BindingConstraintHour(problemeHebdo->ProblemeAResoudre->NombreDeContraintes, - MatriceDesContraintesCouplantes.NomDeLaContrainteCouplante); + data.NomDeLaContrainteCouplante); } builder.build(); } diff --git a/src/solver/optimisation/BindingConstraintHour.h b/src/solver/optimisation/BindingConstraintHour.h index 1b0eb6224b..51cc8bbd5c 100644 --- a/src/solver/optimisation/BindingConstraintHour.h +++ b/src/solver/optimisation/BindingConstraintHour.h @@ -1,9 +1,13 @@ #pragma once #include "constraint_builder.h" +struct BindingConstraintHourData : public BindingConstraintData +{ + std::vector& NumeroDeContrainteDesContraintesCouplantes; +} class BindingConstraintHour : private Constraint { public: using Constraint::Constraint; - void add(int pdt, int cntCouplante); + void add(int pdt, int cntCouplante, BindingConstraintHourData& data); }; diff --git a/src/solver/optimisation/BindingConstraintWeek.cpp b/src/solver/optimisation/BindingConstraintWeek.cpp index 24f2e17db5..5c8ea61444 100644 --- a/src/solver/optimisation/BindingConstraintWeek.cpp +++ b/src/solver/optimisation/BindingConstraintWeek.cpp @@ -1,25 +1,21 @@ #include "BindingConstraintWeek.h" -void BindingConstraintWeek::add(int cntCouplante) +void BindingConstraintWeek::add(int cntCouplante, BindingConstraintWeekData& data) { - const CONTRAINTES_COUPLANTES& MatriceDesContraintesCouplantes - = problemeHebdo->MatriceDesContraintesCouplantes[cntCouplante]; int semaine = problemeHebdo->weekInTheYear; - CORRESPONDANCES_DES_CONTRAINTES_HEBDOMADAIRES& CorrespondanceCntNativesCntOptimHebdomadaires - = problemeHebdo->CorrespondanceCntNativesCntOptimHebdomadaires; - if (MatriceDesContraintesCouplantes.TypeDeContrainteCouplante != CONTRAINTE_HEBDOMADAIRE) + auto& NumeroDeContrainteDesContraintesCouplantes + = data.NumeroDeContrainteDesContraintesCouplantes; + if (data.TypeDeContrainteCouplante != CONTRAINTE_HEBDOMADAIRE) return; - const int nbInterco - = MatriceDesContraintesCouplantes.NombreDInterconnexionsDansLaContrainteCouplante; - const int nbClusters - = MatriceDesContraintesCouplantes.NombreDePaliersDispatchDansLaContrainteCouplante; + const int nbInterco = data.NombreDInterconnexionsDansLaContrainteCouplante; + const int nbClusters = data.NombreDePaliersDispatchDansLaContrainteCouplante; for (int index = 0; index < nbInterco; index++) { - int interco = MatriceDesContraintesCouplantes.NumeroDeLInterconnexion[index]; - double poids = MatriceDesContraintesCouplantes.PoidsDeLInterconnexion[index]; - int offset = MatriceDesContraintesCouplantes.OffsetTemporelSurLInterco[index]; + int interco = data.NumeroDeLInterconnexion[index]; + double poids = data.PoidsDeLInterconnexion[index]; + int offset = data.OffsetTemporelSurLInterco[index]; for (int pdt = 0; pdt < problemeHebdo->NombreDePasDeTempsPourUneOptimisation; pdt++) { builder.updateHourWithinWeek(pdt); @@ -40,16 +36,16 @@ void BindingConstraintWeek::add(int cntCouplante) for (int index = 0; index < nbClusters; index++) { - int pays = MatriceDesContraintesCouplantes.PaysDuPalierDispatch[index]; - const PALIERS_THERMIQUES& PaliersThermiquesDuPays - = problemeHebdo->PaliersThermiquesDuPays[pays]; - const int palier - = PaliersThermiquesDuPays.NumeroDuPalierDansLEnsembleDesPaliersThermiques - [MatriceDesContraintesCouplantes.NumeroDuPalierDispatch[index]]; - double poids = MatriceDesContraintesCouplantes.PoidsDuPalierDispatch[index]; - int offset = MatriceDesContraintesCouplantes.OffsetTemporelSurLePalierDispatch[index]; - for (int pdt = 0; pdt < problemeHebdo->NombreDePasDeTempsPourUneOptimisation; pdt++) - { + int pays = data.PaysDuPalierDispatch[index]; + const PALIERS_THERMIQUES& PaliersThermiquesDuPays + = problemeHebdo->PaliersThermiquesDuPays[pays]; + const int palier + = PaliersThermiquesDuPays + .NumeroDuPalierDansLEnsembleDesPaliersThermiques[data.NumeroDuPalierDispatch[index]]; + double poids = data.PoidsDuPalierDispatch[index]; + int offset = data.OffsetTemporelSurLePalierDispatch[index]; + for (int pdt = 0; pdt < problemeHebdo->NombreDePasDeTempsPourUneOptimisation; pdt++) + { int pdt1; builder.updateHourWithinWeek(pdt); // useless? @@ -68,22 +64,21 @@ void BindingConstraintWeek::add(int cntCouplante) offset, false, problemeHebdo->NombreDePasDeTemps); - } + } } - char op = MatriceDesContraintesCouplantes.SensDeLaContrainteCouplante; - builder.operatorRHS(op); + char op = data.SensDeLaContrainteCouplante; + builder.operatorRHS(op); - CorrespondanceCntNativesCntOptimHebdomadaires - .NumeroDeContrainteDesContraintesCouplantes[cntCouplante] - = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; - // Name - { - ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, - problemeHebdo->NamedProblems); - namer.UpdateTimeStep(semaine); - namer.BindingConstraintWeek(problemeHebdo->ProblemeAResoudre->NombreDeContraintes, - MatriceDesContraintesCouplantes.NomDeLaContrainteCouplante); - } + NumeroDeContrainteDesContraintesCouplantes[cntCouplante] + = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; + // Name + { + ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, + problemeHebdo->NamedProblems); + namer.UpdateTimeStep(semaine); + namer.BindingConstraintWeek(problemeHebdo->ProblemeAResoudre->NombreDeContraintes, + data.NomDeLaContrainteCouplante); + } builder.build(); } \ No newline at end of file diff --git a/src/solver/optimisation/BindingConstraintWeek.h b/src/solver/optimisation/BindingConstraintWeek.h index 5d1b945462..347db31c45 100644 --- a/src/solver/optimisation/BindingConstraintWeek.h +++ b/src/solver/optimisation/BindingConstraintWeek.h @@ -1,9 +1,16 @@ #pragma once #include "constraint_builder.h" +struct BindingConstraintWeekData : public BindingConstraintData +{ + // std::vector&>& CorrespondanceCntNativesCntOptimJournalieres; + std::vector& NumeroDeContrainteDesContraintesCouplantes; + // CORRESPONDANCES_DES_CONTRAINTES_HEBDOMADAIRES& CorrespondanceCntNativesCntOptimHebdomadaires; +}; + class BindingConstraintWeek : private Constraint { public: using Constraint::Constraint; - void add(int cntCouplante); + void add(int cntCouplante, BindingConstraintWeekData& data); }; \ No newline at end of file diff --git a/src/solver/optimisation/FictitiousLoad.cpp b/src/solver/optimisation/FictitiousLoad.cpp index 36904c1465..25c2ecee8c 100644 --- a/src/solver/optimisation/FictitiousLoad.cpp +++ b/src/solver/optimisation/FictitiousLoad.cpp @@ -1,14 +1,12 @@ #include "FictitiousLoad.h" -void FictitiousLoad::add(int pdt, int pays) +void FictitiousLoad::add(int pdt, + int pays, + std::vector& NumeroDeContraintePourEviterLesChargesFictives) { /** can be done without this --- keep it for now**/ - CORRESPONDANCES_DES_VARIABLES& CorrespondanceVarNativesVarOptim - = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt]; - CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim - = problemeHebdo->CorrespondanceCntNativesCntOptim[pdt]; - CorrespondanceCntNativesCntOptim.NumeroDeContraintePourEviterLesChargesFictives[pays] + NumeroDeContraintePourEviterLesChargesFictives[pays] = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; /******/ diff --git a/src/solver/optimisation/FictitiousLoad.h b/src/solver/optimisation/FictitiousLoad.h index d2d866b5d6..f981e1755c 100644 --- a/src/solver/optimisation/FictitiousLoad.h +++ b/src/solver/optimisation/FictitiousLoad.h @@ -6,5 +6,5 @@ class FictitiousLoad : private Constraint { public: using Constraint::Constraint; - void add(int pdt, int pays); + void add(int pdt, int pays, std::vector& NumeroDeContraintePourEviterLesChargesFictives); }; diff --git a/src/solver/optimisation/FlowDissociation.cpp b/src/solver/optimisation/FlowDissociation.cpp index 67f7d61bf4..f4c52bf5d4 100644 --- a/src/solver/optimisation/FlowDissociation.cpp +++ b/src/solver/optimisation/FlowDissociation.cpp @@ -1,21 +1,15 @@ #include "FlowDissociation.h" -void FlowDissociation::add(int pdt, int interco) +void FlowDissociation::add(int pdt, + int interco, + std::vector& NumeroDeContrainteDeDissociationDeFlux) { if (const COUTS_DE_TRANSPORT& CoutDeTransport = problemeHebdo->CoutDeTransport[interco]; CoutDeTransport.IntercoGereeAvecDesCouts) { - /** can be done without this --- keep it for now**/ - CORRESPONDANCES_DES_VARIABLES& CorrespondanceVarNativesVarOptim - = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt]; - CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim - = problemeHebdo->CorrespondanceCntNativesCntOptim[pdt]; - CorrespondanceCntNativesCntOptim.NumeroDeContrainteDeDissociationDeFlux[interco] - = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; - /******/ - // TODO improve this - + NumeroDeContrainteDeDissociationDeFlux[interco] + = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; { const auto origin = problemeHebdo->NomsDesPays[problemeHebdo->PaysOrigineDeLInterconnexion[interco]]; diff --git a/src/solver/optimisation/FlowDissociation.h b/src/solver/optimisation/FlowDissociation.h index e135b595aa..f4dc7c0474 100644 --- a/src/solver/optimisation/FlowDissociation.h +++ b/src/solver/optimisation/FlowDissociation.h @@ -5,5 +5,6 @@ class FlowDissociation : private Constraint { public: using Constraint::Constraint; - void add(int pdt, int interco); + void add(int pdt, int interco, + std::vector& NumeroDeContrainteDeDissociationDeFlux); }; diff --git a/src/solver/optimisation/HydroPower.cpp b/src/solver/optimisation/HydroPower.cpp index 50a24d48c8..ae8c4ecda4 100644 --- a/src/solver/optimisation/HydroPower.cpp +++ b/src/solver/optimisation/HydroPower.cpp @@ -1,4 +1,7 @@ #include "HydroPower.h" +struct HydroPowerData +{ +}; void HydroPower::add(int pays) { diff --git a/src/solver/optimisation/ShortTermStorageLevel.cpp b/src/solver/optimisation/ShortTermStorageLevel.cpp index 5fb9838e57..442640f376 100644 --- a/src/solver/optimisation/ShortTermStorageLevel.cpp +++ b/src/solver/optimisation/ShortTermStorageLevel.cpp @@ -1,18 +1,12 @@ #include "ShortTermStorageLevel.h" -void ShortTermStorageLevel::add(int pdt, int pays) +void ShortTermStorageLevel::add(int pdt, + int pays, + std::vector& ShortTermStorageLevelConstraint) { // TODO improve this ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, problemeHebdo->NamedProblems); - /** can be done without this --- keep it for now**/ - CORRESPONDANCES_DES_VARIABLES& CorrespondanceVarNativesVarOptim - = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt]; - CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim - = problemeHebdo->CorrespondanceCntNativesCntOptim[pdt]; - - /******/ - const int hourInTheYear = problemeHebdo->weekInTheYear * 168 + pdt; namer.UpdateTimeStep(hourInTheYear); namer.UpdateArea(problemeHebdo->NomsDesPays[pays]); @@ -24,7 +18,7 @@ void ShortTermStorageLevel::add(int pdt, int pays) namer.ShortTermStorageLevel(problemeHebdo->ProblemeAResoudre->NombreDeContraintes, storage.name); const auto index = storage.clusterGlobalIndex; - CorrespondanceCntNativesCntOptim.ShortTermStorageLevelConstraint[index] + ShortTermStorageLevelConstraint[index] = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; builder.include(Variable::ShortTermStorageLevel(index), 1.0) diff --git a/src/solver/optimisation/ShortTermStorageLevel.h b/src/solver/optimisation/ShortTermStorageLevel.h index bf739a6679..0d910674cb 100644 --- a/src/solver/optimisation/ShortTermStorageLevel.h +++ b/src/solver/optimisation/ShortTermStorageLevel.h @@ -5,5 +5,6 @@ class ShortTermStorageLevel : private Constraint { public: using Constraint::Constraint; - void add(int pdt, int pays); + void add(int pdt, int pays, + std::vector & ShortTermStorageLevelConstraint); }; 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 90ac4709c1..9273848c5c 100644 --- a/src/solver/optimisation/adequacy_patch_csr/csr_quadratic_problem.cpp +++ b/src/solver/optimisation/adequacy_patch_csr/csr_quadratic_problem.cpp @@ -33,62 +33,61 @@ #include "csr_quadratic_problem.h" #include "hourly_csr_problem.h" #include "sim_structure_probleme_economique.h" - +#include "../constraint_builder.h" +#include "../opt_rename_problem.h" using namespace Antares::Data; namespace Antares::Solver::Optimization { -void CsrQuadraticProblem::setConstraintsOnFlows(std::vector& Pi, std::vector& Colonne) -{ - int hour = hourlyCsrProblem_.triggeredHour; - const CORRESPONDANCES_DES_VARIABLES& CorrespondanceVarNativesVarOptim - = problemeHebdo_->CorrespondanceVarNativesVarOptim[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++) +class CsrFlowDissociation : private Constraint +{ +public: + using Constraint::Constraint; + void add(int hour, std::map& numberOfConstraintCsrFlowDissociation) { - if (problemeHebdo_->adequacyPatchRuntimeData->originAreaMode[Interco] - == Antares::Data::AdequacyPatch::physicalAreaInsideAdqPatch - && problemeHebdo_->adequacyPatchRuntimeData->extremityAreaMode[Interco] - == Antares::Data::AdequacyPatch::physicalAreaInsideAdqPatch) + builder.updateHourWithinWeek(hour); + const CORRESPONDANCES_DES_VARIABLES& CorrespondanceVarNativesVarOptim + = problemeHebdo->CorrespondanceVarNativesVarOptim[hour]; + + ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, + problemeHebdo->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++) { - int NombreDeTermes = 0; - int var = CorrespondanceVarNativesVarOptim.NumeroDeVariableDeLInterconnexion[Interco]; - if (var >= 0) - { - Pi[NombreDeTermes] = 1.0; - Colonne[NombreDeTermes] = var; - NombreDeTermes++; - } - var = CorrespondanceVarNativesVarOptim - .NumeroDeVariableCoutOrigineVersExtremiteDeLInterconnexion[Interco]; - if (var >= 0) - { - Pi[NombreDeTermes] = -1.0; - Colonne[NombreDeTermes] = var; - NombreDeTermes++; - } - var = CorrespondanceVarNativesVarOptim - .NumeroDeVariableCoutExtremiteVersOrigineDeLInterconnexion[Interco]; - if (var >= 0) + if (problemeHebdo->adequacyPatchRuntimeData->originAreaMode[interco] + == Antares::Data::AdequacyPatch::physicalAreaInsideAdqPatch + && problemeHebdo->adequacyPatchRuntimeData->extremityAreaMode[interco] + == Antares::Data::AdequacyPatch::physicalAreaInsideAdqPatch) { - Pi[NombreDeTermes] = 1.0; - Colonne[NombreDeTermes] = var; - NombreDeTermes++; + builder.include(Variable::NTCDirect(interco), 1.0) + .include(Variable::IntercoDirectCost(interco), -1.0) + .include(Variable::IntercoIndirectCost(interco), 1.0); + + numberOfConstraintCsrFlowDissociation[interco] + = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; + + const auto& origin + = problemeHebdo + ->NomsDesPays[problemeHebdo->PaysOrigineDeLInterconnexion[interco]]; + const auto& destination + = problemeHebdo + ->NomsDesPays[problemeHebdo->PaysExtremiteDeLInterconnexion[interco]]; + namer.CsrFlowDissociation( + problemeHebdo->ProblemeAResoudre->NombreDeContraintes, origin, destination); + + builder.build(); } - - hourlyCsrProblem_.numberOfConstraintCsrFlowDissociation[Interco] - = problemeAResoudre_.NombreDeContraintes; - - std::string NomDeLaContrainte = "flow=d-i, Interco:" + std::to_string(Interco); - logs.debug() << "C Interco: " << problemeAResoudre_.NombreDeContraintes << ": " - << NomDeLaContrainte; - - OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - &problemeAResoudre_, Pi, Colonne, NombreDeTermes, '='); } } +}; +void CsrQuadraticProblem::setConstraintsOnFlows(std::vector& Pi, std::vector& Colonne) +{ + int hour = hourlyCsrProblem_.triggeredHour; + CsrFlowDissociation csrFlowDissociation(problemeHebdo_); + csrFlowDissociation.add(hour, hourlyCsrProblem_.numberOfConstraintCsrFlowDissociation); } 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 8bfa226ceb..83424087f6 100644 --- a/src/solver/optimisation/constraint_builder.cpp +++ b/src/solver/optimisation/constraint_builder.cpp @@ -2,14 +2,13 @@ void ConstraintBuilder::build() { - std::vector& Pi = problemeAResoudre.Pi; - std::vector& Colonne = problemeAResoudre.Colonne; + std::vector& Pi = problemeAResoudre->Pi; + std::vector& Colonne = problemeAResoudre->Colonne; // TODO check operator_ if (nombreDeTermes_ > 0) { // Matrix - OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - &problemeAResoudre, Pi, Colonne, nombreDeTermes_, operator_); + OPT_ChargerLaContrainteDansLaMatriceDesContraintes(); } nombreDeTermes_ = 0; } @@ -20,12 +19,12 @@ int ConstraintBuilder::getVariableIndex(const Variable::Variant& variable, int delta) const { int pdt = hourInWeek_ + shift; - const int nbTimeSteps = problemeHebdo.NombreDePasDeTempsPourUneOptimisation; + const int nbTimeSteps = problemeHebdo->NombreDePasDeTempsPourUneOptimisation; // if (wrap) // { // pdt %= nbTimeSteps; // if (pdt < 0) - // pdt += problemeHebdo.NombreDePasDeTemps; + // pdt += problemeHebdo->NombreDePasDeTemps; // } // if (pdt < 0 || pdt >= nbTimeSteps) // { @@ -44,8 +43,8 @@ int ConstraintBuilder::getVariableIndex(const Variable::Variant& variable, } } const Variable::Visitor visitor(varNative[pdt], - problemeHebdo.NumeroDeVariableStockFinal, - problemeHebdo.NumeroDeVariableDeTrancheDeStock); + problemeHebdo->NumeroDeVariableStockFinal, + problemeHebdo->NumeroDeVariableDeTrancheDeStock); return std::visit(visitor, variable); } @@ -55,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 = problemeAResoudre->Pi; + std::vector& Colonne = problemeAResoudre->Colonne; int varIndex = getVariableIndex(var, shift, wrap, delta); if (varIndex >= 0) { @@ -65,4 +64,52 @@ ConstraintBuilder& ConstraintBuilder::include(Variable::Variant var, nombreDeTermes_++; } return *this; +} + +void ConstraintBuilder::OPT_ChargerLaContrainteDansLaMatriceDesContraintes() +{ + int& nombreDeContraintes = problemeAResoudre->NombreDeContraintes; + int& nombreDeTermesDansLaMatriceDeContrainte + = problemeAResoudre->NombreDeTermesDansLaMatriceDesContraintes; + std::vector& Pi = problemeAResoudre->Pi; + std::vector& Colonne = problemeAResoudre->Colonne; + + problemeAResoudre->IndicesDebutDeLigne[nombreDeContraintes] + = nombreDeTermesDansLaMatriceDeContrainte; + for (int i = 0; i < nombreDeTermes_; i++) + { + problemeAResoudre + ->CoefficientsDeLaMatriceDesContraintes[nombreDeTermesDansLaMatriceDeContrainte] + = Pi[i]; + problemeAResoudre->IndicesColonnes[nombreDeTermesDansLaMatriceDeContrainte] = Colonne[i]; + nombreDeTermesDansLaMatriceDeContrainte++; + if (nombreDeTermesDansLaMatriceDeContrainte + == problemeAResoudre->NombreDeTermesAllouesDansLaMatriceDesContraintes) + { + OPT_AugmenterLaTailleDeLaMatriceDesContraintes(); + } + } + problemeAResoudre->NombreDeTermesDesLignes[nombreDeContraintes] = nombreDeTermes_; + + problemeAResoudre->Sens[nombreDeContraintes] = operator_; + nombreDeContraintes++; + + return; +} + +void ConstraintBuilder::OPT_AugmenterLaTailleDeLaMatriceDesContraintes() +{ + int NbTermes = problemeAResoudre->NombreDeTermesAllouesDansLaMatriceDesContraintes; + NbTermes += problemeAResoudre->IncrementDAllocationMatriceDesContraintes; + + logs.info(); + logs.info() << " Expected Number of Non-zero terms in Problem Matrix : increased to : " + << NbTermes; + logs.info(); + + problemeAResoudre->CoefficientsDeLaMatriceDesContraintes.resize(NbTermes); + + problemeAResoudre->IndicesColonnes.resize(NbTermes); + + problemeAResoudre->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 c912e99061..bc0ad22014 100644 --- a/src/solver/optimisation/constraint_builder.h +++ b/src/solver/optimisation/constraint_builder.h @@ -246,10 +246,10 @@ class ConstraintBuilder { public: ConstraintBuilder( - PROBLEME_HEBDO& problemeHebdo, + const PROBLEME_HEBDO* problemeHebdo, const std::vector& CorrespondanceVarNativesVarOptim) : problemeHebdo(problemeHebdo), - problemeAResoudre(*problemeHebdo.ProblemeAResoudre), + problemeAResoudre(problemeHebdo->ProblemeAResoudre), varNative(CorrespondanceVarNativesVarOptim) { } @@ -305,8 +305,11 @@ class ConstraintBuilder } private: - PROBLEME_HEBDO& problemeHebdo; - PROBLEME_ANTARES_A_RESOUDRE& problemeAResoudre; + void OPT_ChargerLaContrainteDansLaMatriceDesContraintes(); + + void OPT_AugmenterLaTailleDeLaMatriceDesContraintes(); + const PROBLEME_HEBDO* problemeHebdo; + PROBLEME_ANTARES_A_RESOUDRE* problemeAResoudre; const std::vector& varNative; unsigned int hourInWeek_ = 0; @@ -320,13 +323,13 @@ class ConstraintBuilder class Constraint { public: - explicit Constraint(PROBLEME_HEBDO* problemeHebdo) : + explicit Constraint(const PROBLEME_HEBDO* problemeHebdo) : problemeHebdo(problemeHebdo), builder(*problemeHebdo, problemeHebdo->CorrespondanceVarNativesVarOptim) { } - PROBLEME_HEBDO* problemeHebdo; // TODO remove + const PROBLEME_HEBDO* problemeHebdo; // TODO remove ConstraintBuilder builder; }; @@ -345,3 +348,19 @@ inline void exportPaliers(const PROBLEME_HEBDO& problemeHebdo, constraintBuilder.include(Variable::DispatchableProduction(palier), -1.0); } } + +struct BindingConstraintData +{ + const char TypeDeContrainteCouplante; + const int NombreDInterconnexionsDansLaContrainteCouplante; + const std::vector& NumeroDeLInterconnexion; + const std::vector& PoidsDeLInterconnexion; + const std::vector& OffsetTemporelSurLInterco; + const int NombreDePaliersDispatchDansLaContrainteCouplante; + const std::vector& PaysDuPalierDispatch; + const std::vector& NumeroDuPalierDispatch; + const std::vector& PoidsDuPalierDispatch; + const std::vector& OffsetTemporelSurLePalierDispatch; + const char SensDeLaContrainteCouplante; + const char* NomDeLaContrainteCouplante; +}; \ No newline at end of file diff --git a/src/solver/optimisation/opt_alloc_probleme_a_optimiser.cpp b/src/solver/optimisation/opt_alloc_probleme_a_optimiser.cpp index 968dcb3f49..79a20488ac 100644 --- a/src/solver/optimisation/opt_alloc_probleme_a_optimiser.cpp +++ b/src/solver/optimisation/opt_alloc_probleme_a_optimiser.cpp @@ -158,20 +158,3 @@ void OPT_AllocDuProblemeAOptimiser(PROBLEME_HEBDO* problemeHebdo) optimisationAllocateProblem(problemeHebdo, mxPaliers); } - -void OPT_AugmenterLaTailleDeLaMatriceDesContraintes(PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre) -{ - int NbTermes = ProblemeAResoudre->NombreDeTermesAllouesDansLaMatriceDesContraintes; - NbTermes += ProblemeAResoudre->IncrementDAllocationMatriceDesContraintes; - - logs.info(); - logs.info() << " Expected Number of Non-zero terms in Problem Matrix : increased to : " - << NbTermes; - logs.info(); - - ProblemeAResoudre->CoefficientsDeLaMatriceDesContraintes.resize(NbTermes); - - ProblemeAResoudre->IndicesColonnes.resize(NbTermes); - - ProblemeAResoudre->NombreDeTermesAllouesDansLaMatriceDesContraintes = NbTermes; -} 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 e18b4ecb99..0c9bc6d269 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 @@ -51,6 +51,75 @@ #include using namespace Antares::Data; +static BindingConstraintData GetBindingConstraintDataFromProblemHebdo(PROBLEME_HEBDO* problemeHebdo, + int cntCouplante) +{ + const CONTRAINTES_COUPLANTES& MatriceDesContraintesCouplantes + = problemeHebdo->MatriceDesContraintesCouplantes[cntCouplante]; + + return {MatriceDesContraintesCouplantes.TypeDeContrainteCouplante, + MatriceDesContraintesCouplantes.NombreDInterconnexionsDansLaContrainteCouplante, + MatriceDesContraintesCouplantes.NumeroDeLInterconnexion, + MatriceDesContraintesCouplantes.PoidsDeLInterconnexion, + MatriceDesContraintesCouplantes.OffsetTemporelSurLInterco, + MatriceDesContraintesCouplantes.NombreDePaliersDispatchDansLaContrainteCouplante, + MatriceDesContraintesCouplantes.PaysDuPalierDispatch, + MatriceDesContraintesCouplantes.NumeroDuPalierDispatch, + MatriceDesContraintesCouplantes.PoidsDuPalierDispatch, + MatriceDesContraintesCouplantes.OffsetTemporelSurLePalierDispatch, + MatriceDesContraintesCouplantes.SensDeLaContrainteCouplante, + MatriceDesContraintesCouplantes.NomDeLaContrainteCouplante}; +} + +static BindingConstraintHourData GetBindingConstraintHourDataFromProblemHebdo( + PROBLEME_HEBDO* problemeHebdo, + int cntCouplante, + int pdt) +{ + const CONTRAINTES_COUPLANTES& MatriceDesContraintesCouplantes + = problemeHebdo->MatriceDesContraintesCouplantes[cntCouplante]; + + CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim + = problemeHebdo->CorrespondanceCntNativesCntOptim[pdt]; + BindingConstraintData data + = GetBindingConstraintDataFromProblemHebdo(problemeHebdo, cntCouplante); + return {data, CorrespondanceCntNativesCntOptim.NumeroDeContrainteDesContraintesCouplantes}; +} + +static BindingConstraintDayData GetBindingConstraintDayDataFromProblemHebdo( + PROBLEME_HEBDO* problemeHebdo, + int cntCouplante) +{ + const CONTRAINTES_COUPLANTES& MatriceDesContraintesCouplantes + = problemeHebdo->MatriceDesContraintesCouplantes[cntCouplante]; + + BindingConstraintData data + = GetBindingConstraintDataFromProblemHebdo(problemeHebdo, cntCouplante); + // TODO transfrom std::vector into + // std::vector&>& + // std::vector> correspondanceCntNativesCntOptimJournalieres; + // std::transform(problemeHebdo->CorrespondanceCntNativesCntOptimJournalieres.begin(), + // problemeHebdo->CorrespondanceCntNativesCntOptimJournalieres.end(), + // std::back_inserter(correspondanceCntNativesCntOptimJournalieres), + // [](CORRESPONDANCES_DES_CONTRAINTES_JOURNALIERES& corr) -> std::vector& + // { return corr.NumeroDeContrainteDesContraintesCouplantes; }); + + return {data, problemeHebdo->CorrespondanceCntNativesCntOptimJournalieres}; +} +static BindingConstraintWeekData GetBindingConstraintWeekDataFromProblemHebdo( + PROBLEME_HEBDO* problemeHebdo, + int cntCouplante) +{ + const CONTRAINTES_COUPLANTES& MatriceDesContraintesCouplantes + = problemeHebdo->MatriceDesContraintesCouplantes[cntCouplante]; + + BindingConstraintData data + = GetBindingConstraintDataFromProblemHebdo(problemeHebdo, cntCouplante); + + return {data, + problemeHebdo->CorrespondanceCntNativesCntOptimHebdomadaires + .NumeroDeContrainteDesContraintesCouplantes}; +} void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* problemeHebdo, Solver::IResultWriter& writer) { @@ -104,38 +173,56 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro for (uint32_t pays = 0; pays < problemeHebdo->NombreDePays; pays++) { - areaBalance.add(pdt, pays); - - fictitiousLoad.add(pdt, pays); - - shortTermStorageLevel.add(pdt, pays); + areaBalance.add( + pdt, + pays, + CorrespondanceCntNativesCntOptim.NumeroDeContrainteDesBilansPays, + CorrespondanceVarNativesVarOptim.SIM_ShortTermStorage.InjectionVariable, + CorrespondanceVarNativesVarOptim.SIM_ShortTermStorage.WithdrawalVariable); + + fictitiousLoad.add( + pdt, + pays, + CorrespondanceCntNativesCntOptim.NumeroDeContraintePourEviterLesChargesFictives); + + shortTermStorageLevel.add( + pdt, pays, CorrespondanceCntNativesCntOptim.ShortTermStorageLevelConstraint); } for (uint32_t interco = 0; interco < problemeHebdo->NombreDInterconnexions; interco++) { - flowDissociation.add(pdt, interco); + CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim + = problemeHebdo->CorrespondanceCntNativesCntOptim[pdt]; + flowDissociation.add( + pdt, + interco, + CorrespondanceCntNativesCntOptim.NumeroDeContrainteDeDissociationDeFlux); } for (uint32_t cntCouplante = 0; cntCouplante < problemeHebdo->NombreDeContraintesCouplantes; cntCouplante++) { - bindingConstraintHour.add(pdt, cntCouplante); + bindingConstraintHour.add( + pdt, + cntCouplante, + GetBindingConstraintHourDataFromProblemHebdo(problemeHebdo, cntCouplante, pdt)); } } for (uint32_t cntCouplante = 0; cntCouplante < problemeHebdo->NombreDeContraintesCouplantes; cntCouplante++) { - bindingConstraintDay.add(cntCouplante); + bindingConstraintDay.add( + cntCouplante, GetBindingConstraintDayDataFromProblemHebdo(problemeHebdo, cntCouplante)); } if (nombreDePasDeTempsPourUneOptimisation > nombreDePasDeTempsDUneJournee) { - CORRESPONDANCES_DES_CONTRAINTES_HEBDOMADAIRES& CorrespondanceCntNativesCntOptimHebdomadaires - = problemeHebdo->CorrespondanceCntNativesCntOptimHebdomadaires; for (uint32_t cntCouplante = 0; cntCouplante < problemeHebdo->NombreDeContraintesCouplantes; cntCouplante++) { - bindingConstraintWeek.add(cntCouplante); + bindingConstraintWeek.add( + cntCouplante, + GetBindingConstraintWeekDataFromProblemHebdo(problemeHebdo, cntCouplante)); } } @@ -184,15 +271,16 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) { - const auto& CorrespondanceVarNativesVarOptim = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt]; CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim - = problemeHebdo->CorrespondanceCntNativesCntOptim[pdt]; + = problemeHebdo->CorrespondanceCntNativesCntOptim[pdt]; int timeStepInYear = problemeHebdo->weekInTheYear * 168 + pdt; constraintNamer.UpdateTimeStep(timeStepInYear); + for (uint32_t pays = 0; pays < problemeHebdo->NombreDePays; pays++) { - areaHydroLevel.add(pays, pdt); + areaHydroLevel.add( + pays, pdt, CorrespondanceCntNativesCntOptim.NumeroDeContrainteDesNiveauxPays); } } 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 b3d7399045..1cce001a05 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 @@ -31,54 +31,50 @@ #include "../simulation/sim_structure_donnees.h" #include "../simulation/sim_extern_variables_globales.h" #include "opt_fonctions.h" - -void OPT_ConstruireLaMatriceDesContraintesDuProblemeQuadratique(PROBLEME_HEBDO* problemeHebdo) +#include "constraint_builder.h" +class ExchangeBalance : private Constraint { - PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre = problemeHebdo->ProblemeAResoudre.get(); - - std::vector Pi(ProblemeAResoudre->NombreDeVariables, 0.); - std::vector Colonne(ProblemeAResoudre->NombreDeVariables, 0); - - ProblemeAResoudre->NombreDeContraintes = 0; - ProblemeAResoudre->NombreDeTermesDansLaMatriceDesContraintes = 0; - const CORRESPONDANCES_DES_VARIABLES& correspondanceVarNativesVarOptim - = problemeHebdo->CorrespondanceVarNativesVarOptim[0]; - - for (uint32_t pays = 0; pays < problemeHebdo->NombreDePays - 1; pays++) +public: + using Constraint::Constraint; + void add(uint32_t pays) { - int nombreDeTermes = 0; + builder.updateHourWithinWeek(0); int interco = problemeHebdo->IndexDebutIntercoOrigine[pays]; while (interco >= 0) { - if (int var - = correspondanceVarNativesVarOptim.NumeroDeVariableDeLInterconnexion[interco]; - var >= 0) - { - Pi[nombreDeTermes] = 1.0; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } + builder.include(Variable::IntercoDirectCost(interco), 1.0); interco = problemeHebdo->IndexSuivantIntercoOrigine[interco]; } interco = problemeHebdo->IndexDebutIntercoExtremite[pays]; while (interco >= 0) { - if (int var - = correspondanceVarNativesVarOptim.NumeroDeVariableDeLInterconnexion[interco]; - var >= 0) - { - Pi[nombreDeTermes] = -1.0; - Colonne[nombreDeTermes] = var; - nombreDeTermes++; - } + builder.include(Variable::IntercoDirectCost(interco), -1.0); + interco = problemeHebdo->IndexSuivantIntercoExtremite[interco]; } problemeHebdo->NumeroDeContrainteDeSoldeDEchange[pays] - = ProblemeAResoudre->NombreDeContraintes; + = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; + builder.build(); + } +}; - OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '='); +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); + + ProblemeAResoudre->NombreDeContraintes = 0; + ProblemeAResoudre->NombreDeTermesDansLaMatriceDesContraintes = 0; + const CORRESPONDANCES_DES_VARIABLES& correspondanceVarNativesVarOptim + = problemeHebdo->CorrespondanceVarNativesVarOptim[0]; + ExchangeBalance exchangeBalance(problemeHebdo); + + for (uint32_t pays = 0; pays < problemeHebdo->NombreDePays - 1; pays++) + { + exchangeBalance.add(pays); } } diff --git a/src/solver/optimisation/opt_construction_matrice_des_contraintes_outils.cpp b/src/solver/optimisation/opt_construction_matrice_des_contraintes_outils.cpp index ecbb26cdf5..bd6d0c686f 100644 --- a/src/solver/optimisation/opt_construction_matrice_des_contraintes_outils.cpp +++ b/src/solver/optimisation/opt_construction_matrice_des_contraintes_outils.cpp @@ -30,32 +30,3 @@ #include "../simulation/sim_structure_donnees.h" #include "opt_fonctions.h" - -void OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre, - std::vector& Pi, - std::vector& Colonne, - int NombreDeTermesDeLaContrainte, - char SensContrainte) -{ - int& nombreDeTermes = ProblemeAResoudre->NombreDeTermesDansLaMatriceDesContraintes; - int& nombreDeContraintes = ProblemeAResoudre->NombreDeContraintes; - - ProblemeAResoudre->IndicesDebutDeLigne[nombreDeContraintes] = nombreDeTermes; - for (int i = 0; i < NombreDeTermesDeLaContrainte; i++) - { - ProblemeAResoudre->CoefficientsDeLaMatriceDesContraintes[nombreDeTermes] = Pi[i]; - ProblemeAResoudre->IndicesColonnes[nombreDeTermes] = Colonne[i]; - nombreDeTermes++; - if (nombreDeTermes == ProblemeAResoudre->NombreDeTermesAllouesDansLaMatriceDesContraintes) - { - OPT_AugmenterLaTailleDeLaMatriceDesContraintes(ProblemeAResoudre); - } - } - ProblemeAResoudre->NombreDeTermesDesLignes[nombreDeContraintes] = NombreDeTermesDeLaContrainte; - - ProblemeAResoudre->Sens[nombreDeContraintes] = SensContrainte; - nombreDeContraintes++; - - return; -} diff --git a/src/solver/optimisation/opt_fonctions.h b/src/solver/optimisation/opt_fonctions.h index e2807f0c8d..fd5292e24c 100644 --- a/src/solver/optimisation/opt_fonctions.h +++ b/src/solver/optimisation/opt_fonctions.h @@ -102,11 +102,6 @@ void OPT_RestaurerLesDonnees(const PROBLEME_HEBDO*); void OPT_CalculerLesPminThermiquesEnFonctionDeMUTetMDT(PROBLEME_HEBDO*); double OPT_CalculerAireMaxPminJour(int, int, int, int, std::vector&, std::vector&); -void OPT_ChargerLaContrainteDansLaMatriceDesContraintes(PROBLEME_ANTARES_A_RESOUDRE*, - std::vector&, - std::vector&, - int, - char); void OPT_ChainagesDesIntercoPartantDUnNoeud(PROBLEME_HEBDO*); void OPT_AllocateFromNumberOfVariableConstraints(PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre, @@ -114,7 +109,6 @@ void OPT_AllocateFromNumberOfVariableConstraints(PROBLEME_ANTARES_A_RESOUDRE* Pr void OPT_FreeOptimizationData(PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre); void OPT_AllocDuProblemeAOptimiser(PROBLEME_HEBDO*); int OPT_DecompteDesVariablesEtDesContraintesDuProblemeAOptimiser(PROBLEME_HEBDO*); -void OPT_AugmenterLaTailleDeLaMatriceDesContraintes(PROBLEME_ANTARES_A_RESOUDRE*); /*------------------------------*/ diff --git a/src/solver/optimisation/opt_rename_problem.cpp b/src/solver/optimisation/opt_rename_problem.cpp index 0d90030460..54f774f085 100644 --- a/src/solver/optimisation/opt_rename_problem.cpp +++ b/src/solver/optimisation/opt_rename_problem.cpp @@ -215,6 +215,15 @@ void ConstraintNamer::FlowDissociation(unsigned int constraint, SetLinkElementName(constraint, "FlowDissociation"); } +void ConstraintNamer::CsrFlowDissociation(unsigned int constraint, + const std::string& origin, + const std::string& destination) +{ + origin_ = origin; + destination_ = destination; + SetLinkElementName(constraint, "CsrFlowDissociation"); +} + void ConstraintNamer::AreaBalance(unsigned int constraint) { SetAreaElementNameHour(constraint, "AreaBalance"); diff --git a/src/solver/optimisation/opt_rename_problem.h b/src/solver/optimisation/opt_rename_problem.h index 6c19a3e415..5cd8eeb6ad 100644 --- a/src/solver/optimisation/opt_rename_problem.h +++ b/src/solver/optimisation/opt_rename_problem.h @@ -110,6 +110,10 @@ class ConstraintNamer : public Namer void FlowDissociation(unsigned int constraint, const std::string& origin, const std::string& destination); + + void CsrFlowDissociation(unsigned int constraint, + const std::string& origin, + const std::string& destination); void AreaBalance(unsigned int constraint); void FictiveLoads(unsigned int constraint); void HydroPower(unsigned int constraint); From b40aec7af5f581c48a2bb387ab6cf7ad2168f9fe Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Mon, 11 Sep 2023 17:19:43 +0200 Subject: [PATCH 34/43] part 1: introduce constraints data objects --- .../optimisation/FinalStockEquivalent.cpp | 9 ++- .../optimisation/FinalStockEquivalent.h | 10 +++- .../optimisation/FinalStockExpression.cpp | 8 +-- .../optimisation/FinalStockExpression.h | 8 ++- src/solver/optimisation/HydroPower.cpp | 22 +++---- src/solver/optimisation/HydroPower.h | 11 +++- ...droPowerSmoothingUsingVariationMaxDown.cpp | 8 +-- ...HydroPowerSmoothingUsingVariationMaxUp.cpp | 8 +-- .../HydroPowerSmoothingUsingVariationSum.cpp | 17 ++---- .../HydroPowerSmoothingUsingVariationSum.h | 2 +- src/solver/optimisation/MaxHydroPower.cpp | 17 +++--- src/solver/optimisation/MaxHydroPower.h | 10 +++- src/solver/optimisation/MaxPumping.cpp | 10 ++-- src/solver/optimisation/MaxPumping.h | 7 ++- src/solver/optimisation/MinHydroPower.cpp | 19 +++--- src/solver/optimisation/MinHydroPower.h | 11 +++- ...n_matrice_des_contraintes_cas_lineaire.cpp | 60 ++++++++++++++++--- 17 files changed, 154 insertions(+), 83 deletions(-) diff --git a/src/solver/optimisation/FinalStockEquivalent.cpp b/src/solver/optimisation/FinalStockEquivalent.cpp index 24f13c1542..a04e6ae593 100644 --- a/src/solver/optimisation/FinalStockEquivalent.cpp +++ b/src/solver/optimisation/FinalStockEquivalent.cpp @@ -1,13 +1,12 @@ #include "FinalStockEquivalent.h" -void FinalStockEquivalent::add(int pays) +void FinalStockEquivalent::add(int pays, FinalStockEquivalentData& data) { - const auto pdt = problemeHebdo->NombreDePasDeTempsPourUneOptimisation - 1; - if (problemeHebdo->CaracteristiquesHydrauliques[pays].AccurateWaterValue - && problemeHebdo->CaracteristiquesHydrauliques[pays].DirectLevelAccess) + const auto pdt = data.pdt; + if (data.AccurateWaterValue && data.DirectLevelAccess) { /* equivalence constraint : StockFinal- Niveau[T]= 0*/ - problemeHebdo->NumeroDeContrainteEquivalenceStockFinal[pays] + data.NumeroDeContrainteEquivalenceStockFinal[pays] = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, problemeHebdo->NamedProblems); diff --git a/src/solver/optimisation/FinalStockEquivalent.h b/src/solver/optimisation/FinalStockEquivalent.h index 99e51d674f..39305a59df 100644 --- a/src/solver/optimisation/FinalStockEquivalent.h +++ b/src/solver/optimisation/FinalStockEquivalent.h @@ -1,9 +1,17 @@ #pragma once #include "constraint_builder.h" +struct FinalStockEquivalentData +{ + const int pdt; + const bool AccurateWaterValue; + const bool DirectLevelAccess; + std::vector& NumeroDeContrainteEquivalenceStockFinal; +}; + class FinalStockEquivalent : private Constraint { public: using Constraint::Constraint; - void add(int pays); + void add(int pays, FinalStockEquivalentData& data); }; diff --git a/src/solver/optimisation/FinalStockExpression.cpp b/src/solver/optimisation/FinalStockExpression.cpp index 611f40f18f..112b1e9657 100644 --- a/src/solver/optimisation/FinalStockExpression.cpp +++ b/src/solver/optimisation/FinalStockExpression.cpp @@ -1,10 +1,10 @@ #include "FinalStockExpression.h" -void FinalStockExpression::add(int pays) +void FinalStockExpression::add(int pays, FinalStockExpressionData& data) { - const auto pdt = problemeHebdo->NombreDePasDeTempsPourUneOptimisation - 1; + const auto pdt = data.pdt; - if (problemeHebdo->CaracteristiquesHydrauliques[pays].AccurateWaterValue) + if (data.AccurateWaterValue) /* expression constraint : - StockFinal +sum (stocklayers) = 0*/ { builder.updateHourWithinWeek(pdt).include(Variable::FinalStorage(pays), -1.0); @@ -12,7 +12,7 @@ void FinalStockExpression::add(int pays) { builder.include(Variable::LayerStorage(pays, layerindex), 1.0); } - problemeHebdo->NumeroDeContrainteExpressionStockFinal[pays] + data.NumeroDeContrainteExpressionStockFinal[pays] = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, diff --git a/src/solver/optimisation/FinalStockExpression.h b/src/solver/optimisation/FinalStockExpression.h index 39ce549ec5..ae25c22302 100644 --- a/src/solver/optimisation/FinalStockExpression.h +++ b/src/solver/optimisation/FinalStockExpression.h @@ -2,9 +2,15 @@ #include "constraint_builder.h" +struct FinalStockExpressionData +{ + const int pdt; + const bool AccurateWaterValue; + std::vector& NumeroDeContrainteExpressionStockFinal; +}; class FinalStockExpression : private Constraint { public: using Constraint::Constraint; - void add(int pays); + void add(int pays, FinalStockExpressionData& data); }; diff --git a/src/solver/optimisation/HydroPower.cpp b/src/solver/optimisation/HydroPower.cpp index ae8c4ecda4..6b6bcfc738 100644 --- a/src/solver/optimisation/HydroPower.cpp +++ b/src/solver/optimisation/HydroPower.cpp @@ -1,26 +1,20 @@ #include "HydroPower.h" -struct HydroPowerData -{ -}; -void HydroPower::add(int pays) +void HydroPower::add(int pays, HydroPowerData& data) { - bool presenceHydro - = problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDHydrauliqueModulable; - bool TurbEntreBornes = problemeHebdo->CaracteristiquesHydrauliques[pays].TurbinageEntreBornes; + bool presenceHydro = data.presenceHydro; + bool TurbEntreBornes = data.TurbEntreBornes; const int NombreDePasDeTempsPourUneOptimisation = problemeHebdo->NombreDePasDeTempsPourUneOptimisation; if (presenceHydro && !TurbEntreBornes) { - if (bool presencePompage - = problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDePompageModulable) + if (data.presencePompage) { - problemeHebdo->NumeroDeContrainteEnergieHydraulique[pays] + data.NumeroDeContrainteEnergieHydraulique[pays] = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; - const double pumpingRatio - = problemeHebdo->CaracteristiquesHydrauliques[pays].PumpingRatio; + const double pumpingRatio = data.pumpingRatio; for (int pdt = 0; pdt < NombreDePasDeTempsPourUneOptimisation; pdt++) { builder.updateHourWithinWeek(pdt); @@ -36,7 +30,7 @@ void HydroPower::add(int pays) builder.include(Variable::HydProd(pays), 1.0); } } - problemeHebdo->NumeroDeContrainteEnergieHydraulique[pays] + data.NumeroDeContrainteEnergieHydraulique[pays] = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; builder.equalTo(); @@ -50,5 +44,5 @@ void HydroPower::add(int pays) builder.build(); } else - problemeHebdo->NumeroDeContrainteEnergieHydraulique[pays] = -1; + data.NumeroDeContrainteEnergieHydraulique[pays] = -1; } diff --git a/src/solver/optimisation/HydroPower.h b/src/solver/optimisation/HydroPower.h index 565c5d0550..7e3631095f 100644 --- a/src/solver/optimisation/HydroPower.h +++ b/src/solver/optimisation/HydroPower.h @@ -1,9 +1,18 @@ #pragma once #include "constraint_builder.h" +struct HydroPowerData +{ + const bool presenceHydro; + const int TurbEntreBornes; + const bool presencePompage; + const int NombreDePasDeTempsPourUneOptimisation; + std::vector& NumeroDeContrainteEnergieHydraulique; + const double pumpingRatio; +}; class HydroPower : private Constraint { public: using Constraint::Constraint; - void add(int pays); + void add(int pays, HydroPowerData& data); }; diff --git a/src/solver/optimisation/HydroPowerSmoothingUsingVariationMaxDown.cpp b/src/solver/optimisation/HydroPowerSmoothingUsingVariationMaxDown.cpp index c14dbe05ff..f58d9fd401 100644 --- a/src/solver/optimisation/HydroPowerSmoothingUsingVariationMaxDown.cpp +++ b/src/solver/optimisation/HydroPowerSmoothingUsingVariationMaxDown.cpp @@ -2,10 +2,10 @@ void HydroPowerSmoothingUsingVariationMaxDown::add(int pays, int pdt) { - if (!problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDHydrauliqueModulable) - { - return; - } + // if (!problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDHydrauliqueModulable) + // { + // return; + // } ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, problemeHebdo->NamedProblems); diff --git a/src/solver/optimisation/HydroPowerSmoothingUsingVariationMaxUp.cpp b/src/solver/optimisation/HydroPowerSmoothingUsingVariationMaxUp.cpp index 047376c358..4ef9ab4a01 100644 --- a/src/solver/optimisation/HydroPowerSmoothingUsingVariationMaxUp.cpp +++ b/src/solver/optimisation/HydroPowerSmoothingUsingVariationMaxUp.cpp @@ -2,10 +2,10 @@ void HydroPowerSmoothingUsingVariationMaxUp::add(int pays, int pdt) { - if (!problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDHydrauliqueModulable) - { - return; - } + // if (!problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDHydrauliqueModulable) + // { + // return; + // } ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, problemeHebdo->NamedProblems); diff --git a/src/solver/optimisation/HydroPowerSmoothingUsingVariationSum.cpp b/src/solver/optimisation/HydroPowerSmoothingUsingVariationSum.cpp index 29813fcf74..21d6022655 100644 --- a/src/solver/optimisation/HydroPowerSmoothingUsingVariationSum.cpp +++ b/src/solver/optimisation/HydroPowerSmoothingUsingVariationSum.cpp @@ -1,20 +1,15 @@ #include "HydroPowerSmoothingUsingVariationSum.h" -void HydroPowerSmoothingUsingVariationSum::add(int pays) +void HydroPowerSmoothingUsingVariationSum::add(int pays, + const int nombreDePasDeTempsPourUneOptimisation) { - if (!problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDHydrauliqueModulable) - { - return; - } + // if (!problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDHydrauliqueModulable) + // { + // return; + // } - const int nombreDePasDeTempsPourUneOptimisation - = problemeHebdo->NombreDePasDeTempsPourUneOptimisation; for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) { - const auto& CorrespondanceVarNativesVarOptim - = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt]; - int nombreDeTermes = 0; - int pdt1 = pdt + 1; if (pdt1 >= nombreDePasDeTempsPourUneOptimisation) pdt1 = 0; diff --git a/src/solver/optimisation/HydroPowerSmoothingUsingVariationSum.h b/src/solver/optimisation/HydroPowerSmoothingUsingVariationSum.h index 47b24008b6..effc7ec05f 100644 --- a/src/solver/optimisation/HydroPowerSmoothingUsingVariationSum.h +++ b/src/solver/optimisation/HydroPowerSmoothingUsingVariationSum.h @@ -5,5 +5,5 @@ class HydroPowerSmoothingUsingVariationSum : private Constraint { public: using Constraint::Constraint; - void add(int pays); + void add(int pays , const int nombreDePasDeTempsPourUneOptimisation); }; \ No newline at end of file diff --git a/src/solver/optimisation/MaxHydroPower.cpp b/src/solver/optimisation/MaxHydroPower.cpp index 4a75208469..51d7984aff 100644 --- a/src/solver/optimisation/MaxHydroPower.cpp +++ b/src/solver/optimisation/MaxHydroPower.cpp @@ -1,15 +1,12 @@ #include "MaxHydroPower.h" -void MaxHydroPower::add(int pays) +void MaxHydroPower::add(int pays, MaxHydroPowerData& data) { - bool presenceHydro - = problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDHydrauliqueModulable; - bool TurbEntreBornes = problemeHebdo->CaracteristiquesHydrauliques[pays].TurbinageEntreBornes; - if (presenceHydro - && (TurbEntreBornes - || problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDePompageModulable)) + bool presenceHydro = data.presenceHydro; + bool TurbEntreBornes = data.TurbEntreBornes; + if (presenceHydro && (TurbEntreBornes || data.PresenceDePompageModulable)) { - problemeHebdo->NumeroDeContrainteMaxEnergieHydraulique[pays] + data.NumeroDeContrainteMaxEnergieHydraulique[pays] = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; const int NombreDePasDeTempsPourUneOptimisation @@ -20,7 +17,7 @@ void MaxHydroPower::add(int pays) builder.updateHourWithinWeek(pdt); builder.include(Variable::HydProd(pays), 1.0); } - problemeHebdo->NumeroDeContrainteMaxEnergieHydraulique[pays] + data.NumeroDeContrainteMaxEnergieHydraulique[pays] = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, @@ -32,5 +29,5 @@ void MaxHydroPower::add(int pays) builder.lessThan().build(); } else - problemeHebdo->NumeroDeContrainteMaxEnergieHydraulique[pays] = -1; + data.NumeroDeContrainteMaxEnergieHydraulique[pays] = -1; } \ No newline at end of file diff --git a/src/solver/optimisation/MaxHydroPower.h b/src/solver/optimisation/MaxHydroPower.h index 91bf25f816..c5a039456e 100644 --- a/src/solver/optimisation/MaxHydroPower.h +++ b/src/solver/optimisation/MaxHydroPower.h @@ -1,9 +1,17 @@ #pragma once #include "constraint_builder.h" +struct MaxHydroPowerData +{ + const bool presenceHydro; + const bool TurbEntreBornes; + const bool PresenceDePompageModulable; + const int NombreDePasDeTempsPourUneOptimisation; + std::vector& NumeroDeContrainteMaxEnergieHydraulique; +}; class MaxHydroPower : private Constraint { public: using Constraint::Constraint; - void add(int pays); + void add(int pays, MaxHydroPowerData& data); }; \ No newline at end of file diff --git a/src/solver/optimisation/MaxPumping.cpp b/src/solver/optimisation/MaxPumping.cpp index f3d688858d..568383c174 100644 --- a/src/solver/optimisation/MaxPumping.cpp +++ b/src/solver/optimisation/MaxPumping.cpp @@ -1,10 +1,10 @@ #include "MaxPumping.h" -void MaxPumping::add(int pays) +void MaxPumping::add(int pays, MaxPumpingData& data) { - if (problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDePompageModulable) + if (data.PresenceDePompageModulable) { - problemeHebdo->NumeroDeContrainteMaxPompage[pays] + data.NumeroDeContrainteMaxPompage[pays] = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; const int NombreDePasDeTempsPourUneOptimisation @@ -15,7 +15,7 @@ void MaxPumping::add(int pays) builder.updateHourWithinWeek(pdt); builder.include(Variable::Pumping(pays), 1.0); } - problemeHebdo->NumeroDeContrainteMaxPompage[pays] + data.NumeroDeContrainteMaxPompage[pays] = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, problemeHebdo->NamedProblems); @@ -25,5 +25,5 @@ void MaxPumping::add(int pays) builder.lessThan().build(); } else - problemeHebdo->NumeroDeContrainteMaxPompage[pays] = -1; + data.NumeroDeContrainteMaxPompage[pays] = -1; } \ No newline at end of file diff --git a/src/solver/optimisation/MaxPumping.h b/src/solver/optimisation/MaxPumping.h index bd6cd43159..91bb0e5ff5 100644 --- a/src/solver/optimisation/MaxPumping.h +++ b/src/solver/optimisation/MaxPumping.h @@ -1,9 +1,14 @@ #pragma once #include "constraint_builder.h" +struct MaxPumpingData +{ + const bool PresenceDePompageModulable; + std::vector& NumeroDeContrainteMaxPompage; +}; class MaxPumping : private Constraint { public: using Constraint::Constraint; - void add(int pays); + void add(int pays, MaxPumpingData& data); }; \ No newline at end of file diff --git a/src/solver/optimisation/MinHydroPower.cpp b/src/solver/optimisation/MinHydroPower.cpp index 28ba696ec5..a6f3b0f89a 100644 --- a/src/solver/optimisation/MinHydroPower.cpp +++ b/src/solver/optimisation/MinHydroPower.cpp @@ -1,19 +1,16 @@ #include "MinHydroPower.h" -void MinHydroPower::add(int pays) +void MinHydroPower::add(int pays, MinHydroPowerData& data) { - bool presenceHydro - = problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDHydrauliqueModulable; - bool TurbEntreBornes = problemeHebdo->CaracteristiquesHydrauliques[pays].TurbinageEntreBornes; - if (presenceHydro - && (TurbEntreBornes - || problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDePompageModulable)) + bool presenceHydro = data.presenceHydro; + bool TurbEntreBornes = data.TurbEntreBornes; + if (presenceHydro && (TurbEntreBornes || data.PresenceDePompageModulable)) { - problemeHebdo->NumeroDeContrainteMinEnergieHydraulique[pays] + data.NumeroDeContrainteMinEnergieHydraulique[pays] = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; const int NombreDePasDeTempsPourUneOptimisation - = problemeHebdo->NombreDePasDeTempsPourUneOptimisation; + = data.NombreDePasDeTempsPourUneOptimisation; ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, problemeHebdo->NamedProblems); @@ -26,10 +23,10 @@ void MinHydroPower::add(int pays) builder.include(Variable::HydProd(pays), 1.0); } - problemeHebdo->NumeroDeContrainteMinEnergieHydraulique[pays] + data.NumeroDeContrainteMinEnergieHydraulique[pays] = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; builder.greaterThan().build(); } else - problemeHebdo->NumeroDeContrainteMinEnergieHydraulique[pays] = -1; + data.NumeroDeContrainteMinEnergieHydraulique[pays] = -1; } diff --git a/src/solver/optimisation/MinHydroPower.h b/src/solver/optimisation/MinHydroPower.h index 6423cbcdd7..e046e44ff8 100644 --- a/src/solver/optimisation/MinHydroPower.h +++ b/src/solver/optimisation/MinHydroPower.h @@ -1,9 +1,18 @@ #pragma once #include "constraint_builder.h" +struct MinHydroPowerData +{ + const bool presenceHydro; + const bool TurbEntreBornes; + const bool PresenceDePompageModulable; + const int NombreDePasDeTempsPourUneOptimisation; + std::vector& NumeroDeContrainteMinEnergieHydraulique; +}; + class MinHydroPower : private Constraint { public: using Constraint::Constraint; - void add(int pays); + void add(int pays, MinHydroPowerData& data); }; 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 0c9bc6d269..d214cbf281 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 @@ -121,6 +121,37 @@ static BindingConstraintWeekData GetBindingConstraintWeekDataFromProblemHebdo( .NumeroDeContrainteDesContraintesCouplantes}; } +static HydroPowerData GetHydroPowerDataFromProblemHebdo(PROBLEME_HEBDO* problemeHebdo, + uint32_t pays) +{ + return {problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDHydrauliqueModulable, + problemeHebdo->CaracteristiquesHydrauliques[pays].TurbinageEntreBornes, + problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDePompageModulable, + problemeHebdo->NombreDePasDeTempsPourUneOptimisation, + problemeHebdo->NumeroDeContrainteEnergieHydraulique, + problemeHebdo->CaracteristiquesHydrauliques[pays].PumpingRatio}; +} + +static MinHydroPowerData GetMinHydroPowerDataFromProblemHebdo(PROBLEME_HEBDO* problemeHebdo, + uint32_t pays) +{ + return {problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDHydrauliqueModulable, + problemeHebdo->CaracteristiquesHydrauliques[pays].TurbinageEntreBornes, + problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDePompageModulable, + problemeHebdo->NombreDePasDeTempsPourUneOptimisation, + problemeHebdo->NumeroDeContrainteMinEnergieHydraulique}; +} + +static MaxHydroPowerData GetMaxHydroPowerDataFromProblemHebdo(PROBLEME_HEBDO* problemeHebdo, + uint32_t pays) +{ + return {problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDHydrauliqueModulable, + problemeHebdo->CaracteristiquesHydrauliques[pays].TurbinageEntreBornes, + problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDePompageModulable, + problemeHebdo->NombreDePasDeTempsPourUneOptimisation, + problemeHebdo->NumeroDeContrainteMaxEnergieHydraulique}; +} + void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* problemeHebdo, Solver::IResultWriter& writer) { int var; @@ -228,7 +259,7 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro for (uint32_t pays = 0; pays < problemeHebdo->NombreDePays; pays++) { - hydroPower.add(pays); + hydroPower.add(pays, GetHydroPowerDataFromProblemHebdo(problemeHebdo, pays)); } if (problemeHebdo->TypeDeLissageHydraulique == LISSAGE_HYDRAULIQUE_SUR_SOMME_DES_VARIATIONS) @@ -238,7 +269,8 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro if (!problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDHydrauliqueModulable) continue; - hydroPowerSmoothingUsingVariationSum.add(pays); + hydroPowerSmoothingUsingVariationSum.add( + pays, problemeHebdo->NombreDePasDeTempsPourUneOptimisation); } } else if (problemeHebdo->TypeDeLissageHydraulique == LISSAGE_HYDRAULIQUE_SUR_VARIATION_MAX) @@ -259,14 +291,17 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro for (uint32_t pays = 0; pays < problemeHebdo->NombreDePays; pays++) { - minHydroPower.add(pays); + minHydroPower.add(pays, GetMinHydroPowerDataFromProblemHebdo(problemeHebdo, pays)); - maxHydroPower.add(pays); + maxHydroPower.add(pays, GetMaxHydroPowerDataFromProblemHebdo(problemeHebdo, pays)); } for (uint32_t pays = 0; pays < problemeHebdo->NombreDePays; pays++) { - maxPumping.add(pays); + MaxPumpingData data + = {problemeHebdo->CaracteristiquesHydrauliques[pays].PresenceDePompageModulable, + problemeHebdo->NumeroDeContrainteMaxPompage}; + maxPumping.add(pays, data); } for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) @@ -287,9 +322,18 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro /* For each area with ad hoc properties, two possible sets of two additional constraints */ for (uint32_t pays = 0; pays < problemeHebdo->NombreDePays; pays++) { - finalStockEquivalent.add(pays); - - finalStockExpression.add(pays); + FinalStockEquivalentData finalStockEquivalentData + = {problemeHebdo->NombreDePasDeTempsPourUneOptimisation - 1, + problemeHebdo->CaracteristiquesHydrauliques[pays].AccurateWaterValue, + problemeHebdo->CaracteristiquesHydrauliques[pays].DirectLevelAccess, + problemeHebdo->NumeroDeContrainteEquivalenceStockFinal}; + finalStockEquivalent.add(pays, finalStockEquivalentData); + FinalStockExpressionData finalStockExpressionData + = {problemeHebdo->NombreDePasDeTempsPourUneOptimisation - 1, + problemeHebdo->CaracteristiquesHydrauliques[pays].AccurateWaterValue, + problemeHebdo->NumeroDeContrainteExpressionStockFinal}; + + finalStockExpression.add(pays, finalStockExpressionData); } if (problemeHebdo->OptimisationAvecCoutsDeDemarrage) From 7af3ab7b925281a29639820edd8d0a96ac5ec8c8 Mon Sep 17 00:00:00 2001 From: abdoulbari zakir <32519851+a-zakir@users.noreply.github.com> Date: Mon, 11 Sep 2023 18:42:24 +0200 Subject: [PATCH 35/43] Mismatch --- .../optimisation/adequacy_patch_csr/csr_quadratic_problem.cpp | 1 + 1 file changed, 1 insertion(+) 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 9273848c5c..6427811dd8 100644 --- a/src/solver/optimisation/adequacy_patch_csr/csr_quadratic_problem.cpp +++ b/src/solver/optimisation/adequacy_patch_csr/csr_quadratic_problem.cpp @@ -86,6 +86,7 @@ class CsrFlowDissociation : private Constraint 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); } From 6ab2a54ea618817a0255a6013abbe91c467e5383 Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Tue, 12 Sep 2023 13:10:29 +0200 Subject: [PATCH 36/43] 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: From b6b77b8a1f9050daa4cdef9415387e08c292deed Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Tue, 12 Sep 2023 15:31:28 +0200 Subject: [PATCH 37/43] build csr_quadratic_problem constraints with the constraint Builder --- .../csr_quadratic_problem.cpp | 255 ++++++++++-------- 1 file changed, 141 insertions(+), 114 deletions(-) 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 ca00b6a93f..803a3cc6aa 100644 --- a/src/solver/optimisation/adequacy_patch_csr/csr_quadratic_problem.cpp +++ b/src/solver/optimisation/adequacy_patch_csr/csr_quadratic_problem.cpp @@ -44,7 +44,7 @@ namespace Antares::Solver::Optimization struct CsrFlowDissociationData { std::map& numberOfConstraintCsrFlowDissociation; - const int NombreDInterconnexions; + const uint32_t NombreDInterconnexions; const std::vector& originAreaMode; const std::vector& extremityAreaMode; @@ -83,7 +83,7 @@ class CsrFlowDissociation : private Constraint const auto& destination = builder.data.NomsDesPays[data.PaysExtremiteDeLInterconnexion[interco]]; namer.CsrFlowDissociation(builder.data.nombreDeContraintes, origin, destination); - + builder.equalTo(); builder.build(); } } @@ -107,173 +107,200 @@ void CsrQuadraticProblem::setConstraintsOnFlows(std::vector& Pi, std::ve csrFlowDissociation.add(hour, csrFlowDissociationData); } - -void CsrQuadraticProblem::setNodeBalanceConstraints(std::vector& Pi, std::vector& Colonne) +struct CsrAreaBalanceData { - int hour = hourlyCsrProblem_.triggeredHour; - const CORRESPONDANCES_DES_VARIABLES& CorrespondanceVarNativesVarOptim - = problemeHebdo_->CorrespondanceVarNativesVarOptim[hour]; + const adqPatchParamsMode& areaMode; + const int hour; + const std::vector& IndexDebutIntercoOrigine; + const std::vector& IndexSuivantIntercoOrigine; + const std::vector& IndexDebutIntercoExtremite; + const std::vector& IndexSuivantIntercoExtremite; - // constraint: - // ENS(node A) + - // - flow (A -> 2) or (+ flow (2 -> A)) there should be only one of them, otherwise double-count - // - spillage(node A) = - // ENS_init(node A) + net_position_init(node A) – spillage_init(node A) - // for all areas inside adequacy patch + const std::vector& originAreaMode; + const std::vector& extremityAreaMode; + const std::vector& PaysOrigineDeLInterconnexion; + const std::vector& PaysExtremiteDeLInterconnexion; + std::map numberOfConstraintCsrAreaBalance; +}; - for (uint32_t Area = 0; Area < problemeHebdo_->NombreDePays; ++Area) +class CsrAreaBalance : private Constraint +{ +public: + using Constraint::Constraint; + void add(uint32_t Area, CsrAreaBalanceData& data) { - if (problemeHebdo_->adequacyPatchRuntimeData->areaMode[Area] - != Data::AdequacyPatch::physicalAreaInsideAdqPatch) - continue; + if (data.areaMode != Data::AdequacyPatch::physicalAreaInsideAdqPatch) + return; // + ENS int NombreDeTermes = 0; - int var = CorrespondanceVarNativesVarOptim.NumeroDeVariableDefaillancePositive[Area]; - if (var >= 0) - { - Pi[NombreDeTermes] = 1.0; - Colonne[NombreDeTermes] = var; - NombreDeTermes++; - } + builder.updateHourWithinWeek(data.hour).include(Variable::NegativeUnsuppliedEnergy(Area), + 1.0); // - export flows - int Interco = problemeHebdo_->IndexDebutIntercoOrigine[Area]; + int Interco = data.IndexDebutIntercoOrigine[Area]; while (Interco >= 0) { - if (problemeHebdo_->adequacyPatchRuntimeData->extremityAreaMode[Interco] - != Data::AdequacyPatch::physicalAreaInsideAdqPatch) + if (data.extremityAreaMode[Interco] != Data::AdequacyPatch::physicalAreaInsideAdqPatch) { - Interco = problemeHebdo_->IndexSuivantIntercoOrigine[Interco]; + Interco = data.IndexSuivantIntercoOrigine[Interco]; continue; } - var = CorrespondanceVarNativesVarOptim - .NumeroDeVariableDeLInterconnexion[Interco]; // flow (A->2) - if (var >= 0) - { - Pi[NombreDeTermes] = -1.0; - Colonne[NombreDeTermes] = var; - NombreDeTermes++; - logs.debug() - << "S-Interco number: [" << std::to_string(Interco) << "] between: [" - << problemeHebdo_->NomsDesPays[Area] << "]-[" - << problemeHebdo_ - ->NomsDesPays[problemeHebdo_->PaysExtremiteDeLInterconnexion[Interco]] - << "]"; - } - Interco = problemeHebdo_->IndexSuivantIntercoOrigine[Interco]; + // flow (A->2) + builder.include(Variable::NTCDirect(Interco), -1.0); + + logs.debug() << "S-Interco number: [" << std::to_string(Interco) << "] between: [" + << builder.data.NomsDesPays[Area] << "]-[" + << builder.data.NomsDesPays[data.PaysExtremiteDeLInterconnexion[Interco]] + << "]"; + + Interco = data.IndexSuivantIntercoOrigine[Interco]; } // or + import flows - Interco = problemeHebdo_->IndexDebutIntercoExtremite[Area]; + Interco = data.IndexDebutIntercoExtremite[Area]; while (Interco >= 0) { - if (problemeHebdo_->adequacyPatchRuntimeData->originAreaMode[Interco] - != Data::AdequacyPatch::physicalAreaInsideAdqPatch) + if (data.originAreaMode[Interco] != Data::AdequacyPatch::physicalAreaInsideAdqPatch) { - Interco = problemeHebdo_->IndexSuivantIntercoExtremite[Interco]; + Interco = data.IndexSuivantIntercoExtremite[Interco]; continue; } - var = CorrespondanceVarNativesVarOptim - .NumeroDeVariableDeLInterconnexion[Interco]; // flow (2 -> A) - if (var >= 0) - { - Pi[NombreDeTermes] = 1.0; - Colonne[NombreDeTermes] = var; - NombreDeTermes++; - logs.debug() - << "E-Interco number: [" << std::to_string(Interco) << "] between: [" - << problemeHebdo_->NomsDesPays[Area] << "]-[" - << problemeHebdo_ - ->NomsDesPays[problemeHebdo_->PaysOrigineDeLInterconnexion[Interco]] - << "]"; - } - Interco = problemeHebdo_->IndexSuivantIntercoExtremite[Interco]; + // flow (2 -> A) + builder.include(Variable::NTCDirect(Interco), 1.0); + + logs.debug() << "E-Interco number: [" << std::to_string(Interco) << "] between: [" + << builder.data.NomsDesPays[Area] << "]-[" + << builder.data.NomsDesPays[data.PaysOrigineDeLInterconnexion[Interco]] + << "]"; + + Interco = data.IndexSuivantIntercoExtremite[Interco]; } // - Spilled Energy - var = CorrespondanceVarNativesVarOptim.NumeroDeVariableDefaillanceNegative[Area]; - if (var >= 0) - { - Pi[NombreDeTermes] = -1.0; - Colonne[NombreDeTermes] = var; - NombreDeTermes++; - } + builder.include(Variable::NegativeUnsuppliedEnergy(Area), -1.0); - hourlyCsrProblem_.numberOfConstraintCsrAreaBalance[Area] - = problemeAResoudre_.NombreDeContraintes; + data.numberOfConstraintCsrAreaBalance[Area] = builder.data.nombreDeContraintes; std::string NomDeLaContrainte - = "Area Balance, Area:" + std::to_string(Area) + "; " + problemeHebdo_->NomsDesPays[Area]; + = "Area Balance, Area:" + std::to_string(Area) + "; " + builder.data.NomsDesPays[Area]; - logs.debug() << "C: " << problemeAResoudre_.NombreDeContraintes << ": " - << NomDeLaContrainte; + logs.debug() << "C: " << builder.data.nombreDeContraintes << ": " << NomDeLaContrainte; + builder.equalTo(); + builder.build(); + } +}; +void CsrQuadraticProblem::setNodeBalanceConstraints(std::vector& Pi, + std::vector& Colonne) +{ + int hour = hourlyCsrProblem_.triggeredHour; + const CORRESPONDANCES_DES_VARIABLES& CorrespondanceVarNativesVarOptim + = problemeHebdo_->CorrespondanceVarNativesVarOptim[hour]; + + // constraint: + // ENS(node A) + + // - flow (A -> 2) or (+ flow (2 -> A)) there should be only one of them, otherwise double-count + // - spillage(node A) = + // ENS_init(node A) + net_position_init(node A) – spillage_init(node A) + // for all areas inside adequacy patch + + ConstraintBuilder builder( + GetConstraintBuilderFromProblemHebdoAndProblemAResoudre(problemeHebdo_, &problemeAResoudre_)); + CsrAreaBalance csrAreaBalance(builder); - OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - &problemeAResoudre_, Pi, Colonne, NombreDeTermes, '='); + for (uint32_t Area = 0; Area < problemeHebdo_->NombreDePays; ++Area) + { + CsrAreaBalanceData csrAreaBalanceData{ + problemeHebdo_->adequacyPatchRuntimeData->areaMode[Area], + hour, + problemeHebdo_->IndexDebutIntercoOrigine, + problemeHebdo_->IndexSuivantIntercoOrigine, + problemeHebdo_->IndexDebutIntercoExtremite, + problemeHebdo_->IndexSuivantIntercoExtremite, + problemeHebdo_->adequacyPatchRuntimeData->originAreaMode, + problemeHebdo_->adequacyPatchRuntimeData->extremityAreaMode, + problemeHebdo_->PaysOrigineDeLInterconnexion, + problemeHebdo_->PaysExtremiteDeLInterconnexion, + hourlyCsrProblem_.numberOfConstraintCsrAreaBalance}; + csrAreaBalance.add(Area, csrAreaBalanceData); } } -void CsrQuadraticProblem::setBindingConstraints(std::vector& Pi, std::vector& Colonne) +struct CsrBindingConstraintHourData { - int hour = hourlyCsrProblem_.triggeredHour; + const CONTRAINTES_COUPLANTES& MatriceDesContraintesCouplantes; - // Special case of the binding constraints - for (uint32_t CntCouplante = 0; CntCouplante < problemeHebdo_->NombreDeContraintesCouplantes; - CntCouplante++) - { - const CONTRAINTES_COUPLANTES& MatriceDesContraintesCouplantes - = problemeHebdo_->MatriceDesContraintesCouplantes[CntCouplante]; + const std::vector& originAreaMode; + const std::vector& extremityAreaMode; + const int hour; - if (MatriceDesContraintesCouplantes.TypeDeContrainteCouplante != CONTRAINTE_HORAIRE) - continue; + std::map& numberOfConstraintCsrHourlyBinding; +}; + +class CsrBindingConstraintHour : private Constraint +{ +public: + using Constraint::Constraint; + void add(int CntCouplante, CsrBindingConstraintHourData& data) + { + if (data.MatriceDesContraintesCouplantes.TypeDeContrainteCouplante != CONTRAINTE_HORAIRE) + return; int NbInterco - = MatriceDesContraintesCouplantes.NombreDInterconnexionsDansLaContrainteCouplante; - int NombreDeTermes = 0; + = data.MatriceDesContraintesCouplantes.NombreDInterconnexionsDansLaContrainteCouplante; + builder.updateHourWithinWeek(data.hour); + for (int Index = 0; Index < NbInterco; Index++) { - int Interco = MatriceDesContraintesCouplantes.NumeroDeLInterconnexion[Index]; - double Poids = MatriceDesContraintesCouplantes.PoidsDeLInterconnexion[Index]; + int Interco = data.MatriceDesContraintesCouplantes.NumeroDeLInterconnexion[Index]; + double Poids = data.MatriceDesContraintesCouplantes.PoidsDeLInterconnexion[Index]; - if (problemeHebdo_->adequacyPatchRuntimeData->originAreaMode[Interco] - == Data::AdequacyPatch::physicalAreaInsideAdqPatch - && problemeHebdo_->adequacyPatchRuntimeData->extremityAreaMode[Interco] + if (data.originAreaMode[Interco] == Data::AdequacyPatch::physicalAreaInsideAdqPatch + && data.extremityAreaMode[Interco] == Data::AdequacyPatch::physicalAreaInsideAdqPatch) { - int var = problemeHebdo_->CorrespondanceVarNativesVarOptim[hour] - .NumeroDeVariableDeLInterconnexion[Interco]; - - if (var >= 0) - { - Pi[NombreDeTermes] = Poids; - Colonne[NombreDeTermes] = var; - NombreDeTermes++; - } + builder.include(Variable::NTCDirect(Interco), Poids); } } - if (NombreDeTermes > 0) // current binding constraint contains an interco type 2<->2 + if (builder.NumberOfVariables() + > 0) // current binding constraint contains an interco type 2<->2 { - hourlyCsrProblem_.numberOfConstraintCsrHourlyBinding[CntCouplante] - = problemeAResoudre_.NombreDeContraintes; + data.numberOfConstraintCsrHourlyBinding[CntCouplante] + = builder.data.nombreDeContraintes; std::string NomDeLaContrainte - = "bc::hourly::" + std::to_string(hour) - + "::" + MatriceDesContraintesCouplantes.NomDeLaContrainteCouplante; + = "bc::hourly::" + std::to_string(data.hour) + + "::" + data.MatriceDesContraintesCouplantes.NomDeLaContrainteCouplante; - logs.debug() << "C (bc): " << problemeAResoudre_.NombreDeContraintes << ": " + logs.debug() << "C (bc): " << builder.data.nombreDeContraintes << ": " << NomDeLaContrainte; - OPT_ChargerLaContrainteDansLaMatriceDesContraintes( - &problemeAResoudre_, - Pi, - Colonne, - NombreDeTermes, - MatriceDesContraintesCouplantes.SensDeLaContrainteCouplante); + char op = data.MatriceDesContraintesCouplantes.SensDeLaContrainteCouplante; + builder.operatorRHS(op); + builder.build(); } } +}; +void CsrQuadraticProblem::setBindingConstraints(std::vector& Pi, std::vector& Colonne) +{ + int hour = hourlyCsrProblem_.triggeredHour; + ConstraintBuilder builder( + GetConstraintBuilderFromProblemHebdoAndProblemAResoudre(problemeHebdo_, &problemeAResoudre_)); + // Special case of the binding constraints + for (uint32_t CntCouplante = 0; CntCouplante < problemeHebdo_->NombreDeContraintesCouplantes; + CntCouplante++) + { + CsrBindingConstraintHourData csrBindingConstraintHourData + = {problemeHebdo_->MatriceDesContraintesCouplantes[CntCouplante], + problemeHebdo_->adequacyPatchRuntimeData->originAreaMode, + problemeHebdo_->adequacyPatchRuntimeData->extremityAreaMode, + hour, + hourlyCsrProblem_.numberOfConstraintCsrHourlyBinding}; + CsrBindingConstraintHour csrBindingConstraintHour(builder); + csrBindingConstraintHour.add(CntCouplante, csrBindingConstraintHourData); + } } void CsrQuadraticProblem::buildConstraintMatrix() From 46a6b960bb5905ff4d8f11e87bb0607d058bf065 Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Tue, 12 Sep 2023 15:48:19 +0200 Subject: [PATCH 38/43] update flowDissociation --- src/solver/optimisation/FlowDissociation.cpp | 21 +++++++------------ src/solver/optimisation/FlowDissociation.h | 11 ++++++++-- ...n_matrice_des_contraintes_cas_lineaire.cpp | 11 ++++++---- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/solver/optimisation/FlowDissociation.cpp b/src/solver/optimisation/FlowDissociation.cpp index f4c52bf5d4..99ce6892ef 100644 --- a/src/solver/optimisation/FlowDissociation.cpp +++ b/src/solver/optimisation/FlowDissociation.cpp @@ -1,25 +1,20 @@ #include "FlowDissociation.h" -void FlowDissociation::add(int pdt, - int interco, - std::vector& NumeroDeContrainteDeDissociationDeFlux) +void FlowDissociation::add(int pdt, int interco, FlowDissociationData& data) { - if (const COUTS_DE_TRANSPORT& CoutDeTransport = problemeHebdo->CoutDeTransport[interco]; + if (const COUTS_DE_TRANSPORT& CoutDeTransport = data.CoutDeTransport[interco]; CoutDeTransport.IntercoGereeAvecDesCouts) { // TODO improve this - NumeroDeContrainteDeDissociationDeFlux[interco] - = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; + data.NumeroDeContrainteDeDissociationDeFlux[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]]; - ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, - problemeHebdo->NamedProblems); - namer.UpdateTimeStep(problemeHebdo->weekInTheYear * 168 + pdt); - namer.FlowDissociation( - problemeHebdo->ProblemeAResoudre->NombreDeContraintes, origin, destination); + = builder.data.NomsDesPays[data.PaysExtremiteDeLInterconnexion[interco]]; + ConstraintNamer namer(builder.data.NomDesContraintes, builder.data.NamedProblems); + namer.UpdateTimeStep(builder.data.weekInTheYear * 168 + pdt); + namer.FlowDissociation(builder.data.nombreDeContraintes, origin, destination); } builder.updateHourWithinWeek(pdt); diff --git a/src/solver/optimisation/FlowDissociation.h b/src/solver/optimisation/FlowDissociation.h index f4dc7c0474..d8cb1ad806 100644 --- a/src/solver/optimisation/FlowDissociation.h +++ b/src/solver/optimisation/FlowDissociation.h @@ -1,10 +1,17 @@ #pragma once #include "constraint_builder.h" +struct FlowDissociationData +{ + std::vector& NumeroDeContrainteDeDissociationDeFlux; + const std::vector& CoutDeTransport; + const std::vector& PaysOrigineDeLInterconnexion; + const std::vector& PaysExtremiteDeLInterconnexion; +}; + class FlowDissociation : private Constraint { public: using Constraint::Constraint; - void add(int pdt, int interco, - std::vector& NumeroDeContrainteDeDissociationDeFlux); + void add(int pdt, int interco, FlowDissociationData& data); }; 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 b2560940b5..fa66b08d1d 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 @@ -235,10 +235,13 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro { CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim = problemeHebdo->CorrespondanceCntNativesCntOptim[pdt]; - flowDissociation.add( - pdt, - interco, - CorrespondanceCntNativesCntOptim.NumeroDeContrainteDeDissociationDeFlux); + FlowDissociationData flowDissociationData + = {CorrespondanceCntNativesCntOptim.NumeroDeContrainteDeDissociationDeFlux, + problemeHebdo->CoutDeTransport, + problemeHebdo->PaysOrigineDeLInterconnexion, + problemeHebdo->PaysExtremiteDeLInterconnexion}; + + flowDissociation.add(pdt, interco, flowDissociationData); } for (uint32_t cntCouplante = 0; cntCouplante < problemeHebdo->NombreDeContraintesCouplantes; cntCouplante++) From 1df8de9bc6283134b740567b3247fa184168325f Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Tue, 12 Sep 2023 16:37:19 +0200 Subject: [PATCH 39/43] big update --- src/solver/optimisation/AreaHydroLevel.cpp | 23 +++++------- src/solver/optimisation/AreaHydroLevel.h | 9 ++++- .../optimisation/BindingConstraintDay.cpp | 37 ++++++++----------- .../optimisation/BindingConstraintDay.h | 4 ++ .../optimisation/BindingConstraintHour.cpp | 28 +++++++------- .../optimisation/BindingConstraintWeek.cpp | 33 ++++++++--------- .../optimisation/FinalStockEquivalent.cpp | 24 ++++++------ .../optimisation/FinalStockExpression.cpp | 12 +++--- src/solver/optimisation/HydroPower.cpp | 17 ++++----- ...droPowerSmoothingUsingVariationMaxDown.cpp | 10 ++--- ...HydroPowerSmoothingUsingVariationMaxUp.cpp | 10 ++--- .../HydroPowerSmoothingUsingVariationSum.cpp | 10 ++--- src/solver/optimisation/MaxHydroPower.cpp | 17 ++++----- src/solver/optimisation/MaxPumping.cpp | 17 ++++----- src/solver/optimisation/MinHydroPower.cpp | 15 +++----- src/solver/optimisation/constraint_builder.h | 7 +++- ...n_matrice_des_contraintes_cas_lineaire.cpp | 16 +++++--- 17 files changed, 137 insertions(+), 152 deletions(-) diff --git a/src/solver/optimisation/AreaHydroLevel.cpp b/src/solver/optimisation/AreaHydroLevel.cpp index f3fa15143b..01ead98485 100644 --- a/src/solver/optimisation/AreaHydroLevel.cpp +++ b/src/solver/optimisation/AreaHydroLevel.cpp @@ -1,31 +1,28 @@ #include "AreaHydroLevel.h" -void AreaHydroLevel::add(int pays, int pdt, std::vector& NumeroDeContrainteDesNiveauxPays) +void AreaHydroLevel::add(int pays, int pdt, AreaHydroLevelData& data) { - NumeroDeContrainteDesNiveauxPays[pays] = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; - if (problemeHebdo->CaracteristiquesHydrauliques[pays].SuiviNiveauHoraire) + data.NumeroDeContrainteDesNiveauxPays[pays] = builder.data.nombreDeContraintes; + if (data.SuiviNiveauHoraire) { builder.updateHourWithinWeek(pdt).include(Variable::HydroLevel(pays), 1.0); if (pdt > 0) { builder.updateHourWithinWeek(pdt - 1).include(Variable::HydroLevel(pays), -1.0); } - ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, - problemeHebdo->NamedProblems); + ConstraintNamer namer(builder.data.NomDesContraintes, builder.data.NamedProblems); - namer.UpdateArea(problemeHebdo->NomsDesPays[pays]); - namer.UpdateTimeStep(problemeHebdo->weekInTheYear * 168 + pdt); - namer.AreaHydroLevel(problemeHebdo->ProblemeAResoudre->NombreDeContraintes); - NumeroDeContrainteDesNiveauxPays[pays] - = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; + namer.UpdateArea(builder.data.NomsDesPays[pays]); + namer.UpdateTimeStep(builder.data.weekInTheYear * 168 + pdt); + namer.AreaHydroLevel(builder.data.nombreDeContraintes); + data.NumeroDeContrainteDesNiveauxPays[pays] = builder.data.nombreDeContraintes; builder.updateHourWithinWeek(pdt) .include(Variable::HydProd(pays), 1.0) - .include(Variable::Pumping(pays), - -problemeHebdo->CaracteristiquesHydrauliques[pays].PumpingRatio) + .include(Variable::Pumping(pays), -data.PumpingRatio) .include(Variable::Overflow(pays), 1.) .equalTo() .build(); } else - NumeroDeContrainteDesNiveauxPays[pays] = -1; + data.NumeroDeContrainteDesNiveauxPays[pays] = -1; } \ No newline at end of file diff --git a/src/solver/optimisation/AreaHydroLevel.h b/src/solver/optimisation/AreaHydroLevel.h index 7a0c118bf5..b075ece1b8 100644 --- a/src/solver/optimisation/AreaHydroLevel.h +++ b/src/solver/optimisation/AreaHydroLevel.h @@ -1,9 +1,16 @@ #pragma once #include "constraint_builder.h" +struct AreaHydroLevelData +{ + std::vector& NumeroDeContrainteDesNiveauxPays; + const bool SuiviNiveauHoraire; + const double PumpingRatio; +}; + class AreaHydroLevel : private Constraint { public: using Constraint::Constraint; - void add(int pays, int pdt, std::vector& NumeroDeContrainteDesNiveauxPays); + void add(int pays, int pdt, AreaHydroLevelData& data); }; \ No newline at end of file diff --git a/src/solver/optimisation/BindingConstraintDay.cpp b/src/solver/optimisation/BindingConstraintDay.cpp index fa8f584428..8916041274 100644 --- a/src/solver/optimisation/BindingConstraintDay.cpp +++ b/src/solver/optimisation/BindingConstraintDay.cpp @@ -9,12 +9,12 @@ void BindingConstraintDay::add(int cntCouplante, BindingConstraintDayData& data) const int nbClusters = data.NombreDePaliersDispatchDansLaContrainteCouplante; const int NombreDePasDeTempsPourUneOptimisation - = problemeHebdo->NombreDePasDeTempsPourUneOptimisation; // TODO - const int NombreDePasDeTempsDUneJournee = problemeHebdo->NombreDePasDeTempsDUneJournee; + = builder.data.NombreDePasDeTempsPourUneOptimisation; // TODO + const int NombreDePasDeTempsDUneJournee = data.NombreDePasDeTempsDUneJournee; int pdtDebut = 0; while (pdtDebut < NombreDePasDeTempsPourUneOptimisation) { - int jour = problemeHebdo->NumeroDeJourDuPasDeTemps[pdtDebut]; + int jour = data.NumeroDeJourDuPasDeTemps[pdtDebut]; auto& CorrespondanceCntNativesCntOptimJournalieres = data.CorrespondanceCntNativesCntOptimJournalieres[jour]; @@ -29,23 +29,22 @@ void BindingConstraintDay::add(int cntCouplante, BindingConstraintDayData& data) int pdt1; if (offset >= 0) { - pdt1 = (pdt + offset) % problemeHebdo->NombreDePasDeTempsPourUneOptimisation; + pdt1 = (pdt + offset) % builder.data.NombreDePasDeTempsPourUneOptimisation; } else { - pdt1 = (pdt + offset + problemeHebdo->NombreDePasDeTemps) - % problemeHebdo->NombreDePasDeTempsPourUneOptimisation; + pdt1 = (pdt + offset + builder.data.NombreDePasDeTemps) + % builder.data.NombreDePasDeTempsPourUneOptimisation; } builder.updateHourWithinWeek(pdt1).include( - Variable::NTCDirect(interco), poids, 0, false, problemeHebdo->NombreDePasDeTemps); + Variable::NTCDirect(interco), poids, 0, false, builder.data.NombreDePasDeTemps); } } for (int index = 0; index < nbClusters; index++) { int pays = data.PaysDuPalierDispatch[index]; - const PALIERS_THERMIQUES& PaliersThermiquesDuPays - = problemeHebdo->PaliersThermiquesDuPays[pays]; + const PALIERS_THERMIQUES& PaliersThermiquesDuPays = data.PaliersThermiquesDuPays[pays]; const int palier = PaliersThermiquesDuPays.NumeroDuPalierDansLEnsembleDesPaliersThermiques [data.NumeroDuPalierDispatch[index]]; @@ -57,39 +56,35 @@ void BindingConstraintDay::add(int cntCouplante, BindingConstraintDayData& data) int pdt1; if (offset >= 0) { - pdt1 = (pdt + offset) % problemeHebdo->NombreDePasDeTempsPourUneOptimisation; + pdt1 = (pdt + offset) % builder.data.NombreDePasDeTempsPourUneOptimisation; } else { - pdt1 = (pdt + offset + problemeHebdo->NombreDePasDeTemps) - % problemeHebdo->NombreDePasDeTempsPourUneOptimisation; + pdt1 = (pdt + offset + builder.data.NombreDePasDeTemps) + % builder.data.NombreDePasDeTempsPourUneOptimisation; } builder.updateHourWithinWeek(pdt1).include(Variable::DispatchableProduction(palier), poids, 0, false, - problemeHebdo->NombreDePasDeTemps); + builder.data.NombreDePasDeTemps); } } CorrespondanceCntNativesCntOptimJournalieres .NumeroDeContrainteDesContraintesCouplantes[cntCouplante] - = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; - - std::vector& AdresseOuPlacerLaValeurDesCoutsMarginaux - = problemeHebdo->ProblemeAResoudre->AdresseOuPlacerLaValeurDesCoutsMarginaux; + = builder.data.nombreDeContraintes; char op = data.SensDeLaContrainteCouplante; builder.operatorRHS(op); { - ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, - problemeHebdo->NamedProblems); + ConstraintNamer namer(builder.data.NomDesContraintes, builder.data.NamedProblems); namer.UpdateTimeStep(jour); - namer.BindingConstraintDay(problemeHebdo->ProblemeAResoudre->NombreDeContraintes, + namer.BindingConstraintDay(builder.data.nombreDeContraintes, data.NomDeLaContrainteCouplante); } builder.build(); - pdtDebut += problemeHebdo->NombreDePasDeTempsDUneJournee; + pdtDebut += data.NombreDePasDeTempsDUneJournee; } } diff --git a/src/solver/optimisation/BindingConstraintDay.h b/src/solver/optimisation/BindingConstraintDay.h index 39a507c872..1c82d6b513 100644 --- a/src/solver/optimisation/BindingConstraintDay.h +++ b/src/solver/optimisation/BindingConstraintDay.h @@ -6,6 +6,10 @@ struct BindingConstraintDayData : public BindingConstraintData // std::vector&>& CorrespondanceCntNativesCntOptimJournalieres; std::vector& CorrespondanceCntNativesCntOptimJournalieres; + + const int32_t NombreDePasDeTempsDUneJournee; + + std::vector& NumeroDeJourDuPasDeTemps; }; class BindingConstraintDay : private Constraint { diff --git a/src/solver/optimisation/BindingConstraintHour.cpp b/src/solver/optimisation/BindingConstraintHour.cpp index 1428fb198f..65e4f61fc5 100644 --- a/src/solver/optimisation/BindingConstraintHour.cpp +++ b/src/solver/optimisation/BindingConstraintHour.cpp @@ -3,7 +3,7 @@ void BindingConstraintHour::add(int pdt, int cntCouplante, BindingConstraintHourData& data) { data.NumeroDeContrainteDesContraintesCouplantes[cntCouplante] - = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; + = builder.data.nombreDeContraintes; if (data.TypeDeContrainteCouplante != CONTRAINTE_HORAIRE) return; @@ -19,16 +19,16 @@ void BindingConstraintHour::add(int pdt, int cntCouplante, BindingConstraintHour int pdt1; if (offset >= 0) { - pdt1 = (pdt + offset) % problemeHebdo->NombreDePasDeTempsPourUneOptimisation; + pdt1 = (pdt + offset) % builder.data.NombreDePasDeTempsPourUneOptimisation; } else { - pdt1 = (pdt + offset + problemeHebdo->NombreDePasDeTemps) - % problemeHebdo->NombreDePasDeTempsPourUneOptimisation; + pdt1 = (pdt + offset + builder.data.NombreDePasDeTemps) + % builder.data.NombreDePasDeTempsPourUneOptimisation; } builder.updateHourWithinWeek(pdt1).include( - Variable::NTCDirect(interco), poids, 0, false, problemeHebdo->NombreDePasDeTemps); + Variable::NTCDirect(interco), poids, 0, false, builder.data.NombreDePasDeTemps); } // Thermal clusters @@ -36,8 +36,7 @@ void BindingConstraintHour::add(int pdt, int cntCouplante, BindingConstraintHour for (int index = 0; index < nbClusters; index++) { const int pays = data.PaysDuPalierDispatch[index]; - const PALIERS_THERMIQUES& PaliersThermiquesDuPays - = problemeHebdo->PaliersThermiquesDuPays[pays]; + const PALIERS_THERMIQUES& PaliersThermiquesDuPays = data.PaliersThermiquesDuPays[pays]; const int palier = PaliersThermiquesDuPays .NumeroDuPalierDansLEnsembleDesPaliersThermiques[data.NumeroDuPalierDispatch[index]]; @@ -47,28 +46,27 @@ void BindingConstraintHour::add(int pdt, int cntCouplante, BindingConstraintHour if (offset >= 0) { - pdt1 = (pdt + offset) % problemeHebdo->NombreDePasDeTempsPourUneOptimisation; + pdt1 = (pdt + offset) % builder.data.NombreDePasDeTempsPourUneOptimisation; } else { - pdt1 = (pdt + offset + problemeHebdo->NombreDePasDeTemps) - % problemeHebdo->NombreDePasDeTempsPourUneOptimisation; + pdt1 = (pdt + offset + builder.data.NombreDePasDeTemps) + % builder.data.NombreDePasDeTempsPourUneOptimisation; } builder.updateHourWithinWeek(pdt1).include(Variable::DispatchableProduction(palier), poids, 0, false, - problemeHebdo->NombreDePasDeTemps); + builder.data.NombreDePasDeTemps); } char op = data.SensDeLaContrainteCouplante; builder.operatorRHS(op); { - ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, - problemeHebdo->NamedProblems); - namer.UpdateTimeStep(problemeHebdo->weekInTheYear * 168 + pdt); - namer.BindingConstraintHour(problemeHebdo->ProblemeAResoudre->NombreDeContraintes, + ConstraintNamer namer(builder.data.NomDesContraintes, builder.data.NamedProblems); + namer.UpdateTimeStep(builder.data.weekInTheYear * 168 + pdt); + namer.BindingConstraintHour(builder.data.nombreDeContraintes, data.NomDeLaContrainteCouplante); } builder.build(); diff --git a/src/solver/optimisation/BindingConstraintWeek.cpp b/src/solver/optimisation/BindingConstraintWeek.cpp index 5c8ea61444..128387b415 100644 --- a/src/solver/optimisation/BindingConstraintWeek.cpp +++ b/src/solver/optimisation/BindingConstraintWeek.cpp @@ -2,7 +2,7 @@ void BindingConstraintWeek::add(int cntCouplante, BindingConstraintWeekData& data) { - int semaine = problemeHebdo->weekInTheYear; + int semaine = builder.data.weekInTheYear; auto& NumeroDeContrainteDesContraintesCouplantes = data.NumeroDeContrainteDesContraintesCouplantes; if (data.TypeDeContrainteCouplante != CONTRAINTE_HEBDOMADAIRE) @@ -16,68 +16,65 @@ void BindingConstraintWeek::add(int cntCouplante, BindingConstraintWeekData& dat int interco = data.NumeroDeLInterconnexion[index]; double poids = data.PoidsDeLInterconnexion[index]; int offset = data.OffsetTemporelSurLInterco[index]; - for (int pdt = 0; pdt < problemeHebdo->NombreDePasDeTempsPourUneOptimisation; pdt++) + for (int pdt = 0; pdt < builder.data.NombreDePasDeTempsPourUneOptimisation; pdt++) { builder.updateHourWithinWeek(pdt); int pdt1; if (offset >= 0) { - pdt1 = (pdt + offset) % problemeHebdo->NombreDePasDeTempsPourUneOptimisation; + pdt1 = (pdt + offset) % builder.data.NombreDePasDeTempsPourUneOptimisation; } else { - pdt1 = (pdt + offset + problemeHebdo->NombreDePasDeTemps) - % problemeHebdo->NombreDePasDeTempsPourUneOptimisation; + pdt1 = (pdt + offset + builder.data.NombreDePasDeTemps) + % builder.data.NombreDePasDeTempsPourUneOptimisation; } builder.updateHourWithinWeek(pdt1).include( - Variable::NTCDirect(interco), poids, 0, false, problemeHebdo->NombreDePasDeTemps); + Variable::NTCDirect(interco), poids, 0, false, builder.data.NombreDePasDeTemps); } } for (int index = 0; index < nbClusters; index++) { int pays = data.PaysDuPalierDispatch[index]; - const PALIERS_THERMIQUES& PaliersThermiquesDuPays - = problemeHebdo->PaliersThermiquesDuPays[pays]; + const PALIERS_THERMIQUES& PaliersThermiquesDuPays = data.PaliersThermiquesDuPays[pays]; const int palier = PaliersThermiquesDuPays .NumeroDuPalierDansLEnsembleDesPaliersThermiques[data.NumeroDuPalierDispatch[index]]; double poids = data.PoidsDuPalierDispatch[index]; int offset = data.OffsetTemporelSurLePalierDispatch[index]; - for (int pdt = 0; pdt < problemeHebdo->NombreDePasDeTempsPourUneOptimisation; pdt++) + for (int pdt = 0; pdt < builder.data.NombreDePasDeTempsPourUneOptimisation; pdt++) { int pdt1; builder.updateHourWithinWeek(pdt); // useless? if (offset >= 0) { - pdt1 = (pdt + offset) % problemeHebdo->NombreDePasDeTempsPourUneOptimisation; + pdt1 = (pdt + offset) % builder.data.NombreDePasDeTempsPourUneOptimisation; } else { - pdt1 = (pdt + offset + problemeHebdo->NombreDePasDeTemps) - % problemeHebdo->NombreDePasDeTempsPourUneOptimisation; + pdt1 = (pdt + offset + builder.data.NombreDePasDeTemps) + % builder.data.NombreDePasDeTempsPourUneOptimisation; } builder.updateHourWithinWeek(pdt1).include(Variable::DispatchableProduction(palier), poids, offset, false, - problemeHebdo->NombreDePasDeTemps); + builder.data.NombreDePasDeTemps); } } char op = data.SensDeLaContrainteCouplante; builder.operatorRHS(op); - NumeroDeContrainteDesContraintesCouplantes[cntCouplante] - = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; + NumeroDeContrainteDesContraintesCouplantes[cntCouplante] = builder.data.nombreDeContraintes; // Name { - ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, - problemeHebdo->NamedProblems); + ConstraintNamer namer(builder.data.NomDesContraintes, builder.data.NamedProblems); namer.UpdateTimeStep(semaine); - namer.BindingConstraintWeek(problemeHebdo->ProblemeAResoudre->NombreDeContraintes, + namer.BindingConstraintWeek(builder.data.nombreDeContraintes, data.NomDeLaContrainteCouplante); } builder.build(); diff --git a/src/solver/optimisation/FinalStockEquivalent.cpp b/src/solver/optimisation/FinalStockEquivalent.cpp index a04e6ae593..28fef46c81 100644 --- a/src/solver/optimisation/FinalStockEquivalent.cpp +++ b/src/solver/optimisation/FinalStockEquivalent.cpp @@ -6,20 +6,18 @@ void FinalStockEquivalent::add(int pays, FinalStockEquivalentData& data) if (data.AccurateWaterValue && data.DirectLevelAccess) { /* equivalence constraint : StockFinal- Niveau[T]= 0*/ - data.NumeroDeContrainteEquivalenceStockFinal[pays] - = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; - ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, - problemeHebdo->NamedProblems); + data.NumeroDeContrainteEquivalenceStockFinal[pays] = builder.data.nombreDeContraintes; + ConstraintNamer namer(builder.data.NomDesContraintes, builder.data.NamedProblems); - namer.UpdateArea(problemeHebdo->NomsDesPays[pays]); - namer.UpdateTimeStep(problemeHebdo->weekInTheYear * 168 + pdt); - namer.FinalStockEquivalent(problemeHebdo->ProblemeAResoudre->NombreDeContraintes); + namer.UpdateArea(builder.data.NomsDesPays[pays]); + namer.UpdateTimeStep(builder.data.weekInTheYear * 168 + pdt); + namer.FinalStockEquivalent(builder.data.nombreDeContraintes); - builder.updateHourWithinWeek(pdt) - .include(Variable::FinalStorage(pays), 1.0) - .updateHourWithinWeek(problemeHebdo->NombreDePasDeTempsPourUneOptimisation - 1) - .include(Variable::HydroLevel(pays), -1.0) - .equalTo() - .build(); + builder.updateHourWithinWeek(pdt) + .include(Variable::FinalStorage(pays), 1.0) + .updateHourWithinWeek(builder.data.NombreDePasDeTempsPourUneOptimisation - 1) + .include(Variable::HydroLevel(pays), -1.0) + .equalTo() + .build(); } } diff --git a/src/solver/optimisation/FinalStockExpression.cpp b/src/solver/optimisation/FinalStockExpression.cpp index 112b1e9657..18bba99030 100644 --- a/src/solver/optimisation/FinalStockExpression.cpp +++ b/src/solver/optimisation/FinalStockExpression.cpp @@ -12,15 +12,13 @@ void FinalStockExpression::add(int pays, FinalStockExpressionData& data) { builder.include(Variable::LayerStorage(pays, layerindex), 1.0); } - data.NumeroDeContrainteExpressionStockFinal[pays] - = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; + data.NumeroDeContrainteExpressionStockFinal[pays] = builder.data.nombreDeContraintes; - ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, - problemeHebdo->NamedProblems); + ConstraintNamer namer(builder.data.NomDesContraintes, builder.data.NamedProblems); - namer.UpdateArea(problemeHebdo->NomsDesPays[pays]); - namer.UpdateTimeStep(problemeHebdo->weekInTheYear * 168 + pdt); - namer.FinalStockExpression(problemeHebdo->ProblemeAResoudre->NombreDeContraintes); + namer.UpdateArea(builder.data.NomsDesPays[pays]); + namer.UpdateTimeStep(builder.data.weekInTheYear * 168 + pdt); + namer.FinalStockExpression(builder.data.nombreDeContraintes); builder.equalTo().build(); } } diff --git a/src/solver/optimisation/HydroPower.cpp b/src/solver/optimisation/HydroPower.cpp index 6b6bcfc738..e829263d2c 100644 --- a/src/solver/optimisation/HydroPower.cpp +++ b/src/solver/optimisation/HydroPower.cpp @@ -6,13 +6,12 @@ void HydroPower::add(int pays, HydroPowerData& data) bool TurbEntreBornes = data.TurbEntreBornes; const int NombreDePasDeTempsPourUneOptimisation - = problemeHebdo->NombreDePasDeTempsPourUneOptimisation; + = builder.data.NombreDePasDeTempsPourUneOptimisation; if (presenceHydro && !TurbEntreBornes) { if (data.presencePompage) { - data.NumeroDeContrainteEnergieHydraulique[pays] - = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; + data.NumeroDeContrainteEnergieHydraulique[pays] = builder.data.nombreDeContraintes; const double pumpingRatio = data.pumpingRatio; for (int pdt = 0; pdt < NombreDePasDeTempsPourUneOptimisation; pdt++) @@ -30,16 +29,14 @@ void HydroPower::add(int pays, HydroPowerData& data) builder.include(Variable::HydProd(pays), 1.0); } } - data.NumeroDeContrainteEnergieHydraulique[pays] - = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; + data.NumeroDeContrainteEnergieHydraulique[pays] = builder.data.nombreDeContraintes; builder.equalTo(); { - ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, - problemeHebdo->NamedProblems); - namer.UpdateArea(problemeHebdo->NomsDesPays[pays]); - namer.UpdateTimeStep(problemeHebdo->weekInTheYear); - namer.HydroPower(problemeHebdo->ProblemeAResoudre->NombreDeContraintes); + ConstraintNamer namer(builder.data.NomDesContraintes, builder.data.NamedProblems); + namer.UpdateArea(builder.data.NomsDesPays[pays]); + namer.UpdateTimeStep(builder.data.weekInTheYear); + namer.HydroPower(builder.data.nombreDeContraintes); } builder.build(); } diff --git a/src/solver/optimisation/HydroPowerSmoothingUsingVariationMaxDown.cpp b/src/solver/optimisation/HydroPowerSmoothingUsingVariationMaxDown.cpp index f58d9fd401..faee7e34f4 100644 --- a/src/solver/optimisation/HydroPowerSmoothingUsingVariationMaxDown.cpp +++ b/src/solver/optimisation/HydroPowerSmoothingUsingVariationMaxDown.cpp @@ -7,12 +7,10 @@ void HydroPowerSmoothingUsingVariationMaxDown::add(int pays, int pdt) // return; // } - ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, - problemeHebdo->NamedProblems); - namer.UpdateArea(problemeHebdo->NomsDesPays[pays]); - namer.UpdateTimeStep(problemeHebdo->weekInTheYear * 168 + pdt); - namer.HydroPowerSmoothingUsingVariationMaxDown( - problemeHebdo->ProblemeAResoudre->NombreDeContraintes); + ConstraintNamer namer(builder.data.NomDesContraintes, builder.data.NamedProblems); + namer.UpdateArea(builder.data.NomsDesPays[pays]); + namer.UpdateTimeStep(builder.data.weekInTheYear * 168 + pdt); + namer.HydroPowerSmoothingUsingVariationMaxDown(builder.data.nombreDeContraintes); builder.updateHourWithinWeek(pdt) .include(Variable::HydProd(pays), 1.0) diff --git a/src/solver/optimisation/HydroPowerSmoothingUsingVariationMaxUp.cpp b/src/solver/optimisation/HydroPowerSmoothingUsingVariationMaxUp.cpp index 4ef9ab4a01..df3e6e3520 100644 --- a/src/solver/optimisation/HydroPowerSmoothingUsingVariationMaxUp.cpp +++ b/src/solver/optimisation/HydroPowerSmoothingUsingVariationMaxUp.cpp @@ -7,12 +7,10 @@ void HydroPowerSmoothingUsingVariationMaxUp::add(int pays, int pdt) // return; // } - ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, - problemeHebdo->NamedProblems); - namer.UpdateArea(problemeHebdo->NomsDesPays[pays]); - namer.UpdateTimeStep(problemeHebdo->weekInTheYear * 168 + pdt); - namer.HydroPowerSmoothingUsingVariationMaxUp( - problemeHebdo->ProblemeAResoudre->NombreDeContraintes); + ConstraintNamer namer(builder.data.NomDesContraintes, builder.data.NamedProblems); + namer.UpdateArea(builder.data.NomsDesPays[pays]); + namer.UpdateTimeStep(builder.data.weekInTheYear * 168 + pdt); + namer.HydroPowerSmoothingUsingVariationMaxUp(builder.data.nombreDeContraintes); builder.updateHourWithinWeek(pdt) .include(Variable::HydProd(pays), 1.0) diff --git a/src/solver/optimisation/HydroPowerSmoothingUsingVariationSum.cpp b/src/solver/optimisation/HydroPowerSmoothingUsingVariationSum.cpp index 21d6022655..827c3d3cbe 100644 --- a/src/solver/optimisation/HydroPowerSmoothingUsingVariationSum.cpp +++ b/src/solver/optimisation/HydroPowerSmoothingUsingVariationSum.cpp @@ -13,12 +13,10 @@ void HydroPowerSmoothingUsingVariationSum::add(int pays, int pdt1 = pdt + 1; if (pdt1 >= nombreDePasDeTempsPourUneOptimisation) pdt1 = 0; - ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, - problemeHebdo->NamedProblems); - namer.UpdateArea(problemeHebdo->NomsDesPays[pays]); - namer.UpdateTimeStep(problemeHebdo->weekInTheYear * 168 + pdt); - namer.HydroPowerSmoothingUsingVariationSum( - problemeHebdo->ProblemeAResoudre->NombreDeContraintes); + ConstraintNamer namer(builder.data.NomDesContraintes, builder.data.NamedProblems); + namer.UpdateArea(builder.data.NomsDesPays[pays]); + namer.UpdateTimeStep(builder.data.weekInTheYear * 168 + pdt); + namer.HydroPowerSmoothingUsingVariationSum(builder.data.nombreDeContraintes); builder.updateHourWithinWeek(pdt) .include(Variable::HydProd(pays), 1.0) diff --git a/src/solver/optimisation/MaxHydroPower.cpp b/src/solver/optimisation/MaxHydroPower.cpp index 51d7984aff..eea3435038 100644 --- a/src/solver/optimisation/MaxHydroPower.cpp +++ b/src/solver/optimisation/MaxHydroPower.cpp @@ -6,25 +6,22 @@ void MaxHydroPower::add(int pays, MaxHydroPowerData& data) bool TurbEntreBornes = data.TurbEntreBornes; if (presenceHydro && (TurbEntreBornes || data.PresenceDePompageModulable)) { - data.NumeroDeContrainteMaxEnergieHydraulique[pays] - = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; + data.NumeroDeContrainteMaxEnergieHydraulique[pays] = builder.data.nombreDeContraintes; const int NombreDePasDeTempsPourUneOptimisation - = problemeHebdo->NombreDePasDeTempsPourUneOptimisation; + = builder.data.NombreDePasDeTempsPourUneOptimisation; for (int pdt = 0; pdt < NombreDePasDeTempsPourUneOptimisation; pdt++) { builder.updateHourWithinWeek(pdt); builder.include(Variable::HydProd(pays), 1.0); } - data.NumeroDeContrainteMaxEnergieHydraulique[pays] - = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; + data.NumeroDeContrainteMaxEnergieHydraulique[pays] = builder.data.nombreDeContraintes; - ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, - problemeHebdo->NamedProblems); - namer.UpdateArea(problemeHebdo->NomsDesPays[pays]); - namer.UpdateTimeStep(problemeHebdo->weekInTheYear); - namer.MaxHydroPower(problemeHebdo->ProblemeAResoudre->NombreDeContraintes); + ConstraintNamer namer(builder.data.NomDesContraintes, builder.data.NamedProblems); + namer.UpdateArea(builder.data.NomsDesPays[pays]); + namer.UpdateTimeStep(builder.data.weekInTheYear); + namer.MaxHydroPower(builder.data.nombreDeContraintes); builder.lessThan().build(); } diff --git a/src/solver/optimisation/MaxPumping.cpp b/src/solver/optimisation/MaxPumping.cpp index 568383c174..7ee3cbd439 100644 --- a/src/solver/optimisation/MaxPumping.cpp +++ b/src/solver/optimisation/MaxPumping.cpp @@ -4,24 +4,21 @@ void MaxPumping::add(int pays, MaxPumpingData& data) { if (data.PresenceDePompageModulable) { - data.NumeroDeContrainteMaxPompage[pays] - = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; + data.NumeroDeContrainteMaxPompage[pays] = builder.data.nombreDeContraintes; const int NombreDePasDeTempsPourUneOptimisation - = problemeHebdo->NombreDePasDeTempsPourUneOptimisation; + = builder.data.NombreDePasDeTempsPourUneOptimisation; for (int pdt = 0; pdt < NombreDePasDeTempsPourUneOptimisation; pdt++) { builder.updateHourWithinWeek(pdt); builder.include(Variable::Pumping(pays), 1.0); } - data.NumeroDeContrainteMaxPompage[pays] - = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; - ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, - problemeHebdo->NamedProblems); - namer.UpdateArea(problemeHebdo->NomsDesPays[pays]); - namer.UpdateTimeStep(problemeHebdo->weekInTheYear); - namer.MaxPumping(problemeHebdo->ProblemeAResoudre->NombreDeContraintes); + data.NumeroDeContrainteMaxPompage[pays] = builder.data.nombreDeContraintes; + ConstraintNamer namer(builder.data.NomDesContraintes, builder.data.NamedProblems); + namer.UpdateArea(builder.data.NomsDesPays[pays]); + namer.UpdateTimeStep(builder.data.weekInTheYear); + namer.MaxPumping(builder.data.nombreDeContraintes); builder.lessThan().build(); } else diff --git a/src/solver/optimisation/MinHydroPower.cpp b/src/solver/optimisation/MinHydroPower.cpp index a6f3b0f89a..f557575426 100644 --- a/src/solver/optimisation/MinHydroPower.cpp +++ b/src/solver/optimisation/MinHydroPower.cpp @@ -6,25 +6,22 @@ void MinHydroPower::add(int pays, MinHydroPowerData& data) bool TurbEntreBornes = data.TurbEntreBornes; if (presenceHydro && (TurbEntreBornes || data.PresenceDePompageModulable)) { - data.NumeroDeContrainteMinEnergieHydraulique[pays] - = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; + data.NumeroDeContrainteMinEnergieHydraulique[pays] = builder.data.nombreDeContraintes; const int NombreDePasDeTempsPourUneOptimisation = data.NombreDePasDeTempsPourUneOptimisation; - ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, - problemeHebdo->NamedProblems); - namer.UpdateArea(problemeHebdo->NomsDesPays[pays]); - namer.UpdateTimeStep(problemeHebdo->weekInTheYear); - namer.MinHydroPower(problemeHebdo->ProblemeAResoudre->NombreDeContraintes); + ConstraintNamer namer(builder.data.NomDesContraintes, builder.data.NamedProblems); + namer.UpdateArea(builder.data.NomsDesPays[pays]); + namer.UpdateTimeStep(builder.data.weekInTheYear); + namer.MinHydroPower(builder.data.nombreDeContraintes); for (int pdt = 0; pdt < NombreDePasDeTempsPourUneOptimisation; pdt++) { builder.updateHourWithinWeek(pdt); builder.include(Variable::HydProd(pays), 1.0); } - data.NumeroDeContrainteMinEnergieHydraulique[pays] - = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; + data.NumeroDeContrainteMinEnergieHydraulique[pays] = builder.data.nombreDeContraintes; builder.greaterThan().build(); } else diff --git a/src/solver/optimisation/constraint_builder.h b/src/solver/optimisation/constraint_builder.h index 6be1dce6df..7169fa6dbe 100644 --- a/src/solver/optimisation/constraint_builder.h +++ b/src/solver/optimisation/constraint_builder.h @@ -256,13 +256,14 @@ struct ConstraintBuilderData std::string& Sens; int& IncrementDAllocationMatriceDesContraintes; const std::vector& CorrespondanceVarNativesVarOptim; - const int NombreDePasDeTempsPourUneOptimisation; + const int32_t NombreDePasDeTempsPourUneOptimisation; const std::vector& NumeroDeVariableStockFinal; const std::vector>& NumeroDeVariableDeTrancheDeStock; std::vector& NomDesContraintes; const bool NamedProblems; const std::vector NomsDesPays; const uint32_t weekInTheYear; + const uint32_t NombreDePasDeTemps; }; class ConstraintBuilder { @@ -373,6 +374,7 @@ struct BindingConstraintData const std::vector& OffsetTemporelSurLePalierDispatch; const char SensDeLaContrainteCouplante; const char* NomDeLaContrainteCouplante; + const std::vector& PaliersThermiquesDuPays; }; inline ConstraintBuilder GetConstraintBuilderFromProblemHebdoAndProblemAResoudre( @@ -397,7 +399,8 @@ inline ConstraintBuilder GetConstraintBuilderFromProblemHebdoAndProblemAResoudre ProblemeAResoudre->NomDesContraintes, problemeHebdo->NamedProblems, problemeHebdo->NomsDesPays, - problemeHebdo->weekInTheYear}; + problemeHebdo->weekInTheYear, + problemeHebdo->NombreDePasDeTemps}; return ConstraintBuilder(data); } 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 fa66b08d1d..458b6b84f7 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 @@ -56,7 +56,6 @@ static BindingConstraintData GetBindingConstraintDataFromProblemHebdo(PROBLEME_H { const CONTRAINTES_COUPLANTES& MatriceDesContraintesCouplantes = problemeHebdo->MatriceDesContraintesCouplantes[cntCouplante]; - return {MatriceDesContraintesCouplantes.TypeDeContrainteCouplante, MatriceDesContraintesCouplantes.NombreDInterconnexionsDansLaContrainteCouplante, MatriceDesContraintesCouplantes.NumeroDeLInterconnexion, @@ -68,7 +67,8 @@ static BindingConstraintData GetBindingConstraintDataFromProblemHebdo(PROBLEME_H MatriceDesContraintesCouplantes.PoidsDuPalierDispatch, MatriceDesContraintesCouplantes.OffsetTemporelSurLePalierDispatch, MatriceDesContraintesCouplantes.SensDeLaContrainteCouplante, - MatriceDesContraintesCouplantes.NomDeLaContrainteCouplante}; + MatriceDesContraintesCouplantes.NomDeLaContrainteCouplante, + problemeHebdo->PaliersThermiquesDuPays}; } static BindingConstraintHourData GetBindingConstraintHourDataFromProblemHebdo( @@ -104,7 +104,10 @@ static BindingConstraintDayData GetBindingConstraintDayDataFromProblemHebdo( // [](CORRESPONDANCES_DES_CONTRAINTES_JOURNALIERES& corr) -> std::vector& // { return corr.NumeroDeContrainteDesContraintesCouplantes; }); - return {data, problemeHebdo->CorrespondanceCntNativesCntOptimJournalieres}; + return {data, + problemeHebdo->CorrespondanceCntNativesCntOptimJournalieres, + problemeHebdo->NombreDePasDeTempsDUneJournee, + problemeHebdo->NumeroDeJourDuPasDeTemps}; } static BindingConstraintWeekData GetBindingConstraintWeekDataFromProblemHebdo( PROBLEME_HEBDO* problemeHebdo, @@ -329,8 +332,11 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro for (uint32_t pays = 0; pays < problemeHebdo->NombreDePays; pays++) { - areaHydroLevel.add( - pays, pdt, CorrespondanceCntNativesCntOptim.NumeroDeContrainteDesNiveauxPays); + AreaHydroLevelData data + = {CorrespondanceCntNativesCntOptim.NumeroDeContrainteDesNiveauxPays, + problemeHebdo->CaracteristiquesHydrauliques[pays].SuiviNiveauHoraire, + problemeHebdo->CaracteristiquesHydrauliques[pays].PumpingRatio}; + areaHydroLevel.add(pays, pdt, data); } } From ee1186efdc1914798899f6a94eabe3aee0375586 Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Tue, 12 Sep 2023 17:34:54 +0200 Subject: [PATCH 40/43] reshape Start-Up Cost Constraints --- src/solver/optimisation/ConsistenceNODU.cpp | 26 ++++++------- src/solver/optimisation/ConsistenceNODU.h | 7 +++- src/solver/optimisation/MinDownTime.cpp | 34 ++++++++--------- src/solver/optimisation/MinDownTime.h | 12 +++++- .../NbDispUnitsMinBoundSinceMinUpTime.cpp | 29 ++++++-------- .../NbDispUnitsMinBoundSinceMinUpTime.h | 11 +++++- .../NbUnitsOutageLessThanNbUnitsStop.cpp | 22 +++++------ .../NbUnitsOutageLessThanNbUnitsStop.h | 6 ++- .../PMaxDispatchableGeneration.cpp | 17 ++++----- .../optimisation/PMaxDispatchableGeneration.h | 7 +++- .../PMinDispatchableGeneration.cpp | 17 ++++----- .../optimisation/PMinDispatchableGeneration.h | 2 +- .../csr_quadratic_problem.cpp | 2 +- src/solver/optimisation/constraint_builder.h | 5 +++ ...nstruction_contraintes_couts_demarrage.cpp | 38 ++++++++++++++++--- 15 files changed, 143 insertions(+), 92 deletions(-) diff --git a/src/solver/optimisation/ConsistenceNODU.cpp b/src/solver/optimisation/ConsistenceNODU.cpp index e5d7b16bf8..300e43584f 100644 --- a/src/solver/optimisation/ConsistenceNODU.cpp +++ b/src/solver/optimisation/ConsistenceNODU.cpp @@ -1,22 +1,23 @@ #include "ConsistenceNODU.h" -void ConsistenceNODU::add(int pays, int cluster, int clusterIndex, int pdt, bool Simulation) +void ConsistenceNODU::add(int pays, + int cluster, + int clusterIndex, + int pdt, + bool Simulation, + StartUpCostsData& data) { if (!Simulation) { - const PALIERS_THERMIQUES& PaliersThermiquesDuPays - = problemeHebdo->PaliersThermiquesDuPays[pays]; + const PALIERS_THERMIQUES& PaliersThermiquesDuPays = data.PaliersThermiquesDuPays[pays]; int NombreDePasDeTempsPourUneOptimisation - = problemeHebdo->NombreDePasDeTempsPourUneOptimisation; + = builder.data.NombreDePasDeTempsPourUneOptimisation; int Pdtmoins1 = pdt - 1; if (Pdtmoins1 < 0) Pdtmoins1 = NombreDePasDeTempsPourUneOptimisation + Pdtmoins1; - CORRESPONDANCES_DES_VARIABLES& CorrespondanceVarNativesVarOptimTmoins1 - = problemeHebdo->CorrespondanceVarNativesVarOptim[Pdtmoins1]; - builder.updateHourWithinWeek(pdt) .include(Variable::NODU(cluster), 1.0) .updateHourWithinWeek(Pdtmoins1) @@ -28,12 +29,11 @@ void ConsistenceNODU::add(int pays, int cluster, int clusterIndex, int pdt, bool if (builder.NumberOfVariables() > 0) { - ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, - problemeHebdo->NamedProblems); - namer.UpdateArea(problemeHebdo->NomsDesPays[pays]); + ConstraintNamer namer(builder.data.NomDesContraintes, builder.data.NamedProblems); + namer.UpdateArea(builder.data.NomsDesPays[pays]); - namer.UpdateTimeStep(problemeHebdo->weekInTheYear * 168 + pdt); - namer.ConsistenceNODU(problemeHebdo->ProblemeAResoudre->NombreDeContraintes, + namer.UpdateTimeStep(builder.data.weekInTheYear * 168 + pdt); + namer.ConsistenceNODU(builder.data.nombreDeContraintes, PaliersThermiquesDuPays.NomsDesPaliersThermiques[clusterIndex]); builder.build(); @@ -42,6 +42,6 @@ void ConsistenceNODU::add(int pays, int cluster, int clusterIndex, int pdt, bool else { nbTermesContraintesPourLesCoutsDeDemarrage += 4; - problemeHebdo->ProblemeAResoudre->NombreDeContraintes++; + builder.data.nombreDeContraintes++; } } diff --git a/src/solver/optimisation/ConsistenceNODU.h b/src/solver/optimisation/ConsistenceNODU.h index 3f61effda1..6d97cd4c92 100644 --- a/src/solver/optimisation/ConsistenceNODU.h +++ b/src/solver/optimisation/ConsistenceNODU.h @@ -5,6 +5,11 @@ class ConsistenceNODU : private Constraint { public: using Constraint::Constraint; - void add(int pays, int cluster, int clusterIndex, int pdt, bool Simulation); + void add(int pays, + int cluster, + int clusterIndex, + int pdt, + bool Simulation, + StartUpCostsData& data); int nbTermesContraintesPourLesCoutsDeDemarrage = 0; }; \ No newline at end of file diff --git a/src/solver/optimisation/MinDownTime.cpp b/src/solver/optimisation/MinDownTime.cpp index 170c4179e0..f4fef3fdf5 100644 --- a/src/solver/optimisation/MinDownTime.cpp +++ b/src/solver/optimisation/MinDownTime.cpp @@ -1,19 +1,21 @@ #include "MinDownTime.h" -void MinDownTime::add(int pays, int cluster, int clusterIndex, int pdt, bool Simulation) +void MinDownTime::add(int pays, + int cluster, + int clusterIndex, + int pdt, + bool Simulation, + MinDownTimeData& data) { - const PALIERS_THERMIQUES& PaliersThermiquesDuPays - = problemeHebdo->PaliersThermiquesDuPays[pays]; + const PALIERS_THERMIQUES& PaliersThermiquesDuPays = data.PaliersThermiquesDuPays[pays]; const int DureeMinimaleDArretDUnGroupeDuPalierThermique = PaliersThermiquesDuPays.DureeMinimaleDArretDUnGroupeDuPalierThermique[clusterIndex]; - CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim - = problemeHebdo->CorrespondanceCntNativesCntOptim[pdt]; - CorrespondanceCntNativesCntOptim.NumeroDeContrainteDesContraintesDeDureeMinDArret[cluster] = -1; + data.NumeroDeContrainteDesContraintesDeDureeMinDArret[cluster] = -1; if (!Simulation) { int NombreDePasDeTempsPourUneOptimisation - = problemeHebdo->NombreDePasDeTempsPourUneOptimisation; + = builder.data.NombreDePasDeTempsPourUneOptimisation; const std::vector& NombreMaxDeGroupesEnMarcheDuPalierThermique = PaliersThermiquesDuPays.PuissanceDisponibleEtCout[clusterIndex] @@ -33,15 +35,13 @@ void MinDownTime::add(int pays, int cluster, int clusterIndex, int pdt, bool Sim builder.lessThan(); if (builder.NumberOfVariables() > 1) { - CorrespondanceCntNativesCntOptim - .NumeroDeContrainteDesContraintesDeDureeMinDArret[cluster] - = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; - ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, - problemeHebdo->NamedProblems); - namer.UpdateArea(problemeHebdo->NomsDesPays[pays]); - - namer.UpdateTimeStep(problemeHebdo->weekInTheYear * 168 + pdt); - namer.MinDownTime(problemeHebdo->ProblemeAResoudre->NombreDeContraintes, + data.NumeroDeContrainteDesContraintesDeDureeMinDArret[cluster] + = builder.data.nombreDeContraintes; + ConstraintNamer namer(builder.data.NomDesContraintes, builder.data.NamedProblems); + namer.UpdateArea(builder.data.NomsDesPays[pays]); + + namer.UpdateTimeStep(builder.data.weekInTheYear * 168 + pdt); + namer.MinDownTime(builder.data.nombreDeContraintes, PaliersThermiquesDuPays.NomsDesPaliersThermiques[clusterIndex]); builder.build(); @@ -51,6 +51,6 @@ void MinDownTime::add(int pays, int cluster, int clusterIndex, int pdt, bool Sim { nbTermesContraintesPourLesCoutsDeDemarrage += 1 + DureeMinimaleDArretDUnGroupeDuPalierThermique; - problemeHebdo->ProblemeAResoudre->NombreDeContraintes++; + builder.data.nombreDeContraintes++; } } diff --git a/src/solver/optimisation/MinDownTime.h b/src/solver/optimisation/MinDownTime.h index ee29fab770..aa3ce25425 100644 --- a/src/solver/optimisation/MinDownTime.h +++ b/src/solver/optimisation/MinDownTime.h @@ -1,10 +1,18 @@ #pragma once #include "constraint_builder.h" - +struct MinDownTimeData : public StartUpCostsData +{ + std::vector& NumeroDeContrainteDesContraintesDeDureeMinDArret; +}; class MinDownTime : private Constraint { public: using Constraint::Constraint; - void add(int pays, int cluster, int clusterIndex, int pdt, bool Simulation); + void add(int pays, + int cluster, + int clusterIndex, + int pdt, + bool Simulation, + MinDownTimeData& data); int nbTermesContraintesPourLesCoutsDeDemarrage = 0; }; \ No newline at end of file diff --git a/src/solver/optimisation/NbDispUnitsMinBoundSinceMinUpTime.cpp b/src/solver/optimisation/NbDispUnitsMinBoundSinceMinUpTime.cpp index 4ac959d3fa..2f8232613a 100644 --- a/src/solver/optimisation/NbDispUnitsMinBoundSinceMinUpTime.cpp +++ b/src/solver/optimisation/NbDispUnitsMinBoundSinceMinUpTime.cpp @@ -4,21 +4,18 @@ void NbDispUnitsMinBoundSinceMinUpTime::add(int pays, int cluster, int clusterIndex, int pdt, - bool Simulation) + bool Simulation, + NbDispUnitsMinBoundSinceMinUpTimeData& data) { - const PALIERS_THERMIQUES& PaliersThermiquesDuPays - = problemeHebdo->PaliersThermiquesDuPays[pays]; + const PALIERS_THERMIQUES& PaliersThermiquesDuPays = data.PaliersThermiquesDuPays[pays]; const int DureeMinimaleDeMarcheDUnGroupeDuPalierThermique = PaliersThermiquesDuPays.DureeMinimaleDeMarcheDUnGroupeDuPalierThermique[clusterIndex]; - CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim - = problemeHebdo->CorrespondanceCntNativesCntOptim[pdt]; - CorrespondanceCntNativesCntOptim.NumeroDeContrainteDesContraintesDeDureeMinDeMarche[cluster] - = -1; + data.NumeroDeContrainteDesContraintesDeDureeMinDeMarche[cluster] = -1; if (!Simulation) { int NombreDePasDeTempsPourUneOptimisation - = problemeHebdo->NombreDePasDeTempsPourUneOptimisation; + = builder.data.NombreDePasDeTempsPourUneOptimisation; const std::vector& NombreMaxDeGroupesEnMarcheDuPalierThermique = PaliersThermiquesDuPays.PuissanceDisponibleEtCout[clusterIndex] @@ -40,17 +37,15 @@ void NbDispUnitsMinBoundSinceMinUpTime::add(int pays, builder.greaterThan(); if (builder.NumberOfVariables() > 1) { - CorrespondanceCntNativesCntOptim - .NumeroDeContrainteDesContraintesDeDureeMinDeMarche[cluster] - = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; + data.NumeroDeContrainteDesContraintesDeDureeMinDeMarche[cluster] + = builder.data.nombreDeContraintes; - ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, - problemeHebdo->NamedProblems); - namer.UpdateArea(problemeHebdo->NomsDesPays[pays]); + ConstraintNamer namer(builder.data.NomDesContraintes, builder.data.NamedProblems); + namer.UpdateArea(builder.data.NomsDesPays[pays]); - namer.UpdateTimeStep(problemeHebdo->weekInTheYear * 168 + pdt); + namer.UpdateTimeStep(builder.data.weekInTheYear * 168 + pdt); namer.NbDispUnitsMinBoundSinceMinUpTime( - problemeHebdo->ProblemeAResoudre->NombreDeContraintes, + builder.data.nombreDeContraintes, PaliersThermiquesDuPays.NomsDesPaliersThermiques[clusterIndex]); builder.build(); } @@ -59,6 +54,6 @@ void NbDispUnitsMinBoundSinceMinUpTime::add(int pays, { nbTermesContraintesPourLesCoutsDeDemarrage += 1 + 2 * DureeMinimaleDeMarcheDUnGroupeDuPalierThermique; - problemeHebdo->ProblemeAResoudre->NombreDeContraintes++; + builder.data.nombreDeContraintes++; } } diff --git a/src/solver/optimisation/NbDispUnitsMinBoundSinceMinUpTime.h b/src/solver/optimisation/NbDispUnitsMinBoundSinceMinUpTime.h index baf6edcbcf..e4f85d8e17 100644 --- a/src/solver/optimisation/NbDispUnitsMinBoundSinceMinUpTime.h +++ b/src/solver/optimisation/NbDispUnitsMinBoundSinceMinUpTime.h @@ -1,10 +1,19 @@ #pragma once #include "constraint_builder.h" +struct NbDispUnitsMinBoundSinceMinUpTimeData : public StartUpCostsData +{ + std::vector& NumeroDeContrainteDesContraintesDeDureeMinDeMarche; +}; class NbDispUnitsMinBoundSinceMinUpTime : private Constraint { public: using Constraint::Constraint; - void add(int pays, int cluster, int clusterIndex, int pdt, bool Simulation); + void add(int pays, + int cluster, + int clusterIndex, + int pdt, + bool Simulation, + NbDispUnitsMinBoundSinceMinUpTimeData& data); int nbTermesContraintesPourLesCoutsDeDemarrage = 0; }; \ No newline at end of file diff --git a/src/solver/optimisation/NbUnitsOutageLessThanNbUnitsStop.cpp b/src/solver/optimisation/NbUnitsOutageLessThanNbUnitsStop.cpp index dee28fa384..f809731325 100644 --- a/src/solver/optimisation/NbUnitsOutageLessThanNbUnitsStop.cpp +++ b/src/solver/optimisation/NbUnitsOutageLessThanNbUnitsStop.cpp @@ -4,19 +4,16 @@ void NbUnitsOutageLessThanNbUnitsStop::add(int pays, int cluster, int clusterIndex, int pdt, - bool Simulation) + bool Simulation, + NbUnitsOutageLessThanNbUnitsStopData& data) { if (!Simulation) { - const PALIERS_THERMIQUES& PaliersThermiquesDuPays - = problemeHebdo->PaliersThermiquesDuPays[pays]; + const PALIERS_THERMIQUES& PaliersThermiquesDuPays = data.PaliersThermiquesDuPays[pays]; const int DureeMinimaleDArretDUnGroupeDuPalierThermique = PaliersThermiquesDuPays.DureeMinimaleDArretDUnGroupeDuPalierThermique[clusterIndex]; - CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim - = problemeHebdo->CorrespondanceCntNativesCntOptim[pdt]; - CorrespondanceCntNativesCntOptim.NumeroDeContrainteDesContraintesDeDureeMinDeMarche[cluster] - = -1; + data.NumeroDeContrainteDesContraintesDeDureeMinDeMarche[cluster] = -1; builder.updateHourWithinWeek(pdt) .include(Variable::NumberBreakingDownDispatchableUnits(cluster), 1.0) @@ -25,12 +22,11 @@ void NbUnitsOutageLessThanNbUnitsStop::add(int pays, if (builder.NumberOfVariables() > 0) { - ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, - problemeHebdo->NamedProblems); - namer.UpdateArea(problemeHebdo->NomsDesPays[pays]); - namer.UpdateTimeStep(problemeHebdo->weekInTheYear * 168 + pdt); + ConstraintNamer namer(builder.data.NomDesContraintes, builder.data.NamedProblems); + namer.UpdateArea(builder.data.NomsDesPays[pays]); + namer.UpdateTimeStep(builder.data.weekInTheYear * 168 + pdt); namer.NbUnitsOutageLessThanNbUnitsStop( - problemeHebdo->ProblemeAResoudre->NombreDeContraintes, + builder.data.nombreDeContraintes, PaliersThermiquesDuPays.NomsDesPaliersThermiques[clusterIndex]); builder.build(); @@ -39,6 +35,6 @@ void NbUnitsOutageLessThanNbUnitsStop::add(int pays, else { nbTermesContraintesPourLesCoutsDeDemarrage += 4; - problemeHebdo->ProblemeAResoudre->NombreDeContraintes++; + builder.data.nombreDeContraintes++; } } diff --git a/src/solver/optimisation/NbUnitsOutageLessThanNbUnitsStop.h b/src/solver/optimisation/NbUnitsOutageLessThanNbUnitsStop.h index bb09468cf3..f6f5aafe8d 100644 --- a/src/solver/optimisation/NbUnitsOutageLessThanNbUnitsStop.h +++ b/src/solver/optimisation/NbUnitsOutageLessThanNbUnitsStop.h @@ -1,10 +1,14 @@ #pragma once #include "constraint_builder.h" +struct NbUnitsOutageLessThanNbUnitsStopData : public StartUpCostsData +{ + std::vector& NumeroDeContrainteDesContraintesDeDureeMinDeMarche; +}; class NbUnitsOutageLessThanNbUnitsStop : private Constraint { public: using Constraint::Constraint; - void add(int pays, int cluster, int clusterIndex, int pdt, bool Simulation); + void add(int pays, int cluster, int clusterIndex, int pdt, bool Simulation, NbUnitsOutageLessThanNbUnitsStopData&data); int nbTermesContraintesPourLesCoutsDeDemarrage = 0; }; \ No newline at end of file diff --git a/src/solver/optimisation/PMaxDispatchableGeneration.cpp b/src/solver/optimisation/PMaxDispatchableGeneration.cpp index 8dd5d50f25..155e9297f1 100644 --- a/src/solver/optimisation/PMaxDispatchableGeneration.cpp +++ b/src/solver/optimisation/PMaxDispatchableGeneration.cpp @@ -4,12 +4,12 @@ void PMaxDispatchableGeneration::add(int pays, int cluster, int clusterIndex, int pdt, - bool Simulation) + bool Simulation, + StartUpCostsData& data) { if (!Simulation) { - const PALIERS_THERMIQUES& PaliersThermiquesDuPays - = problemeHebdo->PaliersThermiquesDuPays[pays]; + const PALIERS_THERMIQUES& PaliersThermiquesDuPays = data.PaliersThermiquesDuPays[pays]; double pmaxDUnGroupeDuPalierThermique = PaliersThermiquesDuPays.PmaxDUnGroupeDuPalierThermique[clusterIndex]; @@ -19,14 +19,13 @@ void PMaxDispatchableGeneration::add(int pays, .lessThan(); if (builder.NumberOfVariables() > 0) { - 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.UpdateTimeStep(builder.data.weekInTheYear * 168 + pdt); + namer.UpdateArea(builder.data.NomsDesPays[pays]); namer.PMaxDispatchableGeneration( - problemeHebdo->ProblemeAResoudre->NombreDeContraintes, + builder.data.nombreDeContraintes, PaliersThermiquesDuPays.NomsDesPaliersThermiques[clusterIndex]); } builder.build(); @@ -34,6 +33,6 @@ void PMaxDispatchableGeneration::add(int pays, else { nbTermesContraintesPourLesCoutsDeDemarrage += 2; - problemeHebdo->ProblemeAResoudre->NombreDeContraintes++; + builder.data.nombreDeContraintes++; } } \ No newline at end of file diff --git a/src/solver/optimisation/PMaxDispatchableGeneration.h b/src/solver/optimisation/PMaxDispatchableGeneration.h index b088b23851..fb3fb07860 100644 --- a/src/solver/optimisation/PMaxDispatchableGeneration.h +++ b/src/solver/optimisation/PMaxDispatchableGeneration.h @@ -5,6 +5,11 @@ class PMaxDispatchableGeneration : private Constraint { public: using Constraint::Constraint; - void add(int pays, int cluster, int clusterIndex, int pdt, bool Simulation); + void add(int pays, + int cluster, + int clusterIndex, + int pdt, + bool Simulation, + StartUpCostsData& data); int nbTermesContraintesPourLesCoutsDeDemarrage = 0; }; \ No newline at end of file diff --git a/src/solver/optimisation/PMinDispatchableGeneration.cpp b/src/solver/optimisation/PMinDispatchableGeneration.cpp index 2d0595e67b..58b35923bb 100644 --- a/src/solver/optimisation/PMinDispatchableGeneration.cpp +++ b/src/solver/optimisation/PMinDispatchableGeneration.cpp @@ -4,12 +4,12 @@ void PMinDispatchableGeneration::add(int pays, int cluster, int clusterIndex, int pdt, - bool Simulation) + bool Simulation, + StartUpCostsData& data) { if (!Simulation) { - const PALIERS_THERMIQUES& PaliersThermiquesDuPays - = problemeHebdo->PaliersThermiquesDuPays[pays]; + const PALIERS_THERMIQUES& PaliersThermiquesDuPays = data.PaliersThermiquesDuPays[pays]; double pminDUnGroupeDuPalierThermique = PaliersThermiquesDuPays.pminDUnGroupeDuPalierThermique[clusterIndex]; @@ -20,13 +20,12 @@ void PMinDispatchableGeneration::add(int pays, /*consider Adding naming constraint inside the builder*/ if (builder.NumberOfVariables() > 0) { - ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, - problemeHebdo->NamedProblems); - namer.UpdateArea(problemeHebdo->NomsDesPays[pays]); + ConstraintNamer namer(builder.data.NomDesContraintes, builder.data.NamedProblems); + namer.UpdateArea(builder.data.NomsDesPays[pays]); - namer.UpdateTimeStep(problemeHebdo->weekInTheYear * 168 + pdt); + namer.UpdateTimeStep(builder.data.weekInTheYear * 168 + pdt); namer.PMinDispatchableGeneration( - problemeHebdo->ProblemeAResoudre->NombreDeContraintes, + builder.data.nombreDeContraintes, PaliersThermiquesDuPays.NomsDesPaliersThermiques[clusterIndex]); } builder.build(); @@ -34,6 +33,6 @@ void PMinDispatchableGeneration::add(int pays, else { nbTermesContraintesPourLesCoutsDeDemarrage += 2; - problemeHebdo->ProblemeAResoudre->NombreDeContraintes++; + builder.data.nombreDeContraintes++; } } diff --git a/src/solver/optimisation/PMinDispatchableGeneration.h b/src/solver/optimisation/PMinDispatchableGeneration.h index cad678e936..ab1499c3e4 100644 --- a/src/solver/optimisation/PMinDispatchableGeneration.h +++ b/src/solver/optimisation/PMinDispatchableGeneration.h @@ -5,6 +5,6 @@ class PMinDispatchableGeneration : private Constraint { public: using Constraint::Constraint; - void add(int pays, int cluster, int clusterIndex, int pdt, bool Simulation); + void add(int pays, int cluster, int clusterIndex, int pdt, bool Simulation, StartUpCostsData& data); int nbTermesContraintesPourLesCoutsDeDemarrage = 0; }; \ No newline at end of file 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 803a3cc6aa..b11f81f06f 100644 --- a/src/solver/optimisation/adequacy_patch_csr/csr_quadratic_problem.cpp +++ b/src/solver/optimisation/adequacy_patch_csr/csr_quadratic_problem.cpp @@ -309,7 +309,7 @@ void CsrQuadraticProblem::buildConstraintMatrix() std::vector Pi(problemeAResoudre_.NombreDeVariables); std::vector Colonne(problemeAResoudre_.NombreDeVariables); - + // TODO reset problemeAResoudre_.Pi and problemeAResoudre_.Colonne? problemeAResoudre_.NombreDeContraintes = 0; problemeAResoudre_.NombreDeTermesDansLaMatriceDesContraintes = 0; diff --git a/src/solver/optimisation/constraint_builder.h b/src/solver/optimisation/constraint_builder.h index 7169fa6dbe..6f1026db91 100644 --- a/src/solver/optimisation/constraint_builder.h +++ b/src/solver/optimisation/constraint_builder.h @@ -377,6 +377,11 @@ struct BindingConstraintData const std::vector& PaliersThermiquesDuPays; }; +struct StartUpCostsData +{ + const std::vector& PaliersThermiquesDuPays; +}; + inline ConstraintBuilder GetConstraintBuilderFromProblemHebdoAndProblemAResoudre( const PROBLEME_HEBDO* problemeHebdo, PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre) diff --git a/src/solver/optimisation/opt_construction_contraintes_couts_demarrage.cpp b/src/solver/optimisation/opt_construction_contraintes_couts_demarrage.cpp index dafafcf8e2..02b3816f06 100644 --- a/src/solver/optimisation/opt_construction_contraintes_couts_demarrage.cpp +++ b/src/solver/optimisation/opt_construction_contraintes_couts_demarrage.cpp @@ -54,6 +54,9 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( std::vector& Colonne = ProblemeAResoudre->Colonne; ConstraintNamer constraintNamer(ProblemeAResoudre->NomDesContraintes, problemeHebdo->NamedProblems); + + StartUpCostsData startUpCostsData = {problemeHebdo->PaliersThermiquesDuPays}; + int nbTermesContraintesPourLesCoutsDeDemarrage = 0; for (uint32_t pays = 0; pays < problemeHebdo->NombreDePays; pays++) { @@ -69,11 +72,13 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) { - pMaxDispatchableGeneration.add(pays, palier, index, pdt, Simulation); + pMaxDispatchableGeneration.add( + pays, palier, index, pdt, Simulation, startUpCostsData); nbTermesContraintesPourLesCoutsDeDemarrage += pMaxDispatchableGeneration.nbTermesContraintesPourLesCoutsDeDemarrage; - pMinDispatchableGeneration.add(pays, palier, index, pdt, Simulation); + pMinDispatchableGeneration.add( + pays, palier, index, pdt, Simulation, startUpCostsData); nbTermesContraintesPourLesCoutsDeDemarrage += pMinDispatchableGeneration.nbTermesContraintesPourLesCoutsDeDemarrage; } @@ -93,7 +98,7 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) { ConsistenceNODU consistenceNODU(builder); - consistenceNODU.add(pays, palier, index, pdt, Simulation); + consistenceNODU.add(pays, palier, index, pdt, Simulation, startUpCostsData); nbTermesContraintesPourLesCoutsDeDemarrage += consistenceNODU.nbTermesContraintesPourLesCoutsDeDemarrage; } @@ -114,7 +119,14 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) { - nbUnitsOutageLessThanNbUnitsStop.add(pays, palier, index, pdt, Simulation); + CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim + = problemeHebdo->CorrespondanceCntNativesCntOptim[pdt]; + NbUnitsOutageLessThanNbUnitsStopData nbUnitsOutageLessThanNbUnitsStopData + = {startUpCostsData, + CorrespondanceCntNativesCntOptim + .NumeroDeContrainteDesContraintesDeDureeMinDeMarche}; + nbUnitsOutageLessThanNbUnitsStop.add( + pays, palier, index, pdt, Simulation, nbUnitsOutageLessThanNbUnitsStopData); nbTermesContraintesPourLesCoutsDeDemarrage += nbUnitsOutageLessThanNbUnitsStop.nbTermesContraintesPourLesCoutsDeDemarrage; } @@ -138,7 +150,14 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) { - nbDispUnitsMinBoundSinceMinUpTime.add(pays, palier, index, pdt, Simulation); + CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim + = problemeHebdo->CorrespondanceCntNativesCntOptim[pdt]; + NbDispUnitsMinBoundSinceMinUpTimeData nbDispUnitsMinBoundSinceMinUpTimeData + = {startUpCostsData, + CorrespondanceCntNativesCntOptim + .NumeroDeContrainteDesContraintesDeDureeMinDeMarche}; + nbDispUnitsMinBoundSinceMinUpTime.add( + pays, palier, index, pdt, Simulation, nbDispUnitsMinBoundSinceMinUpTimeData); nbTermesContraintesPourLesCoutsDeDemarrage += nbDispUnitsMinBoundSinceMinUpTime.nbTermesContraintesPourLesCoutsDeDemarrage; } @@ -157,7 +176,14 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) { - minDownTime.add(pays, palier, index, pdt, Simulation); + CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim + = problemeHebdo->CorrespondanceCntNativesCntOptim[pdt]; + MinDownTimeData minDownTimeData + = {startUpCostsData, + CorrespondanceCntNativesCntOptim + .NumeroDeContrainteDesContraintesDeDureeMinDArret}; + + minDownTime.add(pays, palier, index, pdt, Simulation, minDownTimeData); nbTermesContraintesPourLesCoutsDeDemarrage += minDownTime.nbTermesContraintesPourLesCoutsDeDemarrage; } From 9d935eca4f38a6c1902628dfb85d5d862852cd32 Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Tue, 12 Sep 2023 17:43:57 +0200 Subject: [PATCH 41/43] add empty line --- src/solver/optimisation/MinDownTime.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/solver/optimisation/MinDownTime.h b/src/solver/optimisation/MinDownTime.h index aa3ce25425..e6df2ea202 100644 --- a/src/solver/optimisation/MinDownTime.h +++ b/src/solver/optimisation/MinDownTime.h @@ -4,6 +4,7 @@ struct MinDownTimeData : public StartUpCostsData { std::vector& NumeroDeContrainteDesContraintesDeDureeMinDArret; }; + class MinDownTime : private Constraint { public: From 5cece36fbf57b60a46f04e371c7c4f09abf5ea97 Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Fri, 15 Sep 2023 11:22:36 +0200 Subject: [PATCH 42/43] start debug session --- src/solver/optimisation/CMakeLists.txt | 2 + .../csr_quadratic_problem.cpp | 1 + src/solver/optimisation/constraint_builder.h | 37 +------------------ .../optimisation/constraint_builder_utils.cpp | 29 +++++++++++++++ .../optimisation/constraint_builder_utils.h | 12 ++++++ ...nstruction_contraintes_couts_demarrage.cpp | 1 + ...n_matrice_des_contraintes_cas_lineaire.cpp | 1 + ...atrice_des_contraintes_cas_quadratique.cpp | 1 + 8 files changed, 48 insertions(+), 36 deletions(-) create mode 100644 src/solver/optimisation/constraint_builder_utils.cpp create mode 100644 src/solver/optimisation/constraint_builder_utils.h diff --git a/src/solver/optimisation/CMakeLists.txt b/src/solver/optimisation/CMakeLists.txt index a92d6a0cd9..bcdde70e40 100644 --- a/src/solver/optimisation/CMakeLists.txt +++ b/src/solver/optimisation/CMakeLists.txt @@ -73,6 +73,8 @@ set(RTESOLVER_OPT constraint_builder.cpp constraint_builder.h + constraint_builder_utils.h + constraint_builder_utils.cpp AreaBalance.h AreaBalance.cpp 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 b11f81f06f..856096b24b 100644 --- a/src/solver/optimisation/adequacy_patch_csr/csr_quadratic_problem.cpp +++ b/src/solver/optimisation/adequacy_patch_csr/csr_quadratic_problem.cpp @@ -34,6 +34,7 @@ #include "hourly_csr_problem.h" #include "sim_structure_probleme_economique.h" #include "../constraint_builder.h" +#include "../constraint_builder_utils.h" #include "../opt_rename_problem.h" #include "adequacy_patch_runtime_data.h" diff --git a/src/solver/optimisation/constraint_builder.h b/src/solver/optimisation/constraint_builder.h index 6f1026db91..13be5511fb 100644 --- a/src/solver/optimisation/constraint_builder.h +++ b/src/solver/optimisation/constraint_builder.h @@ -261,7 +261,7 @@ struct ConstraintBuilderData const std::vector>& NumeroDeVariableDeTrancheDeStock; std::vector& NomDesContraintes; const bool NamedProblems; - const std::vector NomsDesPays; + const std::vector& NomsDesPays; const uint32_t weekInTheYear; const uint32_t NombreDePasDeTemps; }; @@ -381,38 +381,3 @@ struct StartUpCostsData { const std::vector& PaliersThermiquesDuPays; }; - -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, - problemeHebdo->NombreDePasDeTemps}; - - 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/constraint_builder_utils.cpp b/src/solver/optimisation/constraint_builder_utils.cpp new file mode 100644 index 0000000000..cfe14da083 --- /dev/null +++ b/src/solver/optimisation/constraint_builder_utils.cpp @@ -0,0 +1,29 @@ +#include "constraint_builder_utils.h" + +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, + problemeHebdo->NombreDePasDeTemps}; + + return ConstraintBuilder(data); +} \ No newline at end of file diff --git a/src/solver/optimisation/constraint_builder_utils.h b/src/solver/optimisation/constraint_builder_utils.h new file mode 100644 index 0000000000..d76513a5a3 --- /dev/null +++ b/src/solver/optimisation/constraint_builder_utils.h @@ -0,0 +1,12 @@ +#pragma once +#include "constraint_builder.h" +ConstraintBuilder GetConstraintBuilderFromProblemHebdoAndProblemAResoudre( + const PROBLEME_HEBDO* problemeHebdo, + PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre); + +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 02b3816f06..38d17ee1e6 100644 --- a/src/solver/optimisation/opt_construction_contraintes_couts_demarrage.cpp +++ b/src/solver/optimisation/opt_construction_contraintes_couts_demarrage.cpp @@ -38,6 +38,7 @@ #include "NbUnitsOutageLessThanNbUnitsStop.h" #include "NbDispUnitsMinBoundSinceMinUpTime.h" #include "MinDownTime.h" +#include "constraint_builder_utils.h" using namespace Antares::Data; 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 458b6b84f7..6650b536c3 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 @@ -47,6 +47,7 @@ #include "AreaHydroLevel.h" #include "FinalStockEquivalent.h" #include "FinalStockExpression.h" +#include "constraint_builder_utils.h" #include 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 608ddd25df..5d6a35bceb 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,6 +32,7 @@ #include "../simulation/sim_extern_variables_globales.h" #include "opt_fonctions.h" #include "constraint_builder.h" +#include "constraint_builder_utils.h" struct ExchangeBalanceData { From 1ab00ba6a39aafd3721d806de11beda5526d823e Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Sat, 16 Sep 2023 13:47:24 +0200 Subject: [PATCH 43/43] secure refs --- src/solver/optimisation/AreaBalance.cpp | 66 ++++---- src/solver/optimisation/AreaBalance.h | 24 ++- src/solver/optimisation/AreaHydroLevel.h | 4 +- .../optimisation/BindingConstraintDay.cpp | 4 +- .../optimisation/BindingConstraintDay.h | 46 +++++- .../optimisation/BindingConstraintHour.h | 36 +++++ .../optimisation/BindingConstraintWeek.cpp | 5 +- .../optimisation/BindingConstraintWeek.h | 36 +++++ .../optimisation/FinalStockEquivalent.h | 6 +- .../optimisation/FinalStockExpression.h | 4 +- src/solver/optimisation/HydroPower.h | 10 +- src/solver/optimisation/MaxHydroPower.h | 8 +- src/solver/optimisation/MaxPumping.h | 2 +- src/solver/optimisation/MinHydroPower.h | 8 +- .../optimisation/constraint_builder.cpp | 89 ++++++++--- src/solver/optimisation/constraint_builder.h | 145 ++++++++++++++++-- .../optimisation/constraint_builder_utils.cpp | 4 +- ...nstruction_contraintes_couts_demarrage.cpp | 31 ++-- ...n_matrice_des_contraintes_cas_lineaire.cpp | 122 ++++++++++----- 19 files changed, 496 insertions(+), 154 deletions(-) diff --git a/src/solver/optimisation/AreaBalance.cpp b/src/solver/optimisation/AreaBalance.cpp index 80382ecf62..6134be2557 100644 --- a/src/solver/optimisation/AreaBalance.cpp +++ b/src/solver/optimisation/AreaBalance.cpp @@ -22,43 +22,45 @@ static void shortTermStorageBalance(const ::ShortTermStorage::AREA_INPUT& shortT // Constraint definitions void AreaBalance::add(int pdt, int pays, AreaBalanceData& data) { - /** can be done without this --- keep it for now**/ - data.NumeroDeContrainteDesBilansPays[pays] = builder.data.nombreDeContraintes; + // /** can be done without this --- keep it for now**/ + // data.NumeroDeContrainteDesBilansPays[pays] = builder.data.nombreDeContraintes; - /******/ - // TODO improve this - { - 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); - } + // /******/ + // // TODO improve this - builder.updateHourWithinWeek(pdt); + // 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); - int interco = data.IndexDebutIntercoOrigine[pays]; - while (interco >= 0) - { - builder.include(Variable::NTCDirect(interco), 1.0); - interco = data.IndexSuivantIntercoOrigine[interco]; - } + // builder.updateHourWithinWeek(pdt); - interco = data.IndexDebutIntercoExtremite[pays]; - while (interco >= 0) - { - builder.include(Variable::NTCDirect(interco), -1.0); - interco = data.IndexSuivantIntercoExtremite[interco]; - } + // int interco = data.IndexDebutIntercoOrigine[pays]; + // while (interco >= 0) + // { + // builder.include(Variable::NTCDirect(interco), 1.0); + // interco = data.IndexSuivantIntercoOrigine[interco]; + // } + + // interco = data.IndexDebutIntercoExtremite[pays]; + // while (interco >= 0) + // { + // builder.include(Variable::NTCDirect(interco), -1.0); + // interco = data.IndexSuivantIntercoExtremite[interco]; + // } - 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); + // 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( - data.ShortTermStorage[pays], builder, data.InjectionVariable, data.WithdrawalVariable); + // shortTermStorageBalance( + // data.ShortTermStorage[pays], builder, data.InjectionVariable, data.WithdrawalVariable); - builder.equalTo(); - builder.build(); + // builder.equalTo(); + // builder.build(); + logs.info() << "" << data.NumeroDeContrainteDesBilansPays[pays] << "\n"; + int a = 13; + int b = a / 33; } diff --git a/src/solver/optimisation/AreaBalance.h b/src/solver/optimisation/AreaBalance.h index 16c79d8156..6a970cdab2 100644 --- a/src/solver/optimisation/AreaBalance.h +++ b/src/solver/optimisation/AreaBalance.h @@ -3,10 +3,32 @@ struct AreaBalanceData { + 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) + + : + NumeroDeContrainteDesBilansPays(NumeroDeContrainteDesBilansPays), + InjectionVariable(InjectionVariable), + WithdrawalVariable(WithdrawalVariable), + IndexDebutIntercoOrigine(IndexDebutIntercoOrigine), + IndexSuivantIntercoOrigine(IndexSuivantIntercoOrigine), + IndexDebutIntercoExtremite(IndexDebutIntercoExtremite), + IndexSuivantIntercoExtremite(IndexSuivantIntercoExtremite), + PaliersThermiquesDuPays(PaliersThermiquesDuPays), + ShortTermStorage(ShortTermStorage) + { + } + std::vector& NumeroDeContrainteDesBilansPays; std::vector& InjectionVariable; std::vector& WithdrawalVariable; - const std::vector& IndexDebutIntercoOrigine; const std::vector& IndexSuivantIntercoOrigine; const std::vector& IndexDebutIntercoExtremite; diff --git a/src/solver/optimisation/AreaHydroLevel.h b/src/solver/optimisation/AreaHydroLevel.h index b075ece1b8..928c834548 100644 --- a/src/solver/optimisation/AreaHydroLevel.h +++ b/src/solver/optimisation/AreaHydroLevel.h @@ -4,8 +4,8 @@ struct AreaHydroLevelData { std::vector& NumeroDeContrainteDesNiveauxPays; - const bool SuiviNiveauHoraire; - const double PumpingRatio; + const bool& SuiviNiveauHoraire; + const double& PumpingRatio; }; class AreaHydroLevel : private Constraint diff --git a/src/solver/optimisation/BindingConstraintDay.cpp b/src/solver/optimisation/BindingConstraintDay.cpp index 8916041274..e48b49742f 100644 --- a/src/solver/optimisation/BindingConstraintDay.cpp +++ b/src/solver/optimisation/BindingConstraintDay.cpp @@ -15,8 +15,6 @@ void BindingConstraintDay::add(int cntCouplante, BindingConstraintDayData& data) while (pdtDebut < NombreDePasDeTempsPourUneOptimisation) { int jour = data.NumeroDeJourDuPasDeTemps[pdtDebut]; - auto& CorrespondanceCntNativesCntOptimJournalieres - = data.CorrespondanceCntNativesCntOptimJournalieres[jour]; for (int index = 0; index < nbInterco; index++) { @@ -72,7 +70,7 @@ void BindingConstraintDay::add(int cntCouplante, BindingConstraintDayData& data) } } - CorrespondanceCntNativesCntOptimJournalieres + data.CorrespondanceCntNativesCntOptimJournalieres[jour] .NumeroDeContrainteDesContraintesCouplantes[cntCouplante] = builder.data.nombreDeContraintes; diff --git a/src/solver/optimisation/BindingConstraintDay.h b/src/solver/optimisation/BindingConstraintDay.h index 1c82d6b513..0f410aebc7 100644 --- a/src/solver/optimisation/BindingConstraintDay.h +++ b/src/solver/optimisation/BindingConstraintDay.h @@ -3,11 +3,55 @@ struct BindingConstraintDayData : public BindingConstraintData { + BindingConstraintDayData(BindingConstraintDayData& data) : + BindingConstraintData(data), + CorrespondanceCntNativesCntOptimJournalieres( + data.CorrespondanceCntNativesCntOptimJournalieres), + NombreDePasDeTempsDUneJournee(data.NombreDePasDeTempsDUneJournee), + NumeroDeJourDuPasDeTemps(data.NumeroDeJourDuPasDeTemps) + { + } + BindingConstraintDayData(const char& TypeDeContrainteCouplante, + const int& NombreDInterconnexionsDansLaContrainteCouplante, + const std::vector& NumeroDeLInterconnexion, + const std::vector& PoidsDeLInterconnexion, + const std::vector& OffsetTemporelSurLInterco, + const int& NombreDePaliersDispatchDansLaContrainteCouplante, + const std::vector& PaysDuPalierDispatch, + const std::vector& NumeroDuPalierDispatch, + const std::vector& PoidsDuPalierDispatch, + const std::vector& OffsetTemporelSurLePalierDispatch, + const char& SensDeLaContrainteCouplante, + const char* const& NomDeLaContrainteCouplante, + const std::vector& PaliersThermiquesDuPays, + std::vector& + CorrespondanceCntNativesCntOptimJournalieres, + const int32_t& NombreDePasDeTempsDUneJournee, + std::vector& NumeroDeJourDuPasDeTemps) : + BindingConstraintData(TypeDeContrainteCouplante, + NombreDInterconnexionsDansLaContrainteCouplante, + NumeroDeLInterconnexion, + PoidsDeLInterconnexion, + OffsetTemporelSurLInterco, + NombreDePaliersDispatchDansLaContrainteCouplante, + PaysDuPalierDispatch, + NumeroDuPalierDispatch, + PoidsDuPalierDispatch, + OffsetTemporelSurLePalierDispatch, + SensDeLaContrainteCouplante, + NomDeLaContrainteCouplante, + PaliersThermiquesDuPays), + CorrespondanceCntNativesCntOptimJournalieres(CorrespondanceCntNativesCntOptimJournalieres), + NombreDePasDeTempsDUneJournee(NombreDePasDeTempsDUneJournee), + NumeroDeJourDuPasDeTemps(NumeroDeJourDuPasDeTemps) + { + } + // std::vector&>& CorrespondanceCntNativesCntOptimJournalieres; std::vector& CorrespondanceCntNativesCntOptimJournalieres; - const int32_t NombreDePasDeTempsDUneJournee; + const int32_t& NombreDePasDeTempsDUneJournee; std::vector& NumeroDeJourDuPasDeTemps; }; diff --git a/src/solver/optimisation/BindingConstraintHour.h b/src/solver/optimisation/BindingConstraintHour.h index 68cf6258d1..b08f2b9db5 100644 --- a/src/solver/optimisation/BindingConstraintHour.h +++ b/src/solver/optimisation/BindingConstraintHour.h @@ -3,6 +3,42 @@ struct BindingConstraintHourData : public BindingConstraintData { + BindingConstraintHourData(BindingConstraintHourData& data) : + BindingConstraintData(data), + NumeroDeContrainteDesContraintesCouplantes(data.NumeroDeContrainteDesContraintesCouplantes) + { + } + BindingConstraintHourData(const char& TypeDeContrainteCouplante, + const int& NombreDInterconnexionsDansLaContrainteCouplante, + const std::vector& NumeroDeLInterconnexion, + const std::vector& PoidsDeLInterconnexion, + const std::vector& OffsetTemporelSurLInterco, + const int& NombreDePaliersDispatchDansLaContrainteCouplante, + const std::vector& PaysDuPalierDispatch, + const std::vector& NumeroDuPalierDispatch, + const std::vector& PoidsDuPalierDispatch, + const std::vector& OffsetTemporelSurLePalierDispatch, + const char& SensDeLaContrainteCouplante, + const char* const& NomDeLaContrainteCouplante, + const std::vector& PaliersThermiquesDuPays, + std::vector& NumeroDeContrainteDesContraintesCouplantes) : + BindingConstraintData(TypeDeContrainteCouplante, + NombreDInterconnexionsDansLaContrainteCouplante, + NumeroDeLInterconnexion, + PoidsDeLInterconnexion, + OffsetTemporelSurLInterco, + NombreDePaliersDispatchDansLaContrainteCouplante, + PaysDuPalierDispatch, + NumeroDuPalierDispatch, + PoidsDuPalierDispatch, + OffsetTemporelSurLePalierDispatch, + SensDeLaContrainteCouplante, + NomDeLaContrainteCouplante, + PaliersThermiquesDuPays), + NumeroDeContrainteDesContraintesCouplantes(NumeroDeContrainteDesContraintesCouplantes) + { + } + std::vector& NumeroDeContrainteDesContraintesCouplantes; }; diff --git a/src/solver/optimisation/BindingConstraintWeek.cpp b/src/solver/optimisation/BindingConstraintWeek.cpp index 128387b415..8c103617ff 100644 --- a/src/solver/optimisation/BindingConstraintWeek.cpp +++ b/src/solver/optimisation/BindingConstraintWeek.cpp @@ -3,8 +3,6 @@ void BindingConstraintWeek::add(int cntCouplante, BindingConstraintWeekData& data) { int semaine = builder.data.weekInTheYear; - auto& NumeroDeContrainteDesContraintesCouplantes - = data.NumeroDeContrainteDesContraintesCouplantes; if (data.TypeDeContrainteCouplante != CONTRAINTE_HEBDOMADAIRE) return; @@ -69,7 +67,8 @@ void BindingConstraintWeek::add(int cntCouplante, BindingConstraintWeekData& dat char op = data.SensDeLaContrainteCouplante; builder.operatorRHS(op); - NumeroDeContrainteDesContraintesCouplantes[cntCouplante] = builder.data.nombreDeContraintes; + data.NumeroDeContrainteDesContraintesCouplantes[cntCouplante] + = builder.data.nombreDeContraintes; // Name { ConstraintNamer namer(builder.data.NomDesContraintes, builder.data.NamedProblems); diff --git a/src/solver/optimisation/BindingConstraintWeek.h b/src/solver/optimisation/BindingConstraintWeek.h index 347db31c45..8648537456 100644 --- a/src/solver/optimisation/BindingConstraintWeek.h +++ b/src/solver/optimisation/BindingConstraintWeek.h @@ -3,6 +3,42 @@ struct BindingConstraintWeekData : public BindingConstraintData { + BindingConstraintWeekData(BindingConstraintWeekData& data) : + BindingConstraintData(data), + NumeroDeContrainteDesContraintesCouplantes(data.NumeroDeContrainteDesContraintesCouplantes) + { + } + + BindingConstraintWeekData(const char& TypeDeContrainteCouplante, + const int& NombreDInterconnexionsDansLaContrainteCouplante, + const std::vector& NumeroDeLInterconnexion, + const std::vector& PoidsDeLInterconnexion, + const std::vector& OffsetTemporelSurLInterco, + const int& NombreDePaliersDispatchDansLaContrainteCouplante, + const std::vector& PaysDuPalierDispatch, + const std::vector& NumeroDuPalierDispatch, + const std::vector& PoidsDuPalierDispatch, + const std::vector& OffsetTemporelSurLePalierDispatch, + const char& SensDeLaContrainteCouplante, + const char* const& NomDeLaContrainteCouplante, + const std::vector& PaliersThermiquesDuPays, + std::vector& NumeroDeContrainteDesContraintesCouplantes) : + BindingConstraintData(TypeDeContrainteCouplante, + NombreDInterconnexionsDansLaContrainteCouplante, + NumeroDeLInterconnexion, + PoidsDeLInterconnexion, + OffsetTemporelSurLInterco, + NombreDePaliersDispatchDansLaContrainteCouplante, + PaysDuPalierDispatch, + NumeroDuPalierDispatch, + PoidsDuPalierDispatch, + OffsetTemporelSurLePalierDispatch, + SensDeLaContrainteCouplante, + NomDeLaContrainteCouplante, + PaliersThermiquesDuPays), + NumeroDeContrainteDesContraintesCouplantes(NumeroDeContrainteDesContraintesCouplantes) + { + } // std::vector&>& CorrespondanceCntNativesCntOptimJournalieres; std::vector& NumeroDeContrainteDesContraintesCouplantes; // CORRESPONDANCES_DES_CONTRAINTES_HEBDOMADAIRES& CorrespondanceCntNativesCntOptimHebdomadaires; diff --git a/src/solver/optimisation/FinalStockEquivalent.h b/src/solver/optimisation/FinalStockEquivalent.h index 39305a59df..810d6ffe45 100644 --- a/src/solver/optimisation/FinalStockEquivalent.h +++ b/src/solver/optimisation/FinalStockEquivalent.h @@ -3,9 +3,9 @@ struct FinalStockEquivalentData { - const int pdt; - const bool AccurateWaterValue; - const bool DirectLevelAccess; + const int& pdt; + const bool& AccurateWaterValue; + const bool& DirectLevelAccess; std::vector& NumeroDeContrainteEquivalenceStockFinal; }; diff --git a/src/solver/optimisation/FinalStockExpression.h b/src/solver/optimisation/FinalStockExpression.h index ae25c22302..5be07115c7 100644 --- a/src/solver/optimisation/FinalStockExpression.h +++ b/src/solver/optimisation/FinalStockExpression.h @@ -4,8 +4,8 @@ struct FinalStockExpressionData { - const int pdt; - const bool AccurateWaterValue; + const int& pdt; + const bool& AccurateWaterValue; std::vector& NumeroDeContrainteExpressionStockFinal; }; class FinalStockExpression : private Constraint diff --git a/src/solver/optimisation/HydroPower.h b/src/solver/optimisation/HydroPower.h index 7e3631095f..05caf5bbe4 100644 --- a/src/solver/optimisation/HydroPower.h +++ b/src/solver/optimisation/HydroPower.h @@ -2,12 +2,12 @@ #include "constraint_builder.h" struct HydroPowerData { - const bool presenceHydro; - const int TurbEntreBornes; - const bool presencePompage; - const int NombreDePasDeTempsPourUneOptimisation; + const bool& presenceHydro; + const int& TurbEntreBornes; + const bool& presencePompage; + const int& NombreDePasDeTempsPourUneOptimisation; std::vector& NumeroDeContrainteEnergieHydraulique; - const double pumpingRatio; + const double& pumpingRatio; }; class HydroPower : private Constraint diff --git a/src/solver/optimisation/MaxHydroPower.h b/src/solver/optimisation/MaxHydroPower.h index c5a039456e..57def58589 100644 --- a/src/solver/optimisation/MaxHydroPower.h +++ b/src/solver/optimisation/MaxHydroPower.h @@ -3,10 +3,10 @@ struct MaxHydroPowerData { - const bool presenceHydro; - const bool TurbEntreBornes; - const bool PresenceDePompageModulable; - const int NombreDePasDeTempsPourUneOptimisation; + const bool& presenceHydro; + const bool& TurbEntreBornes; + const bool& PresenceDePompageModulable; + const int& NombreDePasDeTempsPourUneOptimisation; std::vector& NumeroDeContrainteMaxEnergieHydraulique; }; class MaxHydroPower : private Constraint diff --git a/src/solver/optimisation/MaxPumping.h b/src/solver/optimisation/MaxPumping.h index 91bb0e5ff5..a796678e04 100644 --- a/src/solver/optimisation/MaxPumping.h +++ b/src/solver/optimisation/MaxPumping.h @@ -2,7 +2,7 @@ #include "constraint_builder.h" struct MaxPumpingData { - const bool PresenceDePompageModulable; + const bool& PresenceDePompageModulable; std::vector& NumeroDeContrainteMaxPompage; }; diff --git a/src/solver/optimisation/MinHydroPower.h b/src/solver/optimisation/MinHydroPower.h index e046e44ff8..4d9620a48c 100644 --- a/src/solver/optimisation/MinHydroPower.h +++ b/src/solver/optimisation/MinHydroPower.h @@ -3,10 +3,10 @@ struct MinHydroPowerData { - const bool presenceHydro; - const bool TurbEntreBornes; - const bool PresenceDePompageModulable; - const int NombreDePasDeTempsPourUneOptimisation; + const bool& presenceHydro; + const bool& TurbEntreBornes; + const bool& PresenceDePompageModulable; + const int& NombreDePasDeTempsPourUneOptimisation; std::vector& NumeroDeContrainteMinEnergieHydraulique; }; diff --git a/src/solver/optimisation/constraint_builder.cpp b/src/solver/optimisation/constraint_builder.cpp index d43437636b..3cc8fae217 100644 --- a/src/solver/optimisation/constraint_builder.cpp +++ b/src/solver/optimisation/constraint_builder.cpp @@ -1,9 +1,57 @@ #include "constraint_builder.h" +// for debug +int Variable::Visitor::operator()(const NTCDirect& v) const +{ + return nativeOptimVar.NumeroDeVariableDeLInterconnexion[v.index]; +} + +ConstraintBuilderData::ConstraintBuilderData( + std::vector& Pi, + std::vector& Colonne, + int& nombreDeContraintes, + int& nombreDeTermesDansLaMatriceDeContrainte, + std::vector& IndicesDebutDeLigne, + std::vector& CoefficientsDeLaMatriceDesContraintes, + std::vector& IndicesColonnes, + int& NombreDeTermesAllouesDansLaMatriceDesContraintes, + std::vector& NombreDeTermesDesLignes, + std::string& Sens, + int& IncrementDAllocationMatriceDesContraintes, + const std::vector& CorrespondanceVarNativesVarOptim, + const int32_t& NombreDePasDeTempsPourUneOptimisation, + const std::vector& NumeroDeVariableStockFinal, + const std::vector>& NumeroDeVariableDeTrancheDeStock, + std::vector& NomDesContraintes, + const bool& NamedProblems, + const std::vector& NomsDesPays, + const uint32_t& weekInTheYear, + const uint32_t& NombreDePasDeTemps) : + Pi(Pi), + Colonne(Colonne), + nombreDeContraintes(nombreDeContraintes), + nombreDeTermesDansLaMatriceDeContrainte(nombreDeTermesDansLaMatriceDeContrainte), + IndicesDebutDeLigne(IndicesDebutDeLigne), + CoefficientsDeLaMatriceDesContraintes(CoefficientsDeLaMatriceDesContraintes), + IndicesColonnes(IndicesColonnes), + NombreDeTermesAllouesDansLaMatriceDesContraintes(NombreDeTermesAllouesDansLaMatriceDesContraintes), + NombreDeTermesDesLignes(NombreDeTermesDesLignes), + Sens(Sens), + IncrementDAllocationMatriceDesContraintes(IncrementDAllocationMatriceDesContraintes), + CorrespondanceVarNativesVarOptim(CorrespondanceVarNativesVarOptim), + NombreDePasDeTempsPourUneOptimisation(NombreDePasDeTempsPourUneOptimisation), + NumeroDeVariableStockFinal(NumeroDeVariableStockFinal), + NumeroDeVariableDeTrancheDeStock(NumeroDeVariableDeTrancheDeStock), + NomDesContraintes(NomDesContraintes), + NamedProblems(NamedProblems), + NomsDesPays(NomsDesPays), + weekInTheYear(weekInTheYear), + NombreDePasDeTemps(NombreDePasDeTemps) +{ +} + void ConstraintBuilder::build() { - std::vector& Pi = data.Pi; - std::vector& Colonne = data.Colonne; // TODO check operator_ if (nombreDeTermes_ > 0) { @@ -18,8 +66,8 @@ int ConstraintBuilder::getVariableIndex(const Variable::Variant& variable, bool wrap, int delta) const { - int pdt = hourInWeek_ + shift; - const int nbTimeSteps = data.NombreDePasDeTempsPourUneOptimisation; + auto pdt = hourInWeek_ + shift; + const auto nbTimeSteps = data.NombreDePasDeTempsPourUneOptimisation; // if (wrap) // { // pdt %= nbTimeSteps; @@ -42,6 +90,7 @@ int ConstraintBuilder::getVariableIndex(const Variable::Variant& variable, pdt = (pdt + delta) % nbTimeSteps; } } + // auto& a = data.CorrespondanceVarNativesVarOptim[pdt]; const Variable::Visitor visitor(data.CorrespondanceVarNativesVarOptim[pdt], data.NumeroDeVariableStockFinal, data.NumeroDeVariableDeTrancheDeStock); @@ -54,13 +103,11 @@ ConstraintBuilder& ConstraintBuilder::include(Variable::Variant var, bool wrap, int delta) { - std::vector& Pi = data.Pi; - std::vector& Colonne = data.Colonne; int varIndex = getVariableIndex(var, shift, wrap, delta); if (varIndex >= 0) { - Pi[nombreDeTermes_] = coeff; - Colonne[nombreDeTermes_] = varIndex; + data.Pi[nombreDeTermes_] = coeff; + data.Colonne[nombreDeTermes_] = varIndex; nombreDeTermes_++; } return *this; @@ -68,27 +115,29 @@ ConstraintBuilder& ConstraintBuilder::include(Variable::Variant var, void ConstraintBuilder::OPT_ChargerLaContrainteDansLaMatriceDesContraintes() { - int& nombreDeContraintes = data.nombreDeContraintes; - int& nombreDeTermesDansLaMatriceDeContrainte = data.nombreDeTermesDansLaMatriceDeContrainte; - std::vector& Pi = data.Pi; - std::vector& Colonne = data.Colonne; + // int& nombreDeContraintes = data.nombreDeContraintes; + // int& nombreDeTermesDansLaMatriceDeContrainte = data.nombreDeTermesDansLaMatriceDeContrainte; + // std::vector& Pi = data.Pi; + // std::vector& Colonne = data.Colonne; - data.IndicesDebutDeLigne[nombreDeContraintes] = nombreDeTermesDansLaMatriceDeContrainte; + data.IndicesDebutDeLigne[data.nombreDeContraintes] + = data.nombreDeTermesDansLaMatriceDeContrainte; for (int i = 0; i < nombreDeTermes_; i++) { - data.CoefficientsDeLaMatriceDesContraintes[nombreDeTermesDansLaMatriceDeContrainte] = Pi[i]; - data.IndicesColonnes[nombreDeTermesDansLaMatriceDeContrainte] = Colonne[i]; - nombreDeTermesDansLaMatriceDeContrainte++; - if (nombreDeTermesDansLaMatriceDeContrainte + data.CoefficientsDeLaMatriceDesContraintes[data.nombreDeTermesDansLaMatriceDeContrainte] + = data.Pi[i]; + data.IndicesColonnes[data.nombreDeTermesDansLaMatriceDeContrainte] = data.Colonne[i]; + data.nombreDeTermesDansLaMatriceDeContrainte++; + if (data.nombreDeTermesDansLaMatriceDeContrainte == data.NombreDeTermesAllouesDansLaMatriceDesContraintes) { OPT_AugmenterLaTailleDeLaMatriceDesContraintes(); } } - data.NombreDeTermesDesLignes[nombreDeContraintes] = nombreDeTermes_; + data.NombreDeTermesDesLignes[data.nombreDeContraintes] = nombreDeTermes_; - data.Sens[nombreDeContraintes] = operator_; - nombreDeContraintes++; + data.Sens[data.nombreDeContraintes] = operator_; + data.nombreDeContraintes++; return; } diff --git a/src/solver/optimisation/constraint_builder.h b/src/solver/optimisation/constraint_builder.h index 13be5511fb..ed4c4fc496 100644 --- a/src/solver/optimisation/constraint_builder.h +++ b/src/solver/optimisation/constraint_builder.h @@ -170,10 +170,7 @@ class Visitor return nativeOptimVar .NumeroDeVariableDuNombreDeGroupesQuiTombentEnPanneDuPalierThermique[v.index]; } - int operator()(const NTCDirect& v) const - { - return nativeOptimVar.NumeroDeVariableDeLInterconnexion[v.index]; - } + int operator()(const NTCDirect& v) const; int operator()(const IntercoDirectCost& v) const { return nativeOptimVar.NumeroDeVariableCoutOrigineVersExtremiteDeLInterconnexion[v.index]; @@ -242,8 +239,61 @@ class Visitor }; } // namespace Variable -struct ConstraintBuilderData +class ConstraintBuilderData { +public: + ConstraintBuilderData() = delete; + ConstraintBuilderData(const ConstraintBuilderData& other) = delete; + ConstraintBuilderData(ConstraintBuilderData&&) = delete; + + explicit ConstraintBuilderData(ConstraintBuilderData& data) : + Pi(data.Pi), + Colonne(data.Colonne), + nombreDeContraintes(data.nombreDeContraintes), + nombreDeTermesDansLaMatriceDeContrainte(data.nombreDeTermesDansLaMatriceDeContrainte), + IndicesDebutDeLigne(data.IndicesDebutDeLigne), + CoefficientsDeLaMatriceDesContraintes(data.CoefficientsDeLaMatriceDesContraintes), + IndicesColonnes(data.IndicesColonnes), + NombreDeTermesAllouesDansLaMatriceDesContraintes( + data.NombreDeTermesAllouesDansLaMatriceDesContraintes), + NombreDeTermesDesLignes(data.NombreDeTermesDesLignes), + Sens(data.Sens), + IncrementDAllocationMatriceDesContraintes(data.IncrementDAllocationMatriceDesContraintes), + CorrespondanceVarNativesVarOptim(data.CorrespondanceVarNativesVarOptim), + NombreDePasDeTempsPourUneOptimisation(data.NombreDePasDeTempsPourUneOptimisation), + NumeroDeVariableStockFinal(data.NumeroDeVariableStockFinal), + NumeroDeVariableDeTrancheDeStock(data.NumeroDeVariableDeTrancheDeStock), + NomDesContraintes(data.NomDesContraintes), + NamedProblems(data.NamedProblems), + NomsDesPays(data.NomsDesPays), + weekInTheYear(data.weekInTheYear), + NombreDePasDeTemps(data.NombreDePasDeTemps) + + { + } + + explicit ConstraintBuilderData( + std::vector& Pi, + std::vector& Colonne, + int& nombreDeContraintes, + int& nombreDeTermesDansLaMatriceDeContrainte, + std::vector& IndicesDebutDeLigne, + std::vector& CoefficientsDeLaMatriceDesContraintes, + std::vector& IndicesColonnes, + int& NombreDeTermesAllouesDansLaMatriceDesContraintes, + std::vector& NombreDeTermesDesLignes, + std::string& Sens, + int& IncrementDAllocationMatriceDesContraintes, + const std::vector& CorrespondanceVarNativesVarOptim, + const int32_t& NombreDePasDeTempsPourUneOptimisation, + const std::vector& NumeroDeVariableStockFinal, + const std::vector>& NumeroDeVariableDeTrancheDeStock, + std::vector& NomDesContraintes, + const bool& NamedProblems, + const std::vector& NomsDesPays, + const uint32_t& weekInTheYear, + const uint32_t& NombreDePasDeTemps); + std::vector& Pi; std::vector& Colonne; int& nombreDeContraintes; @@ -256,19 +306,25 @@ struct ConstraintBuilderData std::string& Sens; int& IncrementDAllocationMatriceDesContraintes; const std::vector& CorrespondanceVarNativesVarOptim; - const int32_t NombreDePasDeTempsPourUneOptimisation; + const int32_t& NombreDePasDeTempsPourUneOptimisation; const std::vector& NumeroDeVariableStockFinal; const std::vector>& NumeroDeVariableDeTrancheDeStock; std::vector& NomDesContraintes; - const bool NamedProblems; + const bool& NamedProblems; const std::vector& NomsDesPays; - const uint32_t weekInTheYear; - const uint32_t NombreDePasDeTemps; + const uint32_t& weekInTheYear; + const uint32_t& NombreDePasDeTemps; }; class ConstraintBuilder { public: - ConstraintBuilder(ConstraintBuilderData& data) : data(data) + ConstraintBuilder() = delete; + ConstraintBuilder(const ConstraintBuilder& other) = delete; + ConstraintBuilder(ConstraintBuilder&&) = delete; + explicit ConstraintBuilder(ConstraintBuilder& other) : ConstraintBuilder(other.data) + { + } + explicit ConstraintBuilder(ConstraintBuilderData& data) : data(data) { } @@ -341,6 +397,8 @@ class ConstraintBuilder class Constraint { public: + Constraint() = delete; + explicit Constraint(const Constraint& other) = delete; explicit Constraint(ConstraintBuilder& builder) : builder(builder) { } @@ -360,20 +418,75 @@ inline void exportPaliers(const PALIERS_THERMIQUES& PaliersThermiquesDuPays, } } -struct BindingConstraintData +class BindingConstraintData { - const char TypeDeContrainteCouplante; - const int NombreDInterconnexionsDansLaContrainteCouplante; +public: + BindingConstraintData() = delete; + BindingConstraintData(const BindingConstraintData& other) = delete; + BindingConstraintData(BindingConstraintData&&) = delete; + BindingConstraintData(const char& TypeDeContrainteCouplante, + const int& NombreDInterconnexionsDansLaContrainteCouplante, + const std::vector& NumeroDeLInterconnexion, + const std::vector& PoidsDeLInterconnexion, + const std::vector& OffsetTemporelSurLInterco, + const int& NombreDePaliersDispatchDansLaContrainteCouplante, + const std::vector& PaysDuPalierDispatch, + const std::vector& NumeroDuPalierDispatch, + const std::vector& PoidsDuPalierDispatch, + const std::vector& OffsetTemporelSurLePalierDispatch, + const char& SensDeLaContrainteCouplante, + const char* const& NomDeLaContrainteCouplante, + const std::vector& PaliersThermiquesDuPays) : + + TypeDeContrainteCouplante(TypeDeContrainteCouplante), + NombreDInterconnexionsDansLaContrainteCouplante( + NombreDInterconnexionsDansLaContrainteCouplante), + NumeroDeLInterconnexion(NumeroDeLInterconnexion), + PoidsDeLInterconnexion(PoidsDeLInterconnexion), + OffsetTemporelSurLInterco(OffsetTemporelSurLInterco), + NombreDePaliersDispatchDansLaContrainteCouplante( + NombreDePaliersDispatchDansLaContrainteCouplante), + PaysDuPalierDispatch(PaysDuPalierDispatch), + NumeroDuPalierDispatch(NumeroDuPalierDispatch), + PoidsDuPalierDispatch(PoidsDuPalierDispatch), + OffsetTemporelSurLePalierDispatch(OffsetTemporelSurLePalierDispatch), + SensDeLaContrainteCouplante(SensDeLaContrainteCouplante), + NomDeLaContrainteCouplante(NomDeLaContrainteCouplante), + PaliersThermiquesDuPays(PaliersThermiquesDuPays) + { + } + BindingConstraintData(BindingConstraintData& data) : + + TypeDeContrainteCouplante(data.TypeDeContrainteCouplante), + NombreDInterconnexionsDansLaContrainteCouplante( + data.NombreDInterconnexionsDansLaContrainteCouplante), + NumeroDeLInterconnexion(data.NumeroDeLInterconnexion), + PoidsDeLInterconnexion(data.PoidsDeLInterconnexion), + OffsetTemporelSurLInterco(data.OffsetTemporelSurLInterco), + NombreDePaliersDispatchDansLaContrainteCouplante( + data.NombreDePaliersDispatchDansLaContrainteCouplante), + PaysDuPalierDispatch(data.PaysDuPalierDispatch), + NumeroDuPalierDispatch(data.NumeroDuPalierDispatch), + PoidsDuPalierDispatch(data.PoidsDuPalierDispatch), + OffsetTemporelSurLePalierDispatch(data.OffsetTemporelSurLePalierDispatch), + SensDeLaContrainteCouplante(data.SensDeLaContrainteCouplante), + NomDeLaContrainteCouplante(data.NomDeLaContrainteCouplante), + PaliersThermiquesDuPays(data.PaliersThermiquesDuPays) + { + } + + const char& TypeDeContrainteCouplante; + const int& NombreDInterconnexionsDansLaContrainteCouplante; const std::vector& NumeroDeLInterconnexion; const std::vector& PoidsDeLInterconnexion; const std::vector& OffsetTemporelSurLInterco; - const int NombreDePaliersDispatchDansLaContrainteCouplante; + const int& NombreDePaliersDispatchDansLaContrainteCouplante; const std::vector& PaysDuPalierDispatch; const std::vector& NumeroDuPalierDispatch; const std::vector& PoidsDuPalierDispatch; const std::vector& OffsetTemporelSurLePalierDispatch; - const char SensDeLaContrainteCouplante; - const char* NomDeLaContrainteCouplante; + const char& SensDeLaContrainteCouplante; + const char* const& NomDeLaContrainteCouplante; const std::vector& PaliersThermiquesDuPays; }; diff --git a/src/solver/optimisation/constraint_builder_utils.cpp b/src/solver/optimisation/constraint_builder_utils.cpp index cfe14da083..7421b45ee3 100644 --- a/src/solver/optimisation/constraint_builder_utils.cpp +++ b/src/solver/optimisation/constraint_builder_utils.cpp @@ -4,7 +4,7 @@ ConstraintBuilder GetConstraintBuilderFromProblemHebdoAndProblemAResoudre( const PROBLEME_HEBDO* problemeHebdo, PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre) { - ConstraintBuilderData data{ProblemeAResoudre->Pi, + ConstraintBuilderData data(ProblemeAResoudre->Pi, ProblemeAResoudre->Colonne, ProblemeAResoudre->NombreDeContraintes, ProblemeAResoudre->NombreDeTermesDansLaMatriceDesContraintes, @@ -23,7 +23,7 @@ ConstraintBuilder GetConstraintBuilderFromProblemHebdoAndProblemAResoudre( problemeHebdo->NamedProblems, problemeHebdo->NomsDesPays, problemeHebdo->weekInTheYear, - problemeHebdo->NombreDePasDeTemps}; + problemeHebdo->NombreDePasDeTemps); return ConstraintBuilder(data); } \ No newline at end of file diff --git a/src/solver/optimisation/opt_construction_contraintes_couts_demarrage.cpp b/src/solver/optimisation/opt_construction_contraintes_couts_demarrage.cpp index 38d17ee1e6..bb88cc480c 100644 --- a/src/solver/optimisation/opt_construction_contraintes_couts_demarrage.cpp +++ b/src/solver/optimisation/opt_construction_contraintes_couts_demarrage.cpp @@ -47,12 +47,13 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( bool Simulation) { PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre = problemeHebdo->ProblemeAResoudre.get(); - ConstraintBuilder builder(GetConstraintBuilderFromProblemHebdo(problemeHebdo)); + + ConstraintBuilder builder = GetConstraintBuilderFromProblemHebdo(problemeHebdo); int nombreDePasDeTempsPourUneOptimisation = problemeHebdo->NombreDePasDeTempsPourUneOptimisation; - std::vector& Pi = ProblemeAResoudre->Pi; - std::vector& Colonne = ProblemeAResoudre->Colonne; + // std::vector& Pi = ProblemeAResoudre->Pi; + // std::vector& Colonne = ProblemeAResoudre->Colonne; ConstraintNamer constraintNamer(ProblemeAResoudre->NomDesContraintes, problemeHebdo->NamedProblems); @@ -120,11 +121,11 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) { - CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim - = problemeHebdo->CorrespondanceCntNativesCntOptim[pdt]; + // CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim + // = problemeHebdo->CorrespondanceCntNativesCntOptim[pdt]; NbUnitsOutageLessThanNbUnitsStopData nbUnitsOutageLessThanNbUnitsStopData - = {startUpCostsData, - CorrespondanceCntNativesCntOptim + = {startUpCostsData.PaliersThermiquesDuPays, + problemeHebdo->CorrespondanceCntNativesCntOptim[pdt] .NumeroDeContrainteDesContraintesDeDureeMinDeMarche}; nbUnitsOutageLessThanNbUnitsStop.add( pays, palier, index, pdt, Simulation, nbUnitsOutageLessThanNbUnitsStopData); @@ -151,11 +152,11 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) { - CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim - = problemeHebdo->CorrespondanceCntNativesCntOptim[pdt]; + // CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim + // = problemeHebdo->CorrespondanceCntNativesCntOptim[pdt]; NbDispUnitsMinBoundSinceMinUpTimeData nbDispUnitsMinBoundSinceMinUpTimeData - = {startUpCostsData, - CorrespondanceCntNativesCntOptim + = {startUpCostsData.PaliersThermiquesDuPays, + problemeHebdo->CorrespondanceCntNativesCntOptim[pdt] .NumeroDeContrainteDesContraintesDeDureeMinDeMarche}; nbDispUnitsMinBoundSinceMinUpTime.add( pays, palier, index, pdt, Simulation, nbDispUnitsMinBoundSinceMinUpTimeData); @@ -177,11 +178,11 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) { - CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim - = problemeHebdo->CorrespondanceCntNativesCntOptim[pdt]; + // CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim + // = problemeHebdo->CorrespondanceCntNativesCntOptim[pdt]; MinDownTimeData minDownTimeData - = {startUpCostsData, - CorrespondanceCntNativesCntOptim + = {startUpCostsData.PaliersThermiquesDuPays, + problemeHebdo->CorrespondanceCntNativesCntOptim[pdt] .NumeroDeContrainteDesContraintesDeDureeMinDArret}; minDownTime.add(pays, palier, index, pdt, Simulation, minDownTimeData); 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 6650b536c3..01acc670f4 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 @@ -80,11 +80,26 @@ static BindingConstraintHourData GetBindingConstraintHourDataFromProblemHebdo( const CONTRAINTES_COUPLANTES& MatriceDesContraintesCouplantes = problemeHebdo->MatriceDesContraintesCouplantes[cntCouplante]; - CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim - = problemeHebdo->CorrespondanceCntNativesCntOptim[pdt]; - BindingConstraintData data - = GetBindingConstraintDataFromProblemHebdo(problemeHebdo, cntCouplante); - return {data, CorrespondanceCntNativesCntOptim.NumeroDeContrainteDesContraintesCouplantes}; + // CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim + // = problemeHebdo->CorrespondanceCntNativesCntOptim[pdt]; + // BindingConstraintData data + // = GetBindingConstraintDataFromProblemHebdo(problemeHebdo, cntCouplante); + return BindingConstraintHourData( + MatriceDesContraintesCouplantes.TypeDeContrainteCouplante, + MatriceDesContraintesCouplantes.NombreDInterconnexionsDansLaContrainteCouplante, + MatriceDesContraintesCouplantes.NumeroDeLInterconnexion, + MatriceDesContraintesCouplantes.PoidsDeLInterconnexion, + MatriceDesContraintesCouplantes.OffsetTemporelSurLInterco, + MatriceDesContraintesCouplantes.NombreDePaliersDispatchDansLaContrainteCouplante, + MatriceDesContraintesCouplantes.PaysDuPalierDispatch, + MatriceDesContraintesCouplantes.NumeroDuPalierDispatch, + MatriceDesContraintesCouplantes.PoidsDuPalierDispatch, + MatriceDesContraintesCouplantes.OffsetTemporelSurLePalierDispatch, + MatriceDesContraintesCouplantes.SensDeLaContrainteCouplante, + MatriceDesContraintesCouplantes.NomDeLaContrainteCouplante, + problemeHebdo->PaliersThermiquesDuPays, + problemeHebdo->CorrespondanceCntNativesCntOptim[pdt] + .NumeroDeContrainteDesContraintesCouplantes); } static BindingConstraintDayData GetBindingConstraintDayDataFromProblemHebdo( @@ -94,8 +109,8 @@ static BindingConstraintDayData GetBindingConstraintDayDataFromProblemHebdo( const CONTRAINTES_COUPLANTES& MatriceDesContraintesCouplantes = problemeHebdo->MatriceDesContraintesCouplantes[cntCouplante]; - BindingConstraintData data - = GetBindingConstraintDataFromProblemHebdo(problemeHebdo, cntCouplante); + // BindingConstraintData data + // = GetBindingConstraintDataFromProblemHebdo(problemeHebdo, cntCouplante); // TODO transfrom std::vector into // std::vector&>& // std::vector> correspondanceCntNativesCntOptimJournalieres; @@ -105,10 +120,23 @@ static BindingConstraintDayData GetBindingConstraintDayDataFromProblemHebdo( // [](CORRESPONDANCES_DES_CONTRAINTES_JOURNALIERES& corr) -> std::vector& // { return corr.NumeroDeContrainteDesContraintesCouplantes; }); - return {data, - problemeHebdo->CorrespondanceCntNativesCntOptimJournalieres, - problemeHebdo->NombreDePasDeTempsDUneJournee, - problemeHebdo->NumeroDeJourDuPasDeTemps}; + return BindingConstraintDayData( + MatriceDesContraintesCouplantes.TypeDeContrainteCouplante, + MatriceDesContraintesCouplantes.NombreDInterconnexionsDansLaContrainteCouplante, + MatriceDesContraintesCouplantes.NumeroDeLInterconnexion, + MatriceDesContraintesCouplantes.PoidsDeLInterconnexion, + MatriceDesContraintesCouplantes.OffsetTemporelSurLInterco, + MatriceDesContraintesCouplantes.NombreDePaliersDispatchDansLaContrainteCouplante, + MatriceDesContraintesCouplantes.PaysDuPalierDispatch, + MatriceDesContraintesCouplantes.NumeroDuPalierDispatch, + MatriceDesContraintesCouplantes.PoidsDuPalierDispatch, + MatriceDesContraintesCouplantes.OffsetTemporelSurLePalierDispatch, + MatriceDesContraintesCouplantes.SensDeLaContrainteCouplante, + MatriceDesContraintesCouplantes.NomDeLaContrainteCouplante, + problemeHebdo->PaliersThermiquesDuPays, + problemeHebdo->CorrespondanceCntNativesCntOptimJournalieres, + problemeHebdo->NombreDePasDeTempsDUneJournee, + problemeHebdo->NumeroDeJourDuPasDeTemps); } static BindingConstraintWeekData GetBindingConstraintWeekDataFromProblemHebdo( PROBLEME_HEBDO* problemeHebdo, @@ -117,12 +145,25 @@ static BindingConstraintWeekData GetBindingConstraintWeekDataFromProblemHebdo( const CONTRAINTES_COUPLANTES& MatriceDesContraintesCouplantes = problemeHebdo->MatriceDesContraintesCouplantes[cntCouplante]; - BindingConstraintData data - = GetBindingConstraintDataFromProblemHebdo(problemeHebdo, cntCouplante); - - return {data, - problemeHebdo->CorrespondanceCntNativesCntOptimHebdomadaires - .NumeroDeContrainteDesContraintesCouplantes}; + // BindingConstraintData data + // = GetBindingConstraintDataFromProblemHebdo(problemeHebdo, cntCouplante); + + return BindingConstraintWeekData( + MatriceDesContraintesCouplantes.TypeDeContrainteCouplante, + MatriceDesContraintesCouplantes.NombreDInterconnexionsDansLaContrainteCouplante, + MatriceDesContraintesCouplantes.NumeroDeLInterconnexion, + MatriceDesContraintesCouplantes.PoidsDeLInterconnexion, + MatriceDesContraintesCouplantes.OffsetTemporelSurLInterco, + MatriceDesContraintesCouplantes.NombreDePaliersDispatchDansLaContrainteCouplante, + MatriceDesContraintesCouplantes.PaysDuPalierDispatch, + MatriceDesContraintesCouplantes.NumeroDuPalierDispatch, + MatriceDesContraintesCouplantes.PoidsDuPalierDispatch, + MatriceDesContraintesCouplantes.OffsetTemporelSurLePalierDispatch, + MatriceDesContraintesCouplantes.SensDeLaContrainteCouplante, + MatriceDesContraintesCouplantes.NomDeLaContrainteCouplante, + problemeHebdo->PaliersThermiquesDuPays, + problemeHebdo->CorrespondanceCntNativesCntOptimHebdomadaires + .NumeroDeContrainteDesContraintesCouplantes); } static HydroPowerData GetHydroPowerDataFromProblemHebdo(PROBLEME_HEBDO* problemeHebdo, @@ -167,16 +208,16 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro int nombreDePasDeTempsPourUneOptimisation = problemeHebdo->NombreDePasDeTempsPourUneOptimisation; - std::vector& Pi = ProblemeAResoudre->Pi; - std::vector& Colonne = ProblemeAResoudre->Colonne; + // std::vector& Pi = ProblemeAResoudre->Pi; + // std::vector& Colonne = ProblemeAResoudre->Colonne; ProblemeAResoudre->NombreDeContraintes = 0; ProblemeAResoudre->NombreDeTermesDansLaMatriceDesContraintes = 0; ConstraintNamer constraintNamer(ProblemeAResoudre->NomDesContraintes, problemeHebdo->NamedProblems); - ConstraintBuilder builder(GetConstraintBuilderFromProblemHebdo(problemeHebdo)); + ConstraintBuilder builder = GetConstraintBuilderFromProblemHebdo(problemeHebdo); + AreaBalance areaBalance = AreaBalance(builder); - AreaBalance areaBalance(builder); FictitiousLoad fictitiousLoad(builder); ShortTermStorageLevel shortTermStorageLevel(builder); FlowDissociation flowDissociation(builder); @@ -202,34 +243,36 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro { int timeStepInYear = problemeHebdo->weekInTheYear * 168 + pdt; constraintNamer.UpdateTimeStep(timeStepInYear); - CORRESPONDANCES_DES_VARIABLES& CorrespondanceVarNativesVarOptim = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt]; - CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim - = problemeHebdo->CorrespondanceCntNativesCntOptim[pdt]; + // CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim + // = problemeHebdo->CorrespondanceCntNativesCntOptim[pdt]; for (uint32_t pays = 0; pays < problemeHebdo->NombreDePays; pays++) { - AreaBalanceData areaBalanceData{ - CorrespondanceCntNativesCntOptim.NumeroDeContrainteDesBilansPays, - CorrespondanceVarNativesVarOptim.SIM_ShortTermStorage.InjectionVariable, - CorrespondanceVarNativesVarOptim.SIM_ShortTermStorage.WithdrawalVariable, + AreaBalanceData areaBalanceData( + problemeHebdo->CorrespondanceCntNativesCntOptim[pdt].NumeroDeContrainteDesBilansPays, + problemeHebdo->CorrespondanceVarNativesVarOptim[pdt] + .SIM_ShortTermStorage.InjectionVariable, + problemeHebdo->CorrespondanceVarNativesVarOptim[pdt] + .SIM_ShortTermStorage.WithdrawalVariable, problemeHebdo->IndexDebutIntercoOrigine, problemeHebdo->IndexSuivantIntercoOrigine, problemeHebdo->IndexDebutIntercoExtremite, problemeHebdo->IndexSuivantIntercoExtremite, problemeHebdo->PaliersThermiquesDuPays[pays], - problemeHebdo->ShortTermStorage}; + problemeHebdo->ShortTermStorage); areaBalance.add(pdt, pays, areaBalanceData); FictitiousLoadData fictitiousLoadData - = {CorrespondanceCntNativesCntOptim.NumeroDeContraintePourEviterLesChargesFictives, + = {problemeHebdo->CorrespondanceCntNativesCntOptim[pdt] + .NumeroDeContraintePourEviterLesChargesFictives, problemeHebdo->PaliersThermiquesDuPays[pays], problemeHebdo->DefaillanceNegativeUtiliserHydro}; fictitiousLoad.add(pdt, pays, fictitiousLoadData); ShortTermStorageLevelData shortTermStorageLevelData = { - CorrespondanceCntNativesCntOptim.ShortTermStorageLevelConstraint, + problemeHebdo->CorrespondanceCntNativesCntOptim[pdt].ShortTermStorageLevelConstraint, problemeHebdo->ShortTermStorage, }; shortTermStorageLevel.add(pdt, pays, shortTermStorageLevelData); @@ -237,10 +280,9 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro for (uint32_t interco = 0; interco < problemeHebdo->NombreDInterconnexions; interco++) { - CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim - = problemeHebdo->CorrespondanceCntNativesCntOptim[pdt]; FlowDissociationData flowDissociationData - = {CorrespondanceCntNativesCntOptim.NumeroDeContrainteDeDissociationDeFlux, + = {problemeHebdo->CorrespondanceCntNativesCntOptim[pdt] + .NumeroDeContrainteDeDissociationDeFlux, problemeHebdo->CoutDeTransport, problemeHebdo->PaysOrigineDeLInterconnexion, problemeHebdo->PaysExtremiteDeLInterconnexion}; @@ -325,18 +367,18 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++) { - CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim - = problemeHebdo->CorrespondanceCntNativesCntOptim[pdt]; + // CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim + // = problemeHebdo->CorrespondanceCntNativesCntOptim[pdt]; int timeStepInYear = problemeHebdo->weekInTheYear * 168 + pdt; constraintNamer.UpdateTimeStep(timeStepInYear); for (uint32_t pays = 0; pays < problemeHebdo->NombreDePays; pays++) { - AreaHydroLevelData data - = {CorrespondanceCntNativesCntOptim.NumeroDeContrainteDesNiveauxPays, - problemeHebdo->CaracteristiquesHydrauliques[pays].SuiviNiveauHoraire, - problemeHebdo->CaracteristiquesHydrauliques[pays].PumpingRatio}; + AreaHydroLevelData data = { + problemeHebdo->CorrespondanceCntNativesCntOptim[pdt].NumeroDeContrainteDesNiveauxPays, + problemeHebdo->CaracteristiquesHydrauliques[pays].SuiviNiveauHoraire, + problemeHebdo->CaracteristiquesHydrauliques[pays].PumpingRatio}; areaHydroLevel.add(pays, pdt, data); } }