Skip to content

Commit

Permalink
Name constraints & variables in MPS files (#1294)
Browse files Browse the repository at this point in the history
* add ConstraintBuilder class

* Revert "add ConstraintBuilder class"

This reverts commit a85cd78.

* begin pblm vars renaming

* add separator after zone

* send vars names to mps writers

* init var name with empty string

* rename DefaillancePositive variable

* Rename PalierThermique variables

* update Cout* vars

* avoid already named variables

* work on constraints

* begin constraints naming & quick refacto

* fix duplicated separator

* update zone, link and timestep identifiers

* continuing on constraints

* process constraints with no ts

* add MaxPompage Constraint

* update MaxPompage  name

* Check on Area name

* update "couts_demarrage" constraints name

* translate into English

* get area names from problemHebdo instead of study

* translate var names into english

* update ThermalCluster variables

* get & store Thermal Clusters name

* update short termes storage cnt

* delete commented code

* on new code style

* avoiding malloc/free

* delete unused constants

* try fix: test failure

* fix cluster number

* roll back set week number =0

* fix weekly bc

* undo auto-format

* small changes

* export short term storage name to opt

* rename short terme sto vars and others

* Update src/solver/optimisation/opt_appel_solveur_lineaire.cpp

Co-authored-by: Florian Omnès <[email protected]>

* add thermal cluster variants names

* fix

* update FinalStockExpression cnt

* updates

* unify thermal cluster variable format

* same as thermal cluster vars

* move implementation details

* rename zone-->area

* check area's name

* remove commented code

* move area name check to a suitable place

* rename function

* fix

* remove double check

* refacto

* update deps version

* lightening variable namer calls

* clean code

* fix daily bc ts

* fix merge issue

* remove redundant variable

* pr reviews

* try-> use new instead of malloc

* updates

* remove duplicated code

* remove vars name from cnt builders

* move variable namer

* tmp changes

* cherry-pick a676e48..3fd0d5d

* fix flow dissociation cnt

* update

* avoid double naming for link vars

* merge

* [DEV] Fix valgrind errors

* add option for naming

* --named-problems works for constraints

* --named-problems works for variables

* check name

* clean area updates

* remove unnecessary area updates

* rename struct enums

* remove enums

* shared ptr as ref

* add name so ShortTerm Sto Cnt

* shorten shortTerm st name var/cnt

* remove empty methods

* update

* rename struct

* rename vars

* refacto utilities classes

* remove unnecessary check

* rename members vars

* remove free function declaration

* unsigned --> unsigned int

* Update src/solver/misc/options.cpp

change option name

Co-authored-by: Florian Omnès <[email protected]>

* fix duplicated  contraints name

* push header

* Avoid leaking char** from Sirius for variable & constraint names (#1399)

* Avoid leaking char** from Sirius for variable & constraint names

* Update antares-deps submodule

* Remove unused private members

* contraintNamer do naming before it created

* Simplify TargetVectorUpdater, keep same behavior (#1403)

Remove std::function, std::bind

* vector index: change int-> unsigned int

* smell code

* delete unused vars

* smell code...

* delete unused var

* remove  unused var

* remove unused var

* smell code

* fix minors smell code

* unsigned/signed smell codes

---------

Co-authored-by: Florian Omnès <[email protected]>
Co-authored-by: Vincent Payet <[email protected]>
  • Loading branch information
3 people authored Jul 6, 2023
1 parent c515839 commit ccb2749
Show file tree
Hide file tree
Showing 27 changed files with 783 additions and 333 deletions.
2 changes: 1 addition & 1 deletion antares-deps-version.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"antares_deps_version": "2.0.2a"
"antares_deps_version": "2.0.2b"
}
2 changes: 1 addition & 1 deletion src/antares-deps
Submodule antares-deps updated 1 files
+1 −1 CMakeLists.txt
8 changes: 8 additions & 0 deletions src/libs/antares/study/area/area.h
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,14 @@ void AreaListEnsureDataRenewableTimeSeries(AreaList* l);
*/
void AreaListEnsureDataThermalPrepro(AreaList* l);

/*!
** \brief to check that Area name does not contains character *
*/
inline bool CheckForbiddenCharacterInAreaName(const AnyString& name)
{
return name.contains('*');
}

} // namespace Data
} // namespace Antares

Expand Down
12 changes: 10 additions & 2 deletions src/libs/antares/study/area/list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,6 @@ Area* AreaList::add(Area* a)
}
return a;
}

