Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove malloc in src/solver/hydro/ #1626

Merged
merged 43 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
eff4d71
[DEV] turbine
payetvin Sep 12, 2023
6544d17
[DEV] donnees_annuelles.h
payetvin Sep 12, 2023
bea98b1
[DEV] CoutLineaire CoutLineaireBruite CoefficientsDeLaMatriceDesContr…
payetvin Sep 12, 2023
e1937c3
[DEV] Sens
payetvin Sep 12, 2023
951ecfe
[DEV] Type de variable
payetvin Sep 12, 2023
f479d4e
[DEV] PROBLEME_LINEAIRE_PARTIE_FIXE
payetvin Sep 12, 2023
92f430f
[DEV] Xmin Xmax SecondeMembre
payetvin Sep 12, 2023
69a9861
[DEV] X CoutsReduits CoutsMarginauxDesContraintes
payetvin Sep 12, 2023
f86b83c
[DEV] PositionDeLaVariable ComplementDeLaBase
payetvin Sep 12, 2023
f838e95
[DEV] PROBLEME_LINEAIRE_PARTIE_VARIABLE
payetvin Sep 12, 2023
1ee25fa
[DEV] CorrespondanceDesVariables
payetvin Sep 12, 2023
3bb0888
[DEV] ProblemeLineairePartieFixe
payetvin Sep 12, 2023
2dc2a67
[DEV] ProblemeLineairePartieVariable
payetvin Sep 12, 2023
51729ac
[FIX] use new instead of malloc to call constructor
payetvin Sep 13, 2023
cc88b22
[DEV] ProblemeHydraulique
payetvin Sep 13, 2023
17a0370
[DEV] DONNEES_ANNUELLES
payetvin Sep 13, 2023
fb5cd5e
[FIX] Segfault
payetvin Sep 13, 2023
634d415
[DEV] ProblemeSpx
payetvin Sep 13, 2023
170f915
[FIX] Solved unfeasible
payetvin Sep 15, 2023
739bdcd
[DEV] Var scope in hydro/monthly
payetvin Sep 18, 2023
05932f3
[DEV] Var scope in hydro/daily
payetvin Sep 18, 2023
6151c2b
[DEV] Use new instead of malloc for PROBLEME_SIMPLEXE
payetvin Sep 18, 2023
436ecc5
[DEV] Use new instead of malloc for PROBLEME_SIMPLEXE in monthly
payetvin Sep 18, 2023
38cf1fd
[DEV] static_cast
payetvin Sep 18, 2023
6d2bc64
[DEV] const int nbpdt
payetvin Sep 18, 2023
90d5649
[DEV] Comment in h2o_m_resoudre_le_probleme_lineaire.cpp
payetvin Sep 18, 2023
3b2732f
[DEV] Use pointer instead of ref in management/daily
payetvin Sep 18, 2023
f948eb7
[DEV] (std::nothrow)
payetvin Sep 18, 2023
c4dd148
[DEV] Replace flag by vector of bool
payetvin Sep 21, 2023
3e135f7
[DEV] Updated lisser_sur_turbines
payetvin Sep 21, 2023
1a0dd4e
[MERGE] develop¸ fix conflicts in management/daily.cpp
payetvin Sep 21, 2023
99395c7
[DEV] unique_ptr for daily
payetvin Sep 22, 2023
8ec141f
[DEV] unique_ptr for daily/prob_a_resoudre
payetvin Sep 22, 2023
9dd42ca
[DEV] unique_ptr for monthly/prob_a_resoudre
payetvin Sep 22, 2023
b450b92
[FIX] Try fixing windows unfeasible
payetvin Sep 22, 2023
ffd40a9
[FIX] Code smell
payetvin Sep 22, 2023
19acabb
[DEV] Use pointer instead of copy
payetvin Sep 25, 2023
d69d7a3
[DEV] remove h2o_m_sys.h
payetvin Sep 25, 2023
e38709b
[DEV] remove h2o_j_sys.h
payetvin Sep 25, 2023
e47373b
[FIX] Compile
payetvin Sep 25, 2023
bbe7c31
Fix monthlyVariables
flomnes Sep 25, 2023
4703653
[DEV] Minor improvement for var looping
payetvin Sep 25, 2023
d70e160
Simplify, add const qualifier
flomnes Sep 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions src/solver/hydro/daily/h2o_j_construire_les_contraintes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,12 @@ void H2O_J_ConstruireLesContraintes(int NbPdt,
std::vector<int>& 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];
Expand All @@ -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;
Expand Down
7 changes: 2 additions & 5 deletions src/solver/hydro/daily/h2o_j_construire_les_variables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,9 @@ void H2O_j_ConstruireLesVariables(int NbPdt,
std::vector<double*>& 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;
Expand Down
2 changes: 1 addition & 1 deletion src/solver/hydro/daily/h2o_j_fonctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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*);
Expand Down
3 changes: 2 additions & 1 deletion src/solver/hydro/daily/h2o_j_free.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ void H2O_J_Free(DONNEES_MENSUELLES* DonneesMensuelles)
SPX_LibererProbleme(ProbSpx);
}

