Skip to content

Commit

Permalink
Factorisation of code before expanding to all variables in the optimi…
Browse files Browse the repository at this point in the history
…sation problem
  • Loading branch information
sylvmara committed Nov 27, 2024
1 parent 9651e22 commit e0a20c8
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 58 deletions.
2 changes: 1 addition & 1 deletion src/libs/antares/study/include/antares/study/parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ class Parameters final
//! \name Delta Cluster
//@{
//! Output the delta of groups inside clusters for each hour of each mode
bool deltaClusterOutput;
bool exportRawOptimizationResults;
//@}

/*!
Expand Down
2 changes: 1 addition & 1 deletion src/libs/antares/study/load.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void Study::parameterFiller(const StudyLoadOptions& options)
parameters.timeSeriesToArchive = 0;
parameters.storeTimeseriesNumbers = false;
parameters.synthesis = false;
parameters.deltaClusterOutput = false;
parameters.exportRawOptimizationResults = false;
}

if (options.loadOnlyNeeded && !parameters.timeSeriesToGenerate)
Expand Down
6 changes: 3 additions & 3 deletions src/libs/antares/study/parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ void Parameters::reset()
readonly = false;
synthesis = true;
//Outputing the delta of the number of groups that are on inside each clusters
deltaClusterOutput = false;
exportRawOptimizationResults = false;

// Hydro heuristic policy
hydroHeuristicPolicy.hhPolicy = hhpAccommodateRuleCurves;
Expand Down Expand Up @@ -625,9 +625,9 @@ static bool SGDIntLoadFamily_Output(Parameters& d,
{
return value.to<bool>(d.synthesis);
}
if (key == "delta-cluster")
if (key == "export-raw-optimization-results")
{
return value.to<bool>(d.deltaClusterOutput);
return value.to<bool>(d.exportRawOptimizationResults);
}
if (key == "hydro-debug")
{
Expand Down
91 changes: 40 additions & 51 deletions src/solver/optimisation/opt_optimisation_lineaire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,42 @@ void resizeProbleme(PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre,
}
} // namespace

void OPT_ExportRawOptimizationResults(PROBLEME_HEBDO* problemeHebdo,
Solver::IResultWriter& writer,
std::string filename)
{
if (problemeHebdo->exportRawOptimizationResults)
{
uint32_t NombreDePasDeTempsProblemeHebdo = problemeHebdo->NombreDePasDeTemps;
const std::string fileName = std::string("RawResultsWeek") + std::to_string(problemeHebdo->weekInTheYear) + "_" + filename + ".txt";
std::string content;
std::string baseContent;
for (uint32_t pdtHebdo = 0; pdtHebdo < NombreDePasDeTempsProblemeHebdo; pdtHebdo++)
{
for (uint32_t pays = 0; pays < problemeHebdo->NombreDePays; pays++)
{
std::string areaName = problemeHebdo->NomsDesPays[pays];
RESULTATS_HORAIRES& ResultatsHoraires = problemeHebdo->ResultatsHoraires[pays];
std::vector<PRODUCTION_THERMIQUE_OPTIMALE>& ProductionThermique = ResultatsHoraires.ProductionThermique;
PALIERS_THERMIQUES& PaliersThermiquesDuPays
= problemeHebdo->PaliersThermiquesDuPays[pays];

for (int index = 0; index < PaliersThermiquesDuPays.NombreDePaliersThermiques; index++)
{
std::string clusterName = PaliersThermiquesDuPays.NomsDesPaliersThermiques[index];

baseContent = "ResultatsHoraires:ProductionThermique:" + areaName + ":" + clusterName + ":";
content += baseContent + "NombreDeGroupesEnMarcheDuPalier<" + std::to_string(pdtHebdo) + ">" + "\t" + std::to_string(ProductionThermique[pdtHebdo].NombreDeGroupesEnMarcheDuPalier[index]) + "\r\n";
content += baseContent + "NombreDeGroupesQuiDemarrentDuPalier<" + std::to_string(pdtHebdo) + ">" + "\t" + std::to_string(ProductionThermique[pdtHebdo].NombreDeGroupesQuiDemarrentDuPalier[index]) + "\r\n";
content += baseContent + "NombreDeGroupesQuiSArretentDuPalier<" + std::to_string(pdtHebdo) + ">" + "\t" + std::to_string(ProductionThermique[pdtHebdo].NombreDeGroupesQuiSArretentDuPalier[index]) + "\r\n";
content += baseContent + "NombreDeGroupesQuiTombentEnPanneDuPalier<" + std::to_string(pdtHebdo) + ">" + "\t" + std::to_string(ProductionThermique[pdtHebdo].NombreDeGroupesQuiTombentEnPanneDuPalier[index]) + "\r\n";
}
}
writer.addEntryFromBuffer(fileName, content);
}
}
}

bool OPT_OptimisationLineaire(const OptimizationOptions& options,
PROBLEME_HEBDO* problemeHebdo,
Solver::IResultWriter& writer,
Expand Down Expand Up @@ -224,32 +260,8 @@ bool OPT_OptimisationLineaire(const OptimizationOptions& options,
writer,
PREMIERE_OPTIMISATION,
simulationObserver);
if (problemeHebdo->exportDeltaClusters)
{
int NombreDePasDeTempsProblemeHebdo = problemeHebdo->NombreDePasDeTemps;
for (int pays = 0; pays < problemeHebdo->NombreDePays; pays++)
{
RESULTATS_HORAIRES& ResultatsHoraires = problemeHebdo->ResultatsHoraires[pays];
std::vector<PRODUCTION_THERMIQUE_OPTIMALE>& ProductionThermique = ResultatsHoraires.ProductionThermique;
PALIERS_THERMIQUES& PaliersThermiquesDuPays
= problemeHebdo->PaliersThermiquesDuPays[pays];
const std::string fileName = problemeHebdo->NomsDesPays[pays] + std::string("_week") + std::to_string(problemeHebdo->weekInTheYear) + "_beforeHeuristic.txt";
std::string content;
content += "clusterName_PdtHebdo NombreDeGroupesEnMarcheDuPalier NombreDeGroupesQuiDemarrentDuPalier NombreDeGroupesQuiSArretentDuPalier \r\n";
for (int index = 0; index < PaliersThermiquesDuPays.NombreDePaliersThermiques; index++)
{
for (int pdtHebdo = 0; pdtHebdo < NombreDePasDeTempsProblemeHebdo; pdtHebdo++)
{
content += PaliersThermiquesDuPays.NomsDesPaliersThermiques[index] + "_Pdt" + std::to_string(pdtHebdo) + " ";

content += std::to_string(ProductionThermique[pdtHebdo].NombreDeGroupesEnMarcheDuPalier[index]) + " ";
content += std::to_string(ProductionThermique[pdtHebdo].NombreDeGroupesQuiDemarrentDuPalier[index]) + " ";
content += std::to_string(ProductionThermique[pdtHebdo].NombreDeGroupesQuiSArretentDuPalier[index]) + "\r\n";
}
}
writer.addEntryFromBuffer(fileName, content);
}
}
std::string filename = "beforeHeuristic";
OPT_ExportRawOptimizationResults(problemeHebdo, writer, filename);

// We only need the 2nd optimization when NOT solving with integer variables
// We also skip the 2nd optimization in the hidden 'Expansion' mode
Expand All @@ -263,31 +275,8 @@ bool OPT_OptimisationLineaire(const OptimizationOptions& options,
writer,
DEUXIEME_OPTIMISATION,
simulationObserver);
if (problemeHebdo->exportDeltaClusters)
{
int NombreDePasDeTempsProblemeHebdo = problemeHebdo->NombreDePasDeTemps;
for (int pays = 0; pays < problemeHebdo->NombreDePays; pays++)
{
RESULTATS_HORAIRES& ResultatsHoraires = problemeHebdo->ResultatsHoraires[pays];
std::vector<PRODUCTION_THERMIQUE_OPTIMALE>& ProductionThermique = ResultatsHoraires.ProductionThermique;
PALIERS_THERMIQUES& PaliersThermiquesDuPays
= problemeHebdo->PaliersThermiquesDuPays[pays];
const std::string fileName = problemeHebdo->NomsDesPays[pays] + std::string("_week") + std::to_string(problemeHebdo->weekInTheYear) + "_afterHeuristic.txt";
std::string content;
content += "clusterName_PdtHebdo NombreDeGroupesEnMarcheDuPalier NombreDeGroupesQuiDemarrentDuPalier NombreDeGroupesQuiSArretentDuPalier \r\n";
for (int index = 0; index < PaliersThermiquesDuPays.NombreDePaliersThermiques; index++)
{
for (int pdtHebdo = 0; pdtHebdo < NombreDePasDeTempsProblemeHebdo; pdtHebdo++)
{
content += PaliersThermiquesDuPays.NomsDesPaliersThermiques[index] + "_Pdt" + std::to_string(pdtHebdo) + " ";
content += std::to_string(ProductionThermique[pdtHebdo].NombreDeGroupesEnMarcheDuPalier[index]) + " ";
content += std::to_string(ProductionThermique[pdtHebdo].NombreDeGroupesQuiDemarrentDuPalier[index]) + " ";
content += std::to_string(ProductionThermique[pdtHebdo].NombreDeGroupesQuiSArretentDuPalier[index]) + "\r\n";
}
}
writer.addEntryFromBuffer(fileName, content);
}
}
filename = "afterHeuristic";
OPT_ExportRawOptimizationResults(problemeHebdo, writer, filename);
}
return ret;
}
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ struct PROBLEME_HEBDO
bool exportMPSOnError = false;
bool ExportStructure = false;
bool NamedProblems = false;
bool exportDeltaClusters = false;
bool exportRawOptimizationResults = false;

uint32_t HeureDansLAnnee = 0;
bool LeProblemeADejaEteInstancie = false;
Expand Down
2 changes: 1 addition & 1 deletion src/solver/simulation/sim_calcul_economique.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -975,5 +975,5 @@ void SIM_RenseignementProblemeHebdo(const Study& study,
problem.CaracteristiquesHydrauliques[k].ContrainteDePmaxHydrauliqueHoraireRef
= problem.CaracteristiquesHydrauliques[k].ContrainteDePmaxHydrauliqueHoraire;
}
problem.exportDeltaClusters = parameters.deltaClusterOutput;
problem.exportRawOptimizationResults = parameters.exportRawOptimizationResults;
}

0 comments on commit e0a20c8

Please sign in to comment.