Skip to content

Commit

Permalink
[DEV] Var scope
Browse files Browse the repository at this point in the history
  • Loading branch information
payetvin committed Sep 27, 2023
1 parent b5cae89 commit 6685522
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 110 deletions.
7 changes: 2 additions & 5 deletions src/solver/hydro/daily2/h2o2_j_apply_costs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,15 @@

void H2O2_J_apply_costs(const Hydro_problem_costs& h2o2_costs, DONNEES_MENSUELLES_ETENDUES& problem)
{
int NombreDeProblemes;
int NbPdt;

NombreDeProblemes = problem.ProblemeHydrauliqueEtendu->NombreDeProblemes;
int NombreDeProblemes = problem.ProblemeHydrauliqueEtendu->NombreDeProblemes;
auto& ProblemeLineaireEtenduPartieFixe
= problem.ProblemeHydrauliqueEtendu->ProblemeLineaireEtenduPartieFixe;
auto& CorrespondanceDesVariables = problem.ProblemeHydrauliqueEtendu->CorrespondanceDesVariables;
const auto& NbJoursDUnProbleme = problem.ProblemeHydrauliqueEtendu->NbJoursDUnProbleme;

for (int pb_num = 0; pb_num < NombreDeProblemes; pb_num++)
{
NbPdt = NbJoursDUnProbleme[pb_num];
int NbPdt = NbJoursDUnProbleme[pb_num];

for (int var = 0; var < ProblemeLineaireEtenduPartieFixe[pb_num].NombreDeVariables; var++)
ProblemeLineaireEtenduPartieFixe[pb_num].CoutLineaire[var] = 0.0;
Expand Down
22 changes: 9 additions & 13 deletions src/solver/hydro/daily2/h2o2_j_construire_les_contraintes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,8 @@ void H2O2_J_ConstruireLesContraintes(
std::vector<int>& IndicesColonnes,
CORRESPONDANCE_DES_VARIABLES_PB_ETENDU& CorrespondanceDesVariables)
{
int NombreDeContraintes;
int il;
int Pdt;

NombreDeContraintes = 0;
il = 0;
int NombreDeContraintes = 0;
int il = 0;

IndicesDebutDeLigne[NombreDeContraintes] = il;

Expand All @@ -61,7 +57,7 @@ void H2O2_J_ConstruireLesContraintes(

NombreDeContraintes++;

for (Pdt = 1; Pdt < NbPdt; Pdt++)
for (int Pdt = 1; Pdt < NbPdt; Pdt++)
{
IndicesDebutDeLigne[NombreDeContraintes] = il;

Expand All @@ -88,7 +84,7 @@ void H2O2_J_ConstruireLesContraintes(

IndicesDebutDeLigne[NombreDeContraintes] = il;

for (Pdt = 0; Pdt < NbPdt; Pdt++)
for (int Pdt = 0; Pdt < NbPdt; Pdt++)
{
CoefficientsDeLaMatriceDesContraintes[il] = 1.0;
IndicesColonnes[il] = CorrespondanceDesVariables.NumeroVar_Turbine[Pdt];
Expand All @@ -103,7 +99,7 @@ void H2O2_J_ConstruireLesContraintes(
NombreDeTermesDesLignes[NombreDeContraintes] = NbPdt + 1;
NombreDeContraintes++;

for (Pdt = 0; Pdt < NbPdt; Pdt++)
for (int Pdt = 0; Pdt < NbPdt; Pdt++)
{
IndicesDebutDeLigne[NombreDeContraintes] = il;

Expand All @@ -120,7 +116,7 @@ void H2O2_J_ConstruireLesContraintes(
NombreDeContraintes++;
}

for (Pdt = 0; Pdt < NbPdt; Pdt++)
for (int Pdt = 0; Pdt < NbPdt; Pdt++)
{
IndicesDebutDeLigne[NombreDeContraintes] = il;

Expand All @@ -137,7 +133,7 @@ void H2O2_J_ConstruireLesContraintes(
NombreDeContraintes++;
}

for (Pdt = 0; Pdt < NbPdt; Pdt++)
for (int Pdt = 0; Pdt < NbPdt; Pdt++)
{
IndicesDebutDeLigne[NombreDeContraintes] = il;

Expand All @@ -154,7 +150,7 @@ void H2O2_J_ConstruireLesContraintes(
NombreDeContraintes++;
}

for (Pdt = 0; Pdt < NbPdt; Pdt++)
for (int Pdt = 0; Pdt < NbPdt; Pdt++)
{
IndicesDebutDeLigne[NombreDeContraintes] = il;

Expand All @@ -171,7 +167,7 @@ void H2O2_J_ConstruireLesContraintes(
NombreDeContraintes++;
}

for (Pdt = 0; Pdt < NbPdt; Pdt++)
for (int Pdt = 0; Pdt < NbPdt; Pdt++)
{
IndicesDebutDeLigne[NombreDeContraintes] = il;

Expand Down
15 changes: 6 additions & 9 deletions src/solver/hydro/daily2/h2o2_j_construire_les_variables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,9 @@ void H2O2_j_ConstruireLesVariables(
std::vector<double*>& AdresseOuPlacerLaValeurDesVariablesOptimisees,
CORRESPONDANCE_DES_VARIABLES_PB_ETENDU& CorrespondanceDesVariables)
{
int Var;
int Pdt;
int Var = 0;

Var = 0;

for (Pdt = 0; Pdt < NbPdt; Pdt++)
for (int Pdt = 0; Pdt < NbPdt; Pdt++)
{
CorrespondanceDesVariables.NumeroVar_Turbine[Pdt] = Var;
Xmin[Var] = 0.0;
Expand All @@ -63,7 +60,7 @@ void H2O2_j_ConstruireLesVariables(
Var++;
}

for (Pdt = 0; Pdt < NbPdt; Pdt++)
for (int Pdt = 0; Pdt < NbPdt; Pdt++)
{
CorrespondanceDesVariables.NumeroVar_niveauxFinJours[Pdt] = Var;
Xmin[Var] = 0.0;
Expand All @@ -81,7 +78,7 @@ void H2O2_j_ConstruireLesVariables(
AdresseOuPlacerLaValeurDesVariablesOptimisees[Var] = &(DonneesMensuellesEtendues->waste);
Var++;

for (Pdt = 0; Pdt < NbPdt; Pdt++)
for (int Pdt = 0; Pdt < NbPdt; Pdt++)
{
CorrespondanceDesVariables.NumeroVar_overflow[Pdt] = Var;
Xmin[Var] = 0.0;
Expand All @@ -92,7 +89,7 @@ void H2O2_j_ConstruireLesVariables(
Var++;
}

for (Pdt = 0; Pdt < NbPdt; Pdt++)
for (int Pdt = 0; Pdt < NbPdt; Pdt++)
{
CorrespondanceDesVariables.NumeroVar_deviations[Pdt] = Var;
Xmin[Var] = 0.0;
Expand All @@ -103,7 +100,7 @@ void H2O2_j_ConstruireLesVariables(
Var++;
}

for (Pdt = 0; Pdt < NbPdt; Pdt++)
for (int Pdt = 0; Pdt < NbPdt; Pdt++)
{
CorrespondanceDesVariables.NumeroVar_violations[Pdt] = Var;
Xmin[Var] = 0.0;
Expand Down
11 changes: 3 additions & 8 deletions src/solver/hydro/daily2/h2o2_j_free.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,10 @@ extern "C"

void H2O2_J_Free(DONNEES_MENSUELLES_ETENDUES* DonneesMensuelles)
{
int i;
int NombreDeProblemes;
PROBLEME_HYDRAULIQUE_ETENDU* ProblemeHydrauliqueEtendu = DonneesMensuelles->ProblemeHydrauliqueEtendu;
int NombreDeProblemes = ProblemeHydrauliqueEtendu->NombreDeProblemes;

PROBLEME_HYDRAULIQUE_ETENDU* ProblemeHydrauliqueEtendu;

ProblemeHydrauliqueEtendu = DonneesMensuelles->ProblemeHydrauliqueEtendu;
NombreDeProblemes = ProblemeHydrauliqueEtendu->NombreDeProblemes;

for (i = 0; i < NombreDeProblemes; i++)
for (int i = 0; i < NombreDeProblemes; i++)
{
PROBLEME_SPX* ProbSpx = (PROBLEME_SPX*)ProblemeHydrauliqueEtendu->ProblemeSpx[i];
if (ProbSpx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,12 @@
void H2O2_J_InitialiserLesBornesdesVariables(DONNEES_MENSUELLES_ETENDUES* DonneesMensuelles,
int NumeroDeProbleme)
{
int Pdt;
int NbPdt;
int Var;

const auto& TurbineMax = DonneesMensuelles->TurbineMax;
const auto& TurbineMin = DonneesMensuelles->TurbineMin;

PROBLEME_HYDRAULIQUE_ETENDU* ProblemeHydrauliqueEtendu;

ProblemeHydrauliqueEtendu = DonneesMensuelles->ProblemeHydrauliqueEtendu;
PROBLEME_HYDRAULIQUE_ETENDU* ProblemeHydrauliqueEtendu = DonneesMensuelles->ProblemeHydrauliqueEtendu;

NbPdt = ProblemeHydrauliqueEtendu->NbJoursDUnProbleme[NumeroDeProbleme];
int NbPdt = ProblemeHydrauliqueEtendu->NbJoursDUnProbleme[NumeroDeProbleme];

auto& CorrespondanceDesVariables
= ProblemeHydrauliqueEtendu->CorrespondanceDesVariables[NumeroDeProbleme];
Expand All @@ -52,9 +46,9 @@ void H2O2_J_InitialiserLesBornesdesVariables(DONNEES_MENSUELLES_ETENDUES* Donnee

auto& Xmax = ProblemeLineaireEtenduPartieVariable.Xmax;
auto& Xmin = ProblemeLineaireEtenduPartieVariable.Xmin;
for (Pdt = 0; Pdt < NbPdt; Pdt++)
for (int Pdt = 0; Pdt < NbPdt; Pdt++)
{
Var = NumeroVar_Turbine[Pdt];
int Var = NumeroVar_Turbine[Pdt];
Xmax[Var] = TurbineMax[Pdt];
Xmin[Var] = TurbineMin[Pdt];
}
Expand Down
22 changes: 9 additions & 13 deletions src/solver/hydro/daily2/h2o2_j_initialiser_les_second_membre.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,19 @@
void H2O2_J_InitialiserLeSecondMembre(DONNEES_MENSUELLES_ETENDUES* DonneesMensuelles,
int NumeroDeProbleme)
{
PROBLEME_HYDRAULIQUE_ETENDU* ProblemeHydrauliqueEtendu;
PROBLEME_HYDRAULIQUE_ETENDU* ProblemeHydrauliqueEtendu = DonneesMensuelles->ProblemeHydrauliqueEtendu;

ProblemeHydrauliqueEtendu = DonneesMensuelles->ProblemeHydrauliqueEtendu;
auto& ProblemeLineairePartieVariable
= ProblemeHydrauliqueEtendu->ProblemeLineaireEtenduPartieVariable[NumeroDeProbleme];
auto& SecondMembre = ProblemeLineairePartieVariable.SecondMembre;

int NbPdt, Pdt, Cnt;

NbPdt = ProblemeHydrauliqueEtendu->NbJoursDUnProbleme[NumeroDeProbleme];

Cnt = 0;
int NbPdt = ProblemeHydrauliqueEtendu->NbJoursDUnProbleme[NumeroDeProbleme];
int Cnt = 0;

SecondMembre[Cnt] = DonneesMensuelles->NiveauInitialDuMois + DonneesMensuelles->apports[0];
Cnt++;

for (Pdt = 1; Pdt < NbPdt; Pdt++)
for (int Pdt = 1; Pdt < NbPdt; Pdt++)
{
SecondMembre[Cnt] = DonneesMensuelles->apports[Pdt];
Cnt++;
Expand All @@ -55,31 +51,31 @@ void H2O2_J_InitialiserLeSecondMembre(DONNEES_MENSUELLES_ETENDUES* DonneesMensue
SecondMembre[Cnt] = DonneesMensuelles->TurbineDuMois;
Cnt++;

for (Pdt = 0; Pdt < NbPdt; Pdt++)
for (int Pdt = 0; Pdt < NbPdt; Pdt++)
{
SecondMembre[Cnt] = DonneesMensuelles->TurbineCible[Pdt];
Cnt++;
}

for (Pdt = 0; Pdt < NbPdt; Pdt++)
for (int Pdt = 0; Pdt < NbPdt; Pdt++)
{
SecondMembre[Cnt] = DonneesMensuelles->TurbineCible[Pdt];
Cnt++;
}

for (Pdt = 0; Pdt < NbPdt; Pdt++)
for (int Pdt = 0; Pdt < NbPdt; Pdt++)
{
SecondMembre[Cnt] = 0.;
Cnt++;
}

for (Pdt = 0; Pdt < NbPdt; Pdt++)
for (int Pdt = 0; Pdt < NbPdt; Pdt++)
{
SecondMembre[Cnt] = DonneesMensuelles->niveauBas[Pdt];
Cnt++;
}

for (Pdt = 0; Pdt < NbPdt; Pdt++)
for (int Pdt = 0; Pdt < NbPdt; Pdt++)
{
SecondMembre[Cnt] = 0.;
Cnt++;
Expand Down
25 changes: 8 additions & 17 deletions src/solver/hydro/daily2/h2o2_j_instanciation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,13 @@

DONNEES_MENSUELLES_ETENDUES* H2O2_J_Instanciation()
{
int i;
int NombreDeProblemes;
int NbPdt;
int j;
int NombreDeVariables;
int NombreDeContraintes;
int NombreDeTermesAlloues;
DONNEES_MENSUELLES_ETENDUES* DonneesMensuellesEtendues = new DONNEES_MENSUELLES_ETENDUES;
PROBLEME_HYDRAULIQUE_ETENDU* ProblemeHydrauliqueEtendu;

if (DonneesMensuellesEtendues == NULL)
return (NULL);

DonneesMensuellesEtendues->ProblemeHydrauliqueEtendu = new PROBLEME_HYDRAULIQUE_ETENDU;

ProblemeHydrauliqueEtendu = DonneesMensuellesEtendues->ProblemeHydrauliqueEtendu;
auto ProblemeHydrauliqueEtendu = DonneesMensuellesEtendues->ProblemeHydrauliqueEtendu;

ProblemeHydrauliqueEtendu->NombreDeProblemes = 4;

Expand All @@ -70,7 +61,7 @@ DONNEES_MENSUELLES_ETENDUES* H2O2_J_Instanciation()
DonneesMensuellesEtendues->deviations.assign(NbJoursDUnProbleme[3], 0.);
DonneesMensuellesEtendues->violations.assign(NbJoursDUnProbleme[3], 0.);

NombreDeProblemes = ProblemeHydrauliqueEtendu->NombreDeProblemes;
int NombreDeProblemes = ProblemeHydrauliqueEtendu->NombreDeProblemes;

ProblemeHydrauliqueEtendu->CorrespondanceDesVariables.resize(NombreDeProblemes);
ProblemeHydrauliqueEtendu->ProblemeLineaireEtenduPartieFixe.resize(NombreDeProblemes);
Expand All @@ -85,9 +76,9 @@ DONNEES_MENSUELLES_ETENDUES* H2O2_J_Instanciation()
auto& ProblemeLineaireEtenduPartieVariable
= ProblemeHydrauliqueEtendu->ProblemeLineaireEtenduPartieVariable;

for (i = 0; i < NombreDeProblemes; i++)
for (int i = 0; i < NombreDeProblemes; i++)
{
NbPdt = NbJoursDUnProbleme[i];
int NbPdt = NbJoursDUnProbleme[i];

auto& CorrVar = CorrespondanceDesVariables[i];

Expand All @@ -99,7 +90,7 @@ DONNEES_MENSUELLES_ETENDUES* H2O2_J_Instanciation()

auto& PlFixe = ProblemeLineaireEtenduPartieFixe[i];

NombreDeVariables = 0;
int NombreDeVariables = 0;
NombreDeVariables += NbPdt;

NombreDeVariables += NbPdt;
Expand All @@ -116,7 +107,7 @@ DONNEES_MENSUELLES_ETENDUES* H2O2_J_Instanciation()

PlFixe.TypeDeVariable.assign(NombreDeVariables, 0);

NombreDeContraintes = 0;
int NombreDeContraintes = 0;
NombreDeContraintes += NbPdt;

NombreDeContraintes += 1;
Expand All @@ -132,7 +123,7 @@ DONNEES_MENSUELLES_ETENDUES* H2O2_J_Instanciation()
PlFixe.IndicesDebutDeLigne.assign(NombreDeContraintes, 0.);
PlFixe.NombreDeTermesDesLignes.assign(NombreDeContraintes, 0.);

NombreDeTermesAlloues = 0;
int NombreDeTermesAlloues = 0;
NombreDeTermesAlloues += 3;
NombreDeTermesAlloues += 4 * (NbPdt - 1);
NombreDeTermesAlloues += 1;
Expand Down Expand Up @@ -164,7 +155,7 @@ DONNEES_MENSUELLES_ETENDUES* H2O2_J_Instanciation()
PlVariable.CoutsMarginauxDesContraintes.assign(NombreDeContraintes, 0.);
}

for (i = 0; i < NombreDeProblemes; i++)
for (int i = 0; i < NombreDeProblemes; i++)
{
H2O2_j_ConstruireLesVariables(
NbJoursDUnProbleme[i],
Expand Down
6 changes: 1 addition & 5 deletions src/solver/hydro/daily2/h2o2_j_optimiser_un_mois.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@

void H2O2_J_OptimiserUnMois(DONNEES_MENSUELLES_ETENDUES* DonneesMensuelles)
{
PROBLEME_HYDRAULIQUE_ETENDU* ProblemeHydrauliqueEtendu;

ProblemeHydrauliqueEtendu = DonneesMensuelles->ProblemeHydrauliqueEtendu;
auto ProblemeHydrauliqueEtendu = DonneesMensuelles->ProblemeHydrauliqueEtendu;

int NumeroDeProbleme = -1;
for (int i = 0; i < ProblemeHydrauliqueEtendu->NombreDeProblemes; i++)
Expand All @@ -54,9 +52,7 @@ void H2O2_J_OptimiserUnMois(DONNEES_MENSUELLES_ETENDUES* DonneesMensuelles)
DonneesMensuelles->ResultatsValides = NON;

H2O2_J_InitialiserLeSecondMembre(DonneesMensuelles, NumeroDeProbleme);

H2O2_J_InitialiserLesBornesdesVariables(DonneesMensuelles, NumeroDeProbleme);

H2O2_J_ResoudreLeProblemeLineaire(DonneesMensuelles, NumeroDeProbleme);

return;
Expand Down
Loading

0 comments on commit 6685522

Please sign in to comment.