Skip to content

Commit

Permalink
Remove manual alloc and update code standards in hydro/daily2 (#1651)
Browse files Browse the repository at this point in the history
* [DEV] TurbineMax/min

* [FIX] Use new to call constructor for vector

* [DEV] niveauxbas apports

* [DEV] DONNEES_MENSUELLES_ETENDUES

* [DEV] CoutLineaire CoefficientsDeLaMatriceDesContraintes

* [DEV] Sens

* [FIX] Using new

* [DEV] NombreDeTermesDesLignes IndicesDebutDeLigne

* [DEV] IndicesColonnes

* [DEV] Xmin Xmax SecondMembre

* [DEV] X CoutsReduits CoutsMarginauxDesContraintes

* [DEV] PositionDeLaVariable ComplementDeLaBase

* [DEV] AdresseOuPlacerLaValeurDesVariablesOptimisees

* [DEV] CORRESPONDANCE_DES_VARIABLES_PB_ETENDU

* [DEV] NbJoursDUnProbleme

* [DEV] ProblemeSpx

* [DEV] TypeDeVariable

* [DEV] CorrespondanceDesVariables

* [DEV] ProblemeLineaireEtenduPartieFixe

* [DEV] ProblemeLineaireEtenduPartieVariable

* [DEV] Var scope

* [DEV] ProblemeHydrauliqueEtendu

* [DEV] Use unique_ptr for Probleme

* [DEV] Remove probleme in struct

* [DEV] Remove probleme in monthly

* [DEV] Remove probleme in daily/

* [DEV] DONNEES_MENSUELLES_ETENDUES&

* [FIX] code smells

* [FIX] vois* for probspx

* [DEV] std::vector<PROBLEME_SPX*> ProblemeSpx for daily and monthly

* [DEV] Remove error checking for unique_ptr

* [FIX] Code smell
  • Loading branch information
payetvin authored Oct 3, 2023
1 parent 8113212 commit d45109f
Show file tree
Hide file tree
Showing 19 changed files with 357 additions and 654 deletions.
16 changes: 13 additions & 3 deletions src/solver/hydro/daily/h2o_j_donnees_optimisation.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@
#ifndef __SOLVER_H2O_J_STRUCTURE_INTERNE__
#define __SOLVER_H2O_J_STRUCTURE_INTERNE__

#ifdef __CPLUSPLUS
extern "C"
{
#endif

#include "spx_definition_arguments.h"
#include "spx_fonctions.h"

#ifdef __CPLUSPLUS
}
#endif

#define LINFINI 1.e+80

#define JOURS_28 28
Expand Down Expand Up @@ -127,9 +139,7 @@ struct PROBLEME_HYDRAULIQUE
std::vector<PROBLEME_LINEAIRE_PARTIE_FIXE> ProblemeLineairePartieFixe;
std::vector<PROBLEME_LINEAIRE_PARTIE_VARIABLE> ProblemeLineairePartieVariable;

std::vector<void*> ProblemeSpx; /* Il y en a 1 par reservoir. Un probleme couvre 1 mois */
void* Probleme; /* Le probleme en cours passe au simplexe */

std::vector<PROBLEME_SPX*> ProblemeSpx; /* Il y en a 1 par reservoir. Un probleme couvre 1 mois */
};

#endif
2 changes: 0 additions & 2 deletions src/solver/hydro/daily/h2o_j_instanciation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ DONNEES_MENSUELLES* H2O_J_Instanciation(void)

ProblemeHydraulique.ProblemeSpx.assign(NombreDeProblemes, nullptr);

ProblemeHydraulique.Probleme = NULL;

std::vector<CORRESPONDANCE_DES_VARIABLES>& CorrespondanceDesVariables
= ProblemeHydraulique.CorrespondanceDesVariables;

Expand Down
22 changes: 2 additions & 20 deletions src/solver/hydro/daily/h2o_j_resoudre_le_probleme_lineaire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,6 @@
** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions
*/

#ifdef __CPLUSPLUS
extern "C"
{
#endif

#include "spx_definition_arguments.h"
#include "spx_fonctions.h"

#ifdef __CPLUSPLUS
}
#endif

#include "h2o_j_donnees_mensuelles.h"
#include "h2o_j_fonctions.h"

