From eff4d718b4c20a62724a5d401d824e587965ddf6 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Tue, 12 Sep 2023 15:10:12 +0200 Subject: [PATCH 01/42] [DEV] turbine --- .../hydro/monthly/h2o_m_donnees_annuelles.h | 6 +++--- src/solver/hydro/monthly/h2o_m_free.cpp | 3 --- ...m_initialiser_les_bornes_des_variables.cpp | 6 ++---- .../h2o_m_initialiser_les_second_membre.cpp | 3 +-- .../hydro/monthly/h2o_m_instanciation.cpp | 19 +++---------------- src/solver/hydro/monthly/h2o_m_sys.h | 1 + 6 files changed, 10 insertions(+), 28 deletions(-) diff --git a/src/solver/hydro/monthly/h2o_m_donnees_annuelles.h b/src/solver/hydro/monthly/h2o_m_donnees_annuelles.h index b9363cbd0e..6491b7d16d 100644 --- a/src/solver/hydro/monthly/h2o_m_donnees_annuelles.h +++ b/src/solver/hydro/monthly/h2o_m_donnees_annuelles.h @@ -45,9 +45,9 @@ typedef struct double CoutDepassementVolume; /* A renseigner par l'appelant : 1 valeur */ double CoutViolMaxDuVolumeMin; // A renseigner par l'appelant : 1 valeur double VolumeInitial; /* A renseigner par l'appelant : 1 valeur */ - double* TurbineMax; /* A renseigner par l'appelant : 1 valeur par mois */ - double* TurbineMin; - double* TurbineCible; /* A renseigner par l'appelant : 1 valeur par mois */ + std::vector TurbineMax; /* A renseigner par l'appelant : 1 valeur par mois */ + std::vector TurbineMin; + std::vector TurbineCible; /* A renseigner par l'appelant : 1 valeur par mois */ double* Apport; /* A renseigner par l'appelant : 1 valeur par mois */ /* Pour decrire la bande de volumes permise */ double* VolumeMin; /* A renseigner par l'appelant : 1 valeur par mois */ diff --git a/src/solver/hydro/monthly/h2o_m_free.cpp b/src/solver/hydro/monthly/h2o_m_free.cpp index a027456fe0..8142c04c4f 100644 --- a/src/solver/hydro/monthly/h2o_m_free.cpp +++ b/src/solver/hydro/monthly/h2o_m_free.cpp @@ -94,9 +94,6 @@ void H2O_M_Free(DONNEES_ANNUELLES* DonneesAnnuelles) free(ProblemeHydraulique->Probleme); free(ProblemeHydraulique); - free(DonneesAnnuelles->TurbineMax); - free(DonneesAnnuelles->TurbineMin); - free(DonneesAnnuelles->TurbineCible); free(DonneesAnnuelles->Apport); free(DonneesAnnuelles->VolumeMin); free(DonneesAnnuelles->VolumeMax); diff --git a/src/solver/hydro/monthly/h2o_m_initialiser_les_bornes_des_variables.cpp b/src/solver/hydro/monthly/h2o_m_initialiser_les_bornes_des_variables.cpp index 75ab1880a9..d026890b9f 100644 --- a/src/solver/hydro/monthly/h2o_m_initialiser_les_bornes_des_variables.cpp +++ b/src/solver/hydro/monthly/h2o_m_initialiser_les_bornes_des_variables.cpp @@ -36,8 +36,6 @@ void H2O_M_InitialiserBornesEtCoutsDesVariables(DONNEES_ANNUELLES* DonneesAnnuel double* Xmin; double* Xmax; double* X; - double* TurbineMax; - const double* TurbineMin; double* CoutLineaire; double CoutDepassementVolume; @@ -50,8 +48,8 @@ void H2O_M_InitialiserBornesEtCoutsDesVariables(DONNEES_ANNUELLES* DonneesAnnuel NbPdt = DonneesAnnuelles->NombreDePasDeTemps; CoutDepassementVolume = DonneesAnnuelles->CoutDepassementVolume; - TurbineMax = DonneesAnnuelles->TurbineMax; - TurbineMin = DonneesAnnuelles->TurbineMin; + auto& TurbineMax = DonneesAnnuelles->TurbineMax; + const auto& TurbineMin = DonneesAnnuelles->TurbineMin; ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; ProblemeLineairePartieFixe = ProblemeHydraulique->ProblemeLineairePartieFixe; diff --git a/src/solver/hydro/monthly/h2o_m_initialiser_les_second_membre.cpp b/src/solver/hydro/monthly/h2o_m_initialiser_les_second_membre.cpp index f507114144..05bc0ba8cc 100644 --- a/src/solver/hydro/monthly/h2o_m_initialiser_les_second_membre.cpp +++ b/src/solver/hydro/monthly/h2o_m_initialiser_les_second_membre.cpp @@ -33,7 +33,6 @@ void H2O_M_InitialiserLeSecondMembre(DONNEES_ANNUELLES* DonneesAnnuelles) int Pdt; int Cnt; int NbPdt; - double* TurbineCible; double* SecondMembre; double ChgmtSens; @@ -44,7 +43,7 @@ void H2O_M_InitialiserLeSecondMembre(DONNEES_ANNUELLES* DonneesAnnuelles) NbPdt = DonneesAnnuelles->NombreDePasDeTemps; - TurbineCible = DonneesAnnuelles->TurbineCible; + auto& TurbineCible = DonneesAnnuelles->TurbineCible; ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; diff --git a/src/solver/hydro/monthly/h2o_m_instanciation.cpp b/src/solver/hydro/monthly/h2o_m_instanciation.cpp index ed3e5c03fa..da33c7a4b1 100644 --- a/src/solver/hydro/monthly/h2o_m_instanciation.cpp +++ b/src/solver/hydro/monthly/h2o_m_instanciation.cpp @@ -59,22 +59,9 @@ DONNEES_ANNUELLES* H2O_M_Instanciation(int NombreDeReservoirs) return (NULL); } - DonneesAnnuelles->TurbineMax = (double*)malloc((unsigned int)NbPdt * sizeof(double)); - if (DonneesAnnuelles->TurbineMax == NULL) - { - return (NULL); - } - DonneesAnnuelles->TurbineMin = (double*)malloc((unsigned int)NbPdt * sizeof(double)); - if (DonneesAnnuelles->TurbineMin == NULL) - { - return (NULL); - } - - DonneesAnnuelles->TurbineCible = (double*)malloc((unsigned int)NbPdt * sizeof(double)); - if (DonneesAnnuelles->TurbineCible == NULL) - { - return (NULL); - } + DonneesAnnuelles->TurbineMax.assign(NbPdt, 0.); + DonneesAnnuelles->TurbineMin.assign(NbPdt, 0.); + DonneesAnnuelles->TurbineCible.assign(NbPdt, 0.); DonneesAnnuelles->Apport = (double*)malloc((unsigned int)NbPdt * sizeof(double)); if (DonneesAnnuelles->Apport == NULL) diff --git a/src/solver/hydro/monthly/h2o_m_sys.h b/src/solver/hydro/monthly/h2o_m_sys.h index 3e39c1d90f..5a254bd647 100644 --- a/src/solver/hydro/monthly/h2o_m_sys.h +++ b/src/solver/hydro/monthly/h2o_m_sys.h @@ -35,5 +35,6 @@ #include #include #include +#include #endif /* __SOLVER_H2O_M_SYS__ */ From 6544d1722e79373e3f9664000ac5caf8f2ed599f Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Tue, 12 Sep 2023 15:13:09 +0200 Subject: [PATCH 02/42] [DEV] donnees_annuelles.h --- .../hydro/monthly/h2o_m_donnees_annuelles.h | 10 +++--- src/solver/hydro/monthly/h2o_m_free.cpp | 5 --- .../hydro/monthly/h2o_m_instanciation.cpp | 32 +++---------------- 3 files changed, 10 insertions(+), 37 deletions(-) diff --git a/src/solver/hydro/monthly/h2o_m_donnees_annuelles.h b/src/solver/hydro/monthly/h2o_m_donnees_annuelles.h index 6491b7d16d..7fda16553d 100644 --- a/src/solver/hydro/monthly/h2o_m_donnees_annuelles.h +++ b/src/solver/hydro/monthly/h2o_m_donnees_annuelles.h @@ -48,10 +48,10 @@ typedef struct std::vector TurbineMax; /* A renseigner par l'appelant : 1 valeur par mois */ std::vector TurbineMin; std::vector TurbineCible; /* A renseigner par l'appelant : 1 valeur par mois */ - double* Apport; /* A renseigner par l'appelant : 1 valeur par mois */ + std::vector Apport; /* A renseigner par l'appelant : 1 valeur par mois */ /* Pour decrire la bande de volumes permise */ - double* VolumeMin; /* A renseigner par l'appelant : 1 valeur par mois */ - double* VolumeMax; /* A renseigner par l'appelant : 1 valeur par mois */ + std::vector VolumeMin; /* A renseigner par l'appelant : 1 valeur par mois */ + std::vector VolumeMax; /* A renseigner par l'appelant : 1 valeur par mois */ /* Les resultats */ char @@ -60,8 +60,8 @@ typedef struct NON s'il y a eu un probleme dans la resolution EMERGENCY_SHUT_DOWN si la resolution du probleme a donne lieu a une erreur interne */ - double* Turbine; /* Resultat a recuperer par l'appelant */ - double* Volume; /* Resultat a recuperer par l'appelant */ + std::vector Turbine; /* Resultat a recuperer par l'appelant */ + std::vector Volume; /* Resultat a recuperer par l'appelant */ /******************************************************************************************/ /* Problemes internes (utilise uniquement par l'optimisation) */ diff --git a/src/solver/hydro/monthly/h2o_m_free.cpp b/src/solver/hydro/monthly/h2o_m_free.cpp index 8142c04c4f..1f45c1f013 100644 --- a/src/solver/hydro/monthly/h2o_m_free.cpp +++ b/src/solver/hydro/monthly/h2o_m_free.cpp @@ -94,11 +94,6 @@ void H2O_M_Free(DONNEES_ANNUELLES* DonneesAnnuelles) free(ProblemeHydraulique->Probleme); free(ProblemeHydraulique); - free(DonneesAnnuelles->Apport); - free(DonneesAnnuelles->VolumeMin); - free(DonneesAnnuelles->VolumeMax); - free(DonneesAnnuelles->Turbine); - free(DonneesAnnuelles->Volume); free(DonneesAnnuelles); return; diff --git a/src/solver/hydro/monthly/h2o_m_instanciation.cpp b/src/solver/hydro/monthly/h2o_m_instanciation.cpp index da33c7a4b1..d0119193b3 100644 --- a/src/solver/hydro/monthly/h2o_m_instanciation.cpp +++ b/src/solver/hydro/monthly/h2o_m_instanciation.cpp @@ -62,35 +62,13 @@ DONNEES_ANNUELLES* H2O_M_Instanciation(int NombreDeReservoirs) DonneesAnnuelles->TurbineMax.assign(NbPdt, 0.); DonneesAnnuelles->TurbineMin.assign(NbPdt, 0.); DonneesAnnuelles->TurbineCible.assign(NbPdt, 0.); + DonneesAnnuelles->Turbine.assign(NbPdt, 0.); - DonneesAnnuelles->Apport = (double*)malloc((unsigned int)NbPdt * sizeof(double)); - if (DonneesAnnuelles->Apport == NULL) - { - return (NULL); - } + DonneesAnnuelles->Apport.assign(NbPdt, 0.); - DonneesAnnuelles->VolumeMin = (double*)malloc((unsigned int)NbPdt * sizeof(double)); - if (DonneesAnnuelles->VolumeMin == NULL) - { - return (NULL); - } - DonneesAnnuelles->VolumeMax = (double*)malloc((unsigned int)NbPdt * sizeof(double)); - if (DonneesAnnuelles->VolumeMax == NULL) - { - return (NULL); - } - - DonneesAnnuelles->Turbine = (double*)malloc((unsigned int)NbPdt * sizeof(double)); - if (DonneesAnnuelles->Turbine == NULL) - { - return (NULL); - } - - DonneesAnnuelles->Volume = (double*)malloc((unsigned int)NbPdt * sizeof(double)); - if (DonneesAnnuelles->Volume == NULL) - { - return (NULL); - } + DonneesAnnuelles->Volume.assign(NbPdt, 0.); + DonneesAnnuelles->VolumeMin.assign(NbPdt, 0.); + DonneesAnnuelles->VolumeMax.assign(NbPdt, 0.); ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; From bea98b1cf58ae304943baf960f10e953c7425aef Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Tue, 12 Sep 2023 15:23:55 +0200 Subject: [PATCH 03/42] [DEV] CoutLineaire CoutLineaireBruite CoefficientsDeLaMatriceDesContraintes --- .../hydro/monthly/h2o_m_ajouter_bruit.cpp | 30 +++++---------- .../h2o_m_construire_les_contraintes.cpp | 3 +- .../monthly/h2o_m_donnees_optimisation.h | 6 +-- src/solver/hydro/monthly/h2o_m_free.cpp | 3 -- ...m_initialiser_les_bornes_des_variables.cpp | 37 ++++++++----------- .../hydro/monthly/h2o_m_instanciation.cpp | 23 +++--------- .../h2o_m_resoudre_le_probleme_lineaire.cpp | 4 +- 7 files changed, 38 insertions(+), 68 deletions(-) diff --git a/src/solver/hydro/monthly/h2o_m_ajouter_bruit.cpp b/src/solver/hydro/monthly/h2o_m_ajouter_bruit.cpp index 9bd90bac18..e5fb3fa953 100644 --- a/src/solver/hydro/monthly/h2o_m_ajouter_bruit.cpp +++ b/src/solver/hydro/monthly/h2o_m_ajouter_bruit.cpp @@ -11,23 +11,13 @@ constexpr unsigned int seed = 0x79686d64; // "hydm" in hexa void H2O_M_AjouterBruitAuCout(DONNEES_ANNUELLES* DonneesAnnuelles) { - CORRESPONDANCE_DES_VARIABLES* CorrespondanceDesVariables; - const double* CoutLineaire; - double* CoutLineaireBruite; - int Var; - int Pdt; - int NbPdt; - // We don't want to keep variables ProblemeHydraulique and ProblemeLineairePartieFixe - { - PROBLEME_HYDRAULIQUE* ProblemeHydraulique; - PROBLEME_LINEAIRE_PARTIE_FIXE* ProblemeLineairePartieFixe; - ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; - ProblemeLineairePartieFixe = ProblemeHydraulique->ProblemeLineairePartieFixe; - CorrespondanceDesVariables = ProblemeHydraulique->CorrespondanceDesVariables; - CoutLineaire = ProblemeLineairePartieFixe->CoutLineaire; - CoutLineaireBruite = ProblemeLineairePartieFixe->CoutLineaireBruite; - NbPdt = DonneesAnnuelles->NombreDePasDeTemps; - } + PROBLEME_HYDRAULIQUE* ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; + PROBLEME_LINEAIRE_PARTIE_FIXE* ProblemeLineairePartieFixe + = ProblemeHydraulique->ProblemeLineairePartieFixe; + CORRESPONDANCE_DES_VARIABLES* CorrespondanceDesVariables + = ProblemeHydraulique->CorrespondanceDesVariables; + auto& CoutLineaireBruite = ProblemeLineairePartieFixe->CoutLineaireBruite; + const auto& CoutLineaire = ProblemeLineairePartieFixe->CoutLineaire; Antares::MersenneTwister noiseGenerator; noiseGenerator.reset(Constants::seed); // Arbitrary seed, hard-coded since we don't really want @@ -42,14 +32,14 @@ void H2O_M_AjouterBruitAuCout(DONNEES_ANNUELLES* DonneesAnnuelles) for (const auto variable : monthlyVariables) { - for (Pdt = 0; Pdt < NbPdt; Pdt++) + for (int Pdt = 0; Pdt < DonneesAnnuelles->NombreDePasDeTemps; Pdt++) { - Var = variable[Pdt]; + int Var = variable[Pdt]; CoutLineaireBruite[Var] = CoutLineaire[Var] + noiseGenerator() * Constants::noiseAmplitude; } } - Var = CorrespondanceDesVariables->NumeroDeLaVariableViolMaxVolumeMin; + int Var = CorrespondanceDesVariables->NumeroDeLaVariableViolMaxVolumeMin; CoutLineaireBruite[Var] = CoutLineaire[Var] + noiseGenerator() * Constants::noiseAmplitude; Var = CorrespondanceDesVariables->NumeroDeLaVariableXi; diff --git a/src/solver/hydro/monthly/h2o_m_construire_les_contraintes.cpp b/src/solver/hydro/monthly/h2o_m_construire_les_contraintes.cpp index c9d17cca84..9a2bdeb988 100644 --- a/src/solver/hydro/monthly/h2o_m_construire_les_contraintes.cpp +++ b/src/solver/hydro/monthly/h2o_m_construire_les_contraintes.cpp @@ -34,7 +34,6 @@ void H2O_M_ConstruireLesContraintes(DONNEES_ANNUELLES* DonneesAnnuelles) int il; int Pdt; int NbPdt; - double* CoefficientsDeLaMatriceDesContraintes; int* IndicesColonnes; int* IndicesDebutDeLigne; int* NombreDeTermesDesLignes; @@ -60,7 +59,7 @@ void H2O_M_ConstruireLesContraintes(DONNEES_ANNUELLES* DonneesAnnuelles) CorrespondanceDesVariables = ProblemeHydraulique->CorrespondanceDesVariables; ProblemeLineairePartieFixe = ProblemeHydraulique->ProblemeLineairePartieFixe; - CoefficientsDeLaMatriceDesContraintes + auto& CoefficientsDeLaMatriceDesContraintes = ProblemeLineairePartieFixe->CoefficientsDeLaMatriceDesContraintes; IndicesColonnes = ProblemeLineairePartieFixe->IndicesColonnes; IndicesDebutDeLigne = ProblemeLineairePartieFixe->IndicesDebutDeLigne; diff --git a/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h b/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h index c3d56569f4..92bff95980 100644 --- a/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h +++ b/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h @@ -38,8 +38,8 @@ typedef struct { int NombreDeVariables; - double* CoutLineaire; - double* CoutLineaireBruite; /* Ajout de bruit pour forcer l'unicité des solutions */ + std::vector CoutLineaire; + std::vector CoutLineaireBruite; /* Ajout de bruit pour forcer l'unicité des solutions */ int* TypeDeVariable; /* Indicateur du type de variable, il ne doit prendre que les suivantes (voir le fichier spx_constantes_externes.h mais ne jamais utiliser les valeurs explicites des constantes): VARIABLE_FIXE , @@ -53,7 +53,7 @@ typedef struct char* Sens; int* IndicesDebutDeLigne; int* NombreDeTermesDesLignes; - double* CoefficientsDeLaMatriceDesContraintes; + std::vector CoefficientsDeLaMatriceDesContraintes; int* IndicesColonnes; int NombreDeTermesAlloues; } PROBLEME_LINEAIRE_PARTIE_FIXE; diff --git a/src/solver/hydro/monthly/h2o_m_free.cpp b/src/solver/hydro/monthly/h2o_m_free.cpp index 1f45c1f013..8bf4bfe038 100644 --- a/src/solver/hydro/monthly/h2o_m_free.cpp +++ b/src/solver/hydro/monthly/h2o_m_free.cpp @@ -59,13 +59,10 @@ void H2O_M_Free(DONNEES_ANNUELLES* DonneesAnnuelles) ->NumeroDeVariableDEcartNegatifAuTurbineCible); free(ProblemeHydraulique->CorrespondanceDesVariables); - free(ProblemeHydraulique->ProblemeLineairePartieFixe->CoutLineaire); - free(ProblemeHydraulique->ProblemeLineairePartieFixe->CoutLineaireBruite); free(ProblemeHydraulique->ProblemeLineairePartieFixe->TypeDeVariable); free(ProblemeHydraulique->ProblemeLineairePartieFixe->Sens); free(ProblemeHydraulique->ProblemeLineairePartieFixe->IndicesDebutDeLigne); free(ProblemeHydraulique->ProblemeLineairePartieFixe->NombreDeTermesDesLignes); - free(ProblemeHydraulique->ProblemeLineairePartieFixe->CoefficientsDeLaMatriceDesContraintes); free(ProblemeHydraulique->ProblemeLineairePartieFixe->IndicesColonnes); free(ProblemeHydraulique->ProblemeLineairePartieFixe); diff --git a/src/solver/hydro/monthly/h2o_m_initialiser_les_bornes_des_variables.cpp b/src/solver/hydro/monthly/h2o_m_initialiser_les_bornes_des_variables.cpp index d026890b9f..e5813774a6 100644 --- a/src/solver/hydro/monthly/h2o_m_initialiser_les_bornes_des_variables.cpp +++ b/src/solver/hydro/monthly/h2o_m_initialiser_les_bornes_des_variables.cpp @@ -30,49 +30,44 @@ void H2O_M_InitialiserBornesEtCoutsDesVariables(DONNEES_ANNUELLES* DonneesAnnuelles) { - int Pdt; - int NbPdt; int Var; double* Xmin; double* Xmax; double* X; - double* CoutLineaire; - double CoutDepassementVolume; - const PROBLEME_HYDRAULIQUE* ProblemeHydraulique; - const PROBLEME_LINEAIRE_PARTIE_FIXE* ProblemeLineairePartieFixe; - const PROBLEME_LINEAIRE_PARTIE_VARIABLE* ProblemeLineairePartieVariable; - const CORRESPONDANCE_DES_VARIABLES* CorrespondanceDesVariables; + const PROBLEME_HYDRAULIQUE* ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; + const PROBLEME_LINEAIRE_PARTIE_VARIABLE* ProblemeLineairePartieVariable + = ProblemeHydraulique->ProblemeLineairePartieVariable; + const CORRESPONDANCE_DES_VARIABLES* CorrespondanceDesVariables + = ProblemeHydraulique->CorrespondanceDesVariables; + PROBLEME_LINEAIRE_PARTIE_FIXE* ProblemeLineairePartieFixe + = ProblemeHydraulique->ProblemeLineairePartieFixe; DonneesAnnuelles->Volume[0] = DonneesAnnuelles->VolumeInitial; - NbPdt = DonneesAnnuelles->NombreDePasDeTemps; - CoutDepassementVolume = DonneesAnnuelles->CoutDepassementVolume; + int NbPdt = DonneesAnnuelles->NombreDePasDeTemps; + double CoutDepassementVolume = DonneesAnnuelles->CoutDepassementVolume; auto& TurbineMax = DonneesAnnuelles->TurbineMax; const auto& TurbineMin = DonneesAnnuelles->TurbineMin; - ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; - ProblemeLineairePartieFixe = ProblemeHydraulique->ProblemeLineairePartieFixe; - ProblemeLineairePartieVariable = ProblemeHydraulique->ProblemeLineairePartieVariable; - CorrespondanceDesVariables = ProblemeHydraulique->CorrespondanceDesVariables; Xmin = ProblemeLineairePartieVariable->Xmin; Xmax = ProblemeLineairePartieVariable->Xmax; X = ProblemeLineairePartieVariable->X; - CoutLineaire = ProblemeLineairePartieFixe->CoutLineaire; + auto& CoutLineaire = ProblemeLineairePartieFixe->CoutLineaire; Var = CorrespondanceDesVariables->NumeroDeVariableVolume[0]; X[Var] = DonneesAnnuelles->Volume[0]; Xmin[Var] = DonneesAnnuelles->Volume[0]; Xmax[Var] = DonneesAnnuelles->Volume[0]; - for (Pdt = 0; Pdt < NbPdt; Pdt++) + for (int Pdt = 0; Pdt < NbPdt; Pdt++) { Var = CorrespondanceDesVariables->NumeroDeVariableVolume[Pdt]; CoutLineaire[Var] = 0.0; } - for (Pdt = 0; Pdt < NbPdt; Pdt++) + for (int Pdt = 0; Pdt < NbPdt; Pdt++) { Var = CorrespondanceDesVariables->NumeroDeVariableTurbine[Pdt]; Xmax[Var] = TurbineMax[Pdt]; @@ -80,13 +75,13 @@ void H2O_M_InitialiserBornesEtCoutsDesVariables(DONNEES_ANNUELLES* DonneesAnnuel CoutLineaire[Var] = 0.0; } - for (Pdt = 0; Pdt < NbPdt; Pdt++) + for (int Pdt = 0; Pdt < NbPdt; Pdt++) { Var = CorrespondanceDesVariables->NumeroDeVariableDepassementVolumeMax[Pdt]; CoutLineaire[Var] = CoutDepassementVolume; } - for (Pdt = 0; Pdt < NbPdt; Pdt++) + for (int Pdt = 0; Pdt < NbPdt; Pdt++) { Var = CorrespondanceDesVariables->NumeroDeVariableDepassementVolumeMin[Pdt]; CoutLineaire[Var] = CoutDepassementVolume; @@ -95,13 +90,13 @@ void H2O_M_InitialiserBornesEtCoutsDesVariables(DONNEES_ANNUELLES* DonneesAnnuel Var = CorrespondanceDesVariables->NumeroDeLaVariableViolMaxVolumeMin; CoutLineaire[Var] = DonneesAnnuelles->CoutViolMaxDuVolumeMin; - for (Pdt = 0; Pdt < NbPdt; Pdt++) + for (int Pdt = 0; Pdt < NbPdt; Pdt++) { Var = CorrespondanceDesVariables->NumeroDeVariableDEcartPositifAuTurbineCible[Pdt]; CoutLineaire[Var] = 1.0; } - for (Pdt = 0; Pdt < NbPdt; Pdt++) + for (int Pdt = 0; Pdt < NbPdt; Pdt++) { Var = CorrespondanceDesVariables->NumeroDeVariableDEcartNegatifAuTurbineCible[Pdt]; CoutLineaire[Var] = 1.0; diff --git a/src/solver/hydro/monthly/h2o_m_instanciation.cpp b/src/solver/hydro/monthly/h2o_m_instanciation.cpp index d0119193b3..797582c822 100644 --- a/src/solver/hydro/monthly/h2o_m_instanciation.cpp +++ b/src/solver/hydro/monthly/h2o_m_instanciation.cpp @@ -165,18 +165,10 @@ DONNEES_ANNUELLES* H2O_M_Instanciation(int NombreDeReservoirs) NombreDeVariables += 1; ProblemeLineairePartieFixe->NombreDeVariables = NombreDeVariables; - ProblemeLineairePartieFixe->CoutLineaire - = (double*)malloc((unsigned int)NombreDeVariables * sizeof(double)); - if (ProblemeLineairePartieFixe->CoutLineaire == NULL) - { - return (0); - } - ProblemeLineairePartieFixe->CoutLineaireBruite - = (double*)malloc((unsigned int)NombreDeVariables * sizeof(double)); - if (ProblemeLineairePartieFixe->CoutLineaireBruite == NULL) - { - return (0); - } + + ProblemeLineairePartieFixe->CoutLineaire.assign(NombreDeVariables, 0.); + ProblemeLineairePartieFixe->CoutLineaireBruite.assign(NombreDeVariables, 0.); + ProblemeLineairePartieFixe->TypeDeVariable = (int*)malloc((unsigned int)NombreDeVariables * sizeof(int)); if (ProblemeLineairePartieFixe->TypeDeVariable == NULL) @@ -225,11 +217,8 @@ DONNEES_ANNUELLES* H2O_M_Instanciation(int NombreDeReservoirs) ProblemeLineairePartieFixe->NombreDeTermesAlloues = NombreDeTermesAlloues; ProblemeLineairePartieFixe->CoefficientsDeLaMatriceDesContraintes - = (double*)malloc((unsigned int)NombreDeTermesAlloues * sizeof(double)); - if (ProblemeLineairePartieFixe->CoefficientsDeLaMatriceDesContraintes == NULL) - { - return (0); - } + .assign(NombreDeTermesAlloues, 0.); + ProblemeLineairePartieFixe->IndicesColonnes = (int*)malloc((unsigned int)NombreDeTermesAlloues * sizeof(int)); if (ProblemeLineairePartieFixe->IndicesColonnes == NULL) diff --git a/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp b/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp index f89c512e35..a60a583e5c 100644 --- a/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp +++ b/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp @@ -102,7 +102,7 @@ void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES* DonneesAnnuelles, int N Probleme->NombreMaxDIterations = -1; Probleme->DureeMaxDuCalcul = -1.; - Probleme->CoutLineaire = ProblemeLineairePartieFixe->CoutLineaireBruite; + Probleme->CoutLineaire = ProblemeLineairePartieFixe->CoutLineaireBruite.data(); Probleme->X = ProblemeLineairePartieVariable->X; Probleme->Xmin = ProblemeLineairePartieVariable->Xmin; Probleme->Xmax = ProblemeLineairePartieVariable->Xmax; @@ -114,7 +114,7 @@ void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES* DonneesAnnuelles, int N Probleme->NombreDeTermesDesLignes = ProblemeLineairePartieFixe->NombreDeTermesDesLignes; Probleme->IndicesColonnes = ProblemeLineairePartieFixe->IndicesColonnes; Probleme->CoefficientsDeLaMatriceDesContraintes - = ProblemeLineairePartieFixe->CoefficientsDeLaMatriceDesContraintes; + = ProblemeLineairePartieFixe->CoefficientsDeLaMatriceDesContraintes.data(); Probleme->Sens = ProblemeLineairePartieFixe->Sens; Probleme->SecondMembre = ProblemeLineairePartieVariable->SecondMembre; From e1937c376f9d20771fc032bd3bb4c6ea85a7760a Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Tue, 12 Sep 2023 15:25:53 +0200 Subject: [PATCH 04/42] [DEV] Sens --- .../hydro/monthly/h2o_m_construire_les_contraintes.cpp | 3 +-- src/solver/hydro/monthly/h2o_m_donnees_optimisation.h | 2 +- src/solver/hydro/monthly/h2o_m_free.cpp | 1 - src/solver/hydro/monthly/h2o_m_instanciation.cpp | 8 ++------ .../hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp | 4 ++-- 5 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/solver/hydro/monthly/h2o_m_construire_les_contraintes.cpp b/src/solver/hydro/monthly/h2o_m_construire_les_contraintes.cpp index 9a2bdeb988..d4ab33eb5c 100644 --- a/src/solver/hydro/monthly/h2o_m_construire_les_contraintes.cpp +++ b/src/solver/hydro/monthly/h2o_m_construire_les_contraintes.cpp @@ -37,7 +37,6 @@ void H2O_M_ConstruireLesContraintes(DONNEES_ANNUELLES* DonneesAnnuelles) int* IndicesColonnes; int* IndicesDebutDeLigne; int* NombreDeTermesDesLignes; - char* Sens; double ChgmtSens; int* NumeroDeVariableVolume; int* NumeroDeVariableTurbine; @@ -63,7 +62,7 @@ void H2O_M_ConstruireLesContraintes(DONNEES_ANNUELLES* DonneesAnnuelles) = ProblemeLineairePartieFixe->CoefficientsDeLaMatriceDesContraintes; IndicesColonnes = ProblemeLineairePartieFixe->IndicesColonnes; IndicesDebutDeLigne = ProblemeLineairePartieFixe->IndicesDebutDeLigne; - Sens = ProblemeLineairePartieFixe->Sens; + auto& Sens = ProblemeLineairePartieFixe->Sens; NombreDeTermesDesLignes = ProblemeLineairePartieFixe->NombreDeTermesDesLignes; NumeroDeVariableVolume = CorrespondanceDesVariables->NumeroDeVariableVolume; diff --git a/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h b/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h index 92bff95980..07ea2bd451 100644 --- a/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h +++ b/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h @@ -50,7 +50,7 @@ typedef struct */ /* La matrice des contraintes */ int NombreDeContraintes; - char* Sens; + std::vector Sens; int* IndicesDebutDeLigne; int* NombreDeTermesDesLignes; std::vector CoefficientsDeLaMatriceDesContraintes; diff --git a/src/solver/hydro/monthly/h2o_m_free.cpp b/src/solver/hydro/monthly/h2o_m_free.cpp index 8bf4bfe038..8c5d750051 100644 --- a/src/solver/hydro/monthly/h2o_m_free.cpp +++ b/src/solver/hydro/monthly/h2o_m_free.cpp @@ -60,7 +60,6 @@ void H2O_M_Free(DONNEES_ANNUELLES* DonneesAnnuelles) free(ProblemeHydraulique->CorrespondanceDesVariables); free(ProblemeHydraulique->ProblemeLineairePartieFixe->TypeDeVariable); - free(ProblemeHydraulique->ProblemeLineairePartieFixe->Sens); free(ProblemeHydraulique->ProblemeLineairePartieFixe->IndicesDebutDeLigne); free(ProblemeHydraulique->ProblemeLineairePartieFixe->NombreDeTermesDesLignes); free(ProblemeHydraulique->ProblemeLineairePartieFixe->IndicesColonnes); diff --git a/src/solver/hydro/monthly/h2o_m_instanciation.cpp b/src/solver/hydro/monthly/h2o_m_instanciation.cpp index 797582c822..4871f1c6ba 100644 --- a/src/solver/hydro/monthly/h2o_m_instanciation.cpp +++ b/src/solver/hydro/monthly/h2o_m_instanciation.cpp @@ -186,12 +186,8 @@ DONNEES_ANNUELLES* H2O_M_Instanciation(int NombreDeReservoirs) NombreDeContraintes += NbPdt; ProblemeLineairePartieFixe->NombreDeContraintes = NombreDeContraintes; - ProblemeLineairePartieFixe->Sens - = (char*)malloc((unsigned int)NombreDeContraintes * sizeof(char)); - if (ProblemeLineairePartieFixe->Sens == NULL) - { - return (0); - } + ProblemeLineairePartieFixe->Sens.assign(NombreDeContraintes, 0); + ProblemeLineairePartieFixe->IndicesDebutDeLigne = (int*)malloc((unsigned int)NombreDeContraintes * sizeof(int)); if (ProblemeLineairePartieFixe->IndicesDebutDeLigne == NULL) diff --git a/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp b/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp index a60a583e5c..8fb19e7d58 100644 --- a/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp +++ b/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp @@ -95,7 +95,7 @@ void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES* DonneesAnnuelles, int N SPX_ModifierLeVecteurSecondMembre(ProbSpx, ProblemeLineairePartieVariable->SecondMembre, - ProblemeLineairePartieFixe->Sens, + ProblemeLineairePartieFixe->Sens.data(), ProblemeLineairePartieFixe->NombreDeContraintes); } @@ -115,7 +115,7 @@ void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES* DonneesAnnuelles, int N Probleme->IndicesColonnes = ProblemeLineairePartieFixe->IndicesColonnes; Probleme->CoefficientsDeLaMatriceDesContraintes = ProblemeLineairePartieFixe->CoefficientsDeLaMatriceDesContraintes.data(); - Probleme->Sens = ProblemeLineairePartieFixe->Sens; + Probleme->Sens = ProblemeLineairePartieFixe->Sens.data(); Probleme->SecondMembre = ProblemeLineairePartieVariable->SecondMembre; Probleme->ChoixDeLAlgorithme = SPX_DUAL; From 951ecfeb52763d9745cb39267136987c1c8aa819 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Tue, 12 Sep 2023 15:27:46 +0200 Subject: [PATCH 05/42] [DEV] Type de variable --- src/solver/hydro/monthly/h2o_m_donnees_optimisation.h | 2 +- src/solver/hydro/monthly/h2o_m_free.cpp | 1 - src/solver/hydro/monthly/h2o_m_instanciation.cpp | 7 +------ .../hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp | 2 +- 4 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h b/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h index 07ea2bd451..80e5536ec6 100644 --- a/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h +++ b/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h @@ -40,7 +40,7 @@ typedef struct int NombreDeVariables; std::vector CoutLineaire; std::vector CoutLineaireBruite; /* Ajout de bruit pour forcer l'unicité des solutions */ - int* TypeDeVariable; /* Indicateur du type de variable, il ne doit prendre que les suivantes + std::vector TypeDeVariable; /* Indicateur du type de variable, il ne doit prendre que les suivantes (voir le fichier spx_constantes_externes.h mais ne jamais utiliser les valeurs explicites des constantes): VARIABLE_FIXE , VARIABLE_BORNEE_DES_DEUX_COTES , diff --git a/src/solver/hydro/monthly/h2o_m_free.cpp b/src/solver/hydro/monthly/h2o_m_free.cpp index 8c5d750051..fb54da880b 100644 --- a/src/solver/hydro/monthly/h2o_m_free.cpp +++ b/src/solver/hydro/monthly/h2o_m_free.cpp @@ -59,7 +59,6 @@ void H2O_M_Free(DONNEES_ANNUELLES* DonneesAnnuelles) ->NumeroDeVariableDEcartNegatifAuTurbineCible); free(ProblemeHydraulique->CorrespondanceDesVariables); - free(ProblemeHydraulique->ProblemeLineairePartieFixe->TypeDeVariable); free(ProblemeHydraulique->ProblemeLineairePartieFixe->IndicesDebutDeLigne); free(ProblemeHydraulique->ProblemeLineairePartieFixe->NombreDeTermesDesLignes); free(ProblemeHydraulique->ProblemeLineairePartieFixe->IndicesColonnes); diff --git a/src/solver/hydro/monthly/h2o_m_instanciation.cpp b/src/solver/hydro/monthly/h2o_m_instanciation.cpp index 4871f1c6ba..4d50bc630c 100644 --- a/src/solver/hydro/monthly/h2o_m_instanciation.cpp +++ b/src/solver/hydro/monthly/h2o_m_instanciation.cpp @@ -169,12 +169,7 @@ DONNEES_ANNUELLES* H2O_M_Instanciation(int NombreDeReservoirs) ProblemeLineairePartieFixe->CoutLineaire.assign(NombreDeVariables, 0.); ProblemeLineairePartieFixe->CoutLineaireBruite.assign(NombreDeVariables, 0.); - ProblemeLineairePartieFixe->TypeDeVariable - = (int*)malloc((unsigned int)NombreDeVariables * sizeof(int)); - if (ProblemeLineairePartieFixe->TypeDeVariable == NULL) - { - return (0); - } + ProblemeLineairePartieFixe->TypeDeVariable.assign(NombreDeVariables, 0); NombreDeContraintes = 0; NombreDeContraintes += NbPdt; diff --git a/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp b/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp index 8fb19e7d58..88f0f4e02a 100644 --- a/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp +++ b/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp @@ -107,7 +107,7 @@ void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES* DonneesAnnuelles, int N Probleme->Xmin = ProblemeLineairePartieVariable->Xmin; Probleme->Xmax = ProblemeLineairePartieVariable->Xmax; Probleme->NombreDeVariables = ProblemeLineairePartieFixe->NombreDeVariables; - Probleme->TypeDeVariable = ProblemeLineairePartieFixe->TypeDeVariable; + Probleme->TypeDeVariable = ProblemeLineairePartieFixe->TypeDeVariable.data(); Probleme->NombreDeContraintes = ProblemeLineairePartieFixe->NombreDeContraintes; Probleme->IndicesDebutDeLigne = ProblemeLineairePartieFixe->IndicesDebutDeLigne; From f479d4e2161934f7c58dde5fa9cca8dc819c98bd Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Tue, 12 Sep 2023 15:54:48 +0200 Subject: [PATCH 06/42] [DEV] PROBLEME_LINEAIRE_PARTIE_FIXE --- .../h2o_m_construire_les_contraintes.cpp | 9 +++----- .../monthly/h2o_m_donnees_optimisation.h | 6 +++--- src/solver/hydro/monthly/h2o_m_free.cpp | 3 --- .../hydro/monthly/h2o_m_instanciation.cpp | 21 +++---------------- .../h2o_m_resoudre_le_probleme_lineaire.cpp | 6 +++--- 5 files changed, 12 insertions(+), 33 deletions(-) diff --git a/src/solver/hydro/monthly/h2o_m_construire_les_contraintes.cpp b/src/solver/hydro/monthly/h2o_m_construire_les_contraintes.cpp index d4ab33eb5c..6fe0f7ed25 100644 --- a/src/solver/hydro/monthly/h2o_m_construire_les_contraintes.cpp +++ b/src/solver/hydro/monthly/h2o_m_construire_les_contraintes.cpp @@ -34,9 +34,6 @@ void H2O_M_ConstruireLesContraintes(DONNEES_ANNUELLES* DonneesAnnuelles) int il; int Pdt; int NbPdt; - int* IndicesColonnes; - int* IndicesDebutDeLigne; - int* NombreDeTermesDesLignes; double ChgmtSens; int* NumeroDeVariableVolume; int* NumeroDeVariableTurbine; @@ -60,10 +57,10 @@ void H2O_M_ConstruireLesContraintes(DONNEES_ANNUELLES* DonneesAnnuelles) auto& CoefficientsDeLaMatriceDesContraintes = ProblemeLineairePartieFixe->CoefficientsDeLaMatriceDesContraintes; - IndicesColonnes = ProblemeLineairePartieFixe->IndicesColonnes; - IndicesDebutDeLigne = ProblemeLineairePartieFixe->IndicesDebutDeLigne; + auto& IndicesColonnes = ProblemeLineairePartieFixe->IndicesColonnes; + auto& IndicesDebutDeLigne = ProblemeLineairePartieFixe->IndicesDebutDeLigne; auto& Sens = ProblemeLineairePartieFixe->Sens; - NombreDeTermesDesLignes = ProblemeLineairePartieFixe->NombreDeTermesDesLignes; + auto& NombreDeTermesDesLignes = ProblemeLineairePartieFixe->NombreDeTermesDesLignes; NumeroDeVariableVolume = CorrespondanceDesVariables->NumeroDeVariableVolume; NumeroDeVariableTurbine = CorrespondanceDesVariables->NumeroDeVariableTurbine; diff --git a/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h b/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h index 80e5536ec6..1640b76bea 100644 --- a/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h +++ b/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h @@ -51,10 +51,10 @@ typedef struct /* La matrice des contraintes */ int NombreDeContraintes; std::vector Sens; - int* IndicesDebutDeLigne; - int* NombreDeTermesDesLignes; + std::vector IndicesDebutDeLigne; + std::vector NombreDeTermesDesLignes; std::vector CoefficientsDeLaMatriceDesContraintes; - int* IndicesColonnes; + std::vector IndicesColonnes; int NombreDeTermesAlloues; } PROBLEME_LINEAIRE_PARTIE_FIXE; diff --git a/src/solver/hydro/monthly/h2o_m_free.cpp b/src/solver/hydro/monthly/h2o_m_free.cpp index fb54da880b..c9aeba7bf3 100644 --- a/src/solver/hydro/monthly/h2o_m_free.cpp +++ b/src/solver/hydro/monthly/h2o_m_free.cpp @@ -59,9 +59,6 @@ void H2O_M_Free(DONNEES_ANNUELLES* DonneesAnnuelles) ->NumeroDeVariableDEcartNegatifAuTurbineCible); free(ProblemeHydraulique->CorrespondanceDesVariables); - free(ProblemeHydraulique->ProblemeLineairePartieFixe->IndicesDebutDeLigne); - free(ProblemeHydraulique->ProblemeLineairePartieFixe->NombreDeTermesDesLignes); - free(ProblemeHydraulique->ProblemeLineairePartieFixe->IndicesColonnes); free(ProblemeHydraulique->ProblemeLineairePartieFixe); free(ProblemeHydraulique->ProblemeLineairePartieVariable->Xmin); diff --git a/src/solver/hydro/monthly/h2o_m_instanciation.cpp b/src/solver/hydro/monthly/h2o_m_instanciation.cpp index 4d50bc630c..15033ac188 100644 --- a/src/solver/hydro/monthly/h2o_m_instanciation.cpp +++ b/src/solver/hydro/monthly/h2o_m_instanciation.cpp @@ -183,18 +183,8 @@ DONNEES_ANNUELLES* H2O_M_Instanciation(int NombreDeReservoirs) ProblemeLineairePartieFixe->NombreDeContraintes = NombreDeContraintes; ProblemeLineairePartieFixe->Sens.assign(NombreDeContraintes, 0); - ProblemeLineairePartieFixe->IndicesDebutDeLigne - = (int*)malloc((unsigned int)NombreDeContraintes * sizeof(int)); - if (ProblemeLineairePartieFixe->IndicesDebutDeLigne == NULL) - { - return (0); - } - ProblemeLineairePartieFixe->NombreDeTermesDesLignes - = (int*)malloc((unsigned int)NombreDeContraintes * sizeof(int)); - if (ProblemeLineairePartieFixe->NombreDeTermesDesLignes == NULL) - { - return (0); - } + ProblemeLineairePartieFixe->IndicesDebutDeLigne.assign(NombreDeContraintes, 0); + ProblemeLineairePartieFixe->NombreDeTermesDesLignes.assign(NombreDeContraintes, 0); NombreDeTermesAlloues = 0; NombreDeTermesAlloues += 3 * NbPdt; @@ -210,12 +200,7 @@ DONNEES_ANNUELLES* H2O_M_Instanciation(int NombreDeReservoirs) ProblemeLineairePartieFixe->CoefficientsDeLaMatriceDesContraintes .assign(NombreDeTermesAlloues, 0.); - ProblemeLineairePartieFixe->IndicesColonnes - = (int*)malloc((unsigned int)NombreDeTermesAlloues * sizeof(int)); - if (ProblemeLineairePartieFixe->IndicesColonnes == NULL) - { - return (0); - } + ProblemeLineairePartieFixe->IndicesColonnes.assign(NombreDeTermesAlloues, 0); ProblemeLineairePartieVariable->Xmin = (double*)malloc((unsigned int)NombreDeVariables * sizeof(double)); diff --git a/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp b/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp index 88f0f4e02a..6c8d587930 100644 --- a/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp +++ b/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp @@ -110,9 +110,9 @@ void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES* DonneesAnnuelles, int N Probleme->TypeDeVariable = ProblemeLineairePartieFixe->TypeDeVariable.data(); Probleme->NombreDeContraintes = ProblemeLineairePartieFixe->NombreDeContraintes; - Probleme->IndicesDebutDeLigne = ProblemeLineairePartieFixe->IndicesDebutDeLigne; - Probleme->NombreDeTermesDesLignes = ProblemeLineairePartieFixe->NombreDeTermesDesLignes; - Probleme->IndicesColonnes = ProblemeLineairePartieFixe->IndicesColonnes; + Probleme->IndicesDebutDeLigne = ProblemeLineairePartieFixe->IndicesDebutDeLigne.data(); + Probleme->NombreDeTermesDesLignes = ProblemeLineairePartieFixe->NombreDeTermesDesLignes.data(); + Probleme->IndicesColonnes = ProblemeLineairePartieFixe->IndicesColonnes.data(); Probleme->CoefficientsDeLaMatriceDesContraintes = ProblemeLineairePartieFixe->CoefficientsDeLaMatriceDesContraintes.data(); Probleme->Sens = ProblemeLineairePartieFixe->Sens.data(); From 92f430f8cee4b967655b562b7270a6d061c4ad8f Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Tue, 12 Sep 2023 16:00:21 +0200 Subject: [PATCH 07/42] [DEV] Xmin Xmax SecondeMembre --- .../monthly/h2o_m_donnees_optimisation.h | 6 ++-- src/solver/hydro/monthly/h2o_m_free.cpp | 3 -- ...m_initialiser_les_bornes_des_variables.cpp | 8 ++--- .../h2o_m_initialiser_les_second_membre.cpp | 33 +++++++------------ .../hydro/monthly/h2o_m_instanciation.cpp | 22 ++----------- .../h2o_m_resoudre_le_probleme_lineaire.cpp | 8 ++--- 6 files changed, 24 insertions(+), 56 deletions(-) diff --git a/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h b/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h index 1640b76bea..8029ef828d 100644 --- a/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h +++ b/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h @@ -64,9 +64,9 @@ typedef struct /* Donnees variables de la matrice des contraintes */ /* On met quand-meme les bornes dans la partie variable pour le cas ou on voudrait avoir un jour des bornes min et max variables dans le temps et en fonction des reservoirs */ - double* Xmin; - double* Xmax; - double* SecondMembre; + std::vector Xmin; + std::vector Xmax; + std::vector SecondMembre; /* Tableau de pointeur a des doubles. Ce tableau est parallele a X, il permet de renseigner directement les structures de description du reseau avec les resultats contenus dans X */ diff --git a/src/solver/hydro/monthly/h2o_m_free.cpp b/src/solver/hydro/monthly/h2o_m_free.cpp index c9aeba7bf3..03bec365c4 100644 --- a/src/solver/hydro/monthly/h2o_m_free.cpp +++ b/src/solver/hydro/monthly/h2o_m_free.cpp @@ -61,9 +61,6 @@ void H2O_M_Free(DONNEES_ANNUELLES* DonneesAnnuelles) free(ProblemeHydraulique->ProblemeLineairePartieFixe); - free(ProblemeHydraulique->ProblemeLineairePartieVariable->Xmin); - free(ProblemeHydraulique->ProblemeLineairePartieVariable->Xmax); - free(ProblemeHydraulique->ProblemeLineairePartieVariable->SecondMembre); free((ProblemeHydraulique->ProblemeLineairePartieVariable) ->AdresseOuPlacerLaValeurDesVariablesOptimisees); free(ProblemeHydraulique->ProblemeLineairePartieVariable->X); diff --git a/src/solver/hydro/monthly/h2o_m_initialiser_les_bornes_des_variables.cpp b/src/solver/hydro/monthly/h2o_m_initialiser_les_bornes_des_variables.cpp index e5813774a6..5d35eae2e6 100644 --- a/src/solver/hydro/monthly/h2o_m_initialiser_les_bornes_des_variables.cpp +++ b/src/solver/hydro/monthly/h2o_m_initialiser_les_bornes_des_variables.cpp @@ -31,12 +31,10 @@ void H2O_M_InitialiserBornesEtCoutsDesVariables(DONNEES_ANNUELLES* DonneesAnnuelles) { int Var; - double* Xmin; - double* Xmax; double* X; const PROBLEME_HYDRAULIQUE* ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; - const PROBLEME_LINEAIRE_PARTIE_VARIABLE* ProblemeLineairePartieVariable + PROBLEME_LINEAIRE_PARTIE_VARIABLE* ProblemeLineairePartieVariable = ProblemeHydraulique->ProblemeLineairePartieVariable; const CORRESPONDANCE_DES_VARIABLES* CorrespondanceDesVariables = ProblemeHydraulique->CorrespondanceDesVariables; @@ -51,8 +49,8 @@ void H2O_M_InitialiserBornesEtCoutsDesVariables(DONNEES_ANNUELLES* DonneesAnnuel const auto& TurbineMin = DonneesAnnuelles->TurbineMin; - Xmin = ProblemeLineairePartieVariable->Xmin; - Xmax = ProblemeLineairePartieVariable->Xmax; + auto& Xmin = ProblemeLineairePartieVariable->Xmin; + auto& Xmax = ProblemeLineairePartieVariable->Xmax; X = ProblemeLineairePartieVariable->X; auto& CoutLineaire = ProblemeLineairePartieFixe->CoutLineaire; diff --git a/src/solver/hydro/monthly/h2o_m_initialiser_les_second_membre.cpp b/src/solver/hydro/monthly/h2o_m_initialiser_les_second_membre.cpp index 05bc0ba8cc..3cb60f4726 100644 --- a/src/solver/hydro/monthly/h2o_m_initialiser_les_second_membre.cpp +++ b/src/solver/hydro/monthly/h2o_m_initialiser_les_second_membre.cpp @@ -30,29 +30,18 @@ void H2O_M_InitialiserLeSecondMembre(DONNEES_ANNUELLES* DonneesAnnuelles) { - int Pdt; - int Cnt; - int NbPdt; - double* SecondMembre; - double ChgmtSens; + PROBLEME_HYDRAULIQUE* ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; + PROBLEME_LINEAIRE_PARTIE_VARIABLE* ProblemeLineairePartieVariable + = ProblemeHydraulique->ProblemeLineairePartieVariable; - PROBLEME_HYDRAULIQUE* ProblemeHydraulique; - PROBLEME_LINEAIRE_PARTIE_VARIABLE* ProblemeLineairePartieVariable; - - ChgmtSens = -1; - - NbPdt = DonneesAnnuelles->NombreDePasDeTemps; + double ChgmtSens = -1; + int NbPdt = DonneesAnnuelles->NombreDePasDeTemps; + int Cnt = 0; auto& TurbineCible = DonneesAnnuelles->TurbineCible; + auto& SecondMembre = ProblemeLineairePartieVariable->SecondMembre; - ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; - - ProblemeLineairePartieVariable = ProblemeHydraulique->ProblemeLineairePartieVariable; - SecondMembre = ProblemeLineairePartieVariable->SecondMembre; - - Cnt = 0; - - for (Pdt = 1; Pdt < NbPdt; Pdt++) + for (int Pdt = 1; Pdt < NbPdt; Pdt++) { SecondMembre[Cnt] = DonneesAnnuelles->Apport[Pdt - 1]; Cnt++; @@ -61,7 +50,7 @@ void H2O_M_InitialiserLeSecondMembre(DONNEES_ANNUELLES* DonneesAnnuelles) SecondMembre[Cnt] = DonneesAnnuelles->Volume[0] - DonneesAnnuelles->Apport[NbPdt - 1]; Cnt++; - for (Pdt = 1; Pdt < NbPdt; Pdt++) + for (int Pdt = 1; Pdt < NbPdt; Pdt++) { SecondMembre[Cnt] = DonneesAnnuelles->VolumeMax[Pdt]; Cnt++; @@ -70,13 +59,13 @@ void H2O_M_InitialiserLeSecondMembre(DONNEES_ANNUELLES* DonneesAnnuelles) Cnt++; } - for (Pdt = 1; Pdt < NbPdt; Pdt++) + for (int Pdt = 1; Pdt < NbPdt; Pdt++) { SecondMembre[Cnt] = 0.; Cnt++; } - for (Pdt = 0; Pdt < NbPdt; Pdt++) + for (int Pdt = 0; Pdt < NbPdt; Pdt++) { SecondMembre[Cnt] = TurbineCible[Pdt]; Cnt++; diff --git a/src/solver/hydro/monthly/h2o_m_instanciation.cpp b/src/solver/hydro/monthly/h2o_m_instanciation.cpp index 15033ac188..8280d72a38 100644 --- a/src/solver/hydro/monthly/h2o_m_instanciation.cpp +++ b/src/solver/hydro/monthly/h2o_m_instanciation.cpp @@ -202,25 +202,9 @@ DONNEES_ANNUELLES* H2O_M_Instanciation(int NombreDeReservoirs) ProblemeLineairePartieFixe->IndicesColonnes.assign(NombreDeTermesAlloues, 0); - ProblemeLineairePartieVariable->Xmin - = (double*)malloc((unsigned int)NombreDeVariables * sizeof(double)); - if (ProblemeLineairePartieVariable->Xmin == NULL) - { - return (0); - } - - ProblemeLineairePartieVariable->Xmax - = (double*)malloc((unsigned int)NombreDeVariables * sizeof(double)); - if (ProblemeLineairePartieVariable->Xmax == NULL) - { - return (0); - } - ProblemeLineairePartieVariable->SecondMembre - = (double*)malloc((unsigned int)NombreDeContraintes * sizeof(double)); - if (ProblemeLineairePartieVariable->SecondMembre == NULL) - { - return (0); - } + ProblemeLineairePartieVariable->Xmin.assign(NombreDeVariables, 0.); + ProblemeLineairePartieVariable->Xmax.assign(NombreDeVariables, 0.); + ProblemeLineairePartieVariable->SecondMembre.assign(NombreDeContraintes, 0.); ProblemeLineairePartieVariable->AdresseOuPlacerLaValeurDesVariablesOptimisees = (double**)malloc((unsigned int)NombreDeVariables * sizeof(double*)); diff --git a/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp b/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp index 6c8d587930..1c82cb15d6 100644 --- a/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp +++ b/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp @@ -94,7 +94,7 @@ void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES* DonneesAnnuelles, int N Probleme->BaseDeDepartFournie = UTILISER_LA_BASE_DU_PROBLEME_SPX; SPX_ModifierLeVecteurSecondMembre(ProbSpx, - ProblemeLineairePartieVariable->SecondMembre, + ProblemeLineairePartieVariable->SecondMembre.data(), ProblemeLineairePartieFixe->Sens.data(), ProblemeLineairePartieFixe->NombreDeContraintes); } @@ -104,8 +104,8 @@ void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES* DonneesAnnuelles, int N Probleme->CoutLineaire = ProblemeLineairePartieFixe->CoutLineaireBruite.data(); Probleme->X = ProblemeLineairePartieVariable->X; - Probleme->Xmin = ProblemeLineairePartieVariable->Xmin; - Probleme->Xmax = ProblemeLineairePartieVariable->Xmax; + Probleme->Xmin = ProblemeLineairePartieVariable->Xmin.data(); + Probleme->Xmax = ProblemeLineairePartieVariable->Xmax.data(); Probleme->NombreDeVariables = ProblemeLineairePartieFixe->NombreDeVariables; Probleme->TypeDeVariable = ProblemeLineairePartieFixe->TypeDeVariable.data(); @@ -116,7 +116,7 @@ void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES* DonneesAnnuelles, int N Probleme->CoefficientsDeLaMatriceDesContraintes = ProblemeLineairePartieFixe->CoefficientsDeLaMatriceDesContraintes.data(); Probleme->Sens = ProblemeLineairePartieFixe->Sens.data(); - Probleme->SecondMembre = ProblemeLineairePartieVariable->SecondMembre; + Probleme->SecondMembre = ProblemeLineairePartieVariable->SecondMembre.data(); Probleme->ChoixDeLAlgorithme = SPX_DUAL; From 69a9861e3cb90014fd18d2a0efe0aa5283e24078 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Tue, 12 Sep 2023 16:03:42 +0200 Subject: [PATCH 08/42] [DEV] X CoutsReduits CoutsMarginauxDesContraintes --- .../monthly/h2o_m_donnees_optimisation.h | 6 ++--- src/solver/hydro/monthly/h2o_m_free.cpp | 3 --- ...m_initialiser_les_bornes_des_variables.cpp | 3 +-- .../hydro/monthly/h2o_m_instanciation.cpp | 22 +++---------------- .../h2o_m_resoudre_le_probleme_lineaire.cpp | 6 ++--- 5 files changed, 10 insertions(+), 30 deletions(-) diff --git a/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h b/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h index 8029ef828d..e3a67b8e18 100644 --- a/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h +++ b/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h @@ -72,7 +72,7 @@ typedef struct resultats contenus dans X */ double** AdresseOuPlacerLaValeurDesVariablesOptimisees; /* Resultat */ - double* X; + std::vector X; /* En Entree ou en Sortie */ int ExistenceDUneSolution; /* En sortie, vaut : OUI_SPX s'il y a une solution, @@ -86,8 +86,8 @@ typedef struct int* PositionDeLaVariable; /* Vecteur a passer au Simplexe pour recuperer la base optimale */ int* ComplementDeLaBase; /* Vecteur a passer au Simplexe pour recuperer la base optimale */ - double* CoutsReduits; /* Vecteur a passer au Simplexe pour recuperer les couts reduits */ - double* CoutsMarginauxDesContraintes; /* Vecteur a passer au Simplexe pour recuperer les couts + std::vector CoutsReduits; /* Vecteur a passer au Simplexe pour recuperer les couts reduits */ + std::vector CoutsMarginauxDesContraintes; /* Vecteur a passer au Simplexe pour recuperer les couts marginaux */ } PROBLEME_LINEAIRE_PARTIE_VARIABLE; diff --git a/src/solver/hydro/monthly/h2o_m_free.cpp b/src/solver/hydro/monthly/h2o_m_free.cpp index 03bec365c4..a5bd78d8f3 100644 --- a/src/solver/hydro/monthly/h2o_m_free.cpp +++ b/src/solver/hydro/monthly/h2o_m_free.cpp @@ -63,11 +63,8 @@ void H2O_M_Free(DONNEES_ANNUELLES* DonneesAnnuelles) free((ProblemeHydraulique->ProblemeLineairePartieVariable) ->AdresseOuPlacerLaValeurDesVariablesOptimisees); - free(ProblemeHydraulique->ProblemeLineairePartieVariable->X); free(ProblemeHydraulique->ProblemeLineairePartieVariable->PositionDeLaVariable); free(ProblemeHydraulique->ProblemeLineairePartieVariable->ComplementDeLaBase); - free(ProblemeHydraulique->ProblemeLineairePartieVariable->CoutsReduits); - free(ProblemeHydraulique->ProblemeLineairePartieVariable->CoutsMarginauxDesContraintes); free(ProblemeHydraulique->ProblemeLineairePartieVariable); for (i = 0; i < ProblemeHydraulique->NombreDeReservoirs; i++) diff --git a/src/solver/hydro/monthly/h2o_m_initialiser_les_bornes_des_variables.cpp b/src/solver/hydro/monthly/h2o_m_initialiser_les_bornes_des_variables.cpp index 5d35eae2e6..76c04e9edc 100644 --- a/src/solver/hydro/monthly/h2o_m_initialiser_les_bornes_des_variables.cpp +++ b/src/solver/hydro/monthly/h2o_m_initialiser_les_bornes_des_variables.cpp @@ -31,7 +31,6 @@ void H2O_M_InitialiserBornesEtCoutsDesVariables(DONNEES_ANNUELLES* DonneesAnnuelles) { int Var; - double* X; const PROBLEME_HYDRAULIQUE* ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; PROBLEME_LINEAIRE_PARTIE_VARIABLE* ProblemeLineairePartieVariable @@ -51,7 +50,7 @@ void H2O_M_InitialiserBornesEtCoutsDesVariables(DONNEES_ANNUELLES* DonneesAnnuel auto& Xmin = ProblemeLineairePartieVariable->Xmin; auto& Xmax = ProblemeLineairePartieVariable->Xmax; - X = ProblemeLineairePartieVariable->X; + auto& X = ProblemeLineairePartieVariable->X; auto& CoutLineaire = ProblemeLineairePartieFixe->CoutLineaire; Var = CorrespondanceDesVariables->NumeroDeVariableVolume[0]; diff --git a/src/solver/hydro/monthly/h2o_m_instanciation.cpp b/src/solver/hydro/monthly/h2o_m_instanciation.cpp index 8280d72a38..d4fc4cb29a 100644 --- a/src/solver/hydro/monthly/h2o_m_instanciation.cpp +++ b/src/solver/hydro/monthly/h2o_m_instanciation.cpp @@ -213,12 +213,7 @@ DONNEES_ANNUELLES* H2O_M_Instanciation(int NombreDeReservoirs) return (0); } - ProblemeLineairePartieVariable->X - = (double*)malloc((unsigned int)NombreDeVariables * sizeof(double)); - if (ProblemeLineairePartieVariable->X == NULL) - { - return (0); - } + ProblemeLineairePartieVariable->X.assign(NombreDeVariables, 0.); for (j = 0; j < NombreDeVariables; j++) { @@ -239,19 +234,8 @@ DONNEES_ANNUELLES* H2O_M_Instanciation(int NombreDeReservoirs) return (0); } - ProblemeLineairePartieVariable->CoutsReduits - = (double*)malloc((unsigned int)NombreDeVariables * sizeof(double)); - if (ProblemeLineairePartieVariable->CoutsReduits == NULL) - { - return (0); - } - - ProblemeLineairePartieVariable->CoutsMarginauxDesContraintes - = (double*)malloc((unsigned int)NombreDeContraintes * sizeof(double)); - if (ProblemeLineairePartieVariable->CoutsMarginauxDesContraintes == NULL) - { - return (0); - } + ProblemeLineairePartieVariable->CoutsReduits.assign(NombreDeVariables, 0.); + ProblemeLineairePartieVariable->CoutsMarginauxDesContraintes.assign(NombreDeContraintes, 0.); H2O_M_ConstruireLesVariables(DonneesAnnuelles); diff --git a/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp b/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp index 1c82cb15d6..c68b31a498 100644 --- a/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp +++ b/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp @@ -103,7 +103,7 @@ void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES* DonneesAnnuelles, int N Probleme->DureeMaxDuCalcul = -1.; Probleme->CoutLineaire = ProblemeLineairePartieFixe->CoutLineaireBruite.data(); - Probleme->X = ProblemeLineairePartieVariable->X; + Probleme->X = ProblemeLineairePartieVariable->X.data(); Probleme->Xmin = ProblemeLineairePartieVariable->Xmin.data(); Probleme->Xmax = ProblemeLineairePartieVariable->Xmax.data(); Probleme->NombreDeVariables = ProblemeLineairePartieFixe->NombreDeVariables; @@ -134,8 +134,8 @@ void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES* DonneesAnnuelles, int N Probleme->CoutMax = 0.0; Probleme->CoutsMarginauxDesContraintes - = ProblemeLineairePartieVariable->CoutsMarginauxDesContraintes; - Probleme->CoutsReduits = ProblemeLineairePartieVariable->CoutsReduits; + = ProblemeLineairePartieVariable->CoutsMarginauxDesContraintes.data(); + Probleme->CoutsReduits = ProblemeLineairePartieVariable->CoutsReduits.data(); #ifndef NDEBUG if (PremierPassage == OUI) From f86b83cfbb261d3de049b94fbe756ee096a9b81d Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Tue, 12 Sep 2023 16:06:16 +0200 Subject: [PATCH 09/42] [DEV] PositionDeLaVariable ComplementDeLaBase --- .../hydro/monthly/h2o_m_donnees_optimisation.h | 4 ++-- src/solver/hydro/monthly/h2o_m_free.cpp | 2 -- src/solver/hydro/monthly/h2o_m_instanciation.cpp | 15 ++------------- .../h2o_m_resoudre_le_probleme_lineaire.cpp | 4 ++-- 4 files changed, 6 insertions(+), 19 deletions(-) diff --git a/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h b/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h index e3a67b8e18..faa15725fb 100644 --- a/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h +++ b/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h @@ -84,8 +84,8 @@ typedef struct pas de solution */ - int* PositionDeLaVariable; /* Vecteur a passer au Simplexe pour recuperer la base optimale */ - int* ComplementDeLaBase; /* Vecteur a passer au Simplexe pour recuperer la base optimale */ + std::vector PositionDeLaVariable; /* Vecteur a passer au Simplexe pour recuperer la base optimale */ + std::vector ComplementDeLaBase; /* Vecteur a passer au Simplexe pour recuperer la base optimale */ std::vector CoutsReduits; /* Vecteur a passer au Simplexe pour recuperer les couts reduits */ std::vector CoutsMarginauxDesContraintes; /* Vecteur a passer au Simplexe pour recuperer les couts marginaux */ diff --git a/src/solver/hydro/monthly/h2o_m_free.cpp b/src/solver/hydro/monthly/h2o_m_free.cpp index a5bd78d8f3..00986e2412 100644 --- a/src/solver/hydro/monthly/h2o_m_free.cpp +++ b/src/solver/hydro/monthly/h2o_m_free.cpp @@ -63,8 +63,6 @@ void H2O_M_Free(DONNEES_ANNUELLES* DonneesAnnuelles) free((ProblemeHydraulique->ProblemeLineairePartieVariable) ->AdresseOuPlacerLaValeurDesVariablesOptimisees); - free(ProblemeHydraulique->ProblemeLineairePartieVariable->PositionDeLaVariable); - free(ProblemeHydraulique->ProblemeLineairePartieVariable->ComplementDeLaBase); free(ProblemeHydraulique->ProblemeLineairePartieVariable); for (i = 0; i < ProblemeHydraulique->NombreDeReservoirs; i++) diff --git a/src/solver/hydro/monthly/h2o_m_instanciation.cpp b/src/solver/hydro/monthly/h2o_m_instanciation.cpp index d4fc4cb29a..10e2166eb3 100644 --- a/src/solver/hydro/monthly/h2o_m_instanciation.cpp +++ b/src/solver/hydro/monthly/h2o_m_instanciation.cpp @@ -220,19 +220,8 @@ DONNEES_ANNUELLES* H2O_M_Instanciation(int NombreDeReservoirs) ProblemeLineairePartieVariable->AdresseOuPlacerLaValeurDesVariablesOptimisees[j] = NULL; } - ProblemeLineairePartieVariable->PositionDeLaVariable - = (int*)malloc((unsigned int)NombreDeVariables * sizeof(int)); - if (ProblemeLineairePartieVariable->PositionDeLaVariable == NULL) - { - return (0); - } - - ProblemeLineairePartieVariable->ComplementDeLaBase - = (int*)malloc((unsigned int)NombreDeContraintes * sizeof(int)); - if (ProblemeLineairePartieVariable->ComplementDeLaBase == NULL) - { - return (0); - } + ProblemeLineairePartieVariable->PositionDeLaVariable.assign(NombreDeVariables, 0); + ProblemeLineairePartieVariable->ComplementDeLaBase.assign(NombreDeContraintes, 0); ProblemeLineairePartieVariable->CoutsReduits.assign(NombreDeVariables, 0.); ProblemeLineairePartieVariable->CoutsMarginauxDesContraintes.assign(NombreDeContraintes, 0.); diff --git a/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp b/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp index c68b31a498..0c463c0eff 100644 --- a/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp +++ b/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp @@ -124,9 +124,9 @@ void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES* DonneesAnnuelles, int N Probleme->FaireDuScaling = OUI_SPX; Probleme->StrategieAntiDegenerescence = AGRESSIF; - Probleme->PositionDeLaVariable = ProblemeLineairePartieVariable->PositionDeLaVariable; + Probleme->PositionDeLaVariable = ProblemeLineairePartieVariable->PositionDeLaVariable.data(); Probleme->NbVarDeBaseComplementaires = 0; - Probleme->ComplementDeLaBase = ProblemeLineairePartieVariable->ComplementDeLaBase; + Probleme->ComplementDeLaBase = ProblemeLineairePartieVariable->ComplementDeLaBase.data(); Probleme->LibererMemoireALaFin = NON_SPX; From f838e95ff64001792e7d671fbf899f41ab922e25 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Tue, 12 Sep 2023 16:07:46 +0200 Subject: [PATCH 10/42] [DEV] PROBLEME_LINEAIRE_PARTIE_VARIABLE --- src/solver/hydro/monthly/h2o_m_donnees_optimisation.h | 2 +- src/solver/hydro/monthly/h2o_m_free.cpp | 2 -- src/solver/hydro/monthly/h2o_m_instanciation.cpp | 10 +--------- 3 files changed, 2 insertions(+), 12 deletions(-) diff --git a/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h b/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h index faa15725fb..7c295b12d2 100644 --- a/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h +++ b/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h @@ -70,7 +70,7 @@ typedef struct /* Tableau de pointeur a des doubles. Ce tableau est parallele a X, il permet de renseigner directement les structures de description du reseau avec les resultats contenus dans X */ - double** AdresseOuPlacerLaValeurDesVariablesOptimisees; + std::vector AdresseOuPlacerLaValeurDesVariablesOptimisees; /* Resultat */ std::vector X; /* En Entree ou en Sortie */ diff --git a/src/solver/hydro/monthly/h2o_m_free.cpp b/src/solver/hydro/monthly/h2o_m_free.cpp index 00986e2412..ac63ec76af 100644 --- a/src/solver/hydro/monthly/h2o_m_free.cpp +++ b/src/solver/hydro/monthly/h2o_m_free.cpp @@ -61,8 +61,6 @@ void H2O_M_Free(DONNEES_ANNUELLES* DonneesAnnuelles) free(ProblemeHydraulique->ProblemeLineairePartieFixe); - free((ProblemeHydraulique->ProblemeLineairePartieVariable) - ->AdresseOuPlacerLaValeurDesVariablesOptimisees); free(ProblemeHydraulique->ProblemeLineairePartieVariable); for (i = 0; i < ProblemeHydraulique->NombreDeReservoirs; i++) diff --git a/src/solver/hydro/monthly/h2o_m_instanciation.cpp b/src/solver/hydro/monthly/h2o_m_instanciation.cpp index 10e2166eb3..af3208afec 100644 --- a/src/solver/hydro/monthly/h2o_m_instanciation.cpp +++ b/src/solver/hydro/monthly/h2o_m_instanciation.cpp @@ -207,18 +207,10 @@ DONNEES_ANNUELLES* H2O_M_Instanciation(int NombreDeReservoirs) ProblemeLineairePartieVariable->SecondMembre.assign(NombreDeContraintes, 0.); ProblemeLineairePartieVariable->AdresseOuPlacerLaValeurDesVariablesOptimisees - = (double**)malloc((unsigned int)NombreDeVariables * sizeof(double*)); - if (ProblemeLineairePartieVariable->AdresseOuPlacerLaValeurDesVariablesOptimisees == NULL) - { - return (0); - } + .assign(NombreDeVariables, nullptr); ProblemeLineairePartieVariable->X.assign(NombreDeVariables, 0.); - for (j = 0; j < NombreDeVariables; j++) - { - ProblemeLineairePartieVariable->AdresseOuPlacerLaValeurDesVariablesOptimisees[j] = NULL; - } ProblemeLineairePartieVariable->PositionDeLaVariable.assign(NombreDeVariables, 0); ProblemeLineairePartieVariable->ComplementDeLaBase.assign(NombreDeContraintes, 0); From 1ee25faa339b53baeaa2e706ce91f24d5c4adb86 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Tue, 12 Sep 2023 16:49:34 +0200 Subject: [PATCH 11/42] [DEV] CorrespondanceDesVariables --- .../hydro/monthly/h2o_m_ajouter_bruit.cpp | 20 +++---- .../h2o_m_construire_les_contraintes.cpp | 34 +++++------ .../h2o_m_construire_les_variables.cpp | 22 +++---- .../monthly/h2o_m_donnees_optimisation.h | 14 ++--- src/solver/hydro/monthly/h2o_m_free.cpp | 10 ---- ...m_initialiser_les_bornes_des_variables.cpp | 20 +++---- .../hydro/monthly/h2o_m_instanciation.cpp | 57 +++---------------- 7 files changed, 59 insertions(+), 118 deletions(-) diff --git a/src/solver/hydro/monthly/h2o_m_ajouter_bruit.cpp b/src/solver/hydro/monthly/h2o_m_ajouter_bruit.cpp index e5fb3fa953..394a0e8205 100644 --- a/src/solver/hydro/monthly/h2o_m_ajouter_bruit.cpp +++ b/src/solver/hydro/monthly/h2o_m_ajouter_bruit.cpp @@ -14,7 +14,7 @@ void H2O_M_AjouterBruitAuCout(DONNEES_ANNUELLES* DonneesAnnuelles) PROBLEME_HYDRAULIQUE* ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; PROBLEME_LINEAIRE_PARTIE_FIXE* ProblemeLineairePartieFixe = ProblemeHydraulique->ProblemeLineairePartieFixe; - CORRESPONDANCE_DES_VARIABLES* CorrespondanceDesVariables + CORRESPONDANCE_DES_VARIABLES& CorrespondanceDesVariables = ProblemeHydraulique->CorrespondanceDesVariables; auto& CoutLineaireBruite = ProblemeLineairePartieFixe->CoutLineaireBruite; const auto& CoutLineaire = ProblemeLineairePartieFixe->CoutLineaire; @@ -22,13 +22,13 @@ void H2O_M_AjouterBruitAuCout(DONNEES_ANNUELLES* DonneesAnnuelles) Antares::MersenneTwister noiseGenerator; noiseGenerator.reset(Constants::seed); // Arbitrary seed, hard-coded since we don't really want // the user to change it - const std::vector monthlyVariables - = {CorrespondanceDesVariables->NumeroDeVariableVolume, - CorrespondanceDesVariables->NumeroDeVariableTurbine, - CorrespondanceDesVariables->NumeroDeVariableDepassementVolumeMax, - CorrespondanceDesVariables->NumeroDeVariableDepassementVolumeMin, - CorrespondanceDesVariables->NumeroDeVariableDEcartPositifAuTurbineCible, - CorrespondanceDesVariables->NumeroDeVariableDEcartNegatifAuTurbineCible}; + const std::vector> monthlyVariables + = {CorrespondanceDesVariables.NumeroDeVariableVolume, + CorrespondanceDesVariables.NumeroDeVariableTurbine, + CorrespondanceDesVariables.NumeroDeVariableDepassementVolumeMax, + CorrespondanceDesVariables.NumeroDeVariableDepassementVolumeMin, + CorrespondanceDesVariables.NumeroDeVariableDEcartPositifAuTurbineCible, + CorrespondanceDesVariables.NumeroDeVariableDEcartNegatifAuTurbineCible}; for (const auto variable : monthlyVariables) { @@ -39,9 +39,9 @@ void H2O_M_AjouterBruitAuCout(DONNEES_ANNUELLES* DonneesAnnuelles) = CoutLineaire[Var] + noiseGenerator() * Constants::noiseAmplitude; } } - int Var = CorrespondanceDesVariables->NumeroDeLaVariableViolMaxVolumeMin; + int Var = CorrespondanceDesVariables.NumeroDeLaVariableViolMaxVolumeMin; CoutLineaireBruite[Var] = CoutLineaire[Var] + noiseGenerator() * Constants::noiseAmplitude; - Var = CorrespondanceDesVariables->NumeroDeLaVariableXi; + Var = CorrespondanceDesVariables.NumeroDeLaVariableXi; CoutLineaireBruite[Var] = CoutLineaire[Var] + noiseGenerator() * Constants::noiseAmplitude; } diff --git a/src/solver/hydro/monthly/h2o_m_construire_les_contraintes.cpp b/src/solver/hydro/monthly/h2o_m_construire_les_contraintes.cpp index 6fe0f7ed25..5d5b431d9c 100644 --- a/src/solver/hydro/monthly/h2o_m_construire_les_contraintes.cpp +++ b/src/solver/hydro/monthly/h2o_m_construire_les_contraintes.cpp @@ -35,16 +35,9 @@ void H2O_M_ConstruireLesContraintes(DONNEES_ANNUELLES* DonneesAnnuelles) int Pdt; int NbPdt; double ChgmtSens; - int* NumeroDeVariableVolume; - int* NumeroDeVariableTurbine; - int* NumeroDeVariableDepassementVolumeMax; - int* NumeroDeVariableDepassementVolumeMin; - int* NumeroDeVariableDEcartPositifAuTurbineCible; - int* NumeroDeVariableDEcartNegatifAuTurbineCible; int NumeroDeLaVariableXi; PROBLEME_HYDRAULIQUE* ProblemeHydraulique; - CORRESPONDANCE_DES_VARIABLES* CorrespondanceDesVariables; PROBLEME_LINEAIRE_PARTIE_FIXE* ProblemeLineairePartieFixe; ChgmtSens = -1.0; @@ -52,7 +45,8 @@ void H2O_M_ConstruireLesContraintes(DONNEES_ANNUELLES* DonneesAnnuelles) NbPdt = DonneesAnnuelles->NombreDePasDeTemps; ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; - CorrespondanceDesVariables = ProblemeHydraulique->CorrespondanceDesVariables; + CORRESPONDANCE_DES_VARIABLES& CorrespondanceDesVariables + = ProblemeHydraulique->CorrespondanceDesVariables; ProblemeLineairePartieFixe = ProblemeHydraulique->ProblemeLineairePartieFixe; auto& CoefficientsDeLaMatriceDesContraintes @@ -62,17 +56,17 @@ void H2O_M_ConstruireLesContraintes(DONNEES_ANNUELLES* DonneesAnnuelles) auto& Sens = ProblemeLineairePartieFixe->Sens; auto& NombreDeTermesDesLignes = ProblemeLineairePartieFixe->NombreDeTermesDesLignes; - NumeroDeVariableVolume = CorrespondanceDesVariables->NumeroDeVariableVolume; - NumeroDeVariableTurbine = CorrespondanceDesVariables->NumeroDeVariableTurbine; - NumeroDeVariableDepassementVolumeMax - = CorrespondanceDesVariables->NumeroDeVariableDepassementVolumeMax; - NumeroDeVariableDepassementVolumeMin - = CorrespondanceDesVariables->NumeroDeVariableDepassementVolumeMin; - NumeroDeVariableDEcartPositifAuTurbineCible - = CorrespondanceDesVariables->NumeroDeVariableDEcartPositifAuTurbineCible; - NumeroDeVariableDEcartNegatifAuTurbineCible - = CorrespondanceDesVariables->NumeroDeVariableDEcartNegatifAuTurbineCible; - NumeroDeLaVariableXi = CorrespondanceDesVariables->NumeroDeLaVariableXi; + auto& NumeroDeVariableVolume = CorrespondanceDesVariables.NumeroDeVariableVolume; + auto& NumeroDeVariableTurbine = CorrespondanceDesVariables.NumeroDeVariableTurbine; + auto& NumeroDeVariableDepassementVolumeMax + = CorrespondanceDesVariables.NumeroDeVariableDepassementVolumeMax; + auto& NumeroDeVariableDepassementVolumeMin + = CorrespondanceDesVariables.NumeroDeVariableDepassementVolumeMin; + auto& NumeroDeVariableDEcartPositifAuTurbineCible + = CorrespondanceDesVariables.NumeroDeVariableDEcartPositifAuTurbineCible; + auto& NumeroDeVariableDEcartNegatifAuTurbineCible + = CorrespondanceDesVariables.NumeroDeVariableDEcartNegatifAuTurbineCible; + NumeroDeLaVariableXi = CorrespondanceDesVariables.NumeroDeLaVariableXi; NombreDeContraintes = 0; il = 0; @@ -152,7 +146,7 @@ void H2O_M_ConstruireLesContraintes(DONNEES_ANNUELLES* DonneesAnnuelles) il++; CoefficientsDeLaMatriceDesContraintes[il] = -1.0; - IndicesColonnes[il] = CorrespondanceDesVariables->NumeroDeLaVariableViolMaxVolumeMin; + IndicesColonnes[il] = CorrespondanceDesVariables.NumeroDeLaVariableViolMaxVolumeMin; il++; Sens[NombreDeContraintes] = '<'; diff --git a/src/solver/hydro/monthly/h2o_m_construire_les_variables.cpp b/src/solver/hydro/monthly/h2o_m_construire_les_variables.cpp index d4adcbf5bb..28fae89837 100644 --- a/src/solver/hydro/monthly/h2o_m_construire_les_variables.cpp +++ b/src/solver/hydro/monthly/h2o_m_construire_les_variables.cpp @@ -45,21 +45,21 @@ void H2O_M_ConstruireLesVariables(DONNEES_ANNUELLES* DonneesAnnuelles) int Pdt; int NbPdt; PROBLEME_HYDRAULIQUE* ProblemeHydraulique; - CORRESPONDANCE_DES_VARIABLES* CorrespondanceDesVariables; PROBLEME_LINEAIRE_PARTIE_FIXE* ProblemeLineairePartieFixe; PROBLEME_LINEAIRE_PARTIE_VARIABLE* ProblemeLineairePartieVariable; NbPdt = DonneesAnnuelles->NombreDePasDeTemps; ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; - CorrespondanceDesVariables = ProblemeHydraulique->CorrespondanceDesVariables; + CORRESPONDANCE_DES_VARIABLES& CorrespondanceDesVariables + = ProblemeHydraulique->CorrespondanceDesVariables; ProblemeLineairePartieFixe = ProblemeHydraulique->ProblemeLineairePartieFixe; ProblemeLineairePartieVariable = ProblemeHydraulique->ProblemeLineairePartieVariable; Var = 0; Pdt = 0; - CorrespondanceDesVariables->NumeroDeVariableVolume[Pdt] = Var; + CorrespondanceDesVariables.NumeroDeVariableVolume[Pdt] = Var; ProblemeLineairePartieVariable->Xmin[Var] = 0.0; ProblemeLineairePartieVariable->Xmax[Var] = 1.0; ProblemeLineairePartieFixe->TypeDeVariable[Var] = VARIABLE_BORNEE_DES_DEUX_COTES; @@ -69,7 +69,7 @@ void H2O_M_ConstruireLesVariables(DONNEES_ANNUELLES* DonneesAnnuelles) for (Pdt = 1; Pdt < NbPdt; Pdt++) { - CorrespondanceDesVariables->NumeroDeVariableVolume[Pdt] = Var; + CorrespondanceDesVariables.NumeroDeVariableVolume[Pdt] = Var; ProblemeLineairePartieVariable->Xmin[Var] = 0.0; ProblemeLineairePartieVariable->Xmax[Var] = 1.0; ProblemeLineairePartieFixe->TypeDeVariable[Var] = VARIABLE_BORNEE_DES_DEUX_COTES; @@ -80,7 +80,7 @@ void H2O_M_ConstruireLesVariables(DONNEES_ANNUELLES* DonneesAnnuelles) for (Pdt = 0; Pdt < NbPdt; Pdt++) { - CorrespondanceDesVariables->NumeroDeVariableTurbine[Pdt] = Var; + CorrespondanceDesVariables.NumeroDeVariableTurbine[Pdt] = Var; ProblemeLineairePartieVariable->Xmin[Var] = 0.0; ProblemeLineairePartieVariable->Xmax[Var] = 0.0; ProblemeLineairePartieFixe->TypeDeVariable[Var] = VARIABLE_BORNEE_DES_DEUX_COTES; @@ -91,7 +91,7 @@ void H2O_M_ConstruireLesVariables(DONNEES_ANNUELLES* DonneesAnnuelles) for (Pdt = 0; Pdt < NbPdt; Pdt++) { - CorrespondanceDesVariables->NumeroDeVariableDepassementVolumeMax[Pdt] = Var; + CorrespondanceDesVariables.NumeroDeVariableDepassementVolumeMax[Pdt] = Var; ProblemeLineairePartieVariable->Xmin[Var] = 0.0; ProblemeLineairePartieVariable->Xmax[Var] = LINFINI; ProblemeLineairePartieFixe->TypeDeVariable[Var] = VARIABLE_BORNEE_INFERIEUREMENT; @@ -100,14 +100,14 @@ void H2O_M_ConstruireLesVariables(DONNEES_ANNUELLES* DonneesAnnuelles) for (Pdt = 0; Pdt < NbPdt; Pdt++) { - CorrespondanceDesVariables->NumeroDeVariableDepassementVolumeMin[Pdt] = Var; + CorrespondanceDesVariables.NumeroDeVariableDepassementVolumeMin[Pdt] = Var; ProblemeLineairePartieVariable->Xmin[Var] = 0.0; ProblemeLineairePartieVariable->Xmax[Var] = LINFINI; ProblemeLineairePartieFixe->TypeDeVariable[Var] = VARIABLE_BORNEE_INFERIEUREMENT; Var++; } - CorrespondanceDesVariables->NumeroDeLaVariableViolMaxVolumeMin = Var; + CorrespondanceDesVariables.NumeroDeLaVariableViolMaxVolumeMin = Var; ProblemeLineairePartieVariable->Xmin[Var] = 0.0; ProblemeLineairePartieVariable->Xmax[Var] = LINFINI; ProblemeLineairePartieFixe->TypeDeVariable[Var] = VARIABLE_BORNEE_INFERIEUREMENT; @@ -115,7 +115,7 @@ void H2O_M_ConstruireLesVariables(DONNEES_ANNUELLES* DonneesAnnuelles) for (Pdt = 0; Pdt < NbPdt; Pdt++) { - CorrespondanceDesVariables->NumeroDeVariableDEcartPositifAuTurbineCible[Pdt] = Var; + CorrespondanceDesVariables.NumeroDeVariableDEcartPositifAuTurbineCible[Pdt] = Var; ProblemeLineairePartieVariable->Xmin[Var] = 0.0; ProblemeLineairePartieVariable->Xmax[Var] = LINFINI; ProblemeLineairePartieFixe->TypeDeVariable[Var] = VARIABLE_BORNEE_INFERIEUREMENT; @@ -124,14 +124,14 @@ void H2O_M_ConstruireLesVariables(DONNEES_ANNUELLES* DonneesAnnuelles) for (Pdt = 0; Pdt < NbPdt; Pdt++) { - CorrespondanceDesVariables->NumeroDeVariableDEcartNegatifAuTurbineCible[Pdt] = Var; + CorrespondanceDesVariables.NumeroDeVariableDEcartNegatifAuTurbineCible[Pdt] = Var; ProblemeLineairePartieVariable->Xmin[Var] = 0.0; ProblemeLineairePartieVariable->Xmax[Var] = LINFINI; ProblemeLineairePartieFixe->TypeDeVariable[Var] = VARIABLE_BORNEE_INFERIEUREMENT; Var++; } - CorrespondanceDesVariables->NumeroDeLaVariableXi = Var; + CorrespondanceDesVariables.NumeroDeLaVariableXi = Var; ProblemeLineairePartieVariable->Xmin[Var] = -LINFINI; ProblemeLineairePartieVariable->Xmax[Var] = LINFINI; ProblemeLineairePartieFixe->TypeDeVariable[Var] = VARIABLE_NON_BORNEE; diff --git a/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h b/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h index 7c295b12d2..998edf4f13 100644 --- a/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h +++ b/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h @@ -94,13 +94,13 @@ typedef struct /* Les correspondances des variables */ typedef struct { - int* NumeroDeVariableVolume; /* Volumes */ - int* NumeroDeVariableTurbine; /* Turbines */ - int* NumeroDeVariableDepassementVolumeMax; /* Depassement du volume max */ - int* NumeroDeVariableDepassementVolumeMin; /* Depassement du volume min */ + std::vector NumeroDeVariableVolume; /* Volumes */ + std::vector NumeroDeVariableTurbine; /* Turbines */ + std::vector NumeroDeVariableDepassementVolumeMax; /* Depassement du volume max */ + std::vector NumeroDeVariableDepassementVolumeMin; /* Depassement du volume min */ int NumeroDeLaVariableViolMaxVolumeMin; // Depassement max du volume min - int* NumeroDeVariableDEcartPositifAuTurbineCible; /* Ecart positif au volume cible */ - int* NumeroDeVariableDEcartNegatifAuTurbineCible; /* Ecart negatif au volume cible */ + std::vector NumeroDeVariableDEcartPositifAuTurbineCible; /* Ecart positif au volume cible */ + std::vector NumeroDeVariableDEcartNegatifAuTurbineCible; /* Ecart negatif au volume cible */ int NumeroDeLaVariableXi; /* Variable decrivant l'ecart max au turbine cible */ } CORRESPONDANCE_DES_VARIABLES; @@ -110,7 +110,7 @@ typedef struct int NombreDeReservoirs; char LesCoutsOntEteInitialises; /* Vaut OUI ou NON */ - CORRESPONDANCE_DES_VARIABLES* CorrespondanceDesVariables; + CORRESPONDANCE_DES_VARIABLES CorrespondanceDesVariables; PROBLEME_LINEAIRE_PARTIE_FIXE* ProblemeLineairePartieFixe; PROBLEME_LINEAIRE_PARTIE_VARIABLE* ProblemeLineairePartieVariable; diff --git a/src/solver/hydro/monthly/h2o_m_free.cpp b/src/solver/hydro/monthly/h2o_m_free.cpp index ac63ec76af..80c49ff768 100644 --- a/src/solver/hydro/monthly/h2o_m_free.cpp +++ b/src/solver/hydro/monthly/h2o_m_free.cpp @@ -49,16 +49,6 @@ void H2O_M_Free(DONNEES_ANNUELLES* DonneesAnnuelles) ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; - free(ProblemeHydraulique->CorrespondanceDesVariables->NumeroDeVariableVolume); - free(ProblemeHydraulique->CorrespondanceDesVariables->NumeroDeVariableTurbine); - free(ProblemeHydraulique->CorrespondanceDesVariables->NumeroDeVariableDepassementVolumeMax); - free(ProblemeHydraulique->CorrespondanceDesVariables->NumeroDeVariableDepassementVolumeMin); - free((ProblemeHydraulique->CorrespondanceDesVariables) - ->NumeroDeVariableDEcartPositifAuTurbineCible); - free((ProblemeHydraulique->CorrespondanceDesVariables) - ->NumeroDeVariableDEcartNegatifAuTurbineCible); - free(ProblemeHydraulique->CorrespondanceDesVariables); - free(ProblemeHydraulique->ProblemeLineairePartieFixe); free(ProblemeHydraulique->ProblemeLineairePartieVariable); diff --git a/src/solver/hydro/monthly/h2o_m_initialiser_les_bornes_des_variables.cpp b/src/solver/hydro/monthly/h2o_m_initialiser_les_bornes_des_variables.cpp index 76c04e9edc..82b1a88792 100644 --- a/src/solver/hydro/monthly/h2o_m_initialiser_les_bornes_des_variables.cpp +++ b/src/solver/hydro/monthly/h2o_m_initialiser_les_bornes_des_variables.cpp @@ -35,7 +35,7 @@ void H2O_M_InitialiserBornesEtCoutsDesVariables(DONNEES_ANNUELLES* DonneesAnnuel const PROBLEME_HYDRAULIQUE* ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; PROBLEME_LINEAIRE_PARTIE_VARIABLE* ProblemeLineairePartieVariable = ProblemeHydraulique->ProblemeLineairePartieVariable; - const CORRESPONDANCE_DES_VARIABLES* CorrespondanceDesVariables + const CORRESPONDANCE_DES_VARIABLES& CorrespondanceDesVariables = ProblemeHydraulique->CorrespondanceDesVariables; PROBLEME_LINEAIRE_PARTIE_FIXE* ProblemeLineairePartieFixe = ProblemeHydraulique->ProblemeLineairePartieFixe; @@ -53,20 +53,20 @@ void H2O_M_InitialiserBornesEtCoutsDesVariables(DONNEES_ANNUELLES* DonneesAnnuel auto& X = ProblemeLineairePartieVariable->X; auto& CoutLineaire = ProblemeLineairePartieFixe->CoutLineaire; - Var = CorrespondanceDesVariables->NumeroDeVariableVolume[0]; + Var = CorrespondanceDesVariables.NumeroDeVariableVolume[0]; X[Var] = DonneesAnnuelles->Volume[0]; Xmin[Var] = DonneesAnnuelles->Volume[0]; Xmax[Var] = DonneesAnnuelles->Volume[0]; for (int Pdt = 0; Pdt < NbPdt; Pdt++) { - Var = CorrespondanceDesVariables->NumeroDeVariableVolume[Pdt]; + Var = CorrespondanceDesVariables.NumeroDeVariableVolume[Pdt]; CoutLineaire[Var] = 0.0; } for (int Pdt = 0; Pdt < NbPdt; Pdt++) { - Var = CorrespondanceDesVariables->NumeroDeVariableTurbine[Pdt]; + Var = CorrespondanceDesVariables.NumeroDeVariableTurbine[Pdt]; Xmax[Var] = TurbineMax[Pdt]; Xmin[Var] = TurbineMin[Pdt]; CoutLineaire[Var] = 0.0; @@ -74,31 +74,31 @@ void H2O_M_InitialiserBornesEtCoutsDesVariables(DONNEES_ANNUELLES* DonneesAnnuel for (int Pdt = 0; Pdt < NbPdt; Pdt++) { - Var = CorrespondanceDesVariables->NumeroDeVariableDepassementVolumeMax[Pdt]; + Var = CorrespondanceDesVariables.NumeroDeVariableDepassementVolumeMax[Pdt]; CoutLineaire[Var] = CoutDepassementVolume; } for (int Pdt = 0; Pdt < NbPdt; Pdt++) { - Var = CorrespondanceDesVariables->NumeroDeVariableDepassementVolumeMin[Pdt]; + Var = CorrespondanceDesVariables.NumeroDeVariableDepassementVolumeMin[Pdt]; CoutLineaire[Var] = CoutDepassementVolume; } - Var = CorrespondanceDesVariables->NumeroDeLaVariableViolMaxVolumeMin; + Var = CorrespondanceDesVariables.NumeroDeLaVariableViolMaxVolumeMin; CoutLineaire[Var] = DonneesAnnuelles->CoutViolMaxDuVolumeMin; for (int Pdt = 0; Pdt < NbPdt; Pdt++) { - Var = CorrespondanceDesVariables->NumeroDeVariableDEcartPositifAuTurbineCible[Pdt]; + Var = CorrespondanceDesVariables.NumeroDeVariableDEcartPositifAuTurbineCible[Pdt]; CoutLineaire[Var] = 1.0; } for (int Pdt = 0; Pdt < NbPdt; Pdt++) { - Var = CorrespondanceDesVariables->NumeroDeVariableDEcartNegatifAuTurbineCible[Pdt]; + Var = CorrespondanceDesVariables.NumeroDeVariableDEcartNegatifAuTurbineCible[Pdt]; CoutLineaire[Var] = 1.0; } - Var = CorrespondanceDesVariables->NumeroDeLaVariableXi; + Var = CorrespondanceDesVariables.NumeroDeLaVariableXi; CoutLineaire[Var] = 1.0; } diff --git a/src/solver/hydro/monthly/h2o_m_instanciation.cpp b/src/solver/hydro/monthly/h2o_m_instanciation.cpp index af3208afec..f84ddd8663 100644 --- a/src/solver/hydro/monthly/h2o_m_instanciation.cpp +++ b/src/solver/hydro/monthly/h2o_m_instanciation.cpp @@ -39,7 +39,6 @@ DONNEES_ANNUELLES* H2O_M_Instanciation(int NombreDeReservoirs) DONNEES_ANNUELLES* DonneesAnnuelles; PROBLEME_HYDRAULIQUE* ProblemeHydraulique; - CORRESPONDANCE_DES_VARIABLES* CorrespondanceDesVariables; PROBLEME_LINEAIRE_PARTIE_FIXE* ProblemeLineairePartieFixe; PROBLEME_LINEAIRE_PARTIE_VARIABLE* ProblemeLineairePartieVariable; @@ -74,13 +73,6 @@ DONNEES_ANNUELLES* H2O_M_Instanciation(int NombreDeReservoirs) ProblemeHydraulique->NombreDeReservoirs = NombreDeReservoirs; - ProblemeHydraulique->CorrespondanceDesVariables - = (CORRESPONDANCE_DES_VARIABLES*)malloc(sizeof(CORRESPONDANCE_DES_VARIABLES)); - if (ProblemeHydraulique->CorrespondanceDesVariables == NULL) - { - return (0); - } - ProblemeHydraulique->ProblemeLineairePartieFixe = (PROBLEME_LINEAIRE_PARTIE_FIXE*)malloc(sizeof(PROBLEME_LINEAIRE_PARTIE_FIXE)); if (ProblemeHydraulique->ProblemeLineairePartieFixe == NULL) @@ -108,51 +100,16 @@ DONNEES_ANNUELLES* H2O_M_Instanciation(int NombreDeReservoirs) ProblemeHydraulique->Probleme = NULL; - CorrespondanceDesVariables = ProblemeHydraulique->CorrespondanceDesVariables; + CORRESPONDANCE_DES_VARIABLES CorrespondanceDesVariables = ProblemeHydraulique->CorrespondanceDesVariables; ProblemeLineairePartieFixe = ProblemeHydraulique->ProblemeLineairePartieFixe; ProblemeLineairePartieVariable = ProblemeHydraulique->ProblemeLineairePartieVariable; - CorrespondanceDesVariables->NumeroDeVariableVolume - = (int*)malloc((unsigned int)NbPdt * sizeof(int)); - if (CorrespondanceDesVariables->NumeroDeVariableVolume == NULL) - { - return (0); - } - - CorrespondanceDesVariables->NumeroDeVariableTurbine - = (int*)malloc((unsigned int)NbPdt * sizeof(int)); - if (CorrespondanceDesVariables->NumeroDeVariableTurbine == NULL) - { - return (0); - } - - CorrespondanceDesVariables->NumeroDeVariableDepassementVolumeMin - = (int*)malloc((unsigned int)NbPdt * sizeof(int)); - if (CorrespondanceDesVariables->NumeroDeVariableDepassementVolumeMin == NULL) - { - return (0); - } - - CorrespondanceDesVariables->NumeroDeVariableDepassementVolumeMax - = (int*)malloc((unsigned int)NbPdt * sizeof(int)); - if (CorrespondanceDesVariables->NumeroDeVariableDepassementVolumeMax == NULL) - { - return (0); - } - - CorrespondanceDesVariables->NumeroDeVariableDEcartPositifAuTurbineCible - = (int*)malloc((unsigned int)NbPdt * sizeof(int)); - if (CorrespondanceDesVariables->NumeroDeVariableDEcartPositifAuTurbineCible == NULL) - { - return (0); - } - - CorrespondanceDesVariables->NumeroDeVariableDEcartNegatifAuTurbineCible - = (int*)malloc((unsigned int)NbPdt * sizeof(int)); - if (CorrespondanceDesVariables->NumeroDeVariableDEcartNegatifAuTurbineCible == NULL) - { - return (0); - } + CorrespondanceDesVariables.NumeroDeVariableVolume.assign(NbPdt, 0); + CorrespondanceDesVariables.NumeroDeVariableTurbine.assign(NbPdt, 0); + CorrespondanceDesVariables.NumeroDeVariableDepassementVolumeMin.assign(NbPdt, 0); + CorrespondanceDesVariables.NumeroDeVariableDepassementVolumeMax.assign(NbPdt, 0); + CorrespondanceDesVariables.NumeroDeVariableDEcartPositifAuTurbineCible.assign(NbPdt, 0); + CorrespondanceDesVariables.NumeroDeVariableDEcartNegatifAuTurbineCible.assign(NbPdt, 0); NombreDeVariables = 0; NombreDeVariables += NbPdt; From 3bb0888140e8b1dcb309c9a9f5bc37d7ba4a8a11 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Tue, 12 Sep 2023 16:54:32 +0200 Subject: [PATCH 12/42] [DEV] ProblemeLineairePartieFixe --- .../hydro/monthly/h2o_m_ajouter_bruit.cpp | 6 ++-- .../h2o_m_construire_les_contraintes.cpp | 20 +++++------ .../h2o_m_construire_les_variables.cpp | 24 ++++++------- .../monthly/h2o_m_donnees_optimisation.h | 2 +- src/solver/hydro/monthly/h2o_m_free.cpp | 2 -- ...m_initialiser_les_bornes_des_variables.cpp | 6 ++-- .../hydro/monthly/h2o_m_instanciation.cpp | 34 +++++++----------- .../h2o_m_resoudre_le_probleme_lineaire.cpp | 35 +++++++++---------- 8 files changed, 59 insertions(+), 70 deletions(-) diff --git a/src/solver/hydro/monthly/h2o_m_ajouter_bruit.cpp b/src/solver/hydro/monthly/h2o_m_ajouter_bruit.cpp index 394a0e8205..547d822c63 100644 --- a/src/solver/hydro/monthly/h2o_m_ajouter_bruit.cpp +++ b/src/solver/hydro/monthly/h2o_m_ajouter_bruit.cpp @@ -12,12 +12,12 @@ constexpr unsigned int seed = 0x79686d64; // "hydm" in hexa void H2O_M_AjouterBruitAuCout(DONNEES_ANNUELLES* DonneesAnnuelles) { PROBLEME_HYDRAULIQUE* ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; - PROBLEME_LINEAIRE_PARTIE_FIXE* ProblemeLineairePartieFixe + PROBLEME_LINEAIRE_PARTIE_FIXE& ProblemeLineairePartieFixe = ProblemeHydraulique->ProblemeLineairePartieFixe; CORRESPONDANCE_DES_VARIABLES& CorrespondanceDesVariables = ProblemeHydraulique->CorrespondanceDesVariables; - auto& CoutLineaireBruite = ProblemeLineairePartieFixe->CoutLineaireBruite; - const auto& CoutLineaire = ProblemeLineairePartieFixe->CoutLineaire; + auto& CoutLineaireBruite = ProblemeLineairePartieFixe.CoutLineaireBruite; + const auto& CoutLineaire = ProblemeLineairePartieFixe.CoutLineaire; Antares::MersenneTwister noiseGenerator; noiseGenerator.reset(Constants::seed); // Arbitrary seed, hard-coded since we don't really want diff --git a/src/solver/hydro/monthly/h2o_m_construire_les_contraintes.cpp b/src/solver/hydro/monthly/h2o_m_construire_les_contraintes.cpp index 5d5b431d9c..5a07b7210e 100644 --- a/src/solver/hydro/monthly/h2o_m_construire_les_contraintes.cpp +++ b/src/solver/hydro/monthly/h2o_m_construire_les_contraintes.cpp @@ -38,7 +38,6 @@ void H2O_M_ConstruireLesContraintes(DONNEES_ANNUELLES* DonneesAnnuelles) int NumeroDeLaVariableXi; PROBLEME_HYDRAULIQUE* ProblemeHydraulique; - PROBLEME_LINEAIRE_PARTIE_FIXE* ProblemeLineairePartieFixe; ChgmtSens = -1.0; @@ -47,14 +46,15 @@ void H2O_M_ConstruireLesContraintes(DONNEES_ANNUELLES* DonneesAnnuelles) ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; CORRESPONDANCE_DES_VARIABLES& CorrespondanceDesVariables = ProblemeHydraulique->CorrespondanceDesVariables; - ProblemeLineairePartieFixe = ProblemeHydraulique->ProblemeLineairePartieFixe; + PROBLEME_LINEAIRE_PARTIE_FIXE& ProblemeLineairePartieFixe + = ProblemeHydraulique->ProblemeLineairePartieFixe; auto& CoefficientsDeLaMatriceDesContraintes - = ProblemeLineairePartieFixe->CoefficientsDeLaMatriceDesContraintes; - auto& IndicesColonnes = ProblemeLineairePartieFixe->IndicesColonnes; - auto& IndicesDebutDeLigne = ProblemeLineairePartieFixe->IndicesDebutDeLigne; - auto& Sens = ProblemeLineairePartieFixe->Sens; - auto& NombreDeTermesDesLignes = ProblemeLineairePartieFixe->NombreDeTermesDesLignes; + = ProblemeLineairePartieFixe.CoefficientsDeLaMatriceDesContraintes; + auto& IndicesColonnes = ProblemeLineairePartieFixe.IndicesColonnes; + auto& IndicesDebutDeLigne = ProblemeLineairePartieFixe.IndicesDebutDeLigne; + auto& Sens = ProblemeLineairePartieFixe.Sens; + auto& NombreDeTermesDesLignes = ProblemeLineairePartieFixe.NombreDeTermesDesLignes; auto& NumeroDeVariableVolume = CorrespondanceDesVariables.NumeroDeVariableVolume; auto& NumeroDeVariableTurbine = CorrespondanceDesVariables.NumeroDeVariableTurbine; @@ -114,8 +114,8 @@ void H2O_M_ConstruireLesContraintes(DONNEES_ANNUELLES* DonneesAnnuelles) IndicesColonnes[il] = NumeroDeVariableVolume[Pdt]; il++; - ProblemeLineairePartieFixe->CoefficientsDeLaMatriceDesContraintes[il] = -1.0; - ProblemeLineairePartieFixe->IndicesColonnes[il] = NumeroDeVariableDepassementVolumeMax[Pdt]; + ProblemeLineairePartieFixe.CoefficientsDeLaMatriceDesContraintes[il] = -1.0; + ProblemeLineairePartieFixe.IndicesColonnes[il] = NumeroDeVariableDepassementVolumeMax[Pdt]; il++; Sens[NombreDeContraintes] = '<'; @@ -193,7 +193,7 @@ void H2O_M_ConstruireLesContraintes(DONNEES_ANNUELLES* DonneesAnnuelles) NombreDeContraintes++; } - ProblemeLineairePartieFixe->NombreDeContraintes = NombreDeContraintes; + ProblemeLineairePartieFixe.NombreDeContraintes = NombreDeContraintes; return; } diff --git a/src/solver/hydro/monthly/h2o_m_construire_les_variables.cpp b/src/solver/hydro/monthly/h2o_m_construire_les_variables.cpp index 28fae89837..381dfe468b 100644 --- a/src/solver/hydro/monthly/h2o_m_construire_les_variables.cpp +++ b/src/solver/hydro/monthly/h2o_m_construire_les_variables.cpp @@ -45,7 +45,6 @@ void H2O_M_ConstruireLesVariables(DONNEES_ANNUELLES* DonneesAnnuelles) int Pdt; int NbPdt; PROBLEME_HYDRAULIQUE* ProblemeHydraulique; - PROBLEME_LINEAIRE_PARTIE_FIXE* ProblemeLineairePartieFixe; PROBLEME_LINEAIRE_PARTIE_VARIABLE* ProblemeLineairePartieVariable; NbPdt = DonneesAnnuelles->NombreDePasDeTemps; @@ -53,7 +52,8 @@ void H2O_M_ConstruireLesVariables(DONNEES_ANNUELLES* DonneesAnnuelles) ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; CORRESPONDANCE_DES_VARIABLES& CorrespondanceDesVariables = ProblemeHydraulique->CorrespondanceDesVariables; - ProblemeLineairePartieFixe = ProblemeHydraulique->ProblemeLineairePartieFixe; + PROBLEME_LINEAIRE_PARTIE_FIXE& ProblemeLineairePartieFixe + = ProblemeHydraulique->ProblemeLineairePartieFixe; ProblemeLineairePartieVariable = ProblemeHydraulique->ProblemeLineairePartieVariable; Var = 0; @@ -62,7 +62,7 @@ void H2O_M_ConstruireLesVariables(DONNEES_ANNUELLES* DonneesAnnuelles) CorrespondanceDesVariables.NumeroDeVariableVolume[Pdt] = Var; ProblemeLineairePartieVariable->Xmin[Var] = 0.0; ProblemeLineairePartieVariable->Xmax[Var] = 1.0; - ProblemeLineairePartieFixe->TypeDeVariable[Var] = VARIABLE_BORNEE_DES_DEUX_COTES; + ProblemeLineairePartieFixe.TypeDeVariable[Var] = VARIABLE_BORNEE_DES_DEUX_COTES; ProblemeLineairePartieVariable->AdresseOuPlacerLaValeurDesVariablesOptimisees[Var] = &(DonneesAnnuelles->Volume[Pdt]); Var++; @@ -72,7 +72,7 @@ void H2O_M_ConstruireLesVariables(DONNEES_ANNUELLES* DonneesAnnuelles) CorrespondanceDesVariables.NumeroDeVariableVolume[Pdt] = Var; ProblemeLineairePartieVariable->Xmin[Var] = 0.0; ProblemeLineairePartieVariable->Xmax[Var] = 1.0; - ProblemeLineairePartieFixe->TypeDeVariable[Var] = VARIABLE_BORNEE_DES_DEUX_COTES; + ProblemeLineairePartieFixe.TypeDeVariable[Var] = VARIABLE_BORNEE_DES_DEUX_COTES; ProblemeLineairePartieVariable->AdresseOuPlacerLaValeurDesVariablesOptimisees[Var] = &(DonneesAnnuelles->Volume[Pdt]); Var++; @@ -83,7 +83,7 @@ void H2O_M_ConstruireLesVariables(DONNEES_ANNUELLES* DonneesAnnuelles) CorrespondanceDesVariables.NumeroDeVariableTurbine[Pdt] = Var; ProblemeLineairePartieVariable->Xmin[Var] = 0.0; ProblemeLineairePartieVariable->Xmax[Var] = 0.0; - ProblemeLineairePartieFixe->TypeDeVariable[Var] = VARIABLE_BORNEE_DES_DEUX_COTES; + ProblemeLineairePartieFixe.TypeDeVariable[Var] = VARIABLE_BORNEE_DES_DEUX_COTES; ProblemeLineairePartieVariable->AdresseOuPlacerLaValeurDesVariablesOptimisees[Var] = &(DonneesAnnuelles->Turbine[Pdt]); Var++; @@ -94,7 +94,7 @@ void H2O_M_ConstruireLesVariables(DONNEES_ANNUELLES* DonneesAnnuelles) CorrespondanceDesVariables.NumeroDeVariableDepassementVolumeMax[Pdt] = Var; ProblemeLineairePartieVariable->Xmin[Var] = 0.0; ProblemeLineairePartieVariable->Xmax[Var] = LINFINI; - ProblemeLineairePartieFixe->TypeDeVariable[Var] = VARIABLE_BORNEE_INFERIEUREMENT; + ProblemeLineairePartieFixe.TypeDeVariable[Var] = VARIABLE_BORNEE_INFERIEUREMENT; Var++; } @@ -103,14 +103,14 @@ void H2O_M_ConstruireLesVariables(DONNEES_ANNUELLES* DonneesAnnuelles) CorrespondanceDesVariables.NumeroDeVariableDepassementVolumeMin[Pdt] = Var; ProblemeLineairePartieVariable->Xmin[Var] = 0.0; ProblemeLineairePartieVariable->Xmax[Var] = LINFINI; - ProblemeLineairePartieFixe->TypeDeVariable[Var] = VARIABLE_BORNEE_INFERIEUREMENT; + ProblemeLineairePartieFixe.TypeDeVariable[Var] = VARIABLE_BORNEE_INFERIEUREMENT; Var++; } CorrespondanceDesVariables.NumeroDeLaVariableViolMaxVolumeMin = Var; ProblemeLineairePartieVariable->Xmin[Var] = 0.0; ProblemeLineairePartieVariable->Xmax[Var] = LINFINI; - ProblemeLineairePartieFixe->TypeDeVariable[Var] = VARIABLE_BORNEE_INFERIEUREMENT; + ProblemeLineairePartieFixe.TypeDeVariable[Var] = VARIABLE_BORNEE_INFERIEUREMENT; Var++; for (Pdt = 0; Pdt < NbPdt; Pdt++) @@ -118,7 +118,7 @@ void H2O_M_ConstruireLesVariables(DONNEES_ANNUELLES* DonneesAnnuelles) CorrespondanceDesVariables.NumeroDeVariableDEcartPositifAuTurbineCible[Pdt] = Var; ProblemeLineairePartieVariable->Xmin[Var] = 0.0; ProblemeLineairePartieVariable->Xmax[Var] = LINFINI; - ProblemeLineairePartieFixe->TypeDeVariable[Var] = VARIABLE_BORNEE_INFERIEUREMENT; + ProblemeLineairePartieFixe.TypeDeVariable[Var] = VARIABLE_BORNEE_INFERIEUREMENT; Var++; } @@ -127,17 +127,17 @@ void H2O_M_ConstruireLesVariables(DONNEES_ANNUELLES* DonneesAnnuelles) CorrespondanceDesVariables.NumeroDeVariableDEcartNegatifAuTurbineCible[Pdt] = Var; ProblemeLineairePartieVariable->Xmin[Var] = 0.0; ProblemeLineairePartieVariable->Xmax[Var] = LINFINI; - ProblemeLineairePartieFixe->TypeDeVariable[Var] = VARIABLE_BORNEE_INFERIEUREMENT; + ProblemeLineairePartieFixe.TypeDeVariable[Var] = VARIABLE_BORNEE_INFERIEUREMENT; Var++; } CorrespondanceDesVariables.NumeroDeLaVariableXi = Var; ProblemeLineairePartieVariable->Xmin[Var] = -LINFINI; ProblemeLineairePartieVariable->Xmax[Var] = LINFINI; - ProblemeLineairePartieFixe->TypeDeVariable[Var] = VARIABLE_NON_BORNEE; + ProblemeLineairePartieFixe.TypeDeVariable[Var] = VARIABLE_NON_BORNEE; Var++; - ProblemeLineairePartieFixe->NombreDeVariables = Var; + ProblemeLineairePartieFixe.NombreDeVariables = Var; return; } diff --git a/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h b/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h index 998edf4f13..b2a4bce23a 100644 --- a/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h +++ b/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h @@ -112,7 +112,7 @@ typedef struct CORRESPONDANCE_DES_VARIABLES CorrespondanceDesVariables; - PROBLEME_LINEAIRE_PARTIE_FIXE* ProblemeLineairePartieFixe; + PROBLEME_LINEAIRE_PARTIE_FIXE ProblemeLineairePartieFixe; PROBLEME_LINEAIRE_PARTIE_VARIABLE* ProblemeLineairePartieVariable; void** ProblemeSpx; /* Il y en a 1 par reservoir */ diff --git a/src/solver/hydro/monthly/h2o_m_free.cpp b/src/solver/hydro/monthly/h2o_m_free.cpp index 80c49ff768..59d0f2c967 100644 --- a/src/solver/hydro/monthly/h2o_m_free.cpp +++ b/src/solver/hydro/monthly/h2o_m_free.cpp @@ -49,8 +49,6 @@ void H2O_M_Free(DONNEES_ANNUELLES* DonneesAnnuelles) ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; - free(ProblemeHydraulique->ProblemeLineairePartieFixe); - free(ProblemeHydraulique->ProblemeLineairePartieVariable); for (i = 0; i < ProblemeHydraulique->NombreDeReservoirs; i++) diff --git a/src/solver/hydro/monthly/h2o_m_initialiser_les_bornes_des_variables.cpp b/src/solver/hydro/monthly/h2o_m_initialiser_les_bornes_des_variables.cpp index 82b1a88792..2073a8a4c2 100644 --- a/src/solver/hydro/monthly/h2o_m_initialiser_les_bornes_des_variables.cpp +++ b/src/solver/hydro/monthly/h2o_m_initialiser_les_bornes_des_variables.cpp @@ -32,12 +32,12 @@ void H2O_M_InitialiserBornesEtCoutsDesVariables(DONNEES_ANNUELLES* DonneesAnnuel { int Var; - const PROBLEME_HYDRAULIQUE* ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; + PROBLEME_HYDRAULIQUE* ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; PROBLEME_LINEAIRE_PARTIE_VARIABLE* ProblemeLineairePartieVariable = ProblemeHydraulique->ProblemeLineairePartieVariable; const CORRESPONDANCE_DES_VARIABLES& CorrespondanceDesVariables = ProblemeHydraulique->CorrespondanceDesVariables; - PROBLEME_LINEAIRE_PARTIE_FIXE* ProblemeLineairePartieFixe + PROBLEME_LINEAIRE_PARTIE_FIXE& ProblemeLineairePartieFixe = ProblemeHydraulique->ProblemeLineairePartieFixe; DonneesAnnuelles->Volume[0] = DonneesAnnuelles->VolumeInitial; @@ -51,7 +51,7 @@ void H2O_M_InitialiserBornesEtCoutsDesVariables(DONNEES_ANNUELLES* DonneesAnnuel auto& Xmin = ProblemeLineairePartieVariable->Xmin; auto& Xmax = ProblemeLineairePartieVariable->Xmax; auto& X = ProblemeLineairePartieVariable->X; - auto& CoutLineaire = ProblemeLineairePartieFixe->CoutLineaire; + auto& CoutLineaire = ProblemeLineairePartieFixe.CoutLineaire; Var = CorrespondanceDesVariables.NumeroDeVariableVolume[0]; X[Var] = DonneesAnnuelles->Volume[0]; diff --git a/src/solver/hydro/monthly/h2o_m_instanciation.cpp b/src/solver/hydro/monthly/h2o_m_instanciation.cpp index f84ddd8663..37bc2d3d5a 100644 --- a/src/solver/hydro/monthly/h2o_m_instanciation.cpp +++ b/src/solver/hydro/monthly/h2o_m_instanciation.cpp @@ -39,7 +39,6 @@ DONNEES_ANNUELLES* H2O_M_Instanciation(int NombreDeReservoirs) DONNEES_ANNUELLES* DonneesAnnuelles; PROBLEME_HYDRAULIQUE* ProblemeHydraulique; - PROBLEME_LINEAIRE_PARTIE_FIXE* ProblemeLineairePartieFixe; PROBLEME_LINEAIRE_PARTIE_VARIABLE* ProblemeLineairePartieVariable; DonneesAnnuelles = (DONNEES_ANNUELLES*)malloc(sizeof(DONNEES_ANNUELLES)); @@ -73,13 +72,6 @@ DONNEES_ANNUELLES* H2O_M_Instanciation(int NombreDeReservoirs) ProblemeHydraulique->NombreDeReservoirs = NombreDeReservoirs; - ProblemeHydraulique->ProblemeLineairePartieFixe - = (PROBLEME_LINEAIRE_PARTIE_FIXE*)malloc(sizeof(PROBLEME_LINEAIRE_PARTIE_FIXE)); - if (ProblemeHydraulique->ProblemeLineairePartieFixe == NULL) - { - return (0); - } - ProblemeHydraulique->ProblemeLineairePartieVariable = (PROBLEME_LINEAIRE_PARTIE_VARIABLE*)malloc(sizeof(PROBLEME_LINEAIRE_PARTIE_VARIABLE)); if (ProblemeHydraulique->ProblemeLineairePartieVariable == NULL) @@ -100,8 +92,8 @@ DONNEES_ANNUELLES* H2O_M_Instanciation(int NombreDeReservoirs) ProblemeHydraulique->Probleme = NULL; - CORRESPONDANCE_DES_VARIABLES CorrespondanceDesVariables = ProblemeHydraulique->CorrespondanceDesVariables; - ProblemeLineairePartieFixe = ProblemeHydraulique->ProblemeLineairePartieFixe; + CORRESPONDANCE_DES_VARIABLES& CorrespondanceDesVariables = ProblemeHydraulique->CorrespondanceDesVariables; + PROBLEME_LINEAIRE_PARTIE_FIXE& ProblemeLineairePartieFixe = ProblemeHydraulique->ProblemeLineairePartieFixe; ProblemeLineairePartieVariable = ProblemeHydraulique->ProblemeLineairePartieVariable; CorrespondanceDesVariables.NumeroDeVariableVolume.assign(NbPdt, 0); @@ -121,12 +113,12 @@ DONNEES_ANNUELLES* H2O_M_Instanciation(int NombreDeReservoirs) NombreDeVariables += NbPdt; NombreDeVariables += 1; - ProblemeLineairePartieFixe->NombreDeVariables = NombreDeVariables; + ProblemeLineairePartieFixe.NombreDeVariables = NombreDeVariables; - ProblemeLineairePartieFixe->CoutLineaire.assign(NombreDeVariables, 0.); - ProblemeLineairePartieFixe->CoutLineaireBruite.assign(NombreDeVariables, 0.); + ProblemeLineairePartieFixe.CoutLineaire.assign(NombreDeVariables, 0.); + ProblemeLineairePartieFixe.CoutLineaireBruite.assign(NombreDeVariables, 0.); - ProblemeLineairePartieFixe->TypeDeVariable.assign(NombreDeVariables, 0); + ProblemeLineairePartieFixe.TypeDeVariable.assign(NombreDeVariables, 0); NombreDeContraintes = 0; NombreDeContraintes += NbPdt; @@ -137,11 +129,11 @@ DONNEES_ANNUELLES* H2O_M_Instanciation(int NombreDeReservoirs) NombreDeContraintes += NbPdt; NombreDeContraintes += NbPdt; - ProblemeLineairePartieFixe->NombreDeContraintes = NombreDeContraintes; - ProblemeLineairePartieFixe->Sens.assign(NombreDeContraintes, 0); + ProblemeLineairePartieFixe.NombreDeContraintes = NombreDeContraintes; + ProblemeLineairePartieFixe.Sens.assign(NombreDeContraintes, 0); - ProblemeLineairePartieFixe->IndicesDebutDeLigne.assign(NombreDeContraintes, 0); - ProblemeLineairePartieFixe->NombreDeTermesDesLignes.assign(NombreDeContraintes, 0); + ProblemeLineairePartieFixe.IndicesDebutDeLigne.assign(NombreDeContraintes, 0); + ProblemeLineairePartieFixe.NombreDeTermesDesLignes.assign(NombreDeContraintes, 0); NombreDeTermesAlloues = 0; NombreDeTermesAlloues += 3 * NbPdt; @@ -152,12 +144,12 @@ DONNEES_ANNUELLES* H2O_M_Instanciation(int NombreDeReservoirs) NombreDeTermesAlloues += 3 * NbPdt; NombreDeTermesAlloues += 3 * NbPdt; - ProblemeLineairePartieFixe->NombreDeTermesAlloues = NombreDeTermesAlloues; + ProblemeLineairePartieFixe.NombreDeTermesAlloues = NombreDeTermesAlloues; - ProblemeLineairePartieFixe->CoefficientsDeLaMatriceDesContraintes + ProblemeLineairePartieFixe.CoefficientsDeLaMatriceDesContraintes .assign(NombreDeTermesAlloues, 0.); - ProblemeLineairePartieFixe->IndicesColonnes.assign(NombreDeTermesAlloues, 0); + ProblemeLineairePartieFixe.IndicesColonnes.assign(NombreDeTermesAlloues, 0); ProblemeLineairePartieVariable->Xmin.assign(NombreDeVariables, 0.); ProblemeLineairePartieVariable->Xmax.assign(NombreDeVariables, 0.); diff --git a/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp b/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp index 0c463c0eff..daecb1e466 100644 --- a/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp +++ b/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp @@ -52,19 +52,18 @@ void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES* DonneesAnnuelles, int N double* pt; char PremierPassage; - PROBLEME_HYDRAULIQUE* ProblemeHydraulique; + PROBLEME_HYDRAULIQUE* ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; PROBLEME_LINEAIRE_PARTIE_VARIABLE* ProblemeLineairePartieVariable; - PROBLEME_LINEAIRE_PARTIE_FIXE* ProblemeLineairePartieFixe; + PROBLEME_LINEAIRE_PARTIE_FIXE& ProblemeLineairePartieFixe + = ProblemeHydraulique->ProblemeLineairePartieFixe; PROBLEME_SIMPLEXE* Probleme; PROBLEME_SPX* ProbSpx; PremierPassage = OUI; - ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; ProblemeLineairePartieVariable = ProblemeHydraulique->ProblemeLineairePartieVariable; - ProblemeLineairePartieFixe = ProblemeHydraulique->ProblemeLineairePartieFixe; ProbSpx = (PROBLEME_SPX*)ProblemeHydraulique->ProblemeSpx[NumeroDeReservoir]; @@ -95,27 +94,27 @@ void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES* DonneesAnnuelles, int N SPX_ModifierLeVecteurSecondMembre(ProbSpx, ProblemeLineairePartieVariable->SecondMembre.data(), - ProblemeLineairePartieFixe->Sens.data(), - ProblemeLineairePartieFixe->NombreDeContraintes); + ProblemeLineairePartieFixe.Sens.data(), + ProblemeLineairePartieFixe.NombreDeContraintes); } Probleme->NombreMaxDIterations = -1; Probleme->DureeMaxDuCalcul = -1.; - Probleme->CoutLineaire = ProblemeLineairePartieFixe->CoutLineaireBruite.data(); + Probleme->CoutLineaire = ProblemeLineairePartieFixe.CoutLineaireBruite.data(); Probleme->X = ProblemeLineairePartieVariable->X.data(); Probleme->Xmin = ProblemeLineairePartieVariable->Xmin.data(); Probleme->Xmax = ProblemeLineairePartieVariable->Xmax.data(); - Probleme->NombreDeVariables = ProblemeLineairePartieFixe->NombreDeVariables; - Probleme->TypeDeVariable = ProblemeLineairePartieFixe->TypeDeVariable.data(); + Probleme->NombreDeVariables = ProblemeLineairePartieFixe.NombreDeVariables; + Probleme->TypeDeVariable = ProblemeLineairePartieFixe.TypeDeVariable.data(); - Probleme->NombreDeContraintes = ProblemeLineairePartieFixe->NombreDeContraintes; - Probleme->IndicesDebutDeLigne = ProblemeLineairePartieFixe->IndicesDebutDeLigne.data(); - Probleme->NombreDeTermesDesLignes = ProblemeLineairePartieFixe->NombreDeTermesDesLignes.data(); - Probleme->IndicesColonnes = ProblemeLineairePartieFixe->IndicesColonnes.data(); + Probleme->NombreDeContraintes = ProblemeLineairePartieFixe.NombreDeContraintes; + Probleme->IndicesDebutDeLigne = ProblemeLineairePartieFixe.IndicesDebutDeLigne.data(); + Probleme->NombreDeTermesDesLignes = ProblemeLineairePartieFixe.NombreDeTermesDesLignes.data(); + Probleme->IndicesColonnes = ProblemeLineairePartieFixe.IndicesColonnes.data(); Probleme->CoefficientsDeLaMatriceDesContraintes - = ProblemeLineairePartieFixe->CoefficientsDeLaMatriceDesContraintes.data(); - Probleme->Sens = ProblemeLineairePartieFixe->Sens.data(); + = ProblemeLineairePartieFixe.CoefficientsDeLaMatriceDesContraintes.data(); + Probleme->Sens = ProblemeLineairePartieFixe.Sens.data(); Probleme->SecondMembre = ProblemeLineairePartieVariable->SecondMembre.data(); Probleme->ChoixDeLAlgorithme = SPX_DUAL; @@ -181,19 +180,19 @@ void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES* DonneesAnnuelles, int N for (Var = 0; Var < Probleme->NombreDeVariables; Var++) { ProblemeHydraulique->CoutDeLaSolution - += ProblemeLineairePartieFixe->CoutLineaire[Var] * Probleme->X[Var]; + += ProblemeLineairePartieFixe.CoutLineaire[Var] * Probleme->X[Var]; } ProblemeHydraulique->CoutDeLaSolutionBruite = 0.0; for (Var = 0; Var < Probleme->NombreDeVariables; Var++) { ProblemeHydraulique->CoutDeLaSolutionBruite - += ProblemeLineairePartieFixe->CoutLineaireBruite[Var] * Probleme->X[Var]; + += ProblemeLineairePartieFixe.CoutLineaireBruite[Var] * Probleme->X[Var]; } DonneesAnnuelles->ResultatsValides = OUI; - for (Var = 0; Var < ProblemeLineairePartieFixe->NombreDeVariables; Var++) + for (Var = 0; Var < ProblemeLineairePartieFixe.NombreDeVariables; Var++) { pt = ProblemeLineairePartieVariable->AdresseOuPlacerLaValeurDesVariablesOptimisees[Var]; if (pt != NULL) From 2dc2a670847a3e9919cb1385ac3833277e5ba544 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Tue, 12 Sep 2023 17:04:57 +0200 Subject: [PATCH 13/42] [DEV] ProblemeLineairePartieVariable --- .../h2o_m_construire_les_variables.cpp | 57 +++++++++---------- .../monthly/h2o_m_donnees_optimisation.h | 2 +- src/solver/hydro/monthly/h2o_m_free.cpp | 2 - ...m_initialiser_les_bornes_des_variables.cpp | 8 +-- .../h2o_m_initialiser_les_second_membre.cpp | 4 +- .../hydro/monthly/h2o_m_instanciation.cpp | 36 +++++------- .../h2o_m_resoudre_le_probleme_lineaire.cpp | 34 +++++------ 7 files changed, 67 insertions(+), 76 deletions(-) diff --git a/src/solver/hydro/monthly/h2o_m_construire_les_variables.cpp b/src/solver/hydro/monthly/h2o_m_construire_les_variables.cpp index 381dfe468b..53ec792472 100644 --- a/src/solver/hydro/monthly/h2o_m_construire_les_variables.cpp +++ b/src/solver/hydro/monthly/h2o_m_construire_les_variables.cpp @@ -44,36 +44,35 @@ void H2O_M_ConstruireLesVariables(DONNEES_ANNUELLES* DonneesAnnuelles) int Var; int Pdt; int NbPdt; - PROBLEME_HYDRAULIQUE* ProblemeHydraulique; - PROBLEME_LINEAIRE_PARTIE_VARIABLE* ProblemeLineairePartieVariable; + PROBLEME_HYDRAULIQUE* ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; + PROBLEME_LINEAIRE_PARTIE_VARIABLE& ProblemeLineairePartieVariable + = ProblemeHydraulique->ProblemeLineairePartieVariable; + PROBLEME_LINEAIRE_PARTIE_FIXE& ProblemeLineairePartieFixe + = ProblemeHydraulique->ProblemeLineairePartieFixe; + CORRESPONDANCE_DES_VARIABLES& CorrespondanceDesVariables + = ProblemeHydraulique->CorrespondanceDesVariables; NbPdt = DonneesAnnuelles->NombreDePasDeTemps; - ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; - CORRESPONDANCE_DES_VARIABLES& CorrespondanceDesVariables - = ProblemeHydraulique->CorrespondanceDesVariables; - PROBLEME_LINEAIRE_PARTIE_FIXE& ProblemeLineairePartieFixe - = ProblemeHydraulique->ProblemeLineairePartieFixe; - ProblemeLineairePartieVariable = ProblemeHydraulique->ProblemeLineairePartieVariable; Var = 0; Pdt = 0; CorrespondanceDesVariables.NumeroDeVariableVolume[Pdt] = Var; - ProblemeLineairePartieVariable->Xmin[Var] = 0.0; - ProblemeLineairePartieVariable->Xmax[Var] = 1.0; + ProblemeLineairePartieVariable.Xmin[Var] = 0.0; + ProblemeLineairePartieVariable.Xmax[Var] = 1.0; ProblemeLineairePartieFixe.TypeDeVariable[Var] = VARIABLE_BORNEE_DES_DEUX_COTES; - ProblemeLineairePartieVariable->AdresseOuPlacerLaValeurDesVariablesOptimisees[Var] + ProblemeLineairePartieVariable.AdresseOuPlacerLaValeurDesVariablesOptimisees[Var] = &(DonneesAnnuelles->Volume[Pdt]); Var++; for (Pdt = 1; Pdt < NbPdt; Pdt++) { CorrespondanceDesVariables.NumeroDeVariableVolume[Pdt] = Var; - ProblemeLineairePartieVariable->Xmin[Var] = 0.0; - ProblemeLineairePartieVariable->Xmax[Var] = 1.0; + ProblemeLineairePartieVariable.Xmin[Var] = 0.0; + ProblemeLineairePartieVariable.Xmax[Var] = 1.0; ProblemeLineairePartieFixe.TypeDeVariable[Var] = VARIABLE_BORNEE_DES_DEUX_COTES; - ProblemeLineairePartieVariable->AdresseOuPlacerLaValeurDesVariablesOptimisees[Var] + ProblemeLineairePartieVariable.AdresseOuPlacerLaValeurDesVariablesOptimisees[Var] = &(DonneesAnnuelles->Volume[Pdt]); Var++; } @@ -81,10 +80,10 @@ void H2O_M_ConstruireLesVariables(DONNEES_ANNUELLES* DonneesAnnuelles) for (Pdt = 0; Pdt < NbPdt; Pdt++) { CorrespondanceDesVariables.NumeroDeVariableTurbine[Pdt] = Var; - ProblemeLineairePartieVariable->Xmin[Var] = 0.0; - ProblemeLineairePartieVariable->Xmax[Var] = 0.0; + ProblemeLineairePartieVariable.Xmin[Var] = 0.0; + ProblemeLineairePartieVariable.Xmax[Var] = 0.0; ProblemeLineairePartieFixe.TypeDeVariable[Var] = VARIABLE_BORNEE_DES_DEUX_COTES; - ProblemeLineairePartieVariable->AdresseOuPlacerLaValeurDesVariablesOptimisees[Var] + ProblemeLineairePartieVariable.AdresseOuPlacerLaValeurDesVariablesOptimisees[Var] = &(DonneesAnnuelles->Turbine[Pdt]); Var++; } @@ -92,8 +91,8 @@ void H2O_M_ConstruireLesVariables(DONNEES_ANNUELLES* DonneesAnnuelles) for (Pdt = 0; Pdt < NbPdt; Pdt++) { CorrespondanceDesVariables.NumeroDeVariableDepassementVolumeMax[Pdt] = Var; - ProblemeLineairePartieVariable->Xmin[Var] = 0.0; - ProblemeLineairePartieVariable->Xmax[Var] = LINFINI; + ProblemeLineairePartieVariable.Xmin[Var] = 0.0; + ProblemeLineairePartieVariable.Xmax[Var] = LINFINI; ProblemeLineairePartieFixe.TypeDeVariable[Var] = VARIABLE_BORNEE_INFERIEUREMENT; Var++; } @@ -101,23 +100,23 @@ void H2O_M_ConstruireLesVariables(DONNEES_ANNUELLES* DonneesAnnuelles) for (Pdt = 0; Pdt < NbPdt; Pdt++) { CorrespondanceDesVariables.NumeroDeVariableDepassementVolumeMin[Pdt] = Var; - ProblemeLineairePartieVariable->Xmin[Var] = 0.0; - ProblemeLineairePartieVariable->Xmax[Var] = LINFINI; + ProblemeLineairePartieVariable.Xmin[Var] = 0.0; + ProblemeLineairePartieVariable.Xmax[Var] = LINFINI; ProblemeLineairePartieFixe.TypeDeVariable[Var] = VARIABLE_BORNEE_INFERIEUREMENT; Var++; } CorrespondanceDesVariables.NumeroDeLaVariableViolMaxVolumeMin = Var; - ProblemeLineairePartieVariable->Xmin[Var] = 0.0; - ProblemeLineairePartieVariable->Xmax[Var] = LINFINI; + ProblemeLineairePartieVariable.Xmin[Var] = 0.0; + ProblemeLineairePartieVariable.Xmax[Var] = LINFINI; ProblemeLineairePartieFixe.TypeDeVariable[Var] = VARIABLE_BORNEE_INFERIEUREMENT; Var++; for (Pdt = 0; Pdt < NbPdt; Pdt++) { CorrespondanceDesVariables.NumeroDeVariableDEcartPositifAuTurbineCible[Pdt] = Var; - ProblemeLineairePartieVariable->Xmin[Var] = 0.0; - ProblemeLineairePartieVariable->Xmax[Var] = LINFINI; + ProblemeLineairePartieVariable.Xmin[Var] = 0.0; + ProblemeLineairePartieVariable.Xmax[Var] = LINFINI; ProblemeLineairePartieFixe.TypeDeVariable[Var] = VARIABLE_BORNEE_INFERIEUREMENT; Var++; } @@ -125,15 +124,15 @@ void H2O_M_ConstruireLesVariables(DONNEES_ANNUELLES* DonneesAnnuelles) for (Pdt = 0; Pdt < NbPdt; Pdt++) { CorrespondanceDesVariables.NumeroDeVariableDEcartNegatifAuTurbineCible[Pdt] = Var; - ProblemeLineairePartieVariable->Xmin[Var] = 0.0; - ProblemeLineairePartieVariable->Xmax[Var] = LINFINI; + ProblemeLineairePartieVariable.Xmin[Var] = 0.0; + ProblemeLineairePartieVariable.Xmax[Var] = LINFINI; ProblemeLineairePartieFixe.TypeDeVariable[Var] = VARIABLE_BORNEE_INFERIEUREMENT; Var++; } CorrespondanceDesVariables.NumeroDeLaVariableXi = Var; - ProblemeLineairePartieVariable->Xmin[Var] = -LINFINI; - ProblemeLineairePartieVariable->Xmax[Var] = LINFINI; + ProblemeLineairePartieVariable.Xmin[Var] = -LINFINI; + ProblemeLineairePartieVariable.Xmax[Var] = LINFINI; ProblemeLineairePartieFixe.TypeDeVariable[Var] = VARIABLE_NON_BORNEE; Var++; diff --git a/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h b/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h index b2a4bce23a..6576be3887 100644 --- a/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h +++ b/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h @@ -113,7 +113,7 @@ typedef struct CORRESPONDANCE_DES_VARIABLES CorrespondanceDesVariables; PROBLEME_LINEAIRE_PARTIE_FIXE ProblemeLineairePartieFixe; - PROBLEME_LINEAIRE_PARTIE_VARIABLE* ProblemeLineairePartieVariable; + PROBLEME_LINEAIRE_PARTIE_VARIABLE ProblemeLineairePartieVariable; void** ProblemeSpx; /* Il y en a 1 par reservoir */ void* Probleme; /* Le probleme en cours passe au simplexe */ diff --git a/src/solver/hydro/monthly/h2o_m_free.cpp b/src/solver/hydro/monthly/h2o_m_free.cpp index 59d0f2c967..46c6670064 100644 --- a/src/solver/hydro/monthly/h2o_m_free.cpp +++ b/src/solver/hydro/monthly/h2o_m_free.cpp @@ -49,8 +49,6 @@ void H2O_M_Free(DONNEES_ANNUELLES* DonneesAnnuelles) ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; - free(ProblemeHydraulique->ProblemeLineairePartieVariable); - for (i = 0; i < ProblemeHydraulique->NombreDeReservoirs; i++) { ProbSpx = (PROBLEME_SPX*)ProblemeHydraulique->ProblemeSpx[i]; diff --git a/src/solver/hydro/monthly/h2o_m_initialiser_les_bornes_des_variables.cpp b/src/solver/hydro/monthly/h2o_m_initialiser_les_bornes_des_variables.cpp index 2073a8a4c2..16e1292ef7 100644 --- a/src/solver/hydro/monthly/h2o_m_initialiser_les_bornes_des_variables.cpp +++ b/src/solver/hydro/monthly/h2o_m_initialiser_les_bornes_des_variables.cpp @@ -33,7 +33,7 @@ void H2O_M_InitialiserBornesEtCoutsDesVariables(DONNEES_ANNUELLES* DonneesAnnuel int Var; PROBLEME_HYDRAULIQUE* ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; - PROBLEME_LINEAIRE_PARTIE_VARIABLE* ProblemeLineairePartieVariable + PROBLEME_LINEAIRE_PARTIE_VARIABLE& ProblemeLineairePartieVariable = ProblemeHydraulique->ProblemeLineairePartieVariable; const CORRESPONDANCE_DES_VARIABLES& CorrespondanceDesVariables = ProblemeHydraulique->CorrespondanceDesVariables; @@ -48,9 +48,9 @@ void H2O_M_InitialiserBornesEtCoutsDesVariables(DONNEES_ANNUELLES* DonneesAnnuel const auto& TurbineMin = DonneesAnnuelles->TurbineMin; - auto& Xmin = ProblemeLineairePartieVariable->Xmin; - auto& Xmax = ProblemeLineairePartieVariable->Xmax; - auto& X = ProblemeLineairePartieVariable->X; + auto& Xmin = ProblemeLineairePartieVariable.Xmin; + auto& Xmax = ProblemeLineairePartieVariable.Xmax; + auto& X = ProblemeLineairePartieVariable.X; auto& CoutLineaire = ProblemeLineairePartieFixe.CoutLineaire; Var = CorrespondanceDesVariables.NumeroDeVariableVolume[0]; diff --git a/src/solver/hydro/monthly/h2o_m_initialiser_les_second_membre.cpp b/src/solver/hydro/monthly/h2o_m_initialiser_les_second_membre.cpp index 3cb60f4726..27aac08793 100644 --- a/src/solver/hydro/monthly/h2o_m_initialiser_les_second_membre.cpp +++ b/src/solver/hydro/monthly/h2o_m_initialiser_les_second_membre.cpp @@ -31,7 +31,7 @@ void H2O_M_InitialiserLeSecondMembre(DONNEES_ANNUELLES* DonneesAnnuelles) { PROBLEME_HYDRAULIQUE* ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; - PROBLEME_LINEAIRE_PARTIE_VARIABLE* ProblemeLineairePartieVariable + PROBLEME_LINEAIRE_PARTIE_VARIABLE& ProblemeLineairePartieVariable = ProblemeHydraulique->ProblemeLineairePartieVariable; double ChgmtSens = -1; @@ -39,7 +39,7 @@ void H2O_M_InitialiserLeSecondMembre(DONNEES_ANNUELLES* DonneesAnnuelles) int Cnt = 0; auto& TurbineCible = DonneesAnnuelles->TurbineCible; - auto& SecondMembre = ProblemeLineairePartieVariable->SecondMembre; + auto& SecondMembre = ProblemeLineairePartieVariable.SecondMembre; for (int Pdt = 1; Pdt < NbPdt; Pdt++) { diff --git a/src/solver/hydro/monthly/h2o_m_instanciation.cpp b/src/solver/hydro/monthly/h2o_m_instanciation.cpp index 37bc2d3d5a..25ecd32a68 100644 --- a/src/solver/hydro/monthly/h2o_m_instanciation.cpp +++ b/src/solver/hydro/monthly/h2o_m_instanciation.cpp @@ -39,8 +39,6 @@ DONNEES_ANNUELLES* H2O_M_Instanciation(int NombreDeReservoirs) DONNEES_ANNUELLES* DonneesAnnuelles; PROBLEME_HYDRAULIQUE* ProblemeHydraulique; - PROBLEME_LINEAIRE_PARTIE_VARIABLE* ProblemeLineairePartieVariable; - DonneesAnnuelles = (DONNEES_ANNUELLES*)malloc(sizeof(DONNEES_ANNUELLES)); if (DonneesAnnuelles == NULL) { @@ -72,13 +70,6 @@ DONNEES_ANNUELLES* H2O_M_Instanciation(int NombreDeReservoirs) ProblemeHydraulique->NombreDeReservoirs = NombreDeReservoirs; - ProblemeHydraulique->ProblemeLineairePartieVariable - = (PROBLEME_LINEAIRE_PARTIE_VARIABLE*)malloc(sizeof(PROBLEME_LINEAIRE_PARTIE_VARIABLE)); - if (ProblemeHydraulique->ProblemeLineairePartieVariable == NULL) - { - return (0); - } - ProblemeHydraulique->ProblemeSpx = (void**)malloc((unsigned int)NombreDeReservoirs * sizeof(void*)); if (ProblemeHydraulique->ProblemeSpx == NULL) @@ -92,9 +83,12 @@ DONNEES_ANNUELLES* H2O_M_Instanciation(int NombreDeReservoirs) ProblemeHydraulique->Probleme = NULL; - CORRESPONDANCE_DES_VARIABLES& CorrespondanceDesVariables = ProblemeHydraulique->CorrespondanceDesVariables; - PROBLEME_LINEAIRE_PARTIE_FIXE& ProblemeLineairePartieFixe = ProblemeHydraulique->ProblemeLineairePartieFixe; - ProblemeLineairePartieVariable = ProblemeHydraulique->ProblemeLineairePartieVariable; + CORRESPONDANCE_DES_VARIABLES& CorrespondanceDesVariables + = ProblemeHydraulique->CorrespondanceDesVariables; + PROBLEME_LINEAIRE_PARTIE_FIXE& ProblemeLineairePartieFixe + = ProblemeHydraulique->ProblemeLineairePartieFixe; + PROBLEME_LINEAIRE_PARTIE_VARIABLE& ProblemeLineairePartieVariable + = ProblemeHydraulique->ProblemeLineairePartieVariable; CorrespondanceDesVariables.NumeroDeVariableVolume.assign(NbPdt, 0); CorrespondanceDesVariables.NumeroDeVariableTurbine.assign(NbPdt, 0); @@ -151,21 +145,21 @@ DONNEES_ANNUELLES* H2O_M_Instanciation(int NombreDeReservoirs) ProblemeLineairePartieFixe.IndicesColonnes.assign(NombreDeTermesAlloues, 0); - ProblemeLineairePartieVariable->Xmin.assign(NombreDeVariables, 0.); - ProblemeLineairePartieVariable->Xmax.assign(NombreDeVariables, 0.); - ProblemeLineairePartieVariable->SecondMembre.assign(NombreDeContraintes, 0.); + ProblemeLineairePartieVariable.Xmin.assign(NombreDeVariables, 0.); + ProblemeLineairePartieVariable.Xmax.assign(NombreDeVariables, 0.); + ProblemeLineairePartieVariable.SecondMembre.assign(NombreDeContraintes, 0.); - ProblemeLineairePartieVariable->AdresseOuPlacerLaValeurDesVariablesOptimisees + ProblemeLineairePartieVariable.AdresseOuPlacerLaValeurDesVariablesOptimisees .assign(NombreDeVariables, nullptr); - ProblemeLineairePartieVariable->X.assign(NombreDeVariables, 0.); + ProblemeLineairePartieVariable.X.assign(NombreDeVariables, 0.); - ProblemeLineairePartieVariable->PositionDeLaVariable.assign(NombreDeVariables, 0); - ProblemeLineairePartieVariable->ComplementDeLaBase.assign(NombreDeContraintes, 0); + ProblemeLineairePartieVariable.PositionDeLaVariable.assign(NombreDeVariables, 0); + ProblemeLineairePartieVariable.ComplementDeLaBase.assign(NombreDeContraintes, 0); - ProblemeLineairePartieVariable->CoutsReduits.assign(NombreDeVariables, 0.); - ProblemeLineairePartieVariable->CoutsMarginauxDesContraintes.assign(NombreDeContraintes, 0.); + ProblemeLineairePartieVariable.CoutsReduits.assign(NombreDeVariables, 0.); + ProblemeLineairePartieVariable.CoutsMarginauxDesContraintes.assign(NombreDeContraintes, 0.); H2O_M_ConstruireLesVariables(DonneesAnnuelles); diff --git a/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp b/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp index daecb1e466..d640c7c77d 100644 --- a/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp +++ b/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp @@ -53,7 +53,8 @@ void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES* DonneesAnnuelles, int N char PremierPassage; PROBLEME_HYDRAULIQUE* ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; - PROBLEME_LINEAIRE_PARTIE_VARIABLE* ProblemeLineairePartieVariable; + PROBLEME_LINEAIRE_PARTIE_VARIABLE& ProblemeLineairePartieVariable + = ProblemeHydraulique->ProblemeLineairePartieVariable; PROBLEME_LINEAIRE_PARTIE_FIXE& ProblemeLineairePartieFixe = ProblemeHydraulique->ProblemeLineairePartieFixe; @@ -63,7 +64,6 @@ void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES* DonneesAnnuelles, int N PremierPassage = OUI; - ProblemeLineairePartieVariable = ProblemeHydraulique->ProblemeLineairePartieVariable; ProbSpx = (PROBLEME_SPX*)ProblemeHydraulique->ProblemeSpx[NumeroDeReservoir]; @@ -93,7 +93,7 @@ void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES* DonneesAnnuelles, int N Probleme->BaseDeDepartFournie = UTILISER_LA_BASE_DU_PROBLEME_SPX; SPX_ModifierLeVecteurSecondMembre(ProbSpx, - ProblemeLineairePartieVariable->SecondMembre.data(), + ProblemeLineairePartieVariable.SecondMembre.data(), ProblemeLineairePartieFixe.Sens.data(), ProblemeLineairePartieFixe.NombreDeContraintes); } @@ -102,9 +102,9 @@ void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES* DonneesAnnuelles, int N Probleme->DureeMaxDuCalcul = -1.; Probleme->CoutLineaire = ProblemeLineairePartieFixe.CoutLineaireBruite.data(); - Probleme->X = ProblemeLineairePartieVariable->X.data(); - Probleme->Xmin = ProblemeLineairePartieVariable->Xmin.data(); - Probleme->Xmax = ProblemeLineairePartieVariable->Xmax.data(); + Probleme->X = ProblemeLineairePartieVariable.X.data(); + Probleme->Xmin = ProblemeLineairePartieVariable.Xmin.data(); + Probleme->Xmax = ProblemeLineairePartieVariable.Xmax.data(); Probleme->NombreDeVariables = ProblemeLineairePartieFixe.NombreDeVariables; Probleme->TypeDeVariable = ProblemeLineairePartieFixe.TypeDeVariable.data(); @@ -115,7 +115,7 @@ void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES* DonneesAnnuelles, int N Probleme->CoefficientsDeLaMatriceDesContraintes = ProblemeLineairePartieFixe.CoefficientsDeLaMatriceDesContraintes.data(); Probleme->Sens = ProblemeLineairePartieFixe.Sens.data(); - Probleme->SecondMembre = ProblemeLineairePartieVariable->SecondMembre.data(); + Probleme->SecondMembre = ProblemeLineairePartieVariable.SecondMembre.data(); Probleme->ChoixDeLAlgorithme = SPX_DUAL; @@ -123,9 +123,9 @@ void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES* DonneesAnnuelles, int N Probleme->FaireDuScaling = OUI_SPX; Probleme->StrategieAntiDegenerescence = AGRESSIF; - Probleme->PositionDeLaVariable = ProblemeLineairePartieVariable->PositionDeLaVariable.data(); + Probleme->PositionDeLaVariable = ProblemeLineairePartieVariable.PositionDeLaVariable.data(); Probleme->NbVarDeBaseComplementaires = 0; - Probleme->ComplementDeLaBase = ProblemeLineairePartieVariable->ComplementDeLaBase.data(); + Probleme->ComplementDeLaBase = ProblemeLineairePartieVariable.ComplementDeLaBase.data(); Probleme->LibererMemoireALaFin = NON_SPX; @@ -133,8 +133,8 @@ void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES* DonneesAnnuelles, int N Probleme->CoutMax = 0.0; Probleme->CoutsMarginauxDesContraintes - = ProblemeLineairePartieVariable->CoutsMarginauxDesContraintes.data(); - Probleme->CoutsReduits = ProblemeLineairePartieVariable->CoutsReduits.data(); + = ProblemeLineairePartieVariable.CoutsMarginauxDesContraintes.data(); + Probleme->CoutsReduits = ProblemeLineairePartieVariable.CoutsReduits.data(); #ifndef NDEBUG if (PremierPassage == OUI) @@ -154,12 +154,12 @@ void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES* DonneesAnnuelles, int N ProblemeHydraulique->ProblemeSpx[NumeroDeReservoir] = (void*)ProbSpx; } - ProblemeLineairePartieVariable->ExistenceDUneSolution = Probleme->ExistenceDUneSolution; + ProblemeLineairePartieVariable.ExistenceDUneSolution = Probleme->ExistenceDUneSolution; - if (ProblemeLineairePartieVariable->ExistenceDUneSolution != OUI_SPX && PremierPassage == OUI + if (ProblemeLineairePartieVariable.ExistenceDUneSolution != OUI_SPX && PremierPassage == OUI && ProbSpx != NULL) { - if (ProblemeLineairePartieVariable->ExistenceDUneSolution != SPX_ERREUR_INTERNE) + if (ProblemeLineairePartieVariable.ExistenceDUneSolution != SPX_ERREUR_INTERNE) { SPX_LibererProbleme(ProbSpx); @@ -174,7 +174,7 @@ void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES* DonneesAnnuelles, int N } } - if (ProblemeLineairePartieVariable->ExistenceDUneSolution == OUI_SPX) + if (ProblemeLineairePartieVariable.ExistenceDUneSolution == OUI_SPX) { ProblemeHydraulique->CoutDeLaSolution = 0.0; for (Var = 0; Var < Probleme->NombreDeVariables; Var++) @@ -194,9 +194,9 @@ void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES* DonneesAnnuelles, int N for (Var = 0; Var < ProblemeLineairePartieFixe.NombreDeVariables; Var++) { - pt = ProblemeLineairePartieVariable->AdresseOuPlacerLaValeurDesVariablesOptimisees[Var]; + pt = ProblemeLineairePartieVariable.AdresseOuPlacerLaValeurDesVariablesOptimisees[Var]; if (pt != NULL) - *pt = ProblemeLineairePartieVariable->X[Var]; + *pt = ProblemeLineairePartieVariable.X[Var]; } } else From 51729ac2f808408f6c547eee238cd38dd6f2ab37 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Wed, 13 Sep 2023 09:18:09 +0200 Subject: [PATCH 14/42] [FIX] use new instead of malloc to call constructor --- src/solver/hydro/monthly/h2o_m_instanciation.cpp | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/solver/hydro/monthly/h2o_m_instanciation.cpp b/src/solver/hydro/monthly/h2o_m_instanciation.cpp index 25ecd32a68..bb8a62b75e 100644 --- a/src/solver/hydro/monthly/h2o_m_instanciation.cpp +++ b/src/solver/hydro/monthly/h2o_m_instanciation.cpp @@ -39,21 +39,12 @@ DONNEES_ANNUELLES* H2O_M_Instanciation(int NombreDeReservoirs) DONNEES_ANNUELLES* DonneesAnnuelles; PROBLEME_HYDRAULIQUE* ProblemeHydraulique; - DonneesAnnuelles = (DONNEES_ANNUELLES*)malloc(sizeof(DONNEES_ANNUELLES)); - if (DonneesAnnuelles == NULL) - { - return (NULL); - } + DonneesAnnuelles = new DONNEES_ANNUELLES; DonneesAnnuelles->NombreDePasDeTemps = 12; NbPdt = DonneesAnnuelles->NombreDePasDeTemps; - DonneesAnnuelles->ProblemeHydraulique - = (PROBLEME_HYDRAULIQUE*)malloc(sizeof(PROBLEME_HYDRAULIQUE)); - if (DonneesAnnuelles->ProblemeHydraulique == NULL) - { - return (NULL); - } + DonneesAnnuelles->ProblemeHydraulique = new PROBLEME_HYDRAULIQUE; DonneesAnnuelles->TurbineMax.assign(NbPdt, 0.); DonneesAnnuelles->TurbineMin.assign(NbPdt, 0.); From cc88b226bb14365ec277b8c74ad056a380492416 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Wed, 13 Sep 2023 09:54:51 +0200 Subject: [PATCH 15/42] [DEV] ProblemeHydraulique --- src/solver/hydro/management/monthly.cpp | 4 ++-- .../hydro/monthly/h2o_m_ajouter_bruit.cpp | 6 ++--- .../h2o_m_construire_les_contraintes.cpp | 7 +++--- .../h2o_m_construire_les_variables.cpp | 8 +++---- .../hydro/monthly/h2o_m_donnees_annuelles.h | 2 +- src/solver/hydro/monthly/h2o_m_free.cpp | 13 +++++------ ...m_initialiser_les_bornes_des_variables.cpp | 8 +++---- .../h2o_m_initialiser_les_second_membre.cpp | 4 ++-- .../hydro/monthly/h2o_m_instanciation.cpp | 21 ++++++++---------- .../monthly/h2o_m_optimiser_une_annee.cpp | 6 ++--- .../h2o_m_resoudre_le_probleme_lineaire.cpp | 22 +++++++++---------- 11 files changed, 46 insertions(+), 55 deletions(-) diff --git a/src/solver/hydro/management/monthly.cpp b/src/solver/hydro/management/monthly.cpp index 2e631ae576..544ba7a518 100644 --- a/src/solver/hydro/management/monthly.cpp +++ b/src/solver/hydro/management/monthly.cpp @@ -205,8 +205,8 @@ void HydroManagement::prepareMonthlyOptimalGenerations(double* random_reservoir_ data.MOL[realmonth] = problem.Volume[month]; } data.MOL[initReservoirLvlMonth] = lvi; - solutionCost = problem.ProblemeHydraulique->CoutDeLaSolution; - solutionCostNoised = problem.ProblemeHydraulique->CoutDeLaSolutionBruite; + solutionCost = problem.ProblemeHydraulique.CoutDeLaSolution; + solutionCostNoised = problem.ProblemeHydraulique.CoutDeLaSolutionBruite; break; } diff --git a/src/solver/hydro/monthly/h2o_m_ajouter_bruit.cpp b/src/solver/hydro/monthly/h2o_m_ajouter_bruit.cpp index 547d822c63..7f5379acdb 100644 --- a/src/solver/hydro/monthly/h2o_m_ajouter_bruit.cpp +++ b/src/solver/hydro/monthly/h2o_m_ajouter_bruit.cpp @@ -11,11 +11,11 @@ constexpr unsigned int seed = 0x79686d64; // "hydm" in hexa void H2O_M_AjouterBruitAuCout(DONNEES_ANNUELLES* DonneesAnnuelles) { - PROBLEME_HYDRAULIQUE* ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; + PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; PROBLEME_LINEAIRE_PARTIE_FIXE& ProblemeLineairePartieFixe - = ProblemeHydraulique->ProblemeLineairePartieFixe; + = ProblemeHydraulique.ProblemeLineairePartieFixe; CORRESPONDANCE_DES_VARIABLES& CorrespondanceDesVariables - = ProblemeHydraulique->CorrespondanceDesVariables; + = ProblemeHydraulique.CorrespondanceDesVariables; auto& CoutLineaireBruite = ProblemeLineairePartieFixe.CoutLineaireBruite; const auto& CoutLineaire = ProblemeLineairePartieFixe.CoutLineaire; diff --git a/src/solver/hydro/monthly/h2o_m_construire_les_contraintes.cpp b/src/solver/hydro/monthly/h2o_m_construire_les_contraintes.cpp index 5a07b7210e..21f153d5cc 100644 --- a/src/solver/hydro/monthly/h2o_m_construire_les_contraintes.cpp +++ b/src/solver/hydro/monthly/h2o_m_construire_les_contraintes.cpp @@ -37,17 +37,16 @@ void H2O_M_ConstruireLesContraintes(DONNEES_ANNUELLES* DonneesAnnuelles) double ChgmtSens; int NumeroDeLaVariableXi; - PROBLEME_HYDRAULIQUE* ProblemeHydraulique; ChgmtSens = -1.0; NbPdt = DonneesAnnuelles->NombreDePasDeTemps; - ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; + PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; CORRESPONDANCE_DES_VARIABLES& CorrespondanceDesVariables - = ProblemeHydraulique->CorrespondanceDesVariables; + = ProblemeHydraulique.CorrespondanceDesVariables; PROBLEME_LINEAIRE_PARTIE_FIXE& ProblemeLineairePartieFixe - = ProblemeHydraulique->ProblemeLineairePartieFixe; + = ProblemeHydraulique.ProblemeLineairePartieFixe; auto& CoefficientsDeLaMatriceDesContraintes = ProblemeLineairePartieFixe.CoefficientsDeLaMatriceDesContraintes; diff --git a/src/solver/hydro/monthly/h2o_m_construire_les_variables.cpp b/src/solver/hydro/monthly/h2o_m_construire_les_variables.cpp index 53ec792472..8a05e8e11b 100644 --- a/src/solver/hydro/monthly/h2o_m_construire_les_variables.cpp +++ b/src/solver/hydro/monthly/h2o_m_construire_les_variables.cpp @@ -44,13 +44,13 @@ void H2O_M_ConstruireLesVariables(DONNEES_ANNUELLES* DonneesAnnuelles) int Var; int Pdt; int NbPdt; - PROBLEME_HYDRAULIQUE* ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; + PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; PROBLEME_LINEAIRE_PARTIE_VARIABLE& ProblemeLineairePartieVariable - = ProblemeHydraulique->ProblemeLineairePartieVariable; + = ProblemeHydraulique.ProblemeLineairePartieVariable; PROBLEME_LINEAIRE_PARTIE_FIXE& ProblemeLineairePartieFixe - = ProblemeHydraulique->ProblemeLineairePartieFixe; + = ProblemeHydraulique.ProblemeLineairePartieFixe; CORRESPONDANCE_DES_VARIABLES& CorrespondanceDesVariables - = ProblemeHydraulique->CorrespondanceDesVariables; + = ProblemeHydraulique.CorrespondanceDesVariables; NbPdt = DonneesAnnuelles->NombreDePasDeTemps; diff --git a/src/solver/hydro/monthly/h2o_m_donnees_annuelles.h b/src/solver/hydro/monthly/h2o_m_donnees_annuelles.h index 7fda16553d..175aed380c 100644 --- a/src/solver/hydro/monthly/h2o_m_donnees_annuelles.h +++ b/src/solver/hydro/monthly/h2o_m_donnees_annuelles.h @@ -65,7 +65,7 @@ typedef struct /******************************************************************************************/ /* Problemes internes (utilise uniquement par l'optimisation) */ - PROBLEME_HYDRAULIQUE* ProblemeHydraulique; + PROBLEME_HYDRAULIQUE ProblemeHydraulique; int NombreDePasDeTemps; /* 12 */ } DONNEES_ANNUELLES; diff --git a/src/solver/hydro/monthly/h2o_m_free.cpp b/src/solver/hydro/monthly/h2o_m_free.cpp index 46c6670064..17f1456993 100644 --- a/src/solver/hydro/monthly/h2o_m_free.cpp +++ b/src/solver/hydro/monthly/h2o_m_free.cpp @@ -45,22 +45,19 @@ void H2O_M_Free(DONNEES_ANNUELLES* DonneesAnnuelles) int i; PROBLEME_SPX* ProbSpx; - PROBLEME_HYDRAULIQUE* ProblemeHydraulique; + PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; - ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; - - for (i = 0; i < ProblemeHydraulique->NombreDeReservoirs; i++) + for (i = 0; i < ProblemeHydraulique.NombreDeReservoirs; i++) { - ProbSpx = (PROBLEME_SPX*)ProblemeHydraulique->ProblemeSpx[i]; + ProbSpx = (PROBLEME_SPX*)ProblemeHydraulique.ProblemeSpx[i]; if (ProbSpx != NULL) { SPX_LibererProbleme(ProbSpx); } } - free(ProblemeHydraulique->ProblemeSpx); - free(ProblemeHydraulique->Probleme); - free(ProblemeHydraulique); + free(ProblemeHydraulique.ProblemeSpx); + free(ProblemeHydraulique.Probleme); free(DonneesAnnuelles); diff --git a/src/solver/hydro/monthly/h2o_m_initialiser_les_bornes_des_variables.cpp b/src/solver/hydro/monthly/h2o_m_initialiser_les_bornes_des_variables.cpp index 16e1292ef7..f9fb0f2204 100644 --- a/src/solver/hydro/monthly/h2o_m_initialiser_les_bornes_des_variables.cpp +++ b/src/solver/hydro/monthly/h2o_m_initialiser_les_bornes_des_variables.cpp @@ -32,13 +32,13 @@ void H2O_M_InitialiserBornesEtCoutsDesVariables(DONNEES_ANNUELLES* DonneesAnnuel { int Var; - PROBLEME_HYDRAULIQUE* ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; + PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; PROBLEME_LINEAIRE_PARTIE_VARIABLE& ProblemeLineairePartieVariable - = ProblemeHydraulique->ProblemeLineairePartieVariable; + = ProblemeHydraulique.ProblemeLineairePartieVariable; const CORRESPONDANCE_DES_VARIABLES& CorrespondanceDesVariables - = ProblemeHydraulique->CorrespondanceDesVariables; + = ProblemeHydraulique.CorrespondanceDesVariables; PROBLEME_LINEAIRE_PARTIE_FIXE& ProblemeLineairePartieFixe - = ProblemeHydraulique->ProblemeLineairePartieFixe; + = ProblemeHydraulique.ProblemeLineairePartieFixe; DonneesAnnuelles->Volume[0] = DonneesAnnuelles->VolumeInitial; diff --git a/src/solver/hydro/monthly/h2o_m_initialiser_les_second_membre.cpp b/src/solver/hydro/monthly/h2o_m_initialiser_les_second_membre.cpp index 27aac08793..d0378bef51 100644 --- a/src/solver/hydro/monthly/h2o_m_initialiser_les_second_membre.cpp +++ b/src/solver/hydro/monthly/h2o_m_initialiser_les_second_membre.cpp @@ -30,9 +30,9 @@ void H2O_M_InitialiserLeSecondMembre(DONNEES_ANNUELLES* DonneesAnnuelles) { - PROBLEME_HYDRAULIQUE* ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; + PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; PROBLEME_LINEAIRE_PARTIE_VARIABLE& ProblemeLineairePartieVariable - = ProblemeHydraulique->ProblemeLineairePartieVariable; + = ProblemeHydraulique.ProblemeLineairePartieVariable; double ChgmtSens = -1; int NbPdt = DonneesAnnuelles->NombreDePasDeTemps; diff --git a/src/solver/hydro/monthly/h2o_m_instanciation.cpp b/src/solver/hydro/monthly/h2o_m_instanciation.cpp index bb8a62b75e..5840ef71dc 100644 --- a/src/solver/hydro/monthly/h2o_m_instanciation.cpp +++ b/src/solver/hydro/monthly/h2o_m_instanciation.cpp @@ -37,15 +37,12 @@ DONNEES_ANNUELLES* H2O_M_Instanciation(int NombreDeReservoirs) int NombreDeContraintes; int NombreDeTermesAlloues; DONNEES_ANNUELLES* DonneesAnnuelles; - PROBLEME_HYDRAULIQUE* ProblemeHydraulique; DonneesAnnuelles = new DONNEES_ANNUELLES; DonneesAnnuelles->NombreDePasDeTemps = 12; NbPdt = DonneesAnnuelles->NombreDePasDeTemps; - DonneesAnnuelles->ProblemeHydraulique = new PROBLEME_HYDRAULIQUE; - DonneesAnnuelles->TurbineMax.assign(NbPdt, 0.); DonneesAnnuelles->TurbineMin.assign(NbPdt, 0.); DonneesAnnuelles->TurbineCible.assign(NbPdt, 0.); @@ -57,29 +54,29 @@ DONNEES_ANNUELLES* H2O_M_Instanciation(int NombreDeReservoirs) DonneesAnnuelles->VolumeMin.assign(NbPdt, 0.); DonneesAnnuelles->VolumeMax.assign(NbPdt, 0.); - ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; + PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; - ProblemeHydraulique->NombreDeReservoirs = NombreDeReservoirs; + ProblemeHydraulique.NombreDeReservoirs = NombreDeReservoirs; - ProblemeHydraulique->ProblemeSpx + ProblemeHydraulique.ProblemeSpx = (void**)malloc((unsigned int)NombreDeReservoirs * sizeof(void*)); - if (ProblemeHydraulique->ProblemeSpx == NULL) + if (ProblemeHydraulique.ProblemeSpx == NULL) { return (0); } for (i = 0; i < NombreDeReservoirs; i++) { - ProblemeHydraulique->ProblemeSpx[i] = NULL; + ProblemeHydraulique.ProblemeSpx[i] = NULL; } - ProblemeHydraulique->Probleme = NULL; + ProblemeHydraulique.Probleme = NULL; CORRESPONDANCE_DES_VARIABLES& CorrespondanceDesVariables - = ProblemeHydraulique->CorrespondanceDesVariables; + = ProblemeHydraulique.CorrespondanceDesVariables; PROBLEME_LINEAIRE_PARTIE_FIXE& ProblemeLineairePartieFixe - = ProblemeHydraulique->ProblemeLineairePartieFixe; + = ProblemeHydraulique.ProblemeLineairePartieFixe; PROBLEME_LINEAIRE_PARTIE_VARIABLE& ProblemeLineairePartieVariable - = ProblemeHydraulique->ProblemeLineairePartieVariable; + = ProblemeHydraulique.ProblemeLineairePartieVariable; CorrespondanceDesVariables.NumeroDeVariableVolume.assign(NbPdt, 0); CorrespondanceDesVariables.NumeroDeVariableTurbine.assign(NbPdt, 0); diff --git a/src/solver/hydro/monthly/h2o_m_optimiser_une_annee.cpp b/src/solver/hydro/monthly/h2o_m_optimiser_une_annee.cpp index 2e9a0e3a4a..c95468f3e0 100644 --- a/src/solver/hydro/monthly/h2o_m_optimiser_une_annee.cpp +++ b/src/solver/hydro/monthly/h2o_m_optimiser_une_annee.cpp @@ -30,11 +30,9 @@ void H2O_M_OptimiserUneAnnee(DONNEES_ANNUELLES* DonneesAnnuelles, int NumeroDeReservoir) { - PROBLEME_HYDRAULIQUE* ProblemeHydraulique; + PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; - ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; - - if (NumeroDeReservoir < 0 || NumeroDeReservoir > ProblemeHydraulique->NombreDeReservoirs) + if (NumeroDeReservoir < 0 || NumeroDeReservoir > ProblemeHydraulique.NombreDeReservoirs) { DonneesAnnuelles->ResultatsValides = EMERGENCY_SHUT_DOWN; return; diff --git a/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp b/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp index d640c7c77d..bf4ff4c00d 100644 --- a/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp +++ b/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp @@ -52,11 +52,11 @@ void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES* DonneesAnnuelles, int N double* pt; char PremierPassage; - PROBLEME_HYDRAULIQUE* ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; + PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; PROBLEME_LINEAIRE_PARTIE_VARIABLE& ProblemeLineairePartieVariable - = ProblemeHydraulique->ProblemeLineairePartieVariable; + = ProblemeHydraulique.ProblemeLineairePartieVariable; PROBLEME_LINEAIRE_PARTIE_FIXE& ProblemeLineairePartieFixe - = ProblemeHydraulique->ProblemeLineairePartieFixe; + = ProblemeHydraulique.ProblemeLineairePartieFixe; PROBLEME_SIMPLEXE* Probleme; PROBLEME_SPX* ProbSpx; @@ -65,9 +65,9 @@ void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES* DonneesAnnuelles, int N - ProbSpx = (PROBLEME_SPX*)ProblemeHydraulique->ProblemeSpx[NumeroDeReservoir]; + ProbSpx = (PROBLEME_SPX*)ProblemeHydraulique.ProblemeSpx[NumeroDeReservoir]; - Probleme = (PROBLEME_SIMPLEXE*)ProblemeHydraulique->Probleme; + Probleme = (PROBLEME_SIMPLEXE*)ProblemeHydraulique.Probleme; if (Probleme == NULL) { Probleme = (PROBLEME_SIMPLEXE*)malloc(sizeof(PROBLEME_SIMPLEXE)); @@ -76,7 +76,7 @@ void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES* DonneesAnnuelles, int N DonneesAnnuelles->ResultatsValides = EMERGENCY_SHUT_DOWN; return; } - ProblemeHydraulique->Probleme = (void*)Probleme; + ProblemeHydraulique.Probleme = (void*)Probleme; } RESOLUTION: @@ -151,7 +151,7 @@ void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES* DonneesAnnuelles, int N if (ProbSpx != NULL) { - ProblemeHydraulique->ProblemeSpx[NumeroDeReservoir] = (void*)ProbSpx; + ProblemeHydraulique.ProblemeSpx[NumeroDeReservoir] = (void*)ProbSpx; } ProblemeLineairePartieVariable.ExistenceDUneSolution = Probleme->ExistenceDUneSolution; @@ -176,17 +176,17 @@ void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES* DonneesAnnuelles, int N if (ProblemeLineairePartieVariable.ExistenceDUneSolution == OUI_SPX) { - ProblemeHydraulique->CoutDeLaSolution = 0.0; + ProblemeHydraulique.CoutDeLaSolution = 0.0; for (Var = 0; Var < Probleme->NombreDeVariables; Var++) { - ProblemeHydraulique->CoutDeLaSolution + ProblemeHydraulique.CoutDeLaSolution += ProblemeLineairePartieFixe.CoutLineaire[Var] * Probleme->X[Var]; } - ProblemeHydraulique->CoutDeLaSolutionBruite = 0.0; + ProblemeHydraulique.CoutDeLaSolutionBruite = 0.0; for (Var = 0; Var < Probleme->NombreDeVariables; Var++) { - ProblemeHydraulique->CoutDeLaSolutionBruite + ProblemeHydraulique.CoutDeLaSolutionBruite += ProblemeLineairePartieFixe.CoutLineaireBruite[Var] * Probleme->X[Var]; } From 17a0370b85e1c98af2957dbbb978e78b1bf64f56 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Wed, 13 Sep 2023 10:22:04 +0200 Subject: [PATCH 16/42] [DEV] DONNEES_ANNUELLES --- src/solver/hydro/management/monthly.cpp | 4 +-- .../hydro/monthly/h2o_m_ajouter_bruit.cpp | 6 ++-- .../h2o_m_construire_les_contraintes.cpp | 6 ++-- .../h2o_m_construire_les_variables.cpp | 12 +++---- src/solver/hydro/monthly/h2o_m_fonctions.h | 16 ++++----- ...m_initialiser_les_bornes_des_variables.cpp | 22 ++++++------- .../h2o_m_initialiser_les_second_membre.cpp | 16 ++++----- .../hydro/monthly/h2o_m_instanciation.cpp | 33 ++++++++----------- .../monthly/h2o_m_optimiser_une_annee.cpp | 8 ++--- .../h2o_m_resoudre_le_probleme_lineaire.cpp | 12 +++---- 10 files changed, 65 insertions(+), 70 deletions(-) diff --git a/src/solver/hydro/management/monthly.cpp b/src/solver/hydro/management/monthly.cpp index 544ba7a518..3595e4fcf3 100644 --- a/src/solver/hydro/management/monthly.cpp +++ b/src/solver/hydro/management/monthly.cpp @@ -168,7 +168,7 @@ void HydroManagement::prepareMonthlyOptimalGenerations(double* random_reservoir_ if (area.hydro.reservoirManagement) { - auto& problem = *H2O_M_Instanciation(1); + auto problem = H2O_M_Instanciation(1); double totalInflowsYear = prepareMonthlyTargetGenerations(area, data); assert(totalInflowsYear >= 0.); @@ -192,7 +192,7 @@ void HydroManagement::prepareMonthlyOptimalGenerations(double* random_reservoir_ problem.VolumeMax[month] = maxLvl[firstDay]; } - H2O_M_OptimiserUneAnnee(&problem, 0); + H2O_M_OptimiserUneAnnee(problem, 0); switch (problem.ResultatsValides) { case OUI: { if (Logs::Verbosity::Debug::enabled) diff --git a/src/solver/hydro/monthly/h2o_m_ajouter_bruit.cpp b/src/solver/hydro/monthly/h2o_m_ajouter_bruit.cpp index 7f5379acdb..3b0c1ada26 100644 --- a/src/solver/hydro/monthly/h2o_m_ajouter_bruit.cpp +++ b/src/solver/hydro/monthly/h2o_m_ajouter_bruit.cpp @@ -9,9 +9,9 @@ constexpr double noiseAmplitude = 1e-3; constexpr unsigned int seed = 0x79686d64; // "hydm" in hexa } // namespace Constants -void H2O_M_AjouterBruitAuCout(DONNEES_ANNUELLES* DonneesAnnuelles) +void H2O_M_AjouterBruitAuCout(DONNEES_ANNUELLES& DonneesAnnuelles) { - PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; + PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesAnnuelles.ProblemeHydraulique; PROBLEME_LINEAIRE_PARTIE_FIXE& ProblemeLineairePartieFixe = ProblemeHydraulique.ProblemeLineairePartieFixe; CORRESPONDANCE_DES_VARIABLES& CorrespondanceDesVariables @@ -32,7 +32,7 @@ void H2O_M_AjouterBruitAuCout(DONNEES_ANNUELLES* DonneesAnnuelles) for (const auto variable : monthlyVariables) { - for (int Pdt = 0; Pdt < DonneesAnnuelles->NombreDePasDeTemps; Pdt++) + for (int Pdt = 0; Pdt < DonneesAnnuelles.NombreDePasDeTemps; Pdt++) { int Var = variable[Pdt]; CoutLineaireBruite[Var] diff --git a/src/solver/hydro/monthly/h2o_m_construire_les_contraintes.cpp b/src/solver/hydro/monthly/h2o_m_construire_les_contraintes.cpp index 21f153d5cc..8e451e98fd 100644 --- a/src/solver/hydro/monthly/h2o_m_construire_les_contraintes.cpp +++ b/src/solver/hydro/monthly/h2o_m_construire_les_contraintes.cpp @@ -28,7 +28,7 @@ #include "h2o_m_donnees_annuelles.h" #include "h2o_m_fonctions.h" -void H2O_M_ConstruireLesContraintes(DONNEES_ANNUELLES* DonneesAnnuelles) +void H2O_M_ConstruireLesContraintes(DONNEES_ANNUELLES& DonneesAnnuelles) { int NombreDeContraintes; int il; @@ -40,9 +40,9 @@ void H2O_M_ConstruireLesContraintes(DONNEES_ANNUELLES* DonneesAnnuelles) ChgmtSens = -1.0; - NbPdt = DonneesAnnuelles->NombreDePasDeTemps; + NbPdt = DonneesAnnuelles.NombreDePasDeTemps; - PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; + PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesAnnuelles.ProblemeHydraulique; CORRESPONDANCE_DES_VARIABLES& CorrespondanceDesVariables = ProblemeHydraulique.CorrespondanceDesVariables; PROBLEME_LINEAIRE_PARTIE_FIXE& ProblemeLineairePartieFixe diff --git a/src/solver/hydro/monthly/h2o_m_construire_les_variables.cpp b/src/solver/hydro/monthly/h2o_m_construire_les_variables.cpp index 8a05e8e11b..fcac3ad2bf 100644 --- a/src/solver/hydro/monthly/h2o_m_construire_les_variables.cpp +++ b/src/solver/hydro/monthly/h2o_m_construire_les_variables.cpp @@ -39,12 +39,12 @@ extern "C" #include "h2o_m_donnees_annuelles.h" #include "h2o_m_fonctions.h" -void H2O_M_ConstruireLesVariables(DONNEES_ANNUELLES* DonneesAnnuelles) +void H2O_M_ConstruireLesVariables(DONNEES_ANNUELLES& DonneesAnnuelles) { int Var; int Pdt; int NbPdt; - PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; + PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesAnnuelles.ProblemeHydraulique; PROBLEME_LINEAIRE_PARTIE_VARIABLE& ProblemeLineairePartieVariable = ProblemeHydraulique.ProblemeLineairePartieVariable; PROBLEME_LINEAIRE_PARTIE_FIXE& ProblemeLineairePartieFixe @@ -52,7 +52,7 @@ void H2O_M_ConstruireLesVariables(DONNEES_ANNUELLES* DonneesAnnuelles) CORRESPONDANCE_DES_VARIABLES& CorrespondanceDesVariables = ProblemeHydraulique.CorrespondanceDesVariables; - NbPdt = DonneesAnnuelles->NombreDePasDeTemps; + NbPdt = DonneesAnnuelles.NombreDePasDeTemps; Var = 0; @@ -63,7 +63,7 @@ void H2O_M_ConstruireLesVariables(DONNEES_ANNUELLES* DonneesAnnuelles) ProblemeLineairePartieVariable.Xmax[Var] = 1.0; ProblemeLineairePartieFixe.TypeDeVariable[Var] = VARIABLE_BORNEE_DES_DEUX_COTES; ProblemeLineairePartieVariable.AdresseOuPlacerLaValeurDesVariablesOptimisees[Var] - = &(DonneesAnnuelles->Volume[Pdt]); + = &(DonneesAnnuelles.Volume[Pdt]); Var++; for (Pdt = 1; Pdt < NbPdt; Pdt++) @@ -73,7 +73,7 @@ void H2O_M_ConstruireLesVariables(DONNEES_ANNUELLES* DonneesAnnuelles) ProblemeLineairePartieVariable.Xmax[Var] = 1.0; ProblemeLineairePartieFixe.TypeDeVariable[Var] = VARIABLE_BORNEE_DES_DEUX_COTES; ProblemeLineairePartieVariable.AdresseOuPlacerLaValeurDesVariablesOptimisees[Var] - = &(DonneesAnnuelles->Volume[Pdt]); + = &(DonneesAnnuelles.Volume[Pdt]); Var++; } @@ -84,7 +84,7 @@ void H2O_M_ConstruireLesVariables(DONNEES_ANNUELLES* DonneesAnnuelles) ProblemeLineairePartieVariable.Xmax[Var] = 0.0; ProblemeLineairePartieFixe.TypeDeVariable[Var] = VARIABLE_BORNEE_DES_DEUX_COTES; ProblemeLineairePartieVariable.AdresseOuPlacerLaValeurDesVariablesOptimisees[Var] - = &(DonneesAnnuelles->Turbine[Pdt]); + = &(DonneesAnnuelles.Turbine[Pdt]); Var++; } diff --git a/src/solver/hydro/monthly/h2o_m_fonctions.h b/src/solver/hydro/monthly/h2o_m_fonctions.h index b11315743c..86f072f6d1 100644 --- a/src/solver/hydro/monthly/h2o_m_fonctions.h +++ b/src/solver/hydro/monthly/h2o_m_fonctions.h @@ -27,15 +27,15 @@ #ifndef __SOLVER_H2O_M_FONCTIONS__ #define __SOLVER_H2O_M_FONCTIONS__ -DONNEES_ANNUELLES* H2O_M_Instanciation(int); -void H2O_M_OptimiserUneAnnee(DONNEES_ANNUELLES*, int); +DONNEES_ANNUELLES H2O_M_Instanciation(int); +void H2O_M_OptimiserUneAnnee(DONNEES_ANNUELLES&, int); void H2O_M_Free(DONNEES_ANNUELLES*); -void H2O_M_ConstruireLesContraintes(DONNEES_ANNUELLES*); -void H2O_M_ConstruireLesVariables(DONNEES_ANNUELLES*); -void H2O_M_InitialiserBornesEtCoutsDesVariables(DONNEES_ANNUELLES*); -void H2O_M_InitialiserLeSecondMembre(DONNEES_ANNUELLES*); -void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES*, int); -void H2O_M_AjouterBruitAuCout(DONNEES_ANNUELLES*); +void H2O_M_ConstruireLesContraintes(DONNEES_ANNUELLES&); +void H2O_M_ConstruireLesVariables(DONNEES_ANNUELLES&); +void H2O_M_InitialiserBornesEtCoutsDesVariables(DONNEES_ANNUELLES&); +void H2O_M_InitialiserLeSecondMembre(DONNEES_ANNUELLES&); +void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES&, int); +void H2O_M_AjouterBruitAuCout(DONNEES_ANNUELLES&); #endif /* __SOLVER_H2O_M_FONCTIONS__ */ diff --git a/src/solver/hydro/monthly/h2o_m_initialiser_les_bornes_des_variables.cpp b/src/solver/hydro/monthly/h2o_m_initialiser_les_bornes_des_variables.cpp index f9fb0f2204..545382165b 100644 --- a/src/solver/hydro/monthly/h2o_m_initialiser_les_bornes_des_variables.cpp +++ b/src/solver/hydro/monthly/h2o_m_initialiser_les_bornes_des_variables.cpp @@ -28,11 +28,11 @@ #include "h2o_m_donnees_annuelles.h" #include "h2o_m_fonctions.h" -void H2O_M_InitialiserBornesEtCoutsDesVariables(DONNEES_ANNUELLES* DonneesAnnuelles) +void H2O_M_InitialiserBornesEtCoutsDesVariables(DONNEES_ANNUELLES& DonneesAnnuelles) { int Var; - PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; + PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesAnnuelles.ProblemeHydraulique; PROBLEME_LINEAIRE_PARTIE_VARIABLE& ProblemeLineairePartieVariable = ProblemeHydraulique.ProblemeLineairePartieVariable; const CORRESPONDANCE_DES_VARIABLES& CorrespondanceDesVariables @@ -40,12 +40,12 @@ void H2O_M_InitialiserBornesEtCoutsDesVariables(DONNEES_ANNUELLES* DonneesAnnuel PROBLEME_LINEAIRE_PARTIE_FIXE& ProblemeLineairePartieFixe = ProblemeHydraulique.ProblemeLineairePartieFixe; - DonneesAnnuelles->Volume[0] = DonneesAnnuelles->VolumeInitial; + DonneesAnnuelles.Volume[0] = DonneesAnnuelles.VolumeInitial; - int NbPdt = DonneesAnnuelles->NombreDePasDeTemps; - double CoutDepassementVolume = DonneesAnnuelles->CoutDepassementVolume; - auto& TurbineMax = DonneesAnnuelles->TurbineMax; - const auto& TurbineMin = DonneesAnnuelles->TurbineMin; + int NbPdt = DonneesAnnuelles.NombreDePasDeTemps; + double CoutDepassementVolume = DonneesAnnuelles.CoutDepassementVolume; + auto& TurbineMax = DonneesAnnuelles.TurbineMax; + const auto& TurbineMin = DonneesAnnuelles.TurbineMin; auto& Xmin = ProblemeLineairePartieVariable.Xmin; @@ -54,9 +54,9 @@ void H2O_M_InitialiserBornesEtCoutsDesVariables(DONNEES_ANNUELLES* DonneesAnnuel auto& CoutLineaire = ProblemeLineairePartieFixe.CoutLineaire; Var = CorrespondanceDesVariables.NumeroDeVariableVolume[0]; - X[Var] = DonneesAnnuelles->Volume[0]; - Xmin[Var] = DonneesAnnuelles->Volume[0]; - Xmax[Var] = DonneesAnnuelles->Volume[0]; + X[Var] = DonneesAnnuelles.Volume[0]; + Xmin[Var] = DonneesAnnuelles.Volume[0]; + Xmax[Var] = DonneesAnnuelles.Volume[0]; for (int Pdt = 0; Pdt < NbPdt; Pdt++) { @@ -85,7 +85,7 @@ void H2O_M_InitialiserBornesEtCoutsDesVariables(DONNEES_ANNUELLES* DonneesAnnuel } Var = CorrespondanceDesVariables.NumeroDeLaVariableViolMaxVolumeMin; - CoutLineaire[Var] = DonneesAnnuelles->CoutViolMaxDuVolumeMin; + CoutLineaire[Var] = DonneesAnnuelles.CoutViolMaxDuVolumeMin; for (int Pdt = 0; Pdt < NbPdt; Pdt++) { diff --git a/src/solver/hydro/monthly/h2o_m_initialiser_les_second_membre.cpp b/src/solver/hydro/monthly/h2o_m_initialiser_les_second_membre.cpp index d0378bef51..233ca33ce7 100644 --- a/src/solver/hydro/monthly/h2o_m_initialiser_les_second_membre.cpp +++ b/src/solver/hydro/monthly/h2o_m_initialiser_les_second_membre.cpp @@ -28,34 +28,34 @@ #include "h2o_m_donnees_annuelles.h" #include "h2o_m_fonctions.h" -void H2O_M_InitialiserLeSecondMembre(DONNEES_ANNUELLES* DonneesAnnuelles) +void H2O_M_InitialiserLeSecondMembre(DONNEES_ANNUELLES& DonneesAnnuelles) { - PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; + PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesAnnuelles.ProblemeHydraulique; PROBLEME_LINEAIRE_PARTIE_VARIABLE& ProblemeLineairePartieVariable = ProblemeHydraulique.ProblemeLineairePartieVariable; double ChgmtSens = -1; - int NbPdt = DonneesAnnuelles->NombreDePasDeTemps; + int NbPdt = DonneesAnnuelles.NombreDePasDeTemps; int Cnt = 0; - auto& TurbineCible = DonneesAnnuelles->TurbineCible; + auto& TurbineCible = DonneesAnnuelles.TurbineCible; auto& SecondMembre = ProblemeLineairePartieVariable.SecondMembre; for (int Pdt = 1; Pdt < NbPdt; Pdt++) { - SecondMembre[Cnt] = DonneesAnnuelles->Apport[Pdt - 1]; + SecondMembre[Cnt] = DonneesAnnuelles.Apport[Pdt - 1]; Cnt++; } - SecondMembre[Cnt] = DonneesAnnuelles->Volume[0] - DonneesAnnuelles->Apport[NbPdt - 1]; + SecondMembre[Cnt] = DonneesAnnuelles.Volume[0] - DonneesAnnuelles.Apport[NbPdt - 1]; Cnt++; for (int Pdt = 1; Pdt < NbPdt; Pdt++) { - SecondMembre[Cnt] = DonneesAnnuelles->VolumeMax[Pdt]; + SecondMembre[Cnt] = DonneesAnnuelles.VolumeMax[Pdt]; Cnt++; - SecondMembre[Cnt] = DonneesAnnuelles->VolumeMin[Pdt] * ChgmtSens; + SecondMembre[Cnt] = DonneesAnnuelles.VolumeMin[Pdt] * ChgmtSens; Cnt++; } diff --git a/src/solver/hydro/monthly/h2o_m_instanciation.cpp b/src/solver/hydro/monthly/h2o_m_instanciation.cpp index 5840ef71dc..9b7ab8baba 100644 --- a/src/solver/hydro/monthly/h2o_m_instanciation.cpp +++ b/src/solver/hydro/monthly/h2o_m_instanciation.cpp @@ -28,7 +28,7 @@ #include "h2o_m_donnees_annuelles.h" #include "h2o_m_fonctions.h" -DONNEES_ANNUELLES* H2O_M_Instanciation(int NombreDeReservoirs) +DONNEES_ANNUELLES H2O_M_Instanciation(int NombreDeReservoirs) { int i; int NbPdt; @@ -36,34 +36,29 @@ DONNEES_ANNUELLES* H2O_M_Instanciation(int NombreDeReservoirs) int NombreDeVariables; int NombreDeContraintes; int NombreDeTermesAlloues; - DONNEES_ANNUELLES* DonneesAnnuelles; + DONNEES_ANNUELLES DonneesAnnuelles; - DonneesAnnuelles = new DONNEES_ANNUELLES; - DonneesAnnuelles->NombreDePasDeTemps = 12; + DonneesAnnuelles.NombreDePasDeTemps = 12; - NbPdt = DonneesAnnuelles->NombreDePasDeTemps; + NbPdt = DonneesAnnuelles.NombreDePasDeTemps; - DonneesAnnuelles->TurbineMax.assign(NbPdt, 0.); - DonneesAnnuelles->TurbineMin.assign(NbPdt, 0.); - DonneesAnnuelles->TurbineCible.assign(NbPdt, 0.); - DonneesAnnuelles->Turbine.assign(NbPdt, 0.); + DonneesAnnuelles.TurbineMax.assign(NbPdt, 0.); + DonneesAnnuelles.TurbineMin.assign(NbPdt, 0.); + DonneesAnnuelles.TurbineCible.assign(NbPdt, 0.); + DonneesAnnuelles.Turbine.assign(NbPdt, 0.); - DonneesAnnuelles->Apport.assign(NbPdt, 0.); + DonneesAnnuelles.Apport.assign(NbPdt, 0.); - DonneesAnnuelles->Volume.assign(NbPdt, 0.); - DonneesAnnuelles->VolumeMin.assign(NbPdt, 0.); - DonneesAnnuelles->VolumeMax.assign(NbPdt, 0.); + DonneesAnnuelles.Volume.assign(NbPdt, 0.); + DonneesAnnuelles.VolumeMin.assign(NbPdt, 0.); + DonneesAnnuelles.VolumeMax.assign(NbPdt, 0.); - PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; + PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesAnnuelles.ProblemeHydraulique; ProblemeHydraulique.NombreDeReservoirs = NombreDeReservoirs; ProblemeHydraulique.ProblemeSpx = (void**)malloc((unsigned int)NombreDeReservoirs * sizeof(void*)); - if (ProblemeHydraulique.ProblemeSpx == NULL) - { - return (0); - } for (i = 0; i < NombreDeReservoirs; i++) { ProblemeHydraulique.ProblemeSpx[i] = NULL; @@ -153,5 +148,5 @@ DONNEES_ANNUELLES* H2O_M_Instanciation(int NombreDeReservoirs) H2O_M_ConstruireLesContraintes(DonneesAnnuelles); - return (DonneesAnnuelles); + return DonneesAnnuelles; } diff --git a/src/solver/hydro/monthly/h2o_m_optimiser_une_annee.cpp b/src/solver/hydro/monthly/h2o_m_optimiser_une_annee.cpp index c95468f3e0..ea717851d5 100644 --- a/src/solver/hydro/monthly/h2o_m_optimiser_une_annee.cpp +++ b/src/solver/hydro/monthly/h2o_m_optimiser_une_annee.cpp @@ -28,17 +28,17 @@ #include "h2o_m_donnees_annuelles.h" #include "h2o_m_fonctions.h" -void H2O_M_OptimiserUneAnnee(DONNEES_ANNUELLES* DonneesAnnuelles, int NumeroDeReservoir) +void H2O_M_OptimiserUneAnnee(DONNEES_ANNUELLES& DonneesAnnuelles, int NumeroDeReservoir) { - PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; + PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesAnnuelles.ProblemeHydraulique; if (NumeroDeReservoir < 0 || NumeroDeReservoir > ProblemeHydraulique.NombreDeReservoirs) { - DonneesAnnuelles->ResultatsValides = EMERGENCY_SHUT_DOWN; + DonneesAnnuelles.ResultatsValides = EMERGENCY_SHUT_DOWN; return; } - DonneesAnnuelles->ResultatsValides = NON; + DonneesAnnuelles.ResultatsValides = NON; H2O_M_InitialiserBornesEtCoutsDesVariables(DonneesAnnuelles); diff --git a/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp b/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp index bf4ff4c00d..6214eb2a75 100644 --- a/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp +++ b/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp @@ -46,13 +46,13 @@ extern "C" #define SNPRINTF snprintf #endif -void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES* DonneesAnnuelles, int NumeroDeReservoir) +void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES& DonneesAnnuelles, int NumeroDeReservoir) { int Var; double* pt; char PremierPassage; - PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; + PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesAnnuelles.ProblemeHydraulique; PROBLEME_LINEAIRE_PARTIE_VARIABLE& ProblemeLineairePartieVariable = ProblemeHydraulique.ProblemeLineairePartieVariable; PROBLEME_LINEAIRE_PARTIE_FIXE& ProblemeLineairePartieFixe @@ -73,7 +73,7 @@ void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES* DonneesAnnuelles, int N Probleme = (PROBLEME_SIMPLEXE*)malloc(sizeof(PROBLEME_SIMPLEXE)); if (Probleme == NULL) { - DonneesAnnuelles->ResultatsValides = EMERGENCY_SHUT_DOWN; + DonneesAnnuelles.ResultatsValides = EMERGENCY_SHUT_DOWN; return; } ProblemeHydraulique.Probleme = (void*)Probleme; @@ -169,7 +169,7 @@ void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES* DonneesAnnuelles, int N } else { - DonneesAnnuelles->ResultatsValides = EMERGENCY_SHUT_DOWN; + DonneesAnnuelles.ResultatsValides = EMERGENCY_SHUT_DOWN; return; } } @@ -190,7 +190,7 @@ void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES* DonneesAnnuelles, int N += ProblemeLineairePartieFixe.CoutLineaireBruite[Var] * Probleme->X[Var]; } - DonneesAnnuelles->ResultatsValides = OUI; + DonneesAnnuelles.ResultatsValides = OUI; for (Var = 0; Var < ProblemeLineairePartieFixe.NombreDeVariables; Var++) { @@ -201,7 +201,7 @@ void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES* DonneesAnnuelles, int N } else { - DonneesAnnuelles->ResultatsValides = NON; + DonneesAnnuelles.ResultatsValides = NON; return; } From fb5cd5e8f2c1f8ccc72691ac90adaa1624afc483 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Wed, 13 Sep 2023 11:19:27 +0200 Subject: [PATCH 17/42] [FIX] Segfault --- src/solver/hydro/management/monthly.cpp | 2 +- src/solver/hydro/monthly/h2o_m_fonctions.h | 2 +- src/solver/hydro/monthly/h2o_m_free.cpp | 6 ++---- src/solver/hydro/monthly/h2o_m_instanciation.cpp | 2 +- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/solver/hydro/management/monthly.cpp b/src/solver/hydro/management/monthly.cpp index 3595e4fcf3..c24008427d 100644 --- a/src/solver/hydro/management/monthly.cpp +++ b/src/solver/hydro/management/monthly.cpp @@ -224,7 +224,7 @@ void HydroManagement::prepareMonthlyOptimalGenerations(double* random_reservoir_ } } - H2O_M_Free(&problem); + H2O_M_Free(problem); } else diff --git a/src/solver/hydro/monthly/h2o_m_fonctions.h b/src/solver/hydro/monthly/h2o_m_fonctions.h index 86f072f6d1..aa5a531b28 100644 --- a/src/solver/hydro/monthly/h2o_m_fonctions.h +++ b/src/solver/hydro/monthly/h2o_m_fonctions.h @@ -29,7 +29,7 @@ DONNEES_ANNUELLES H2O_M_Instanciation(int); void H2O_M_OptimiserUneAnnee(DONNEES_ANNUELLES&, int); -void H2O_M_Free(DONNEES_ANNUELLES*); +void H2O_M_Free(DONNEES_ANNUELLES&); void H2O_M_ConstruireLesContraintes(DONNEES_ANNUELLES&); void H2O_M_ConstruireLesVariables(DONNEES_ANNUELLES&); diff --git a/src/solver/hydro/monthly/h2o_m_free.cpp b/src/solver/hydro/monthly/h2o_m_free.cpp index 17f1456993..366a5af46f 100644 --- a/src/solver/hydro/monthly/h2o_m_free.cpp +++ b/src/solver/hydro/monthly/h2o_m_free.cpp @@ -40,12 +40,12 @@ extern "C" #include "h2o_m_donnees_annuelles.h" #include "h2o_m_fonctions.h" -void H2O_M_Free(DONNEES_ANNUELLES* DonneesAnnuelles) +void H2O_M_Free(DONNEES_ANNUELLES& DonneesAnnuelles) { int i; PROBLEME_SPX* ProbSpx; - PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; + PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesAnnuelles.ProblemeHydraulique; for (i = 0; i < ProblemeHydraulique.NombreDeReservoirs; i++) { @@ -59,7 +59,5 @@ void H2O_M_Free(DONNEES_ANNUELLES* DonneesAnnuelles) free(ProblemeHydraulique.ProblemeSpx); free(ProblemeHydraulique.Probleme); - free(DonneesAnnuelles); - return; } diff --git a/src/solver/hydro/monthly/h2o_m_instanciation.cpp b/src/solver/hydro/monthly/h2o_m_instanciation.cpp index 9b7ab8baba..096a866d93 100644 --- a/src/solver/hydro/monthly/h2o_m_instanciation.cpp +++ b/src/solver/hydro/monthly/h2o_m_instanciation.cpp @@ -36,7 +36,7 @@ DONNEES_ANNUELLES H2O_M_Instanciation(int NombreDeReservoirs) int NombreDeVariables; int NombreDeContraintes; int NombreDeTermesAlloues; - DONNEES_ANNUELLES DonneesAnnuelles; + DONNEES_ANNUELLES DonneesAnnuelles{}; DonneesAnnuelles.NombreDePasDeTemps = 12; From 634d415712e6011d95aab7d72281d7506ed4a8df Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Wed, 13 Sep 2023 11:22:11 +0200 Subject: [PATCH 18/42] [DEV] ProblemeSpx --- src/solver/hydro/monthly/h2o_m_donnees_optimisation.h | 2 +- src/solver/hydro/monthly/h2o_m_free.cpp | 4 +--- src/solver/hydro/monthly/h2o_m_instanciation.cpp | 11 +++-------- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h b/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h index 6576be3887..15c3fc1bed 100644 --- a/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h +++ b/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h @@ -115,7 +115,7 @@ typedef struct PROBLEME_LINEAIRE_PARTIE_FIXE ProblemeLineairePartieFixe; PROBLEME_LINEAIRE_PARTIE_VARIABLE ProblemeLineairePartieVariable; - void** ProblemeSpx; /* Il y en a 1 par reservoir */ + std::vector ProblemeSpx; /* Il y en a 1 par reservoir */ void* Probleme; /* Le probleme en cours passe au simplexe */ double CoutDeLaSolution; diff --git a/src/solver/hydro/monthly/h2o_m_free.cpp b/src/solver/hydro/monthly/h2o_m_free.cpp index 366a5af46f..03746b1db2 100644 --- a/src/solver/hydro/monthly/h2o_m_free.cpp +++ b/src/solver/hydro/monthly/h2o_m_free.cpp @@ -42,12 +42,11 @@ extern "C" void H2O_M_Free(DONNEES_ANNUELLES& DonneesAnnuelles) { - int i; PROBLEME_SPX* ProbSpx; PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesAnnuelles.ProblemeHydraulique; - for (i = 0; i < ProblemeHydraulique.NombreDeReservoirs; i++) + for (int i = 0; i < ProblemeHydraulique.NombreDeReservoirs; i++) { ProbSpx = (PROBLEME_SPX*)ProblemeHydraulique.ProblemeSpx[i]; if (ProbSpx != NULL) @@ -56,7 +55,6 @@ void H2O_M_Free(DONNEES_ANNUELLES& DonneesAnnuelles) } } - free(ProblemeHydraulique.ProblemeSpx); free(ProblemeHydraulique.Probleme); return; diff --git a/src/solver/hydro/monthly/h2o_m_instanciation.cpp b/src/solver/hydro/monthly/h2o_m_instanciation.cpp index 096a866d93..c44a5a6775 100644 --- a/src/solver/hydro/monthly/h2o_m_instanciation.cpp +++ b/src/solver/hydro/monthly/h2o_m_instanciation.cpp @@ -57,14 +57,9 @@ DONNEES_ANNUELLES H2O_M_Instanciation(int NombreDeReservoirs) ProblemeHydraulique.NombreDeReservoirs = NombreDeReservoirs; - ProblemeHydraulique.ProblemeSpx - = (void**)malloc((unsigned int)NombreDeReservoirs * sizeof(void*)); - for (i = 0; i < NombreDeReservoirs; i++) - { - ProblemeHydraulique.ProblemeSpx[i] = NULL; - } - - ProblemeHydraulique.Probleme = NULL; + ProblemeHydraulique.ProblemeSpx.assign(NombreDeReservoirs, nullptr); + + ProblemeHydraulique.Probleme = nullptr; CORRESPONDANCE_DES_VARIABLES& CorrespondanceDesVariables = ProblemeHydraulique.CorrespondanceDesVariables; From 170f915f619a642d81d9e4030c04e9bcd40d233d Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Fri, 15 Sep 2023 17:11:43 +0200 Subject: [PATCH 19/42] [FIX] Solved unfeasible --- src/solver/hydro/daily/h2o_j_fonctions.h | 2 +- src/solver/hydro/daily/h2o_j_instanciation.cpp | 14 +++++++------- src/solver/hydro/management/daily.cpp | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/solver/hydro/daily/h2o_j_fonctions.h b/src/solver/hydro/daily/h2o_j_fonctions.h index 2be835dc3e..5614e98d12 100644 --- a/src/solver/hydro/daily/h2o_j_fonctions.h +++ b/src/solver/hydro/daily/h2o_j_fonctions.h @@ -28,7 +28,7 @@ #ifndef __SOLVER_H2O_J_FONCTIONS__ #define __SOLVER_H2O_J_FONCTIONS__ -DONNEES_MENSUELLES H2O_J_Instanciation(void); +DONNEES_MENSUELLES* H2O_J_Instanciation(void); void H2O_J_OptimiserUnMois(DONNEES_MENSUELLES*); void H2O_J_Free(DONNEES_MENSUELLES*); diff --git a/src/solver/hydro/daily/h2o_j_instanciation.cpp b/src/solver/hydro/daily/h2o_j_instanciation.cpp index fa0ecf5fa7..4824e7a545 100644 --- a/src/solver/hydro/daily/h2o_j_instanciation.cpp +++ b/src/solver/hydro/daily/h2o_j_instanciation.cpp @@ -28,11 +28,11 @@ #include "h2o_j_donnees_mensuelles.h" #include "h2o_j_fonctions.h" -DONNEES_MENSUELLES H2O_J_Instanciation(void) +DONNEES_MENSUELLES* H2O_J_Instanciation(void) { - DONNEES_MENSUELLES DonneesMensuelles; + DONNEES_MENSUELLES* DonneesMensuelles = new DONNEES_MENSUELLES;; - PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesMensuelles.ProblemeHydraulique; + PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesMensuelles->ProblemeHydraulique; ProblemeHydraulique.NombreDeProblemes = 4; @@ -44,10 +44,10 @@ DONNEES_MENSUELLES H2O_J_Instanciation(void) NbJoursDUnProbleme[2] = 30; NbJoursDUnProbleme[3] = 31; - DonneesMensuelles.TurbineMax.assign(NbJoursDUnProbleme[3], 0.); - DonneesMensuelles.TurbineMin.assign(NbJoursDUnProbleme[3], 0.); - DonneesMensuelles.TurbineCible.assign(NbJoursDUnProbleme[3], 0.); - DonneesMensuelles.Turbine.assign(NbJoursDUnProbleme[3], 0.); + DonneesMensuelles->TurbineMax.assign(NbJoursDUnProbleme[3], 0.); + DonneesMensuelles->TurbineMin.assign(NbJoursDUnProbleme[3], 0.); + DonneesMensuelles->TurbineCible.assign(NbJoursDUnProbleme[3], 0.); + DonneesMensuelles->Turbine.assign(NbJoursDUnProbleme[3], 0.); int NombreDeProblemes = ProblemeHydraulique.NombreDeProblemes; diff --git a/src/solver/hydro/management/daily.cpp b/src/solver/hydro/management/daily.cpp index 3650be78e1..25aa8116e4 100644 --- a/src/solver/hydro/management/daily.cpp +++ b/src/solver/hydro/management/daily.cpp @@ -391,7 +391,7 @@ inline void HydroManagement::prepareDailyOptimalGenerations(Solver::Variable::St uint firstDay = study.calendar.months[simulationMonth].daysYear.first; uint endDay = firstDay + daysPerMonth; - DONNEES_MENSUELLES problem = H2O_J_Instanciation(); + DONNEES_MENSUELLES& problem = *H2O_J_Instanciation(); H2O_J_AjouterBruitAuCout(problem); problem.NombreDeJoursDuMois = (int)daysPerMonth; problem.TurbineDuMois = data.MOG[realmonth]; From 739bdcd9561a22934d0b6da47c5a604f02f48b31 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Mon, 18 Sep 2023 10:46:05 +0200 Subject: [PATCH 20/42] [DEV] Var scope in hydro/monthly --- .../h2o_m_construire_les_contraintes.cpp | 28 ++++--------- .../h2o_m_construire_les_variables.cpp | 26 +++++------- src/solver/hydro/monthly/h2o_m_free.cpp | 7 +--- ...m_initialiser_les_bornes_des_variables.cpp | 4 +- .../hydro/monthly/h2o_m_instanciation.cpp | 16 ++------ .../monthly/h2o_m_optimiser_une_annee.cpp | 3 -- .../h2o_m_resoudre_le_probleme_lineaire.cpp | 41 +++++++------------ 7 files changed, 41 insertions(+), 84 deletions(-) diff --git a/src/solver/hydro/monthly/h2o_m_construire_les_contraintes.cpp b/src/solver/hydro/monthly/h2o_m_construire_les_contraintes.cpp index 8e451e98fd..9c1ef5062a 100644 --- a/src/solver/hydro/monthly/h2o_m_construire_les_contraintes.cpp +++ b/src/solver/hydro/monthly/h2o_m_construire_les_contraintes.cpp @@ -30,18 +30,6 @@ void H2O_M_ConstruireLesContraintes(DONNEES_ANNUELLES& DonneesAnnuelles) { - int NombreDeContraintes; - int il; - int Pdt; - int NbPdt; - double ChgmtSens; - int NumeroDeLaVariableXi; - - - ChgmtSens = -1.0; - - NbPdt = DonneesAnnuelles.NombreDePasDeTemps; - PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesAnnuelles.ProblemeHydraulique; CORRESPONDANCE_DES_VARIABLES& CorrespondanceDesVariables = ProblemeHydraulique.CorrespondanceDesVariables; @@ -65,12 +53,14 @@ void H2O_M_ConstruireLesContraintes(DONNEES_ANNUELLES& DonneesAnnuelles) = CorrespondanceDesVariables.NumeroDeVariableDEcartPositifAuTurbineCible; auto& NumeroDeVariableDEcartNegatifAuTurbineCible = CorrespondanceDesVariables.NumeroDeVariableDEcartNegatifAuTurbineCible; - NumeroDeLaVariableXi = CorrespondanceDesVariables.NumeroDeLaVariableXi; + int NumeroDeLaVariableXi = CorrespondanceDesVariables.NumeroDeLaVariableXi; - NombreDeContraintes = 0; - il = 0; + double ChgmtSens = -1.0; + int NbPdt = DonneesAnnuelles.NombreDePasDeTemps; + int NombreDeContraintes = 0; + int il = 0; - for (Pdt = 1; Pdt < NbPdt; Pdt++) + for (int Pdt = 1; Pdt < NbPdt; Pdt++) { IndicesDebutDeLigne[NombreDeContraintes] = il; @@ -105,7 +95,7 @@ void H2O_M_ConstruireLesContraintes(DONNEES_ANNUELLES& DonneesAnnuelles) NombreDeTermesDesLignes[NombreDeContraintes] = 2; NombreDeContraintes++; - for (Pdt = 1; Pdt < NbPdt; Pdt++) + for (int Pdt = 1; Pdt < NbPdt; Pdt++) { IndicesDebutDeLigne[NombreDeContraintes] = il; @@ -136,7 +126,7 @@ void H2O_M_ConstruireLesContraintes(DONNEES_ANNUELLES& DonneesAnnuelles) NombreDeContraintes++; } - for (Pdt = 1; Pdt < NbPdt; Pdt++) + for (int Pdt = 1; Pdt < NbPdt; Pdt++) { IndicesDebutDeLigne[NombreDeContraintes] = il; @@ -153,7 +143,7 @@ void H2O_M_ConstruireLesContraintes(DONNEES_ANNUELLES& DonneesAnnuelles) NombreDeContraintes++; } - for (Pdt = 0; Pdt < NbPdt; Pdt++) + for (int Pdt = 0; Pdt < NbPdt; Pdt++) { IndicesDebutDeLigne[NombreDeContraintes] = il; diff --git a/src/solver/hydro/monthly/h2o_m_construire_les_variables.cpp b/src/solver/hydro/monthly/h2o_m_construire_les_variables.cpp index fcac3ad2bf..7895f43a80 100644 --- a/src/solver/hydro/monthly/h2o_m_construire_les_variables.cpp +++ b/src/solver/hydro/monthly/h2o_m_construire_les_variables.cpp @@ -41,9 +41,6 @@ extern "C" void H2O_M_ConstruireLesVariables(DONNEES_ANNUELLES& DonneesAnnuelles) { - int Var; - int Pdt; - int NbPdt; PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesAnnuelles.ProblemeHydraulique; PROBLEME_LINEAIRE_PARTIE_VARIABLE& ProblemeLineairePartieVariable = ProblemeHydraulique.ProblemeLineairePartieVariable; @@ -52,21 +49,18 @@ void H2O_M_ConstruireLesVariables(DONNEES_ANNUELLES& DonneesAnnuelles) CORRESPONDANCE_DES_VARIABLES& CorrespondanceDesVariables = ProblemeHydraulique.CorrespondanceDesVariables; - NbPdt = DonneesAnnuelles.NombreDePasDeTemps; + int NbPdt = DonneesAnnuelles.NombreDePasDeTemps; + int Var = 0; - - Var = 0; - - Pdt = 0; - CorrespondanceDesVariables.NumeroDeVariableVolume[Pdt] = Var; + CorrespondanceDesVariables.NumeroDeVariableVolume[0] = Var; ProblemeLineairePartieVariable.Xmin[Var] = 0.0; ProblemeLineairePartieVariable.Xmax[Var] = 1.0; ProblemeLineairePartieFixe.TypeDeVariable[Var] = VARIABLE_BORNEE_DES_DEUX_COTES; ProblemeLineairePartieVariable.AdresseOuPlacerLaValeurDesVariablesOptimisees[Var] - = &(DonneesAnnuelles.Volume[Pdt]); + = &(DonneesAnnuelles.Volume[0]); Var++; - for (Pdt = 1; Pdt < NbPdt; Pdt++) + for (int Pdt = 1; Pdt < NbPdt; Pdt++) { CorrespondanceDesVariables.NumeroDeVariableVolume[Pdt] = Var; ProblemeLineairePartieVariable.Xmin[Var] = 0.0; @@ -77,7 +71,7 @@ void H2O_M_ConstruireLesVariables(DONNEES_ANNUELLES& DonneesAnnuelles) Var++; } - for (Pdt = 0; Pdt < NbPdt; Pdt++) + for (int Pdt = 0; Pdt < NbPdt; Pdt++) { CorrespondanceDesVariables.NumeroDeVariableTurbine[Pdt] = Var; ProblemeLineairePartieVariable.Xmin[Var] = 0.0; @@ -88,7 +82,7 @@ void H2O_M_ConstruireLesVariables(DONNEES_ANNUELLES& DonneesAnnuelles) Var++; } - for (Pdt = 0; Pdt < NbPdt; Pdt++) + for (int Pdt = 0; Pdt < NbPdt; Pdt++) { CorrespondanceDesVariables.NumeroDeVariableDepassementVolumeMax[Pdt] = Var; ProblemeLineairePartieVariable.Xmin[Var] = 0.0; @@ -97,7 +91,7 @@ void H2O_M_ConstruireLesVariables(DONNEES_ANNUELLES& DonneesAnnuelles) Var++; } - for (Pdt = 0; Pdt < NbPdt; Pdt++) + for (int Pdt = 0; Pdt < NbPdt; Pdt++) { CorrespondanceDesVariables.NumeroDeVariableDepassementVolumeMin[Pdt] = Var; ProblemeLineairePartieVariable.Xmin[Var] = 0.0; @@ -112,7 +106,7 @@ void H2O_M_ConstruireLesVariables(DONNEES_ANNUELLES& DonneesAnnuelles) ProblemeLineairePartieFixe.TypeDeVariable[Var] = VARIABLE_BORNEE_INFERIEUREMENT; Var++; - for (Pdt = 0; Pdt < NbPdt; Pdt++) + for (int Pdt = 0; Pdt < NbPdt; Pdt++) { CorrespondanceDesVariables.NumeroDeVariableDEcartPositifAuTurbineCible[Pdt] = Var; ProblemeLineairePartieVariable.Xmin[Var] = 0.0; @@ -121,7 +115,7 @@ void H2O_M_ConstruireLesVariables(DONNEES_ANNUELLES& DonneesAnnuelles) Var++; } - for (Pdt = 0; Pdt < NbPdt; Pdt++) + for (int Pdt = 0; Pdt < NbPdt; Pdt++) { CorrespondanceDesVariables.NumeroDeVariableDEcartNegatifAuTurbineCible[Pdt] = Var; ProblemeLineairePartieVariable.Xmin[Var] = 0.0; diff --git a/src/solver/hydro/monthly/h2o_m_free.cpp b/src/solver/hydro/monthly/h2o_m_free.cpp index 03746b1db2..b4f917abc5 100644 --- a/src/solver/hydro/monthly/h2o_m_free.cpp +++ b/src/solver/hydro/monthly/h2o_m_free.cpp @@ -42,17 +42,14 @@ extern "C" void H2O_M_Free(DONNEES_ANNUELLES& DonneesAnnuelles) { - PROBLEME_SPX* ProbSpx; PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesAnnuelles.ProblemeHydraulique; for (int i = 0; i < ProblemeHydraulique.NombreDeReservoirs; i++) { - ProbSpx = (PROBLEME_SPX*)ProblemeHydraulique.ProblemeSpx[i]; - if (ProbSpx != NULL) - { + PROBLEME_SPX* ProbSpx = (PROBLEME_SPX*)ProblemeHydraulique.ProblemeSpx[i]; + if (ProbSpx) SPX_LibererProbleme(ProbSpx); - } } free(ProblemeHydraulique.Probleme); diff --git a/src/solver/hydro/monthly/h2o_m_initialiser_les_bornes_des_variables.cpp b/src/solver/hydro/monthly/h2o_m_initialiser_les_bornes_des_variables.cpp index 545382165b..05157e3d4a 100644 --- a/src/solver/hydro/monthly/h2o_m_initialiser_les_bornes_des_variables.cpp +++ b/src/solver/hydro/monthly/h2o_m_initialiser_les_bornes_des_variables.cpp @@ -30,8 +30,6 @@ void H2O_M_InitialiserBornesEtCoutsDesVariables(DONNEES_ANNUELLES& DonneesAnnuelles) { - int Var; - PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesAnnuelles.ProblemeHydraulique; PROBLEME_LINEAIRE_PARTIE_VARIABLE& ProblemeLineairePartieVariable = ProblemeHydraulique.ProblemeLineairePartieVariable; @@ -53,7 +51,7 @@ void H2O_M_InitialiserBornesEtCoutsDesVariables(DONNEES_ANNUELLES& DonneesAnnuel auto& X = ProblemeLineairePartieVariable.X; auto& CoutLineaire = ProblemeLineairePartieFixe.CoutLineaire; - Var = CorrespondanceDesVariables.NumeroDeVariableVolume[0]; + int Var = CorrespondanceDesVariables.NumeroDeVariableVolume[0]; X[Var] = DonneesAnnuelles.Volume[0]; Xmin[Var] = DonneesAnnuelles.Volume[0]; Xmax[Var] = DonneesAnnuelles.Volume[0]; diff --git a/src/solver/hydro/monthly/h2o_m_instanciation.cpp b/src/solver/hydro/monthly/h2o_m_instanciation.cpp index c44a5a6775..47f0191197 100644 --- a/src/solver/hydro/monthly/h2o_m_instanciation.cpp +++ b/src/solver/hydro/monthly/h2o_m_instanciation.cpp @@ -30,17 +30,10 @@ DONNEES_ANNUELLES H2O_M_Instanciation(int NombreDeReservoirs) { - int i; - int NbPdt; - int j; - int NombreDeVariables; - int NombreDeContraintes; - int NombreDeTermesAlloues; DONNEES_ANNUELLES DonneesAnnuelles{}; DonneesAnnuelles.NombreDePasDeTemps = 12; - - NbPdt = DonneesAnnuelles.NombreDePasDeTemps; + int NbPdt = DonneesAnnuelles.NombreDePasDeTemps; DonneesAnnuelles.TurbineMax.assign(NbPdt, 0.); DonneesAnnuelles.TurbineMin.assign(NbPdt, 0.); @@ -58,7 +51,6 @@ DONNEES_ANNUELLES H2O_M_Instanciation(int NombreDeReservoirs) ProblemeHydraulique.NombreDeReservoirs = NombreDeReservoirs; ProblemeHydraulique.ProblemeSpx.assign(NombreDeReservoirs, nullptr); - ProblemeHydraulique.Probleme = nullptr; CORRESPONDANCE_DES_VARIABLES& CorrespondanceDesVariables @@ -75,7 +67,7 @@ DONNEES_ANNUELLES H2O_M_Instanciation(int NombreDeReservoirs) CorrespondanceDesVariables.NumeroDeVariableDEcartPositifAuTurbineCible.assign(NbPdt, 0); CorrespondanceDesVariables.NumeroDeVariableDEcartNegatifAuTurbineCible.assign(NbPdt, 0); - NombreDeVariables = 0; + int NombreDeVariables = 0; NombreDeVariables += NbPdt; NombreDeVariables += NbPdt; NombreDeVariables += NbPdt; @@ -92,7 +84,7 @@ DONNEES_ANNUELLES H2O_M_Instanciation(int NombreDeReservoirs) ProblemeLineairePartieFixe.TypeDeVariable.assign(NombreDeVariables, 0); - NombreDeContraintes = 0; + int NombreDeContraintes = 0; NombreDeContraintes += NbPdt; NombreDeContraintes += 1; NombreDeContraintes += NbPdt; @@ -107,7 +99,7 @@ DONNEES_ANNUELLES H2O_M_Instanciation(int NombreDeReservoirs) ProblemeLineairePartieFixe.IndicesDebutDeLigne.assign(NombreDeContraintes, 0); ProblemeLineairePartieFixe.NombreDeTermesDesLignes.assign(NombreDeContraintes, 0); - NombreDeTermesAlloues = 0; + int NombreDeTermesAlloues = 0; NombreDeTermesAlloues += 3 * NbPdt; NombreDeTermesAlloues += 2; NombreDeTermesAlloues += 2 * NbPdt; diff --git a/src/solver/hydro/monthly/h2o_m_optimiser_une_annee.cpp b/src/solver/hydro/monthly/h2o_m_optimiser_une_annee.cpp index ea717851d5..caa489b5d3 100644 --- a/src/solver/hydro/monthly/h2o_m_optimiser_une_annee.cpp +++ b/src/solver/hydro/monthly/h2o_m_optimiser_une_annee.cpp @@ -41,11 +41,8 @@ void H2O_M_OptimiserUneAnnee(DONNEES_ANNUELLES& DonneesAnnuelles, int NumeroDeRe DonneesAnnuelles.ResultatsValides = NON; H2O_M_InitialiserBornesEtCoutsDesVariables(DonneesAnnuelles); - H2O_M_AjouterBruitAuCout(DonneesAnnuelles); - H2O_M_InitialiserLeSecondMembre(DonneesAnnuelles); - H2O_M_ResoudreLeProblemeLineaire(DonneesAnnuelles, NumeroDeReservoir); return; diff --git a/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp b/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp index 6214eb2a75..efbb01bc3e 100644 --- a/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp +++ b/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp @@ -48,30 +48,21 @@ extern "C" void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES& DonneesAnnuelles, int NumeroDeReservoir) { - int Var; - double* pt; - char PremierPassage; - PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesAnnuelles.ProblemeHydraulique; PROBLEME_LINEAIRE_PARTIE_VARIABLE& ProblemeLineairePartieVariable = ProblemeHydraulique.ProblemeLineairePartieVariable; PROBLEME_LINEAIRE_PARTIE_FIXE& ProblemeLineairePartieFixe = ProblemeHydraulique.ProblemeLineairePartieFixe; - PROBLEME_SIMPLEXE* Probleme; - PROBLEME_SPX* ProbSpx; - - PremierPassage = OUI; - + char PremierPassage = OUI; + PROBLEME_SPX* ProbSpx = (PROBLEME_SPX*)ProblemeHydraulique.ProblemeSpx[NumeroDeReservoir]; + PROBLEME_SIMPLEXE* Probleme = (PROBLEME_SIMPLEXE*)ProblemeHydraulique.Probleme; - ProbSpx = (PROBLEME_SPX*)ProblemeHydraulique.ProblemeSpx[NumeroDeReservoir]; - - Probleme = (PROBLEME_SIMPLEXE*)ProblemeHydraulique.Probleme; - if (Probleme == NULL) + if (!Probleme) { Probleme = (PROBLEME_SIMPLEXE*)malloc(sizeof(PROBLEME_SIMPLEXE)); - if (Probleme == NULL) + if (!Probleme) { DonneesAnnuelles.ResultatsValides = EMERGENCY_SHUT_DOWN; return; @@ -81,7 +72,7 @@ void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES& DonneesAnnuelles, int N RESOLUTION: - if (ProbSpx == NULL) + if (!ProbSpx) { Probleme->Contexte = SIMPLEXE_SEUL; Probleme->BaseDeDepartFournie = NON_SPX; @@ -149,10 +140,8 @@ void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES& DonneesAnnuelles, int N ProbSpx = SPX_Simplexe(Probleme, ProbSpx); - if (ProbSpx != NULL) - { + if (ProbSpx) ProblemeHydraulique.ProblemeSpx[NumeroDeReservoir] = (void*)ProbSpx; - } ProblemeLineairePartieVariable.ExistenceDUneSolution = Probleme->ExistenceDUneSolution; @@ -177,26 +166,26 @@ void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES& DonneesAnnuelles, int N if (ProblemeLineairePartieVariable.ExistenceDUneSolution == OUI_SPX) { ProblemeHydraulique.CoutDeLaSolution = 0.0; - for (Var = 0; Var < Probleme->NombreDeVariables; Var++) + for (int i = 0; i < Probleme->NombreDeVariables; i++) { ProblemeHydraulique.CoutDeLaSolution - += ProblemeLineairePartieFixe.CoutLineaire[Var] * Probleme->X[Var]; + += ProblemeLineairePartieFixe.CoutLineaire[i] * Probleme->X[i]; } ProblemeHydraulique.CoutDeLaSolutionBruite = 0.0; - for (Var = 0; Var < Probleme->NombreDeVariables; Var++) + for (int i = 0; i < Probleme->NombreDeVariables; i++) { ProblemeHydraulique.CoutDeLaSolutionBruite - += ProblemeLineairePartieFixe.CoutLineaireBruite[Var] * Probleme->X[Var]; + += ProblemeLineairePartieFixe.CoutLineaireBruite[i] * Probleme->X[i]; } DonneesAnnuelles.ResultatsValides = OUI; - for (Var = 0; Var < ProblemeLineairePartieFixe.NombreDeVariables; Var++) + for (int i = 0; i < ProblemeLineairePartieFixe.NombreDeVariables; i++) { - pt = ProblemeLineairePartieVariable.AdresseOuPlacerLaValeurDesVariablesOptimisees[Var]; - if (pt != NULL) - *pt = ProblemeLineairePartieVariable.X[Var]; + double* pt = ProblemeLineairePartieVariable.AdresseOuPlacerLaValeurDesVariablesOptimisees[i]; + if (pt) + *pt = ProblemeLineairePartieVariable.X[i]; } } else From 05932f31cf3a61334a4d4166141bb5339315cfef Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Mon, 18 Sep 2023 10:52:48 +0200 Subject: [PATCH 21/42] [DEV] Var scope in hydro/daily --- .../h2o_j_construire_les_contraintes.cpp | 15 +++---- .../daily/h2o_j_construire_les_variables.cpp | 7 +-- ...j_initialiser_les_bornes_des_variables.cpp | 8 +--- .../h2o_j_initialiser_les_second_membre.cpp | 15 ++----- .../daily/h2o_j_lisser_les_sur_turbines.cpp | 45 +++++++------------ .../hydro/daily/h2o_j_optimiser_un_mois.cpp | 10 +---- .../h2o_j_resoudre_le_probleme_lineaire.cpp | 34 +++++--------- 7 files changed, 43 insertions(+), 91 deletions(-) diff --git a/src/solver/hydro/daily/h2o_j_construire_les_contraintes.cpp b/src/solver/hydro/daily/h2o_j_construire_les_contraintes.cpp index 51c2c94277..fbb3cad8ce 100644 --- a/src/solver/hydro/daily/h2o_j_construire_les_contraintes.cpp +++ b/src/solver/hydro/daily/h2o_j_construire_les_contraintes.cpp @@ -39,17 +39,12 @@ void H2O_J_ConstruireLesContraintes(int NbPdt, std::vector& IndicesColonnes, CORRESPONDANCE_DES_CONTRAINTES& CorrespondanceDesContraintes) { - int NombreDeContraintes; - int il; - int Pdt; - int NombreDeTermes; + int NombreDeContraintes = 0; + int NombreDeTermes = 0; + int il = 0; - NombreDeContraintes = 0; - il = 0; - - NombreDeTermes = 0; IndicesDebutDeLigne[NombreDeContraintes] = il; - for (Pdt = 0; Pdt < NbPdt; Pdt++) + for (int Pdt = 0; Pdt < NbPdt; Pdt++) { CoefficientsDeLaMatriceDesContraintes[il] = 1.0; IndicesColonnes[il] = NumeroDeVariableTurbine[Pdt]; @@ -67,7 +62,7 @@ void H2O_J_ConstruireLesContraintes(int NbPdt, CorrespondanceDesContraintes.NumeroDeContrainteDEnergieMensuelle = NombreDeContraintes; NombreDeContraintes++; - for (Pdt = 0; Pdt < NbPdt; Pdt++) + for (int Pdt = 0; Pdt < NbPdt; Pdt++) { NombreDeTermes = 0; IndicesDebutDeLigne[NombreDeContraintes] = il; diff --git a/src/solver/hydro/daily/h2o_j_construire_les_variables.cpp b/src/solver/hydro/daily/h2o_j_construire_les_variables.cpp index 888a7e151a..cca46ab312 100644 --- a/src/solver/hydro/daily/h2o_j_construire_les_variables.cpp +++ b/src/solver/hydro/daily/h2o_j_construire_les_variables.cpp @@ -47,12 +47,9 @@ void H2O_j_ConstruireLesVariables(int NbPdt, std::vector& AdresseOuPlacerLaValeurDesVariablesOptimisees, CORRESPONDANCE_DES_VARIABLES& CorrespondanceDesVariables) { - int Var; - int Pdt; + int Var = 0; - Var = 0; - - for (Pdt = 0; Pdt < NbPdt; Pdt++) + for (int Pdt = 0; Pdt < NbPdt; Pdt++) { NumeroDeVariableTurbine[Pdt] = Var; Xmin[Var] = 0.0; diff --git a/src/solver/hydro/daily/h2o_j_initialiser_les_bornes_des_variables.cpp b/src/solver/hydro/daily/h2o_j_initialiser_les_bornes_des_variables.cpp index 48d0c46b39..a69f5c3e57 100644 --- a/src/solver/hydro/daily/h2o_j_initialiser_les_bornes_des_variables.cpp +++ b/src/solver/hydro/daily/h2o_j_initialiser_les_bornes_des_variables.cpp @@ -32,10 +32,6 @@ void H2O_J_InitialiserLesBornesdesVariables(DONNEES_MENSUELLES* DonneesMensuelles, int NumeroDeProbleme) { - int NbPdt; - int Var; - - const std::vector& TurbineMax = DonneesMensuelles->TurbineMax; const std::vector& TurbineMin = DonneesMensuelles->TurbineMin; const std::vector& TurbineCible = DonneesMensuelles->TurbineCible; @@ -43,7 +39,7 @@ void H2O_J_InitialiserLesBornesdesVariables(DONNEES_MENSUELLES* DonneesMensuelle PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesMensuelles->ProblemeHydraulique; - NbPdt = ProblemeHydraulique.NbJoursDUnProbleme[NumeroDeProbleme]; + int NbPdt = ProblemeHydraulique.NbJoursDUnProbleme[NumeroDeProbleme]; const CORRESPONDANCE_DES_VARIABLES& CorrespondanceDesVariables = ProblemeHydraulique.CorrespondanceDesVariables[NumeroDeProbleme]; @@ -58,7 +54,7 @@ void H2O_J_InitialiserLesBornesdesVariables(DONNEES_MENSUELLES* DonneesMensuelle for (int Pdt = 0; Pdt < NbPdt; Pdt++) { - Var = CorrespondanceDesVariables.NumeroDeVariableTurbine[Pdt]; + int Var = CorrespondanceDesVariables.NumeroDeVariableTurbine[Pdt]; Xmax[Var] = TurbineMax[Pdt]; Xmin[Var] = std::min(TurbineMax[Pdt], std::max(TurbineCible[Pdt], TurbineMin[Pdt])); diff --git a/src/solver/hydro/daily/h2o_j_initialiser_les_second_membre.cpp b/src/solver/hydro/daily/h2o_j_initialiser_les_second_membre.cpp index 61d3bb2393..ca63a40004 100644 --- a/src/solver/hydro/daily/h2o_j_initialiser_les_second_membre.cpp +++ b/src/solver/hydro/daily/h2o_j_initialiser_les_second_membre.cpp @@ -30,20 +30,12 @@ void H2O_J_InitialiserLeSecondMembre(DONNEES_MENSUELLES* DonneesMensuelles, int NumeroDeProbleme) { - int Pdt; - int Cnt; - int NbPdt; - - int NumeroDeContrainteDEnergieMensuelle; - PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesMensuelles->ProblemeHydraulique; - NbPdt = ProblemeHydraulique.NbJoursDUnProbleme[NumeroDeProbleme]; - CORRESPONDANCE_DES_CONTRAINTES& CorrespondanceDesContraintes = ProblemeHydraulique.CorrespondanceDesContraintes[NumeroDeProbleme]; - NumeroDeContrainteDEnergieMensuelle + int NumeroDeContrainteDEnergieMensuelle = CorrespondanceDesContraintes.NumeroDeContrainteDEnergieMensuelle; std::vector& SecondMembre @@ -51,9 +43,10 @@ void H2O_J_InitialiserLeSecondMembre(DONNEES_MENSUELLES* DonneesMensuelles, int SecondMembre[NumeroDeContrainteDEnergieMensuelle] = DonneesMensuelles->TurbineDuMois; - for (Pdt = 0; Pdt < NbPdt; Pdt++) + int NbPdt = ProblemeHydraulique.NbJoursDUnProbleme[NumeroDeProbleme]; + for (int Pdt = 0; Pdt < NbPdt; Pdt++) { - Cnt = CorrespondanceDesContraintes.NumeroDeContrainteSurXi[Pdt]; + int Cnt = CorrespondanceDesContraintes.NumeroDeContrainteSurXi[Pdt]; SecondMembre[Cnt] = DonneesMensuelles->TurbineCible[Pdt]; } diff --git a/src/solver/hydro/daily/h2o_j_lisser_les_sur_turbines.cpp b/src/solver/hydro/daily/h2o_j_lisser_les_sur_turbines.cpp index 463d9b6ec4..94ab01b71a 100644 --- a/src/solver/hydro/daily/h2o_j_lisser_les_sur_turbines.cpp +++ b/src/solver/hydro/daily/h2o_j_lisser_les_sur_turbines.cpp @@ -32,55 +32,43 @@ void H2O_J_LisserLesSurTurbines(DONNEES_MENSUELLES* DonneesMensuelles, int NumeroDeProbleme) { - int Pdt; - int Cnt; - int NbPdt; - double X; - int Np; - char* Flag; - char LimiteAtteinte; - int NbCycles; - double SurTurbineARepartir; - double Xmoy; - double MargeMin; - double SurTurbine; PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesMensuelles->ProblemeHydraulique; std::vector& TurbineMax = DonneesMensuelles->TurbineMax; std::vector& Turbine = DonneesMensuelles->Turbine; std::vector& TurbineCible = DonneesMensuelles->TurbineCible; - Flag = (char*) ProblemeHydraulique.ProblemeLineairePartieVariable[NumeroDeProbleme].Xmax.data(); + char* Flag = (char*) ProblemeHydraulique.ProblemeLineairePartieVariable[NumeroDeProbleme].Xmax.data(); - NbPdt = ProblemeHydraulique.NbJoursDUnProbleme[NumeroDeProbleme]; + int NbPdt = ProblemeHydraulique.NbJoursDUnProbleme[NumeroDeProbleme]; - SurTurbineARepartir = 0.0; - for (Pdt = 0; Pdt < NbPdt; Pdt++) + double SurTurbineARepartir = 0.0; + for (int Pdt = 0; Pdt < NbPdt; Pdt++) { Flag[Pdt] = 0; if (Turbine[Pdt] - TurbineCible[Pdt] > ZERO) Flag[Pdt] = 1; } - for (Pdt = 0; Pdt < NbPdt; Pdt++) + for (int Pdt = 0; Pdt < NbPdt; Pdt++) { if (Flag[Pdt] == 1) SurTurbineARepartir += Turbine[Pdt] - TurbineCible[Pdt]; } - for (Pdt = 0; Pdt < NbPdt; Pdt++) + for (int Pdt = 0; Pdt < NbPdt; Pdt++) Flag[Pdt] = 0; - for (Pdt = 0; Pdt < NbPdt; Pdt++) + for (int Pdt = 0; Pdt < NbPdt; Pdt++) { if (TurbineMax[Pdt] - TurbineCible[Pdt] > ZERO) Flag[Pdt] = 1; } - NbCycles = 0; + int NbCycles = 0; BoucleDeRepartition: - Np = 0; - for (Pdt = 0; Pdt < NbPdt; Pdt++) + int Np = 0; + for (int Pdt = 0; Pdt < NbPdt; Pdt++) { if (Flag[Pdt] == 1) Np++; @@ -90,10 +78,10 @@ void H2O_J_LisserLesSurTurbines(DONNEES_MENSUELLES* DonneesMensuelles, int Numer return; } - MargeMin = 0.; - for (Pdt = 0; Pdt < NbPdt; Pdt++) + double MargeMin = 0.; + for (int Pdt = 0; Pdt < NbPdt; Pdt++) MargeMin += TurbineMax[Pdt]; - for (Pdt = 0; Pdt < NbPdt; Pdt++) + for (int Pdt = 0; Pdt < NbPdt; Pdt++) { if (Flag[Pdt] == 1) { @@ -102,14 +90,15 @@ void H2O_J_LisserLesSurTurbines(DONNEES_MENSUELLES* DonneesMensuelles, int Numer } } - Xmoy = SurTurbineARepartir / Np; + double Xmoy = SurTurbineARepartir / Np; + double SurTurbine; if (Xmoy <= MargeMin) SurTurbine = Xmoy; else SurTurbine = MargeMin; - LimiteAtteinte = 0; - for (Pdt = 0; Pdt < NbPdt; Pdt++) + char LimiteAtteinte = 0; + for (int Pdt = 0; Pdt < NbPdt; Pdt++) { if (Flag[Pdt] == 0) continue; diff --git a/src/solver/hydro/daily/h2o_j_optimiser_un_mois.cpp b/src/solver/hydro/daily/h2o_j_optimiser_un_mois.cpp index 050e2ea7f0..73caf5b7cf 100644 --- a/src/solver/hydro/daily/h2o_j_optimiser_un_mois.cpp +++ b/src/solver/hydro/daily/h2o_j_optimiser_un_mois.cpp @@ -30,13 +30,10 @@ void H2O_J_OptimiserUnMois(DONNEES_MENSUELLES* DonneesMensuelles) { - int NumeroDeProbleme; - int i; - PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesMensuelles->ProblemeHydraulique; - NumeroDeProbleme = -1; - for (i = 0; i < ProblemeHydraulique.NombreDeProblemes; i++) + int NumeroDeProbleme = -1; + for (int i = 0; i < ProblemeHydraulique.NombreDeProblemes; i++) { if (DonneesMensuelles->NombreDeJoursDuMois == ProblemeHydraulique.NbJoursDUnProbleme[i]) { @@ -53,11 +50,8 @@ void H2O_J_OptimiserUnMois(DONNEES_MENSUELLES* DonneesMensuelles) DonneesMensuelles->ResultatsValides = NON; H2O_J_InitialiserLeSecondMembre(DonneesMensuelles, NumeroDeProbleme); - H2O_J_InitialiserLesBornesdesVariables(DonneesMensuelles, NumeroDeProbleme); - H2O_J_ResoudreLeProblemeLineaire(DonneesMensuelles, NumeroDeProbleme); - H2O_J_LisserLesSurTurbines(DonneesMensuelles, NumeroDeProbleme); return; diff --git a/src/solver/hydro/daily/h2o_j_resoudre_le_probleme_lineaire.cpp b/src/solver/hydro/daily/h2o_j_resoudre_le_probleme_lineaire.cpp index 517ec9203c..6fb3082e74 100644 --- a/src/solver/hydro/daily/h2o_j_resoudre_le_probleme_lineaire.cpp +++ b/src/solver/hydro/daily/h2o_j_resoudre_le_probleme_lineaire.cpp @@ -48,16 +48,6 @@ extern "C" void H2O_J_ResoudreLeProblemeLineaire(DONNEES_MENSUELLES* DonneesMensuelles, int NumeroDeProbleme) { - int Var; - double* pt; - char PremierPassage; - - - PROBLEME_SIMPLEXE* Probleme; - PROBLEME_SPX* ProbSpx; - - PremierPassage = OUI; - PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesMensuelles->ProblemeHydraulique; PROBLEME_LINEAIRE_PARTIE_VARIABLE& ProblemeLineairePartieVariable @@ -66,13 +56,13 @@ void H2O_J_ResoudreLeProblemeLineaire(DONNEES_MENSUELLES* DonneesMensuelles, int PROBLEME_LINEAIRE_PARTIE_FIXE& ProblemeLineairePartieFixe = ProblemeHydraulique.ProblemeLineairePartieFixe[NumeroDeProbleme]; - ProbSpx = (PROBLEME_SPX*)ProblemeHydraulique.ProblemeSpx[NumeroDeProbleme]; + PROBLEME_SPX* ProbSpx = (PROBLEME_SPX*)ProblemeHydraulique.ProblemeSpx[NumeroDeProbleme]; + PROBLEME_SIMPLEXE* Probleme = (PROBLEME_SIMPLEXE*)ProblemeHydraulique.Probleme; - Probleme = (PROBLEME_SIMPLEXE*)ProblemeHydraulique.Probleme; - if (Probleme == NULL) + if (!Probleme) { Probleme = (PROBLEME_SIMPLEXE*)malloc(sizeof(PROBLEME_SIMPLEXE)); - if (Probleme == NULL) + if (!Probleme) { DonneesMensuelles->ResultatsValides = EMERGENCY_SHUT_DOWN; return; @@ -80,9 +70,11 @@ void H2O_J_ResoudreLeProblemeLineaire(DONNEES_MENSUELLES* DonneesMensuelles, int ProblemeHydraulique.Probleme = (void*)Probleme; } + char PremierPassage = OUI; + RESOLUTION: - if (ProbSpx == NULL) + if (!ProbSpx) { Probleme->Contexte = SIMPLEXE_SEUL; Probleme->BaseDeDepartFournie = NON_SPX; @@ -150,10 +142,8 @@ void H2O_J_ResoudreLeProblemeLineaire(DONNEES_MENSUELLES* DonneesMensuelles, int ProbSpx = SPX_Simplexe(Probleme, ProbSpx); - if (ProbSpx != NULL) - { + if (ProbSpx) ProblemeHydraulique.ProblemeSpx[NumeroDeProbleme] = (void*)ProbSpx; - } ProblemeLineairePartieVariable.ExistenceDUneSolution = Probleme->ExistenceDUneSolution; @@ -179,13 +169,11 @@ void H2O_J_ResoudreLeProblemeLineaire(DONNEES_MENSUELLES* DonneesMensuelles, int { DonneesMensuelles->ResultatsValides = OUI; - for (Var = 0; Var < ProblemeLineairePartieFixe.NombreDeVariables; Var++) + for (int Var = 0; Var < ProblemeLineairePartieFixe.NombreDeVariables; Var++) { - pt = ProblemeLineairePartieVariable.AdresseOuPlacerLaValeurDesVariablesOptimisees[Var]; - if (pt != NULL) - { + double* pt = ProblemeLineairePartieVariable.AdresseOuPlacerLaValeurDesVariablesOptimisees[Var]; + if (pt) *pt = ProblemeLineairePartieVariable.X[Var]; - } } } else From 6151c2b88e7d1fc9502453a4014904c894d59346 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Mon, 18 Sep 2023 11:09:20 +0200 Subject: [PATCH 22/42] [DEV] Use new instead of malloc for PROBLEME_SIMPLEXE --- src/solver/hydro/daily/h2o_j_free.cpp | 3 ++- src/solver/hydro/daily/h2o_j_resoudre_le_probleme_lineaire.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/solver/hydro/daily/h2o_j_free.cpp b/src/solver/hydro/daily/h2o_j_free.cpp index d8eed93a43..e950b5beaa 100644 --- a/src/solver/hydro/daily/h2o_j_free.cpp +++ b/src/solver/hydro/daily/h2o_j_free.cpp @@ -51,7 +51,8 @@ void H2O_J_Free(DONNEES_MENSUELLES* DonneesMensuelles) SPX_LibererProbleme(ProbSpx); } - free(ProblemeHydraulique.Probleme); + PROBLEME_SIMPLEXE* pb = (PROBLEME_SIMPLEXE*)ProblemeHydraulique.Probleme; + delete pb; return; } diff --git a/src/solver/hydro/daily/h2o_j_resoudre_le_probleme_lineaire.cpp b/src/solver/hydro/daily/h2o_j_resoudre_le_probleme_lineaire.cpp index 6fb3082e74..590f221ee2 100644 --- a/src/solver/hydro/daily/h2o_j_resoudre_le_probleme_lineaire.cpp +++ b/src/solver/hydro/daily/h2o_j_resoudre_le_probleme_lineaire.cpp @@ -61,7 +61,7 @@ void H2O_J_ResoudreLeProblemeLineaire(DONNEES_MENSUELLES* DonneesMensuelles, int if (!Probleme) { - Probleme = (PROBLEME_SIMPLEXE*)malloc(sizeof(PROBLEME_SIMPLEXE)); + Probleme = new PROBLEME_SIMPLEXE; if (!Probleme) { DonneesMensuelles->ResultatsValides = EMERGENCY_SHUT_DOWN; From 436ecc5963dac55bf3afa9d87bb4bcf28b254a77 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Mon, 18 Sep 2023 11:11:24 +0200 Subject: [PATCH 23/42] [DEV] Use new instead of malloc for PROBLEME_SIMPLEXE in monthly --- src/solver/hydro/monthly/h2o_m_free.cpp | 3 ++- .../hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/solver/hydro/monthly/h2o_m_free.cpp b/src/solver/hydro/monthly/h2o_m_free.cpp index b4f917abc5..d8e55e05b4 100644 --- a/src/solver/hydro/monthly/h2o_m_free.cpp +++ b/src/solver/hydro/monthly/h2o_m_free.cpp @@ -52,7 +52,8 @@ void H2O_M_Free(DONNEES_ANNUELLES& DonneesAnnuelles) SPX_LibererProbleme(ProbSpx); } - free(ProblemeHydraulique.Probleme); + PROBLEME_SIMPLEXE* pb = (PROBLEME_SIMPLEXE*)ProblemeHydraulique.Probleme; + delete pb; return; } diff --git a/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp b/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp index efbb01bc3e..e2873e1e3f 100644 --- a/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp +++ b/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp @@ -61,7 +61,7 @@ void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES& DonneesAnnuelles, int N if (!Probleme) { - Probleme = (PROBLEME_SIMPLEXE*)malloc(sizeof(PROBLEME_SIMPLEXE)); + Probleme = new PROBLEME_SIMPLEXE; if (!Probleme) { DonneesAnnuelles.ResultatsValides = EMERGENCY_SHUT_DOWN; From 38cf1fd1e430423b07d2bc8b7764195cb770b54b Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Mon, 18 Sep 2023 13:29:47 +0200 Subject: [PATCH 24/42] [DEV] static_cast --- src/solver/hydro/daily/h2o_j_free.cpp | 2 +- src/solver/hydro/monthly/h2o_m_free.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/solver/hydro/daily/h2o_j_free.cpp b/src/solver/hydro/daily/h2o_j_free.cpp index e950b5beaa..a5dfba5f6a 100644 --- a/src/solver/hydro/daily/h2o_j_free.cpp +++ b/src/solver/hydro/daily/h2o_j_free.cpp @@ -51,7 +51,7 @@ void H2O_J_Free(DONNEES_MENSUELLES* DonneesMensuelles) SPX_LibererProbleme(ProbSpx); } - PROBLEME_SIMPLEXE* pb = (PROBLEME_SIMPLEXE*)ProblemeHydraulique.Probleme; + PROBLEME_SIMPLEXE* pb = static_cast(ProblemeHydraulique.Probleme); delete pb; return; diff --git a/src/solver/hydro/monthly/h2o_m_free.cpp b/src/solver/hydro/monthly/h2o_m_free.cpp index d8e55e05b4..960d9c6847 100644 --- a/src/solver/hydro/monthly/h2o_m_free.cpp +++ b/src/solver/hydro/monthly/h2o_m_free.cpp @@ -52,7 +52,7 @@ void H2O_M_Free(DONNEES_ANNUELLES& DonneesAnnuelles) SPX_LibererProbleme(ProbSpx); } - PROBLEME_SIMPLEXE* pb = (PROBLEME_SIMPLEXE*)ProblemeHydraulique.Probleme; + PROBLEME_SIMPLEXE* pb = static_cast(ProblemeHydraulique.Probleme); delete pb; return; From 6d2bc6414d73b79253a5bc066746ff5a6c275796 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Mon, 18 Sep 2023 13:33:53 +0200 Subject: [PATCH 25/42] [DEV] const int nbpdt --- .../hydro/daily/h2o_j_initialiser_les_bornes_des_variables.cpp | 2 +- src/solver/hydro/daily/h2o_j_initialiser_les_second_membre.cpp | 2 +- src/solver/hydro/daily/h2o_j_instanciation.cpp | 2 +- src/solver/hydro/daily/h2o_j_lisser_les_sur_turbines.cpp | 2 +- src/solver/hydro/monthly/h2o_m_construire_les_contraintes.cpp | 2 +- src/solver/hydro/monthly/h2o_m_construire_les_variables.cpp | 2 +- .../monthly/h2o_m_initialiser_les_bornes_des_variables.cpp | 2 +- .../hydro/monthly/h2o_m_initialiser_les_second_membre.cpp | 2 +- src/solver/hydro/monthly/h2o_m_instanciation.cpp | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/solver/hydro/daily/h2o_j_initialiser_les_bornes_des_variables.cpp b/src/solver/hydro/daily/h2o_j_initialiser_les_bornes_des_variables.cpp index a69f5c3e57..913c2a02a9 100644 --- a/src/solver/hydro/daily/h2o_j_initialiser_les_bornes_des_variables.cpp +++ b/src/solver/hydro/daily/h2o_j_initialiser_les_bornes_des_variables.cpp @@ -39,7 +39,7 @@ void H2O_J_InitialiserLesBornesdesVariables(DONNEES_MENSUELLES* DonneesMensuelle PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesMensuelles->ProblemeHydraulique; - int NbPdt = ProblemeHydraulique.NbJoursDUnProbleme[NumeroDeProbleme]; + const int NbPdt = ProblemeHydraulique.NbJoursDUnProbleme[NumeroDeProbleme]; const CORRESPONDANCE_DES_VARIABLES& CorrespondanceDesVariables = ProblemeHydraulique.CorrespondanceDesVariables[NumeroDeProbleme]; diff --git a/src/solver/hydro/daily/h2o_j_initialiser_les_second_membre.cpp b/src/solver/hydro/daily/h2o_j_initialiser_les_second_membre.cpp index ca63a40004..0035235297 100644 --- a/src/solver/hydro/daily/h2o_j_initialiser_les_second_membre.cpp +++ b/src/solver/hydro/daily/h2o_j_initialiser_les_second_membre.cpp @@ -43,7 +43,7 @@ void H2O_J_InitialiserLeSecondMembre(DONNEES_MENSUELLES* DonneesMensuelles, int SecondMembre[NumeroDeContrainteDEnergieMensuelle] = DonneesMensuelles->TurbineDuMois; - int NbPdt = ProblemeHydraulique.NbJoursDUnProbleme[NumeroDeProbleme]; + const int NbPdt = ProblemeHydraulique.NbJoursDUnProbleme[NumeroDeProbleme]; for (int Pdt = 0; Pdt < NbPdt; Pdt++) { int Cnt = CorrespondanceDesContraintes.NumeroDeContrainteSurXi[Pdt]; diff --git a/src/solver/hydro/daily/h2o_j_instanciation.cpp b/src/solver/hydro/daily/h2o_j_instanciation.cpp index 4824e7a545..fac90f4c3c 100644 --- a/src/solver/hydro/daily/h2o_j_instanciation.cpp +++ b/src/solver/hydro/daily/h2o_j_instanciation.cpp @@ -77,7 +77,7 @@ DONNEES_MENSUELLES* H2O_J_Instanciation(void) for (int i = 0; i < NombreDeProblemes; i++) { - int NbPdt = NbJoursDUnProbleme[i]; + const int NbPdt = NbJoursDUnProbleme[i]; CorrespondanceDesVariables[i].NumeroDeVariableTurbine.assign(NbPdt, 0); CorrespondanceDesContraintes[i].NumeroDeContrainteSurXi.assign(NbPdt, 0); diff --git a/src/solver/hydro/daily/h2o_j_lisser_les_sur_turbines.cpp b/src/solver/hydro/daily/h2o_j_lisser_les_sur_turbines.cpp index 94ab01b71a..bfde29ddc1 100644 --- a/src/solver/hydro/daily/h2o_j_lisser_les_sur_turbines.cpp +++ b/src/solver/hydro/daily/h2o_j_lisser_les_sur_turbines.cpp @@ -40,7 +40,7 @@ void H2O_J_LisserLesSurTurbines(DONNEES_MENSUELLES* DonneesMensuelles, int Numer char* Flag = (char*) ProblemeHydraulique.ProblemeLineairePartieVariable[NumeroDeProbleme].Xmax.data(); - int NbPdt = ProblemeHydraulique.NbJoursDUnProbleme[NumeroDeProbleme]; + const int NbPdt = ProblemeHydraulique.NbJoursDUnProbleme[NumeroDeProbleme]; double SurTurbineARepartir = 0.0; for (int Pdt = 0; Pdt < NbPdt; Pdt++) diff --git a/src/solver/hydro/monthly/h2o_m_construire_les_contraintes.cpp b/src/solver/hydro/monthly/h2o_m_construire_les_contraintes.cpp index 9c1ef5062a..3e1b61ec93 100644 --- a/src/solver/hydro/monthly/h2o_m_construire_les_contraintes.cpp +++ b/src/solver/hydro/monthly/h2o_m_construire_les_contraintes.cpp @@ -56,7 +56,7 @@ void H2O_M_ConstruireLesContraintes(DONNEES_ANNUELLES& DonneesAnnuelles) int NumeroDeLaVariableXi = CorrespondanceDesVariables.NumeroDeLaVariableXi; double ChgmtSens = -1.0; - int NbPdt = DonneesAnnuelles.NombreDePasDeTemps; + const int NbPdt = DonneesAnnuelles.NombreDePasDeTemps; int NombreDeContraintes = 0; int il = 0; diff --git a/src/solver/hydro/monthly/h2o_m_construire_les_variables.cpp b/src/solver/hydro/monthly/h2o_m_construire_les_variables.cpp index 7895f43a80..93eb7d297f 100644 --- a/src/solver/hydro/monthly/h2o_m_construire_les_variables.cpp +++ b/src/solver/hydro/monthly/h2o_m_construire_les_variables.cpp @@ -49,7 +49,7 @@ void H2O_M_ConstruireLesVariables(DONNEES_ANNUELLES& DonneesAnnuelles) CORRESPONDANCE_DES_VARIABLES& CorrespondanceDesVariables = ProblemeHydraulique.CorrespondanceDesVariables; - int NbPdt = DonneesAnnuelles.NombreDePasDeTemps; + const int NbPdt = DonneesAnnuelles.NombreDePasDeTemps; int Var = 0; CorrespondanceDesVariables.NumeroDeVariableVolume[0] = Var; diff --git a/src/solver/hydro/monthly/h2o_m_initialiser_les_bornes_des_variables.cpp b/src/solver/hydro/monthly/h2o_m_initialiser_les_bornes_des_variables.cpp index 05157e3d4a..c55cb17d1d 100644 --- a/src/solver/hydro/monthly/h2o_m_initialiser_les_bornes_des_variables.cpp +++ b/src/solver/hydro/monthly/h2o_m_initialiser_les_bornes_des_variables.cpp @@ -40,7 +40,7 @@ void H2O_M_InitialiserBornesEtCoutsDesVariables(DONNEES_ANNUELLES& DonneesAnnuel DonneesAnnuelles.Volume[0] = DonneesAnnuelles.VolumeInitial; - int NbPdt = DonneesAnnuelles.NombreDePasDeTemps; + const int NbPdt = DonneesAnnuelles.NombreDePasDeTemps; double CoutDepassementVolume = DonneesAnnuelles.CoutDepassementVolume; auto& TurbineMax = DonneesAnnuelles.TurbineMax; const auto& TurbineMin = DonneesAnnuelles.TurbineMin; diff --git a/src/solver/hydro/monthly/h2o_m_initialiser_les_second_membre.cpp b/src/solver/hydro/monthly/h2o_m_initialiser_les_second_membre.cpp index 233ca33ce7..9c08ade8c5 100644 --- a/src/solver/hydro/monthly/h2o_m_initialiser_les_second_membre.cpp +++ b/src/solver/hydro/monthly/h2o_m_initialiser_les_second_membre.cpp @@ -35,7 +35,7 @@ void H2O_M_InitialiserLeSecondMembre(DONNEES_ANNUELLES& DonneesAnnuelles) = ProblemeHydraulique.ProblemeLineairePartieVariable; double ChgmtSens = -1; - int NbPdt = DonneesAnnuelles.NombreDePasDeTemps; + const int NbPdt = DonneesAnnuelles.NombreDePasDeTemps; int Cnt = 0; auto& TurbineCible = DonneesAnnuelles.TurbineCible; diff --git a/src/solver/hydro/monthly/h2o_m_instanciation.cpp b/src/solver/hydro/monthly/h2o_m_instanciation.cpp index 47f0191197..e91df7a7be 100644 --- a/src/solver/hydro/monthly/h2o_m_instanciation.cpp +++ b/src/solver/hydro/monthly/h2o_m_instanciation.cpp @@ -33,7 +33,7 @@ DONNEES_ANNUELLES H2O_M_Instanciation(int NombreDeReservoirs) DONNEES_ANNUELLES DonneesAnnuelles{}; DonneesAnnuelles.NombreDePasDeTemps = 12; - int NbPdt = DonneesAnnuelles.NombreDePasDeTemps; + const int NbPdt = DonneesAnnuelles.NombreDePasDeTemps; DonneesAnnuelles.TurbineMax.assign(NbPdt, 0.); DonneesAnnuelles.TurbineMin.assign(NbPdt, 0.); From 90d56493d00c5062b4d42d33217738eddae445af Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Mon, 18 Sep 2023 15:53:29 +0200 Subject: [PATCH 26/42] [DEV] Comment in h2o_m_resoudre_le_probleme_lineaire.cpp --- .../h2o_m_resoudre_le_probleme_lineaire.cpp | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp b/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp index e2873e1e3f..f1794f1139 100644 --- a/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp +++ b/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp @@ -46,6 +46,8 @@ extern "C" #define SNPRINTF snprintf #endif +#include + void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES& DonneesAnnuelles, int NumeroDeReservoir) { PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesAnnuelles.ProblemeHydraulique; @@ -54,14 +56,14 @@ void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES& DonneesAnnuelles, int N PROBLEME_LINEAIRE_PARTIE_FIXE& ProblemeLineairePartieFixe = ProblemeHydraulique.ProblemeLineairePartieFixe; - char PremierPassage = OUI; + bool PremierPassage = true; PROBLEME_SPX* ProbSpx = (PROBLEME_SPX*)ProblemeHydraulique.ProblemeSpx[NumeroDeReservoir]; PROBLEME_SIMPLEXE* Probleme = (PROBLEME_SIMPLEXE*)ProblemeHydraulique.Probleme; if (!Probleme) { - Probleme = new PROBLEME_SIMPLEXE; + Probleme = new(std::nothrow) PROBLEME_SIMPLEXE; if (!Probleme) { DonneesAnnuelles.ResultatsValides = EMERGENCY_SHUT_DOWN; @@ -128,7 +130,7 @@ void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES& DonneesAnnuelles, int N Probleme->CoutsReduits = ProblemeLineairePartieVariable.CoutsReduits.data(); #ifndef NDEBUG - if (PremierPassage == OUI) + if (PremierPassage) Probleme->AffichageDesTraces = NON_SPX; else Probleme->AffichageDesTraces = OUI_SPX; @@ -145,15 +147,14 @@ void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES& DonneesAnnuelles, int N ProblemeLineairePartieVariable.ExistenceDUneSolution = Probleme->ExistenceDUneSolution; - if (ProblemeLineairePartieVariable.ExistenceDUneSolution != OUI_SPX && PremierPassage == OUI - && ProbSpx != NULL) + if (ProblemeLineairePartieVariable.ExistenceDUneSolution != OUI_SPX && PremierPassage && ProbSpx) { if (ProblemeLineairePartieVariable.ExistenceDUneSolution != SPX_ERREUR_INTERNE) { SPX_LibererProbleme(ProbSpx); ProbSpx = NULL; - PremierPassage = NON; + PremierPassage = false; goto RESOLUTION; } else @@ -166,26 +167,26 @@ void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES& DonneesAnnuelles, int N if (ProblemeLineairePartieVariable.ExistenceDUneSolution == OUI_SPX) { ProblemeHydraulique.CoutDeLaSolution = 0.0; - for (int i = 0; i < Probleme->NombreDeVariables; i++) + for (int var = 0; var < Probleme->NombreDeVariables; var++) { ProblemeHydraulique.CoutDeLaSolution - += ProblemeLineairePartieFixe.CoutLineaire[i] * Probleme->X[i]; + += ProblemeLineairePartieFixe.CoutLineaire[var] * Probleme->X[var]; } ProblemeHydraulique.CoutDeLaSolutionBruite = 0.0; - for (int i = 0; i < Probleme->NombreDeVariables; i++) + for (int var = 0; var < Probleme->NombreDeVariables; var++) { ProblemeHydraulique.CoutDeLaSolutionBruite - += ProblemeLineairePartieFixe.CoutLineaireBruite[i] * Probleme->X[i]; + += ProblemeLineairePartieFixe.CoutLineaireBruite[var] * Probleme->X[var]; } DonneesAnnuelles.ResultatsValides = OUI; - for (int i = 0; i < ProblemeLineairePartieFixe.NombreDeVariables; i++) + for (int var = 0; var < ProblemeLineairePartieFixe.NombreDeVariables; var++) { - double* pt = ProblemeLineairePartieVariable.AdresseOuPlacerLaValeurDesVariablesOptimisees[i]; + double* pt = ProblemeLineairePartieVariable.AdresseOuPlacerLaValeurDesVariablesOptimisees[var]; if (pt) - *pt = ProblemeLineairePartieVariable.X[i]; + *pt = ProblemeLineairePartieVariable.X[var]; } } else From 3b2732ff7d36ff9fa86badee31da4dba97c6ea06 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Mon, 18 Sep 2023 15:58:58 +0200 Subject: [PATCH 27/42] [DEV] Use pointer instead of ref in management/daily --- .../hydro/daily/h2o_j_instanciation.cpp | 2 +- src/solver/hydro/management/daily.cpp | 22 +++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/solver/hydro/daily/h2o_j_instanciation.cpp b/src/solver/hydro/daily/h2o_j_instanciation.cpp index fac90f4c3c..7065756843 100644 --- a/src/solver/hydro/daily/h2o_j_instanciation.cpp +++ b/src/solver/hydro/daily/h2o_j_instanciation.cpp @@ -30,7 +30,7 @@ DONNEES_MENSUELLES* H2O_J_Instanciation(void) { - DONNEES_MENSUELLES* DonneesMensuelles = new DONNEES_MENSUELLES;; + DONNEES_MENSUELLES* DonneesMensuelles = new DONNEES_MENSUELLES; PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesMensuelles->ProblemeHydraulique; diff --git a/src/solver/hydro/management/daily.cpp b/src/solver/hydro/management/daily.cpp index 25aa8116e4..aa827b8913 100644 --- a/src/solver/hydro/management/daily.cpp +++ b/src/solver/hydro/management/daily.cpp @@ -391,28 +391,28 @@ inline void HydroManagement::prepareDailyOptimalGenerations(Solver::Variable::St uint firstDay = study.calendar.months[simulationMonth].daysYear.first; uint endDay = firstDay + daysPerMonth; - DONNEES_MENSUELLES& problem = *H2O_J_Instanciation(); - H2O_J_AjouterBruitAuCout(problem); - problem.NombreDeJoursDuMois = (int)daysPerMonth; - problem.TurbineDuMois = data.MOG[realmonth]; + DONNEES_MENSUELLES* problem = H2O_J_Instanciation(); + H2O_J_AjouterBruitAuCout(*problem); + problem->NombreDeJoursDuMois = (int)daysPerMonth; + problem->TurbineDuMois = data.MOG[realmonth]; uint dayMonth = 0; for (uint day = firstDay; day != endDay; ++day) { - problem.TurbineMax[dayMonth] = maxP[day] * maxE[day]; - problem.TurbineMin[dayMonth] = data.dailyMinGen[day]; - problem.TurbineCible[dayMonth] = dailyTargetGen[day]; + problem->TurbineMax[dayMonth] = maxP[day] * maxE[day]; + problem->TurbineMin[dayMonth] = data.dailyMinGen[day]; + problem->TurbineCible[dayMonth] = dailyTargetGen[day]; dayMonth++; } - H2O_J_OptimiserUnMois(&problem); - switch (problem.ResultatsValides) + H2O_J_OptimiserUnMois(problem); + switch (problem->ResultatsValides) { case OUI: dayMonth = 0; for (uint day = firstDay; day != endDay; ++day) { - valgen.HydrauliqueModulableQuotidien[day] = problem.Turbine[dayMonth]; + valgen.HydrauliqueModulableQuotidien[day] = problem->Turbine[dayMonth]; dayMonth++; } break; @@ -424,7 +424,7 @@ inline void HydroManagement::prepareDailyOptimalGenerations(Solver::Variable::St break; } - H2O_J_Free(&problem); + H2O_J_Free(problem); #ifndef NDEBUG for (uint day = firstDay; day != endDay; ++day) From f948eb7b32ffb1d2f9b92b12112c33bb3194e93f Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Mon, 18 Sep 2023 16:22:28 +0200 Subject: [PATCH 28/42] [DEV] (std::nothrow) --- src/solver/hydro/daily/h2o_j_resoudre_le_probleme_lineaire.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/solver/hydro/daily/h2o_j_resoudre_le_probleme_lineaire.cpp b/src/solver/hydro/daily/h2o_j_resoudre_le_probleme_lineaire.cpp index 590f221ee2..e13c807adc 100644 --- a/src/solver/hydro/daily/h2o_j_resoudre_le_probleme_lineaire.cpp +++ b/src/solver/hydro/daily/h2o_j_resoudre_le_probleme_lineaire.cpp @@ -61,7 +61,7 @@ void H2O_J_ResoudreLeProblemeLineaire(DONNEES_MENSUELLES* DonneesMensuelles, int if (!Probleme) { - Probleme = new PROBLEME_SIMPLEXE; + Probleme = new(std::nothrow) PROBLEME_SIMPLEXE; if (!Probleme) { DonneesMensuelles->ResultatsValides = EMERGENCY_SHUT_DOWN; From c4dd14847c369931945d6eeb1de5d2e2d4443644 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Thu, 21 Sep 2023 15:19:05 +0200 Subject: [PATCH 29/42] [DEV] Replace flag by vector of bool --- .../daily/h2o_j_lisser_les_sur_turbines.cpp | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/solver/hydro/daily/h2o_j_lisser_les_sur_turbines.cpp b/src/solver/hydro/daily/h2o_j_lisser_les_sur_turbines.cpp index bfde29ddc1..bda43ea52c 100644 --- a/src/solver/hydro/daily/h2o_j_lisser_les_sur_turbines.cpp +++ b/src/solver/hydro/daily/h2o_j_lisser_les_sur_turbines.cpp @@ -34,34 +34,34 @@ void H2O_J_LisserLesSurTurbines(DONNEES_MENSUELLES* DonneesMensuelles, int Numer { PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesMensuelles->ProblemeHydraulique; - std::vector& TurbineMax = DonneesMensuelles->TurbineMax; - std::vector& Turbine = DonneesMensuelles->Turbine; - std::vector& TurbineCible = DonneesMensuelles->TurbineCible; - - char* Flag = (char*) ProblemeHydraulique.ProblemeLineairePartieVariable[NumeroDeProbleme].Xmax.data(); + auto& Turbine = DonneesMensuelles->Turbine; + const auto& TurbineMax = DonneesMensuelles->TurbineMax; + const auto& TurbineCible = DonneesMensuelles->TurbineCible; const int NbPdt = ProblemeHydraulique.NbJoursDUnProbleme[NumeroDeProbleme]; + std::vector flag(NbPdt); + double SurTurbineARepartir = 0.0; for (int Pdt = 0; Pdt < NbPdt; Pdt++) { - Flag[Pdt] = 0; + flag[Pdt] = 0; if (Turbine[Pdt] - TurbineCible[Pdt] > ZERO) - Flag[Pdt] = 1; + flag[Pdt] = 1; } for (int Pdt = 0; Pdt < NbPdt; Pdt++) { - if (Flag[Pdt] == 1) + if (flag[Pdt] == 1) SurTurbineARepartir += Turbine[Pdt] - TurbineCible[Pdt]; } for (int Pdt = 0; Pdt < NbPdt; Pdt++) - Flag[Pdt] = 0; + flag[Pdt] = 0; for (int Pdt = 0; Pdt < NbPdt; Pdt++) { if (TurbineMax[Pdt] - TurbineCible[Pdt] > ZERO) - Flag[Pdt] = 1; + flag[Pdt] = 1; } int NbCycles = 0; @@ -70,7 +70,7 @@ void H2O_J_LisserLesSurTurbines(DONNEES_MENSUELLES* DonneesMensuelles, int Numer int Np = 0; for (int Pdt = 0; Pdt < NbPdt; Pdt++) { - if (Flag[Pdt] == 1) + if (flag[Pdt] == 1) Np++; } if (Np <= 0) @@ -83,7 +83,7 @@ void H2O_J_LisserLesSurTurbines(DONNEES_MENSUELLES* DonneesMensuelles, int Numer MargeMin += TurbineMax[Pdt]; for (int Pdt = 0; Pdt < NbPdt; Pdt++) { - if (Flag[Pdt] == 1) + if (flag[Pdt] == 1) { if (TurbineMax[Pdt] - TurbineCible[Pdt] < MargeMin) MargeMin = TurbineMax[Pdt] - TurbineCible[Pdt]; @@ -100,7 +100,7 @@ void H2O_J_LisserLesSurTurbines(DONNEES_MENSUELLES* DonneesMensuelles, int Numer char LimiteAtteinte = 0; for (int Pdt = 0; Pdt < NbPdt; Pdt++) { - if (Flag[Pdt] == 0) + if (flag[Pdt] == 0) continue; Turbine[Pdt] = TurbineCible[Pdt] + SurTurbine; @@ -108,7 +108,7 @@ void H2O_J_LisserLesSurTurbines(DONNEES_MENSUELLES* DonneesMensuelles, int Numer { SurTurbineARepartir -= SurTurbine; LimiteAtteinte = 1; - Flag[Pdt] = 0; + flag[Pdt] = 0; } } From 3e135f7e3768b5cf0ff3db2d46d230d71bac8ab8 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Thu, 21 Sep 2023 15:47:06 +0200 Subject: [PATCH 30/42] [DEV] Updated lisser_sur_turbines --- .../daily/h2o_j_lisser_les_sur_turbines.cpp | 50 ++++++------------- 1 file changed, 15 insertions(+), 35 deletions(-) diff --git a/src/solver/hydro/daily/h2o_j_lisser_les_sur_turbines.cpp b/src/solver/hydro/daily/h2o_j_lisser_les_sur_turbines.cpp index bda43ea52c..4f1381fb7e 100644 --- a/src/solver/hydro/daily/h2o_j_lisser_les_sur_turbines.cpp +++ b/src/solver/hydro/daily/h2o_j_lisser_les_sur_turbines.cpp @@ -28,6 +28,8 @@ #include "h2o_j_donnees_mensuelles.h" #include "h2o_j_fonctions.h" +#include + #define ZERO 1.e-9 void H2O_J_LisserLesSurTurbines(DONNEES_MENSUELLES* DonneesMensuelles, int NumeroDeProbleme) @@ -44,51 +46,29 @@ void H2O_J_LisserLesSurTurbines(DONNEES_MENSUELLES* DonneesMensuelles, int Numer double SurTurbineARepartir = 0.0; for (int Pdt = 0; Pdt < NbPdt; Pdt++) - { - flag[Pdt] = 0; - if (Turbine[Pdt] - TurbineCible[Pdt] > ZERO) - flag[Pdt] = 1; - } + flag[Pdt] = (Turbine[Pdt] - TurbineCible[Pdt] > ZERO); for (int Pdt = 0; Pdt < NbPdt; Pdt++) - { - if (flag[Pdt] == 1) + if (flag[Pdt]) SurTurbineARepartir += Turbine[Pdt] - TurbineCible[Pdt]; - } for (int Pdt = 0; Pdt < NbPdt; Pdt++) - flag[Pdt] = 0; - for (int Pdt = 0; Pdt < NbPdt; Pdt++) - { - if (TurbineMax[Pdt] - TurbineCible[Pdt] > ZERO) - flag[Pdt] = 1; - } + flag[Pdt] = (TurbineMax[Pdt] - TurbineCible[Pdt] > ZERO);; int NbCycles = 0; BoucleDeRepartition: - int Np = 0; - for (int Pdt = 0; Pdt < NbPdt; Pdt++) - { - if (flag[Pdt] == 1) - Np++; - } - if (Np <= 0) - { + int Np = std::count(flag.begin(), flag.end(), true); + if (Np == 0) return; - } double MargeMin = 0.; for (int Pdt = 0; Pdt < NbPdt; Pdt++) MargeMin += TurbineMax[Pdt]; + for (int Pdt = 0; Pdt < NbPdt; Pdt++) - { - if (flag[Pdt] == 1) - { - if (TurbineMax[Pdt] - TurbineCible[Pdt] < MargeMin) - MargeMin = TurbineMax[Pdt] - TurbineCible[Pdt]; - } - } + if (flag[Pdt] && TurbineMax[Pdt] - TurbineCible[Pdt] < MargeMin) + MargeMin = TurbineMax[Pdt] - TurbineCible[Pdt]; double Xmoy = SurTurbineARepartir / Np; double SurTurbine; @@ -97,22 +77,22 @@ void H2O_J_LisserLesSurTurbines(DONNEES_MENSUELLES* DonneesMensuelles, int Numer else SurTurbine = MargeMin; - char LimiteAtteinte = 0; + bool limiteAtteinte = 0; for (int Pdt = 0; Pdt < NbPdt; Pdt++) { - if (flag[Pdt] == 0) + if (!flag[Pdt]) continue; Turbine[Pdt] = TurbineCible[Pdt] + SurTurbine; if (TurbineMax[Pdt] - Turbine[Pdt] <= ZERO) { SurTurbineARepartir -= SurTurbine; - LimiteAtteinte = 1; - flag[Pdt] = 0; + limiteAtteinte = true; + flag[Pdt] = false; } } - if (LimiteAtteinte == 1 && SurTurbineARepartir > 0.0) + if (limiteAtteinte && SurTurbineARepartir > 0.0) { NbCycles++; if (NbCycles <= NbPdt) From 99395c78a99e2694fb70862ef715f476f01602da Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Fri, 22 Sep 2023 10:32:00 +0200 Subject: [PATCH 31/42] [DEV] unique_ptr for daily --- src/solver/hydro/daily/h2o_j_fonctions.h | 2 +- src/solver/hydro/daily/h2o_j_instanciation.cpp | 4 ++-- src/solver/hydro/daily/h2o_j_sys.h | 2 +- src/solver/hydro/management/daily.cpp | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/solver/hydro/daily/h2o_j_fonctions.h b/src/solver/hydro/daily/h2o_j_fonctions.h index 5614e98d12..75afd34c69 100644 --- a/src/solver/hydro/daily/h2o_j_fonctions.h +++ b/src/solver/hydro/daily/h2o_j_fonctions.h @@ -28,7 +28,7 @@ #ifndef __SOLVER_H2O_J_FONCTIONS__ #define __SOLVER_H2O_J_FONCTIONS__ -DONNEES_MENSUELLES* H2O_J_Instanciation(void); +std::unique_ptr H2O_J_Instanciation(void); void H2O_J_OptimiserUnMois(DONNEES_MENSUELLES*); void H2O_J_Free(DONNEES_MENSUELLES*); diff --git a/src/solver/hydro/daily/h2o_j_instanciation.cpp b/src/solver/hydro/daily/h2o_j_instanciation.cpp index 7065756843..746ab17def 100644 --- a/src/solver/hydro/daily/h2o_j_instanciation.cpp +++ b/src/solver/hydro/daily/h2o_j_instanciation.cpp @@ -28,9 +28,9 @@ #include "h2o_j_donnees_mensuelles.h" #include "h2o_j_fonctions.h" -DONNEES_MENSUELLES* H2O_J_Instanciation(void) +std::unique_ptr H2O_J_Instanciation(void) { - DONNEES_MENSUELLES* DonneesMensuelles = new DONNEES_MENSUELLES; + std::unique_ptr DonneesMensuelles = std::make_unique(); PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesMensuelles->ProblemeHydraulique; diff --git a/src/solver/hydro/daily/h2o_j_sys.h b/src/solver/hydro/daily/h2o_j_sys.h index f2c6b9ba09..77e9fb1e98 100644 --- a/src/solver/hydro/daily/h2o_j_sys.h +++ b/src/solver/hydro/daily/h2o_j_sys.h @@ -33,7 +33,7 @@ #include #include #include -#include +#include #include #endif /* __SOLVER_H2O_J_SYS__ */ diff --git a/src/solver/hydro/management/daily.cpp b/src/solver/hydro/management/daily.cpp index abaa7cd4b8..d3dbd9a64d 100644 --- a/src/solver/hydro/management/daily.cpp +++ b/src/solver/hydro/management/daily.cpp @@ -389,7 +389,7 @@ inline void HydroManagement::prepareDailyOptimalGenerations(Solver::Variable::St uint firstDay = calendar_.months[simulationMonth].daysYear.first; uint endDay = firstDay + daysPerMonth; - DONNEES_MENSUELLES* problem = H2O_J_Instanciation(); + std::unique_ptr problem = H2O_J_Instanciation(); H2O_J_AjouterBruitAuCout(*problem); problem->NombreDeJoursDuMois = (int)daysPerMonth; problem->TurbineDuMois = data.MOG[realmonth]; @@ -403,7 +403,7 @@ inline void HydroManagement::prepareDailyOptimalGenerations(Solver::Variable::St dayMonth++; } - H2O_J_OptimiserUnMois(problem); + H2O_J_OptimiserUnMois(problem.get()); switch (problem->ResultatsValides) { case OUI: @@ -422,7 +422,7 @@ inline void HydroManagement::prepareDailyOptimalGenerations(Solver::Variable::St break; } - H2O_J_Free(problem); + H2O_J_Free(problem.get()); #ifndef NDEBUG for (uint day = firstDay; day != endDay; ++day) From 8ec141f86cf3c2df4ea4a59d262209a345cdef55 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Fri, 22 Sep 2023 12:02:37 +0200 Subject: [PATCH 32/42] [DEV] unique_ptr for daily/prob_a_resoudre --- src/solver/hydro/daily/h2o_j_free.cpp | 3 --- .../daily/h2o_j_resoudre_le_probleme_lineaire.cpp | 13 ++++--------- src/solver/hydro/management/daily.cpp | 2 +- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/solver/hydro/daily/h2o_j_free.cpp b/src/solver/hydro/daily/h2o_j_free.cpp index a5dfba5f6a..d19196ab49 100644 --- a/src/solver/hydro/daily/h2o_j_free.cpp +++ b/src/solver/hydro/daily/h2o_j_free.cpp @@ -51,8 +51,5 @@ void H2O_J_Free(DONNEES_MENSUELLES* DonneesMensuelles) SPX_LibererProbleme(ProbSpx); } - PROBLEME_SIMPLEXE* pb = static_cast(ProblemeHydraulique.Probleme); - delete pb; - return; } diff --git a/src/solver/hydro/daily/h2o_j_resoudre_le_probleme_lineaire.cpp b/src/solver/hydro/daily/h2o_j_resoudre_le_probleme_lineaire.cpp index e13c807adc..3593d1c182 100644 --- a/src/solver/hydro/daily/h2o_j_resoudre_le_probleme_lineaire.cpp +++ b/src/solver/hydro/daily/h2o_j_resoudre_le_probleme_lineaire.cpp @@ -57,17 +57,12 @@ void H2O_J_ResoudreLeProblemeLineaire(DONNEES_MENSUELLES* DonneesMensuelles, int = ProblemeHydraulique.ProblemeLineairePartieFixe[NumeroDeProbleme]; PROBLEME_SPX* ProbSpx = (PROBLEME_SPX*)ProblemeHydraulique.ProblemeSpx[NumeroDeProbleme]; - PROBLEME_SIMPLEXE* Probleme = (PROBLEME_SIMPLEXE*)ProblemeHydraulique.Probleme; + std::unique_ptr Probleme = std::make_unique(); if (!Probleme) { - Probleme = new(std::nothrow) PROBLEME_SIMPLEXE; - if (!Probleme) - { - DonneesMensuelles->ResultatsValides = EMERGENCY_SHUT_DOWN; - return; - } - ProblemeHydraulique.Probleme = (void*)Probleme; + DonneesMensuelles->ResultatsValides = EMERGENCY_SHUT_DOWN; + return; } char PremierPassage = OUI; @@ -140,7 +135,7 @@ void H2O_J_ResoudreLeProblemeLineaire(DONNEES_MENSUELLES* DonneesMensuelles, int Probleme->NombreDeContraintesCoupes = 0; - ProbSpx = SPX_Simplexe(Probleme, ProbSpx); + ProbSpx = SPX_Simplexe(Probleme.get(), ProbSpx); if (ProbSpx) ProblemeHydraulique.ProblemeSpx[NumeroDeProbleme] = (void*)ProbSpx; diff --git a/src/solver/hydro/management/daily.cpp b/src/solver/hydro/management/daily.cpp index d3dbd9a64d..e987e58022 100644 --- a/src/solver/hydro/management/daily.cpp +++ b/src/solver/hydro/management/daily.cpp @@ -389,7 +389,7 @@ inline void HydroManagement::prepareDailyOptimalGenerations(Solver::Variable::St uint firstDay = calendar_.months[simulationMonth].daysYear.first; uint endDay = firstDay + daysPerMonth; - std::unique_ptr problem = H2O_J_Instanciation(); + auto problem = H2O_J_Instanciation(); H2O_J_AjouterBruitAuCout(*problem); problem->NombreDeJoursDuMois = (int)daysPerMonth; problem->TurbineDuMois = data.MOG[realmonth]; From 9dd42cafc6c939be482a78842f63e087bc2607e1 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Fri, 22 Sep 2023 12:05:35 +0200 Subject: [PATCH 33/42] [DEV] unique_ptr for monthly/prob_a_resoudre --- .../h2o_j_resoudre_le_probleme_lineaire.cpp | 9 ++++----- src/solver/hydro/monthly/h2o_m_free.cpp | 3 --- .../h2o_m_resoudre_le_probleme_lineaire.cpp | 16 ++++++---------- 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/src/solver/hydro/daily/h2o_j_resoudre_le_probleme_lineaire.cpp b/src/solver/hydro/daily/h2o_j_resoudre_le_probleme_lineaire.cpp index 3593d1c182..c5df253c29 100644 --- a/src/solver/hydro/daily/h2o_j_resoudre_le_probleme_lineaire.cpp +++ b/src/solver/hydro/daily/h2o_j_resoudre_le_probleme_lineaire.cpp @@ -65,7 +65,7 @@ void H2O_J_ResoudreLeProblemeLineaire(DONNEES_MENSUELLES* DonneesMensuelles, int return; } - char PremierPassage = OUI; + bool PremierPassage = true; RESOLUTION: @@ -125,7 +125,7 @@ void H2O_J_ResoudreLeProblemeLineaire(DONNEES_MENSUELLES* DonneesMensuelles, int Probleme->CoutsReduits = ProblemeLineairePartieVariable.CoutsReduits.data(); #ifndef NDEBUG - if (PremierPassage == OUI) + if (PremierPassage) Probleme->AffichageDesTraces = NON_SPX; else Probleme->AffichageDesTraces = OUI_SPX; @@ -142,15 +142,14 @@ void H2O_J_ResoudreLeProblemeLineaire(DONNEES_MENSUELLES* DonneesMensuelles, int ProblemeLineairePartieVariable.ExistenceDUneSolution = Probleme->ExistenceDUneSolution; - if (ProblemeLineairePartieVariable.ExistenceDUneSolution != OUI_SPX && PremierPassage == OUI - && ProbSpx != NULL) + if (ProblemeLineairePartieVariable.ExistenceDUneSolution != OUI_SPX && PremierPassage && ProbSpx) { if (ProblemeLineairePartieVariable.ExistenceDUneSolution != SPX_ERREUR_INTERNE) { SPX_LibererProbleme(ProbSpx); ProbSpx = NULL; - PremierPassage = NON; + PremierPassage = false; goto RESOLUTION; } else diff --git a/src/solver/hydro/monthly/h2o_m_free.cpp b/src/solver/hydro/monthly/h2o_m_free.cpp index 960d9c6847..be762274e2 100644 --- a/src/solver/hydro/monthly/h2o_m_free.cpp +++ b/src/solver/hydro/monthly/h2o_m_free.cpp @@ -52,8 +52,5 @@ void H2O_M_Free(DONNEES_ANNUELLES& DonneesAnnuelles) SPX_LibererProbleme(ProbSpx); } - PROBLEME_SIMPLEXE* pb = static_cast(ProblemeHydraulique.Probleme); - delete pb; - return; } diff --git a/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp b/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp index f1794f1139..56a69881ed 100644 --- a/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp +++ b/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.cpp @@ -56,22 +56,18 @@ void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES& DonneesAnnuelles, int N PROBLEME_LINEAIRE_PARTIE_FIXE& ProblemeLineairePartieFixe = ProblemeHydraulique.ProblemeLineairePartieFixe; - bool PremierPassage = true; PROBLEME_SPX* ProbSpx = (PROBLEME_SPX*)ProblemeHydraulique.ProblemeSpx[NumeroDeReservoir]; - PROBLEME_SIMPLEXE* Probleme = (PROBLEME_SIMPLEXE*)ProblemeHydraulique.Probleme; + std::unique_ptr Probleme = std::make_unique(); if (!Probleme) { - Probleme = new(std::nothrow) PROBLEME_SIMPLEXE; - if (!Probleme) - { - DonneesAnnuelles.ResultatsValides = EMERGENCY_SHUT_DOWN; - return; - } - ProblemeHydraulique.Probleme = (void*)Probleme; + DonneesAnnuelles.ResultatsValides = EMERGENCY_SHUT_DOWN; + return; } + bool PremierPassage = true; + RESOLUTION: if (!ProbSpx) @@ -140,7 +136,7 @@ void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES& DonneesAnnuelles, int N Probleme->NombreDeContraintesCoupes = 0; - ProbSpx = SPX_Simplexe(Probleme, ProbSpx); + ProbSpx = SPX_Simplexe(Probleme.get(), ProbSpx); if (ProbSpx) ProblemeHydraulique.ProblemeSpx[NumeroDeReservoir] = (void*)ProbSpx; From b450b92d971fd7e21084d209114271c2134ff1db Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Fri, 22 Sep 2023 13:57:22 +0200 Subject: [PATCH 34/42] [FIX] Try fixing windows unfeasible --- src/solver/hydro/daily/h2o_j_fonctions.h | 2 +- src/solver/hydro/daily/h2o_j_instanciation.cpp | 4 ++-- src/solver/hydro/management/daily.cpp | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/solver/hydro/daily/h2o_j_fonctions.h b/src/solver/hydro/daily/h2o_j_fonctions.h index 75afd34c69..5614e98d12 100644 --- a/src/solver/hydro/daily/h2o_j_fonctions.h +++ b/src/solver/hydro/daily/h2o_j_fonctions.h @@ -28,7 +28,7 @@ #ifndef __SOLVER_H2O_J_FONCTIONS__ #define __SOLVER_H2O_J_FONCTIONS__ -std::unique_ptr H2O_J_Instanciation(void); +DONNEES_MENSUELLES* H2O_J_Instanciation(void); void H2O_J_OptimiserUnMois(DONNEES_MENSUELLES*); void H2O_J_Free(DONNEES_MENSUELLES*); diff --git a/src/solver/hydro/daily/h2o_j_instanciation.cpp b/src/solver/hydro/daily/h2o_j_instanciation.cpp index 746ab17def..7065756843 100644 --- a/src/solver/hydro/daily/h2o_j_instanciation.cpp +++ b/src/solver/hydro/daily/h2o_j_instanciation.cpp @@ -28,9 +28,9 @@ #include "h2o_j_donnees_mensuelles.h" #include "h2o_j_fonctions.h" -std::unique_ptr H2O_J_Instanciation(void) +DONNEES_MENSUELLES* H2O_J_Instanciation(void) { - std::unique_ptr DonneesMensuelles = std::make_unique(); + DONNEES_MENSUELLES* DonneesMensuelles = new DONNEES_MENSUELLES; PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesMensuelles->ProblemeHydraulique; diff --git a/src/solver/hydro/management/daily.cpp b/src/solver/hydro/management/daily.cpp index e987e58022..abaa7cd4b8 100644 --- a/src/solver/hydro/management/daily.cpp +++ b/src/solver/hydro/management/daily.cpp @@ -389,7 +389,7 @@ inline void HydroManagement::prepareDailyOptimalGenerations(Solver::Variable::St uint firstDay = calendar_.months[simulationMonth].daysYear.first; uint endDay = firstDay + daysPerMonth; - auto problem = H2O_J_Instanciation(); + DONNEES_MENSUELLES* problem = H2O_J_Instanciation(); H2O_J_AjouterBruitAuCout(*problem); problem->NombreDeJoursDuMois = (int)daysPerMonth; problem->TurbineDuMois = data.MOG[realmonth]; @@ -403,7 +403,7 @@ inline void HydroManagement::prepareDailyOptimalGenerations(Solver::Variable::St dayMonth++; } - H2O_J_OptimiserUnMois(problem.get()); + H2O_J_OptimiserUnMois(problem); switch (problem->ResultatsValides) { case OUI: @@ -422,7 +422,7 @@ inline void HydroManagement::prepareDailyOptimalGenerations(Solver::Variable::St break; } - H2O_J_Free(problem.get()); + H2O_J_Free(problem); #ifndef NDEBUG for (uint day = firstDay; day != endDay; ++day) From ffd40a994f1b8f20dd3457e8ff4273503bcf0845 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Fri, 22 Sep 2023 15:08:05 +0200 Subject: [PATCH 35/42] [FIX] Code smell --- src/solver/hydro/daily/h2o_j_lisser_les_sur_turbines.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/solver/hydro/daily/h2o_j_lisser_les_sur_turbines.cpp b/src/solver/hydro/daily/h2o_j_lisser_les_sur_turbines.cpp index 4f1381fb7e..5a5c5ea66f 100644 --- a/src/solver/hydro/daily/h2o_j_lisser_les_sur_turbines.cpp +++ b/src/solver/hydro/daily/h2o_j_lisser_les_sur_turbines.cpp @@ -58,7 +58,8 @@ void H2O_J_LisserLesSurTurbines(DONNEES_MENSUELLES* DonneesMensuelles, int Numer int NbCycles = 0; BoucleDeRepartition: - int Np = std::count(flag.begin(), flag.end(), true); + const int Np = std::count(flag.begin(), flag.end(), true); + if (Np == 0) return; @@ -77,7 +78,7 @@ void H2O_J_LisserLesSurTurbines(DONNEES_MENSUELLES* DonneesMensuelles, int Numer else SurTurbine = MargeMin; - bool limiteAtteinte = 0; + bool limiteAtteinte = false; for (int Pdt = 0; Pdt < NbPdt; Pdt++) { if (!flag[Pdt]) From 19acabb0077002a236e0a45f588fdf4a104d53ab Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Mon, 25 Sep 2023 16:34:50 +0200 Subject: [PATCH 36/42] [DEV] Use pointer instead of copy --- src/solver/hydro/monthly/h2o_m_ajouter_bruit.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/solver/hydro/monthly/h2o_m_ajouter_bruit.cpp b/src/solver/hydro/monthly/h2o_m_ajouter_bruit.cpp index 3b0c1ada26..a597ada34a 100644 --- a/src/solver/hydro/monthly/h2o_m_ajouter_bruit.cpp +++ b/src/solver/hydro/monthly/h2o_m_ajouter_bruit.cpp @@ -22,13 +22,13 @@ void H2O_M_AjouterBruitAuCout(DONNEES_ANNUELLES& DonneesAnnuelles) Antares::MersenneTwister noiseGenerator; noiseGenerator.reset(Constants::seed); // Arbitrary seed, hard-coded since we don't really want // the user to change it - const std::vector> monthlyVariables - = {CorrespondanceDesVariables.NumeroDeVariableVolume, - CorrespondanceDesVariables.NumeroDeVariableTurbine, - CorrespondanceDesVariables.NumeroDeVariableDepassementVolumeMax, - CorrespondanceDesVariables.NumeroDeVariableDepassementVolumeMin, - CorrespondanceDesVariables.NumeroDeVariableDEcartPositifAuTurbineCible, - CorrespondanceDesVariables.NumeroDeVariableDEcartNegatifAuTurbineCible}; + const std::vector& monthlyVariables + = {CorrespondanceDesVariables.NumeroDeVariableVolume.data(), + CorrespondanceDesVariables.NumeroDeVariableTurbine.data(), + CorrespondanceDesVariables.NumeroDeVariableDepassementVolumeMax.data(), + CorrespondanceDesVariables.NumeroDeVariableDepassementVolumeMin.data(), + CorrespondanceDesVariables.NumeroDeVariableDEcartPositifAuTurbineCible.data(), + CorrespondanceDesVariables.NumeroDeVariableDEcartNegatifAuTurbineCible.data()}; for (const auto variable : monthlyVariables) { From d69d7a39c9745e5470ed0901a676f827dd142136 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Mon, 25 Sep 2023 16:42:40 +0200 Subject: [PATCH 37/42] [DEV] remove h2o_m_sys.h --- src/solver/hydro/CMakeLists.txt | 1 - .../monthly/h2o_m_donnees_optimisation.h | 2 +- src/solver/hydro/monthly/h2o_m_sys.h | 40 ------------------- 3 files changed, 1 insertion(+), 42 deletions(-) delete mode 100644 src/solver/hydro/monthly/h2o_m_sys.h diff --git a/src/solver/hydro/CMakeLists.txt b/src/solver/hydro/CMakeLists.txt index e600e34406..09e5b8b073 100644 --- a/src/solver/hydro/CMakeLists.txt +++ b/src/solver/hydro/CMakeLists.txt @@ -30,7 +30,6 @@ set(SRC_EXT_SOLVER_H2O_MONTHLY monthly/h2o_m_optimiser_une_annee.cpp monthly/h2o_m_ajouter_bruit.cpp monthly/h2o_m_resoudre_le_probleme_lineaire.cpp - monthly/h2o_m_sys.h ) set(SRC_EXT_SOLVER_H2O2_DAILY diff --git a/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h b/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h index 15c3fc1bed..0ff290ac78 100644 --- a/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h +++ b/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h @@ -27,7 +27,7 @@ #ifndef __SOLVER_H2O_M_STRUCTURE_INTERNE__ #define __SOLVER_H2O_M_STRUCTURE_INTERNE__ -#include "h2o_m_sys.h" +#include #define LINFINI 1.e+80 diff --git a/src/solver/hydro/monthly/h2o_m_sys.h b/src/solver/hydro/monthly/h2o_m_sys.h deleted file mode 100644 index 5a254bd647..0000000000 --- a/src/solver/hydro/monthly/h2o_m_sys.h +++ /dev/null @@ -1,40 +0,0 @@ -/* -** Copyright 2007-2023 RTE -** Authors: Antares_Simulator Team -** -** This file is part of Antares_Simulator. -** -** Antares_Simulator is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** There are special exceptions to the terms and conditions of the -** license as they are applied to this software. View the full text of -** the exceptions in file COPYING.txt in the directory of this software -** distribution -** -** Antares_Simulator is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with Antares_Simulator. If not, see . -** -** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions -*/ -#ifndef __SOLVER_H2O_M_SYS__ -#define __SOLVER_H2O_M_SYS__ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#endif /* __SOLVER_H2O_M_SYS__ */ From e38709bb655562cfdef4198259e3c7dc1061ec6c Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Mon, 25 Sep 2023 16:58:42 +0200 Subject: [PATCH 38/42] [DEV] remove h2o_j_sys.h --- src/solver/hydro/CMakeLists.txt | 1 - .../hydro/daily/h2o_j_donnees_optimisation.h | 2 - src/solver/hydro/daily/h2o_j_sys.h | 39 ------------------- 3 files changed, 42 deletions(-) delete mode 100644 src/solver/hydro/daily/h2o_j_sys.h diff --git a/src/solver/hydro/CMakeLists.txt b/src/solver/hydro/CMakeLists.txt index 09e5b8b073..8656eb100a 100644 --- a/src/solver/hydro/CMakeLists.txt +++ b/src/solver/hydro/CMakeLists.txt @@ -13,7 +13,6 @@ set(SRC_EXT_SOLVER_H2O_DAILY daily/h2o_j_optimiser_un_mois.cpp daily/h2o_j_resoudre_le_probleme_lineaire.cpp daily/h2o_j_lisser_les_sur_turbines.cpp - daily/h2o_j_sys.h daily/h2o_j_ajouter_bruit_au_cout.cpp ) diff --git a/src/solver/hydro/daily/h2o_j_donnees_optimisation.h b/src/solver/hydro/daily/h2o_j_donnees_optimisation.h index 77126b0e04..35875499e9 100644 --- a/src/solver/hydro/daily/h2o_j_donnees_optimisation.h +++ b/src/solver/hydro/daily/h2o_j_donnees_optimisation.h @@ -27,8 +27,6 @@ #ifndef __SOLVER_H2O_J_STRUCTURE_INTERNE__ #define __SOLVER_H2O_J_STRUCTURE_INTERNE__ -#include "h2o_j_sys.h" - #define LINFINI 1.e+80 #define JOURS_28 28 diff --git a/src/solver/hydro/daily/h2o_j_sys.h b/src/solver/hydro/daily/h2o_j_sys.h deleted file mode 100644 index 77e9fb1e98..0000000000 --- a/src/solver/hydro/daily/h2o_j_sys.h +++ /dev/null @@ -1,39 +0,0 @@ -/* -** Copyright 2007-2023 RTE -** Authors: Antares_Simulator Team -** -** This file is part of Antares_Simulator. -** -** Antares_Simulator is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** There are special exceptions to the terms and conditions of the -** license as they are applied to this software. View the full text of -** the exceptions in file COPYING.txt in the directory of this software -** distribution -** -** Antares_Simulator is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with Antares_Simulator. If not, see . -** -** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions -*/ -#ifndef __SOLVER_H2O_J_SYS__ -#define __SOLVER_H2O_J_SYS__ - -#include -#include -#include -#include -#include -#include -#include -#include - -#endif /* __SOLVER_H2O_J_SYS__ */ From e47373ba8a1d4afd60ac16f9457ddea67f72b7ec Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Mon, 25 Sep 2023 17:00:17 +0200 Subject: [PATCH 39/42] [FIX] Compile --- src/solver/hydro/daily/h2o_j_resoudre_le_probleme_lineaire.cpp | 2 ++ src/solver/hydro/daily2/h2o2_j_donnees_optimisation.h | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/solver/hydro/daily/h2o_j_resoudre_le_probleme_lineaire.cpp b/src/solver/hydro/daily/h2o_j_resoudre_le_probleme_lineaire.cpp index c5df253c29..c81ce6d1b5 100644 --- a/src/solver/hydro/daily/h2o_j_resoudre_le_probleme_lineaire.cpp +++ b/src/solver/hydro/daily/h2o_j_resoudre_le_probleme_lineaire.cpp @@ -46,6 +46,8 @@ extern "C" #define SNPRINTF snprintf #endif +#include + void H2O_J_ResoudreLeProblemeLineaire(DONNEES_MENSUELLES* DonneesMensuelles, int NumeroDeProbleme) { PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesMensuelles->ProblemeHydraulique; diff --git a/src/solver/hydro/daily2/h2o2_j_donnees_optimisation.h b/src/solver/hydro/daily2/h2o2_j_donnees_optimisation.h index a6733498b2..ebe098de3a 100644 --- a/src/solver/hydro/daily2/h2o2_j_donnees_optimisation.h +++ b/src/solver/hydro/daily2/h2o2_j_donnees_optimisation.h @@ -27,7 +27,6 @@ #ifndef __SOLVER_H2O2_J_STRUCTURE_INTERNE__ #define __SOLVER_H2O2_J_STRUCTURE_INTERNE__ -#include "../daily/h2o_j_sys.h" #include "../daily/h2o_j_donnees_optimisation.h" #include #include From bbe7c31dc43ce18e2d4c1c581a49ea08f66a5677 Mon Sep 17 00:00:00 2001 From: Florian OMNES Date: Mon, 25 Sep 2023 17:30:22 +0200 Subject: [PATCH 40/42] Fix monthlyVariables --- src/solver/hydro/monthly/h2o_m_ajouter_bruit.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/solver/hydro/monthly/h2o_m_ajouter_bruit.cpp b/src/solver/hydro/monthly/h2o_m_ajouter_bruit.cpp index a597ada34a..a7864c8af0 100644 --- a/src/solver/hydro/monthly/h2o_m_ajouter_bruit.cpp +++ b/src/solver/hydro/monthly/h2o_m_ajouter_bruit.cpp @@ -22,19 +22,19 @@ void H2O_M_AjouterBruitAuCout(DONNEES_ANNUELLES& DonneesAnnuelles) Antares::MersenneTwister noiseGenerator; noiseGenerator.reset(Constants::seed); // Arbitrary seed, hard-coded since we don't really want // the user to change it - const std::vector& monthlyVariables - = {CorrespondanceDesVariables.NumeroDeVariableVolume.data(), - CorrespondanceDesVariables.NumeroDeVariableTurbine.data(), - CorrespondanceDesVariables.NumeroDeVariableDepassementVolumeMax.data(), - CorrespondanceDesVariables.NumeroDeVariableDepassementVolumeMin.data(), - CorrespondanceDesVariables.NumeroDeVariableDEcartPositifAuTurbineCible.data(), - CorrespondanceDesVariables.NumeroDeVariableDEcartNegatifAuTurbineCible.data()}; + const std::vector*> monthlyVariables + = {&CorrespondanceDesVariables.NumeroDeVariableVolume, + &CorrespondanceDesVariables.NumeroDeVariableTurbine, + &CorrespondanceDesVariables.NumeroDeVariableDepassementVolumeMax, + &CorrespondanceDesVariables.NumeroDeVariableDepassementVolumeMin, + &CorrespondanceDesVariables.NumeroDeVariableDEcartPositifAuTurbineCible, + &CorrespondanceDesVariables.NumeroDeVariableDEcartNegatifAuTurbineCible}; for (const auto variable : monthlyVariables) { for (int Pdt = 0; Pdt < DonneesAnnuelles.NombreDePasDeTemps; Pdt++) { - int Var = variable[Pdt]; + int Var = (*variable)[Pdt]; CoutLineaireBruite[Var] = CoutLineaire[Var] + noiseGenerator() * Constants::noiseAmplitude; } From 47036531b83a31da8bfcc4727d15ae1c3c36e746 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Mon, 25 Sep 2023 17:34:57 +0200 Subject: [PATCH 41/42] [DEV] Minor improvement for var looping --- src/solver/hydro/monthly/h2o_m_ajouter_bruit.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/solver/hydro/monthly/h2o_m_ajouter_bruit.cpp b/src/solver/hydro/monthly/h2o_m_ajouter_bruit.cpp index a7864c8af0..55ce86209e 100644 --- a/src/solver/hydro/monthly/h2o_m_ajouter_bruit.cpp +++ b/src/solver/hydro/monthly/h2o_m_ajouter_bruit.cpp @@ -30,11 +30,11 @@ void H2O_M_AjouterBruitAuCout(DONNEES_ANNUELLES& DonneesAnnuelles) &CorrespondanceDesVariables.NumeroDeVariableDEcartPositifAuTurbineCible, &CorrespondanceDesVariables.NumeroDeVariableDEcartNegatifAuTurbineCible}; - for (const auto variable : monthlyVariables) + for (const auto& variable : monthlyVariables) { - for (int Pdt = 0; Pdt < DonneesAnnuelles.NombreDePasDeTemps; Pdt++) + for (const auto& v : *variable) { - int Var = (*variable)[Pdt]; + int Var = v; CoutLineaireBruite[Var] = CoutLineaire[Var] + noiseGenerator() * Constants::noiseAmplitude; } From d70e160d9f1b587f46ba972887203b868e2223e3 Mon Sep 17 00:00:00 2001 From: Florian OMNES Date: Mon, 25 Sep 2023 17:42:00 +0200 Subject: [PATCH 42/42] Simplify, add const qualifier --- src/solver/hydro/monthly/h2o_m_ajouter_bruit.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/solver/hydro/monthly/h2o_m_ajouter_bruit.cpp b/src/solver/hydro/monthly/h2o_m_ajouter_bruit.cpp index 55ce86209e..113b972117 100644 --- a/src/solver/hydro/monthly/h2o_m_ajouter_bruit.cpp +++ b/src/solver/hydro/monthly/h2o_m_ajouter_bruit.cpp @@ -22,7 +22,7 @@ void H2O_M_AjouterBruitAuCout(DONNEES_ANNUELLES& DonneesAnnuelles) Antares::MersenneTwister noiseGenerator; noiseGenerator.reset(Constants::seed); // Arbitrary seed, hard-coded since we don't really want // the user to change it - const std::vector*> monthlyVariables + const std::vector*> monthlyVariables = {&CorrespondanceDesVariables.NumeroDeVariableVolume, &CorrespondanceDesVariables.NumeroDeVariableTurbine, &CorrespondanceDesVariables.NumeroDeVariableDepassementVolumeMax, @@ -32,9 +32,8 @@ void H2O_M_AjouterBruitAuCout(DONNEES_ANNUELLES& DonneesAnnuelles) for (const auto& variable : monthlyVariables) { - for (const auto& v : *variable) + for (int Var : *variable) { - int Var = v; CoutLineaireBruite[Var] = CoutLineaire[Var] + noiseGenerator() * Constants::noiseAmplitude; }