Area* AreaListAddFromName(AreaList& list, const AnyString& name, uint nbParallelYears)
{
// Initializing names
Expand All @@ -506,7 +505,6 @@ Area* AreaListAddFromNames(AreaList& list,
// Look up
if (!AreaListLFind(&list, lname.c_str()))
{
// Creating the area
Area* area = new Area(name, lname, nbParallelYears);
// Adding it
Area* ret = list.add(area);
Expand Down Expand Up @@ -559,6 +557,11 @@ bool AreaList::loadListFromFile(const AnyString& filename)
<< ": line " << line;
continue;
}
if (CheckForbiddenCharacterInAreaName(name))
{
logs.error() << "character '*' is forbidden in area name: `" << name << "`";
continue;
}
// Add the area in the list
AreaListAddFromNames(*this, name, lname, pStudy.maxNbYearsInParallel);
}
Expand Down Expand Up @@ -1406,6 +1409,11 @@ bool AreaList::renameArea(const AreaName& oldid, const AreaName& newid, const Ar
if (!oldid || !newName || !newid || areas.empty())
return false;

if (CheckForbiddenCharacterInAreaName(newName))
{
logs.error() << "character '*' is forbidden in area name: `" << newName << "`";
return false;
}
// Detaching the area from the list
Area* area;
{
Expand Down
2 changes: 2 additions & 0 deletions src/libs/antares/study/load-options.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ class StudyLoadOptions
SimplexOptimization simplexOptimizationRange;
//! Mps files export asked
bool mpsToExport;
//! named problems
bool namedProblems = false;
//! Ignore all constraints
bool ignoreConstraints;
//! Simulation mode
Expand Down
9 changes: 9 additions & 0 deletions src/libs/antares/study/parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ void Parameters::reset()

include.exportMPS = mpsExportStatus::NO_EXPORT;
include.exportStructure = false;
namedProblems = false;

include.unfeasibleProblemBehavior = UnfeasibleProblemBehavior::ERROR_MPS;

Expand Down Expand Up @@ -1063,6 +1064,8 @@ bool Parameters::loadFromINI(const IniFile& ini, uint version, const StudyLoadOp
ortoolsUsed = options.ortoolsUsed;
ortoolsSolver = options.ortoolsSolver;

namedProblems = options.namedProblems;

// Attempt to fix bad values if any
fixBadValues();

Expand Down Expand Up @@ -1470,6 +1473,12 @@ void Parameters::prepareForSimulation(const StudyLoadOptions& options)
{
logs.info() << " :: ortools solver " << ortoolsSolver << " used for problem resolution";
}

// indicated that Problems will be named
if (namedProblems)
{
logs.info() << " :: The problems will contain named variables and constraints";
}
}

void Parameters::resetPlaylist(uint nbOfYears)
Expand Down
3 changes: 3 additions & 0 deletions src/libs/antares/study/parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,9 @@ class Parameters final
// Format of results. Currently, only single files or zip archive are supported
ResultFormat resultFormat = legacyFilesDirectories;

// Naming constraints and variables in problems
bool namedProblems;

private:
//! Load data from an INI file
bool loadFromINI(const IniFile& ini, uint version, const StudyLoadOptions& options);
Expand Down
5 changes: 5 additions & 0 deletions src/libs/antares/study/study.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,11 @@ Area* Study::areaAdd(const AreaName& name)
{
if (name.empty())
return nullptr;
if (CheckForbiddenCharacterInAreaName(name))
{
logs.error() << "character '*' is forbidden in area name: `" << name << "`";
return nullptr;
}

// Result
Area* area = nullptr;
Expand Down
6 changes: 6 additions & 0 deletions src/solver/misc/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ std::unique_ptr<GetOpt::Parser> CreateParser(Settings& settings,
"mps-export",
"Export in the mps format the optimization problems.");

// --named-problems
parser->addFlag(options.namedProblems,
' ',
"named-mps-problems",
"Naming constraints and variables in problems.");

parser->addParagraph("\nMisc.");
// --progress
parser->addFlag(
Expand Down
2 changes: 2 additions & 0 deletions src/solver/optimisation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ set(RTESOLVER_OPT
adequacy_patch_csr/count_constraints_variables.cpp

opt_period_string_generator_base.h
opt_rename_problem.h
opt_rename_problem.cpp
)


Expand Down
4 changes: 2 additions & 2 deletions src/solver/optimisation/opt_appel_solveur_lineaire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ class TimeMeasurement
clock::time_point start_;
clock::time_point end_;
};

bool OPT_AppelDuSimplexe(PROBLEME_HEBDO* problemeHebdo,
int NumIntervalle,
const int optimizationNumber,
Expand All @@ -107,7 +106,8 @@ bool OPT_AppelDuSimplexe(PROBLEME_HEBDO* problemeHebdo,
ProblemeAResoudre->StatutDesContraintes);
bool PremierPassage = true;

auto ProbSpx = (PROBLEME_SPX*)(ProblemeAResoudre->ProblemesSpx->ProblemeSpx[(int)NumIntervalle]);
auto ProbSpx
= (PROBLEME_SPX*)(ProblemeAResoudre->ProblemesSpx->ProblemeSpx[(int)NumIntervalle]);
auto solver = (MPSolver*)(ProblemeAResoudre->ProblemesSpx->ProblemeSpx[(int)NumIntervalle]);

auto study = Data::Study::Current::Get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
#include <antares/study.h>
#include <antares/study/area/scratchpad.h>
#include "../simulation/sim_structure_donnees.h"
#include "opt_rename_problem.h"
#include "opt_export_structure.h"
using namespace Antares::Data;

void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage(
PROBLEME_HEBDO* problemeHebdo,
Expand All @@ -55,14 +58,14 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage(

double* Pi = ProblemeAResoudre->Pi;
int* Colonne = ProblemeAResoudre->Colonne;

ConstraintNamer constraintNamer(ProblemeAResoudre->NomDesContraintes,
problemeHebdo->NamedProblems);
int nbTermesContraintesPourLesCoutsDeDemarrage = 0;

for (int pays = 0; pays < problemeHebdo->NombreDePays; pays++)
for (unsigned int pays = 0; pays < problemeHebdo->NombreDePays; pays++)
{
const PALIERS_THERMIQUES& PaliersThermiquesDuPays
= problemeHebdo->PaliersThermiquesDuPays[pays];

constraintNamer.UpdateArea(problemeHebdo->NomsDesPays[pays]);
for (int index = 0; index < PaliersThermiquesDuPays.NombreDePaliersThermiques; index++)
{
double pminDUnGroupeDuPalierThermique
Expand All @@ -72,8 +75,10 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage(
const int palier
= PaliersThermiquesDuPays.NumeroDuPalierDansLEnsembleDesPaliersThermiques[index];

for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++)
for (unsigned int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++)
{
auto timeStepInYear = problemeHebdo->weekInTheYear * 168 + pdt;
constraintNamer.UpdateTimeStep(timeStepInYear);
CorrespondanceVarNativesVarOptim
= problemeHebdo->CorrespondanceVarNativesVarOptim[pdt];

Expand Down Expand Up @@ -112,6 +117,8 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage(
{
if (nombreDeTermes > 0)
{
constraintNamer.PMaxDispatchableGeneration(
ProblemeAResoudre->NombreDeContraintes);
OPT_ChargerLaContrainteDansLaMatriceDesContraintes(
ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '<');
}
Expand Down Expand Up @@ -154,6 +161,8 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage(
{
if (nombreDeTermes > 0)
{
constraintNamer.PMinDispatchableGeneration(
ProblemeAResoudre->NombreDeContraintes);
OPT_ChargerLaContrainteDansLaMatriceDesContraintes(
ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '>');
}
Expand All @@ -168,14 +177,16 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage(
{
const PALIERS_THERMIQUES& PaliersThermiquesDuPays
= problemeHebdo->PaliersThermiquesDuPays[pays];

constraintNamer.UpdateArea(problemeHebdo->NomsDesPays[pays]);
for (int index = 0; index < PaliersThermiquesDuPays.NombreDePaliersThermiques; index++)
{
const int palier
= PaliersThermiquesDuPays.NumeroDuPalierDansLEnsembleDesPaliersThermiques[index];

for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++)
for (unsigned int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++)
{
auto timeStepInYear = problemeHebdo->weekInTheYear * 168 + pdt;
constraintNamer.UpdateTimeStep(timeStepInYear);
CorrespondanceVarNativesVarOptim
= problemeHebdo->CorrespondanceVarNativesVarOptim[pdt];

Expand Down Expand Up @@ -250,6 +261,7 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage(
{
if (nombreDeTermes > 0)
{
constraintNamer.ConsistenceNODU(ProblemeAResoudre->NombreDeContraintes);
OPT_ChargerLaContrainteDansLaMatriceDesContraintes(
ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '=');
}
Expand All @@ -260,18 +272,21 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage(
}
}

for (int pays = 0; pays < problemeHebdo->NombreDePays; pays++)
for (unsigned int pays = 0; pays < problemeHebdo->NombreDePays; pays++)
{
const PALIERS_THERMIQUES& PaliersThermiquesDuPays
= problemeHebdo->PaliersThermiquesDuPays[pays];

constraintNamer.UpdateArea(problemeHebdo->NomsDesPays[pays]);
for (int index = 0; index < PaliersThermiquesDuPays.NombreDePaliersThermiques; index++)
{
const int palier
= PaliersThermiquesDuPays.NumeroDuPalierDansLEnsembleDesPaliersThermiques[index];

for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++)
for (unsigned int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++)
{
auto timeStepInYear = problemeHebdo->weekInTheYear * 168 + pdt;
constraintNamer.UpdateTimeStep(timeStepInYear);
CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim
= problemeHebdo->CorrespondanceCntNativesCntOptim[pdt];
CorrespondanceCntNativesCntOptim
Expand Down Expand Up @@ -314,6 +329,8 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage(
{
if (nombreDeTermes > 0)
{
constraintNamer.NbUnitsOutageLessThanNbUnitsStop(
ProblemeAResoudre->NombreDeContraintes);
OPT_ChargerLaContrainteDansLaMatriceDesContraintes(
ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '<');
}
Expand All @@ -324,11 +341,12 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage(
}
}

for (int pays = 0; pays < problemeHebdo->NombreDePays; pays++)
for (unsigned int pays = 0; pays < problemeHebdo->NombreDePays; pays++)
{
const PALIERS_THERMIQUES& PaliersThermiquesDuPays
= problemeHebdo->PaliersThermiquesDuPays[pays];

constraintNamer.UpdateArea(problemeHebdo->NomsDesPays[pays]);
for (int index = 0; index < PaliersThermiquesDuPays.NombreDePaliersThermiques; index++)
{
int DureeMinimaleDeMarcheDUnGroupeDuPalierThermique
Expand All @@ -338,8 +356,10 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage(
const int palier
= PaliersThermiquesDuPays.NumeroDuPalierDansLEnsembleDesPaliersThermiques[index];

for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++)
for (unsigned int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++)
{
auto timeStepInYear = problemeHebdo->weekInTheYear * 168 + pdt;
constraintNamer.UpdateTimeStep(timeStepInYear);
CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim
= problemeHebdo->CorrespondanceCntNativesCntOptim[pdt];
CorrespondanceCntNativesCntOptim
Expand Down Expand Up @@ -409,6 +429,8 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage(
.NumeroDeContrainteDesContraintesDeDureeMinDeMarche[palier]
= ProblemeAResoudre->NombreDeContraintes;

constraintNamer.NbDispUnitsMinBoundSinceMinUpTime(
ProblemeAResoudre->NombreDeContraintes);
OPT_ChargerLaContrainteDansLaMatriceDesContraintes(
ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '>');
}
Expand All @@ -424,15 +446,18 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage(
const PALIERS_THERMIQUES& PaliersThermiquesDuPays
= problemeHebdo->PaliersThermiquesDuPays[pays];

constraintNamer.UpdateArea(problemeHebdo->NomsDesPays[pays]);
for (int index = 0; index < PaliersThermiquesDuPays.NombreDePaliersThermiques; index++)
{
int DureeMinimaleDArretDUnGroupeDuPalierThermique
= PaliersThermiquesDuPays.DureeMinimaleDArretDUnGroupeDuPalierThermique[index];
const int palier
= PaliersThermiquesDuPays.NumeroDuPalierDansLEnsembleDesPaliersThermiques[index];

for (int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++)
for (unsigned int pdt = 0; pdt < nombreDePasDeTempsPourUneOptimisation; pdt++)
{
auto timeStepInYear = problemeHebdo->weekInTheYear * 168 + pdt;
constraintNamer.UpdateTimeStep(timeStepInYear);
CORRESPONDANCES_DES_CONTRAINTES& CorrespondanceCntNativesCntOptim
= problemeHebdo->CorrespondanceCntNativesCntOptim[pdt];
CorrespondanceCntNativesCntOptim
Expand All @@ -442,13 +467,6 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage(
CorrespondanceVarNativesVarOptim
= problemeHebdo->CorrespondanceVarNativesVarOptim[pdt];

if (!Simulation)
{
CorrespondanceCntNativesCntOptim
.NumeroDeContrainteDesContraintesDeDureeMinDArret[palier]
= -1;
}

int nombreDeTermes = 0;
if (!Simulation)
{
Expand Down Expand Up @@ -496,6 +514,7 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage(
.NumeroDeContrainteDesContraintesDeDureeMinDArret[palier]
= ProblemeAResoudre->NombreDeContraintes;

constraintNamer.MinDownTime(ProblemeAResoudre->NombreDeContraintes);
OPT_ChargerLaContrainteDansLaMatriceDesContraintes(
ProblemeAResoudre, Pi, Colonne, nombreDeTermes, '<');
}
Expand Down
Loading

0 comments on commit ccb2749

Please sign in to comment.