diff --git a/src/libs/antares/benchmarking/info_collectors.cpp b/src/libs/antares/benchmarking/info_collectors.cpp index 3b7ccb5ba7..6cf9e038f5 100644 --- a/src/libs/antares/benchmarking/info_collectors.cpp +++ b/src/libs/antares/benchmarking/info_collectors.cpp @@ -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++; diff --git a/src/libs/antares/study/binding_constraint/BindingConstraint.h b/src/libs/antares/study/binding_constraint/BindingConstraint.h index 93bfbddd12..8bb4758462 100644 --- a/src/libs/antares/study/binding_constraint/BindingConstraint.h +++ b/src/libs/antares/study/binding_constraint/BindingConstraint.h @@ -190,6 +190,7 @@ class BindingConstraint final : public Yuni::NonCopyable //@} bool skipped() const; + bool isActive() const; //Ref to prevent copy. const ref to prevent modification. const Matrix<>& RHSTimeSeries() const; @@ -411,6 +412,7 @@ class BindingConstraint final : public Yuni::NonCopyable void clear(); void copyFrom(BindingConstraint const *original); + }; // class BindingConstraint // class BindConstList diff --git a/src/libs/antares/study/binding_constraint/BindingConstraint.hxx b/src/libs/antares/study/binding_constraint/BindingConstraint.hxx index b40131069a..2243b2035c 100644 --- a/src/libs/antares/study/binding_constraint/BindingConstraint.hxx +++ b/src/libs/antares/study/binding_constraint/BindingConstraint.hxx @@ -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(); } diff --git a/src/libs/antares/study/binding_constraint/BindingConstraintsRepository.cpp b/src/libs/antares/study/binding_constraint/BindingConstraintsRepository.cpp index 0530679b52..bdd8710349 100644 --- a/src/libs/antares/study/binding_constraint/BindingConstraintsRepository.cpp +++ b/src/libs/antares/study/binding_constraint/BindingConstraintsRepository.cpp @@ -15,7 +15,7 @@ void Data::BindingConstraintsRepository::clear() { pList.clear(); - enabledConstraints_.reset(); + activeConstraints_.reset(); } namespace Antares::Data { @@ -341,7 +341,7 @@ void BindingConstraintsRepository::remove(const Area* area) RemovePredicate 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) @@ -349,7 +349,7 @@ void BindingConstraintsRepository::remove(const AreaLink* lnk) RemovePredicate 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) @@ -357,7 +357,7 @@ void BindingConstraintsRepository::remove(const BindingConstraint* bc) RemovePredicate predicate(bc); auto e = std::remove_if(pList.begin(), pList.end(), predicate); pList.erase(e, pList.end()); - enabledConstraints_.reset(); + activeConstraints_.reset(); } @@ -415,17 +415,17 @@ uint64 BindingConstraintsRepository::timeSeriesNumberMemoryUsage() const { return m; } -std::vector> BindingConstraintsRepository::enabled() const { - if (enabledConstraints_) { - return enabledConstraints_.value(); +std::vector> BindingConstraintsRepository::activeContraints() const { + if (activeConstraints_) { + return activeConstraints_.value(); } else { std::vector> 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(); } } @@ -436,9 +436,9 @@ static bool isBindingConstraintTypeInequality(const Data::BindingConstraint& bc) std::vector 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 indices; for (auto bc = firstBC; bc < lastBC; bc++) diff --git a/src/libs/antares/study/binding_constraint/BindingConstraintsRepository.h b/src/libs/antares/study/binding_constraint/BindingConstraintsRepository.h index f510d3f1ea..9822b9440f 100644 --- a/src/libs/antares/study/binding_constraint/BindingConstraintsRepository.h +++ b/src/libs/antares/study/binding_constraint/BindingConstraintsRepository.h @@ -55,7 +55,7 @@ class BindingConstraintsRepository final : public Yuni::NonCopyable - void eachEnabled(const PredicateT& predicate) const; + void eachActive(const PredicateT& predicate) const; iterator begin(); [[nodiscard]] const_iterator begin() const; @@ -173,7 +173,7 @@ class BindingConstraintsRepository final : public Yuni::NonCopyable> groupToTimeSeriesNumbers; - [[nodiscard]] std::vector> enabled() const; + [[nodiscard]] std::vector> activeContraints() const; [[nodiscard]] std::vector getIndicesForInequalityBindingConstraints() const; @@ -190,7 +190,7 @@ class BindingConstraintsRepository final : public Yuni::NonCopyable>> enabledConstraints_; + mutable std::optional>> activeConstraints_; }; struct WhoseNameContains final diff --git a/src/libs/antares/study/binding_constraint/BindingConstraintsRepository.hxx b/src/libs/antares/study/binding_constraint/BindingConstraintsRepository.hxx index 320eb01b1d..30cbc9ac19 100644 --- a/src/libs/antares/study/binding_constraint/BindingConstraintsRepository.hxx +++ b/src/libs/antares/study/binding_constraint/BindingConstraintsRepository.hxx @@ -32,11 +32,11 @@ inline void BindingConstraintsRepository::each(const PredicateT &predicate) cons } template -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); } } diff --git a/src/libs/antares/study/runtime/runtime.cpp b/src/libs/antares/study/runtime/runtime.cpp index 25f14e02d3..a17a62c2ba 100644 --- a/src/libs/antares/study/runtime/runtime.cpp +++ b/src/libs/antares/study/runtime/runtime.cpp @@ -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(); diff --git a/src/solver/simulation/sim_alloc_probleme_hebdo.cpp b/src/solver/simulation/sim_alloc_probleme_hebdo.cpp index 0bb99a418e..f3fa5bd029 100644 --- a/src/solver/simulation/sim_alloc_probleme_hebdo.cpp +++ b/src/solver/simulation/sim_alloc_probleme_hebdo.cpp @@ -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.); @@ -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 @@ -258,22 +258,22 @@ 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.); @@ -281,25 +281,25 @@ void SIM_AllocationProblemeHebdo(PROBLEME_HEBDO& problem, unsigned NombreDePasDe .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: diff --git a/src/solver/simulation/sim_calcul_economique.cpp b/src/solver/simulation/sim_calcul_economique.cpp index 562de0f470..c8529417fb 100644 --- a/src/solver/simulation/sim_calcul_economique.cpp +++ b/src/solver/simulation/sim_calcul_economique.cpp @@ -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; @@ -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(); @@ -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()]; diff --git a/src/solver/simulation/timeseries-numbers.cpp b/src/solver/simulation/timeseries-numbers.cpp index 15aac9240b..332fca3fad 100644 --- a/src/solver/simulation/timeseries-numbers.cpp +++ b/src/solver/simulation/timeseries-numbers.cpp @@ -715,7 +715,7 @@ void drawAndStoreTSnumbersForNOTintraModal(const array& 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) { diff --git a/src/solver/variable/bc.memory-estimation.inc.hxx b/src/solver/variable/bc.memory-estimation.inc.hxx index 1c3d60aa0a..c14e5e12f5 100644 --- a/src/solver/variable/bc.memory-estimation.inc.hxx +++ b/src/solver/variable/bc.memory-estimation.inc.hxx @@ -48,7 +48,7 @@ uint64 BindingConstraints::memoryUsage() const template<> void BindingConstraints::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; @@ -58,16 +58,13 @@ void BindingConstraints::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(); } diff --git a/src/solver/variable/economy/bindingConstraints/bindingConstraintsMarginalCost.h b/src/solver/variable/economy/bindingConstraints/bindingConstraintsMarginalCost.h index 2814ea49b5..c6836a0a01 100644 --- a/src/solver/variable/economy/bindingConstraints/bindingConstraintsMarginalCost.h +++ b/src/solver/variable/economy/bindingConstraints/bindingConstraintsMarginalCost.h @@ -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); }