diff --git a/src/solver/hydro/CMakeLists.txt b/src/solver/hydro/CMakeLists.txt index e600e34406..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 ) @@ -30,7 +29,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/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_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_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_free.cpp b/src/solver/hydro/daily/h2o_j_free.cpp index d8eed93a43..d19196ab49 100644 --- a/src/solver/hydro/daily/h2o_j_free.cpp +++ b/src/solver/hydro/daily/h2o_j_free.cpp @@ -51,7 +51,5 @@ void H2O_J_Free(DONNEES_MENSUELLES* DonneesMensuelles) SPX_LibererProbleme(ProbSpx); } - free(ProblemeHydraulique.Probleme); - return; } 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..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 @@ -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]; + const 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..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 @@ -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++) + const 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_instanciation.cpp b/src/solver/hydro/daily/h2o_j_instanciation.cpp index fa0ecf5fa7..7065756843 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; @@ -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 463d9b6ec4..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 @@ -28,102 +28,72 @@ #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) { - 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; + auto& Turbine = DonneesMensuelles->Turbine; + const auto& TurbineMax = DonneesMensuelles->TurbineMax; + const auto& TurbineCible = DonneesMensuelles->TurbineCible; - Flag = (char*) ProblemeHydraulique.ProblemeLineairePartieVariable[NumeroDeProbleme].Xmax.data(); + const int NbPdt = ProblemeHydraulique.NbJoursDUnProbleme[NumeroDeProbleme]; - NbPdt = ProblemeHydraulique.NbJoursDUnProbleme[NumeroDeProbleme]; + std::vector flag(NbPdt); - SurTurbineARepartir = 0.0; - for (Pdt = 0; Pdt < NbPdt; Pdt++) - { - Flag[Pdt] = 0; - if (Turbine[Pdt] - TurbineCible[Pdt] > ZERO) - Flag[Pdt] = 1; - } + double SurTurbineARepartir = 0.0; + for (int Pdt = 0; Pdt < NbPdt; Pdt++) + flag[Pdt] = (Turbine[Pdt] - TurbineCible[Pdt] > ZERO); - for (Pdt = 0; Pdt < NbPdt; Pdt++) - { - if (Flag[Pdt] == 1) + for (int Pdt = 0; Pdt < NbPdt; Pdt++) + if (flag[Pdt]) SurTurbineARepartir += Turbine[Pdt] - TurbineCible[Pdt]; - } - for (Pdt = 0; Pdt < NbPdt; Pdt++) - Flag[Pdt] = 0; - for (Pdt = 0; Pdt < NbPdt; Pdt++) - { - if (TurbineMax[Pdt] - TurbineCible[Pdt] > ZERO) - Flag[Pdt] = 1; - } + for (int Pdt = 0; Pdt < NbPdt; Pdt++) + flag[Pdt] = (TurbineMax[Pdt] - TurbineCible[Pdt] > ZERO);; - NbCycles = 0; + int NbCycles = 0; BoucleDeRepartition: - Np = 0; - for (Pdt = 0; Pdt < NbPdt; Pdt++) - { - if (Flag[Pdt] == 1) - Np++; - } - if (Np <= 0) - { + const int Np = std::count(flag.begin(), flag.end(), true); + + if (Np == 0) 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++) - { - if (Flag[Pdt] == 1) - { - if (TurbineMax[Pdt] - TurbineCible[Pdt] < MargeMin) - MargeMin = TurbineMax[Pdt] - TurbineCible[Pdt]; - } - } - Xmoy = SurTurbineARepartir / Np; + for (int Pdt = 0; Pdt < NbPdt; Pdt++) + if (flag[Pdt] && TurbineMax[Pdt] - TurbineCible[Pdt] < MargeMin) + MargeMin = TurbineMax[Pdt] - TurbineCible[Pdt]; + + double Xmoy = SurTurbineARepartir / Np; + double SurTurbine; if (Xmoy <= MargeMin) SurTurbine = Xmoy; else SurTurbine = MargeMin; - LimiteAtteinte = 0; - for (Pdt = 0; Pdt < NbPdt; Pdt++) + bool limiteAtteinte = false; + 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) 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..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,18 +46,10 @@ extern "C" #define SNPRINTF snprintf #endif +#include + 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,23 +58,20 @@ 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]; + std::unique_ptr Probleme = std::make_unique(); - Probleme = (PROBLEME_SIMPLEXE*)ProblemeHydraulique.Probleme; - if (Probleme == NULL) + if (!Probleme) { - Probleme = (PROBLEME_SIMPLEXE*)malloc(sizeof(PROBLEME_SIMPLEXE)); - if (Probleme == NULL) - { - DonneesMensuelles->ResultatsValides = EMERGENCY_SHUT_DOWN; - return; - } - ProblemeHydraulique.Probleme = (void*)Probleme; + DonneesMensuelles->ResultatsValides = EMERGENCY_SHUT_DOWN; + return; } + bool PremierPassage = true; + RESOLUTION: - if (ProbSpx == NULL) + if (!ProbSpx) { Probleme->Contexte = SIMPLEXE_SEUL; Probleme->BaseDeDepartFournie = NON_SPX; @@ -138,7 +127,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; @@ -148,24 +137,21 @@ void H2O_J_ResoudreLeProblemeLineaire(DONNEES_MENSUELLES* DonneesMensuelles, int Probleme->NombreDeContraintesCoupes = 0; - ProbSpx = SPX_Simplexe(Probleme, ProbSpx); + ProbSpx = SPX_Simplexe(Probleme.get(), ProbSpx); - if (ProbSpx != NULL) - { + if (ProbSpx) ProblemeHydraulique.ProblemeSpx[NumeroDeProbleme] = (void*)ProbSpx; - } 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 @@ -179,13 +165,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 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 f2c6b9ba09..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__ */ 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 diff --git a/src/solver/hydro/management/daily.cpp b/src/solver/hydro/management/daily.cpp index 04c851b581..abe4f9fab4 100644 --- a/src/solver/hydro/management/daily.cpp +++ b/src/solver/hydro/management/daily.cpp @@ -257,7 +257,7 @@ inline void HydroManagement::prepareDailyOptimalGenerations(Solver::Variable::St auto const& maxE = maxPower[Data::PartHydro::genMaxE]; auto& ventilationResults = ventilationResults_[numSpace][z]; - + std::shared_ptr debugData(nullptr); if (parameters_.hydroDebug) @@ -389,28 +389,28 @@ inline void HydroManagement::prepareDailyOptimalGenerations(Solver::Variable::St uint firstDay = 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) { - ventilationResults.HydrauliqueModulableQuotidien[day] = problem.Turbine[dayMonth]; + ventilationResults.HydrauliqueModulableQuotidien[day] = problem->Turbine[dayMonth]; dayMonth++; } break; @@ -422,7 +422,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) @@ -474,7 +474,7 @@ inline void HydroManagement::prepareDailyOptimalGenerations(Solver::Variable::St uint dayMonth = 0; for (uint day = firstDay; day != endDay; ++day) { - problem.TurbineMax[dayMonth] = maxP[day] * maxE[day] / reservoirCapacity; + problem.TurbineMax[dayMonth] = maxP[day] * maxE[day] / reservoirCapacity; problem.TurbineMin[dayMonth] = data.dailyMinGen[day] / reservoirCapacity; problem.TurbineCible[dayMonth] diff --git a/src/solver/hydro/management/monthly.cpp b/src/solver/hydro/management/monthly.cpp index dae771b2e3..c526916f4e 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) @@ -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; } @@ -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_ajouter_bruit.cpp b/src/solver/hydro/monthly/h2o_m_ajouter_bruit.cpp index 9bd90bac18..113b972117 100644 --- a/src/solver/hydro/monthly/h2o_m_ajouter_bruit.cpp +++ b/src/solver/hydro/monthly/h2o_m_ajouter_bruit.cpp @@ -9,49 +9,38 @@ 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) { - 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 // 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) + for (const auto& variable : monthlyVariables) { - for (Pdt = 0; Pdt < NbPdt; Pdt++) + for (int Var : *variable) { - 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; + 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 c9d17cca84..3e1b61ec93 100644 --- a/src/solver/hydro/monthly/h2o_m_construire_les_contraintes.cpp +++ b/src/solver/hydro/monthly/h2o_m_construire_les_contraintes.cpp @@ -28,61 +28,39 @@ #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; - int Pdt; - int NbPdt; - double* CoefficientsDeLaMatriceDesContraintes; - int* IndicesColonnes; - int* IndicesDebutDeLigne; - int* NombreDeTermesDesLignes; - char* Sens; - 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; - - NbPdt = DonneesAnnuelles->NombreDePasDeTemps; - - ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; - CorrespondanceDesVariables = ProblemeHydraulique->CorrespondanceDesVariables; - ProblemeLineairePartieFixe = ProblemeHydraulique->ProblemeLineairePartieFixe; - - CoefficientsDeLaMatriceDesContraintes - = ProblemeLineairePartieFixe->CoefficientsDeLaMatriceDesContraintes; - IndicesColonnes = ProblemeLineairePartieFixe->IndicesColonnes; - IndicesDebutDeLigne = ProblemeLineairePartieFixe->IndicesDebutDeLigne; - Sens = ProblemeLineairePartieFixe->Sens; - NombreDeTermesDesLignes = ProblemeLineairePartieFixe->NombreDeTermesDesLignes; - - NumeroDeVariableVolume = CorrespondanceDesVariables->NumeroDeVariableVolume; - NumeroDeVariableTurbine = CorrespondanceDesVariables->NumeroDeVariableTurbine; - NumeroDeVariableDepassementVolumeMax - = CorrespondanceDesVariables->NumeroDeVariableDepassementVolumeMax; - NumeroDeVariableDepassementVolumeMin - = CorrespondanceDesVariables->NumeroDeVariableDepassementVolumeMin; - NumeroDeVariableDEcartPositifAuTurbineCible - = CorrespondanceDesVariables->NumeroDeVariableDEcartPositifAuTurbineCible; - NumeroDeVariableDEcartNegatifAuTurbineCible - = CorrespondanceDesVariables->NumeroDeVariableDEcartNegatifAuTurbineCible; - NumeroDeLaVariableXi = CorrespondanceDesVariables->NumeroDeLaVariableXi; - - NombreDeContraintes = 0; - il = 0; - - for (Pdt = 1; Pdt < NbPdt; Pdt++) + PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesAnnuelles.ProblemeHydraulique; + CORRESPONDANCE_DES_VARIABLES& CorrespondanceDesVariables + = ProblemeHydraulique.CorrespondanceDesVariables; + 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; + + auto& NumeroDeVariableVolume = CorrespondanceDesVariables.NumeroDeVariableVolume; + auto& NumeroDeVariableTurbine = CorrespondanceDesVariables.NumeroDeVariableTurbine; + auto& NumeroDeVariableDepassementVolumeMax + = CorrespondanceDesVariables.NumeroDeVariableDepassementVolumeMax; + auto& NumeroDeVariableDepassementVolumeMin + = CorrespondanceDesVariables.NumeroDeVariableDepassementVolumeMin; + auto& NumeroDeVariableDEcartPositifAuTurbineCible + = CorrespondanceDesVariables.NumeroDeVariableDEcartPositifAuTurbineCible; + auto& NumeroDeVariableDEcartNegatifAuTurbineCible + = CorrespondanceDesVariables.NumeroDeVariableDEcartNegatifAuTurbineCible; + int NumeroDeLaVariableXi = CorrespondanceDesVariables.NumeroDeLaVariableXi; + + double ChgmtSens = -1.0; + const int NbPdt = DonneesAnnuelles.NombreDePasDeTemps; + int NombreDeContraintes = 0; + int il = 0; + + for (int Pdt = 1; Pdt < NbPdt; Pdt++) { IndicesDebutDeLigne[NombreDeContraintes] = il; @@ -117,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; @@ -125,8 +103,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] = '<'; @@ -148,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; @@ -157,7 +135,7 @@ void H2O_M_ConstruireLesContraintes(DONNEES_ANNUELLES* DonneesAnnuelles) il++; CoefficientsDeLaMatriceDesContraintes[il] = -1.0; - IndicesColonnes[il] = CorrespondanceDesVariables->NumeroDeLaVariableViolMaxVolumeMin; + IndicesColonnes[il] = CorrespondanceDesVariables.NumeroDeLaVariableViolMaxVolumeMin; il++; Sens[NombreDeContraintes] = '<'; @@ -165,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; @@ -204,7 +182,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 d4adcbf5bb..93eb7d297f 100644 --- a/src/solver/hydro/monthly/h2o_m_construire_les_variables.cpp +++ b/src/solver/hydro/monthly/h2o_m_construire_les_variables.cpp @@ -39,105 +39,98 @@ 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; - CORRESPONDANCE_DES_VARIABLES* CorrespondanceDesVariables; - PROBLEME_LINEAIRE_PARTIE_FIXE* ProblemeLineairePartieFixe; - PROBLEME_LINEAIRE_PARTIE_VARIABLE* ProblemeLineairePartieVariable; - - NbPdt = DonneesAnnuelles->NombreDePasDeTemps; - - ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; - CorrespondanceDesVariables = ProblemeHydraulique->CorrespondanceDesVariables; - ProblemeLineairePartieFixe = ProblemeHydraulique->ProblemeLineairePartieFixe; - ProblemeLineairePartieVariable = ProblemeHydraulique->ProblemeLineairePartieVariable; - - Var = 0; - - Pdt = 0; - CorrespondanceDesVariables->NumeroDeVariableVolume[Pdt] = 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]); + 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; + + const int NbPdt = DonneesAnnuelles.NombreDePasDeTemps; + int Var = 0; + + 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[0]); Var++; - for (Pdt = 1; Pdt < NbPdt; Pdt++) + for (int Pdt = 1; Pdt < NbPdt; Pdt++) { - CorrespondanceDesVariables->NumeroDeVariableVolume[Pdt] = 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]); + CorrespondanceDesVariables.NumeroDeVariableVolume[Pdt] = 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]); Var++; } - for (Pdt = 0; Pdt < NbPdt; Pdt++) + for (int Pdt = 0; Pdt < NbPdt; Pdt++) { - CorrespondanceDesVariables->NumeroDeVariableTurbine[Pdt] = Var; - ProblemeLineairePartieVariable->Xmin[Var] = 0.0; - ProblemeLineairePartieVariable->Xmax[Var] = 0.0; - ProblemeLineairePartieFixe->TypeDeVariable[Var] = VARIABLE_BORNEE_DES_DEUX_COTES; - ProblemeLineairePartieVariable->AdresseOuPlacerLaValeurDesVariablesOptimisees[Var] - = &(DonneesAnnuelles->Turbine[Pdt]); + CorrespondanceDesVariables.NumeroDeVariableTurbine[Pdt] = Var; + ProblemeLineairePartieVariable.Xmin[Var] = 0.0; + ProblemeLineairePartieVariable.Xmax[Var] = 0.0; + ProblemeLineairePartieFixe.TypeDeVariable[Var] = VARIABLE_BORNEE_DES_DEUX_COTES; + ProblemeLineairePartieVariable.AdresseOuPlacerLaValeurDesVariablesOptimisees[Var] + = &(DonneesAnnuelles.Turbine[Pdt]); Var++; } - for (Pdt = 0; Pdt < NbPdt; Pdt++) + for (int Pdt = 0; Pdt < NbPdt; Pdt++) { - CorrespondanceDesVariables->NumeroDeVariableDepassementVolumeMax[Pdt] = Var; - ProblemeLineairePartieVariable->Xmin[Var] = 0.0; - ProblemeLineairePartieVariable->Xmax[Var] = LINFINI; - ProblemeLineairePartieFixe->TypeDeVariable[Var] = VARIABLE_BORNEE_INFERIEUREMENT; + CorrespondanceDesVariables.NumeroDeVariableDepassementVolumeMax[Pdt] = Var; + ProblemeLineairePartieVariable.Xmin[Var] = 0.0; + ProblemeLineairePartieVariable.Xmax[Var] = LINFINI; + ProblemeLineairePartieFixe.TypeDeVariable[Var] = VARIABLE_BORNEE_INFERIEUREMENT; Var++; } - for (Pdt = 0; Pdt < NbPdt; Pdt++) + for (int Pdt = 0; Pdt < NbPdt; Pdt++) { - CorrespondanceDesVariables->NumeroDeVariableDepassementVolumeMin[Pdt] = Var; - ProblemeLineairePartieVariable->Xmin[Var] = 0.0; - ProblemeLineairePartieVariable->Xmax[Var] = LINFINI; - ProblemeLineairePartieFixe->TypeDeVariable[Var] = VARIABLE_BORNEE_INFERIEUREMENT; + CorrespondanceDesVariables.NumeroDeVariableDepassementVolumeMin[Pdt] = Var; + 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; - ProblemeLineairePartieFixe->TypeDeVariable[Var] = VARIABLE_BORNEE_INFERIEUREMENT; + CorrespondanceDesVariables.NumeroDeLaVariableViolMaxVolumeMin = Var; + ProblemeLineairePartieVariable.Xmin[Var] = 0.0; + ProblemeLineairePartieVariable.Xmax[Var] = LINFINI; + 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; - ProblemeLineairePartieVariable->Xmax[Var] = LINFINI; - ProblemeLineairePartieFixe->TypeDeVariable[Var] = VARIABLE_BORNEE_INFERIEUREMENT; + CorrespondanceDesVariables.NumeroDeVariableDEcartPositifAuTurbineCible[Pdt] = Var; + ProblemeLineairePartieVariable.Xmin[Var] = 0.0; + ProblemeLineairePartieVariable.Xmax[Var] = LINFINI; + ProblemeLineairePartieFixe.TypeDeVariable[Var] = VARIABLE_BORNEE_INFERIEUREMENT; Var++; } - for (Pdt = 0; Pdt < NbPdt; Pdt++) + for (int Pdt = 0; Pdt < NbPdt; Pdt++) { - CorrespondanceDesVariables->NumeroDeVariableDEcartNegatifAuTurbineCible[Pdt] = Var; - ProblemeLineairePartieVariable->Xmin[Var] = 0.0; - ProblemeLineairePartieVariable->Xmax[Var] = LINFINI; - ProblemeLineairePartieFixe->TypeDeVariable[Var] = VARIABLE_BORNEE_INFERIEUREMENT; + CorrespondanceDesVariables.NumeroDeVariableDEcartNegatifAuTurbineCible[Pdt] = Var; + 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; - ProblemeLineairePartieFixe->TypeDeVariable[Var] = VARIABLE_NON_BORNEE; + CorrespondanceDesVariables.NumeroDeLaVariableXi = Var; + ProblemeLineairePartieVariable.Xmin[Var] = -LINFINI; + ProblemeLineairePartieVariable.Xmax[Var] = LINFINI; + ProblemeLineairePartieFixe.TypeDeVariable[Var] = VARIABLE_NON_BORNEE; Var++; - ProblemeLineairePartieFixe->NombreDeVariables = Var; + ProblemeLineairePartieFixe.NombreDeVariables = Var; return; } diff --git a/src/solver/hydro/monthly/h2o_m_donnees_annuelles.h b/src/solver/hydro/monthly/h2o_m_donnees_annuelles.h index b9363cbd0e..175aed380c 100644 --- a/src/solver/hydro/monthly/h2o_m_donnees_annuelles.h +++ b/src/solver/hydro/monthly/h2o_m_donnees_annuelles.h @@ -45,13 +45,13 @@ 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 */ - double* Apport; /* 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 */ + 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,12 +60,12 @@ 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) */ - PROBLEME_HYDRAULIQUE* ProblemeHydraulique; + PROBLEME_HYDRAULIQUE ProblemeHydraulique; int NombreDePasDeTemps; /* 12 */ } DONNEES_ANNUELLES; diff --git a/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h b/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h index c3d56569f4..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 @@ -38,9 +38,9 @@ typedef struct { int NombreDeVariables; - double* CoutLineaire; - double* 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 CoutLineaire; + std::vector CoutLineaireBruite; /* Ajout de bruit pour forcer l'unicité des solutions */ + 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 , @@ -50,11 +50,11 @@ typedef struct */ /* La matrice des contraintes */ int NombreDeContraintes; - char* Sens; - int* IndicesDebutDeLigne; - int* NombreDeTermesDesLignes; - double* CoefficientsDeLaMatriceDesContraintes; - int* IndicesColonnes; + std::vector Sens; + std::vector IndicesDebutDeLigne; + std::vector NombreDeTermesDesLignes; + std::vector CoefficientsDeLaMatriceDesContraintes; + std::vector IndicesColonnes; int NombreDeTermesAlloues; } PROBLEME_LINEAIRE_PARTIE_FIXE; @@ -64,15 +64,15 @@ 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 */ - double** AdresseOuPlacerLaValeurDesVariablesOptimisees; + std::vector 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, @@ -84,23 +84,23 @@ 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 */ - 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 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 */ } PROBLEME_LINEAIRE_PARTIE_VARIABLE; /* 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,12 +110,12 @@ 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; + 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_fonctions.h b/src/solver/hydro/monthly/h2o_m_fonctions.h index b11315743c..aa5a531b28 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); -void H2O_M_Free(DONNEES_ANNUELLES*); +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_free.cpp b/src/solver/hydro/monthly/h2o_m_free.cpp index a027456fe0..be762274e2 100644 --- a/src/solver/hydro/monthly/h2o_m_free.cpp +++ b/src/solver/hydro/monthly/h2o_m_free.cpp @@ -40,69 +40,17 @@ 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; + PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesAnnuelles.ProblemeHydraulique; - 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->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); - - free(ProblemeHydraulique->ProblemeLineairePartieVariable->Xmin); - free(ProblemeHydraulique->ProblemeLineairePartieVariable->Xmax); - free(ProblemeHydraulique->ProblemeLineairePartieVariable->SecondMembre); - 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++) + 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->ProblemeSpx); - free(ProblemeHydraulique->Probleme); - free(ProblemeHydraulique); - - free(DonneesAnnuelles->TurbineMax); - free(DonneesAnnuelles->TurbineMin); - free(DonneesAnnuelles->TurbineCible); - 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_initialiser_les_bornes_des_variables.cpp b/src/solver/hydro/monthly/h2o_m_initialiser_les_bornes_des_variables.cpp index 75ab1880a9..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 @@ -28,87 +28,75 @@ #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 Pdt; - int NbPdt; - int Var; - double* Xmin; - double* Xmax; - double* X; - double* TurbineMax; - const double* TurbineMin; - double* CoutLineaire; - double CoutDepassementVolume; + PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesAnnuelles.ProblemeHydraulique; + PROBLEME_LINEAIRE_PARTIE_VARIABLE& ProblemeLineairePartieVariable + = ProblemeHydraulique.ProblemeLineairePartieVariable; + const CORRESPONDANCE_DES_VARIABLES& CorrespondanceDesVariables + = ProblemeHydraulique.CorrespondanceDesVariables; + PROBLEME_LINEAIRE_PARTIE_FIXE& ProblemeLineairePartieFixe + = ProblemeHydraulique.ProblemeLineairePartieFixe; - const PROBLEME_HYDRAULIQUE* ProblemeHydraulique; - const PROBLEME_LINEAIRE_PARTIE_FIXE* ProblemeLineairePartieFixe; - const PROBLEME_LINEAIRE_PARTIE_VARIABLE* ProblemeLineairePartieVariable; - const CORRESPONDANCE_DES_VARIABLES* CorrespondanceDesVariables; + DonneesAnnuelles.Volume[0] = DonneesAnnuelles.VolumeInitial; - DonneesAnnuelles->Volume[0] = DonneesAnnuelles->VolumeInitial; + const int NbPdt = DonneesAnnuelles.NombreDePasDeTemps; + double CoutDepassementVolume = DonneesAnnuelles.CoutDepassementVolume; + auto& TurbineMax = DonneesAnnuelles.TurbineMax; + const auto& TurbineMin = DonneesAnnuelles.TurbineMin; - NbPdt = DonneesAnnuelles->NombreDePasDeTemps; - CoutDepassementVolume = DonneesAnnuelles->CoutDepassementVolume; - TurbineMax = DonneesAnnuelles->TurbineMax; - TurbineMin = DonneesAnnuelles->TurbineMin; - ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; - ProblemeLineairePartieFixe = ProblemeHydraulique->ProblemeLineairePartieFixe; - ProblemeLineairePartieVariable = ProblemeHydraulique->ProblemeLineairePartieVariable; - CorrespondanceDesVariables = ProblemeHydraulique->CorrespondanceDesVariables; + auto& Xmin = ProblemeLineairePartieVariable.Xmin; + auto& Xmax = ProblemeLineairePartieVariable.Xmax; + auto& X = ProblemeLineairePartieVariable.X; + auto& CoutLineaire = ProblemeLineairePartieFixe.CoutLineaire; - Xmin = ProblemeLineairePartieVariable->Xmin; - Xmax = ProblemeLineairePartieVariable->Xmax; - X = ProblemeLineairePartieVariable->X; - CoutLineaire = ProblemeLineairePartieFixe->CoutLineaire; + int Var = CorrespondanceDesVariables.NumeroDeVariableVolume[0]; + X[Var] = DonneesAnnuelles.Volume[0]; + Xmin[Var] = DonneesAnnuelles.Volume[0]; + Xmax[Var] = DonneesAnnuelles.Volume[0]; - 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]; + 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]; + Var = CorrespondanceDesVariables.NumeroDeVariableTurbine[Pdt]; Xmax[Var] = TurbineMax[Pdt]; Xmin[Var] = TurbineMin[Pdt]; CoutLineaire[Var] = 0.0; } - for (Pdt = 0; Pdt < NbPdt; Pdt++) + for (int Pdt = 0; Pdt < NbPdt; Pdt++) { - Var = CorrespondanceDesVariables->NumeroDeVariableDepassementVolumeMax[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]; + Var = CorrespondanceDesVariables.NumeroDeVariableDepassementVolumeMin[Pdt]; CoutLineaire[Var] = CoutDepassementVolume; } - Var = CorrespondanceDesVariables->NumeroDeLaVariableViolMaxVolumeMin; - CoutLineaire[Var] = DonneesAnnuelles->CoutViolMaxDuVolumeMin; + Var = CorrespondanceDesVariables.NumeroDeLaVariableViolMaxVolumeMin; + CoutLineaire[Var] = DonneesAnnuelles.CoutViolMaxDuVolumeMin; - for (Pdt = 0; Pdt < NbPdt; Pdt++) + for (int Pdt = 0; Pdt < NbPdt; Pdt++) { - Var = CorrespondanceDesVariables->NumeroDeVariableDEcartPositifAuTurbineCible[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]; + 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_initialiser_les_second_membre.cpp b/src/solver/hydro/monthly/h2o_m_initialiser_les_second_membre.cpp index f507114144..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 @@ -28,56 +28,44 @@ #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) { - int Pdt; - int Cnt; - int NbPdt; - double* TurbineCible; - double* SecondMembre; - double ChgmtSens; + PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesAnnuelles.ProblemeHydraulique; + PROBLEME_LINEAIRE_PARTIE_VARIABLE& ProblemeLineairePartieVariable + = ProblemeHydraulique.ProblemeLineairePartieVariable; - PROBLEME_HYDRAULIQUE* ProblemeHydraulique; - PROBLEME_LINEAIRE_PARTIE_VARIABLE* ProblemeLineairePartieVariable; + double ChgmtSens = -1; + const int NbPdt = DonneesAnnuelles.NombreDePasDeTemps; + int Cnt = 0; - ChgmtSens = -1; + auto& TurbineCible = DonneesAnnuelles.TurbineCible; + auto& SecondMembre = ProblemeLineairePartieVariable.SecondMembre; - NbPdt = DonneesAnnuelles->NombreDePasDeTemps; - - TurbineCible = DonneesAnnuelles->TurbineCible; - - 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]; + 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 (Pdt = 1; Pdt < NbPdt; Pdt++) + 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++; } - 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 ed3e5c03fa..e91df7a7be 100644 --- a/src/solver/hydro/monthly/h2o_m_instanciation.cpp +++ b/src/solver/hydro/monthly/h2o_m_instanciation.cpp @@ -28,168 +28,46 @@ #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; - int j; - int NombreDeVariables; - int NombreDeContraintes; - int NombreDeTermesAlloues; - DONNEES_ANNUELLES* DonneesAnnuelles; - PROBLEME_HYDRAULIQUE* ProblemeHydraulique; + DONNEES_ANNUELLES DonneesAnnuelles{}; - CORRESPONDANCE_DES_VARIABLES* CorrespondanceDesVariables; - PROBLEME_LINEAIRE_PARTIE_FIXE* ProblemeLineairePartieFixe; - PROBLEME_LINEAIRE_PARTIE_VARIABLE* ProblemeLineairePartieVariable; + DonneesAnnuelles.NombreDePasDeTemps = 12; + const int NbPdt = DonneesAnnuelles.NombreDePasDeTemps; - DonneesAnnuelles = (DONNEES_ANNUELLES*)malloc(sizeof(DONNEES_ANNUELLES)); - if (DonneesAnnuelles == NULL) - { - return (NULL); - } - DonneesAnnuelles->NombreDePasDeTemps = 12; + DonneesAnnuelles.TurbineMax.assign(NbPdt, 0.); + DonneesAnnuelles.TurbineMin.assign(NbPdt, 0.); + DonneesAnnuelles.TurbineCible.assign(NbPdt, 0.); + DonneesAnnuelles.Turbine.assign(NbPdt, 0.); - NbPdt = DonneesAnnuelles->NombreDePasDeTemps; + DonneesAnnuelles.Apport.assign(NbPdt, 0.); - DonneesAnnuelles->ProblemeHydraulique - = (PROBLEME_HYDRAULIQUE*)malloc(sizeof(PROBLEME_HYDRAULIQUE)); - if (DonneesAnnuelles->ProblemeHydraulique == NULL) - { - return (NULL); - } + DonneesAnnuelles.Volume.assign(NbPdt, 0.); + DonneesAnnuelles.VolumeMin.assign(NbPdt, 0.); + DonneesAnnuelles.VolumeMax.assign(NbPdt, 0.); - 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); - } + PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesAnnuelles.ProblemeHydraulique; - DonneesAnnuelles->TurbineCible = (double*)malloc((unsigned int)NbPdt * sizeof(double)); - if (DonneesAnnuelles->TurbineCible == NULL) - { - return (NULL); - } + ProblemeHydraulique.NombreDeReservoirs = NombreDeReservoirs; - DonneesAnnuelles->Apport = (double*)malloc((unsigned int)NbPdt * sizeof(double)); - if (DonneesAnnuelles->Apport == NULL) - { - return (NULL); - } + ProblemeHydraulique.ProblemeSpx.assign(NombreDeReservoirs, nullptr); + ProblemeHydraulique.Probleme = nullptr; - 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); - } + CORRESPONDANCE_DES_VARIABLES& CorrespondanceDesVariables + = ProblemeHydraulique.CorrespondanceDesVariables; + PROBLEME_LINEAIRE_PARTIE_FIXE& ProblemeLineairePartieFixe + = ProblemeHydraulique.ProblemeLineairePartieFixe; + PROBLEME_LINEAIRE_PARTIE_VARIABLE& ProblemeLineairePartieVariable + = ProblemeHydraulique.ProblemeLineairePartieVariable; - DonneesAnnuelles->Turbine = (double*)malloc((unsigned int)NbPdt * sizeof(double)); - if (DonneesAnnuelles->Turbine == NULL) - { - return (NULL); - } + 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); - DonneesAnnuelles->Volume = (double*)malloc((unsigned int)NbPdt * sizeof(double)); - if (DonneesAnnuelles->Volume == NULL) - { - return (NULL); - } - - ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; - - 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) - { - return (0); - } - - 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) - { - return (0); - } - for (i = 0; i < NombreDeReservoirs; i++) - { - ProblemeHydraulique->ProblemeSpx[i] = NULL; - } - - ProblemeHydraulique->Probleme = NULL; - - 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); - } - - NombreDeVariables = 0; + int NombreDeVariables = 0; NombreDeVariables += NbPdt; NombreDeVariables += NbPdt; NombreDeVariables += NbPdt; @@ -199,27 +77,14 @@ DONNEES_ANNUELLES* H2O_M_Instanciation(int NombreDeReservoirs) NombreDeVariables += NbPdt; 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->TypeDeVariable - = (int*)malloc((unsigned int)NombreDeVariables * sizeof(int)); - if (ProblemeLineairePartieFixe->TypeDeVariable == NULL) - { - return (0); - } + ProblemeLineairePartieFixe.NombreDeVariables = NombreDeVariables; - NombreDeContraintes = 0; + ProblemeLineairePartieFixe.CoutLineaire.assign(NombreDeVariables, 0.); + ProblemeLineairePartieFixe.CoutLineaireBruite.assign(NombreDeVariables, 0.); + + ProblemeLineairePartieFixe.TypeDeVariable.assign(NombreDeVariables, 0); + + int NombreDeContraintes = 0; NombreDeContraintes += NbPdt; NombreDeContraintes += 1; NombreDeContraintes += NbPdt; @@ -228,27 +93,13 @@ DONNEES_ANNUELLES* H2O_M_Instanciation(int NombreDeReservoirs) NombreDeContraintes += NbPdt; NombreDeContraintes += NbPdt; - ProblemeLineairePartieFixe->NombreDeContraintes = NombreDeContraintes; - ProblemeLineairePartieFixe->Sens - = (char*)malloc((unsigned int)NombreDeContraintes * sizeof(char)); - if (ProblemeLineairePartieFixe->Sens == NULL) - { - return (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.NombreDeContraintes = NombreDeContraintes; + ProblemeLineairePartieFixe.Sens.assign(NombreDeContraintes, 0); + + ProblemeLineairePartieFixe.IndicesDebutDeLigne.assign(NombreDeContraintes, 0); + ProblemeLineairePartieFixe.NombreDeTermesDesLignes.assign(NombreDeContraintes, 0); - NombreDeTermesAlloues = 0; + int NombreDeTermesAlloues = 0; NombreDeTermesAlloues += 3 * NbPdt; NombreDeTermesAlloues += 2; NombreDeTermesAlloues += 2 * NbPdt; @@ -257,91 +108,32 @@ DONNEES_ANNUELLES* H2O_M_Instanciation(int NombreDeReservoirs) NombreDeTermesAlloues += 3 * NbPdt; NombreDeTermesAlloues += 3 * NbPdt; - ProblemeLineairePartieFixe->NombreDeTermesAlloues = NombreDeTermesAlloues; - - ProblemeLineairePartieFixe->CoefficientsDeLaMatriceDesContraintes - = (double*)malloc((unsigned int)NombreDeTermesAlloues * sizeof(double)); - if (ProblemeLineairePartieFixe->CoefficientsDeLaMatriceDesContraintes == NULL) - { - return (0); - } - ProblemeLineairePartieFixe->IndicesColonnes - = (int*)malloc((unsigned int)NombreDeTermesAlloues * sizeof(int)); - if (ProblemeLineairePartieFixe->IndicesColonnes == NULL) - { - return (0); - } - - ProblemeLineairePartieVariable->Xmin - = (double*)malloc((unsigned int)NombreDeVariables * sizeof(double)); - if (ProblemeLineairePartieVariable->Xmin == NULL) - { - return (0); - } + ProblemeLineairePartieFixe.NombreDeTermesAlloues = NombreDeTermesAlloues; - 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); - } + ProblemeLineairePartieFixe.CoefficientsDeLaMatriceDesContraintes + .assign(NombreDeTermesAlloues, 0.); - ProblemeLineairePartieVariable->AdresseOuPlacerLaValeurDesVariablesOptimisees - = (double**)malloc((unsigned int)NombreDeVariables * sizeof(double*)); - if (ProblemeLineairePartieVariable->AdresseOuPlacerLaValeurDesVariablesOptimisees == NULL) - { - return (0); - } + ProblemeLineairePartieFixe.IndicesColonnes.assign(NombreDeTermesAlloues, 0); - ProblemeLineairePartieVariable->X - = (double*)malloc((unsigned int)NombreDeVariables * sizeof(double)); - if (ProblemeLineairePartieVariable->X == NULL) - { - return (0); - } + ProblemeLineairePartieVariable.Xmin.assign(NombreDeVariables, 0.); + ProblemeLineairePartieVariable.Xmax.assign(NombreDeVariables, 0.); + ProblemeLineairePartieVariable.SecondMembre.assign(NombreDeContraintes, 0.); - for (j = 0; j < NombreDeVariables; j++) - { - ProblemeLineairePartieVariable->AdresseOuPlacerLaValeurDesVariablesOptimisees[j] = NULL; - } + ProblemeLineairePartieVariable.AdresseOuPlacerLaValeurDesVariablesOptimisees + .assign(NombreDeVariables, nullptr); - ProblemeLineairePartieVariable->PositionDeLaVariable - = (int*)malloc((unsigned int)NombreDeVariables * sizeof(int)); - if (ProblemeLineairePartieVariable->PositionDeLaVariable == NULL) - { - return (0); - } + ProblemeLineairePartieVariable.X.assign(NombreDeVariables, 0.); - ProblemeLineairePartieVariable->ComplementDeLaBase - = (int*)malloc((unsigned int)NombreDeContraintes * sizeof(int)); - if (ProblemeLineairePartieVariable->ComplementDeLaBase == NULL) - { - return (0); - } - ProblemeLineairePartieVariable->CoutsReduits - = (double*)malloc((unsigned int)NombreDeVariables * sizeof(double)); - if (ProblemeLineairePartieVariable->CoutsReduits == NULL) - { - return (0); - } + ProblemeLineairePartieVariable.PositionDeLaVariable.assign(NombreDeVariables, 0); + ProblemeLineairePartieVariable.ComplementDeLaBase.assign(NombreDeContraintes, 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); 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 2e9a0e3a4a..caa489b5d3 100644 --- a/src/solver/hydro/monthly/h2o_m_optimiser_une_annee.cpp +++ b/src/solver/hydro/monthly/h2o_m_optimiser_une_annee.cpp @@ -28,26 +28,21 @@ #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; + 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; + DonneesAnnuelles.ResultatsValides = EMERGENCY_SHUT_DOWN; return; } - DonneesAnnuelles->ResultatsValides = NON; + 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 f89c512e35..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 @@ -46,43 +46,31 @@ extern "C" #define SNPRINTF snprintf #endif -void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES* DonneesAnnuelles, int NumeroDeReservoir) -{ - int Var; - double* pt; - char PremierPassage; - - PROBLEME_HYDRAULIQUE* ProblemeHydraulique; - PROBLEME_LINEAIRE_PARTIE_VARIABLE* ProblemeLineairePartieVariable; - PROBLEME_LINEAIRE_PARTIE_FIXE* ProblemeLineairePartieFixe; - - PROBLEME_SIMPLEXE* Probleme; - PROBLEME_SPX* ProbSpx; +#include - PremierPassage = OUI; - - ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; +void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES& DonneesAnnuelles, int NumeroDeReservoir) +{ + PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesAnnuelles.ProblemeHydraulique; + PROBLEME_LINEAIRE_PARTIE_VARIABLE& ProblemeLineairePartieVariable + = ProblemeHydraulique.ProblemeLineairePartieVariable; + PROBLEME_LINEAIRE_PARTIE_FIXE& ProblemeLineairePartieFixe + = ProblemeHydraulique.ProblemeLineairePartieFixe; - ProblemeLineairePartieVariable = ProblemeHydraulique->ProblemeLineairePartieVariable; - ProblemeLineairePartieFixe = ProblemeHydraulique->ProblemeLineairePartieFixe; - ProbSpx = (PROBLEME_SPX*)ProblemeHydraulique->ProblemeSpx[NumeroDeReservoir]; + PROBLEME_SPX* ProbSpx = (PROBLEME_SPX*)ProblemeHydraulique.ProblemeSpx[NumeroDeReservoir]; + std::unique_ptr Probleme = std::make_unique(); - Probleme = (PROBLEME_SIMPLEXE*)ProblemeHydraulique->Probleme; - if (Probleme == NULL) + if (!Probleme) { - Probleme = (PROBLEME_SIMPLEXE*)malloc(sizeof(PROBLEME_SIMPLEXE)); - if (Probleme == NULL) - { - DonneesAnnuelles->ResultatsValides = EMERGENCY_SHUT_DOWN; - return; - } - ProblemeHydraulique->Probleme = (void*)Probleme; + DonneesAnnuelles.ResultatsValides = EMERGENCY_SHUT_DOWN; + return; } + bool PremierPassage = true; + RESOLUTION: - if (ProbSpx == NULL) + if (!ProbSpx) { Probleme->Contexte = SIMPLEXE_SEUL; Probleme->BaseDeDepartFournie = NON_SPX; @@ -94,29 +82,29 @@ void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES* DonneesAnnuelles, int N Probleme->BaseDeDepartFournie = UTILISER_LA_BASE_DU_PROBLEME_SPX; SPX_ModifierLeVecteurSecondMembre(ProbSpx, - ProblemeLineairePartieVariable->SecondMembre, - ProblemeLineairePartieFixe->Sens, - ProblemeLineairePartieFixe->NombreDeContraintes); + ProblemeLineairePartieVariable.SecondMembre.data(), + ProblemeLineairePartieFixe.Sens.data(), + ProblemeLineairePartieFixe.NombreDeContraintes); } Probleme->NombreMaxDIterations = -1; Probleme->DureeMaxDuCalcul = -1.; - Probleme->CoutLineaire = ProblemeLineairePartieFixe->CoutLineaireBruite; - Probleme->X = ProblemeLineairePartieVariable->X; - Probleme->Xmin = ProblemeLineairePartieVariable->Xmin; - Probleme->Xmax = ProblemeLineairePartieVariable->Xmax; - Probleme->NombreDeVariables = ProblemeLineairePartieFixe->NombreDeVariables; - Probleme->TypeDeVariable = ProblemeLineairePartieFixe->TypeDeVariable; - - Probleme->NombreDeContraintes = ProblemeLineairePartieFixe->NombreDeContraintes; - Probleme->IndicesDebutDeLigne = ProblemeLineairePartieFixe->IndicesDebutDeLigne; - Probleme->NombreDeTermesDesLignes = ProblemeLineairePartieFixe->NombreDeTermesDesLignes; - Probleme->IndicesColonnes = ProblemeLineairePartieFixe->IndicesColonnes; + 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->NombreDeContraintes = ProblemeLineairePartieFixe.NombreDeContraintes; + Probleme->IndicesDebutDeLigne = ProblemeLineairePartieFixe.IndicesDebutDeLigne.data(); + Probleme->NombreDeTermesDesLignes = ProblemeLineairePartieFixe.NombreDeTermesDesLignes.data(); + Probleme->IndicesColonnes = ProblemeLineairePartieFixe.IndicesColonnes.data(); Probleme->CoefficientsDeLaMatriceDesContraintes - = ProblemeLineairePartieFixe->CoefficientsDeLaMatriceDesContraintes; - Probleme->Sens = ProblemeLineairePartieFixe->Sens; - Probleme->SecondMembre = ProblemeLineairePartieVariable->SecondMembre; + = ProblemeLineairePartieFixe.CoefficientsDeLaMatriceDesContraintes.data(); + Probleme->Sens = ProblemeLineairePartieFixe.Sens.data(); + Probleme->SecondMembre = ProblemeLineairePartieVariable.SecondMembre.data(); Probleme->ChoixDeLAlgorithme = SPX_DUAL; @@ -124,9 +112,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; @@ -134,11 +122,11 @@ 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) + if (PremierPassage) Probleme->AffichageDesTraces = NON_SPX; else Probleme->AffichageDesTraces = OUI_SPX; @@ -148,61 +136,58 @@ 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 != NULL) - { - ProblemeHydraulique->ProblemeSpx[NumeroDeReservoir] = (void*)ProbSpx; - } + if (ProbSpx) + ProblemeHydraulique.ProblemeSpx[NumeroDeReservoir] = (void*)ProbSpx; - ProblemeLineairePartieVariable->ExistenceDUneSolution = Probleme->ExistenceDUneSolution; + 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) + if (ProblemeLineairePartieVariable.ExistenceDUneSolution != SPX_ERREUR_INTERNE) { SPX_LibererProbleme(ProbSpx); ProbSpx = NULL; - PremierPassage = NON; + PremierPassage = false; goto RESOLUTION; } else { - DonneesAnnuelles->ResultatsValides = EMERGENCY_SHUT_DOWN; + DonneesAnnuelles.ResultatsValides = EMERGENCY_SHUT_DOWN; return; } } - if (ProblemeLineairePartieVariable->ExistenceDUneSolution == OUI_SPX) + if (ProblemeLineairePartieVariable.ExistenceDUneSolution == OUI_SPX) { - ProblemeHydraulique->CoutDeLaSolution = 0.0; - for (Var = 0; Var < Probleme->NombreDeVariables; Var++) + ProblemeHydraulique.CoutDeLaSolution = 0.0; + for (int var = 0; var < Probleme->NombreDeVariables; var++) { - ProblemeHydraulique->CoutDeLaSolution - += ProblemeLineairePartieFixe->CoutLineaire[Var] * Probleme->X[Var]; + ProblemeHydraulique.CoutDeLaSolution + += ProblemeLineairePartieFixe.CoutLineaire[var] * Probleme->X[var]; } - ProblemeHydraulique->CoutDeLaSolutionBruite = 0.0; - for (Var = 0; Var < Probleme->NombreDeVariables; Var++) + ProblemeHydraulique.CoutDeLaSolutionBruite = 0.0; + for (int var = 0; var < Probleme->NombreDeVariables; var++) { - ProblemeHydraulique->CoutDeLaSolutionBruite - += ProblemeLineairePartieFixe->CoutLineaireBruite[Var] * Probleme->X[Var]; + ProblemeHydraulique.CoutDeLaSolutionBruite + += ProblemeLineairePartieFixe.CoutLineaireBruite[var] * Probleme->X[var]; } - DonneesAnnuelles->ResultatsValides = OUI; + DonneesAnnuelles.ResultatsValides = OUI; - for (Var = 0; Var < ProblemeLineairePartieFixe->NombreDeVariables; Var++) + for (int var = 0; var < ProblemeLineairePartieFixe.NombreDeVariables; var++) { - pt = ProblemeLineairePartieVariable->AdresseOuPlacerLaValeurDesVariablesOptimisees[Var]; - if (pt != NULL) - *pt = ProblemeLineairePartieVariable->X[Var]; + double* pt = ProblemeLineairePartieVariable.AdresseOuPlacerLaValeurDesVariablesOptimisees[var]; + if (pt) + *pt = ProblemeLineairePartieVariable.X[var]; } } else { - DonneesAnnuelles->ResultatsValides = NON; + DonneesAnnuelles.ResultatsValides = NON; return; } 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 3e39c1d90f..0000000000 --- a/src/solver/hydro/monthly/h2o_m_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_M_SYS__ -#define __SOLVER_H2O_M_SYS__ - -#include -#include -#include -#include -#include -#include -#include -#include - -#endif /* __SOLVER_H2O_M_SYS__ */