free(ProblemeHydraulique.Probleme);
PROBLEME_SIMPLEXE* pb = static_cast<PROBLEME_SIMPLEXE*>(ProblemeHydraulique.Probleme);
delete pb;

return;
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,14 @@
void H2O_J_InitialiserLesBornesdesVariables(DONNEES_MENSUELLES* DonneesMensuelles,
int NumeroDeProbleme)
{
int NbPdt;
int Var;


const std::vector<double>& TurbineMax = DonneesMensuelles->TurbineMax;
const std::vector<double>& TurbineMin = DonneesMensuelles->TurbineMin;
const std::vector<double>& TurbineCible = DonneesMensuelles->TurbineCible;
std::vector<double>& Turbine = DonneesMensuelles->Turbine;

PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesMensuelles->ProblemeHydraulique;

NbPdt = ProblemeHydraulique.NbJoursDUnProbleme[NumeroDeProbleme];
const int NbPdt = ProblemeHydraulique.NbJoursDUnProbleme[NumeroDeProbleme];

const CORRESPONDANCE_DES_VARIABLES& CorrespondanceDesVariables
= ProblemeHydraulique.CorrespondanceDesVariables[NumeroDeProbleme];
Expand All @@ -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]));
Expand Down
15 changes: 4 additions & 11 deletions src/solver/hydro/daily/h2o_j_initialiser_les_second_membre.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,23 @@

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<double>& SecondMembre
= ProblemeHydraulique.ProblemeLineairePartieVariable[NumeroDeProbleme].SecondMembre;

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];
}

Expand Down
16 changes: 8 additions & 8 deletions src/solver/hydro/daily/h2o_j_instanciation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
69 changes: 29 additions & 40 deletions src/solver/hydro/daily/h2o_j_lisser_les_sur_turbines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,94 +32,83 @@

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<double>& TurbineMax = DonneesMensuelles->TurbineMax;
std::vector<double>& Turbine = DonneesMensuelles->Turbine;
std::vector<double>& 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<bool> flag(NbPdt);

SurTurbineARepartir = 0.0;
for (Pdt = 0; Pdt < NbPdt; Pdt++)
double SurTurbineARepartir = 0.0;
for (int Pdt = 0; Pdt < NbPdt; Pdt++)
{
Flag[Pdt] = 0;
flag[Pdt] = 0;
payetvin marked this conversation as resolved.
Show resolved Hide resolved
if (Turbine[Pdt] - TurbineCible[Pdt] > ZERO)
Flag[Pdt] = 1;
flag[Pdt] = 1;
payetvin marked this conversation as resolved.
Show resolved Hide resolved
}

for (Pdt = 0; Pdt < NbPdt; Pdt++)
for (int Pdt = 0; Pdt < NbPdt; Pdt++)
{
if (Flag[Pdt] == 1)
if (flag[Pdt] == 1)
SurTurbineARepartir += Turbine[Pdt] - TurbineCible[Pdt];
}

for (Pdt = 0; Pdt < NbPdt; Pdt++)
Flag[Pdt] = 0;
for (Pdt = 0; Pdt < NbPdt; Pdt++)
for (int Pdt = 0; Pdt < NbPdt; Pdt++)
flag[Pdt] = 0;
for (int Pdt = 0; Pdt < NbPdt; Pdt++)
payetvin marked this conversation as resolved.
Show resolved Hide resolved
{
if (TurbineMax[Pdt] - TurbineCible[Pdt] > ZERO)
Flag[Pdt] = 1;
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++)
payetvin marked this conversation as resolved.
Show resolved Hide resolved
{
if (Flag[Pdt] == 1)
if (flag[Pdt] == 1)
Np++;
}
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++)
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];
}
}

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)
if (flag[Pdt] == 0)
continue;

Turbine[Pdt] = TurbineCible[Pdt] + SurTurbine;
if (TurbineMax[Pdt] - Turbine[Pdt] <= ZERO)
{
SurTurbineARepartir -= SurTurbine;
LimiteAtteinte = 1;
Flag[Pdt] = 0;
flag[Pdt] = 0;
}
}

Expand Down
10 changes: 2 additions & 8 deletions src/solver/hydro/daily/h2o_j_optimiser_un_mois.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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])
{
Expand All @@ -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;
Expand Down
36 changes: 12 additions & 24 deletions src/solver/hydro/daily/h2o_j_resoudre_le_probleme_lineaire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -66,23 +56,25 @@ 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)
Probleme = new(std::nothrow) PROBLEME_SIMPLEXE;
if (!Probleme)
{
DonneesMensuelles->ResultatsValides = EMERGENCY_SHUT_DOWN;
return;
}
ProblemeHydraulique.Probleme = (void*)Probleme;
}

char PremierPassage = OUI;

RESOLUTION:

if (ProbSpx == NULL)
if (!ProbSpx)
{
Probleme->Contexte = SIMPLEXE_SEUL;
Probleme->BaseDeDepartFournie = NON_SPX;
Expand Down Expand Up @@ -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;

Expand All @@ -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
Expand Down
Loading