Skip to content

Commit

Permalink
Improve clarity for constraints that should be used (#1452)
Browse files Browse the repository at this point in the history
Replace "enabled && !skipped" by "meaningful"
  • Loading branch information
JasonMarechal25 authored Jul 24, 2023
1 parent d227666 commit 4be9453
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 58 deletions.
6 changes: 3 additions & 3 deletions src/libs/antares/benchmarking/info_collectors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ void StudyInfoCollector::enabledThermalClustersCountToFileContent(FileContent& f

void StudyInfoCollector::enabledBindingConstraintsCountToFileContent(FileContent& file_content)
{
auto enabledBindingConstraints = study_.bindingConstraints.enabled();
auto nbEnabledBC = enabledBindingConstraints.size();
auto activeContraints = study_.bindingConstraints.activeContraints();
auto nbEnabledBC = activeContraints.size();
unsigned nbEnabledHourlyBC(0);
unsigned nbEnabledDailyBC(0);
unsigned nbEnabledWeeklyBC(0);

for (uint i = 0; i < nbEnabledBC; i++)
{
switch (enabledBindingConstraints[i]->type())
switch (activeContraints[i]->type())
{
case BindingConstraint::Type::typeHourly:
nbEnabledHourlyBC++;
Expand Down
2 changes: 2 additions & 0 deletions src/libs/antares/study/binding_constraint/BindingConstraint.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ class BindingConstraint final : public Yuni::NonCopyable<BindingConstraint>
//@}

bool skipped() const;
bool isActive() const;

//Ref to prevent copy. const ref to prevent modification.
const Matrix<>& RHSTimeSeries() const;
Expand Down Expand Up @@ -411,6 +412,7 @@ class BindingConstraint final : public Yuni::NonCopyable<BindingConstraint>
void clear();

void copyFrom(BindingConstraint const *original);

}; // class BindingConstraint

// class BindConstList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ inline bool BindingConstraint::skipped() const
return linkCount() == 0 && clusterCount() == 0;
}

inline bool BindingConstraint::isActive() const {
return enabled() && !skipped();
}

inline BindingConstraint::iterator BindingConstraint::begin() {
return pLinkWeights.begin();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
void Data::BindingConstraintsRepository::clear()
{
pList.clear();
enabledConstraints_.reset();
activeConstraints_.reset();
}

namespace Antares::Data {
Expand Down Expand Up @@ -341,23 +341,23 @@ void BindingConstraintsRepository::remove(const Area* area)
RemovePredicate<Area> predicate(area);
auto e = std::remove_if(pList.begin(), pList.end(), predicate);
pList.erase(e, pList.end());
enabledConstraints_.reset();
activeConstraints_.reset();
}

void BindingConstraintsRepository::remove(const AreaLink* lnk)
{
RemovePredicate<AreaLink> predicate(lnk);
auto e = std::remove_if(pList.begin(), pList.end(), predicate);
pList.erase(e, pList.end());
enabledConstraints_.reset();
activeConstraints_.reset();
}

void BindingConstraintsRepository::remove(const BindingConstraint* bc)
{
RemovePredicate<BindingConstraint> predicate(bc);
auto e = std::remove_if(pList.begin(), pList.end(), predicate);
pList.erase(e, pList.end());
enabledConstraints_.reset();
activeConstraints_.reset();
}


Expand Down Expand Up @@ -415,17 +415,17 @@ uint64 BindingConstraintsRepository::timeSeriesNumberMemoryUsage() const {
return m;
}

std::vector<std::shared_ptr<BindingConstraint>> BindingConstraintsRepository::enabled() const {
if (enabledConstraints_) {
return enabledConstraints_.value();
std::vector<std::shared_ptr<BindingConstraint>> BindingConstraintsRepository::activeContraints() const {
if (activeConstraints_) {
return activeConstraints_.value();
} else {
std::vector<std::shared_ptr<BindingConstraint>> out;
std::copy_if(pList.begin(), pList.end(), std::back_inserter(out),
[](const auto &bc) {
return bc->enabled() && !bc->skipped();
return bc->isActive();
});
enabledConstraints_ = std::move(out);
return enabledConstraints_.value();
activeConstraints_ = std::move(out);
return activeConstraints_.value();
}
}

Expand All @@ -436,9 +436,9 @@ static bool isBindingConstraintTypeInequality(const Data::BindingConstraint& bc)

std::vector<uint> BindingConstraintsRepository::getIndicesForInequalityBindingConstraints() const
{
auto enabledBCs = enabled();
const auto firstBC = enabledBCs.begin();
const auto lastBC = enabledBCs.end();
auto activeConstraints = activeContraints();
const auto firstBC = activeConstraints.begin();
const auto lastBC = activeConstraints.end();

std::vector<uint> indices;
for (auto bc = firstBC; bc < lastBC; bc++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class BindingConstraintsRepository final : public Yuni::NonCopyable<BindingConst
** \brief Iterate through all enabled constraints (const)
*/
template<class PredicateT>
void eachEnabled(const PredicateT& predicate) const;
void eachActive(const PredicateT& predicate) const;

iterator begin();
[[nodiscard]] const_iterator begin() const;
Expand Down Expand Up @@ -173,7 +173,7 @@ class BindingConstraintsRepository final : public Yuni::NonCopyable<BindingConst

std::map<std::string, Data::BindingConstraintTimeSeriesNumbers, std::less<>> groupToTimeSeriesNumbers;

[[nodiscard]] std::vector<std::shared_ptr<BindingConstraint>> enabled() const;
[[nodiscard]] std::vector<std::shared_ptr<BindingConstraint>> activeContraints() const;

[[nodiscard]] std::vector<uint> getIndicesForInequalityBindingConstraints() const;

Expand All @@ -190,7 +190,7 @@ class BindingConstraintsRepository final : public Yuni::NonCopyable<BindingConst

[[nodiscard]] bool checkTimeSeriesWidthConsistency() const;

mutable std::optional<std::vector<std::shared_ptr<BindingConstraint>>> enabledConstraints_;
mutable std::optional<std::vector<std::shared_ptr<BindingConstraint>>> activeConstraints_;
};

struct WhoseNameContains final
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ inline void BindingConstraintsRepository::each(const PredicateT &predicate) cons
}

template<class PredicateT>
inline void BindingConstraintsRepository::eachEnabled(const PredicateT &predicate) const {
inline void BindingConstraintsRepository::eachActive(const PredicateT &predicate) const {
uint count = (uint) pList.size();
for (uint i = 0; i != count; ++i) {
auto &constraint = *(pList[i].get());
if (constraint.enabled() && !constraint.skipped())
if (constraint.isActive())
predicate(constraint);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/libs/antares/study/runtime/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ bool StudyRuntimeInfos::loadFromStudy(Study& study)
logs.info() << " thermal clusters: " << thermalPlantTotalCount;
logs.info() << " thermal clusters (must-run): " << thermalPlantTotalCountMustRun;
logs.info() << " short-term storages: " << shortTermStorageCount;
logs.info() << " binding constraints: " << study.bindingConstraints.enabled().size();
logs.info() << " binding constraints: " << study.bindingConstraints.activeContraints().size();
logs.info() << " geographic trimming:" << (gd.geographicTrimming ? "true" : "false");
logs.info() << " memory : " << ((study.memoryUsage()) / 1024 / 1024) << "Mo";
logs.info();
Expand Down
38 changes: 19 additions & 19 deletions src/solver/simulation/sim_alloc_probleme_hebdo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ void SIM_AllocationProblemeHebdo(PROBLEME_HEBDO& problem, unsigned NombreDePasDe
problem.CorrespondanceCntNativesCntOptim.resize(NombreDePasDeTemps);
problem.VariablesDualesDesContraintesDeNTC.resize(NombreDePasDeTemps);

auto enabledBindingConstraints = study.bindingConstraints.enabled();
problem.NombreDeContraintesCouplantes = enabledBindingConstraints.size();
problem.MatriceDesContraintesCouplantes.resize(enabledBindingConstraints.size());
auto activeContraints = study.bindingConstraints.activeContraints();
problem.NombreDeContraintesCouplantes = activeContraints.size();
problem.MatriceDesContraintesCouplantes.resize(activeContraints.size());
problem.PaliersThermiquesDuPays.resize(nbPays);
problem.CaracteristiquesHydrauliques.resize(nbPays);
problem.previousSimulationFinalLevel.assign(nbPays, 0.);
Expand Down Expand Up @@ -223,7 +223,7 @@ void SIM_AllocationProblemeHebdo(PROBLEME_HEBDO& problem, unsigned NombreDePasDe
problem.CorrespondanceCntNativesCntOptim[k].NumeroDeContrainteDeDissociationDeFlux
.assign(linkCount, 0);
problem.CorrespondanceCntNativesCntOptim[k].NumeroDeContrainteDesContraintesCouplantes
.assign(enabledBindingConstraints.size(), 0);
.assign(activeContraints.size(), 0);

problem.CorrespondanceCntNativesCntOptim[k]
.NumeroDeContrainteDesContraintesDeDureeMinDeMarche
Expand Down Expand Up @@ -258,48 +258,48 @@ void SIM_AllocationProblemeHebdo(PROBLEME_HEBDO& problem, unsigned NombreDePasDe
{
problem.CorrespondanceCntNativesCntOptimJournalieres[k]
.NumeroDeContrainteDesContraintesCouplantes
.assign(enabledBindingConstraints.size(), 0);
.assign(activeContraints.size(), 0);
}

problem.CorrespondanceCntNativesCntOptimHebdomadaires
.NumeroDeContrainteDesContraintesCouplantes
.assign(enabledBindingConstraints.size(), 0);
.assign(activeContraints.size(), 0);

const auto& bindingConstraintCount = enabledBindingConstraints.size();
const auto& bindingConstraintCount = activeContraints.size();
problem.ResultatsContraintesCouplantes.resize(bindingConstraintCount);

for (unsigned k = 0; k < bindingConstraintCount; k++)
{
auto enabledConstraints = study.bindingConstraints.enabled();
assert(k < enabledConstraints.size());
assert(enabledConstraints[k]->linkCount() < 50000000);
assert(enabledConstraints[k]->clusterCount() < 50000000);
auto activeConstraints = study.bindingConstraints.activeContraints();
assert(k < activeConstraints.size());
assert(activeConstraints[k]->linkCount() < 50000000);
assert(activeConstraints[k]->clusterCount() < 50000000);

problem.MatriceDesContraintesCouplantes[k].SecondMembreDeLaContrainteCouplante
.assign(NombreDePasDeTemps, 0.);
problem.MatriceDesContraintesCouplantes[k].SecondMembreDeLaContrainteCouplanteRef
.assign(NombreDePasDeTemps, 0.);

problem.MatriceDesContraintesCouplantes[k].NumeroDeLInterconnexion
.assign(enabledBindingConstraints[k]->linkCount(), 0);
.assign(activeContraints[k]->linkCount(), 0);
problem.MatriceDesContraintesCouplantes[k].PoidsDeLInterconnexion
.assign(enabledBindingConstraints[k]->linkCount(), 0.);
.assign(activeContraints[k]->linkCount(), 0.);
problem.MatriceDesContraintesCouplantes[k].OffsetTemporelSurLInterco
.assign(enabledBindingConstraints[k]->linkCount(), 0);
.assign(activeContraints[k]->linkCount(), 0);

problem.MatriceDesContraintesCouplantes[k].NumeroDuPalierDispatch
.assign(enabledBindingConstraints[k]->clusterCount(), 0);
.assign(activeContraints[k]->clusterCount(), 0);
problem.MatriceDesContraintesCouplantes[k].PoidsDuPalierDispatch
.assign(enabledBindingConstraints[k]->clusterCount(), 0.);
.assign(activeContraints[k]->clusterCount(), 0.);
problem.MatriceDesContraintesCouplantes[k].OffsetTemporelSurLePalierDispatch
.assign(enabledBindingConstraints[k]->clusterCount(), 0);
.assign(activeContraints[k]->clusterCount(), 0);
problem.MatriceDesContraintesCouplantes[k].PaysDuPalierDispatch
.assign(enabledBindingConstraints[k]->clusterCount(), 0);
.assign(activeContraints[k]->clusterCount(), 0);


// TODO : create a numberOfTimeSteps method in class of runtime->bindingConstraint
unsigned int nbTimeSteps;
switch (enabledBindingConstraints[k]->type())
switch (activeContraints[k]->type())
{
using namespace Antares::Data;
case BindingConstraint::typeHourly:
Expand Down
14 changes: 7 additions & 7 deletions src/solver/simulation/sim_calcul_economique.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ void SIM_InitialisationProblemeHebdo(Data::Study& study,

problem.NumberOfShortTermStorages = study.runtime->shortTermStorageCount;

auto enabledBindingConstraints = study.bindingConstraints.enabled();
problem.NombreDeContraintesCouplantes = enabledBindingConstraints.size();
auto activeContraints = study.bindingConstraints.activeContraints();
problem.NombreDeContraintesCouplantes = activeContraints.size();

problem.ExportMPS = study.parameters.include.exportMPS;
problem.ExportStructure = study.parameters.include.exportStructure;
Expand Down Expand Up @@ -222,9 +222,9 @@ void SIM_InitialisationProblemeHebdo(Data::Study& study,
problem.PaysExtremiteDeLInterconnexion[i] = link.with->index;
}

for (uint i = 0; i < enabledBindingConstraints.size(); ++i)
for (uint i = 0; i < activeContraints.size(); ++i)
{
auto bc = enabledBindingConstraints[i];
auto bc = activeContraints[i];
CONTRAINTES_COUPLANTES& PtMat = problem.MatriceDesContraintesCouplantes[i];
PtMat.NombreDInterconnexionsDansLaContrainteCouplante = bc->linkCount();
PtMat.NombreDePaliersDispatchDansLaContrainteCouplante = bc->clusterCount();
Expand Down Expand Up @@ -313,11 +313,11 @@ void SIM_InitialisationProblemeHebdo(Data::Study& study,

void preparerBindingConstraint(const PROBLEME_HEBDO &problem, uint numSpace, int PasDeTempsDebut,
const BindingConstraintsRepository &bindingConstraints, const uint weekFirstDay, int pasDeTemps) {
auto enabledConstraints = bindingConstraints.enabled();
const auto constraintCount = enabledConstraints.size();
auto activeContraints = bindingConstraints.activeContraints();
const auto constraintCount = activeContraints.size();
for (unsigned constraintIndex = 0; constraintIndex != constraintCount; ++constraintIndex)
{
auto bc = enabledConstraints[constraintIndex];
auto bc = activeContraints[constraintIndex];
assert(bc->RHSTimeSeries().width && "Invalid constraint data width");
//If there is only one TS, always select it.
const auto ts_number = bc->RHSTimeSeries().width == 1 ? 0 : NumeroChroniquesTireesParGroup[numSpace][bc->group()];
Expand Down
2 changes: 1 addition & 1 deletion src/solver/simulation/timeseries-numbers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ void drawAndStoreTSnumbersForNOTintraModal(const array<bool, timeSeriesCount>& i
for (auto& [group, timeSeries] : study.bindingConstraints.groupToTimeSeriesNumbers)
{
const auto nbTimeSeries
= BindingConstraintsRepository::NumberOfTimeseries(study.bindingConstraints.enabled(), group);
= BindingConstraintsRepository::NumberOfTimeseries(study.bindingConstraints.activeContraints(), group);
auto& value = timeSeries.timeseriesNumbers[0][year];
if (nbTimeSeries == 1)
{
Expand Down
13 changes: 5 additions & 8 deletions src/solver/variable/bc.memory-estimation.inc.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ uint64 BindingConstraints<bc_next_type>::memoryUsage() const
template<>
void BindingConstraints<bc_next_type>::EstimateMemoryUsage(Data::StudyMemoryUsage& u)
{
u.study.bindingConstraints.eachEnabled([&](const Data::BindingConstraint& constraint) {
u.study.bindingConstraints.eachActive([&](const Data::BindingConstraint &constraint) {
if (constraint.operatorType() == Data::BindingConstraint::opEquality)
return;

Expand All @@ -58,16 +58,13 @@ void BindingConstraints<bc_next_type>::EstimateMemoryUsage(Data::StudyMemoryUsag
if (constraint.operatorType() == Data::BindingConstraint::opBoth)
bc_count = 2;

for (int i = 0; i < bc_count; i++)
{
u.requiredMemoryForOutput += sizeof(NextType) + sizeof(void*) /*overhead vector*/;
for (int i = 0; i < bc_count; i++) {
u.requiredMemoryForOutput += sizeof(NextType) + sizeof(void *) /*overhead vector*/;
u.overheadDiskSpaceForSingleBindConstraint();

// year-by-year
if (!u.gatheringInformationsForInput)
{
if (u.study.parameters.yearByYear)
{
if (!u.gatheringInformationsForInput) {
if (u.study.parameters.yearByYear) {
for (unsigned int i = 0; i != u.years; ++i)
u.overheadDiskSpaceForSingleBindConstraint();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class BindingConstMarginCost
pValuesForTheCurrentYear[numSpace].initializeFromStudy(study);

// Set the associated binding constraint
associatedBC_ = study.bindingConstraints.enabled()[bindConstraintGlobalIndex_];
associatedBC_ = study.bindingConstraints.activeContraints()[bindConstraintGlobalIndex_];

NextType::initializeFromStudy(study);
}
Expand Down

0 comments on commit 4be9453

Please sign in to comment.