Expand All @@ -58,15 +46,9 @@ void H2O_J_ResoudreLeProblemeLineaire(DONNEES_MENSUELLES* DonneesMensuelles, int
PROBLEME_LINEAIRE_PARTIE_FIXE& ProblemeLineairePartieFixe
= ProblemeHydraulique.ProblemeLineairePartieFixe[NumeroDeProbleme];

PROBLEME_SPX* ProbSpx = (PROBLEME_SPX*)ProblemeHydraulique.ProblemeSpx[NumeroDeProbleme];
PROBLEME_SPX* ProbSpx = ProblemeHydraulique.ProblemeSpx[NumeroDeProbleme];
std::unique_ptr<PROBLEME_SIMPLEXE> Probleme = std::make_unique<PROBLEME_SIMPLEXE>();

if (!Probleme)
{
DonneesMensuelles->ResultatsValides = EMERGENCY_SHUT_DOWN;
return;
}

bool PremierPassage = true;

RESOLUTION:
Expand Down Expand Up @@ -140,7 +122,7 @@ void H2O_J_ResoudreLeProblemeLineaire(DONNEES_MENSUELLES* DonneesMensuelles, int
ProbSpx = SPX_Simplexe(Probleme.get(), ProbSpx);

if (ProbSpx)
ProblemeHydraulique.ProblemeSpx[NumeroDeProbleme] = (void*)ProbSpx;
ProblemeHydraulique.ProblemeSpx[NumeroDeProbleme] = ProbSpx;

ProblemeLineairePartieVariable.ExistenceDUneSolution = Probleme->ExistenceDUneSolution;

Expand Down
36 changes: 15 additions & 21 deletions src/solver/hydro/daily2/h2o2_j_apply_costs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,55 +31,49 @@

void H2O2_J_apply_costs(const Hydro_problem_costs& h2o2_costs, DONNEES_MENSUELLES_ETENDUES& problem)
{
int NombreDeProblemes;
PROBLEME_LINEAIRE_ETENDU_PARTIE_FIXE** ProblemeLineaireEtenduPartieFixe;
CORRESPONDANCE_DES_VARIABLES_PB_ETENDU** CorrespondanceDesVariables;
int NbPdt;
int* NbJoursDUnProbleme;

NombreDeProblemes = problem.ProblemeHydrauliqueEtendu->NombreDeProblemes;
ProblemeLineaireEtenduPartieFixe
= problem.ProblemeHydrauliqueEtendu->ProblemeLineaireEtenduPartieFixe;
CorrespondanceDesVariables = problem.ProblemeHydrauliqueEtendu->CorrespondanceDesVariables;
NbJoursDUnProbleme = problem.ProblemeHydrauliqueEtendu->NbJoursDUnProbleme;
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;
for (int var = 0; var < ProblemeLineaireEtenduPartieFixe[pb_num].NombreDeVariables; var++)
ProblemeLineaireEtenduPartieFixe[pb_num].CoutLineaire[var] = 0.0;

for (int Pdt = 0; Pdt < NbPdt; Pdt++)
ProblemeLineaireEtenduPartieFixe[pb_num]
->CoutLineaire[CorrespondanceDesVariables[pb_num]->NumeroVar_niveauxFinJours[Pdt]]
.CoutLineaire[CorrespondanceDesVariables[pb_num].NumeroVar_niveauxFinJours[Pdt]]
= h2o2_costs.get_end_days_levels_cost();

for (int Pdt = 0; Pdt < NbPdt; Pdt++)
ProblemeLineaireEtenduPartieFixe[pb_num]
->CoutLineaire[CorrespondanceDesVariables[pb_num]->NumeroVar_overflow[Pdt]]
.CoutLineaire[CorrespondanceDesVariables[pb_num].NumeroVar_overflow[Pdt]]
= h2o2_costs.get_overflow_cost();

for (int Pdt = 0; Pdt < NbPdt; Pdt++)
ProblemeLineaireEtenduPartieFixe[pb_num]
->CoutLineaire[CorrespondanceDesVariables[pb_num]->NumeroVar_deviations[Pdt]]
.CoutLineaire[CorrespondanceDesVariables[pb_num].NumeroVar_deviations[Pdt]]
= h2o2_costs.get_deviations_cost();

for (int Pdt = 0; Pdt < NbPdt; Pdt++)
ProblemeLineaireEtenduPartieFixe[pb_num]
->CoutLineaire[CorrespondanceDesVariables[pb_num]->NumeroVar_violations[Pdt]]
.CoutLineaire[CorrespondanceDesVariables[pb_num].NumeroVar_violations[Pdt]]
= h2o2_costs.get_violations_cost();

ProblemeLineaireEtenduPartieFixe[pb_num]
->CoutLineaire[CorrespondanceDesVariables[pb_num]->NumeroVar_waste]
.CoutLineaire[CorrespondanceDesVariables[pb_num].NumeroVar_waste]
= h2o2_costs.get_waste_cost();

ProblemeLineaireEtenduPartieFixe[pb_num]
->CoutLineaire[CorrespondanceDesVariables[pb_num]->NumeroVar_deviationMax]
.CoutLineaire[CorrespondanceDesVariables[pb_num].NumeroVar_deviationMax]
= h2o2_costs.get_deviationMax_cost();

ProblemeLineaireEtenduPartieFixe[pb_num]
->CoutLineaire[CorrespondanceDesVariables[pb_num]->NumeroVar_violationMax]
.CoutLineaire[CorrespondanceDesVariables[pb_num].NumeroVar_violationMax]
= h2o2_costs.get_violationMax_cost();
}
}
72 changes: 34 additions & 38 deletions src/solver/hydro/daily2/h2o2_j_construire_les_contraintes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,55 +30,51 @@

void H2O2_J_ConstruireLesContraintes(
int NbPdt,
int* IndicesDebutDeLigne,
char* Sens,
int* NombreDeTermesDesLignes,
double* CoefficientsDeLaMatriceDesContraintes,
int* IndicesColonnes,
CORRESPONDANCE_DES_VARIABLES_PB_ETENDU* CorrespondanceDesVariables)
std::vector<int>& IndicesDebutDeLigne,
std::vector<char>& Sens,
std::vector<int>& NombreDeTermesDesLignes,
std::vector<double>& CoefficientsDeLaMatriceDesContraintes,
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;

CoefficientsDeLaMatriceDesContraintes[il] = 1.0;
IndicesColonnes[il] = CorrespondanceDesVariables->NumeroVar_Turbine[0];
IndicesColonnes[il] = CorrespondanceDesVariables.NumeroVar_Turbine[0];
il++;
CoefficientsDeLaMatriceDesContraintes[il] = 1.0;
IndicesColonnes[il] = CorrespondanceDesVariables->NumeroVar_niveauxFinJours[0];
IndicesColonnes[il] = CorrespondanceDesVariables.NumeroVar_niveauxFinJours[0];
il++;
CoefficientsDeLaMatriceDesContraintes[il] = 1.0;
IndicesColonnes[il] = CorrespondanceDesVariables->NumeroVar_overflow[0];
IndicesColonnes[il] = CorrespondanceDesVariables.NumeroVar_overflow[0];
il++;

Sens[NombreDeContraintes] = '=';
NombreDeTermesDesLignes[NombreDeContraintes] = 3;

NombreDeContraintes++;

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

CoefficientsDeLaMatriceDesContraintes[il] = 1.0;
IndicesColonnes[il] = CorrespondanceDesVariables->NumeroVar_Turbine[Pdt];
IndicesColonnes[il] = CorrespondanceDesVariables.NumeroVar_Turbine[Pdt];
il++;

CoefficientsDeLaMatriceDesContraintes[il] = 1.0;
IndicesColonnes[il] = CorrespondanceDesVariables->NumeroVar_niveauxFinJours[Pdt];
IndicesColonnes[il] = CorrespondanceDesVariables.NumeroVar_niveauxFinJours[Pdt];
il++;

CoefficientsDeLaMatriceDesContraintes[il] = -1.0;
IndicesColonnes[il] = CorrespondanceDesVariables->NumeroVar_niveauxFinJours[Pdt - 1];
IndicesColonnes[il] = CorrespondanceDesVariables.NumeroVar_niveauxFinJours[Pdt - 1];
il++;

CoefficientsDeLaMatriceDesContraintes[il] = 1.0;
IndicesColonnes[il] = CorrespondanceDesVariables->NumeroVar_overflow[Pdt];
IndicesColonnes[il] = CorrespondanceDesVariables.NumeroVar_overflow[Pdt];
il++;

Sens[NombreDeContraintes] = '=';
Expand All @@ -88,99 +84,99 @@ 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];
IndicesColonnes[il] = CorrespondanceDesVariables.NumeroVar_Turbine[Pdt];
il++;
}

