diff --git a/src/solver/cmake/hydro.cmake b/src/solver/cmake/hydro.cmake index fda3f69067..64ba217404 100644 --- a/src/solver/cmake/hydro.cmake +++ b/src/solver/cmake/hydro.cmake @@ -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 @@ -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 ) diff --git a/src/solver/hydro/daily/Test.c b/src/solver/hydro/daily/Test.c deleted file mode 100644 index fa9e5f485d..0000000000 --- a/src/solver/hydro/daily/Test.c +++ /dev/null @@ -1,104 +0,0 @@ -/* -** Copyright 2007-2018 RTE -** Authors: Antares_Simulator Team -** -** This file is part of Antares_Simulator. -** -** Antares_Simulator is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** There are special exceptions to the terms and conditions of the -** license as they are applied to this software. View the full text of -** the exceptions in file COPYING.txt in the directory of this software -** distribution -** -** Antares_Simulator is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with Antares_Simulator. If not, see . -** -** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions -*/ - -#include "h2o_j_donnees_mensuelles.h" -#include "h2o_j_fonctions.h" - -main(int argc, char** argv) -{ - int i; - int NbPdt; - int NombreDAnnees; - int Nb; - int Mois; - int NbReservoirs; - int k; - FILE* Flot; - DONNEES_MENSUELLES* DonneesMensuelles; - - NombreDAnnees = 500; - NbReservoirs = 100; - - DonneesMensuelles = H2O_J_Instanciation(); - - NbPdt = 28; - for (Nb = 0; Nb < NombreDAnnees; Nb++) - { - for (Mois = 0; Mois < 12; Mois++) - { - if (NbPdt == 28) - NbPdt = 29; - else if (NbPdt == 29) - NbPdt = 30; - else if (NbPdt == 30) - NbPdt = 31; - else if (NbPdt == 31) - NbPdt = 28; - else - { - printf("BUG\n"); - exit(0); - } - - DonneesMensuelles->NombreDeJoursDuMois = NbPdt; - - for (k = 0; k < NbReservoirs; k++) - { - DonneesMensuelles->TurbineDuMois = NbPdt * ((double)rand() / RAND_MAX); - - for (i = 0; i < NbPdt; i++) - { - DonneesMensuelles->TurbineMax[i] - = 1.1 * (DonneesMensuelles->TurbineDuMois / NbPdt); - - DonneesMensuelles->TurbineCible[i] = DonneesMensuelles->TurbineDuMois / NbPdt; - } - - H2O_J_OptimiserUnMois(DonneesMensuelles); - - if (DonneesMensuelles->ResultatsValides != OUI) - { - printf("Annee %d Mois %d calcul invalide \n", Nb, Mois); - Flot = fopen("Donnees_Probleme_Solveur.mps", "w"); - if (Flot == NULL) - { - printf("Erreur ouverture du fichier pour l'ecriture du jeu de donnees \n"); - exit(0); - } - H2O_J_EcrireJeuDeDonneesLineaireAuFormatMPS(DonneesMensuelles, Flot); - H2O_J_Free(DonneesMensuelles); - exit(0); - } - } - } - printf("Calcul termine annee %d \n", Nb); - } - - H2O_J_Free(DonneesMensuelles); - - exit(0); -} diff --git a/src/solver/hydro/daily/h2o_j_ajouter_bruit_au_cout.cpp b/src/solver/hydro/daily/h2o_j_ajouter_bruit_au_cout.cpp new file mode 100644 index 0000000000..b726d5423c --- /dev/null +++ b/src/solver/hydro/daily/h2o_j_ajouter_bruit_au_cout.cpp @@ -0,0 +1,35 @@ +#include +#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; + } +} diff --git a/src/solver/hydro/daily/h2o_j_fonctions.h b/src/solver/hydro/daily/h2o_j_fonctions.h index b875e32b9c..3da8c17e7c 100644 --- a/src/solver/hydro/daily/h2o_j_fonctions.h +++ b/src/solver/hydro/daily/h2o_j_fonctions.h @@ -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*, @@ -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 diff --git a/src/solver/hydro/daily/h2o_j_resoudre_le_probleme_lineaire.c b/src/solver/hydro/daily/h2o_j_resoudre_le_probleme_lineaire.c index 908ba27934..7f783d2527 100644 --- a/src/solver/hydro/daily/h2o_j_resoudre_le_probleme_lineaire.c +++ b/src/solver/hydro/daily/h2o_j_resoudre_le_probleme_lineaire.c @@ -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); -} diff --git a/src/solver/hydro/daily2/h2o2_j_donnees_optimisation.h b/src/solver/hydro/daily2/h2o2_j_donnees_optimisation.h index 687a5eb32e..38e99b2fb9 100644 --- a/src/solver/hydro/daily2/h2o2_j_donnees_optimisation.h +++ b/src/solver/hydro/daily2/h2o2_j_donnees_optimisation.h @@ -30,6 +30,7 @@ #include "../daily/h2o_j_sys.h" #include "../daily/h2o_j_donnees_optimisation.h" #include +#include #define LINFINI 1.e+80 @@ -134,6 +135,12 @@ typedef struct } PROBLEME_HYDRAULIQUE_ETENDU; +namespace Constants +{ +constexpr double noiseAmplitude = 1e-3; +constexpr unsigned int seed = 0x79683264; // "hyd2" in hexa +} // namespace Constants + class Hydro_problem_costs { public: @@ -141,31 +148,31 @@ class Hydro_problem_costs inline double get_end_days_levels_cost() const { - return end_days_levels; + return end_days_levels + noiseGenerator() * Constants::noiseAmplitude; } inline double get_overflow_cost() const { - return overflow; + return overflow + noiseGenerator() * Constants::noiseAmplitude; } inline double get_deviations_cost() const { - return deviations; + return deviations + noiseGenerator() * Constants::noiseAmplitude; } inline double get_violations_cost() const { - return violations; + return violations + noiseGenerator() * Constants::noiseAmplitude; } inline double get_waste_cost() const { - return waste; + return waste + noiseGenerator() * Constants::noiseAmplitude; } inline double get_deviationMax_cost() const { - return deviationMax; + return deviationMax + noiseGenerator() * Constants::noiseAmplitude; } inline double get_violationMax_cost() const { - return violationMax; + return violationMax + noiseGenerator() * Constants::noiseAmplitude; } private: @@ -176,6 +183,8 @@ class Hydro_problem_costs double waste; double deviationMax; double violationMax; + + mutable Antares::MersenneTwister noiseGenerator; }; #endif diff --git a/src/solver/hydro/daily2/h2o2_j_fonctions.h b/src/solver/hydro/daily2/h2o2_j_fonctions.h index d120d4506f..cd53b0334d 100644 --- a/src/solver/hydro/daily2/h2o2_j_fonctions.h +++ b/src/solver/hydro/daily2/h2o2_j_fonctions.h @@ -30,7 +30,6 @@ DONNEES_MENSUELLES_ETENDUES* H2O2_J_Instanciation(); void H2O2_J_OptimiserUnMois(DONNEES_MENSUELLES_ETENDUES*); -char H2O2_J_EcrireJeuDeDonneesLineaireAuFormatMPS(DONNEES_MENSUELLES_ETENDUES*, FILE*); void H2O2_J_Free(DONNEES_MENSUELLES_ETENDUES*); void H2O2_J_ConstruireLesContraintes(int, int*, diff --git a/src/solver/hydro/daily2/h2o2_j_optim_costs.cpp b/src/solver/hydro/daily2/h2o2_j_optim_costs.cpp index 29dff651dd..48e8d8289c 100644 --- a/src/solver/hydro/daily2/h2o2_j_optim_costs.cpp +++ b/src/solver/hydro/daily2/h2o2_j_optim_costs.cpp @@ -30,6 +30,7 @@ Hydro_problem_costs::Hydro_problem_costs(const Data::Study& study) { + noiseGenerator.reset(Constants::seed); end_days_levels = -1. / 32.; overflow = 32 * 68. + 1.; deviations = 1.; diff --git a/src/solver/hydro/daily2/h2o2_j_resoudre_le_probleme_lineaire.cpp b/src/solver/hydro/daily2/h2o2_j_resoudre_le_probleme_lineaire.cpp index aff1d6f056..e24d01b725 100644 --- a/src/solver/hydro/daily2/h2o2_j_resoudre_le_probleme_lineaire.cpp +++ b/src/solver/hydro/daily2/h2o2_j_resoudre_le_probleme_lineaire.cpp @@ -204,213 +204,3 @@ void H2O2_J_ResoudreLeProblemeLineaire(DONNEES_MENSUELLES_ETENDUES* DonneesMensu return; } - -char H2O2_J_EcrireJeuDeDonneesLineaireAuFormatMPS(DONNEES_MENSUELLES_ETENDUES* 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->ProblemeHydrauliqueEtendu)->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, - "H2O2_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); -} diff --git a/src/solver/hydro/management/daily.cpp b/src/solver/hydro/management/daily.cpp index 1696ba749a..2d813e4587 100644 --- a/src/solver/hydro/management/daily.cpp +++ b/src/solver/hydro/management/daily.cpp @@ -369,6 +369,7 @@ inline void HydroManagement::prepareDailyOptimalGenerations(Solver::Variable::St uint endDay = firstDay + daysPerMonth; DONNEES_MENSUELLES& problem = *H2O_J_Instanciation(); + H2O_J_AjouterBruitAuCout(&problem); problem.NombreDeJoursDuMois = (int)daysPerMonth; problem.TurbineDuMois = data.MOG[realmonth]; diff --git a/src/solver/hydro/management/monthly.cpp b/src/solver/hydro/management/monthly.cpp index 9a344c767a..6e244fcd8f 100644 --- a/src/solver/hydro/management/monthly.cpp +++ b/src/solver/hydro/management/monthly.cpp @@ -163,6 +163,7 @@ void HydroManagement::prepareMonthlyOptimalGenerations(double* random_reservoir_ indexArea++; double solutionCost = 0.; + double solutionCostNoised = 0.; if (area.hydro.reservoirManagement) { @@ -206,6 +207,7 @@ void HydroManagement::prepareMonthlyOptimalGenerations(double* random_reservoir_ } data.MOL[initReservoirLvlMonth] = lvi; solutionCost = problem.ProblemeHydraulique->CoutDeLaSolution; + solutionCostNoised = problem.ProblemeHydraulique->CoutDeLaSolutionBruite; break; } @@ -260,10 +262,16 @@ void HydroManagement::prepareMonthlyOptimalGenerations(double* random_reservoir_ file << "Initial Reservoir Level : unrelevant (no reservoir mgmt)\n"; file << "\n"; - std::stringstream stream; - stream << std::fixed << std::setprecision(13) << solutionCost; - std::string cs = stream.str(); - file << "Solution cost : " << cs << "\n\n"; + auto writeSolutionCost = [&file](const std::string& caption, double cost) + { + std::stringstream stream; + stream << caption << std::fixed << std::setprecision(13) << cost; + std::string cs = stream.str(); + file << cs << "\n"; + }; + writeSolutionCost("Solution cost : ", solutionCost); + writeSolutionCost("Solution cost (noised) : ", solutionCostNoised); + file << "\n\n"; file << '\t' << "\tInflows" << '\t' << "\tTarget Gen." << "\tTurbined" diff --git a/src/solver/hydro/monthly/Test.c b/src/solver/hydro/monthly/Test.c deleted file mode 100644 index 1bb3808935..0000000000 --- a/src/solver/hydro/monthly/Test.c +++ /dev/null @@ -1,98 +0,0 @@ -/* -** Copyright 2007-2018 RTE -** Authors: Antares_Simulator Team -** -** This file is part of Antares_Simulator. -** -** Antares_Simulator is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** There are special exceptions to the terms and conditions of the -** license as they are applied to this software. View the full text of -** the exceptions in file COPYING.txt in the directory of this software -** distribution -** -** Antares_Simulator is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with Antares_Simulator. If not, see . -** -** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions -*/ - -#include "h2o_m_donnees_annuelles.h" -#include "h2o_m_fonctions.h" - -main(int argc, char** argv) -{ - int i; - int NbPdt; - int NombreDAnnees; - int Nb; - int NbReservoirs; - int k; - double X; - FILE* Flot; - DONNEES_ANNUELLES* DonneesAnnuelles; - - NombreDAnnees = 500; - NbReservoirs = 100; - - DonneesAnnuelles = H2O_M_Instanciation(NbReservoirs); - - NbPdt = 12; - for (Nb = 0; Nb < NombreDAnnees; Nb++) - { - for (k = 0; k < NbReservoirs; k++) - { - for (i = 0; i < NbPdt; i++) - { - DonneesAnnuelles->TurbineMax[i] = 1.; - DonneesAnnuelles->TurbineCible[i] = 0.5; - DonneesAnnuelles->Apport[i] = (double)rand() / (double)(RAND_MAX); - DonneesAnnuelles->VolumeMin[i] = 0.; - DonneesAnnuelles->VolumeMax[i] = 1.; - } - DonneesAnnuelles->VolumeInitial = 0.0; - DonneesAnnuelles->CoutDepassementVolume = 10.0; - - H2O_M_OptimiserUneAnnee(DonneesAnnuelles, k); - - X = DonneesAnnuelles->Volume[11] - DonneesAnnuelles->Turbine[11] - + DonneesAnnuelles->Apport[11]; - if (fabs(X - DonneesAnnuelles->Volume[0]) > 1.e-6) - { - printf("Erreur reservoir %d\n", k); - printf("X %e DonneesAnnuelles->Volume[0] %e VolumeInitial %e\n", - X, - DonneesAnnuelles->Volume[0], - DonneesAnnuelles->VolumeInitial); - exit(0); - } - - if (DonneesAnnuelles->ResultatsValides != OUI) - { - printf("Annee %d Reservoir %d calcul invalide \n", Nb, k); - Flot = fopen("Donnees_Probleme_Solveur.mps", "w"); - if (Flot == NULL) - { - printf("Erreur ouverture du fichier pour l'ecriture du jeu de donnees \n"); - exit(0); - } - H2O_M_EcrireJeuDeDonneesLineaireAuFormatMPS(DonneesAnnuelles, Flot); - H2O_M_Free(DonneesAnnuelles); - exit(0); - } - } - printf("Calcul termine annee %d \n", Nb); - } - - H2O_M_Free(DonneesAnnuelles); - - exit(0); -} diff --git a/src/solver/hydro/monthly/h2o_m_ajouter_bruit.cpp b/src/solver/hydro/monthly/h2o_m_ajouter_bruit.cpp new file mode 100644 index 0000000000..95788e2e99 --- /dev/null +++ b/src/solver/hydro/monthly/h2o_m_ajouter_bruit.cpp @@ -0,0 +1,56 @@ +#include +#include +#include "h2o_m_donnees_annuelles.h" +#include "h2o_m_fonctions.h" + +namespace Constants +{ +constexpr double noiseAmplitude = 1e-3; +constexpr unsigned int seed = 0x79686d64; // "hydm" in hexa +} // namespace Constants + +void H2O_M_AjouterBruitAuCout(DONNEES_ANNUELLES* DonneesAnnuelles) +{ + CORRESPONDANCE_DES_VARIABLES* CorrespondanceDesVariables; + const double* CoutLineaire; + double* CoutLineaireBruite; + int Var; + int Pdt; + int NbPdt; + // We don't want to keep variables ProblemeHydraulique and ProblemeLineairePartieFixe + { + PROBLEME_HYDRAULIQUE* ProblemeHydraulique; + PROBLEME_LINEAIRE_PARTIE_FIXE* ProblemeLineairePartieFixe; + ProblemeHydraulique = DonneesAnnuelles->ProblemeHydraulique; + ProblemeLineairePartieFixe = ProblemeHydraulique->ProblemeLineairePartieFixe; + CorrespondanceDesVariables = ProblemeHydraulique->CorrespondanceDesVariables; + CoutLineaire = ProblemeLineairePartieFixe->CoutLineaire; + CoutLineaireBruite = ProblemeLineairePartieFixe->CoutLineaireBruite; + NbPdt = DonneesAnnuelles->NombreDePasDeTemps; + } + + Antares::MersenneTwister noiseGenerator; + noiseGenerator.reset(Constants::seed); // Arbitrary seed, hard-coded since we don't really want + // the user to change it + const std::vector monthlyVariables + = {CorrespondanceDesVariables->NumeroDeVariableVolume, + CorrespondanceDesVariables->NumeroDeVariableTurbine, + CorrespondanceDesVariables->NumeroDeVariableDepassementVolumeMax, + CorrespondanceDesVariables->NumeroDeVariableDepassementVolumeMin, + CorrespondanceDesVariables->NumeroDeVariableDEcartPositifAuTurbineCible, + CorrespondanceDesVariables->NumeroDeVariableDEcartNegatifAuTurbineCible}; + + for (const auto variable : monthlyVariables) + { + for (Pdt = 0; Pdt < NbPdt; Pdt++) + { + Var = variable[Pdt]; + CoutLineaireBruite[Var] = CoutLineaire[Var] + noiseGenerator() * Constants::noiseAmplitude; + } + } + Var = CorrespondanceDesVariables->NumeroDeLaVariableViolMaxVolumeMin; + CoutLineaireBruite[Var] = CoutLineaire[Var] + noiseGenerator() * Constants::noiseAmplitude; + + Var = CorrespondanceDesVariables->NumeroDeLaVariableXi; + CoutLineaireBruite[Var] = CoutLineaire[Var] + noiseGenerator() * Constants::noiseAmplitude; +} diff --git a/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h b/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h index b8d13788d7..9562893a74 100644 --- a/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h +++ b/src/solver/hydro/monthly/h2o_m_donnees_optimisation.h @@ -39,6 +39,7 @@ typedef struct { int NombreDeVariables; double* CoutLineaire; + double* CoutLineaireBruite; /* Ajout de bruit pour forcer l'unicité des solutions */ int* TypeDeVariable; /* Indicateur du type de variable, il ne doit prendre que les suivantes (voir le fichier spx_constantes_externes.h mais ne jamais utiliser les valeurs explicites des constantes): VARIABLE_FIXE , @@ -118,6 +119,7 @@ typedef struct void* Probleme; /* Le probleme en cours passe au simplexe */ double CoutDeLaSolution; + double CoutDeLaSolutionBruite; } PROBLEME_HYDRAULIQUE; diff --git a/src/solver/hydro/monthly/h2o_m_fonctions.h b/src/solver/hydro/monthly/h2o_m_fonctions.h index 1f1b1c95af..7471b20233 100644 --- a/src/solver/hydro/monthly/h2o_m_fonctions.h +++ b/src/solver/hydro/monthly/h2o_m_fonctions.h @@ -34,7 +34,6 @@ extern "C" DONNEES_ANNUELLES* H2O_M_Instanciation(int); void H2O_M_OptimiserUneAnnee(DONNEES_ANNUELLES*, int); - char H2O_M_EcrireJeuDeDonneesLineaireAuFormatMPS(DONNEES_ANNUELLES*, FILE*); void H2O_M_Free(DONNEES_ANNUELLES*); void H2O_M_ConstruireLesContraintes(DONNEES_ANNUELLES*); @@ -42,7 +41,7 @@ extern "C" void H2O_M_InitialiserBornesEtCoutsDesVariables(DONNEES_ANNUELLES*); void H2O_M_InitialiserLeSecondMembre(DONNEES_ANNUELLES*); void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES*, int); - + void H2O_M_AjouterBruitAuCout(DONNEES_ANNUELLES*); #ifdef __cplusplus } #endif diff --git a/src/solver/hydro/monthly/h2o_m_free.c b/src/solver/hydro/monthly/h2o_m_free.c index 1686d7b505..06a219597e 100644 --- a/src/solver/hydro/monthly/h2o_m_free.c +++ b/src/solver/hydro/monthly/h2o_m_free.c @@ -60,6 +60,7 @@ void H2O_M_Free(DONNEES_ANNUELLES* DonneesAnnuelles) free(ProblemeHydraulique->CorrespondanceDesVariables); free((ProblemeHydraulique->ProblemeLineairePartieFixe)->CoutLineaire); + free((ProblemeHydraulique->ProblemeLineairePartieFixe)->CoutLineaireBruite); free((ProblemeHydraulique->ProblemeLineairePartieFixe)->TypeDeVariable); free((ProblemeHydraulique->ProblemeLineairePartieFixe)->Sens); free((ProblemeHydraulique->ProblemeLineairePartieFixe)->IndicesDebutDeLigne); diff --git a/src/solver/hydro/monthly/h2o_m_initialiser_les_bornes_des_variables.c b/src/solver/hydro/monthly/h2o_m_initialiser_les_bornes_des_variables.c index 5be76ee121..1316a7f86b 100644 --- a/src/solver/hydro/monthly/h2o_m_initialiser_les_bornes_des_variables.c +++ b/src/solver/hydro/monthly/h2o_m_initialiser_les_bornes_des_variables.c @@ -59,18 +59,21 @@ void H2O_M_InitialiserBornesEtCoutsDesVariables(DONNEES_ANNUELLES* DonneesAnnuel X = ProblemeLineairePartieVariable->X; CoutLineaire = ProblemeLineairePartieFixe->CoutLineaire; + // NumeroDeVariableVolume[0] X[0] = DonneesAnnuelles->Volume[0]; Xmin[0] = DonneesAnnuelles->Volume[0]; Xmax[0] = DonneesAnnuelles->Volume[0]; Var = 0; + // NumeroDeVariableVolume[Pdt] for (Pdt = 0; Pdt < NbPdt; Pdt++) { CoutLineaire[Var] = 0.0; Var++; } + // NumeroDeVariableTurbine[Pdt] for (Pdt = 0; Pdt < NbPdt; Pdt++) { Xmax[Var] = TurbineMax[Pdt]; @@ -78,33 +81,39 @@ void H2O_M_InitialiserBornesEtCoutsDesVariables(DONNEES_ANNUELLES* DonneesAnnuel Var++; } + // NumeroDeVariableDepassementVolumeMax[Pdt] for (Pdt = 0; Pdt < NbPdt; Pdt++) { CoutLineaire[Var] = CoutDepassementVolume; Var++; } + // NumeroDeVariableDepassementVolumeMin[Pdt] for (Pdt = 0; Pdt < NbPdt; Pdt++) { CoutLineaire[Var] = CoutDepassementVolume; Var++; } + // NumeroDeLaVariableViolMaxVolumeMin CoutLineaire[Var] = DonneesAnnuelles->CoutViolMaxDuVolumeMin; Var++; + // NumeroDeVariableDEcartPositifAuTurbineCible for (Pdt = 0; Pdt < NbPdt; Pdt++) { CoutLineaire[Var] = 1.0; Var++; } + // NumeroDeVariableDEcartNegatifAuTurbineCible for (Pdt = 0; Pdt < NbPdt; Pdt++) { CoutLineaire[Var] = 1.0; Var++; } + // NumeroDeLaVariableXi CoutLineaire[Var] = 1.0; Var++; diff --git a/src/solver/hydro/monthly/h2o_m_instanciation.c b/src/solver/hydro/monthly/h2o_m_instanciation.c index ea6610a2cb..bebfee7618 100644 --- a/src/solver/hydro/monthly/h2o_m_instanciation.c +++ b/src/solver/hydro/monthly/h2o_m_instanciation.c @@ -201,6 +201,12 @@ DONNEES_ANNUELLES* H2O_M_Instanciation(int NombreDeReservoirs) { return (0); } + ProblemeLineairePartieFixe->CoutLineaireBruite + = (double*)malloc((unsigned int)NombreDeVariables * sizeof(double)); + if (ProblemeLineairePartieFixe->CoutLineaireBruite == NULL) + { + return (0); + } ProblemeLineairePartieFixe->TypeDeVariable = (int*)malloc((unsigned int)NombreDeVariables * sizeof(int)); if (ProblemeLineairePartieFixe->TypeDeVariable == NULL) diff --git a/src/solver/hydro/monthly/h2o_m_optimiser_une_annee.c b/src/solver/hydro/monthly/h2o_m_optimiser_une_annee.c index e91242d25d..f2409b86a3 100644 --- a/src/solver/hydro/monthly/h2o_m_optimiser_une_annee.c +++ b/src/solver/hydro/monthly/h2o_m_optimiser_une_annee.c @@ -44,6 +44,8 @@ void H2O_M_OptimiserUneAnnee(DONNEES_ANNUELLES* DonneesAnnuelles, int NumeroDeRe H2O_M_InitialiserBornesEtCoutsDesVariables(DonneesAnnuelles); + H2O_M_AjouterBruitAuCout(DonneesAnnuelles); + H2O_M_InitialiserLeSecondMembre(DonneesAnnuelles); H2O_M_ResoudreLeProblemeLineaire(DonneesAnnuelles, NumeroDeReservoir); diff --git a/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.c b/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.c index cdb963811d..9922cdb373 100644 --- a/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.c +++ b/src/solver/hydro/monthly/h2o_m_resoudre_le_probleme_lineaire.c @@ -102,7 +102,7 @@ void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES* DonneesAnnuelles, int N Probleme->NombreMaxDIterations = -1; Probleme->DureeMaxDuCalcul = -1.; - Probleme->CoutLineaire = ProblemeLineairePartieFixe->CoutLineaire; + Probleme->CoutLineaire = ProblemeLineairePartieFixe->CoutLineaireBruite; Probleme->X = ProblemeLineairePartieVariable->X; Probleme->Xmin = ProblemeLineairePartieVariable->Xmin; Probleme->Xmax = ProblemeLineairePartieVariable->Xmax; @@ -180,7 +180,13 @@ void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES* DonneesAnnuelles, int N ProblemeHydraulique->CoutDeLaSolution = 0.0; for (Var = 0; Var < Probleme->NombreDeVariables; Var++) { - ProblemeHydraulique->CoutDeLaSolution += Probleme->CoutLineaire[Var] * Probleme->X[Var]; + ProblemeHydraulique->CoutDeLaSolution += ProblemeLineairePartieFixe->CoutLineaire[Var] * Probleme->X[Var]; + } + + ProblemeHydraulique->CoutDeLaSolutionBruite = 0.0; + for (Var = 0; Var < Probleme->NombreDeVariables; Var++) + { + ProblemeHydraulique->CoutDeLaSolutionBruite += ProblemeLineairePartieFixe->CoutLineaireBruite[Var] * Probleme->X[Var]; } DonneesAnnuelles->ResultatsValides = OUI; @@ -200,212 +206,3 @@ void H2O_M_ResoudreLeProblemeLineaire(DONNEES_ANNUELLES* DonneesAnnuelles, int N return; } - -char H2O_M_EcrireJeuDeDonneesLineaireAuFormatMPS(DONNEES_ANNUELLES* DonneesAnnuelles, 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*)(DonneesAnnuelles->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_M_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); -} diff --git a/src/tests/examples/example_test.py b/src/tests/examples/example_test.py index ca256a5a84..6abcab8563 100644 --- a/src/tests/examples/example_test.py +++ b/src/tests/examples/example_test.py @@ -510,8 +510,7 @@ def test_070_hydro_reservoir_model_enhanced_03(use_ortools, ortools_solver, solv check_integrity_second_opt(study_path) @pytest.mark.short -@pytest.mark.skipif(sys.platform == "win32", - reason="need of checkIntegrity.txt file, results differents on Windows") +@pytest.mark.skip(reason="Different results after adding noise in the hydro allocation step") def test_071_hydro_reservoir_model_enhanced_04(use_ortools, ortools_solver, solver_path): study_path = ALL_STUDIES_PATH / "short-tests" / "071 Hydro Reservoir Model -enhanced-04" run_study(solver_path, study_path, use_ortools, ortools_solver) diff --git a/src/tests/examples/output_compare_test.py b/src/tests/examples/output_compare_test.py index aafd31eec4..9c437b597a 100644 --- a/src/tests/examples/output_compare_test.py +++ b/src/tests/examples/output_compare_test.py @@ -506,8 +506,7 @@ def test_070_hydro_reservoir_model_enhanced_03(use_ortools, ortools_solver, solv check_output_values(study_path) @pytest.mark.short -@pytest.mark.skipif(sys.platform=="linux", - reason="Results different between linux and windows.") +@pytest.mark.skip(reason="Different results after adding noise in the hydro allocation step") def test_071_hydro_reservoir_model_enhanced_04(use_ortools, ortools_solver, solver_path): study_path = ALL_STUDIES_PATH / "short-tests" / "071 Hydro Reservoir Model -enhanced-04" enable_study_output(study_path, True)