Skip to content

Commit

Permalink
Add noise to the cost in the daily & monthly allocation problem (#622)
Browse files Browse the repository at this point in the history
  • Loading branch information
flomnes authored Mar 28, 2022
1 parent df26979 commit c3c51fb
Show file tree
Hide file tree
Showing 22 changed files with 156 additions and 852 deletions.
2 changes: 2 additions & 0 deletions src/solver/cmake/hydro.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ set(SRC_EXT_SOLVER_H2O_DAILY
hydro/daily/h2o_j_resoudre_le_probleme_lineaire.c
hydro/daily/h2o_j_lisser_les_sur_turbines.c
hydro/daily/h2o_j_sys.h
hydro/daily/h2o_j_ajouter_bruit_au_cout.cpp
)

set(SRC_EXT_SOLVER_H2O_MONTHLY
Expand All @@ -26,6 +27,7 @@ set(SRC_EXT_SOLVER_H2O_MONTHLY
hydro/monthly/h2o_m_initialiser_les_second_membre.c
hydro/monthly/h2o_m_instanciation.c
hydro/monthly/h2o_m_optimiser_une_annee.c
hydro/monthly/h2o_m_ajouter_bruit.cpp
hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.c
hydro/monthly/h2o_m_sys.h
)
Expand Down
104 changes: 0 additions & 104 deletions src/solver/hydro/daily/Test.c

This file was deleted.

35 changes: 35 additions & 0 deletions src/solver/hydro/daily/h2o_j_ajouter_bruit_au_cout.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <antares/mersenne-twister/mersenne-twister.h>
#include "h2o_j_donnees_mensuelles.h"
#include "h2o_j_fonctions.h"

namespace Constants
{
constexpr double noiseAmplitude = 1e-3;
constexpr unsigned int seed = 0x79686a64; // "hydj" in hexa
} // namespace Constants

void H2O_J_AjouterBruitAuCout(DONNEES_MENSUELLES* donnesMensuelles)
{
auto ProblemeHydraulique = donnesMensuelles->ProblemeHydraulique;
auto ProblemeLineairePartieFixe = ProblemeHydraulique->ProblemeLineairePartieFixe;
auto CorrespondanceDesVariables = ProblemeHydraulique->CorrespondanceDesVariables;
auto NombreDeProblemes = ProblemeHydraulique->NombreDeProblemes;
Antares::MersenneTwister noiseGenerator;
noiseGenerator.reset(Constants::seed); // Arbitrary seed, hard-coded since we don't really want
// the user to change it

for (int i = 0; i < NombreDeProblemes; i++)
{
for (int j = 0; j < ProblemeLineairePartieFixe[i]->NombreDeVariables; j++)
{
ProblemeLineairePartieFixe[i]->CoutLineaire[j] += noiseGenerator() * Constants::noiseAmplitude;
}

ProblemeLineairePartieFixe[i]
->CoutLineaire[CorrespondanceDesVariables[i]->NumeroDeLaVariableMu]
+= noiseGenerator() * Constants::noiseAmplitude;
ProblemeLineairePartieFixe[i]
->CoutLineaire[CorrespondanceDesVariables[i]->NumeroDeLaVariableXi]
+= noiseGenerator() * Constants::noiseAmplitude;
}
}
4 changes: 2 additions & 2 deletions src/solver/hydro/daily/h2o_j_fonctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ extern "C"
#endif

DONNEES_MENSUELLES* H2O_J_Instanciation(void);

void H2O_J_OptimiserUnMois(DONNEES_MENSUELLES*);
char H2O_J_EcrireJeuDeDonneesLineaireAuFormatMPS(DONNEES_MENSUELLES*, FILE*);
void H2O_J_Free(DONNEES_MENSUELLES*);
void H2O_J_ConstruireLesContraintes(int,
int*,
Expand All @@ -58,7 +58,7 @@ extern "C"
void H2O_J_InitialiserLeSecondMembre(DONNEES_MENSUELLES*, int);
void H2O_J_ResoudreLeProblemeLineaire(DONNEES_MENSUELLES*, int);
void H2O_J_LisserLesSurTurbines(DONNEES_MENSUELLES*, int);

void H2O_J_AjouterBruitAuCout(DONNEES_MENSUELLES*);
#ifdef __cplusplus
}
#endif
Expand Down
209 changes: 0 additions & 209 deletions src/solver/hydro/daily/h2o_j_resoudre_le_probleme_lineaire.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,212 +197,3 @@ void H2O_J_ResoudreLeProblemeLineaire(DONNEES_MENSUELLES* DonneesMensuelles, int

return;
}

char H2O_J_EcrireJeuDeDonneesLineaireAuFormatMPS(DONNEES_MENSUELLES* DonneesMensuelles, FILE* Flot)
{
int Cnt;
int Var;
int il;
int ilk;
int ilMax;
char* Nombre;
int* Cder;
int* Cdeb;
int* NumeroDeContrainte;
int* Csui;
PROBLEME_SIMPLEXE* Probleme;

int NombreDeVariables;
int* TypeDeBorneDeLaVariable;
double* Xmax;
double* Xmin;
double* CoutLineaire;
int NombreDeContraintes;
double* SecondMembre;
char* Sens;
int* IndicesDebutDeLigne;
int* NombreDeTermesDesLignes;
double* CoefficientsDeLaMatriceDesContraintes;
int* IndicesColonnes;

Probleme = (PROBLEME_SIMPLEXE*)(DonneesMensuelles->ProblemeHydraulique)->Probleme;

NombreDeVariables = Probleme->NombreDeVariables;
TypeDeBorneDeLaVariable = Probleme->TypeDeVariable;
Xmax = Probleme->Xmax;
Xmin = Probleme->Xmin;
CoutLineaire = Probleme->CoutLineaire;
NombreDeContraintes = Probleme->NombreDeContraintes;
SecondMembre = Probleme->SecondMembre;
Sens = Probleme->Sens;
IndicesDebutDeLigne = Probleme->IndicesDebutDeLigne;
NombreDeTermesDesLignes = Probleme->NombreDeTermesDesLignes;
CoefficientsDeLaMatriceDesContraintes = Probleme->CoefficientsDeLaMatriceDesContraintes;
IndicesColonnes = Probleme->IndicesColonnes;

for (ilMax = -1, Cnt = 0; Cnt < NombreDeContraintes; Cnt++)
{
if ((IndicesDebutDeLigne[Cnt] + NombreDeTermesDesLignes[Cnt] - 1) > ilMax)
{
ilMax = IndicesDebutDeLigne[Cnt] + NombreDeTermesDesLignes[Cnt] - 1;
}
}
ilMax += NombreDeContraintes;

Cder = (int*)malloc(NombreDeVariables * sizeof(int));
Cdeb = (int*)malloc(NombreDeVariables * sizeof(int));
NumeroDeContrainte = (int*)malloc(ilMax * sizeof(int));
Csui = (int*)malloc(ilMax * sizeof(int));
Nombre = (char*)malloc(1024);
if (Cder == NULL || Cdeb == NULL || NumeroDeContrainte == NULL || Csui == NULL
|| Nombre == NULL)
{
return (0);
}

for (Var = 0; Var < NombreDeVariables; Var++)
Cdeb[Var] = -1;
for (Cnt = 0; Cnt < NombreDeContraintes; Cnt++)
{
il = IndicesDebutDeLigne[Cnt];
ilMax = il + NombreDeTermesDesLignes[Cnt];
while (il < ilMax)
{
Var = IndicesColonnes[il];
if (Cdeb[Var] < 0)
{
Cdeb[Var] = il;
NumeroDeContrainte[il] = Cnt;
Csui[il] = -1;
Cder[Var] = il;
}
else
{
ilk = Cder[Var];
Csui[ilk] = il;
NumeroDeContrainte[il] = Cnt;
Csui[il] = -1;
Cder[Var] = il;
}
il++;
}
}
free(Cder);

fprintf(Flot, "* Number of variables: %d\n", NombreDeVariables);
fprintf(Flot, "* Number of constraints: %d\n", NombreDeContraintes);

fprintf(Flot, "NAME Pb Solve\n");

fprintf(Flot, "ROWS\n");

fprintf(Flot, " N OBJECTIF\n");

for (Cnt = 0; Cnt < NombreDeContraintes; Cnt++)
{
if (Sens[Cnt] == '=')
{
fprintf(Flot, " E R%07d\n", Cnt);
}
else if (Sens[Cnt] == '<')
{
fprintf(Flot, " L R%07d\n", Cnt);
}
else if (Sens[Cnt] == '>')
{
fprintf(Flot, " G R%07d\n", Cnt);
}
else
{
fprintf(Flot,
"H2O_J_EcrireJeuDeDonneesMPS : le sens de la contrainte %d: %c ne fait pas "
"partie des sens reconnus\n",
Cnt,
Sens[Cnt]);
fprintf(Flot, "Nombre de contraintes %d\n", NombreDeContraintes);
return (0);
}
}

fprintf(Flot, "COLUMNS\n");
for (Var = 0; Var < NombreDeVariables; Var++)
{
if (CoutLineaire[Var] != 0.0)
{
SNPRINTF(Nombre, 1024, "%-.10lf", CoutLineaire[Var]);
fprintf(Flot, " C%07d OBJECTIF %s\n", Var, Nombre);
}
il = Cdeb[Var];
while (il >= 0)
{
SNPRINTF(Nombre, 1024, "%-.10lf", CoefficientsDeLaMatriceDesContraintes[il]);
fprintf(Flot, " C%07d R%07d %s\n", Var, NumeroDeContrainte[il], Nombre);
il = Csui[il];
}
}

fprintf(Flot, "RHS\n");
for (Cnt = 0; Cnt < NombreDeContraintes; Cnt++)
{
if (SecondMembre[Cnt] != 0.0)
{
SNPRINTF(Nombre, 1024, "%-.9lf", SecondMembre[Cnt]);
fprintf(Flot, " RHSVAL R%07d %s\n", Cnt, Nombre);
}
}

fprintf(Flot, "BOUNDS\n");

for (Var = 0; Var < NombreDeVariables; Var++)
{
if (TypeDeBorneDeLaVariable[Var] == VARIABLE_FIXE)
{
SNPRINTF(Nombre, 1024, "%-.9lf", Xmin[Var]);
fprintf(Flot, " FX BNDVALUE C%07d %s\n", Var, Nombre);
continue;
}

if (TypeDeBorneDeLaVariable[Var] == VARIABLE_BORNEE_DES_DEUX_COTES)
{
if (Xmin[Var] != 0.0)
{
SNPRINTF(Nombre, 1024, "%-.9lf", Xmin[Var]);
fprintf(Flot, " LO BNDVALUE C%07d %s\n", Var, Nombre);
}
SNPRINTF(Nombre, 1024, "%-.9lf", Xmax[Var]);
fprintf(Flot, " UP BNDVALUE C%07d %s\n", Var, Nombre);
}
if (TypeDeBorneDeLaVariable[Var] == VARIABLE_BORNEE_INFERIEUREMENT)
{
if (Xmin[Var] != 0.0)
{
SNPRINTF(Nombre, 1024, "%-.9lf", Xmin[Var]);
fprintf(Flot, " LO BNDVALUE C%07d %s\n", Var, Nombre);
}
}
if (TypeDeBorneDeLaVariable[Var] == VARIABLE_BORNEE_SUPERIEUREMENT)
{
fprintf(Flot, " MI BNDVALUE C%07d\n", Var);
if (Xmax[Var] != 0.0)
{
SNPRINTF(Nombre, 1024, "%-.9lf", Xmax[Var]);
fprintf(Flot, " UP BNDVALUE C%07d %s\n", Var, Nombre);
}
}
if (TypeDeBorneDeLaVariable[Var] == VARIABLE_NON_BORNEE)
{
fprintf(Flot, " FR BNDVALUE C%07d\n", Var);
}
}

fprintf(Flot, "ENDATA\n");

free(Cdeb);
free(NumeroDeContrainte);
free(Csui);
free(Nombre);

fclose(Flot);

return (1);
}
Loading

0 comments on commit c3c51fb

Please sign in to comment.