CoefficientsDeLaMatriceDesContraintes[il] = 1.0;
IndicesColonnes[il] = CorrespondanceDesVariables->NumeroVar_waste;
IndicesColonnes[il] = CorrespondanceDesVariables.NumeroVar_waste;
il++;

Sens[NombreDeContraintes] = '=';
NombreDeTermesDesLignes[NombreDeContraintes] = NbPdt + 1;
NombreDeContraintes++;

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

CoefficientsDeLaMatriceDesContraintes[il] = 1.0;
IndicesColonnes[il] = CorrespondanceDesVariables->NumeroVar_Turbine[Pdt];
IndicesColonnes[il] = CorrespondanceDesVariables.NumeroVar_Turbine[Pdt];
il++;

CoefficientsDeLaMatriceDesContraintes[il] = -1.0;
IndicesColonnes[il] = CorrespondanceDesVariables->NumeroVar_deviations[Pdt];
IndicesColonnes[il] = CorrespondanceDesVariables.NumeroVar_deviations[Pdt];
il++;

Sens[NombreDeContraintes] = '<';
NombreDeTermesDesLignes[NombreDeContraintes] = 2;
NombreDeContraintes++;
}

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

CoefficientsDeLaMatriceDesContraintes[il] = 1.0;
IndicesColonnes[il] = CorrespondanceDesVariables->NumeroVar_Turbine[Pdt];
IndicesColonnes[il] = CorrespondanceDesVariables.NumeroVar_Turbine[Pdt];
il++;

