Skip to content

Commit

Permalink
Add individual update times
Browse files Browse the repository at this point in the history
  • Loading branch information
flomnes committed Jul 24, 2023
1 parent 79219b0 commit 345a4e2
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 17 deletions.
9 changes: 6 additions & 3 deletions src/solver/optimisation/opt_appel_solveur_lineaire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ bool OPT_AppelDuSimplexe(PROBLEME_HEBDO* problemeHebdo,
assert(opt >= 0 && opt < 2);
OptimizationStatistics* optimizationStatistics = &(problemeHebdo->optimizationStatistics[opt]);

double updateTime = 0;
RESOLUTION:

if (ProbSpx == nullptr && solver == nullptr)
Expand Down Expand Up @@ -148,7 +149,7 @@ bool OPT_AppelDuSimplexe(PROBLEME_HEBDO* problemeHebdo,
Probleme.Contexte = BRANCH_AND_BOUND_OU_CUT_NOEUD;
Probleme.BaseDeDepartFournie = UTILISER_LA_BASE_DU_PROBLEME_SPX;

TimeMeasurement measure;
TimeMeasurement updateMeasure;
if (ortoolsUsed)
{
ORTOOLS_ModifierLeVecteurCouts(
Expand All @@ -172,8 +173,9 @@ bool OPT_AppelDuSimplexe(PROBLEME_HEBDO* problemeHebdo,
ProblemeAResoudre->Sens.data(),
ProblemeAResoudre->NombreDeContraintes);
}
measure.tick();
optimizationStatistics->addUpdateTime(measure.duration_ms());
updateMeasure.tick();
optimizationStatistics->addUpdateTime(updateMeasure.duration_ms());
updateTime += updateMeasure.duration_ms();
}
}

Expand Down Expand Up @@ -329,6 +331,7 @@ bool OPT_AppelDuSimplexe(PROBLEME_HEBDO* problemeHebdo,
{
problemeHebdo->coutOptimalSolution2[NumIntervalle] = CoutOpt;
problemeHebdo->tempsResolution2[NumIntervalle] = solveTime;
problemeHebdo->tempsUpdate[NumIntervalle] = updateTime;
}
for (int Cnt = 0; Cnt < ProblemeAResoudre->NombreDeContraintes; Cnt++)
{
Expand Down
3 changes: 2 additions & 1 deletion src/solver/simulation/adequacy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,8 @@ bool Adequacy::year(Progression::Task& progression,

optWriter.addTime(w,
pProblemesHebdo[numSpace]->tempsResolution1[0],
pProblemesHebdo[numSpace]->tempsResolution2[0]);
pProblemesHebdo[numSpace]->tempsResolution2[0],
pProblemesHebdo[numSpace]->tempsUpdate[0]);

++progression;
}
Expand Down
3 changes: 2 additions & 1 deletion src/solver/simulation/economy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ bool Economy::year(Progression::Task& progression,
}
optWriter.addTime(w,
pProblemesHebdo[numSpace]->tempsResolution1[0],
pProblemesHebdo[numSpace]->tempsResolution2[0]);
pProblemesHebdo[numSpace]->tempsResolution2[0],
pProblemesHebdo[numSpace]->tempsUpdate[0]);
}
catch (Data::AssertionError& ex)
{
Expand Down
17 changes: 8 additions & 9 deletions src/solver/simulation/opt_time_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,30 @@
** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions
*/
#include "opt_time_writer.h"
#include <filesystem>

OptimizationStatisticsWriter::OptimizationStatisticsWriter(
Antares::Solver::IResultWriter::Ptr writer,
uint year) :
pWriter(writer)
pYear(year), pWriter(writer)
{
printHeader();
#define SEP Yuni::IO::Separator
pFilename << "optimization" << SEP << "week-solve-durations" << SEP << "year_" << year
<< ".txt";
#undef SEP
}

void OptimizationStatisticsWriter::printHeader()
{
pBuffer << "# Week Optimization_1_ms Optimization_2_ms\n";
pBuffer << "# Week Optimization_1_ms Optimization_2_ms Update_ms\n";
}

void OptimizationStatisticsWriter::addTime(uint week, double opt_1_ms, double opt_2_ms)
void OptimizationStatisticsWriter::addTime(uint week, double opt_1_ms, double opt_2_ms, double update_ms)
{
pBuffer << week << " " << opt_1_ms << " " << opt_2_ms << "\n";
pBuffer << week << " " << opt_1_ms << " " << opt_2_ms << " " << update_ms <<"\n";
}

void OptimizationStatisticsWriter::finalize()
{
using path = std::filesystem::path;
const path filename = path("optimization") / "week-by-week" / ("year_" + std::to_string(pYear) + ".txt");
if (pWriter)
pWriter->addEntryFromBuffer(pFilename.c_str(), pBuffer);
pWriter->addEntryFromBuffer(filename.string(), pBuffer);
}
5 changes: 2 additions & 3 deletions src/solver/simulation/opt_time_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions
*/
#pragma once
#include <yuni/core/string.h>
#include <i_writer.h>

#include "simulation.h"
Expand All @@ -34,12 +33,12 @@ class OptimizationStatisticsWriter
{
public:
OptimizationStatisticsWriter(Antares::Solver::IResultWriter::Ptr writer, uint year);
void addTime(uint week, double opt_1_ms, double opt_2_ms);
void addTime(uint week, double opt_1_ms, double opt_2_ms, double update_ms);
void finalize();

private:
void printHeader();
Yuni::Clob pBuffer;
Yuni::String pFilename;
uint pYear;
Antares::Solver::IResultWriter::Ptr pWriter;
};
1 change: 1 addition & 0 deletions src/solver/simulation/sim_alloc_probleme_hebdo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ void SIM_AllocationProblemeHebdo(PROBLEME_HEBDO& problem, unsigned NombreDePasDe

problem.tempsResolution1.assign(7, 0.);
problem.tempsResolution2.assign(7, 0.);
problem.tempsUpdate.assign(7, 0.);
}

void SIM_DesallocationProblemeHebdo(PROBLEME_HEBDO& problem)
Expand Down
1 change: 1 addition & 0 deletions src/solver/simulation/sim_calcul_economique.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ void SIM_RenseignementProblemeHebdo(PROBLEME_HEBDO& problem,
problem.coutOptimalSolution2[opt] = 0.;
problem.tempsResolution1[opt] = 0.;
problem.tempsResolution2[opt] = 0.;
problem.tempsUpdate[opt] = 0.;
}

for (uint k = 0; k < studyruntime.interconnectionsCount(); ++k)
Expand Down
1 change: 1 addition & 0 deletions src/solver/simulation/sim_structure_probleme_economique.h
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,7 @@ struct PROBLEME_HEBDO

std::vector<double> tempsResolution1;
std::vector<double> tempsResolution2;
std::vector<double> tempsUpdate;

/* Unused for now, will be used in future revisions */
#if 0
Expand Down

0 comments on commit 345a4e2

Please sign in to comment.