Skip to content

Commit

Permalink
[FIX] Solved unfeasible and other segfaults
Browse files Browse the repository at this point in the history
  • Loading branch information
payetvin committed Sep 15, 2023
1 parent 634d415 commit 089a1fe
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 37 deletions.
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
14 changes: 7 additions & 7 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[1];

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
3 changes: 2 additions & 1 deletion src/solver/hydro/management/daily.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ inline void HydroManagement::prepareDailyOptimalGenerations(Solver::Variable::St
uint firstDay = study.calendar.months[simulationMonth].daysYear.first;
uint endDay = firstDay + daysPerMonth;

DONNEES_MENSUELLES problem = H2O_J_Instanciation();
DONNEES_MENSUELLES& problem = *H2O_J_Instanciation();
H2O_J_AjouterBruitAuCout(problem);
problem.NombreDeJoursDuMois = (int)daysPerMonth;
problem.TurbineDuMois = data.MOG[realmonth];
Expand Down Expand Up @@ -540,6 +540,7 @@ inline void HydroManagement::prepareDailyOptimalGenerations(Solver::Variable::St
}

H2O2_J_Free(&problem);
delete[] &problem;
}

uint firstDaySimu = study.parameters.simulationDays.first;
Expand Down
2 changes: 1 addition & 1 deletion src/solver/hydro/management/monthly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.);
Expand Down
2 changes: 1 addition & 1 deletion src/solver/hydro/monthly/h2o_m_fonctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#ifndef __SOLVER_H2O_M_FONCTIONS__
#define __SOLVER_H2O_M_FONCTIONS__

DONNEES_ANNUELLES H2O_M_Instanciation(int);
DONNEES_ANNUELLES* H2O_M_Instanciation(int);
void H2O_M_OptimiserUneAnnee(DONNEES_ANNUELLES&, int);
void H2O_M_Free(DONNEES_ANNUELLES&);

Expand Down
3 changes: 2 additions & 1 deletion src/solver/hydro/monthly/h2o_m_free.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ void H2O_M_Free(DONNEES_ANNUELLES& DonneesAnnuelles)
}
}

free(ProblemeHydraulique.Probleme);
/* delete ProblemeHydraulique.Probleme; */
delete &DonneesAnnuelles;

return;
}
43 changes: 18 additions & 25 deletions src/solver/hydro/monthly/h2o_m_instanciation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,25 @@
#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{};
DONNEES_ANNUELLES* DonneesAnnuelles = new DONNEES_ANNUELLES;
DonneesAnnuelles->NombreDePasDeTemps = 12;

DonneesAnnuelles.NombreDePasDeTemps = 12;
int NbPdt = DonneesAnnuelles->NombreDePasDeTemps;

NbPdt = DonneesAnnuelles.NombreDePasDeTemps;
DonneesAnnuelles->TurbineMax.assign(NbPdt, 0.);
DonneesAnnuelles->TurbineMin.assign(NbPdt, 0.);
DonneesAnnuelles->TurbineCible.assign(NbPdt, 0.);
DonneesAnnuelles->Turbine.assign(NbPdt, 0.);

DonneesAnnuelles.TurbineMax.assign(NbPdt, 0.);
DonneesAnnuelles.TurbineMin.assign(NbPdt, 0.);
DonneesAnnuelles.TurbineCible.assign(NbPdt, 0.);
DonneesAnnuelles.Turbine.assign(NbPdt, 0.);
DonneesAnnuelles->Apport.assign(NbPdt, 0.);

DonneesAnnuelles.Apport.assign(NbPdt, 0.);
DonneesAnnuelles->Volume.assign(NbPdt, 0.);
DonneesAnnuelles->VolumeMin.assign(NbPdt, 0.);
DonneesAnnuelles->VolumeMax.assign(NbPdt, 0.);

DonneesAnnuelles.Volume.assign(NbPdt, 0.);
DonneesAnnuelles.VolumeMin.assign(NbPdt, 0.);
DonneesAnnuelles.VolumeMax.assign(NbPdt, 0.);

PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesAnnuelles.ProblemeHydraulique;
PROBLEME_HYDRAULIQUE& ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique;

ProblemeHydraulique.NombreDeReservoirs = NombreDeReservoirs;

Expand All @@ -75,7 +68,7 @@ DONNEES_ANNUELLES H2O_M_Instanciation(int NombreDeReservoirs)
CorrespondanceDesVariables.NumeroDeVariableDEcartPositifAuTurbineCible.assign(NbPdt, 0);
CorrespondanceDesVariables.NumeroDeVariableDEcartNegatifAuTurbineCible.assign(NbPdt, 0);

NombreDeVariables = 0;
int NombreDeVariables = 0;
NombreDeVariables += NbPdt;
NombreDeVariables += NbPdt;
NombreDeVariables += NbPdt;
Expand All @@ -92,7 +85,7 @@ DONNEES_ANNUELLES H2O_M_Instanciation(int NombreDeReservoirs)

ProblemeLineairePartieFixe.TypeDeVariable.assign(NombreDeVariables, 0);

NombreDeContraintes = 0;
int NombreDeContraintes = 0;
NombreDeContraintes += NbPdt;
NombreDeContraintes += 1;
NombreDeContraintes += NbPdt;
Expand All @@ -107,7 +100,7 @@ DONNEES_ANNUELLES H2O_M_Instanciation(int NombreDeReservoirs)
ProblemeLineairePartieFixe.IndicesDebutDeLigne.assign(NombreDeContraintes, 0);
ProblemeLineairePartieFixe.NombreDeTermesDesLignes.assign(NombreDeContraintes, 0);

NombreDeTermesAlloues = 0;
int NombreDeTermesAlloues = 0;
NombreDeTermesAlloues += 3 * NbPdt;
NombreDeTermesAlloues += 2;
NombreDeTermesAlloues += 2 * NbPdt;
Expand Down Expand Up @@ -139,9 +132,9 @@ DONNEES_ANNUELLES H2O_M_Instanciation(int NombreDeReservoirs)
ProblemeLineairePartieVariable.CoutsReduits.assign(NombreDeVariables, 0.);
ProblemeLineairePartieVariable.CoutsMarginauxDesContraintes.assign(NombreDeContraintes, 0.);

H2O_M_ConstruireLesVariables(DonneesAnnuelles);
H2O_M_ConstruireLesVariables(*DonneesAnnuelles);

H2O_M_ConstruireLesContraintes(DonneesAnnuelles);
H2O_M_ConstruireLesContraintes(*DonneesAnnuelles);

return DonneesAnnuelles;
}

0 comments on commit 089a1fe

Please sign in to comment.