From 8ed7085d3b177ba23b2b8357a8637fcf71654778 Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Tue, 19 Sep 2023 10:41:43 +0200 Subject: [PATCH] implement week binding constraints group --- .../BindingConstraintDayGroup.cpp | 3 +- .../optimisation/BindingConstraintWeek.cpp | 101 ++++++++++-------- .../optimisation/BindingConstraintWeek.h | 13 ++- .../BindingConstraintWeekGroup.cpp | 49 +++++++++ .../optimisation/BindingConstraintWeekGroup.h | 16 +++ src/solver/optimisation/CMakeLists.txt | 2 + .../LinearProblemMatrixBuilder.cpp | 13 --- .../optimisation/LinearProblemMatrixBuilder.h | 7 +- 8 files changed, 141 insertions(+), 63 deletions(-) create mode 100644 src/solver/optimisation/BindingConstraintWeekGroup.cpp create mode 100644 src/solver/optimisation/BindingConstraintWeekGroup.h diff --git a/src/solver/optimisation/BindingConstraintDayGroup.cpp b/src/solver/optimisation/BindingConstraintDayGroup.cpp index 3a8f4ee936..a98d9d8030 100644 --- a/src/solver/optimisation/BindingConstraintDayGroup.cpp +++ b/src/solver/optimisation/BindingConstraintDayGroup.cpp @@ -27,6 +27,7 @@ std::shared_ptr return std::make_shared(data); } + void BindingConstraintDayGroup::Build() { std::shared_ptr builder( @@ -36,7 +37,7 @@ void BindingConstraintDayGroup::Build() for (uint32_t cntCouplante = 0; cntCouplante < problemeHebdo_->NombreDeContraintesCouplantes; cntCouplante++) { - bindingConstraintDay.add(cntCouplante, + bindingConstraintDay.add(cntCouplante, GetBindingConstraintDayDataFromProblemHebdo(cntCouplante)); } } \ No newline at end of file diff --git a/src/solver/optimisation/BindingConstraintWeek.cpp b/src/solver/optimisation/BindingConstraintWeek.cpp index 826549e1e3..ddf32d4dfc 100644 --- a/src/solver/optimisation/BindingConstraintWeek.cpp +++ b/src/solver/optimisation/BindingConstraintWeek.cpp @@ -1,65 +1,80 @@ #include "BindingConstraintWeek.h" -void BindingConstraintWeek::add(int cntCouplante) +void BindingConstraintWeek::add(int cntCouplante, std::shared_ptr data) { - const CONTRAINTES_COUPLANTES& MatriceDesContraintesCouplantes - = problemeHebdo->MatriceDesContraintesCouplantes[cntCouplante]; - int semaine = problemeHebdo->weekInTheYear; - CORRESPONDANCES_DES_CONTRAINTES_HEBDOMADAIRES& CorrespondanceCntNativesCntOptimHebdomadaires - = problemeHebdo->CorrespondanceCntNativesCntOptimHebdomadaires; - if (MatriceDesContraintesCouplantes.TypeDeContrainteCouplante != CONTRAINTE_HEBDOMADAIRE) + int semaine = builder->data->weekInTheYear; + 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]; - for (int pdt = 0; pdt < problemeHebdo->NombreDePasDeTempsPourUneOptimisation; pdt++) + int interco = data->NumeroDeLInterconnexion[index]; + double poids = data->PoidsDeLInterconnexion[index]; + int offset = data->OffsetTemporelSurLInterco[index]; + for (int pdt = 0; pdt < builder->data->NombreDePasDeTempsPourUneOptimisation; pdt++) { - builder.updateHourWithinWeek(pdt).include( - Variable::NTCDirect(interco), poids, offset, true, problemeHebdo->NombreDePasDeTemps); + builder->updateHourWithinWeek(pdt); + int pdt1; + if (offset >= 0) + { + pdt1 = (pdt + offset) % builder->data->NombreDePasDeTempsPourUneOptimisation; + } + else + { + pdt1 = (pdt + offset + builder->data->NombreDePasDeTemps) + % builder->data->NombreDePasDeTempsPourUneOptimisation; + } + builder->updateHourWithinWeek(pdt1).include( + NewVariable::NTCDirect(interco), poids, 0, false, builder->data->NombreDePasDeTemps); } } - for (int index = 0; index < nbClusters; index++) + for (int index = 0; index < nbClusters; index++) + { + int pays = data->PaysDuPalierDispatch[index]; + 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 < builder->data->NombreDePasDeTempsPourUneOptimisation; pdt++) { - 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 pdt1; + + builder->updateHourWithinWeek(pdt); // useless? + if (offset >= 0) + { + pdt1 = (pdt + offset) % builder->data->NombreDePasDeTempsPourUneOptimisation; + } + else { - builder.updateHourWithinWeek(pdt).include(Variable::DispatchableProduction(palier), - poids, - offset, - true, - problemeHebdo->NombreDePasDeTemps); + pdt1 = (pdt + offset + builder->data->NombreDePasDeTemps) + % builder->data->NombreDePasDeTempsPourUneOptimisation; } + + builder->updateHourWithinWeek(pdt1).include(NewVariable::DispatchableProduction(palier), + poids, + offset, + false, + builder->data->NombreDePasDeTemps); } + } - char op = MatriceDesContraintesCouplantes.SensDeLaContrainteCouplante; - builder.SetOperator(op); + char op = data->SensDeLaContrainteCouplante; + builder->operatorRHS(op); - CorrespondanceCntNativesCntOptimHebdomadaires - .NumeroDeContrainteDesContraintesCouplantes[cntCouplante] - = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; + data->NumeroDeContrainteDesContraintesCouplantes[cntCouplante] + = builder->data->nombreDeContraintes; // Name { - ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, - problemeHebdo->NamedProblems); - namer.UpdateTimeStep(semaine); - namer.BindingConstraintWeek(problemeHebdo->ProblemeAResoudre->NombreDeContraintes, - MatriceDesContraintesCouplantes.NomDeLaContrainteCouplante); + ConstraintNamer namer(builder->data->NomDesContraintes, builder->data->NamedProblems); + namer.UpdateTimeStep(semaine); + namer.BindingConstraintWeek(builder->data->nombreDeContraintes, + data->NomDeLaContrainteCouplante); } - builder.build(); + builder->build(); } \ No newline at end of file diff --git a/src/solver/optimisation/BindingConstraintWeek.h b/src/solver/optimisation/BindingConstraintWeek.h index 5d1b945462..388f4a2250 100644 --- a/src/solver/optimisation/BindingConstraintWeek.h +++ b/src/solver/optimisation/BindingConstraintWeek.h @@ -1,9 +1,14 @@ #pragma once -#include "constraint_builder.h" +#include "new_constraint_builder.h" -class BindingConstraintWeek : private Constraint +struct BindingConstraintWeekData : public BindingConstraintData +{ + std::vector& NumeroDeContrainteDesContraintesCouplantes; +}; + +class BindingConstraintWeek : private NewConstraint { public: - using Constraint::Constraint; - void add(int cntCouplante); + using NewConstraint::NewConstraint; + void add(int cntCouplante, std::shared_ptr data); }; \ No newline at end of file diff --git a/src/solver/optimisation/BindingConstraintWeekGroup.cpp b/src/solver/optimisation/BindingConstraintWeekGroup.cpp new file mode 100644 index 0000000000..3b1e2b3d12 --- /dev/null +++ b/src/solver/optimisation/BindingConstraintWeekGroup.cpp @@ -0,0 +1,49 @@ +#include "BindingConstraintWeekGroup.h" +#include "new_constraint_builder_utils.h" + +std::shared_ptr + BindingConstraintWeekGroup::GetBindingConstraintWeekDataFromProblemHebdo(int cntCouplante) +{ + const CONTRAINTES_COUPLANTES& MatriceDesContraintesCouplantes + = problemeHebdo_->MatriceDesContraintesCouplantes[cntCouplante]; + + BindingConstraintWeekData data + = {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}; + + return std::make_shared(data); +} + +void BindingConstraintWeekGroup::Build() +{ + std::shared_ptr builder( + NewGetConstraintBuilderFromProblemHebdo(problemeHebdo_)); + BindingConstraintWeek bindingConstraintWeek(builder); + + if (problemeHebdo_->NombreDePasDeTempsPourUneOptimisation + > problemeHebdo_->NombreDePasDeTempsDUneJournee) + { + CORRESPONDANCES_DES_CONTRAINTES_HEBDOMADAIRES& CorrespondanceCntNativesCntOptimHebdomadaires + = problemeHebdo_->CorrespondanceCntNativesCntOptimHebdomadaires; + for (uint32_t cntCouplante = 0; + cntCouplante < problemeHebdo_->NombreDeContraintesCouplantes; + cntCouplante++) + { + bindingConstraintWeek.add(cntCouplante, + GetBindingConstraintWeekDataFromProblemHebdo(cntCouplante)); + } + } +} \ No newline at end of file diff --git a/src/solver/optimisation/BindingConstraintWeekGroup.h b/src/solver/optimisation/BindingConstraintWeekGroup.h new file mode 100644 index 0000000000..0665f9d859 --- /dev/null +++ b/src/solver/optimisation/BindingConstraintWeekGroup.h @@ -0,0 +1,16 @@ +#pragma once +#include "ConstraintGroup.h" +#include "BindingConstraintWeek.h" + +class BindingConstraintWeekGroup : public ConstraintGroup +{ +public: + using ConstraintGroup::ConstraintGroup; + + /*TODO Rename this*/ + void Build() override; + +private: + std::shared_ptr GetBindingConstraintWeekDataFromProblemHebdo( + int cntCouplante); +}; \ No newline at end of file diff --git a/src/solver/optimisation/CMakeLists.txt b/src/solver/optimisation/CMakeLists.txt index 562d256bf3..9a780613a8 100644 --- a/src/solver/optimisation/CMakeLists.txt +++ b/src/solver/optimisation/CMakeLists.txt @@ -132,6 +132,8 @@ set(RTESOLVER_OPT Group1.cpp BindingConstraintDayGroup.h BindingConstraintDayGroup.cpp + BindingConstraintWeekGroup.h + BindingConstraintWeekGroup.cpp ) diff --git a/src/solver/optimisation/LinearProblemMatrixBuilder.cpp b/src/solver/optimisation/LinearProblemMatrixBuilder.cpp index dca456e1cb..fe30d7d99b 100644 --- a/src/solver/optimisation/LinearProblemMatrixBuilder.cpp +++ b/src/solver/optimisation/LinearProblemMatrixBuilder.cpp @@ -68,7 +68,6 @@ void LinearProblemMatrixBuilder::Run() ConstraintNamer constraintNamer(ProblemeAResoudre->NomDesContraintes, problemeHebdo_->NamedProblems); - BindingConstraintWeek bindingConstraintWeek(problemeHebdo_); HydroPower hydroPower(problemeHebdo_); HydroPowerSmoothingUsingVariationSum hydroPowerSmoothingUsingVariationSum(problemeHebdo_); HydroPowerSmoothingUsingVariationMaxDown hydroPowerSmoothingUsingVariationMaxDown( @@ -90,18 +89,6 @@ void LinearProblemMatrixBuilder::Run() group->Build(); } - if (nombreDePasDeTempsPourUneOptimisation > nombreDePasDeTempsDUneJournee) - { - CORRESPONDANCES_DES_CONTRAINTES_HEBDOMADAIRES& CorrespondanceCntNativesCntOptimHebdomadaires - = problemeHebdo_->CorrespondanceCntNativesCntOptimHebdomadaires; - for (uint32_t cntCouplante = 0; - cntCouplante < problemeHebdo_->NombreDeContraintesCouplantes; - cntCouplante++) - { - bindingConstraintWeek.add(cntCouplante); - } - } - for (uint32_t pays = 0; pays < problemeHebdo_->NombreDePays; pays++) { hydroPower.add(pays); diff --git a/src/solver/optimisation/LinearProblemMatrixBuilder.h b/src/solver/optimisation/LinearProblemMatrixBuilder.h index dc0163e956..e53dc2c0ee 100644 --- a/src/solver/optimisation/LinearProblemMatrixBuilder.h +++ b/src/solver/optimisation/LinearProblemMatrixBuilder.h @@ -29,6 +29,7 @@ #include "ConstraintGroup.h" #include "Group1.h" #include "BindingConstraintDayGroup.h" +#include "BindingConstraintWeekGroup.h" #include @@ -41,9 +42,10 @@ class LinearProblemMatrixBuilder problemeHebdo_(problemeHebdo), writer_(writer), group1_(problemeHebdo), - bindingConstraintDayGroup_(problemeHebdo) + bindingConstraintDayGroup_(problemeHebdo), + bindingConstraintWeekGroup_(problemeHebdo) { - constraintgroups_ = {&group1_, &bindingConstraintDayGroup_}; + constraintgroups_ = {&group1_, &bindingConstraintDayGroup_, &bindingConstraintWeekGroup_}; } void Run(); @@ -51,6 +53,7 @@ class LinearProblemMatrixBuilder private: Group1 group1_; BindingConstraintDayGroup bindingConstraintDayGroup_; + BindingConstraintWeekGroup bindingConstraintWeekGroup_; std::vector constraintgroups_; PROBLEME_HEBDO* problemeHebdo_; Solver::IResultWriter& writer_;