CoefficientsDeLaMatriceDesContraintes[il] = 1.0;
IndicesColonnes[il] = CorrespondanceDesVariables->NumeroVar_deviations[Pdt];
IndicesColonnes[il] = CorrespondanceDesVariables.NumeroVar_deviations[Pdt];
il++;

Sens[NombreDeContraintes] = '>';
NombreDeTermesDesLignes[NombreDeContraintes] = 2;
NombreDeContraintes++;
}

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

CoefficientsDeLaMatriceDesContraintes[il] = 1.0;
IndicesColonnes[il] = CorrespondanceDesVariables->NumeroVar_deviations[Pdt];
IndicesColonnes[il] = CorrespondanceDesVariables.NumeroVar_deviations[Pdt];
il++;

CoefficientsDeLaMatriceDesContraintes[il] = -1.0;
IndicesColonnes[il] = CorrespondanceDesVariables->NumeroVar_deviationMax;
IndicesColonnes[il] = CorrespondanceDesVariables.NumeroVar_deviationMax;
il++;

Sens[NombreDeContraintes] = '<';
NombreDeTermesDesLignes[NombreDeContraintes] = 2;
NombreDeContraintes++;
}

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

CoefficientsDeLaMatriceDesContraintes[il] = 1.0;
IndicesColonnes[il] = CorrespondanceDesVariables->NumeroVar_niveauxFinJours[Pdt];
IndicesColonnes[il] = CorrespondanceDesVariables.NumeroVar_niveauxFinJours[Pdt];
il++;

CoefficientsDeLaMatriceDesContraintes[il] = 1.0;
IndicesColonnes[il] = CorrespondanceDesVariables->NumeroVar_violations[Pdt];
IndicesColonnes[il] = CorrespondanceDesVariables.NumeroVar_violations[Pdt];
il++;

Sens[NombreDeContraintes] = '>';
NombreDeTermesDesLignes[NombreDeContraintes] = 2;
NombreDeContraintes++;
}

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

CoefficientsDeLaMatriceDesContraintes[il] = 1.0;
IndicesColonnes[il] = CorrespondanceDesVariables->NumeroVar_violations[Pdt];
IndicesColonnes[il] = CorrespondanceDesVariables.NumeroVar_violations[Pdt];
il++;

CoefficientsDeLaMatriceDesContraintes[il] = -1.0;
IndicesColonnes[il] = CorrespondanceDesVariables->NumeroVar_violationMax;
IndicesColonnes[il] = CorrespondanceDesVariables.NumeroVar_violationMax;
il++;

Sens[NombreDeContraintes] = '<';
Expand Down
Loading

0 comments on commit d45109f

Please sign in to comment.