-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add adequacy patch optimization number to MPS filename to avoid overwrite #1187
Changes from all commits
d56ffdb
7c553e9
f372c9d
4fd89d1
66e4f0e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -136,7 +136,8 @@ void setNTCbounds(double& Xmax, | |||||||||
Xmin = -(ValeursDeNTC->ValeurDeNTCExtremiteVersOrigine[Interco]); | ||||||||||
|
||||||||||
// set for adq patch first step | ||||||||||
if (problemeHebdo->adqPatchParams && problemeHebdo->adqPatchParams->AdequacyFirstStep) | ||||||||||
if (problemeHebdo->adqPatchParams | ||||||||||
&& problemeHebdo->adequacyPatchRuntimeData->LMR_FirstOptimization) | ||||||||||
Comment on lines
+139
to
+140
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
{ | ||||||||||
ntcToZeroStatusForAdqPatch = getNTCtoZeroStatus(problemeHebdo, Interco); | ||||||||||
|
||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ | |
#include "../simulation/sim_structure_probleme_economique.h" | ||
#include "../simulation/sim_structure_probleme_adequation.h" | ||
#include "../simulation/sim_extern_variables_globales.h" | ||
#include "../simulation/adequacy_patch_runtime_data.h" | ||
|
||
#include "opt_fonctions.h" | ||
|
||
|
@@ -98,7 +99,7 @@ class TimeMeasurement | |
bool OPT_AppelDuSimplexe(PROBLEME_HEBDO* problemeHebdo, | ||
int NumIntervalle, | ||
const int optimizationNumber, | ||
std::shared_ptr<OptPeriodStringGenerator> optPeriodStringGenerator) | ||
OptPeriodStringGenerator& optPeriodStringGenerator) | ||
{ | ||
PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre = problemeHebdo->ProblemeAResoudre; | ||
Optimization::PROBLEME_SIMPLEXE_NOMME Probleme(ProblemeAResoudre->NomDesVariables, | ||
|
@@ -107,8 +108,10 @@ bool OPT_AppelDuSimplexe(PROBLEME_HEBDO* problemeHebdo, | |
ProblemeAResoudre->StatutDesContraintes); | ||
char PremierPassage = OUI_ANTARES; | ||
|
||
PROBLEME_SPX* ProbSpx = (PROBLEME_SPX*)(ProblemeAResoudre->ProblemesSpx->ProblemeSpx[(int)NumIntervalle]); | ||
MPSolver* solver = (MPSolver*)(ProblemeAResoudre->ProblemesSpx->ProblemeSpx[(int)NumIntervalle]); | ||
PROBLEME_SPX* ProbSpx | ||
= (PROBLEME_SPX*)(ProblemeAResoudre->ProblemesSpx->ProblemeSpx[(int)NumIntervalle]); | ||
MPSolver* solver | ||
= (MPSolver*)(ProblemeAResoudre->ProblemesSpx->ProblemeSpx[(int)NumIntervalle]); | ||
|
||
auto study = Data::Study::Current::Get(); | ||
bool ortoolsUsed = study->parameters.ortoolsUsed; | ||
|
@@ -234,8 +237,17 @@ bool OPT_AppelDuSimplexe(PROBLEME_HEBDO* problemeHebdo, | |
{ | ||
solver = ORTOOLS_ConvertIfNeeded(&Probleme, solver); | ||
} | ||
const std::string filename = createMPSfilename(optPeriodStringGenerator, optimizationNumber); | ||
mpsWriterFactory mps_writer_factory(problemeHebdo->ExportMPS, problemeHebdo->exportMPSOnError, optimizationNumber, &Probleme, ortoolsUsed, solver); | ||
|
||
auto adqPatchOptNumber | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Following the oral talk we just had, I think that the MPS filename should not be computed here, but at a higher in the call stack. |
||
= getAdqPatchOptmizationNumber(problemeHebdo->adequacyPatchRuntimeData.get()); | ||
const std::string filename | ||
= createMPSfilename(optPeriodStringGenerator, optimizationNumber, adqPatchOptNumber); | ||
mpsWriterFactory mps_writer_factory(problemeHebdo->ExportMPS, | ||
problemeHebdo->exportMPSOnError, | ||
optimizationNumber, | ||
&Probleme, | ||
ortoolsUsed, | ||
solver); | ||
auto mps_writer = mps_writer_factory.create(); | ||
mps_writer->runIfNeeded(study->resultWriter, filename); | ||
|
||
|
@@ -305,7 +317,7 @@ bool OPT_AppelDuSimplexe(PROBLEME_HEBDO* problemeHebdo, | |
logs.info() << " Solver: Safe resolution succeeded"; | ||
} | ||
|
||
double *pt; | ||
double* pt; | ||
double CoutOpt = 0.0; | ||
|
||
for (int i = 0; i < ProblemeAResoudre->NombreDeVariables; i++) | ||
|
@@ -373,12 +385,14 @@ bool OPT_AppelDuSimplexe(PROBLEME_HEBDO* problemeHebdo, | |
|
||
void OPT_EcrireResultatFonctionObjectiveAuFormatTXT( | ||
double optimalSolutionCost, | ||
std::shared_ptr<OptPeriodStringGenerator> optPeriodStringGenerator, | ||
int optimizationNumber) | ||
OptPeriodStringGenerator& optPeriodStringGenerator, | ||
int optimizationNumber, | ||
const std::optional<unsigned int> optAdqPatchNumber) | ||
{ | ||
Yuni::Clob buffer; | ||
auto study = Data::Study::Current::Get(); | ||
auto filename = createCriterionFilename(optPeriodStringGenerator, optimizationNumber); | ||
auto filename | ||
= createCriterionFilename(optPeriodStringGenerator, optimizationNumber, optAdqPatchNumber); | ||
auto writer = study->resultWriter; | ||
|
||
logs.info() << "Solver Criterion File: `" << filename << "'"; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
*/ | ||
|
||
#include "../simulation/simulation.h" | ||
#include "../simulation/adequacy_patch_runtime_data.h" | ||
|
||
#include "opt_fonctions.h" | ||
|
||
|
@@ -110,16 +111,20 @@ bool OPT_OptimisationLineaire(PROBLEME_HEBDO* problemeHebdo, uint numSpace) | |
problemeHebdo->year); | ||
|
||
if (!OPT_AppelDuSimplexe( | ||
problemeHebdo, NumeroDeLIntervalle, optimizationNumber, optPeriodStringGenerator)) | ||
problemeHebdo, NumeroDeLIntervalle, optimizationNumber, *optPeriodStringGenerator)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here we should have (something like) : auto mpsFileNames = MPSfileNames(problemeHebdo->OptimisationAuPasHebdomadaire,
NumeroDeLIntervalle,
problemeHebdo->adequacyPatchRuntimeData
problemeHebdo->weekInTheYear,
problemeHebdo->year)
if (!OPT_AppelDuSimplexe(problemeHebdo,
NumeroDeLIntervalle,
optimizationNumber,
mpsFileNames->mps()))
return false;
if (problemeHebdo->ExportMPS ......)
{
...
OPT_EcrireResultatFonctionObjectiveAuFormatTXT(optimalSolutionCost,
mpsFileNames->criterion());
} This would allow :
|
||
return false; | ||
|
||
if (problemeHebdo->ExportMPS != Data::mpsExportStatus::NO_EXPORT | ||
|| problemeHebdo->Expansion == OUI_ANTARES) | ||
{ | ||
double optimalSolutionCost | ||
= OPT_ObjectiveFunctionResult(problemeHebdo, NumeroDeLIntervalle, optimizationNumber); | ||
OPT_EcrireResultatFonctionObjectiveAuFormatTXT( | ||
optimalSolutionCost, optPeriodStringGenerator, optimizationNumber); | ||
auto adqPatchOptNumber | ||
= getAdqPatchOptmizationNumber(problemeHebdo->adequacyPatchRuntimeData.get()); | ||
OPT_EcrireResultatFonctionObjectiveAuFormatTXT(optimalSolutionCost, | ||
*optPeriodStringGenerator, | ||
optimizationNumber, | ||
adqPatchOptNumber); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include "opt_period_string_generator_base.h" | ||
#include <sstream> | ||
|
||
std::string OptPeriodStringGenerator::createOptimizationFilename( | ||
const std::string& title, | ||
unsigned int optNumber, | ||
const std::optional<unsigned int> adqPatchOptNumber, | ||
const std::string& extension) const | ||
{ | ||
std::ostringstream outputFile; | ||
outputFile << title.c_str() << "-"; | ||
outputFile << this->to_string(); | ||
outputFile << "--optim-nb-"; | ||
|
||
// Special case: Local matching rule (LMR) in adequacy patch performs 2 weekly optimizations | ||
if (adqPatchOptNumber) | ||
outputFile << std::to_string(*adqPatchOptNumber) << "-"; | ||
|
||
outputFile << std::to_string(optNumber); | ||
outputFile << "." << extension.c_str(); | ||
return outputFile.str(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ | |
#pragma once | ||
|
||
#include <string> | ||
#include <optional> | ||
|
||
// --------------------------------------------- | ||
// Optimization period as string : base class | ||
|
@@ -37,4 +38,8 @@ class OptPeriodStringGenerator | |
public: | ||
virtual std::string to_string() const = 0; | ||
virtual ~OptPeriodStringGenerator() = default; | ||
std::string createOptimizationFilename(const std::string& title, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Base class OptPeriodStringGenerator is an abstraction for the optimization period, that is either :
inside the filename. |
||
unsigned int optNumber, | ||
const std::optional<unsigned int> adqPatchOptNumber, | ||
const std::string& extension) const; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok.
Should conflict with #1189