diff --git a/src/solver/optimisation/AreaBalance.cpp b/src/solver/optimisation/AreaBalance.cpp index 94cce06921..13ed6f662c 100644 --- a/src/solver/optimisation/AreaBalance.cpp +++ b/src/solver/optimisation/AreaBalance.cpp @@ -1,18 +1,22 @@ #include "AreaBalance.h" -static void shortTermStorageBalance(const ::ShortTermStorage::AREA_INPUT& shortTermStorageInput, - ConstraintBuilder& constraintBuilder, - std::vector& InjectionVariable, - std::vector& WithdrawalVariable) +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 = InjectionVariable[index]; varInjection >= 0) + if (const int varInjection + = CorrespondanceVarNativesVarOptim.SIM_ShortTermStorage.InjectionVariable[index]; + varInjection >= 0) { constraintBuilder.include(Variable::ShortTermStorageInjection(index), 1.0); } - if (const int varWithdrawal = WithdrawalVariable[index]; varWithdrawal >= 0) + if (const int varWithdrawal + = CorrespondanceVarNativesVarOptim.SIM_ShortTermStorage.WithdrawalVariable[index]; + varWithdrawal >= 0) { constraintBuilder.include(Variable::ShortTermStorageWithdrawal(index), -1.0); } @@ -20,14 +24,15 @@ 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) { /** can be done without this --- keep it for now**/ - NumeroDeContrainteDesBilansPays[pays] = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; + CORRESPONDANCES_DES_VARIABLES& CorrespondanceVarNativesVarOptim + = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt]; + CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim + = problemeHebdo->CorrespondanceCntNativesCntOptim[pdt]; + CorrespondanceCntNativesCntOptim.NumeroDeContrainteDesBilansPays[pays] + = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; /******/ // TODO improve this @@ -62,7 +67,7 @@ void AreaBalance::add(int pdt, .include(Variable::NegativeUnsuppliedEnergy(pays), 1.0); shortTermStorageBalance( - problemeHebdo->ShortTermStorage[pays], builder, InjectionVariable, WithdrawalVariable); + problemeHebdo->ShortTermStorage[pays], builder, CorrespondanceVarNativesVarOptim); builder.equalTo(); builder.build(); diff --git a/src/solver/optimisation/AreaBalance.h b/src/solver/optimisation/AreaBalance.h index 618ba0bbbe..c09900091f 100644 --- a/src/solver/optimisation/AreaBalance.h +++ b/src/solver/optimisation/AreaBalance.h @@ -6,9 +6,5 @@ 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); }; \ No newline at end of file diff --git a/src/solver/optimisation/AreaHydroLevel.cpp b/src/solver/optimisation/AreaHydroLevel.cpp index f3fa15143b..ab59ebe9a0 100644 --- a/src/solver/optimisation/AreaHydroLevel.cpp +++ b/src/solver/optimisation/AreaHydroLevel.cpp @@ -1,8 +1,13 @@ #include "AreaHydroLevel.h" -void AreaHydroLevel::add(int pays, int pdt, std::vector& NumeroDeContrainteDesNiveauxPays) +void AreaHydroLevel::add(int pays, int pdt) { - NumeroDeContrainteDesNiveauxPays[pays] = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; + const auto& CorrespondanceVarNativesVarOptim + = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt]; + CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim + = problemeHebdo->CorrespondanceCntNativesCntOptim[pdt]; + CorrespondanceCntNativesCntOptim.NumeroDeContrainteDesNiveauxPays[pays] + = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; if (problemeHebdo->CaracteristiquesHydrauliques[pays].SuiviNiveauHoraire) { builder.updateHourWithinWeek(pdt).include(Variable::HydroLevel(pays), 1.0); @@ -16,7 +21,7 @@ void AreaHydroLevel::add(int pays, int pdt, std::vector& NumeroDeContrainte namer.UpdateArea(problemeHebdo->NomsDesPays[pays]); namer.UpdateTimeStep(problemeHebdo->weekInTheYear * 168 + pdt); namer.AreaHydroLevel(problemeHebdo->ProblemeAResoudre->NombreDeContraintes); - NumeroDeContrainteDesNiveauxPays[pays] + CorrespondanceCntNativesCntOptim.NumeroDeContrainteDesNiveauxPays[pays] = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; builder.updateHourWithinWeek(pdt) .include(Variable::HydProd(pays), 1.0) @@ -27,5 +32,5 @@ void AreaHydroLevel::add(int pays, int pdt, std::vector& NumeroDeContrainte .build(); } else - NumeroDeContrainteDesNiveauxPays[pays] = -1; + CorrespondanceCntNativesCntOptim.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..ed0a059b3e 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, std::vector& NumeroDeContrainteDesNiveauxPays); + 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 index fa8f584428..6ef3b2a6aa 100644 --- a/src/solver/optimisation/BindingConstraintDay.cpp +++ b/src/solver/optimisation/BindingConstraintDay.cpp @@ -1,12 +1,16 @@ #include "BindingConstraintDay.h" -void BindingConstraintDay::add(int cntCouplante, BindingConstraintDayData& data) +void BindingConstraintDay::add(int cntCouplante) { - if (data.TypeDeContrainteCouplante != CONTRAINTE_JOURNALIERE) + const CONTRAINTES_COUPLANTES& MatriceDesContraintesCouplantes + = problemeHebdo->MatriceDesContraintesCouplantes[cntCouplante]; + if (MatriceDesContraintesCouplantes.TypeDeContrainteCouplante != CONTRAINTE_JOURNALIERE) return; - const int nbInterco = data.NombreDInterconnexionsDansLaContrainteCouplante; - const int nbClusters = data.NombreDePaliersDispatchDansLaContrainteCouplante; + const int nbInterco + = MatriceDesContraintesCouplantes.NombreDInterconnexionsDansLaContrainteCouplante; + const int nbClusters + = MatriceDesContraintesCouplantes.NombreDePaliersDispatchDansLaContrainteCouplante; const int NombreDePasDeTempsPourUneOptimisation = problemeHebdo->NombreDePasDeTempsPourUneOptimisation; // TODO @@ -15,14 +19,14 @@ void BindingConstraintDay::add(int cntCouplante, BindingConstraintDayData& data) while (pdtDebut < NombreDePasDeTempsPourUneOptimisation) { int jour = problemeHebdo->NumeroDeJourDuPasDeTemps[pdtDebut]; - auto& CorrespondanceCntNativesCntOptimJournalieres - = data.CorrespondanceCntNativesCntOptimJournalieres[jour]; + CORRESPONDANCES_DES_CONTRAINTES_JOURNALIERES& CorrespondanceCntNativesCntOptimJournalieres + = problemeHebdo->CorrespondanceCntNativesCntOptimJournalieres[jour]; for (int index = 0; index < nbInterco; index++) { - int interco = data.NumeroDeLInterconnexion[index]; - double poids = data.PoidsDeLInterconnexion[index]; - int offset = data.OffsetTemporelSurLInterco[index]; + int interco = MatriceDesContraintesCouplantes.NumeroDeLInterconnexion[index]; + double poids = MatriceDesContraintesCouplantes.PoidsDeLInterconnexion[index]; + int offset = MatriceDesContraintesCouplantes.OffsetTemporelSurLInterco[index]; for (int pdt = pdtDebut; pdt < pdtDebut + NombreDePasDeTempsDUneJournee; pdt++) { @@ -43,14 +47,14 @@ void BindingConstraintDay::add(int cntCouplante, BindingConstraintDayData& data) for (int index = 0; index < nbClusters; index++) { - int pays = data.PaysDuPalierDispatch[index]; + int pays = MatriceDesContraintesCouplantes.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]; + [MatriceDesContraintesCouplantes.NumeroDuPalierDispatch[index]]; + double poids = MatriceDesContraintesCouplantes.PoidsDuPalierDispatch[index]; + int offset = MatriceDesContraintesCouplantes.OffsetTemporelSurLePalierDispatch[index]; for (int pdt = pdtDebut; pdt < pdtDebut + NombreDePasDeTempsDUneJournee; pdt++) { @@ -80,14 +84,14 @@ void BindingConstraintDay::add(int cntCouplante, BindingConstraintDayData& data) std::vector& AdresseOuPlacerLaValeurDesCoutsMarginaux = problemeHebdo->ProblemeAResoudre->AdresseOuPlacerLaValeurDesCoutsMarginaux; - char op = data.SensDeLaContrainteCouplante; + char op = MatriceDesContraintesCouplantes.SensDeLaContrainteCouplante; builder.operatorRHS(op); { ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, problemeHebdo->NamedProblems); namer.UpdateTimeStep(jour); namer.BindingConstraintDay(problemeHebdo->ProblemeAResoudre->NombreDeContraintes, - data.NomDeLaContrainteCouplante); + MatriceDesContraintesCouplantes.NomDeLaContrainteCouplante); } builder.build(); pdtDebut += problemeHebdo->NombreDePasDeTempsDUneJournee; diff --git a/src/solver/optimisation/BindingConstraintDay.h b/src/solver/optimisation/BindingConstraintDay.h index 39a507c872..5e257b4f6f 100644 --- a/src/solver/optimisation/BindingConstraintDay.h +++ b/src/solver/optimisation/BindingConstraintDay.h @@ -1,15 +1,9 @@ #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, BindingConstraintDayData& data); + void add(int cntCouplante); }; diff --git a/src/solver/optimisation/BindingConstraintHour.cpp b/src/solver/optimisation/BindingConstraintHour.cpp index 1428fb198f..f37b013992 100644 --- a/src/solver/optimisation/BindingConstraintHour.cpp +++ b/src/solver/optimisation/BindingConstraintHour.cpp @@ -1,21 +1,26 @@ #include "BindingConstraintHour.h" -void BindingConstraintHour::add(int pdt, int cntCouplante, BindingConstraintHourData& data) +void BindingConstraintHour::add(int pdt, int cntCouplante) { - data.NumeroDeContrainteDesContraintesCouplantes[cntCouplante] + const CONTRAINTES_COUPLANTES& MatriceDesContraintesCouplantes + = problemeHebdo->MatriceDesContraintesCouplantes[cntCouplante]; + CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim + = problemeHebdo->CorrespondanceCntNativesCntOptim[pdt]; + CorrespondanceCntNativesCntOptim.NumeroDeContrainteDesContraintesCouplantes[cntCouplante] = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; - if (data.TypeDeContrainteCouplante != CONTRAINTE_HORAIRE) + if (MatriceDesContraintesCouplantes.TypeDeContrainteCouplante != CONTRAINTE_HORAIRE) return; builder.updateHourWithinWeek(pdt); // Links - const int nbInterco = data.NombreDInterconnexionsDansLaContrainteCouplante; + const int nbInterco + = MatriceDesContraintesCouplantes.NombreDInterconnexionsDansLaContrainteCouplante; for (int index = 0; index < nbInterco; index++) { - const int interco = data.NumeroDeLInterconnexion[index]; - const double poids = data.PoidsDeLInterconnexion[index]; - const int offset = data.OffsetTemporelSurLInterco[index]; + const int interco = MatriceDesContraintesCouplantes.NumeroDeLInterconnexion[index]; + const double poids = MatriceDesContraintesCouplantes.PoidsDeLInterconnexion[index]; + const int offset = MatriceDesContraintesCouplantes.OffsetTemporelSurLInterco[index]; int pdt1; if (offset >= 0) { @@ -32,17 +37,17 @@ void BindingConstraintHour::add(int pdt, int cntCouplante, BindingConstraintHour } // Thermal clusters - const int nbClusters = data.NombreDePaliersDispatchDansLaContrainteCouplante; + const int nbClusters + = MatriceDesContraintesCouplantes.NombreDePaliersDispatchDansLaContrainteCouplante; for (int index = 0; index < nbClusters; index++) { - const int pays = data.PaysDuPalierDispatch[index]; + const int pays = MatriceDesContraintesCouplantes.PaysDuPalierDispatch[index]; const PALIERS_THERMIQUES& PaliersThermiquesDuPays = problemeHebdo->PaliersThermiquesDuPays[pays]; - const int palier - = PaliersThermiquesDuPays - .NumeroDuPalierDansLEnsembleDesPaliersThermiques[data.NumeroDuPalierDispatch[index]]; - const double poids = data.PoidsDuPalierDispatch[index]; - const int offset = data.OffsetTemporelSurLePalierDispatch[index]; + const int palier = PaliersThermiquesDuPays.NumeroDuPalierDansLEnsembleDesPaliersThermiques + [MatriceDesContraintesCouplantes.NumeroDuPalierDispatch[index]]; + const double poids = MatriceDesContraintesCouplantes.PoidsDuPalierDispatch[index]; + const int offset = MatriceDesContraintesCouplantes.OffsetTemporelSurLePalierDispatch[index]; int pdt1; if (offset >= 0) @@ -62,14 +67,14 @@ void BindingConstraintHour::add(int pdt, int cntCouplante, BindingConstraintHour problemeHebdo->NombreDePasDeTemps); } - char op = data.SensDeLaContrainteCouplante; + 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, - data.NomDeLaContrainteCouplante); + MatriceDesContraintesCouplantes.NomDeLaContrainteCouplante); } builder.build(); } diff --git a/src/solver/optimisation/BindingConstraintHour.h b/src/solver/optimisation/BindingConstraintHour.h index 51cc8bbd5c..1b0eb6224b 100644 --- a/src/solver/optimisation/BindingConstraintHour.h +++ b/src/solver/optimisation/BindingConstraintHour.h @@ -1,13 +1,9 @@ #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, BindingConstraintHourData& data); + void add(int pdt, int cntCouplante); }; diff --git a/src/solver/optimisation/BindingConstraintWeek.cpp b/src/solver/optimisation/BindingConstraintWeek.cpp index 5c8ea61444..24f2e17db5 100644 --- a/src/solver/optimisation/BindingConstraintWeek.cpp +++ b/src/solver/optimisation/BindingConstraintWeek.cpp @@ -1,21 +1,25 @@ #include "BindingConstraintWeek.h" -void BindingConstraintWeek::add(int cntCouplante, BindingConstraintWeekData& data) +void BindingConstraintWeek::add(int cntCouplante) { + const CONTRAINTES_COUPLANTES& MatriceDesContraintesCouplantes + = problemeHebdo->MatriceDesContraintesCouplantes[cntCouplante]; int semaine = problemeHebdo->weekInTheYear; - auto& NumeroDeContrainteDesContraintesCouplantes - = data.NumeroDeContrainteDesContraintesCouplantes; - if (data.TypeDeContrainteCouplante != CONTRAINTE_HEBDOMADAIRE) + CORRESPONDANCES_DES_CONTRAINTES_HEBDOMADAIRES& CorrespondanceCntNativesCntOptimHebdomadaires + = problemeHebdo->CorrespondanceCntNativesCntOptimHebdomadaires; + if (MatriceDesContraintesCouplantes.TypeDeContrainteCouplante != CONTRAINTE_HEBDOMADAIRE) return; - const int nbInterco = data.NombreDInterconnexionsDansLaContrainteCouplante; - const int nbClusters = data.NombreDePaliersDispatchDansLaContrainteCouplante; + const int nbInterco + = MatriceDesContraintesCouplantes.NombreDInterconnexionsDansLaContrainteCouplante; + const int nbClusters + = MatriceDesContraintesCouplantes.NombreDePaliersDispatchDansLaContrainteCouplante; for (int index = 0; index < nbInterco; index++) { - int interco = data.NumeroDeLInterconnexion[index]; - double poids = data.PoidsDeLInterconnexion[index]; - int offset = data.OffsetTemporelSurLInterco[index]; + int interco = MatriceDesContraintesCouplantes.NumeroDeLInterconnexion[index]; + double poids = MatriceDesContraintesCouplantes.PoidsDeLInterconnexion[index]; + int offset = MatriceDesContraintesCouplantes.OffsetTemporelSurLInterco[index]; for (int pdt = 0; pdt < problemeHebdo->NombreDePasDeTempsPourUneOptimisation; pdt++) { builder.updateHourWithinWeek(pdt); @@ -36,16 +40,16 @@ void BindingConstraintWeek::add(int cntCouplante, BindingConstraintWeekData& dat for (int index = 0; index < nbClusters; index++) { - 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 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? @@ -64,21 +68,22 @@ void BindingConstraintWeek::add(int cntCouplante, BindingConstraintWeekData& dat offset, false, problemeHebdo->NombreDePasDeTemps); - } + } } - char op = data.SensDeLaContrainteCouplante; - builder.operatorRHS(op); + char op = MatriceDesContraintesCouplantes.SensDeLaContrainteCouplante; + builder.operatorRHS(op); - NumeroDeContrainteDesContraintesCouplantes[cntCouplante] - = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; - // Name - { - ConstraintNamer namer(problemeHebdo->ProblemeAResoudre->NomDesContraintes, - problemeHebdo->NamedProblems); - namer.UpdateTimeStep(semaine); - namer.BindingConstraintWeek(problemeHebdo->ProblemeAResoudre->NombreDeContraintes, - data.NomDeLaContrainteCouplante); - } + CorrespondanceCntNativesCntOptimHebdomadaires + .NumeroDeContrainteDesContraintesCouplantes[cntCouplante] + = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; + // Name + { + 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/BindingConstraintWeek.h b/src/solver/optimisation/BindingConstraintWeek.h index 347db31c45..5d1b945462 100644 --- a/src/solver/optimisation/BindingConstraintWeek.h +++ b/src/solver/optimisation/BindingConstraintWeek.h @@ -1,16 +1,9 @@ #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, BindingConstraintWeekData& data); + void add(int cntCouplante); }; \ No newline at end of file diff --git a/src/solver/optimisation/FictitiousLoad.cpp b/src/solver/optimisation/FictitiousLoad.cpp index 25c2ecee8c..36904c1465 100644 --- a/src/solver/optimisation/FictitiousLoad.cpp +++ b/src/solver/optimisation/FictitiousLoad.cpp @@ -1,12 +1,14 @@ #include "FictitiousLoad.h" -void FictitiousLoad::add(int pdt, - int pays, - std::vector& NumeroDeContraintePourEviterLesChargesFictives) +void FictitiousLoad::add(int pdt, int pays) { /** can be done without this --- keep it for now**/ - NumeroDeContraintePourEviterLesChargesFictives[pays] + CORRESPONDANCES_DES_VARIABLES& CorrespondanceVarNativesVarOptim + = problemeHebdo->CorrespondanceVarNativesVarOptim[pdt]; + CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim + = problemeHebdo->CorrespondanceCntNativesCntOptim[pdt]; + CorrespondanceCntNativesCntOptim.NumeroDeContraintePourEviterLesChargesFictives[pays] = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; /******/ diff --git a/src/solver/optimisation/FictitiousLoad.h b/src/solver/optimisation/FictitiousLoad.h index f981e1755c..d2d866b5d6 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, std::vector& NumeroDeContraintePourEviterLesChargesFictives); + void add(int pdt, int pays); }; diff --git a/src/solver/optimisation/FlowDissociation.cpp b/src/solver/optimisation/FlowDissociation.cpp index f4c52bf5d4..67f7d61bf4 100644 --- a/src/solver/optimisation/FlowDissociation.cpp +++ b/src/solver/optimisation/FlowDissociation.cpp @@ -1,15 +1,21 @@ #include "FlowDissociation.h" -void FlowDissociation::add(int pdt, - int interco, - std::vector& NumeroDeContrainteDeDissociationDeFlux) +void FlowDissociation::add(int pdt, int interco) { if (const COUTS_DE_TRANSPORT& CoutDeTransport = problemeHebdo->CoutDeTransport[interco]; CoutDeTransport.IntercoGereeAvecDesCouts) { - // TODO improve this - NumeroDeContrainteDeDissociationDeFlux[interco] + /** 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]]; diff --git a/src/solver/optimisation/FlowDissociation.h b/src/solver/optimisation/FlowDissociation.h index f4dc7c0474..e135b595aa 100644 --- a/src/solver/optimisation/FlowDissociation.h +++ b/src/solver/optimisation/FlowDissociation.h @@ -5,6 +5,5 @@ class FlowDissociation : private Constraint { public: using Constraint::Constraint; - void add(int pdt, int interco, - std::vector& NumeroDeContrainteDeDissociationDeFlux); + void add(int pdt, int interco); }; diff --git a/src/solver/optimisation/HydroPower.cpp b/src/solver/optimisation/HydroPower.cpp index ae8c4ecda4..50a24d48c8 100644 --- a/src/solver/optimisation/HydroPower.cpp +++ b/src/solver/optimisation/HydroPower.cpp @@ -1,7 +1,4 @@ #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 442640f376..5fb9838e57 100644 --- a/src/solver/optimisation/ShortTermStorageLevel.cpp +++ b/src/solver/optimisation/ShortTermStorageLevel.cpp @@ -1,12 +1,18 @@ #include "ShortTermStorageLevel.h" -void ShortTermStorageLevel::add(int pdt, - int pays, - std::vector& ShortTermStorageLevelConstraint) +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]); @@ -18,7 +24,7 @@ void ShortTermStorageLevel::add(int pdt, namer.ShortTermStorageLevel(problemeHebdo->ProblemeAResoudre->NombreDeContraintes, storage.name); const auto index = storage.clusterGlobalIndex; - ShortTermStorageLevelConstraint[index] + CorrespondanceCntNativesCntOptim.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 0d910674cb..bf739a6679 100644 --- a/src/solver/optimisation/ShortTermStorageLevel.h +++ b/src/solver/optimisation/ShortTermStorageLevel.h @@ -5,6 +5,5 @@ class ShortTermStorageLevel : private Constraint { public: using Constraint::Constraint; - void add(int pdt, int pays, - std::vector & ShortTermStorageLevelConstraint); + void add(int pdt, int pays); }; 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..90ac4709c1 100644 --- a/src/solver/optimisation/adequacy_patch_csr/csr_quadratic_problem.cpp +++ b/src/solver/optimisation/adequacy_patch_csr/csr_quadratic_problem.cpp @@ -33,61 +33,62 @@ #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 { - -class CsrFlowDissociation : private Constraint +void CsrQuadraticProblem::setConstraintsOnFlows(std::vector& Pi, std::vector& Colonne) { -public: - using Constraint::Constraint; - void add(int hour, std::map& numberOfConstraintCsrFlowDissociation) + 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++) { - 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++) + if (problemeHebdo_->adequacyPatchRuntimeData->originAreaMode[Interco] + == Antares::Data::AdequacyPatch::physicalAreaInsideAdqPatch + && problemeHebdo_->adequacyPatchRuntimeData->extremityAreaMode[Interco] + == Antares::Data::AdequacyPatch::physicalAreaInsideAdqPatch) { - if (problemeHebdo->adequacyPatchRuntimeData->originAreaMode[interco] - == Antares::Data::AdequacyPatch::physicalAreaInsideAdqPatch - && problemeHebdo->adequacyPatchRuntimeData->extremityAreaMode[interco] - == Antares::Data::AdequacyPatch::physicalAreaInsideAdqPatch) + 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) { - 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(); + Pi[NombreDeTermes] = 1.0; + Colonne[NombreDeTermes] = var; + NombreDeTermes++; } + + 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 83424087f6..8bfa226ceb 100644 --- a/src/solver/optimisation/constraint_builder.cpp +++ b/src/solver/optimisation/constraint_builder.cpp @@ -2,13 +2,14 @@ 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(); + OPT_ChargerLaContrainteDansLaMatriceDesContraintes( + &problemeAResoudre, Pi, Colonne, nombreDeTermes_, operator_); } nombreDeTermes_ = 0; } @@ -19,12 +20,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) // { @@ -43,8 +44,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); } @@ -54,8 +55,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) { @@ -64,52 +65,4 @@ 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 bc0ad22014..c912e99061 100644 --- a/src/solver/optimisation/constraint_builder.h +++ b/src/solver/optimisation/constraint_builder.h @@ -246,10 +246,10 @@ class ConstraintBuilder { public: ConstraintBuilder( - const PROBLEME_HEBDO* problemeHebdo, + PROBLEME_HEBDO& problemeHebdo, const std::vector& CorrespondanceVarNativesVarOptim) : problemeHebdo(problemeHebdo), - problemeAResoudre(problemeHebdo->ProblemeAResoudre), + problemeAResoudre(*problemeHebdo.ProblemeAResoudre), varNative(CorrespondanceVarNativesVarOptim) { } @@ -305,11 +305,8 @@ class ConstraintBuilder } private: - void OPT_ChargerLaContrainteDansLaMatriceDesContraintes(); - - void OPT_AugmenterLaTailleDeLaMatriceDesContraintes(); - const PROBLEME_HEBDO* problemeHebdo; - PROBLEME_ANTARES_A_RESOUDRE* problemeAResoudre; + PROBLEME_HEBDO& problemeHebdo; + PROBLEME_ANTARES_A_RESOUDRE& problemeAResoudre; const std::vector& varNative; unsigned int hourInWeek_ = 0; @@ -323,13 +320,13 @@ class ConstraintBuilder class Constraint { public: - explicit Constraint(const PROBLEME_HEBDO* problemeHebdo) : + explicit Constraint(PROBLEME_HEBDO* problemeHebdo) : problemeHebdo(problemeHebdo), builder(*problemeHebdo, problemeHebdo->CorrespondanceVarNativesVarOptim) { } - const PROBLEME_HEBDO* problemeHebdo; // TODO remove + PROBLEME_HEBDO* problemeHebdo; // TODO remove ConstraintBuilder builder; }; @@ -348,19 +345,3 @@ 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 79a20488ac..968dcb3f49 100644 --- a/src/solver/optimisation/opt_alloc_probleme_a_optimiser.cpp +++ b/src/solver/optimisation/opt_alloc_probleme_a_optimiser.cpp @@ -158,3 +158,20 @@ 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 0c9bc6d269..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 @@ -51,75 +51,6 @@ #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) { @@ -173,56 +104,38 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* pro for (uint32_t pays = 0; pays < problemeHebdo->NombreDePays; 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); + areaBalance.add(pdt, pays); + + fictitiousLoad.add(pdt, pays); + + shortTermStorageLevel.add(pdt, pays); } for (uint32_t interco = 0; interco < problemeHebdo->NombreDInterconnexions; interco++) { - CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim - = problemeHebdo->CorrespondanceCntNativesCntOptim[pdt]; - flowDissociation.add( - pdt, - interco, - CorrespondanceCntNativesCntOptim.NumeroDeContrainteDeDissociationDeFlux); + flowDissociation.add(pdt, interco); } for (uint32_t cntCouplante = 0; cntCouplante < problemeHebdo->NombreDeContraintesCouplantes; cntCouplante++) { - bindingConstraintHour.add( - pdt, - cntCouplante, - GetBindingConstraintHourDataFromProblemHebdo(problemeHebdo, cntCouplante, pdt)); + bindingConstraintHour.add(pdt, cntCouplante); } } for (uint32_t cntCouplante = 0; cntCouplante < problemeHebdo->NombreDeContraintesCouplantes; cntCouplante++) { - bindingConstraintDay.add( - cntCouplante, GetBindingConstraintDayDataFromProblemHebdo(problemeHebdo, cntCouplante)); + bindingConstraintDay.add(cntCouplante); } if (nombreDePasDeTempsPourUneOptimisation > nombreDePasDeTempsDUneJournee) { + CORRESPONDANCES_DES_CONTRAINTES_HEBDOMADAIRES& CorrespondanceCntNativesCntOptimHebdomadaires + = problemeHebdo->CorrespondanceCntNativesCntOptimHebdomadaires; for (uint32_t cntCouplante = 0; cntCouplante < problemeHebdo->NombreDeContraintesCouplantes; cntCouplante++) { - bindingConstraintWeek.add( - cntCouplante, - GetBindingConstraintWeekDataFromProblemHebdo(problemeHebdo, cntCouplante)); + bindingConstraintWeek.add(cntCouplante); } } @@ -271,16 +184,15 @@ 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, CorrespondanceCntNativesCntOptim.NumeroDeContrainteDesNiveauxPays); + areaHydroLevel.add(pays, pdt); } } 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..b3d7399045 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,50 +31,54 @@ #include "../simulation/sim_structure_donnees.h" #include "../simulation/sim_extern_variables_globales.h" #include "opt_fonctions.h" -#include "constraint_builder.h" -class ExchangeBalance : private Constraint + +void OPT_ConstruireLaMatriceDesContraintesDuProblemeQuadratique(PROBLEME_HEBDO* problemeHebdo) { -public: - using Constraint::Constraint; - void add(uint32_t pays) + 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++) { - builder.updateHourWithinWeek(0); + int nombreDeTermes = 0; int interco = problemeHebdo->IndexDebutIntercoOrigine[pays]; while (interco >= 0) { - builder.include(Variable::IntercoDirectCost(interco), 1.0); + if (int var + = correspondanceVarNativesVarOptim.NumeroDeVariableDeLInterconnexion[interco]; + var >= 0) + { + Pi[nombreDeTermes] = 1.0; + Colonne[nombreDeTermes] = var; + nombreDeTermes++; + } interco = problemeHebdo->IndexSuivantIntercoOrigine[interco]; } interco = problemeHebdo->IndexDebutIntercoExtremite[pays]; while (interco >= 0) { - builder.include(Variable::IntercoDirectCost(interco), -1.0); - + if (int var + = correspondanceVarNativesVarOptim.NumeroDeVariableDeLInterconnexion[interco]; + var >= 0) + { + Pi[nombreDeTermes] = -1.0; + Colonne[nombreDeTermes] = var; + nombreDeTermes++; + } interco = problemeHebdo->IndexSuivantIntercoExtremite[interco]; } problemeHebdo->NumeroDeContrainteDeSoldeDEchange[pays] - = problemeHebdo->ProblemeAResoudre->NombreDeContraintes; - builder.build(); - } -}; + = ProblemeAResoudre->NombreDeContraintes; -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); + OPT_ChargerLaContrainteDansLaMatriceDesContraintes( + ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '='); } } 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 bd6d0c686f..ecbb26cdf5 100644 --- a/src/solver/optimisation/opt_construction_matrice_des_contraintes_outils.cpp +++ b/src/solver/optimisation/opt_construction_matrice_des_contraintes_outils.cpp @@ -30,3 +30,32 @@ #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 fd5292e24c..e2807f0c8d 100644 --- a/src/solver/optimisation/opt_fonctions.h +++ b/src/solver/optimisation/opt_fonctions.h @@ -102,6 +102,11 @@ 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, @@ -109,6 +114,7 @@ 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 54f774f085..0d90030460 100644 --- a/src/solver/optimisation/opt_rename_problem.cpp +++ b/src/solver/optimisation/opt_rename_problem.cpp @@ -215,15 +215,6 @@ 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 5cd8eeb6ad..6c19a3e415 100644 --- a/src/solver/optimisation/opt_rename_problem.h +++ b/src/solver/optimisation/opt_rename_problem.h @@ -110,10 +110,6 @@ 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);