From 695d60864009558f651220fad1d3dcb95ea95897 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Thu, 7 Dec 2023 15:38:04 +0100 Subject: [PATCH 01/54] [DEV] Use vect instead of map --- .../study/parts/common/cluster_list.cpp | 24 +++++++++++++------ .../antares/study/parts/common/cluster_list.h | 21 +++++++--------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index 3f08915727..5fd06d4f62 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -86,12 +86,10 @@ void ClusterList::remove(iterator i) template bool ClusterList::exists(const Data::ClusterName& id) const { - if (not cluster.empty()) - { - auto element = cluster.find(id); - return (element != cluster.end()); - } - return false; + auto& it = find_if(cluster.begin(), cluster.end(), + [&id](const ClusterT& c) { return c.id == id; }); + + return it != cluster.end(); } template @@ -138,6 +136,16 @@ ClusterT* ClusterList::find(const ClusterT* p) return nullptr; } +template +typename ClusterList::SharedPtr ClusterList::find( + const ClusterList::SharedPtr& p) +{ + auto& it = find_if(cluster.begin(), cluster.end(), + [&id](const ClusterT& c) { return c.id == id; }); + + return (it != cluster.end()) ? *it : nullptr; +} + template void ClusterList::resizeAllTimeseriesNumbers(uint n) { @@ -195,6 +203,8 @@ void ClusterList::rebuildIndex() } } + + template typename ClusterList::SharedPtr ClusterList::add( const ClusterList::SharedPtr& newcluster) @@ -202,7 +212,7 @@ typename ClusterList::SharedPtr ClusterList::add( if (newcluster) { if (exists(newcluster->id())) - return cluster[newcluster->id()]; + return this->find(*newcluster); newcluster->index = (uint)size(); cluster[newcluster->id()] = newcluster; diff --git a/src/libs/antares/study/parts/common/cluster_list.h b/src/libs/antares/study/parts/common/cluster_list.h index 14f90d9fa3..a42ec11a8c 100644 --- a/src/libs/antares/study/parts/common/cluster_list.h +++ b/src/libs/antares/study/parts/common/cluster_list.h @@ -6,6 +6,7 @@ #include +#include #include #include @@ -25,6 +26,8 @@ class ClusterList using SharedPtr = typename std::shared_ptr; // Map container using Map = typename std::map; + // Vector container + using Vect = typename std::vector; //! iterator using iterator = typename Map::iterator; //! const iterator @@ -51,12 +54,8 @@ class ClusterList template void each(const PredicateT& predicate) { - auto end = cluster.cend(); - for (auto i = cluster.cbegin(); i != end; ++i) - { - auto& it = *(i->second); - predicate(it); - } + for (auto& c : cluster) + predicate(*c); } /*! ** \brief Iterate through all clusters (const) @@ -64,12 +63,8 @@ class ClusterList template void each(const PredicateT& predicate) const { - auto end = cluster.end(); - for (auto i = cluster.begin(); i != end; ++i) - { - const auto& it = *(i->second); - predicate(it); - } + for (const auto& c : cluster) + predicate(*c); } //! \name Cluster management @@ -222,7 +217,7 @@ class ClusterList //! All clusters by their index std::vector byIndex; //! All clusters - Map cluster; + Vect cluster; // thermal, renewable, etc. virtual YString typeID() const = 0; From 4ec8de159bf9abb9a57fff4f70e083f3cd1d0316 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Fri, 8 Dec 2023 12:24:02 +0100 Subject: [PATCH 02/54] [DEV] Change iterator typedef with vector iterator --- src/libs/antares/study/parts/common/cluster_list.cpp | 10 +++++----- src/libs/antares/study/parts/common/cluster_list.h | 5 +++-- src/solver/variable/surveyresults/reportbuilder.hxx | 6 +++--- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index 5fd06d4f62..562f13c5ae 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -72,7 +72,7 @@ ClusterT* ClusterList::find(const Data::ClusterName& id) template typename std::shared_ptr ClusterList::detach(iterator i) { - SharedPtr c = i->second; + SharedPtr c = *i; cluster.erase(i); return c; } @@ -141,7 +141,7 @@ typename ClusterList::SharedPtr ClusterList::find( const ClusterList::SharedPtr& p) { auto& it = find_if(cluster.begin(), cluster.end(), - [&id](const ClusterT& c) { return c.id == id; }); + [&p](const ClusterT& c) { return c.id == p.id; }); return (it != cluster.end()) ? *it : nullptr; } @@ -212,13 +212,13 @@ typename ClusterList::SharedPtr ClusterList::add( if (newcluster) { if (exists(newcluster->id())) - return this->find(*newcluster); + return this->find(newcluster); newcluster->index = (uint)size(); - cluster[newcluster->id()] = newcluster; + cluster.push_back(newcluster); ++(groupCount[newcluster->groupId()]); rebuildIndex(); - return cluster[newcluster->id()]; + return cluster.back(); } return nullptr; } diff --git a/src/libs/antares/study/parts/common/cluster_list.h b/src/libs/antares/study/parts/common/cluster_list.h index a42ec11a8c..ee63edcac1 100644 --- a/src/libs/antares/study/parts/common/cluster_list.h +++ b/src/libs/antares/study/parts/common/cluster_list.h @@ -29,9 +29,9 @@ class ClusterList // Vector container using Vect = typename std::vector; //! iterator - using iterator = typename Map::iterator; + using iterator = typename Vect::iterator; //! const iterator - using const_iterator = typename Map::const_iterator; + using const_iterator = typename Vect::const_iterator; public: //! \name Constructor & Destructor @@ -116,6 +116,7 @@ class ClusterList ** \return A pointer to a cluster. nullptr if not found */ const ClusterT* find(const Data::ClusterName& id) const; + SharedPtr find(const ClusterList::SharedPtr& p); /*! ** \brief Try to find a cluster from its pointer diff --git a/src/solver/variable/surveyresults/reportbuilder.hxx b/src/solver/variable/surveyresults/reportbuilder.hxx index 85f49dd3a5..da3b4bdf86 100644 --- a/src/solver/variable/surveyresults/reportbuilder.hxx +++ b/src/solver/variable/surveyresults/reportbuilder.hxx @@ -327,14 +327,14 @@ private: auto end = area.thermal.list.end(); for (auto i = area.thermal.list.begin(); i != end; ++i) { - auto& cluster = *(i->second); + auto& cluster = *i; results.data.thermalCluster = &cluster; - logs.info() << "Exporting results : " << area.name << " :: " << cluster.name(); + logs.info() << "Exporting results : " << area.name << " :: " << cluster->name(); // The new output results.data.output.clear(); results.data.output << results.data.originalOutput << SEP << "areas" << SEP - << area.id << SEP << "thermal" << SEP << cluster.id(); + << area.id << SEP << "thermal" << SEP << cluster->id(); SurveyReportBuilderFile::Run(list, results, numSpace); } From dc727322434dc4b0e1a943a295efe4e1619036ab Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Fri, 8 Dec 2023 12:45:52 +0100 Subject: [PATCH 03/54] [DEV] FIx renewable --- src/libs/antares/study/parts/renewable/container.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/libs/antares/study/parts/renewable/container.cpp b/src/libs/antares/study/parts/renewable/container.cpp index ea7cbdb0fd..0f07904b1c 100644 --- a/src/libs/antares/study/parts/renewable/container.cpp +++ b/src/libs/antares/study/parts/renewable/container.cpp @@ -66,11 +66,9 @@ void PartRenewable::prepareAreaWideIndexes() return; } - auto end = list.end(); uint idx = 0; - for (auto i = list.begin(); i != end; ++i) + for (auto& t : list) { - RenewableCluster* t = i->second.get(); t->areaWideIndex = idx; ++idx; } @@ -86,8 +84,8 @@ uint PartRenewable::removeDisabledClusters() for (auto& it : list) { - if (!it.second->enabled) - disabledClusters.push_back(it.first); + if (!it->enabled) + disabledClusters.push_back(it->id()); } for (auto& cluster : disabledClusters) From 228280f0df37e92cc256ccea4e7ef38fd5288768 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Fri, 8 Dec 2023 14:45:42 +0100 Subject: [PATCH 04/54] [DEV] More modif in common cluster_list --- .../study/parts/common/cluster_list.cpp | 78 +++++++++---------- 1 file changed, 38 insertions(+), 40 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index 562f13c5ae..01ce8a6949 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -58,15 +58,21 @@ typename ClusterList::const_iterator ClusterList::end() cons template const ClusterT* ClusterList::find(const Data::ClusterName& id) const { - auto i = cluster.find(id); - return (i != cluster.end()) ? i->second.get() : nullptr; + for (const auto& c : cluster) + if (c->id() == id) + return c.get(); + + return nullptr; } template ClusterT* ClusterList::find(const Data::ClusterName& id) { - auto i = cluster.find(id); - return (i != cluster.end()) ? i->second.get() : nullptr; + for (auto& c : cluster) + if (c->id() == id) + return c.get(); + + return nullptr; } template @@ -86,8 +92,8 @@ void ClusterList::remove(iterator i) template bool ClusterList::exists(const Data::ClusterName& id) const { - auto& it = find_if(cluster.begin(), cluster.end(), - [&id](const ClusterT& c) { return c.id == id; }); + const auto& it = find_if(cluster.begin(), cluster.end(), + [&id](const ClusterT& c) { return c.id() == id; }); return it != cluster.end(); } @@ -115,35 +121,32 @@ void ClusterList::clear() template const ClusterT* ClusterList::find(const ClusterT* p) const { - auto end = cluster.end(); - for (auto i = cluster.begin(); i != end; ++i) - { - if (p == i->second.get()) - return i->second.get(); - } + for (const auto& c : cluster) + if (c.get() == p) + return c.get(); + return nullptr; } template ClusterT* ClusterList::find(const ClusterT* p) { - auto end = cluster.end(); - for (auto i = cluster.begin(); i != end; ++i) - { - if (p == i->second.get()) - return i->second.get(); - } + for (auto& c : cluster) + if (c.get() == p) + return c.get(); + return nullptr; } template -typename ClusterList::SharedPtr ClusterList::find( - const ClusterList::SharedPtr& p) +typename ClusterList::SharedPtr ClusterList::find + (const ClusterList::SharedPtr& p) { - auto& it = find_if(cluster.begin(), cluster.end(), - [&p](const ClusterT& c) { return c.id == p.id; }); + for (auto& c : cluster) + if (c == p) + return c; - return (it != cluster.end()) ? *it : nullptr; + return nullptr; } template @@ -252,12 +255,10 @@ bool ClusterList::rename(Data::ClusterName idToFind, Data::ClusterName Antares::TransformNameIntoID(newName, newID); // Looking for the renewable cluster in the list - auto it = cluster.find(idToFind); - if (it == cluster.end()) + auto* p = this->find(idToFind); + if (!p) return true; - SharedPtr p = it->second; - if (idToFind == newID) { p->setName(newName); @@ -272,10 +273,7 @@ bool ClusterList::rename(Data::ClusterName idToFind, Data::ClusterName if (this->exists(newID)) return false; - cluster.erase(it); - p->setName(newName); - cluster[newID] = p; // Invalidate matrices attached to the area // It is a bit excessive (all matrices not only those related to the renewable cluster) @@ -292,32 +290,32 @@ template bool ClusterList::forceReload(bool reload) const { bool ret = true; - auto end = cluster.end(); - for (auto i = cluster.begin(); i != end; ++i) - ret = (i->second)->forceReload(reload) and ret; + for (const auto& c : cluster) + ret = c->forceReload(reload) && ret; return ret; } template void ClusterList::markAsModified() const { - auto end = cluster.end(); - for (auto i = cluster.begin(); i != end; ++i) - (i->second)->markAsModified(); + for (const auto& c : cluster) + c->markAsModified(); } template bool ClusterList::remove(const Data::ClusterName& id) { - auto i = cluster.find(id); - if (i == cluster.end()) + const auto& it = find_if(cluster.begin(), cluster.end(), + [&id](const ClusterT& c) { return c.id() == id; }); + + if (it == cluster.end()) return false; // Getting the pointer on the cluster - SharedPtr c = i->second; + SharedPtr c = *it; // Removing it from the list - cluster.erase(i); + cluster.erase(it); // Invalidating the parent area c->parentArea->forceReload(); From e68f7ed0ef2dc52af076c41bad2762879bc99fb0 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Fri, 8 Dec 2023 15:02:10 +0100 Subject: [PATCH 05/54] [DEV] no error common clusterlist --- .../study/parts/common/cluster_list.cpp | 55 +++++++------------ 1 file changed, 20 insertions(+), 35 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index 01ce8a6949..8fa90e651f 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -92,10 +92,11 @@ void ClusterList::remove(iterator i) template bool ClusterList::exists(const Data::ClusterName& id) const { - const auto& it = find_if(cluster.begin(), cluster.end(), - [&id](const ClusterT& c) { return c.id() == id; }); + for (const auto& c : cluster) + if (c->id() == id) + return true; - return it != cluster.end(); + return false; } template @@ -196,12 +197,10 @@ void ClusterList::rebuildIndex() { uint indx = 0; byIndex.resize(size()); - for (auto i = cluster.begin(); i != cluster.end(); ++i) + for (auto& c : cluster) { - auto cluster = i->second.get(); - byIndex[indx] = cluster; - cluster->index = indx; - ++indx; + byIndex[indx] = c.get(); + c->index = indx++; } } } @@ -306,7 +305,7 @@ template bool ClusterList::remove(const Data::ClusterName& id) { const auto& it = find_if(cluster.begin(), cluster.end(), - [&id](const ClusterT& c) { return c.id() == id; }); + [&id](const SharedPtr& c) { return c->id() == id; }); if (it == cluster.end()) return false; @@ -328,16 +327,13 @@ template int ClusterList::saveDataSeriesToFolder(const AnyString& folder) const { if (empty()) - return 1; + return false; - int ret = 1; + bool ret = true; + + for (const auto& c : cluster) + ret = c->saveDataSeriesToFolder(folder) && ret; - auto end = cluster.end(); - for (auto it = cluster.begin(); it != end; ++it) - { - auto& cluster = *(it->second); - ret = cluster.saveDataSeriesToFolder(folder) and ret; - } return ret; } @@ -345,18 +341,16 @@ template int ClusterList::saveDataSeriesToFolder(const AnyString& folder, const String& msg) const { if (empty()) - return 1; + return false; - int ret = 1; + bool ret = true; uint ticks = 0; - auto end = cluster.end(); - for (auto it = cluster.begin(); it != end; ++it) + for (const auto& c : cluster) { - auto& cluster = *(it->second); logs.info() << msg << " " << (ticks * 100 / (1 + this->cluster.size())) << "% complete"; - ret = cluster.saveDataSeriesToFolder(folder) and ret; + ret = c->saveDataSeriesToFolder(folder) && ret; ++ticks; } return ret; @@ -387,19 +381,10 @@ void ClusterList::retrieveTotalCapacityAndUnitCount(double& total, uin total = 0.; unitCount = 0; - if (not cluster.empty()) + for (const auto& c : cluster) { - auto end = cluster.cend(); - for (auto i = cluster.cbegin(); i != end; ++i) - { - if (not i->second) - return; - - // Reference to the thermal cluster - auto& cluster = *(i->second); - unitCount += cluster.unitCount; - total += cluster.unitCount * cluster.nominalCapacity; - } + unitCount += c->unitCount; + total += c->unitCount * c->nominalCapacity; } } From 8eeeb38dec310346b990fd3a69e84bfa4569b1c5 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Fri, 8 Dec 2023 15:18:46 +0100 Subject: [PATCH 06/54] [FIX] compile cleaner-v20 --- .../antares/study/cleaner/cleaner-v20.cpp | 26 +++++++------------ 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/libs/antares/study/cleaner/cleaner-v20.cpp b/src/libs/antares/study/cleaner/cleaner-v20.cpp index a0f4dea784..5f8e6636e1 100644 --- a/src/libs/antares/study/cleaner/cleaner-v20.cpp +++ b/src/libs/antares/study/cleaner/cleaner-v20.cpp @@ -135,23 +135,19 @@ static void listOfFilesAnDirectoriesToKeepForArea(PathList& e, PathList& p, cons buffer.clear() << "input/thermal/clusters/" << id << "/list.ini"; e.add(buffer); - auto end = area->thermal.list.end(); - for (auto i = area->thermal.list.begin(); i != end; ++i) + for (const auto& cluster : area->thermal.list) { - // Reference to the thermal cluster - auto& cluster = *(i->second); - - buffer.clear() << "input/thermal/prepro/" << id << '/' << cluster.id(); + buffer.clear() << "input/thermal/prepro/" << id << '/' << cluster->id(); p.add(buffer); - buffer.clear() << "input/thermal/series/" << id << '/' << cluster.id(); + buffer.clear() << "input/thermal/series/" << id << '/' << cluster->id(); p.add(buffer); - buffer.clear() << "input/thermal/series/" << id << '/' << cluster.id() << "/series.txt"; + buffer.clear() << "input/thermal/series/" << id << '/' << cluster->id() << "/series.txt"; e.add(buffer); - buffer.clear() << "input/thermal/prepro/" << id << '/' << cluster.id() << "/data.txt"; + buffer.clear() << "input/thermal/prepro/" << id << '/' << cluster->id() << "/data.txt"; e.add(buffer); - buffer.clear() << "input/thermal/prepro/" << id << '/' << cluster.id() + buffer.clear() << "input/thermal/prepro/" << id << '/' << cluster->id() << "/modulation.txt"; e.add(buffer); } @@ -168,16 +164,12 @@ static void listOfFilesAnDirectoriesToKeepForArea(PathList& e, PathList& p, cons buffer.clear() << "input/renewables/clusters/" << id << "/list.ini"; e.add(buffer); - auto end = area->renewable.list.end(); - for (auto i = area->renewable.list.begin(); i != end; ++i) + for (const auto& cluster : area->renewable.list) { - // Reference to the thermal cluster - auto& cluster = *(i->second); - - buffer.clear() << "input/renewables/series/" << id << '/' << cluster.id(); + buffer.clear() << "input/renewables/series/" << id << '/' << cluster->id(); p.add(buffer); - buffer.clear() << "input/renewables/series/" << id << '/' << cluster.id() + buffer.clear() << "input/renewables/series/" << id << '/' << cluster->id() << "/series.txt"; e.add(buffer); } From 0c2cc7b8ae6099bb4fe402e421fcbdbe8592842f Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Fri, 8 Dec 2023 15:20:00 +0100 Subject: [PATCH 07/54] [FIX] compile RenewableTSNumberData --- .../antares/study/scenario-builder/RenewableTSNumberData.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/antares/study/scenario-builder/RenewableTSNumberData.cpp b/src/libs/antares/study/scenario-builder/RenewableTSNumberData.cpp index 338f13a4b2..725729f5c9 100644 --- a/src/libs/antares/study/scenario-builder/RenewableTSNumberData.cpp +++ b/src/libs/antares/study/scenario-builder/RenewableTSNumberData.cpp @@ -33,7 +33,7 @@ bool renewableTSNumberData::apply(Study& study) const uint tsGenCountRenewable = get_tsGenCount(study); uint clusterIndex = 0; - for (const auto& [name, cluster] : area.renewable.list) + for (const auto& cluster : area.renewable.list) { // alias to the current column assert(clusterIndex < pTSNumberRules.width); From 5891cec6a7a125132c6b180ffd2854eb389a433a Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Fri, 8 Dec 2023 15:29:32 +0100 Subject: [PATCH 08/54] [FIX] compile thermal container --- .../antares/study/parts/thermal/container.cpp | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/src/libs/antares/study/parts/thermal/container.cpp b/src/libs/antares/study/parts/thermal/container.cpp index 55cebd6440..0d9b3fb66c 100644 --- a/src/libs/antares/study/parts/thermal/container.cpp +++ b/src/libs/antares/study/parts/thermal/container.cpp @@ -40,7 +40,6 @@ namespace Antares { namespace Data { -using NamedCluster = std::pair; PartThermal::PartThermal() : unsuppliedEnergyCost(0.), spilledEnergyCost(0.) { @@ -76,14 +75,11 @@ void PartThermal::prepareAreaWideIndexes() clusters.assign(list.size(), nullptr); - auto end = list.end(); uint idx = 0; - for (auto i = list.begin(); i != end; ++i) + for (const auto& cluster : list) { - ThermalCluster* t = i->second.get(); - t->areaWideIndex = idx; - clusters[idx] = t; - ++idx; + cluster->areaWideIndex = idx; + clusters[idx++] = cluster.get(); } } @@ -99,10 +95,9 @@ uint PartThermal::prepareClustersInMustRunMode() do { mustContinue = false; - auto end = list.end(); - for (auto i = list.begin(); i != end; ++i) + for (auto i = list.begin(); i != list.end(); ++i) { - if ((i->second)->mustrun) + if ((*i)->mustrun) { // Detaching the thermal cluster from the main list... std::shared_ptr cluster = list.detach(i); @@ -148,8 +143,8 @@ uint PartThermal::removeDisabledClusters() for (auto& it : list) { - if (!it.second->enabled) - disabledClusters.push_back(it.first); + if (!it->enabled) + disabledClusters.push_back(it->id()); } for (const auto& cluster : disabledClusters) @@ -175,16 +170,16 @@ void PartThermal::reset() bool PartThermal::hasForcedTimeseriesGeneration() const { using Behavior = LocalTSGenerationBehavior; - return std::any_of(list.begin(), list.end(), [](const NamedCluster& namedCluster) { - return namedCluster.second->tsGenBehavior == Behavior::forceGen; + return std::any_of(list.begin(), list.end(), [](const ThermalClusterList::SharedPtr& cluster) { + return cluster->tsGenBehavior == Behavior::forceGen; }); } bool PartThermal::hasForcedNoTimeseriesGeneration() const { using Behavior = LocalTSGenerationBehavior; - return std::any_of(list.begin(), list.end(), [](const NamedCluster& namedCluster) { - return namedCluster.second->tsGenBehavior == Behavior::forceNoGen; + return std::any_of(list.begin(), list.end(), [](const ThermalClusterList::SharedPtr& cluster) { + return cluster->tsGenBehavior == Behavior::forceNoGen; }); } From 50d64f554e99f54ea5869e6c1d24248a392e0264 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Fri, 8 Dec 2023 15:53:44 +0100 Subject: [PATCH 09/54] [FIX] compile thermal clusterlist --- .../study/parts/thermal/cluster_list.cpp | 39 +++---------------- .../study/parts/thermal/cluster_list.h | 2 - src/libs/antares/study/study.cpp | 8 +--- 3 files changed, 8 insertions(+), 41 deletions(-) diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index 2cd45cfa14..e67891b80e 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -278,31 +278,8 @@ void ThermalClusterList::calculationOfSpinning() void ThermalClusterList::reverseCalculationOfSpinning() { - auto end = cluster.end(); - for (auto it = cluster.begin(); it != end; ++it) - { - auto& cluster = *(it->second); - cluster.reverseCalculationOfSpinning(); - } -} - -bool ThermalClusterList::remove(const ClusterName& id) -{ - auto i = cluster.find(id); - if (i == cluster.end()) - return false; - - // Getting the pointer on the cluster - SharedPtr c = i->second; - - // Removing it from the list - cluster.erase(i); - // Invalidating the parent area - c->parentArea->forceReload(); - - // Rebuilding the index - rebuildIndex(); - return true; + for (const auto& c : cluster) + c->reverseCalculationOfSpinning(); } void ThermalClusterList::enableMustrunForEveryone() @@ -313,13 +290,9 @@ void ThermalClusterList::enableMustrunForEveryone() void ThermalClusterList::ensureDataPrepro() { - auto end = cluster.end(); - for (auto it = cluster.begin(); it != end; ++it) - { - auto c = it->second; - if (not c->prepro) + for (const auto& c : cluster) + if (!c->prepro) c->prepro = new PreproThermal(c); - } } bool ThermalClusterList::saveToFolder(const AnyString& folder) const @@ -485,7 +458,7 @@ bool ThermalClusterList::loadPreproFromFolder(Study& study, Clob buffer; bool ret = true; - for (auto& [name, c] : cluster) + for (const auto& c : cluster) { if (c->prepro) { @@ -518,7 +491,7 @@ bool ThermalClusterList::loadEconomicCosts(Study& study, const AnyString& folder Clob buffer; bool ret = true; - for (auto& [name, c] : cluster) + for (const auto& c : cluster) { assert(c->parentArea and "cluster: invalid parent area"); buffer.clear() << folder << SEP << c->parentArea->id << SEP << c->id(); diff --git a/src/libs/antares/study/parts/thermal/cluster_list.h b/src/libs/antares/study/parts/thermal/cluster_list.h index 1d15b028a9..6a2d1e0a7c 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.h +++ b/src/libs/antares/study/parts/thermal/cluster_list.h @@ -58,8 +58,6 @@ class ThermalClusterList : public ClusterList void enableMustrunForEveryone(); //@} - bool remove(const ClusterName& id) override; - Map mapping; /*! diff --git a/src/libs/antares/study/study.cpp b/src/libs/antares/study/study.cpp index dfaf427287..18c272c12a 100644 --- a/src/libs/antares/study/study.cpp +++ b/src/libs/antares/study/study.cpp @@ -1128,12 +1128,8 @@ void Study::destroyAllWindTSGeneratorData() void Study::destroyAllThermalTSGeneratorData() { areas.each([&](Data::Area& area) { - auto pend = area.thermal.list.end(); - for (auto j = area.thermal.list.begin(); j != pend; ++j) - { - ThermalCluster& cluster = *(j->second); - FreeAndNil(cluster.prepro); - } + for (const auto& cluster : area.thermal.list) + FreeAndNil(cluster->prepro); }); } From 586c124f1e53aff9a27582cddc40163c7778931d Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Fri, 8 Dec 2023 15:58:18 +0100 Subject: [PATCH 10/54] [FIX] compile ui, output var --- src/libs/antares/InfoCollection/StudyInfoCollector.cpp | 8 ++------ .../variable/economy/avail-dispatchable-generation.h | 2 +- src/solver/variable/economy/productionByRenewablePlant.h | 2 +- src/solver/variable/economy/renewableGeneration.h | 2 +- src/ui/action/handler/antares-study/area/create.cpp | 2 +- 5 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/libs/antares/InfoCollection/StudyInfoCollector.cpp b/src/libs/antares/InfoCollection/StudyInfoCollector.cpp index 05f9894f12..3f67705dcf 100644 --- a/src/libs/antares/InfoCollection/StudyInfoCollector.cpp +++ b/src/libs/antares/InfoCollection/StudyInfoCollector.cpp @@ -59,13 +59,9 @@ void StudyInfoCollector::enabledThermalClustersCountToFileContent(FileContent& f for (auto i = study_.areas.begin(); i != end; ++i) { Area& area = *(i->second); - auto end = area.thermal.list.end(); - for (auto i = area.thermal.list.begin(); i != end; ++i) - { - auto& cluster = i->second; + for (const auto& cluster : area.thermal.list) if (cluster->enabled) nbEnabledThermalClusters++; - } } // Adding an item related to number of enabled thermal clusters to the file content @@ -152,4 +148,4 @@ void SimulationInfoCollector::toFileContent(FileContent& file_content) "optimization problem", "non-zero coefficients", opt_info_.nbNonZeroCoeffs); } -} \ No newline at end of file +} diff --git a/src/solver/variable/economy/avail-dispatchable-generation.h b/src/solver/variable/economy/avail-dispatchable-generation.h index 80e3356055..3867d7daba 100644 --- a/src/solver/variable/economy/avail-dispatchable-generation.h +++ b/src/solver/variable/economy/avail-dispatchable-generation.h @@ -194,7 +194,7 @@ class AvailableDispatchGen void addThermalClusterList(Data::ThermalClusterList& list, unsigned int year, unsigned int numSpace) { - for (auto& [name, cluster] : list) + for (auto& cluster : list) { const auto& availableProduction = cluster->series.getColumn(year); for (unsigned int hour = 0; hour != cluster->series.timeSeries.height; ++hour) diff --git a/src/solver/variable/economy/productionByRenewablePlant.h b/src/solver/variable/economy/productionByRenewablePlant.h index 26e0cbc0b6..504ebb92c1 100644 --- a/src/solver/variable/economy/productionByRenewablePlant.h +++ b/src/solver/variable/economy/productionByRenewablePlant.h @@ -277,7 +277,7 @@ class ProductionByRenewablePlant : public Variable::IVariablerenewable.list) + for (const auto& renewableCluster : state.area->renewable.list) { double renewableClusterProduction = renewableCluster->valueAtTimeStep(state.year, state.hourInTheYear); diff --git a/src/solver/variable/economy/renewableGeneration.h b/src/solver/variable/economy/renewableGeneration.h index 5634338ec8..5035cb59f4 100644 --- a/src/solver/variable/economy/renewableGeneration.h +++ b/src/solver/variable/economy/renewableGeneration.h @@ -267,7 +267,7 @@ class RenewableGeneration void hourForEachArea(State& state, unsigned int numSpace) { - for (const auto& [name, renewableCluster] : state.area->renewable.list) + for (const auto& renewableCluster : state.area->renewable.list) { double renewableClusterProduction = renewableCluster->valueAtTimeStep(state.year, state.hourInTheYear); diff --git a/src/ui/action/handler/antares-study/area/create.cpp b/src/ui/action/handler/antares-study/area/create.cpp index 0348c2d253..7b25151182 100644 --- a/src/ui/action/handler/antares-study/area/create.cpp +++ b/src/ui/action/handler/antares-study/area/create.cpp @@ -296,7 +296,7 @@ void Create::createActionsForAStandardAreaCopy(Context& ctx, bool copyPosition) auto end = area->thermal.list.end(); for (auto i = area->thermal.list.begin(); i != end; ++i) { - *root += StandardActionsToCopyThermalCluster(pOriginalAreaName, i->second->name()); + *root += StandardActionsToCopyThermalCluster(pOriginalAreaName, (*i)->name()); } *this += root; } From d84cc5939875c04ce637b7abbb30b38273eb649f Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Fri, 8 Dec 2023 16:01:01 +0100 Subject: [PATCH 11/54] [FIX] timeseries-numbers.cpp --- src/solver/simulation/timeseries-numbers.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/solver/simulation/timeseries-numbers.cpp b/src/solver/simulation/timeseries-numbers.cpp index 82fb8a3273..c387654bd1 100644 --- a/src/solver/simulation/timeseries-numbers.cpp +++ b/src/solver/simulation/timeseries-numbers.cpp @@ -100,7 +100,7 @@ static bool GenerateDeratedMode(Study& study) cluster.series.timeseriesNumbers.zero(); } - for (const auto& [name, cluster] : area.renewable.list) + for (const auto& cluster : area.renewable.list) cluster->series.timeseriesNumbers.zero(); }); @@ -226,7 +226,7 @@ class renewClustersAreaNumberOfTSretriever : public areaNumberOfTSretriever std::vector getAreaTimeSeriesNumber(const Area& area) { std::vector to_return; - for (const auto& [name, cluster] : area.renewable.list) + for (const auto& cluster : area.renewable.list) { to_return.push_back(cluster->series.timeSeries.width); } @@ -443,7 +443,7 @@ bool checkInterModalConsistencyForArea(Area& area, indexTS = ts_to_tsIndex.at(timeSeriesRenewable); if (isTSintermodal[indexTS]) { - for (const auto& [name, cluster] : area.renewable.list) + for (const auto& cluster : area.renewable.list) { uint nbTimeSeries = cluster->series.timeSeries.width; listNumberTsOverArea.push_back(nbTimeSeries); @@ -558,7 +558,7 @@ void storeTSnumbersForIntraModal(const array& intramo auto end_rn_clusters = area.renewable.list.cluster.end(); for (auto j = area.renewable.list.cluster.begin(); j != end_rn_clusters; ++j) { - RenewableClusterList::SharedPtr cluster = j->second; + RenewableClusterList::SharedPtr cluster = *j; if (cluster->enabled) cluster->series.timeseriesNumbers[0][year] = intramodal_draws[indexTS]; } @@ -670,7 +670,7 @@ void drawAndStoreTSnumbersForNOTintraModal(const array& i auto end_rn_clusters = area.renewable.list.cluster.end(); for (auto j = area.renewable.list.cluster.begin(); j != end_rn_clusters; ++j) { - RenewableClusterList::SharedPtr cluster = j->second; + RenewableClusterList::SharedPtr cluster = *j; if (not cluster->enabled) study.runtime->random[seedTimeseriesNumbers].next(); else @@ -792,7 +792,7 @@ void applyMatrixDrawsToInterModalModesInArea(Matrix* tsNumbersMtx, } if (isTSintermodal[ts_to_tsIndex.at(timeSeriesRenewable)]) { - for (auto& [name, cluster] : area.renewable.list) + for (auto& cluster : area.renewable.list) { assert(year < cluster->series.timeseriesNumbers.height); cluster->series.timeseriesNumbers[0][year] = draw; @@ -841,7 +841,7 @@ static void fixTSNumbersWhenWidthIsOne(Study& study) }); // Renewables - for (const auto& [name, cluster] : area.renewable.list) + for (const auto& cluster : area.renewable.list) fixTSNumbersSingleAreaSingleMode(cluster->series.timeseriesNumbers, cluster->series.timeSeries.width, years); From 35fda32da4e82fa1ad91b98400b1cf3e10c26bc8 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Fri, 8 Dec 2023 16:06:14 +0100 Subject: [PATCH 12/54] [FIX] common eco adq --- src/solver/simulation/common-eco-adq.cpp | 37 ++++++++++-------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/src/solver/simulation/common-eco-adq.cpp b/src/solver/simulation/common-eco-adq.cpp index c550b05610..d06335e094 100644 --- a/src/solver/simulation/common-eco-adq.cpp +++ b/src/solver/simulation/common-eco-adq.cpp @@ -132,40 +132,33 @@ void PrepareDataFromClustersInMustrunMode(Data::Study& study, uint numSpace, uin double* mrs = scratchpad.mustrunSum; double* adq = scratchpad.originalMustrunSum; - if (!area.thermal.mustrunList.empty()) + for (const auto& cluster : area.thermal.mustrunList) { - auto end = area.thermal.mustrunList.end(); - for (auto i = area.thermal.mustrunList.begin(); i != end; ++i) + const auto& availableProduction = cluster->series.getColumn(year); + if (inAdequacy && cluster->mustrunOrigin) { - auto& cluster = *(i->second); - const auto& availableProduction = cluster.series.getColumn(year); - if (inAdequacy && cluster.mustrunOrigin) + for (uint h = 0; h != cluster->series.timeSeries.height; ++h) { - for (uint h = 0; h != cluster.series.timeSeries.height; ++h) - { - mrs[h] += availableProduction[h]; - adq[h] += availableProduction[h]; - } - } - else - { - for (uint h = 0; h != cluster.series.timeSeries.height; ++h) - mrs[h] += availableProduction[h]; + mrs[h] += availableProduction[h]; + adq[h] += availableProduction[h]; } } + else + { + for (uint h = 0; h != cluster->series.timeSeries.height; ++h) + mrs[h] += availableProduction[h]; + } } if (inAdequacy) { - auto end = area.thermal.list.end(); - for (auto i = area.thermal.list.begin(); i != end; ++i) + for (const auto& cluster : area.thermal.mustrunList) { - auto& cluster = *(i->second); - if (!cluster.mustrunOrigin) + if (!cluster->mustrunOrigin) continue; - const auto& availableProduction = cluster.series.getColumn(year); - for (uint h = 0; h != cluster.series.timeSeries.height; ++h) + const auto& availableProduction = cluster->series.getColumn(year); + for (uint h = 0; h != cluster->series.timeSeries.height; ++h) adq[h] += availableProduction[h]; } } From 1adcf49e7f615d291b5619e01ca27cd72b3f8229 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Fri, 8 Dec 2023 16:25:22 +0100 Subject: [PATCH 13/54] [FIX] ui compile --- .../htmllistbox/datasource/renewable-cluster-order.cpp | 2 +- .../htmllistbox/datasource/thermal-cluster-order.cpp | 2 +- src/ui/simulator/toolbox/components/map/manager.cpp | 2 +- src/ui/simulator/windows/inspector/frame.cpp | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ui/simulator/toolbox/components/htmllistbox/datasource/renewable-cluster-order.cpp b/src/ui/simulator/toolbox/components/htmllistbox/datasource/renewable-cluster-order.cpp index a79334cc6c..66681a7383 100644 --- a/src/ui/simulator/toolbox/components/htmllistbox/datasource/renewable-cluster-order.cpp +++ b/src/ui/simulator/toolbox/components/htmllistbox/datasource/renewable-cluster-order.cpp @@ -56,7 +56,7 @@ void GetRenewableClusterMap(Data::Area* area, RenewableClusterMap& l, const wxSt const Data::RenewableClusterList::iterator end = area->renewable.list.end(); for (Data::RenewableClusterList::iterator i = area->renewable.list.begin(); i != end; ++i) { - Data::RenewableCluster* cluster = i->second.get(); + Data::RenewableCluster* cluster = (*i).get(); if (search.empty()) { diff --git a/src/ui/simulator/toolbox/components/htmllistbox/datasource/thermal-cluster-order.cpp b/src/ui/simulator/toolbox/components/htmllistbox/datasource/thermal-cluster-order.cpp index 029c0b8a2f..cd8a2a8244 100644 --- a/src/ui/simulator/toolbox/components/htmllistbox/datasource/thermal-cluster-order.cpp +++ b/src/ui/simulator/toolbox/components/htmllistbox/datasource/thermal-cluster-order.cpp @@ -56,7 +56,7 @@ void GetThermalClusterMap(Data::Area* area, ThermalClusterMap& l, const wxString const Data::ThermalClusterList::iterator end = area->thermal.list.end(); for (Data::ThermalClusterList::iterator i = area->thermal.list.begin(); i != end; ++i) { - Data::ThermalCluster* cluster = i->second.get(); + Data::ThermalCluster* cluster = (*i).get(); if (search.empty()) { diff --git a/src/ui/simulator/toolbox/components/map/manager.cpp b/src/ui/simulator/toolbox/components/map/manager.cpp index 7193fbef99..d6030be21c 100644 --- a/src/ui/simulator/toolbox/components/map/manager.cpp +++ b/src/ui/simulator/toolbox/components/map/manager.cpp @@ -768,7 +768,7 @@ void Manager::selectFromBoundingBox(const wxPoint& a, const wxPoint& b, const si for (Data::ThermalClusterList::iterator t = area->thermal.list.begin(); t != tend; ++t) - clusterlist.push_back(t->second.get()); + clusterlist.push_back((*t).get()); } continue; } diff --git a/src/ui/simulator/windows/inspector/frame.cpp b/src/ui/simulator/windows/inspector/frame.cpp index 22b9ad28c9..1243ae9076 100644 --- a/src/ui/simulator/windows/inspector/frame.cpp +++ b/src/ui/simulator/windows/inspector/frame.cpp @@ -180,7 +180,7 @@ void Frame::onSelectAllPlants(wxCommandEvent&) Data::Area& area = *(*i); auto end = area.thermal.list.end(); for (auto i = area.thermal.list.begin(); i != end; ++i) - data->ThClusters.insert(i->second.get()); + data->ThClusters.insert((*i).get()); } data->areas.clear(); data->links.clear(); @@ -216,7 +216,7 @@ void Frame::onSelectAllPlantsFromArea(wxCommandEvent& evt) data->ThClusters.clear(); auto end = area->thermal.list.end(); for (auto i = area->thermal.list.begin(); i != end; ++i) - data->ThClusters.insert(i->second.get()); + data->ThClusters.insert((*i).get()); data->areas.clear(); data->links.clear(); data->empty = data->ThClusters.empty(); From 039ddbfd44c892481a8255f088feec89d96228b4 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Fri, 8 Dec 2023 16:26:53 +0100 Subject: [PATCH 14/54] [FIX] final compile --- src/solver/optimisation/post_process_commands.cpp | 8 +++----- src/solver/variable/surveyresults/reportbuilder.hxx | 6 ++---- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/solver/optimisation/post_process_commands.cpp b/src/solver/optimisation/post_process_commands.cpp index 9c6c3f5d9d..c82892355a 100644 --- a/src/solver/optimisation/post_process_commands.cpp +++ b/src/solver/optimisation/post_process_commands.cpp @@ -31,15 +31,13 @@ void DispatchableMarginPostProcessCmd::execute(const optRuntimeData& opt_runtime { auto& hourlyResults = problemeHebdo_->ResultatsHoraires[area.index]; - auto end = area.thermal.list.end(); - for (auto i = area.thermal.list.begin(); i != end; ++i) + for (const auto& cluster : area.thermal.list) { - auto& cluster = *(i->second); - const auto& availableProduction = cluster.series.getColumn(year); + const auto& availableProduction = cluster->series.getColumn(year); for (uint h = 0; h != nbHoursInWeek; ++h) { double production = hourlyResults.ProductionThermique[h] - .ProductionThermiqueDuPalier[cluster.index]; + .ProductionThermiqueDuPalier[cluster->index]; dtgmrg[h] += availableProduction[h + hourInYear] - production; } } diff --git a/src/solver/variable/surveyresults/reportbuilder.hxx b/src/solver/variable/surveyresults/reportbuilder.hxx index da3b4bdf86..28e9ef6abe 100644 --- a/src/solver/variable/surveyresults/reportbuilder.hxx +++ b/src/solver/variable/surveyresults/reportbuilder.hxx @@ -324,11 +324,9 @@ private: if (VariablesStatsByDataLevel::count) { auto& area = *results.data.area; - auto end = area.thermal.list.end(); - for (auto i = area.thermal.list.begin(); i != end; ++i) + for (const auto& cluster : area.thermal.list) { - auto& cluster = *i; - results.data.thermalCluster = &cluster; + results.data.thermalCluster = cluster.get(); logs.info() << "Exporting results : " << area.name << " :: " << cluster->name(); // The new output From dd22673b1768e29f8749ff3f943a85a3c6fde044 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Fri, 8 Dec 2023 17:18:17 +0100 Subject: [PATCH 15/54] [DEV] Sort cluster --- src/libs/antares/study/parts/common/cluster_list.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index 8fa90e651f..8cfe99b344 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -115,8 +115,7 @@ template void ClusterList::clear() { byIndex.clear(); - if (not cluster.empty()) - cluster.clear(); + cluster.clear(); } template @@ -192,7 +191,9 @@ template void ClusterList::rebuildIndex() { byIndex.clear(); - + std::sort(cluster.begin(), cluster.end(), [&](const auto& a, const auto& b){ + return a->id() < b->id(); + }); if (not empty()) { uint indx = 0; From d46d03431001c5a0b943300d569677565b84394b Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Fri, 8 Dec 2023 17:37:14 +0100 Subject: [PATCH 16/54] [DEV] removed byIndex --- .../antares/study/parts/common/cluster_list.cpp | 16 ++++------------ .../antares/study/parts/common/cluster_list.h | 2 -- .../scenario-builder/RenewableTSNumberData.cpp | 4 ++-- .../scenario-builder/ThermalTSNumberData.cpp | 4 ++-- src/libs/antares/study/study.cpp | 2 +- src/solver/simulation/sim_calcul_economique.cpp | 2 +- src/solver/simulation/timeseries-numbers.cpp | 2 +- .../economy/productionByRenewablePlant.h | 2 +- src/solver/variable/info.h | 2 +- .../renderer/area/renewable.areasummary.cpp | 8 ++++---- .../renderer/area/thermal.areasummary.cpp | 8 ++++---- .../scenario-builder-renewable-renderer.cpp | 4 ++-- .../scenario-builder-thermal-renderer.cpp | 4 ++-- 13 files changed, 25 insertions(+), 35 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index 8cfe99b344..1d589b683b 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -114,7 +114,6 @@ Data::ClusterList::~ClusterList() template void ClusterList::clear() { - byIndex.clear(); cluster.clear(); } @@ -190,20 +189,13 @@ void ClusterList::storeTimeseriesNumbers(Solver::IResultWriter& writer template void ClusterList::rebuildIndex() { - byIndex.clear(); std::sort(cluster.begin(), cluster.end(), [&](const auto& a, const auto& b){ return a->id() < b->id(); }); - if (not empty()) - { - uint indx = 0; - byIndex.resize(size()); - for (auto& c : cluster) - { - byIndex[indx] = c.get(); - c->index = indx++; - } - } + + uint indx = 0; + for (auto& c : cluster) + c->index = indx++; } diff --git a/src/libs/antares/study/parts/common/cluster_list.h b/src/libs/antares/study/parts/common/cluster_list.h index ee63edcac1..5285551ff4 100644 --- a/src/libs/antares/study/parts/common/cluster_list.h +++ b/src/libs/antares/study/parts/common/cluster_list.h @@ -215,8 +215,6 @@ class ClusterList uint64_t memoryUsage() const; public: - //! All clusters by their index - std::vector byIndex; //! All clusters Vect cluster; diff --git a/src/libs/antares/study/scenario-builder/RenewableTSNumberData.cpp b/src/libs/antares/study/scenario-builder/RenewableTSNumberData.cpp index 725729f5c9..d004de7587 100644 --- a/src/libs/antares/study/scenario-builder/RenewableTSNumberData.cpp +++ b/src/libs/antares/study/scenario-builder/RenewableTSNumberData.cpp @@ -79,12 +79,12 @@ void renewableTSNumberData::saveToINIFile(const Study& /* study */, // Foreach renewable cluster... for (uint y = 0; y != pTSNumberRules.height; ++y) { - const uint val = get(pArea->renewable.list.byIndex[index], y); + const uint val = get(pArea->renewable.list.cluster[index].get(), y); // Equals to zero means 'auto', which is the default mode if (!val) continue; file << prefix << pArea->id << "," << y << ',' - << pArea->renewable.list.byIndex[index]->id() << " = " << val << '\n'; + << pArea->renewable.list.cluster[index]->id() << " = " << val << '\n'; } } } diff --git a/src/libs/antares/study/scenario-builder/ThermalTSNumberData.cpp b/src/libs/antares/study/scenario-builder/ThermalTSNumberData.cpp index d9fd64b378..398ae219c9 100644 --- a/src/libs/antares/study/scenario-builder/ThermalTSNumberData.cpp +++ b/src/libs/antares/study/scenario-builder/ThermalTSNumberData.cpp @@ -49,12 +49,12 @@ void thermalTSNumberData::saveToINIFile(const Study& /* study */, // Foreach year ... for (uint y = 0; y != pTSNumberRules.height; ++y) { - const uint val = get(pArea->thermal.list.byIndex[index], y); + const uint val = get(pArea->thermal.list.cluster[index].get(), y); // Equals to zero means 'auto', which is the default mode if (!val) continue; file << prefix << pArea->id << "," << y << ',' - << pArea->thermal.list.byIndex[index]->id() << " = " << val << '\n'; + << pArea->thermal.list.cluster[index]->id() << " = " << val << '\n'; } } } diff --git a/src/libs/antares/study/study.cpp b/src/libs/antares/study/study.cpp index 18c272c12a..f8567c349a 100644 --- a/src/libs/antares/study/study.cpp +++ b/src/libs/antares/study/study.cpp @@ -1530,7 +1530,7 @@ void Study::computePThetaInfForThermalClusters() const for (uint j = 0; j < area.thermal.list.size(); j++) { // Alias du cluster courant - auto& cluster = area.thermal.list.byIndex[j]; + auto& cluster = area.thermal.list.cluster[j]; for (uint k = 0; k < HOURS_PER_YEAR; k++) cluster->PthetaInf[k] = cluster->modulation[Data::thermalMinGenModulation][k] * cluster->unitCount * cluster->nominalCapacity; diff --git a/src/solver/simulation/sim_calcul_economique.cpp b/src/solver/simulation/sim_calcul_economique.cpp index 201f6b9899..3982adce6d 100644 --- a/src/solver/simulation/sim_calcul_economique.cpp +++ b/src/solver/simulation/sim_calcul_economique.cpp @@ -285,7 +285,7 @@ void SIM_InitialisationProblemeHebdo(Data::Study& study, for (uint clusterIndex = 0; clusterIndex != area.thermal.list.size(); ++clusterIndex) { - auto& cluster = *(area.thermal.list.byIndex[clusterIndex]); + auto& cluster = *(area.thermal.list.cluster[clusterIndex]); pbPalier.NumeroDuPalierDansLEnsembleDesPaliersThermiques[clusterIndex] = NombrePaliers + clusterIndex; pbPalier.TailleUnitaireDUnGroupeDuPalierThermique[clusterIndex] diff --git a/src/solver/simulation/timeseries-numbers.cpp b/src/solver/simulation/timeseries-numbers.cpp index c387654bd1..606493f95f 100644 --- a/src/solver/simulation/timeseries-numbers.cpp +++ b/src/solver/simulation/timeseries-numbers.cpp @@ -747,7 +747,7 @@ Matrix* getFirstTSnumberInterModalMatrixFoundInArea( tsNumbersMtx = &(area.thermal.clusters[0]->series.timeseriesNumbers); else if (isTSintermodal[ts_to_tsIndex.at(timeSeriesRenewable)] && area.renewable.list.size() > 0) - tsNumbersMtx = &(area.renewable.list.byIndex[0]->series.timeseriesNumbers); + tsNumbersMtx = &(area.renewable.list.cluster[0]->series.timeseriesNumbers); } assert(tsNumbersMtx); diff --git a/src/solver/variable/economy/productionByRenewablePlant.h b/src/solver/variable/economy/productionByRenewablePlant.h index 504ebb92c1..76ece69c79 100644 --- a/src/solver/variable/economy/productionByRenewablePlant.h +++ b/src/solver/variable/economy/productionByRenewablePlant.h @@ -327,7 +327,7 @@ class ProductionByRenewablePlant : public Variable::IVariablename(); + results.variableCaption = renewable.list.cluster[i]->name(); results.variableUnit = VCardType::Unit(); pValuesForTheCurrentYear[numSpace][i].template buildAnnualSurveyReport( results, fileLevel, precision); diff --git a/src/solver/variable/info.h b/src/solver/variable/info.h index 088b4ddf7f..2a62d64174 100644 --- a/src/solver/variable/info.h +++ b/src/solver/variable/info.h @@ -407,7 +407,7 @@ struct VariableAccessor if (renewable_details) { auto& renewable = results.data.area->renewable; - results.variableCaption = renewable.list.byIndex[idx]->name(); + results.variableCaption = renewable.list.cluster[idx]->name(); return true; } if (st_storage_details) diff --git a/src/ui/simulator/toolbox/components/datagrid/renderer/area/renewable.areasummary.cpp b/src/ui/simulator/toolbox/components/datagrid/renderer/area/renewable.areasummary.cpp index 59ff293c0c..952383759a 100644 --- a/src/ui/simulator/toolbox/components/datagrid/renderer/area/renewable.areasummary.cpp +++ b/src/ui/simulator/toolbox/components/datagrid/renderer/area/renewable.areasummary.cpp @@ -51,7 +51,7 @@ RenewableClusterSummarySingleArea::~RenewableClusterSummarySingleArea() wxString RenewableClusterSummarySingleArea::rowCaption(int rowIndx) const { if (pArea) - return wxStringFromUTF8(pArea->renewable.list.byIndex[rowIndx]->name()); + return wxStringFromUTF8(pArea->renewable.list.cluster[rowIndx]->name()); return wxEmptyString; } @@ -71,7 +71,7 @@ wxString RenewableClusterSummarySingleArea::columnCaption(int colIndx) const wxString RenewableClusterSummarySingleArea::cellValue(int x, int y) const { Data::RenewableCluster* cluster = (pArea and (uint) y < pArea->renewable.list.size()) - ? pArea->renewable.list.byIndex[y] + ? pArea->renewable.list.cluster[y].get() : nullptr; switch (x) { @@ -90,7 +90,7 @@ wxString RenewableClusterSummarySingleArea::cellValue(int x, int y) const double RenewableClusterSummarySingleArea::cellNumericValue(int x, int y) const { Data::RenewableCluster* cluster = (pArea and (uint) y < pArea->renewable.list.size()) - ? pArea->renewable.list.byIndex[y] + ? pArea->renewable.list.cluster[y].get() : nullptr; // gp : do we wish to have the line empty if cluster disabled // if (!cluster->enabled) @@ -112,7 +112,7 @@ double RenewableClusterSummarySingleArea::cellNumericValue(int x, int y) const bool RenewableClusterSummarySingleArea::cellValue(int x, int y, const String& v) { auto* cluster = (pArea and (uint) y < pArea->renewable.list.size()) - ? pArea->renewable.list.byIndex[y] + ? pArea->renewable.list.cluster[y].get() : nullptr; if (cluster) diff --git a/src/ui/simulator/toolbox/components/datagrid/renderer/area/thermal.areasummary.cpp b/src/ui/simulator/toolbox/components/datagrid/renderer/area/thermal.areasummary.cpp index c49cf595a0..a5ba590171 100644 --- a/src/ui/simulator/toolbox/components/datagrid/renderer/area/thermal.areasummary.cpp +++ b/src/ui/simulator/toolbox/components/datagrid/renderer/area/thermal.areasummary.cpp @@ -51,7 +51,7 @@ ThermalClusterSummarySingleArea::~ThermalClusterSummarySingleArea() wxString ThermalClusterSummarySingleArea::rowCaption(int rowIndx) const { if (pArea) - return wxStringFromUTF8(pArea->thermal.list.byIndex[rowIndx]->name()); + return wxStringFromUTF8(pArea->thermal.list.cluster[rowIndx]->name()); return wxEmptyString; } @@ -82,7 +82,7 @@ wxString ThermalClusterSummarySingleArea::columnCaption(int colIndx) const wxString ThermalClusterSummarySingleArea::cellValue(int x, int y) const { Data::ThermalCluster* cluster = (pArea and (uint) y < pArea->thermal.list.size()) - ? pArea->thermal.list.byIndex[y] + ? pArea->thermal.list.cluster[y].get() : nullptr; if (!cluster->enabled) return wxEmptyString; @@ -125,7 +125,7 @@ wxString ThermalClusterSummarySingleArea::cellValue(int x, int y) const double ThermalClusterSummarySingleArea::cellNumericValue(int x, int y) const { Data::ThermalCluster* cluster = (pArea and (uint) y < pArea->thermal.list.size()) - ? pArea->thermal.list.byIndex[y] + ? pArea->thermal.list.cluster[y].get() : nullptr; if (!cluster->enabled) return 0.; @@ -168,7 +168,7 @@ double ThermalClusterSummarySingleArea::cellNumericValue(int x, int y) const bool ThermalClusterSummarySingleArea::cellValue(int x, int y, const String& v) { auto* cluster = (pArea and (uint) y < pArea->thermal.list.size()) - ? pArea->thermal.list.byIndex[y] + ? pArea->thermal.list.cluster[y].get() : nullptr; if (cluster) diff --git a/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-renewable-renderer.cpp b/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-renewable-renderer.cpp index c522544756..95d8052f58 100644 --- a/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-renewable-renderer.cpp +++ b/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-renewable-renderer.cpp @@ -54,7 +54,7 @@ wxString renewableScBuilderRenderer::rowCaption(int rowIndx) const && (uint)rowIndx < selectedArea()->renewable.list.size()) { return wxString() << wxT( - " ") << wxStringFromUTF8(selectedArea()->renewable.list.byIndex[rowIndx]->name()) + " ") << wxStringFromUTF8(selectedArea()->renewable.list.cluster[rowIndx]->name()) << wxT(" "); } return wxEmptyString; @@ -70,7 +70,7 @@ bool renewableScBuilderRenderer::cellValue(int x, int y, const String& value) assert((uint)x < pRules->renewable[selectedArea()->index].height()); uint val = fromStringToTSnumber(value); pRules->renewable[selectedArea()->index].setTSnumber( - selectedArea()->renewable.list.byIndex[y], x, val); + selectedArea()->renewable.list.cluster[y].get(), x, val); return true; } return false; diff --git a/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-thermal-renderer.cpp b/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-thermal-renderer.cpp index 7449c3c9b0..59339154ce 100644 --- a/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-thermal-renderer.cpp +++ b/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-thermal-renderer.cpp @@ -54,7 +54,7 @@ wxString thermalScBuilderRenderer::rowCaption(int rowIndx) const && (uint)rowIndx < selectedArea()->thermal.list.size()) { return wxString() << wxT(" ") - << wxStringFromUTF8(selectedArea()->thermal.list.byIndex[rowIndx]->name()) + << wxStringFromUTF8(selectedArea()->thermal.list.cluster[rowIndx]->name()) << wxT(" "); } return wxEmptyString; @@ -69,7 +69,7 @@ bool thermalScBuilderRenderer::cellValue(int x, int y, const String& value) assert((uint)y < pRules->thermal[selectedArea()->index].width()); assert((uint)x < pRules->thermal[selectedArea()->index].height()); uint val = fromStringToTSnumber(value); - pRules->thermal[selectedArea()->index].setTSnumber(selectedArea()->thermal.list.byIndex[y], x, val); + pRules->thermal[selectedArea()->index].setTSnumber(selectedArea()->thermal.list.cluster[y].get(), x, val); return true; } return false; From a7c80100fa7b621da0f95b8b3d7652079fca2c0c Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Mon, 11 Dec 2023 10:23:51 +0100 Subject: [PATCH 17/54] [DEV] small fix on add function --- .../study/parts/common/cluster_list.cpp | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index 1d589b683b..a966db9cea 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -204,18 +204,16 @@ template typename ClusterList::SharedPtr ClusterList::add( const ClusterList::SharedPtr& newcluster) { - if (newcluster) - { - if (exists(newcluster->id())) - return this->find(newcluster); - - newcluster->index = (uint)size(); - cluster.push_back(newcluster); - ++(groupCount[newcluster->groupId()]); - rebuildIndex(); - return cluster.back(); - } - return nullptr; + if (!newcluster) + return nullptr; + + if (exists(newcluster->id())) + return this->find(newcluster); + + cluster.push_back(newcluster); + ++(groupCount[newcluster->groupId()]); + rebuildIndex(); + return newcluster; } template From 058a5b777dc17237dc1f599000f801348b8115ff Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Mon, 11 Dec 2023 10:35:52 +0100 Subject: [PATCH 18/54] [DEV] code smells --- src/libs/antares/study/parts/common/cluster_list.cpp | 8 +++----- src/libs/antares/study/parts/renewable/container.cpp | 2 +- src/libs/antares/study/parts/thermal/container.cpp | 3 ++- src/solver/simulation/timeseries-numbers.cpp | 2 +- .../variable/economy/avail-dispatchable-generation.h | 2 +- 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index a966db9cea..6ae8fbb739 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -92,11 +92,9 @@ void ClusterList::remove(iterator i) template bool ClusterList::exists(const Data::ClusterName& id) const { - for (const auto& c : cluster) - if (c->id() == id) - return true; - - return false; + return std::any_of(cluster.begin(), cluster.end(), [&id](const auto& c){ + return c->id() == id; + }); } template diff --git a/src/libs/antares/study/parts/renewable/container.cpp b/src/libs/antares/study/parts/renewable/container.cpp index 0f07904b1c..78ed90aa26 100644 --- a/src/libs/antares/study/parts/renewable/container.cpp +++ b/src/libs/antares/study/parts/renewable/container.cpp @@ -67,7 +67,7 @@ void PartRenewable::prepareAreaWideIndexes() } uint idx = 0; - for (auto& t : list) + for (const auto& t : list) { t->areaWideIndex = idx; ++idx; diff --git a/src/libs/antares/study/parts/thermal/container.cpp b/src/libs/antares/study/parts/thermal/container.cpp index 0d9b3fb66c..b5c6fe8e0d 100644 --- a/src/libs/antares/study/parts/thermal/container.cpp +++ b/src/libs/antares/study/parts/thermal/container.cpp @@ -79,7 +79,8 @@ void PartThermal::prepareAreaWideIndexes() for (const auto& cluster : list) { cluster->areaWideIndex = idx; - clusters[idx++] = cluster.get(); + clusters[idx] = cluster.get(); + ++idx; } } diff --git a/src/solver/simulation/timeseries-numbers.cpp b/src/solver/simulation/timeseries-numbers.cpp index 606493f95f..cedd56abca 100644 --- a/src/solver/simulation/timeseries-numbers.cpp +++ b/src/solver/simulation/timeseries-numbers.cpp @@ -792,7 +792,7 @@ void applyMatrixDrawsToInterModalModesInArea(Matrix* tsNumbersMtx, } if (isTSintermodal[ts_to_tsIndex.at(timeSeriesRenewable)]) { - for (auto& cluster : area.renewable.list) + for (const auto& cluster : area.renewable.list) { assert(year < cluster->series.timeseriesNumbers.height); cluster->series.timeseriesNumbers[0][year] = draw; diff --git a/src/solver/variable/economy/avail-dispatchable-generation.h b/src/solver/variable/economy/avail-dispatchable-generation.h index 3867d7daba..9cea0fb713 100644 --- a/src/solver/variable/economy/avail-dispatchable-generation.h +++ b/src/solver/variable/economy/avail-dispatchable-generation.h @@ -194,7 +194,7 @@ class AvailableDispatchGen void addThermalClusterList(Data::ThermalClusterList& list, unsigned int year, unsigned int numSpace) { - for (auto& cluster : list) + for (const auto& cluster : list) { const auto& availableProduction = cluster->series.getColumn(year); for (unsigned int hour = 0; hour != cluster->series.timeSeries.height; ++hour) From 66053ae8b647cde71405f2a9ba1ca35bdfa71bee Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Wed, 13 Dec 2023 14:51:29 +0100 Subject: [PATCH 19/54] [DEV] comments 1 --- .../study/parts/common/cluster_list.cpp | 40 ++++++++----------- .../antares/study/parts/common/cluster_list.h | 16 ++------ .../study/parts/thermal/cluster_list.h | 3 ++ 3 files changed, 23 insertions(+), 36 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index 6ae8fbb739..7f9191e2f3 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -125,15 +125,6 @@ const ClusterT* ClusterList::find(const ClusterT* p) const return nullptr; } -template -ClusterT* ClusterList::find(const ClusterT* p) -{ - for (auto& c : cluster) - if (c.get() == p) - return c.get(); - - return nullptr; -} template typename ClusterList::SharedPtr ClusterList::find @@ -187,7 +178,7 @@ void ClusterList::storeTimeseriesNumbers(Solver::IResultWriter& writer template void ClusterList::rebuildIndex() { - std::sort(cluster.begin(), cluster.end(), [&](const auto& a, const auto& b){ + std::sort(cluster.begin(), cluster.end(), [](const auto& a, const auto& b){ return a->id() < b->id(); }); @@ -243,31 +234,31 @@ bool ClusterList::rename(Data::ClusterName idToFind, Data::ClusterName Antares::TransformNameIntoID(newName, newID); // Looking for the renewable cluster in the list - auto* p = this->find(idToFind); - if (!p) + auto* cluster_ptr = this->find(idToFind); + if (!cluster_ptr) return true; if (idToFind == newID) { - p->setName(newName); + cluster_ptr->setName(newName); return true; } // The name is the same. Aborting nicely. - if (p->name() == newName) + if (cluster_ptr->name() == newName) return true; // Already exist if (this->exists(newID)) return false; - p->setName(newName); + cluster_ptr->setName(newName); // Invalidate matrices attached to the area // It is a bit excessive (all matrices not only those related to the renewable cluster) // will be rewritten but currently it is the less error-prone. - if (p->parentArea) - (p->parentArea)->invalidateJIT = true; + if (cluster_ptr->parentArea) + (cluster_ptr->parentArea)->invalidateJIT = true; // Rebuilding the index rebuildIndex(); @@ -293,6 +284,7 @@ void ClusterList::markAsModified() const template bool ClusterList::remove(const Data::ClusterName& id) { + // using find_if to get an iterator and use erase later const auto& it = find_if(cluster.begin(), cluster.end(), [&id](const SharedPtr& c) { return c->id() == id; }); @@ -313,10 +305,10 @@ bool ClusterList::remove(const Data::ClusterName& id) } template -int ClusterList::saveDataSeriesToFolder(const AnyString& folder) const +bool ClusterList::saveDataSeriesToFolder(const AnyString& folder) const { if (empty()) - return false; + return true; bool ret = true; @@ -327,10 +319,10 @@ int ClusterList::saveDataSeriesToFolder(const AnyString& folder) const } template -int ClusterList::saveDataSeriesToFolder(const AnyString& folder, const String& msg) const +bool ClusterList::saveDataSeriesToFolder(const AnyString& folder, const String& msg) const { if (empty()) - return false; + return true; bool ret = true; uint ticks = 0; @@ -346,14 +338,14 @@ int ClusterList::saveDataSeriesToFolder(const AnyString& folder, const } template -int ClusterList::loadDataSeriesFromFolder(Study& s, +bool ClusterList::loadDataSeriesFromFolder(Study& s, const StudyLoadOptions& options, const AnyString& folder) { if (empty()) - return 1; + return true; - int ret = 1; + bool ret = true; each([&](ClusterT& c) { ret = c.loadDataSeriesFromFolder(s, folder) and ret; diff --git a/src/libs/antares/study/parts/common/cluster_list.h b/src/libs/antares/study/parts/common/cluster_list.h index 5285551ff4..36a9381502 100644 --- a/src/libs/antares/study/parts/common/cluster_list.h +++ b/src/libs/antares/study/parts/common/cluster_list.h @@ -24,8 +24,6 @@ class ClusterList public: // Shared pointer using SharedPtr = typename std::shared_ptr; - // Map container - using Map = typename std::map; // Vector container using Vect = typename std::vector; //! iterator @@ -118,13 +116,7 @@ class ClusterList const ClusterT* find(const Data::ClusterName& id) const; SharedPtr find(const ClusterList::SharedPtr& p); - /*! - ** \brief Try to find a cluster from its pointer - ** - ** \param p Pointer of the cluster to find - ** \return A pointer to a cluster. nullptr if not found - */ - ClusterT* find(const ClusterT* p); + /*! ** \brief Try to find a cluster from its pointer (const) ** @@ -230,13 +222,13 @@ class ClusterList */ std::vector groupCount; - int loadDataSeriesFromFolder(Study& study, + bool loadDataSeriesFromFolder(Study& study, const StudyLoadOptions& options, const AnyString& folder); - int saveDataSeriesToFolder(const AnyString& folder) const; + bool saveDataSeriesToFolder(const AnyString& folder) const; - int saveDataSeriesToFolder(const AnyString& folder, const YString& msg) const; + bool saveDataSeriesToFolder(const AnyString& folder, const YString& msg) const; virtual bool saveToFolder(const AnyString& folder) const = 0; diff --git a/src/libs/antares/study/parts/thermal/cluster_list.h b/src/libs/antares/study/parts/thermal/cluster_list.h index 6a2d1e0a7c..25d13b2088 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.h +++ b/src/libs/antares/study/parts/thermal/cluster_list.h @@ -13,6 +13,9 @@ namespace Data class ThermalClusterList : public ClusterList { public: + // Map container + using Map = typename std::map>; + // Overriden pure virtual methods YString typeID() const override; From 02498036cacba2b74c9d19d13783cc2119b76195 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Wed, 13 Dec 2023 15:48:14 +0100 Subject: [PATCH 20/54] [DEV] change return type to bool --- .../antares/study/parts/common/cluster.cpp | 56 +++++++++---------- src/libs/antares/study/parts/common/cluster.h | 4 +- 2 files changed, 29 insertions(+), 31 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster.cpp b/src/libs/antares/study/parts/common/cluster.cpp index 64e925f8a5..79d119d476 100644 --- a/src/libs/antares/study/parts/common/cluster.cpp +++ b/src/libs/antares/study/parts/common/cluster.cpp @@ -49,45 +49,43 @@ void Cluster::setName(const AnyString& newname) } #define SEP Yuni::IO::Separator -int Cluster::saveDataSeriesToFolder(const AnyString& folder) const +bool Cluster::saveDataSeriesToFolder(const AnyString& folder) const { - if (not folder.empty()) + if (folder.empty()) + return true; + + Yuni::Clob buffer; + + buffer.clear() << folder << SEP << parentArea->id << SEP << id(); + if (Yuni::IO::Directory::Create(buffer)) { - Yuni::Clob buffer; - - buffer.clear() << folder << SEP << parentArea->id << SEP << id(); - if (Yuni::IO::Directory::Create(buffer)) - { - int ret = 1; - buffer.clear() << folder << SEP << parentArea->id << SEP << id() << SEP << "series.txt"; - ret = series.timeSeries.saveToCSVFile(buffer, precision()) && ret; - - return ret; - } - return 0; + bool ret = true; + buffer.clear() << folder << SEP << parentArea->id << SEP << id() << SEP << "series.txt"; + ret = series.timeSeries.saveToCSVFile(buffer, precision()) && ret; + + return ret; } - return 1; + return false; } -int Cluster::loadDataSeriesFromFolder(Study& s, const AnyString& folder) +bool Cluster::loadDataSeriesFromFolder(Study& s, const AnyString& folder) { - if (not folder.empty()) - { - auto& buffer = s.bufferLoadingTS; + if (folder.empty()) + return true; - int ret = 1; - buffer.clear() << folder << SEP << parentArea->id << SEP << id() << SEP << "series." - << s.inputExtension; - ret = series.timeSeries.loadFromCSVFile(buffer, 1, HOURS_PER_YEAR, &s.dataBuffer) && ret; + auto& buffer = s.bufferLoadingTS; - if (s.usedByTheSolver && s.parameters.derated) - series.timeSeries.averageTimeseries(); + bool ret = 1; + buffer.clear() << folder << SEP << parentArea->id << SEP << id() << SEP << "series." + << s.inputExtension; + ret = series.timeSeries.loadFromCSVFile(buffer, 1, HOURS_PER_YEAR, &s.dataBuffer) && ret; - series.timeseriesNumbers.clear(); + if (s.usedByTheSolver && s.parameters.derated) + series.timeSeries.averageTimeseries(); - return ret; - } - return 1; + series.timeseriesNumbers.clear(); + + return ret; } #undef SEP diff --git a/src/libs/antares/study/parts/common/cluster.h b/src/libs/antares/study/parts/common/cluster.h index eee596ede1..d552eb54b8 100644 --- a/src/libs/antares/study/parts/common/cluster.h +++ b/src/libs/antares/study/parts/common/cluster.h @@ -142,8 +142,8 @@ class Cluster //! Set of clusters using Set = std::set; - int saveDataSeriesToFolder(const AnyString& folder) const; - int loadDataSeriesFromFolder(Study& s, const AnyString& folder); + bool saveDataSeriesToFolder(const AnyString& folder) const; + bool loadDataSeriesFromFolder(Study& s, const AnyString& folder); private: virtual unsigned int precision() const = 0; From 61fb46708cb3df52c6c3c4e98d8080ad1d49401d Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Wed, 13 Dec 2023 15:57:56 +0100 Subject: [PATCH 21/54] [DEV] use std::all_of --- .../study/parts/common/cluster_list.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index 7f9191e2f3..0c8e82d070 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -1,4 +1,5 @@ #include +#include #include "cluster_list.h" #include #include "../../study.h" @@ -268,10 +269,10 @@ bool ClusterList::rename(Data::ClusterName idToFind, Data::ClusterName template bool ClusterList::forceReload(bool reload) const { - bool ret = true; - for (const auto& c : cluster) - ret = c->forceReload(reload) && ret; - return ret; + return std::all_of(cluster.begin(), cluster.end(), [&reload](const auto& c){ + return c->forceReload(reload); + }); + } template @@ -310,12 +311,9 @@ bool ClusterList::saveDataSeriesToFolder(const AnyString& folder) cons if (empty()) return true; - bool ret = true; - - for (const auto& c : cluster) - ret = c->saveDataSeriesToFolder(folder) && ret; - - return ret; + return std::all_of(cluster.begin(), cluster.end(), [&folder](const auto& c){ + return c->saveDataSeriesToFolder(folder); + }); } template From 758b349371000908b33f6542579cb9e7aec52034 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Wed, 13 Dec 2023 16:23:45 +0100 Subject: [PATCH 22/54] [DEV] comments in renewables --- .../study/parts/renewable/container.cpp | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/src/libs/antares/study/parts/renewable/container.cpp b/src/libs/antares/study/parts/renewable/container.cpp index 78ed90aa26..4e15d211ba 100644 --- a/src/libs/antares/study/parts/renewable/container.cpp +++ b/src/libs/antares/study/parts/renewable/container.cpp @@ -67,9 +67,9 @@ void PartRenewable::prepareAreaWideIndexes() } uint idx = 0; - for (const auto& t : list) + for (const auto& cluster : list) { - t->areaWideIndex = idx; + cluster->areaWideIndex = idx; ++idx; } } @@ -80,22 +80,15 @@ uint PartRenewable::removeDisabledClusters() if (list.empty()) return 0; - std::vector disabledClusters; + auto firstClusterToRemove = std::remove_if(list.begin(), list.end(), [] (auto& cluster) { + return !cluster->enabled; + }); - for (auto& it : list) - { - if (!it->enabled) - disabledClusters.push_back(it->id()); - } - - for (auto& cluster : disabledClusters) - list.remove(cluster); + list.cluster.erase(firstClusterToRemove , list.end()); // Actually remove the disabled clusters - const auto count = disabledClusters.size(); - if (count) - list.rebuildIndex(); + list.rebuildIndex(); - return count; + return list.size(); } void PartRenewable::reset() From ea38e89a7a774ac90bc8102000664de4eb16457a Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Wed, 13 Dec 2023 16:32:03 +0100 Subject: [PATCH 23/54] [DEV] comments 2 --- .../study/parts/thermal/cluster_list.cpp | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index e67891b80e..99389a79ce 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -364,7 +364,7 @@ bool ThermalClusterList::saveToFolder(const AnyString& folder) const // costs if (c.costgeneration != setManually) - s->add("costgeneration", c.costgeneration); + s->add("costgeneration", c.costgeneration); if (not Math::Zero(c.marginalCost)) s->add("marginal-cost", Math::Round(c.marginalCost, 3)); if (not Math::Zero(c.spreadCost)) @@ -462,7 +462,7 @@ bool ThermalClusterList::loadPreproFromFolder(Study& study, { if (c->prepro) { - assert(c->parentArea and "cluster: invalid parent area"); + assert(c->parentArea && "cluster: invalid parent area"); buffer.clear() << folder << SEP << c->parentArea->id << SEP << c->id(); bool result = c->prepro->loadFromFolder(study, buffer); @@ -473,9 +473,9 @@ bool ThermalClusterList::loadPreproFromFolder(Study& study, result = c->prepro->normalizeAndCheckNPO(); } - ret = result and ret; + ret = result && ret; } - + ++options.progressTicks; options.pushProgressLogs(); } @@ -488,20 +488,17 @@ bool ThermalClusterList::loadEconomicCosts(Study& study, const AnyString& folder if (empty()) return true; - Clob buffer; - bool ret = true; - for (const auto& c : cluster) + return std::all_of(cluster.begin(), cluster.end(), [&study, folder](const auto& c) { - assert(c->parentArea and "cluster: invalid parent area"); + assert(c->parentArea && "cluster: invalid parent area"); + Clob buffer; buffer.clear() << folder << SEP << c->parentArea->id << SEP << c->id(); bool result = c->ecoInput.loadFromFolder(study, buffer); c->ComputeCostTimeSeries(); - - ret = result && ret; - } - return ret; + return result; + }); } } // namespace Data From 2399d09afb8931656ac7aa19afa76d5535a42994 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Wed, 13 Dec 2023 16:48:27 +0100 Subject: [PATCH 24/54] [DEV] refactor removeDisabledClusters by moving it in common --- .../study/parts/common/cluster_list.cpp | 17 +++++++++++++ .../antares/study/parts/common/cluster_list.h | 13 ++++++++++ .../study/parts/renewable/container.cpp | 17 ------------- .../antares/study/parts/renewable/container.h | 12 ---------- .../antares/study/parts/thermal/container.cpp | 24 ------------------- .../antares/study/parts/thermal/container.h | 12 ---------- src/libs/antares/study/runtime/runtime.cpp | 4 ++-- 7 files changed, 32 insertions(+), 67 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index 0c8e82d070..b4b94cf9a3 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -367,6 +367,23 @@ void ClusterList::retrieveTotalCapacityAndUnitCount(double& total, uin } } +template +uint ClusterList::removeDisabledClusters() +{ + // nothing to do if there is no cluster available + if (empty()) + return 0; + + auto firstClusterToRemove = std::remove_if(cluster.begin(), cluster.end(), [] (auto& c) { + return !c->enabled; + }); + + cluster.erase(firstClusterToRemove , cluster.end()); // Actually remove the disabled clusters + + rebuildIndex(); + + return size(); +} // Force template instantiation template class ClusterList; template class ClusterList; diff --git a/src/libs/antares/study/parts/common/cluster_list.h b/src/libs/antares/study/parts/common/cluster_list.h index 36a9381502..73624cc4bd 100644 --- a/src/libs/antares/study/parts/common/cluster_list.h +++ b/src/libs/antares/study/parts/common/cluster_list.h @@ -245,6 +245,19 @@ class ClusterList ** \endcode */ void retrieveTotalCapacityAndUnitCount(double& total, uint& unitCount) const; + + /*! + ** \brief Removes disabled clusters + ** + ** All clusters with the flag 'enabled' turned to false will be removed from 'list'. + ** As a consequence, they will no longer be seen as thermal clusters + ** from the solver's point of view. + ** \warning This method should only be used from the solver + ** + ** \return The number of disabled clusters found + */ + uint removeDisabledClusters(); + //@} }; // class ClusterList } // namespace Data diff --git a/src/libs/antares/study/parts/renewable/container.cpp b/src/libs/antares/study/parts/renewable/container.cpp index 4e15d211ba..fee7793cdb 100644 --- a/src/libs/antares/study/parts/renewable/container.cpp +++ b/src/libs/antares/study/parts/renewable/container.cpp @@ -74,23 +74,6 @@ void PartRenewable::prepareAreaWideIndexes() } } -uint PartRenewable::removeDisabledClusters() -{ - // nothing to do if there is no cluster available - if (list.empty()) - return 0; - - auto firstClusterToRemove = std::remove_if(list.begin(), list.end(), [] (auto& cluster) { - return !cluster->enabled; - }); - - list.cluster.erase(firstClusterToRemove , list.end()); // Actually remove the disabled clusters - - list.rebuildIndex(); - - return list.size(); -} - void PartRenewable::reset() { list.clear(); diff --git a/src/libs/antares/study/parts/renewable/container.h b/src/libs/antares/study/parts/renewable/container.h index ccb20d5b7f..ae4d439608 100644 --- a/src/libs/antares/study/parts/renewable/container.h +++ b/src/libs/antares/study/parts/renewable/container.h @@ -71,18 +71,6 @@ class PartRenewable */ void prepareAreaWideIndexes(); - /*! - ** \brief Removes disabled renewable clusters - ** - ** All clusters with the flag 'enabled' turned to false will be removed from 'list'. - ** As a consequence, they will no longer be seen as renewable clusters - ** from the solver's point of view. - ** \warning This method should only be used from the solver - ** - ** \return The number of disabled clusters found - */ - uint removeDisabledClusters(); - /*! ** \brief Invalidate all JIT data */ diff --git a/src/libs/antares/study/parts/thermal/container.cpp b/src/libs/antares/study/parts/thermal/container.cpp index b5c6fe8e0d..c3feaf0357 100644 --- a/src/libs/antares/study/parts/thermal/container.cpp +++ b/src/libs/antares/study/parts/thermal/container.cpp @@ -134,30 +134,6 @@ uint PartThermal::prepareClustersInMustRunMode() return count; } -uint PartThermal::removeDisabledClusters() -{ - // nothing to do if there is no cluster available - if (list.empty()) - return 0; - - std::vector disabledClusters; - - for (auto& it : list) - { - if (!it->enabled) - disabledClusters.push_back(it->id()); - } - - for (const auto& cluster : disabledClusters) - list.remove(cluster); - - const auto count = disabledClusters.size(); - if (count) - list.rebuildIndex(); - - return count; -} - void PartThermal::reset() { unsuppliedEnergyCost = 0.; diff --git a/src/libs/antares/study/parts/thermal/container.h b/src/libs/antares/study/parts/thermal/container.h index 0c860abe53..6a413c479e 100644 --- a/src/libs/antares/study/parts/thermal/container.h +++ b/src/libs/antares/study/parts/thermal/container.h @@ -81,18 +81,6 @@ class PartThermal */ uint prepareClustersInMustRunMode(); - /*! - ** \brief Removes disabled thermal clusters - ** - ** All clusters with the flag 'enabled' turned to false will be removed from 'list'. - ** As a consequence, they will no longer be seen as thermal clusters - ** from the solver's point of view. - ** \warning This method should only be used from the solver - ** - ** \return The number of disabled clusters found - */ - uint removeDisabledClusters(); - /*! ** \brief Invalidate all JIT data */ diff --git a/src/libs/antares/study/runtime/runtime.cpp b/src/libs/antares/study/runtime/runtime.cpp index 1a58a14f73..bc4e352cfb 100644 --- a/src/libs/antares/study/runtime/runtime.cpp +++ b/src/libs/antares/study/runtime/runtime.cpp @@ -410,13 +410,13 @@ static void removeClusters(Study& study, void StudyRuntimeInfos::removeDisabledThermalClustersFromSolverComputations(Study& study) { removeClusters( - study, "thermal", [](Area& area) { return area.thermal.removeDisabledClusters(); }); + study, "thermal", [](Area& area) { return area.thermal.list.removeDisabledClusters(); }); } void StudyRuntimeInfos::removeDisabledRenewableClustersFromSolverComputations(Study& study) { removeClusters(study, "renewable", [](Area& area) { - uint ret = area.renewable.removeDisabledClusters(); + uint ret = area.renewable.list.removeDisabledClusters(); if (ret > 0) area.renewable.prepareAreaWideIndexes(); return ret; From e653013124a75d5292704f9d540051a69da6a291 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Wed, 13 Dec 2023 16:52:11 +0100 Subject: [PATCH 25/54] [DEV] comments ui --- .../handler/antares-study/area/create.cpp | 8 +++--- src/ui/simulator/windows/inspector/frame.cpp | 25 ++----------------- src/ui/simulator/windows/inspector/frame.h | 1 - 3 files changed, 5 insertions(+), 29 deletions(-) diff --git a/src/ui/action/handler/antares-study/area/create.cpp b/src/ui/action/handler/antares-study/area/create.cpp index 7b25151182..e159af140d 100644 --- a/src/ui/action/handler/antares-study/area/create.cpp +++ b/src/ui/action/handler/antares-study/area/create.cpp @@ -293,11 +293,9 @@ void Create::createActionsForAStandardAreaCopy(Context& ctx, bool copyPosition) auto* root = new RootNodePlant(pOriginalAreaName); // browsing each thermal cluster - auto end = area->thermal.list.end(); - for (auto i = area->thermal.list.begin(); i != end; ++i) - { - *root += StandardActionsToCopyThermalCluster(pOriginalAreaName, (*i)->name()); - } + for (auto& c : area->thermal.list) + *root += StandardActionsToCopyThermalCluster(pOriginalAreaName, c->name()); + *this += root; } } diff --git a/src/ui/simulator/windows/inspector/frame.cpp b/src/ui/simulator/windows/inspector/frame.cpp index 1243ae9076..7bfa6aeb54 100644 --- a/src/ui/simulator/windows/inspector/frame.cpp +++ b/src/ui/simulator/windows/inspector/frame.cpp @@ -178,9 +178,8 @@ void Frame::onSelectAllPlants(wxCommandEvent&) for (auto i = data->areas.begin(); i != areaEnd; ++i) { Data::Area& area = *(*i); - auto end = area.thermal.list.end(); - for (auto i = area.thermal.list.begin(); i != end; ++i) - data->ThClusters.insert((*i).get()); + for (auto& c : area.thermal.list) + data->ThClusters.insert(c.get()); } data->areas.clear(); data->links.clear(); @@ -204,26 +203,6 @@ void Frame::onSelectPlant(wxCommandEvent& evt) } } -// gp : never used - to be removed -void Frame::onSelectAllPlantsFromArea(wxCommandEvent& evt) -{ - InspectorData::Ptr data = gData; - if (!(!data) and gInspector and evt.GetEventObject()) - { - Data::Area* area = (Data::Area*)mapIDPointer[evt.GetId()]; - if (!area) - return; - data->ThClusters.clear(); - auto end = area->thermal.list.end(); - for (auto i = area->thermal.list.begin(); i != end; ++i) - data->ThClusters.insert((*i).get()); - data->areas.clear(); - data->links.clear(); - data->empty = data->ThClusters.empty(); - gInspector->delayApplyGlobalSelection(); - } -} - Frame::Frame(wxWindow* parent, bool allowAnyObject) : Antares::Component::Panel(parent), pNotes(nullptr), diff --git a/src/ui/simulator/windows/inspector/frame.h b/src/ui/simulator/windows/inspector/frame.h index 2d49c0bd8e..153be844c4 100644 --- a/src/ui/simulator/windows/inspector/frame.h +++ b/src/ui/simulator/windows/inspector/frame.h @@ -100,7 +100,6 @@ class Frame final : public Antares::Component::Panel, public Yuni::IEventObserve void onSelectAllPlants(wxCommandEvent& evt); void onSelectPlant(wxCommandEvent& evt); - void onSelectAllPlantsFromArea(wxCommandEvent& evt); void clearAssociatinsBetweenIDAndPtr() { From 2c87746fb05d5a81de93f9b3c95fffb69a71fb9f Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Thu, 14 Dec 2023 15:48:08 +0100 Subject: [PATCH 26/54] [DEV] simplify common clusters : remove 2 useless find functions --- src/libs/antares/study/area/list.cpp | 4 +-- .../study/parts/common/cluster_list.cpp | 28 ++----------------- .../antares/study/parts/common/cluster_list.h | 13 ++------- .../toolbox/input/renewable-cluster.cpp | 2 -- 4 files changed, 7 insertions(+), 40 deletions(-) diff --git a/src/libs/antares/study/area/list.cpp b/src/libs/antares/study/area/list.cpp index 9e6a324e26..8616410dbe 100644 --- a/src/libs/antares/study/area/list.cpp +++ b/src/libs/antares/study/area/list.cpp @@ -1534,8 +1534,8 @@ ThermalCluster* AreaList::findClusterFromINIKey(const AnyString& key) Area* parentArea = findFromName(parentName); if (parentArea == nullptr) return nullptr; - ThermalCluster* i = parentArea->thermal.list.find(id); - return (i != nullptr) ? i : nullptr; + return parentArea->thermal.list.find(id); + } void AreaList::updateNameIDSet() const diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index b4b94cf9a3..aa46d34fba 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -57,7 +57,7 @@ typename ClusterList::const_iterator ClusterList::end() cons } template -const ClusterT* ClusterList::find(const Data::ClusterName& id) const +ClusterT* ClusterList::find(const Data::ClusterName& id) const { for (const auto& c : cluster) if (c->id() == id) @@ -66,16 +66,6 @@ const ClusterT* ClusterList::find(const Data::ClusterName& id) const return nullptr; } -template -ClusterT* ClusterList::find(const Data::ClusterName& id) -{ - for (auto& c : cluster) - if (c->id() == id) - return c.get(); - - return nullptr; -} - template typename std::shared_ptr ClusterList::detach(iterator i) { @@ -126,18 +116,6 @@ const ClusterT* ClusterList::find(const ClusterT* p) const return nullptr; } - -template -typename ClusterList::SharedPtr ClusterList::find - (const ClusterList::SharedPtr& p) -{ - for (auto& c : cluster) - if (c == p) - return c; - - return nullptr; -} - template void ClusterList::resizeAllTimeseriesNumbers(uint n) { @@ -192,13 +170,13 @@ void ClusterList::rebuildIndex() template typename ClusterList::SharedPtr ClusterList::add( - const ClusterList::SharedPtr& newcluster) + const ClusterList::SharedPtr newcluster) { if (!newcluster) return nullptr; if (exists(newcluster->id())) - return this->find(newcluster); + return newcluster; cluster.push_back(newcluster); ++(groupCount[newcluster->groupId()]); diff --git a/src/libs/antares/study/parts/common/cluster_list.h b/src/libs/antares/study/parts/common/cluster_list.h index 73624cc4bd..c87edfd7dc 100644 --- a/src/libs/antares/study/parts/common/cluster_list.h +++ b/src/libs/antares/study/parts/common/cluster_list.h @@ -79,7 +79,7 @@ class ClusterList ** \return True if the cluster has been added, false otherwise */ - SharedPtr add(const SharedPtr& t); + SharedPtr add(const SharedPtr cluster); /*! ** \brief Detach a cluster represented by an iterator ** @@ -100,22 +100,13 @@ class ClusterList */ virtual void remove(iterator i); - /*! - ** \brief Try to find a cluster from its id - ** - ** \param id ID of the cluster to find - ** \return A pointer to a cluster. nullptr if not found - */ - ClusterT* find(const Data::ClusterName& id); /*! ** \brief Try to find a cluster from its id (const) ** ** \param id ID of the cluster to find ** \return A pointer to a cluster. nullptr if not found */ - const ClusterT* find(const Data::ClusterName& id) const; - SharedPtr find(const ClusterList::SharedPtr& p); - + ClusterT* find(const Data::ClusterName& id) const; /*! ** \brief Try to find a cluster from its pointer (const) diff --git a/src/ui/simulator/toolbox/input/renewable-cluster.cpp b/src/ui/simulator/toolbox/input/renewable-cluster.cpp index 043ff85e3a..c3ed76d564 100644 --- a/src/ui/simulator/toolbox/input/renewable-cluster.cpp +++ b/src/ui/simulator/toolbox/input/renewable-cluster.cpp @@ -389,7 +389,6 @@ void RenewableCluster::internalAddPlant(void*) cluster->setName(sFl); cluster->reset(); pArea->renewable.list.add(cluster); - pArea->renewable.list.rebuildIndex(); pArea->renewable.prepareAreaWideIndexes(); // Update the list @@ -467,7 +466,6 @@ void RenewableCluster::internalClonePlant(void*) cluster->copyFrom(selectedPlant); pArea->renewable.list.add(cluster); - pArea->renewable.list.rebuildIndex(); pArea->renewable.prepareAreaWideIndexes(); // Update the list From 04ce1bcdcc983ce83b21a161fe035b8f403ead7e Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Thu, 14 Dec 2023 18:39:11 +0100 Subject: [PATCH 27/54] [DEV] simplify common clusters : "remove" function removal, because unused --- src/libs/antares/study/parts/common/cluster_list.cpp | 6 ------ src/libs/antares/study/parts/common/cluster_list.h | 10 ---------- 2 files changed, 16 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index aa46d34fba..6bced2a798 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -74,12 +74,6 @@ typename std::shared_ptr ClusterList::detach(iterator i) return c; } -template -void ClusterList::remove(iterator i) -{ - cluster.erase(i); -} - template bool ClusterList::exists(const Data::ClusterName& id) const { diff --git a/src/libs/antares/study/parts/common/cluster_list.h b/src/libs/antares/study/parts/common/cluster_list.h index c87edfd7dc..7b70a357de 100644 --- a/src/libs/antares/study/parts/common/cluster_list.h +++ b/src/libs/antares/study/parts/common/cluster_list.h @@ -90,16 +90,6 @@ class ClusterList */ SharedPtr detach(iterator i); - /*! - ** \brief Remove a cluster represented by an iterator - ** - ** The cluster will be removed from the list but _not_ - ** destroyed. - ** The iterator should considered as invalid after using this method. - ** \return void - */ - virtual void remove(iterator i); - /*! ** \brief Try to find a cluster from its id (const) ** From 0b42f10bf979c0e58aa73954ce5c0c52631cb705 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Mon, 18 Dec 2023 11:40:23 +0100 Subject: [PATCH 28/54] [DEV] simplify common clusters : gathering find(...) functions definitions in .cpp --- .../study/parts/common/cluster_list.cpp | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index 6bced2a798..5222237b9b 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -66,6 +66,16 @@ ClusterT* ClusterList::find(const Data::ClusterName& id) const return nullptr; } +template +const ClusterT* ClusterList::find(const ClusterT* p) const +{ + for (const auto& c : cluster) + if (c.get() == p) + return c.get(); + + return nullptr; +} + template typename std::shared_ptr ClusterList::detach(iterator i) { @@ -100,16 +110,6 @@ void ClusterList::clear() cluster.clear(); } -template -const ClusterT* ClusterList::find(const ClusterT* p) const -{ - for (const auto& c : cluster) - if (c.get() == p) - return c.get(); - - return nullptr; -} - template void ClusterList::resizeAllTimeseriesNumbers(uint n) { From 731076f695fad1979b1d042d4b714ccbdafeadda Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Mon, 18 Dec 2023 13:02:58 +0100 Subject: [PATCH 29/54] [DEV] simplify common clusters : we don't need to handle separately the case : cluster list is empty --- src/libs/antares/study/parts/common/cluster_list.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index 5222237b9b..af74dc4767 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -280,9 +280,6 @@ bool ClusterList::remove(const Data::ClusterName& id) template bool ClusterList::saveDataSeriesToFolder(const AnyString& folder) const { - if (empty()) - return true; - return std::all_of(cluster.begin(), cluster.end(), [&folder](const auto& c){ return c->saveDataSeriesToFolder(folder); }); From 64f31a36105da2c1028f9f58e49f205247e1f90d Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Mon, 18 Dec 2023 13:32:22 +0100 Subject: [PATCH 30/54] [DEV] Using ranges and cpp 20 algo --- .../study/parts/common/cluster_list.cpp | 30 +++++-------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index 6bced2a798..8d26dd2042 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -1,4 +1,5 @@ #include +#include #include #include "cluster_list.h" #include @@ -77,9 +78,7 @@ typename std::shared_ptr ClusterList::detach(iterator i) template bool ClusterList::exists(const Data::ClusterName& id) const { - return std::any_of(cluster.begin(), cluster.end(), [&id](const auto& c){ - return c->id() == id; - }); + return std::ranges::any_of(cluster, [&id](const auto& c){ return c->id() == id; }); } template @@ -241,7 +240,7 @@ bool ClusterList::rename(Data::ClusterName idToFind, Data::ClusterName template bool ClusterList::forceReload(bool reload) const { - return std::all_of(cluster.begin(), cluster.end(), [&reload](const auto& c){ + return std::ranges::all_of(cluster, [&reload](const auto& c){ return c->forceReload(reload); }); @@ -257,24 +256,15 @@ void ClusterList::markAsModified() const template bool ClusterList::remove(const Data::ClusterName& id) { - // using find_if to get an iterator and use erase later - const auto& it = find_if(cluster.begin(), cluster.end(), - [&id](const SharedPtr& c) { return c->id() == id; }); - - if (it == cluster.end()) - return false; - - // Getting the pointer on the cluster - SharedPtr c = *it; + auto nbDeletion = std::erase_if(cluster, [&id](const SharedPtr& c) { return c->id() == id; }); - // Removing it from the list - cluster.erase(it); // Invalidating the parent area - c->parentArea->forceReload(); + forceReload(); // Rebuilding the index rebuildIndex(); - return true; + + return nbDeletion > 0; } template @@ -346,11 +336,7 @@ uint ClusterList::removeDisabledClusters() if (empty()) return 0; - auto firstClusterToRemove = std::remove_if(cluster.begin(), cluster.end(), [] (auto& c) { - return !c->enabled; - }); - - cluster.erase(firstClusterToRemove , cluster.end()); // Actually remove the disabled clusters + std::erase_if(cluster, [] (auto& c) { return !c->enabled; }); rebuildIndex(); From a20091489fee31aebda3e0c10520ac79ef1cbdc5 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Mon, 18 Dec 2023 14:25:26 +0100 Subject: [PATCH 31/54] [DEV] renamed cluster into clusters --- .../study/parts/common/cluster_list.cpp | 56 ++++++++-------- .../antares/study/parts/common/cluster_list.h | 64 +++++++++---------- .../study/parts/thermal/cluster_list.cpp | 8 +-- .../RenewableTSNumberData.cpp | 4 +- .../scenario-builder/ThermalTSNumberData.cpp | 4 +- src/libs/antares/study/study.cpp | 2 +- .../simulation/sim_calcul_economique.cpp | 2 +- src/solver/simulation/timeseries-numbers.cpp | 10 +-- .../economy/productionByRenewablePlant.h | 2 +- src/solver/variable/info.h | 2 +- .../renderer/area/renewable.areasummary.cpp | 2 +- .../renderer/area/thermal.areasummary.cpp | 8 +-- .../scenario-builder-renewable-renderer.cpp | 4 +- .../scenario-builder-thermal-renderer.cpp | 4 +- 14 files changed, 86 insertions(+), 86 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index c08e60429a..fc317b0249 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -24,43 +24,43 @@ using namespace Antares; template inline uint ClusterList::size() const { - return (uint)cluster.size(); + return (uint)clusters.size(); } template inline bool ClusterList::empty() const { - return cluster.empty(); + return clusters.empty(); } template typename ClusterList::iterator ClusterList::begin() { - return std::begin(cluster); + return std::begin(clusters); } template typename ClusterList::const_iterator ClusterList::begin() const { - return std::begin(cluster); + return std::begin(clusters); } template typename ClusterList::iterator ClusterList::end() { - return std::end(cluster); + return std::end(clusters); } template typename ClusterList::const_iterator ClusterList::end() const { - return std::end(cluster); + return std::end(clusters); } template ClusterT* ClusterList::find(const Data::ClusterName& id) const { - for (const auto& c : cluster) + for (const auto& c : clusters) if (c->id() == id) return c.get(); @@ -70,7 +70,7 @@ ClusterT* ClusterList::find(const Data::ClusterName& id) const template const ClusterT* ClusterList::find(const ClusterT* p) const { - for (const auto& c : cluster) + for (const auto& c : clusters) if (c.get() == p) return c.get(); @@ -81,14 +81,14 @@ template typename std::shared_ptr ClusterList::detach(iterator i) { SharedPtr c = *i; - cluster.erase(i); + clusters.erase(i); return c; } template bool ClusterList::exists(const Data::ClusterName& id) const { - return std::ranges::any_of(cluster, [&id](const auto& c){ return c->id() == id; }); + return std::ranges::any_of(clusters, [&id](const auto& c){ return c->id() == id; }); } template @@ -106,14 +106,14 @@ Data::ClusterList::~ClusterList() template void ClusterList::clear() { - cluster.clear(); + clusters.clear(); } template void ClusterList::resizeAllTimeseriesNumbers(uint n) { assert(n < 200000); // arbitrary number - if (not cluster.empty()) + if (not clusters.empty()) { if (0 == n) { @@ -131,7 +131,7 @@ void ClusterList::resizeAllTimeseriesNumbers(uint n) template void ClusterList::storeTimeseriesNumbers(Solver::IResultWriter& writer) const { - if (cluster.empty()) + if (clusters.empty()) return; TSNumbersPredicate predicate; @@ -150,12 +150,12 @@ void ClusterList::storeTimeseriesNumbers(Solver::IResultWriter& writer template void ClusterList::rebuildIndex() { - std::sort(cluster.begin(), cluster.end(), [](const auto& a, const auto& b){ + std::sort(clusters.begin(), clusters.end(), [](const auto& a, const auto& b){ return a->id() < b->id(); }); uint indx = 0; - for (auto& c : cluster) + for (auto& c : clusters) c->index = indx++; } @@ -171,7 +171,7 @@ typename ClusterList::SharedPtr ClusterList::add( if (exists(newcluster->id())) return newcluster; - cluster.push_back(newcluster); + clusters.push_back(newcluster); ++(groupCount[newcluster->groupId()]); rebuildIndex(); return newcluster; @@ -182,7 +182,7 @@ uint64_t ClusterList::memoryUsage() const { uint64_t ret = sizeof(ClusterList) + (2 * sizeof(void*)) * this->size(); - each([&](const ClusterT& cluster) { ret += cluster.memoryUsage(); }); + each([&](const ClusterT& clusters) { ret += clusters.memoryUsage(); }); return ret; } @@ -205,7 +205,7 @@ bool ClusterList::rename(Data::ClusterName idToFind, Data::ClusterName Data::ClusterName newID; Antares::TransformNameIntoID(newName, newID); - // Looking for the renewable cluster in the list + // Looking for the renewable clusters in the list auto* cluster_ptr = this->find(idToFind); if (!cluster_ptr) return true; @@ -227,7 +227,7 @@ bool ClusterList::rename(Data::ClusterName idToFind, Data::ClusterName cluster_ptr->setName(newName); // Invalidate matrices attached to the area - // It is a bit excessive (all matrices not only those related to the renewable cluster) + // It is a bit excessive (all matrices not only those related to the renewable clusters) // will be rewritten but currently it is the less error-prone. if (cluster_ptr->parentArea) (cluster_ptr->parentArea)->invalidateJIT = true; @@ -240,7 +240,7 @@ bool ClusterList::rename(Data::ClusterName idToFind, Data::ClusterName template bool ClusterList::forceReload(bool reload) const { - return std::ranges::all_of(cluster, [&reload](const auto& c){ + return std::ranges::all_of(clusters, [&reload](const auto& c){ return c->forceReload(reload); }); @@ -249,14 +249,14 @@ bool ClusterList::forceReload(bool reload) const template void ClusterList::markAsModified() const { - for (const auto& c : cluster) + for (const auto& c : clusters) c->markAsModified(); } template bool ClusterList::remove(const Data::ClusterName& id) { - auto nbDeletion = std::erase_if(cluster, [&id](const SharedPtr& c) { return c->id() == id; }); + auto nbDeletion = std::erase_if(clusters, [&id](const SharedPtr& c) { return c->id() == id; }); // Invalidating the parent area forceReload(); @@ -270,7 +270,7 @@ bool ClusterList::remove(const Data::ClusterName& id) template bool ClusterList::saveDataSeriesToFolder(const AnyString& folder) const { - return std::all_of(cluster.begin(), cluster.end(), [&folder](const auto& c){ + return std::all_of(clusters.begin(), clusters.end(), [&folder](const auto& c){ return c->saveDataSeriesToFolder(folder); }); } @@ -284,9 +284,9 @@ bool ClusterList::saveDataSeriesToFolder(const AnyString& folder, cons bool ret = true; uint ticks = 0; - for (const auto& c : cluster) + for (const auto& c : clusters) { - logs.info() << msg << " " << (ticks * 100 / (1 + this->cluster.size())) + logs.info() << msg << " " << (ticks * 100 / (1 + this->clusters.size())) << "% complete"; ret = c->saveDataSeriesToFolder(folder) && ret; ++ticks; @@ -319,7 +319,7 @@ void ClusterList::retrieveTotalCapacityAndUnitCount(double& total, uin total = 0.; unitCount = 0; - for (const auto& c : cluster) + for (const auto& c : clusters) { unitCount += c->unitCount; total += c->unitCount * c->nominalCapacity; @@ -329,11 +329,11 @@ void ClusterList::retrieveTotalCapacityAndUnitCount(double& total, uin template uint ClusterList::removeDisabledClusters() { - // nothing to do if there is no cluster available + // nothing to do if there is no clusters available if (empty()) return 0; - std::erase_if(cluster, [] (auto& c) { return !c->enabled; }); + std::erase_if(clusters, [] (auto& c) { return !c->enabled; }); rebuildIndex(); diff --git a/src/libs/antares/study/parts/common/cluster_list.h b/src/libs/antares/study/parts/common/cluster_list.h index 7b70a357de..23ce8e565a 100644 --- a/src/libs/antares/study/parts/common/cluster_list.h +++ b/src/libs/antares/study/parts/common/cluster_list.h @@ -52,7 +52,7 @@ class ClusterList template void each(const PredicateT& predicate) { - for (auto& c : cluster) + for (auto& c : clusters) predicate(*c); } /*! @@ -61,11 +61,11 @@ class ClusterList template void each(const PredicateT& predicate) const { - for (const auto& c : cluster) + for (const auto& c : clusters) predicate(*c); } - //! \name Cluster management + //! \name clusters management //@{ /*! ** \brief Destroy all clusters @@ -73,61 +73,61 @@ class ClusterList void clear(); /*! - ** \brief Add a cluster in the list + ** \brief Add a clusters in the list ** - ** \param t The cluster to add - ** \return True if the cluster has been added, false otherwise + ** \param t The clusters to add + ** \return True if the clusters has been added, false otherwise */ - SharedPtr add(const SharedPtr cluster); + SharedPtr add(const SharedPtr clusters); /*! - ** \brief Detach a cluster represented by an iterator + ** \brief Detach a clusters represented by an iterator ** - ** The cluster will be removed from the list but _not_ + ** The clusters will be removed from the list but _not_ ** destroyed. ** The iterator should considered as invalid after using this method. - ** \return A pointer to the cluster, NULL if an error has occured + ** \return A pointer to the clusters, NULL if an error has occured */ SharedPtr detach(iterator i); /*! - ** \brief Try to find a cluster from its id (const) + ** \brief Try to find a clusters from its id (const) ** - ** \param id ID of the cluster to find - ** \return A pointer to a cluster. nullptr if not found + ** \param id ID of the clusters to find + ** \return A pointer to a clusters. nullptr if not found */ ClusterT* find(const Data::ClusterName& id) const; /*! - ** \brief Try to find a cluster from its pointer (const) + ** \brief Try to find a clusters from its pointer (const) ** - ** \param p Pointer of the cluster to find - ** \return A pointer to a cluster. nullptr if not found + ** \param p Pointer of the clusters to find + ** \return A pointer to a clusters. nullptr if not found */ const ClusterT* find(const ClusterT* p) const; /*! - ** \brief Get if a cluster exists + ** \brief Get if a clusters exists ** - ** \param id ID of the cluster to find - ** \return True if the cluster exists + ** \param id ID of the clusters to find + ** \return True if the clusters exists */ bool exists(const Data::ClusterName& id) const; /*! - ** \brief Rename a cluster + ** \brief Rename a clusters ** - ** \param idToFind ID of the cluster to rename - ** \param newName The new name for the cluster - ** \return True if the operation succeeded (the cluster has been renamed) - ** false otherwise (not found or if another cluster has the same name) + ** \param idToFind ID of the clusters to rename + ** \param newName The new name for the clusters + ** \return True if the operation succeeded (the clusters has been renamed) + ** false otherwise (not found or if another clusters has the same name) ** ** The indexes for clusters will be rebuilt. */ bool rename(Data::ClusterName idToFind, Data::ClusterName newName); /*! - ** \brief Remove properly a cluster + ** \brief Remove properly a clusters */ virtual bool remove(const Data::ClusterName& id); @@ -167,7 +167,7 @@ class ClusterList bool forceReload(bool reload = false) const; /*! - ** \brief Mark the cluster as modified + ** \brief Mark the clusters as modified */ void markAsModified() const; @@ -175,7 +175,7 @@ class ClusterList ** \brief Rebuild the index of clusters ** ** As a list of clusters is a hash table, it is not - ** possible to directly accees to a cluster from its index. + ** possible to directly accees to a clusters from its index. ** However an index can be built but it must be re-built when ** the hash table is modified. */ @@ -189,13 +189,13 @@ class ClusterList public: //! All clusters - Vect cluster; + Vect clusters; // thermal, renewable, etc. virtual YString typeID() const = 0; /*! - ** \brief Number of dispatchable cluster per group + ** \brief Number of dispatchable clusters per group ** ** You should rely on these values only after the loading of the study ** and until the study is not modified. @@ -220,9 +220,9 @@ class ClusterList ** ** Pseudo code: ** \code - ** each thermal cluster do - ** total += cluster{unit count} * cluster{nominal capacity} - ** unit += cluster{unit count} + ** each thermal clusters do + ** total += clusters{unit count} * clusters{nominal capacity} + ** unit += clusters{unit count} ** \endcode */ void retrieveTotalCapacityAndUnitCount(double& total, uint& unitCount) const; diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index 99389a79ce..8ed5fd0e64 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -278,7 +278,7 @@ void ThermalClusterList::calculationOfSpinning() void ThermalClusterList::reverseCalculationOfSpinning() { - for (const auto& c : cluster) + for (const auto& c : clusters) c->reverseCalculationOfSpinning(); } @@ -290,7 +290,7 @@ void ThermalClusterList::enableMustrunForEveryone() void ThermalClusterList::ensureDataPrepro() { - for (const auto& c : cluster) + for (const auto& c : clusters) if (!c->prepro) c->prepro = new PreproThermal(c); } @@ -458,7 +458,7 @@ bool ThermalClusterList::loadPreproFromFolder(Study& study, Clob buffer; bool ret = true; - for (const auto& c : cluster) + for (const auto& c : clusters) { if (c->prepro) { @@ -489,7 +489,7 @@ bool ThermalClusterList::loadEconomicCosts(Study& study, const AnyString& folder return true; - return std::all_of(cluster.begin(), cluster.end(), [&study, folder](const auto& c) + return std::all_of(clusters.begin(), clusters.end(), [&study, folder](const auto& c) { assert(c->parentArea && "cluster: invalid parent area"); Clob buffer; diff --git a/src/libs/antares/study/scenario-builder/RenewableTSNumberData.cpp b/src/libs/antares/study/scenario-builder/RenewableTSNumberData.cpp index d004de7587..d927743163 100644 --- a/src/libs/antares/study/scenario-builder/RenewableTSNumberData.cpp +++ b/src/libs/antares/study/scenario-builder/RenewableTSNumberData.cpp @@ -79,12 +79,12 @@ void renewableTSNumberData::saveToINIFile(const Study& /* study */, // Foreach renewable cluster... for (uint y = 0; y != pTSNumberRules.height; ++y) { - const uint val = get(pArea->renewable.list.cluster[index].get(), y); + const uint val = get(pArea->renewable.list.clusters[index].get(), y); // Equals to zero means 'auto', which is the default mode if (!val) continue; file << prefix << pArea->id << "," << y << ',' - << pArea->renewable.list.cluster[index]->id() << " = " << val << '\n'; + << pArea->renewable.list.clusters[index]->id() << " = " << val << '\n'; } } } diff --git a/src/libs/antares/study/scenario-builder/ThermalTSNumberData.cpp b/src/libs/antares/study/scenario-builder/ThermalTSNumberData.cpp index 398ae219c9..a09a8c5150 100644 --- a/src/libs/antares/study/scenario-builder/ThermalTSNumberData.cpp +++ b/src/libs/antares/study/scenario-builder/ThermalTSNumberData.cpp @@ -49,12 +49,12 @@ void thermalTSNumberData::saveToINIFile(const Study& /* study */, // Foreach year ... for (uint y = 0; y != pTSNumberRules.height; ++y) { - const uint val = get(pArea->thermal.list.cluster[index].get(), y); + const uint val = get(pArea->thermal.list.clusters[index].get(), y); // Equals to zero means 'auto', which is the default mode if (!val) continue; file << prefix << pArea->id << "," << y << ',' - << pArea->thermal.list.cluster[index]->id() << " = " << val << '\n'; + << pArea->thermal.list.clusters[index]->id() << " = " << val << '\n'; } } } diff --git a/src/libs/antares/study/study.cpp b/src/libs/antares/study/study.cpp index f8567c349a..bb3ed24f21 100644 --- a/src/libs/antares/study/study.cpp +++ b/src/libs/antares/study/study.cpp @@ -1530,7 +1530,7 @@ void Study::computePThetaInfForThermalClusters() const for (uint j = 0; j < area.thermal.list.size(); j++) { // Alias du cluster courant - auto& cluster = area.thermal.list.cluster[j]; + auto& cluster = area.thermal.list.clusters[j]; for (uint k = 0; k < HOURS_PER_YEAR; k++) cluster->PthetaInf[k] = cluster->modulation[Data::thermalMinGenModulation][k] * cluster->unitCount * cluster->nominalCapacity; diff --git a/src/solver/simulation/sim_calcul_economique.cpp b/src/solver/simulation/sim_calcul_economique.cpp index 3982adce6d..087ad8d178 100644 --- a/src/solver/simulation/sim_calcul_economique.cpp +++ b/src/solver/simulation/sim_calcul_economique.cpp @@ -285,7 +285,7 @@ void SIM_InitialisationProblemeHebdo(Data::Study& study, for (uint clusterIndex = 0; clusterIndex != area.thermal.list.size(); ++clusterIndex) { - auto& cluster = *(area.thermal.list.cluster[clusterIndex]); + auto& cluster = *(area.thermal.list.clusters[clusterIndex]); pbPalier.NumeroDuPalierDansLEnsembleDesPaliersThermiques[clusterIndex] = NombrePaliers + clusterIndex; pbPalier.TailleUnitaireDUnGroupeDuPalierThermique[clusterIndex] diff --git a/src/solver/simulation/timeseries-numbers.cpp b/src/solver/simulation/timeseries-numbers.cpp index cedd56abca..346983f95a 100644 --- a/src/solver/simulation/timeseries-numbers.cpp +++ b/src/solver/simulation/timeseries-numbers.cpp @@ -555,8 +555,8 @@ void storeTSnumbersForIntraModal(const array& intramo if (isTSintramodal[indexTS]) { - auto end_rn_clusters = area.renewable.list.cluster.end(); - for (auto j = area.renewable.list.cluster.begin(); j != end_rn_clusters; ++j) + auto end_rn_clusters = area.renewable.list.clusters.end(); + for (auto j = area.renewable.list.clusters.begin(); j != end_rn_clusters; ++j) { RenewableClusterList::SharedPtr cluster = *j; if (cluster->enabled) @@ -667,8 +667,8 @@ void drawAndStoreTSnumbersForNOTintraModal(const array& i // -------------------------- indexTS = ts_to_tsIndex.at(timeSeriesRenewable); - auto end_rn_clusters = area.renewable.list.cluster.end(); - for (auto j = area.renewable.list.cluster.begin(); j != end_rn_clusters; ++j) + auto end_rn_clusters = area.renewable.list.clusters.end(); + for (auto j = area.renewable.list.clusters.begin(); j != end_rn_clusters; ++j) { RenewableClusterList::SharedPtr cluster = *j; if (not cluster->enabled) @@ -747,7 +747,7 @@ Matrix* getFirstTSnumberInterModalMatrixFoundInArea( tsNumbersMtx = &(area.thermal.clusters[0]->series.timeseriesNumbers); else if (isTSintermodal[ts_to_tsIndex.at(timeSeriesRenewable)] && area.renewable.list.size() > 0) - tsNumbersMtx = &(area.renewable.list.cluster[0]->series.timeseriesNumbers); + tsNumbersMtx = &(area.renewable.list.clusters[0]->series.timeseriesNumbers); } assert(tsNumbersMtx); diff --git a/src/solver/variable/economy/productionByRenewablePlant.h b/src/solver/variable/economy/productionByRenewablePlant.h index 76ece69c79..a7eb726fca 100644 --- a/src/solver/variable/economy/productionByRenewablePlant.h +++ b/src/solver/variable/economy/productionByRenewablePlant.h @@ -327,7 +327,7 @@ class ProductionByRenewablePlant : public Variable::IVariablename(); + results.variableCaption = renewable.list.clusters[i]->name(); results.variableUnit = VCardType::Unit(); pValuesForTheCurrentYear[numSpace][i].template buildAnnualSurveyReport( results, fileLevel, precision); diff --git a/src/solver/variable/info.h b/src/solver/variable/info.h index 2a62d64174..2fc48353f8 100644 --- a/src/solver/variable/info.h +++ b/src/solver/variable/info.h @@ -407,7 +407,7 @@ struct VariableAccessor if (renewable_details) { auto& renewable = results.data.area->renewable; - results.variableCaption = renewable.list.cluster[idx]->name(); + results.variableCaption = renewable.list.clusters[idx]->name(); return true; } if (st_storage_details) diff --git a/src/ui/simulator/toolbox/components/datagrid/renderer/area/renewable.areasummary.cpp b/src/ui/simulator/toolbox/components/datagrid/renderer/area/renewable.areasummary.cpp index 952383759a..c1cff599fc 100644 --- a/src/ui/simulator/toolbox/components/datagrid/renderer/area/renewable.areasummary.cpp +++ b/src/ui/simulator/toolbox/components/datagrid/renderer/area/renewable.areasummary.cpp @@ -51,7 +51,7 @@ RenewableClusterSummarySingleArea::~RenewableClusterSummarySingleArea() wxString RenewableClusterSummarySingleArea::rowCaption(int rowIndx) const { if (pArea) - return wxStringFromUTF8(pArea->renewable.list.cluster[rowIndx]->name()); + return wxStringFromUTF8(pArea->renewable.list.clusters[rowIndx]->name()); return wxEmptyString; } diff --git a/src/ui/simulator/toolbox/components/datagrid/renderer/area/thermal.areasummary.cpp b/src/ui/simulator/toolbox/components/datagrid/renderer/area/thermal.areasummary.cpp index a5ba590171..e36fad8189 100644 --- a/src/ui/simulator/toolbox/components/datagrid/renderer/area/thermal.areasummary.cpp +++ b/src/ui/simulator/toolbox/components/datagrid/renderer/area/thermal.areasummary.cpp @@ -51,7 +51,7 @@ ThermalClusterSummarySingleArea::~ThermalClusterSummarySingleArea() wxString ThermalClusterSummarySingleArea::rowCaption(int rowIndx) const { if (pArea) - return wxStringFromUTF8(pArea->thermal.list.cluster[rowIndx]->name()); + return wxStringFromUTF8(pArea->thermal.list.clusters[rowIndx]->name()); return wxEmptyString; } @@ -82,7 +82,7 @@ wxString ThermalClusterSummarySingleArea::columnCaption(int colIndx) const wxString ThermalClusterSummarySingleArea::cellValue(int x, int y) const { Data::ThermalCluster* cluster = (pArea and (uint) y < pArea->thermal.list.size()) - ? pArea->thermal.list.cluster[y].get() + ? pArea->thermal.list.clusters[y].get() : nullptr; if (!cluster->enabled) return wxEmptyString; @@ -125,7 +125,7 @@ wxString ThermalClusterSummarySingleArea::cellValue(int x, int y) const double ThermalClusterSummarySingleArea::cellNumericValue(int x, int y) const { Data::ThermalCluster* cluster = (pArea and (uint) y < pArea->thermal.list.size()) - ? pArea->thermal.list.cluster[y].get() + ? pArea->thermal.list.clusters[y].get() : nullptr; if (!cluster->enabled) return 0.; @@ -168,7 +168,7 @@ double ThermalClusterSummarySingleArea::cellNumericValue(int x, int y) const bool ThermalClusterSummarySingleArea::cellValue(int x, int y, const String& v) { auto* cluster = (pArea and (uint) y < pArea->thermal.list.size()) - ? pArea->thermal.list.cluster[y].get() + ? pArea->thermal.list.clusters[y].get() : nullptr; if (cluster) diff --git a/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-renewable-renderer.cpp b/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-renewable-renderer.cpp index 95d8052f58..c0265d2d24 100644 --- a/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-renewable-renderer.cpp +++ b/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-renewable-renderer.cpp @@ -54,7 +54,7 @@ wxString renewableScBuilderRenderer::rowCaption(int rowIndx) const && (uint)rowIndx < selectedArea()->renewable.list.size()) { return wxString() << wxT( - " ") << wxStringFromUTF8(selectedArea()->renewable.list.cluster[rowIndx]->name()) + " ") << wxStringFromUTF8(selectedArea()->renewable.list.clusters[rowIndx]->name()) << wxT(" "); } return wxEmptyString; @@ -70,7 +70,7 @@ bool renewableScBuilderRenderer::cellValue(int x, int y, const String& value) assert((uint)x < pRules->renewable[selectedArea()->index].height()); uint val = fromStringToTSnumber(value); pRules->renewable[selectedArea()->index].setTSnumber( - selectedArea()->renewable.list.cluster[y].get(), x, val); + selectedArea()->renewable.list.clusters[y].get(), x, val); return true; } return false; diff --git a/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-thermal-renderer.cpp b/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-thermal-renderer.cpp index 59339154ce..a803ec2b3a 100644 --- a/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-thermal-renderer.cpp +++ b/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-thermal-renderer.cpp @@ -54,7 +54,7 @@ wxString thermalScBuilderRenderer::rowCaption(int rowIndx) const && (uint)rowIndx < selectedArea()->thermal.list.size()) { return wxString() << wxT(" ") - << wxStringFromUTF8(selectedArea()->thermal.list.cluster[rowIndx]->name()) + << wxStringFromUTF8(selectedArea()->thermal.list.clusters[rowIndx]->name()) << wxT(" "); } return wxEmptyString; @@ -69,7 +69,7 @@ bool thermalScBuilderRenderer::cellValue(int x, int y, const String& value) assert((uint)y < pRules->thermal[selectedArea()->index].width()); assert((uint)x < pRules->thermal[selectedArea()->index].height()); uint val = fromStringToTSnumber(value); - pRules->thermal[selectedArea()->index].setTSnumber(selectedArea()->thermal.list.cluster[y].get(), x, val); + pRules->thermal[selectedArea()->index].setTSnumber(selectedArea()->thermal.list.clusters[y].get(), x, val); return true; } return false; From 557201bd085fdee95437876756f295a1b9020541 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Mon, 18 Dec 2023 14:30:30 +0100 Subject: [PATCH 32/54] [FIX] compile --- .../datagrid/renderer/area/renewable.areasummary.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ui/simulator/toolbox/components/datagrid/renderer/area/renewable.areasummary.cpp b/src/ui/simulator/toolbox/components/datagrid/renderer/area/renewable.areasummary.cpp index c1cff599fc..46e3878002 100644 --- a/src/ui/simulator/toolbox/components/datagrid/renderer/area/renewable.areasummary.cpp +++ b/src/ui/simulator/toolbox/components/datagrid/renderer/area/renewable.areasummary.cpp @@ -71,7 +71,7 @@ wxString RenewableClusterSummarySingleArea::columnCaption(int colIndx) const wxString RenewableClusterSummarySingleArea::cellValue(int x, int y) const { Data::RenewableCluster* cluster = (pArea and (uint) y < pArea->renewable.list.size()) - ? pArea->renewable.list.cluster[y].get() + ? pArea->renewable.list.clusters[y].get() : nullptr; switch (x) { @@ -90,7 +90,7 @@ wxString RenewableClusterSummarySingleArea::cellValue(int x, int y) const double RenewableClusterSummarySingleArea::cellNumericValue(int x, int y) const { Data::RenewableCluster* cluster = (pArea and (uint) y < pArea->renewable.list.size()) - ? pArea->renewable.list.cluster[y].get() + ? pArea->renewable.list.clusters[y].get() : nullptr; // gp : do we wish to have the line empty if cluster disabled // if (!cluster->enabled) @@ -112,7 +112,7 @@ double RenewableClusterSummarySingleArea::cellNumericValue(int x, int y) const bool RenewableClusterSummarySingleArea::cellValue(int x, int y, const String& v) { auto* cluster = (pArea and (uint) y < pArea->renewable.list.size()) - ? pArea->renewable.list.cluster[y].get() + ? pArea->renewable.list.clusters[y].get() : nullptr; if (cluster) From 824282e55a75760fb72356371669c9a142b6e177 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Mon, 18 Dec 2023 15:10:19 +0100 Subject: [PATCH 33/54] [DEV] Comments, removed groupCount --- src/libs/antares/study/parts/common/cluster_list.cpp | 3 +-- src/libs/antares/study/parts/common/cluster_list.h | 9 --------- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index fc317b0249..57d9cde22f 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -92,7 +92,7 @@ bool ClusterList::exists(const Data::ClusterName& id) const } template -Data::ClusterList::ClusterList() : groupCount(ClusterT::groupMax, 0) +Data::ClusterList::ClusterList() { } @@ -172,7 +172,6 @@ typename ClusterList::SharedPtr ClusterList::add( return newcluster; clusters.push_back(newcluster); - ++(groupCount[newcluster->groupId()]); rebuildIndex(); return newcluster; } diff --git a/src/libs/antares/study/parts/common/cluster_list.h b/src/libs/antares/study/parts/common/cluster_list.h index 23ce8e565a..019264dd7c 100644 --- a/src/libs/antares/study/parts/common/cluster_list.h +++ b/src/libs/antares/study/parts/common/cluster_list.h @@ -194,15 +194,6 @@ class ClusterList // thermal, renewable, etc. virtual YString typeID() const = 0; - /*! - ** \brief Number of dispatchable clusters per group - ** - ** You should rely on these values only after the loading of the study - ** and until the study is not modified. - ** These values are modified by 'ClusterListAdd()' - */ - std::vector groupCount; - bool loadDataSeriesFromFolder(Study& study, const StudyLoadOptions& options, const AnyString& folder); From a52ea6783f071dcdda4d5b333279d34b4c175a31 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Mon, 18 Dec 2023 15:31:38 +0100 Subject: [PATCH 34/54] [DEV] more comments --- .../InfoCollection/StudyInfoCollector.cpp | 5 ++--- src/libs/antares/study/parts/common/cluster.cpp | 4 ++-- .../antares/study/parts/common/cluster_list.cpp | 16 ++++++---------- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/libs/antares/InfoCollection/StudyInfoCollector.cpp b/src/libs/antares/InfoCollection/StudyInfoCollector.cpp index 3f67705dcf..ba626a59ed 100644 --- a/src/libs/antares/InfoCollection/StudyInfoCollector.cpp +++ b/src/libs/antares/InfoCollection/StudyInfoCollector.cpp @@ -59,9 +59,8 @@ void StudyInfoCollector::enabledThermalClustersCountToFileContent(FileContent& f for (auto i = study_.areas.begin(); i != end; ++i) { Area& area = *(i->second); - for (const auto& cluster : area.thermal.list) - if (cluster->enabled) - nbEnabledThermalClusters++; + nbEnabledThermalClusters += + std::ranges::count_if(area.thermal.list, [](const auto& c) { return c->enabled; }); } // Adding an item related to number of enabled thermal clusters to the file content diff --git a/src/libs/antares/study/parts/common/cluster.cpp b/src/libs/antares/study/parts/common/cluster.cpp index 79d119d476..d10e116c9c 100644 --- a/src/libs/antares/study/parts/common/cluster.cpp +++ b/src/libs/antares/study/parts/common/cluster.cpp @@ -65,7 +65,7 @@ bool Cluster::saveDataSeriesToFolder(const AnyString& folder) const return ret; } - return false; + return true; } bool Cluster::loadDataSeriesFromFolder(Study& s, const AnyString& folder) @@ -75,7 +75,7 @@ bool Cluster::loadDataSeriesFromFolder(Study& s, const AnyString& folder) auto& buffer = s.bufferLoadingTS; - bool ret = 1; + bool ret = true; buffer.clear() << folder << SEP << parentArea->id << SEP << id() << SEP << "series." << s.inputExtension; ret = series.timeSeries.loadFromCSVFile(buffer, 1, HOURS_PER_YEAR, &s.dataBuffer) && ret; diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index 57d9cde22f..1e7e5777f6 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -60,21 +60,17 @@ typename ClusterList::const_iterator ClusterList::end() cons template ClusterT* ClusterList::find(const Data::ClusterName& id) const { - for (const auto& c : clusters) - if (c->id() == id) - return c.get(); + const auto& it = std::ranges::find_if(clusters, [&id](auto& c) { return c->id() == id; }); - return nullptr; + return (it != clusters.end()) ? it->get() : nullptr; } template const ClusterT* ClusterList::find(const ClusterT* p) const { - for (const auto& c : clusters) - if (c.get() == p) - return c.get(); + const auto& it = std::ranges::find_if(clusters, [&p](const auto& c) { return c->id() == p->id(); }); - return nullptr; + return (it != clusters.end()) ? it->get() : nullptr; } template @@ -332,11 +328,11 @@ uint ClusterList::removeDisabledClusters() if (empty()) return 0; - std::erase_if(clusters, [] (auto& c) { return !c->enabled; }); + auto count = std::erase_if(clusters, [] (auto& c) { return !c->enabled; }); rebuildIndex(); - return size(); + return count; } // Force template instantiation template class ClusterList; From 92b2896291b7e532c3d7c35bcc6bc633a84e8196 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Mon, 18 Dec 2023 15:43:24 +0100 Subject: [PATCH 35/54] [DEV] rebuildIndex protected --- .../study/parts/common/cluster_list.cpp | 1 + .../antares/study/parts/common/cluster_list.h | 23 ++++++++++--------- .../antares/study/parts/thermal/container.cpp | 7 ------ .../antares-study/thermal-cluster/create.cpp | 1 - .../toolbox/input/renewable-cluster.cpp | 1 - .../toolbox/input/thermal-cluster.cpp | 3 --- 6 files changed, 13 insertions(+), 23 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index 1e7e5777f6..0a70a9138f 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -78,6 +78,7 @@ typename std::shared_ptr ClusterList::detach(iterator i) { SharedPtr c = *i; clusters.erase(i); + rebuildIndex(); return c; } diff --git a/src/libs/antares/study/parts/common/cluster_list.h b/src/libs/antares/study/parts/common/cluster_list.h index 019264dd7c..7ad892a35a 100644 --- a/src/libs/antares/study/parts/common/cluster_list.h +++ b/src/libs/antares/study/parts/common/cluster_list.h @@ -31,7 +31,6 @@ class ClusterList //! const iterator using const_iterator = typename Vect::const_iterator; -public: //! \name Constructor & Destructor //@{ /*! @@ -171,15 +170,7 @@ class ClusterList */ void markAsModified() const; - /*! - ** \brief Rebuild the index of clusters - ** - ** As a list of clusters is a hash table, it is not - ** possible to directly accees to a clusters from its index. - ** However an index can be built but it must be re-built when - ** the hash table is modified. - */ - void rebuildIndex(); + /*! ** \brief Get the size (bytes) occupied in memory by a `ClusterList` structure @@ -187,7 +178,6 @@ class ClusterList */ uint64_t memoryUsage() const; -public: //! All clusters Vect clusters; @@ -230,6 +220,17 @@ class ClusterList */ uint removeDisabledClusters(); +protected: + /*! + ** \brief Rebuild the index of clusters + ** + ** As a list of clusters is a hash table, it is not + ** possible to directly accees to a clusters from its index. + ** However an index can be built but it must be re-built when + ** the hash table is modified. + */ + void rebuildIndex(); + //@} }; // class ClusterList } // namespace Data diff --git a/src/libs/antares/study/parts/thermal/container.cpp b/src/libs/antares/study/parts/thermal/container.cpp index c3feaf0357..e98f3c5c22 100644 --- a/src/libs/antares/study/parts/thermal/container.cpp +++ b/src/libs/antares/study/parts/thermal/container.cpp @@ -124,13 +124,6 @@ uint PartThermal::prepareClustersInMustRunMode() } } while (mustContinue); - // if some thermal cluster has been moved, we must rebuild all the indexes - if (count) - { - list.rebuildIndex(); - mustrunList.rebuildIndex(); - } - return count; } diff --git a/src/ui/action/handler/antares-study/thermal-cluster/create.cpp b/src/ui/action/handler/antares-study/thermal-cluster/create.cpp index 07eb50f546..67fcebb757 100644 --- a/src/ui/action/handler/antares-study/thermal-cluster/create.cpp +++ b/src/ui/action/handler/antares-study/thermal-cluster/create.cpp @@ -181,7 +181,6 @@ bool Create::performWL(Context& ctx) ctx.cluster->setName(pFuturPlantName); ctx.cluster->reset(); (ctx.area)->thermal.list.add(std::shared_ptr(ctx.cluster)); - (ctx.area)->thermal.list.rebuildIndex(); (ctx.area)->thermal.prepareAreaWideIndexes(); } else diff --git a/src/ui/simulator/toolbox/input/renewable-cluster.cpp b/src/ui/simulator/toolbox/input/renewable-cluster.cpp index c3ed76d564..08bbb8f748 100644 --- a/src/ui/simulator/toolbox/input/renewable-cluster.cpp +++ b/src/ui/simulator/toolbox/input/renewable-cluster.cpp @@ -291,7 +291,6 @@ void RenewableCluster::internalDeletePlant(void*) Refresh(); MarkTheStudyAsModified(); updateInnerValues(); - pArea->renewable.list.rebuildIndex(); pArea->renewable.prepareAreaWideIndexes(); study->uiinfo->reload(); } diff --git a/src/ui/simulator/toolbox/input/thermal-cluster.cpp b/src/ui/simulator/toolbox/input/thermal-cluster.cpp index 0a40b9ee29..bc31719088 100644 --- a/src/ui/simulator/toolbox/input/thermal-cluster.cpp +++ b/src/ui/simulator/toolbox/input/thermal-cluster.cpp @@ -317,7 +317,6 @@ void ThermalCluster::internalDeletePlant(void*) Refresh(); MarkTheStudyAsModified(); updateInnerValues(); - pArea->thermal.list.rebuildIndex(); pArea->thermal.prepareAreaWideIndexes(); study->uiinfo->reload(); @@ -448,7 +447,6 @@ void ThermalCluster::internalAddPlant(void*) cluster->setName(sFl); cluster->reset(); pArea->thermal.list.add(cluster); - pArea->thermal.list.rebuildIndex(); pArea->thermal.prepareAreaWideIndexes(); // Update the list @@ -527,7 +525,6 @@ void ThermalCluster::internalClonePlant(void*) cluster->copyFrom(selectedPlant); pArea->thermal.list.add(cluster); - pArea->thermal.list.rebuildIndex(); pArea->thermal.prepareAreaWideIndexes(); // Update the list From e7f28c38166b22cf645975059fdd3dda45939b63 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Mon, 18 Dec 2023 16:01:56 +0100 Subject: [PATCH 36/54] [DEV] doxygen comments --- .../antares/study/parts/common/cluster_list.h | 51 +++++-------------- 1 file changed, 13 insertions(+), 38 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.h b/src/libs/antares/study/parts/common/cluster_list.h index 7ad892a35a..6861631144 100644 --- a/src/libs/antares/study/parts/common/cluster_list.h +++ b/src/libs/antares/study/parts/common/cluster_list.h @@ -15,33 +15,22 @@ namespace Antares namespace Data { /*! -** \brief List of clusters +** \brief Generic list of clusters ** \ingroup renewableclusters +** This class implements the base functions for a list of cluster +** It's used for thermal and renewable clusters */ template class ClusterList { public: - // Shared pointer using SharedPtr = typename std::shared_ptr; - // Vector container using Vect = typename std::vector; - //! iterator using iterator = typename Vect::iterator; - //! const iterator using const_iterator = typename Vect::const_iterator; - //! \name Constructor & Destructor - //@{ - /*! - ** \brief Default constructor - */ ClusterList(); - /*! - ** \brief Destructor - */ virtual ~ClusterList(); - //@} //! \name Iterating //@{ @@ -133,18 +122,14 @@ class ClusterList //! Get the number of items in the list uint size() const; - //! Get if the list is empty + //! Return true if the list is empty bool empty() const; //@} - //! iterator to the begining of the list iterator begin(); - //! iterator to the begining of the list const_iterator begin() const; - //! iterator to the end of the list iterator end(); - //! iterator to the end of the list const_iterator end() const; /*! @@ -158,8 +143,6 @@ class ClusterList //@} - //! \name Memory management - //@{ /*! ** \brief Invalidate all clusters */ @@ -171,19 +154,17 @@ class ClusterList void markAsModified() const; - /*! ** \brief Get the size (bytes) occupied in memory by a `ClusterList` structure ** \return A size (in bytes) */ uint64_t memoryUsage() const; - //! All clusters + /// The vector containing the clusters Vect clusters; - // thermal, renewable, etc. - virtual YString typeID() const = 0; - + /// \name IO functions + /// @{ bool loadDataSeriesFromFolder(Study& study, const StudyLoadOptions& options, const AnyString& folder); @@ -193,9 +174,8 @@ class ClusterList bool saveDataSeriesToFolder(const AnyString& folder, const YString& msg) const; virtual bool saveToFolder(const AnyString& folder) const = 0; + ///@} - //! \name Informations - //@{ /*! ** \brief Retrieve the total capacity and the total unit count ** @@ -220,18 +200,13 @@ class ClusterList */ uint removeDisabledClusters(); -protected: - /*! - ** \brief Rebuild the index of clusters - ** - ** As a list of clusters is a hash table, it is not - ** possible to directly accees to a clusters from its index. - ** However an index can be built but it must be re-built when - ** the hash table is modified. - */ +private: + /// thermal, renewable, etc. + virtual YString typeID() const = 0; + + /// Sort the vector, set index value for each cluster void rebuildIndex(); - //@} }; // class ClusterList } // namespace Data } // namespace Antares From 66a1852d42264770151818c8eb4eb287cbbcc0dd Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Mon, 18 Dec 2023 16:21:19 +0100 Subject: [PATCH 37/54] [DEV] std::string typeID --- src/libs/antares/study/parts/common/cluster_list.cpp | 2 +- src/libs/antares/study/parts/common/cluster_list.h | 2 +- src/libs/antares/study/parts/renewable/cluster_list.cpp | 5 ----- src/libs/antares/study/parts/renewable/cluster_list.h | 3 +-- src/libs/antares/study/parts/thermal/cluster_list.cpp | 5 ----- src/libs/antares/study/parts/thermal/cluster_list.h | 4 +--- 6 files changed, 4 insertions(+), 17 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index 0a70a9138f..8350055ad6 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -136,7 +136,7 @@ void ClusterList::storeTimeseriesNumbers(Solver::IResultWriter& writer std::string ts_content; each([&](const Cluster& cluster) { - path.clear() << "ts-numbers" << SEP << typeID() << SEP << cluster.parentArea->id << SEP + path.clear() << "ts-numbers" << SEP << typeID << SEP << cluster.parentArea->id << SEP << cluster.id() << ".txt"; ts_content.clear(); // We must clear ts_content here, since saveToBuffer does not do it. cluster.series.timeseriesNumbers.saveToBuffer(ts_content, 0, true, predicate, true); diff --git a/src/libs/antares/study/parts/common/cluster_list.h b/src/libs/antares/study/parts/common/cluster_list.h index 6861631144..16e3f51d67 100644 --- a/src/libs/antares/study/parts/common/cluster_list.h +++ b/src/libs/antares/study/parts/common/cluster_list.h @@ -202,7 +202,7 @@ class ClusterList private: /// thermal, renewable, etc. - virtual YString typeID() const = 0; + std::string typeID = "common"; /// Sort the vector, set index value for each cluster void rebuildIndex(); diff --git a/src/libs/antares/study/parts/renewable/cluster_list.cpp b/src/libs/antares/study/parts/renewable/cluster_list.cpp index 5669429dff..16e5d494c2 100644 --- a/src/libs/antares/study/parts/renewable/cluster_list.cpp +++ b/src/libs/antares/study/parts/renewable/cluster_list.cpp @@ -10,11 +10,6 @@ namespace Antares namespace Data { -YString RenewableClusterList::typeID() const -{ - return "renewables"; -} - #define SEP IO::Separator bool RenewableClusterList::saveToFolder(const AnyString& folder) const diff --git a/src/libs/antares/study/parts/renewable/cluster_list.h b/src/libs/antares/study/parts/renewable/cluster_list.h index e4c3018ace..7a6749ac94 100644 --- a/src/libs/antares/study/parts/renewable/cluster_list.h +++ b/src/libs/antares/study/parts/renewable/cluster_list.h @@ -16,8 +16,7 @@ namespace Data class RenewableClusterList : public ClusterList { public: - // Overriden virtual methods - YString typeID() const override; + std::string typeID = "renewables"; bool loadFromFolder(const AnyString& folder, Area* area); bool saveToFolder(const AnyString& folder) const override; }; // class RenewableClusterList diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index 8ed5fd0e64..52b40de0bd 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -145,11 +145,6 @@ bool ThermalClusterList::loadFromFolder(Study& study, const AnyString& folder, A return ret; } -YString ThermalClusterList::typeID() const -{ - return "thermal"; -} - static bool ThermalClusterLoadFromProperty(ThermalCluster& cluster, const IniFile::Property* p) { if (p->key.empty()) diff --git a/src/libs/antares/study/parts/thermal/cluster_list.h b/src/libs/antares/study/parts/thermal/cluster_list.h index 25d13b2088..79ade80003 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.h +++ b/src/libs/antares/study/parts/thermal/cluster_list.h @@ -13,12 +13,10 @@ namespace Data class ThermalClusterList : public ClusterList { public: + std::string typeID = "thermal"; // Map container using Map = typename std::map>; - // Overriden pure virtual methods - YString typeID() const override; - /*! ** \brief Get the size (bytes) occupied in memory by a `ThermalClusterList` structure ** \return A size (in bytes) From 1dffea3efab161e9a45c595a3c162548f44839ff Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Mon, 18 Dec 2023 16:54:32 +0100 Subject: [PATCH 38/54] [DEV] Remove non const each(predicate), use std::for_each for const one --- src/libs/antares/study/parts/common/cluster_list.h | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.h b/src/libs/antares/study/parts/common/cluster_list.h index 16e3f51d67..cf785d5c46 100644 --- a/src/libs/antares/study/parts/common/cluster_list.h +++ b/src/libs/antares/study/parts/common/cluster_list.h @@ -32,25 +32,13 @@ class ClusterList ClusterList(); virtual ~ClusterList(); - //! \name Iterating - //@{ - /*! - ** \brief Iterate through all clusters - */ - template - void each(const PredicateT& predicate) - { - for (auto& c : clusters) - predicate(*c); - } /*! ** \brief Iterate through all clusters (const) */ template void each(const PredicateT& predicate) const { - for (const auto& c : clusters) - predicate(*c); + std::ranges::for_each(clusters, [&predicate](const auto& c) { predicate(*c); }); } //! \name clusters management From 2afb8119cf6d6cf661fbaef2e0aea67a86c93a9e Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Mon, 18 Dec 2023 17:03:26 +0100 Subject: [PATCH 39/54] [DEV] add operator overload --- src/libs/antares/study/parts/common/cluster_list.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libs/antares/study/parts/common/cluster_list.h b/src/libs/antares/study/parts/common/cluster_list.h index cf785d5c46..16ba025750 100644 --- a/src/libs/antares/study/parts/common/cluster_list.h +++ b/src/libs/antares/study/parts/common/cluster_list.h @@ -120,6 +120,8 @@ class ClusterList iterator end(); const_iterator end() const; + SharedPtr& operator[](std::size_t idx) { return clusters[idx]; } + const SharedPtr& operator[](std::size_t idx) const { return clusters[idx]; } /*! ** \brief Resize all matrices dedicated to the sampled timeseries numbers ** From 334928ef5cfd94dde1532e747a6e944805595494 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Mon, 18 Dec 2023 17:20:16 +0100 Subject: [PATCH 40/54] [DEV] vector clusters protected --- src/libs/antares/study/parts/common/cluster_list.h | 7 ++++--- src/libs/antares/study/parts/thermal/cluster_list.cpp | 5 ++--- .../study/scenario-builder/RenewableTSNumberData.cpp | 4 ++-- .../study/scenario-builder/ThermalTSNumberData.cpp | 4 ++-- src/libs/antares/study/study.cpp | 2 +- src/solver/simulation/sim_calcul_economique.cpp | 2 +- src/solver/simulation/timeseries-numbers.cpp | 10 +++------- .../variable/economy/productionByRenewablePlant.h | 2 +- src/solver/variable/info.h | 2 +- .../datagrid/renderer/area/renewable.areasummary.cpp | 8 ++++---- .../datagrid/renderer/area/thermal.areasummary.cpp | 8 ++++---- .../renderer/scenario-builder-renewable-renderer.cpp | 4 ++-- .../renderer/scenario-builder-thermal-renderer.cpp | 4 ++-- 13 files changed, 29 insertions(+), 33 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.h b/src/libs/antares/study/parts/common/cluster_list.h index 16ba025750..84643c0caf 100644 --- a/src/libs/antares/study/parts/common/cluster_list.h +++ b/src/libs/antares/study/parts/common/cluster_list.h @@ -150,9 +150,6 @@ class ClusterList */ uint64_t memoryUsage() const; - /// The vector containing the clusters - Vect clusters; - /// \name IO functions /// @{ bool loadDataSeriesFromFolder(Study& study, @@ -190,6 +187,10 @@ class ClusterList */ uint removeDisabledClusters(); +protected: + /// The vector containing the clusters + Vect clusters; + private: /// thermal, renewable, etc. std::string typeID = "common"; diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index 52b40de0bd..9bd2e85207 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -273,8 +273,7 @@ void ThermalClusterList::calculationOfSpinning() void ThermalClusterList::reverseCalculationOfSpinning() { - for (const auto& c : clusters) - c->reverseCalculationOfSpinning(); + each([&](ThermalCluster& cluster) { cluster.reverseCalculationOfSpinning(); }); } void ThermalClusterList::enableMustrunForEveryone() @@ -484,7 +483,7 @@ bool ThermalClusterList::loadEconomicCosts(Study& study, const AnyString& folder return true; - return std::all_of(clusters.begin(), clusters.end(), [&study, folder](const auto& c) + return std::ranges::all_of(clusters, [&study, folder](const auto& c) { assert(c->parentArea && "cluster: invalid parent area"); Clob buffer; diff --git a/src/libs/antares/study/scenario-builder/RenewableTSNumberData.cpp b/src/libs/antares/study/scenario-builder/RenewableTSNumberData.cpp index d927743163..808fa9f93b 100644 --- a/src/libs/antares/study/scenario-builder/RenewableTSNumberData.cpp +++ b/src/libs/antares/study/scenario-builder/RenewableTSNumberData.cpp @@ -79,12 +79,12 @@ void renewableTSNumberData::saveToINIFile(const Study& /* study */, // Foreach renewable cluster... for (uint y = 0; y != pTSNumberRules.height; ++y) { - const uint val = get(pArea->renewable.list.clusters[index].get(), y); + const uint val = get(pArea->renewable.list[index].get(), y); // Equals to zero means 'auto', which is the default mode if (!val) continue; file << prefix << pArea->id << "," << y << ',' - << pArea->renewable.list.clusters[index]->id() << " = " << val << '\n'; + << pArea->renewable.list[index]->id() << " = " << val << '\n'; } } } diff --git a/src/libs/antares/study/scenario-builder/ThermalTSNumberData.cpp b/src/libs/antares/study/scenario-builder/ThermalTSNumberData.cpp index a09a8c5150..b67ede4039 100644 --- a/src/libs/antares/study/scenario-builder/ThermalTSNumberData.cpp +++ b/src/libs/antares/study/scenario-builder/ThermalTSNumberData.cpp @@ -49,12 +49,12 @@ void thermalTSNumberData::saveToINIFile(const Study& /* study */, // Foreach year ... for (uint y = 0; y != pTSNumberRules.height; ++y) { - const uint val = get(pArea->thermal.list.clusters[index].get(), y); + const uint val = get(pArea->thermal.list[index].get(), y); // Equals to zero means 'auto', which is the default mode if (!val) continue; file << prefix << pArea->id << "," << y << ',' - << pArea->thermal.list.clusters[index]->id() << " = " << val << '\n'; + << pArea->thermal.list[index]->id() << " = " << val << '\n'; } } } diff --git a/src/libs/antares/study/study.cpp b/src/libs/antares/study/study.cpp index bb3ed24f21..0615baa8b8 100644 --- a/src/libs/antares/study/study.cpp +++ b/src/libs/antares/study/study.cpp @@ -1530,7 +1530,7 @@ void Study::computePThetaInfForThermalClusters() const for (uint j = 0; j < area.thermal.list.size(); j++) { // Alias du cluster courant - auto& cluster = area.thermal.list.clusters[j]; + auto& cluster = area.thermal.list[j]; for (uint k = 0; k < HOURS_PER_YEAR; k++) cluster->PthetaInf[k] = cluster->modulation[Data::thermalMinGenModulation][k] * cluster->unitCount * cluster->nominalCapacity; diff --git a/src/solver/simulation/sim_calcul_economique.cpp b/src/solver/simulation/sim_calcul_economique.cpp index 087ad8d178..cb582d723c 100644 --- a/src/solver/simulation/sim_calcul_economique.cpp +++ b/src/solver/simulation/sim_calcul_economique.cpp @@ -285,7 +285,7 @@ void SIM_InitialisationProblemeHebdo(Data::Study& study, for (uint clusterIndex = 0; clusterIndex != area.thermal.list.size(); ++clusterIndex) { - auto& cluster = *(area.thermal.list.clusters[clusterIndex]); + auto& cluster = *(area.thermal.list[clusterIndex]); pbPalier.NumeroDuPalierDansLEnsembleDesPaliersThermiques[clusterIndex] = NombrePaliers + clusterIndex; pbPalier.TailleUnitaireDUnGroupeDuPalierThermique[clusterIndex] diff --git a/src/solver/simulation/timeseries-numbers.cpp b/src/solver/simulation/timeseries-numbers.cpp index 346983f95a..30cc4b32dc 100644 --- a/src/solver/simulation/timeseries-numbers.cpp +++ b/src/solver/simulation/timeseries-numbers.cpp @@ -555,10 +555,8 @@ void storeTSnumbersForIntraModal(const array& intramo if (isTSintramodal[indexTS]) { - auto end_rn_clusters = area.renewable.list.clusters.end(); - for (auto j = area.renewable.list.clusters.begin(); j != end_rn_clusters; ++j) + for (auto& cluster : area.renewable.list) { - RenewableClusterList::SharedPtr cluster = *j; if (cluster->enabled) cluster->series.timeseriesNumbers[0][year] = intramodal_draws[indexTS]; } @@ -667,10 +665,8 @@ void drawAndStoreTSnumbersForNOTintraModal(const array& i // -------------------------- indexTS = ts_to_tsIndex.at(timeSeriesRenewable); - auto end_rn_clusters = area.renewable.list.clusters.end(); - for (auto j = area.renewable.list.clusters.begin(); j != end_rn_clusters; ++j) + for (auto& cluster : area.renewable.list) { - RenewableClusterList::SharedPtr cluster = *j; if (not cluster->enabled) study.runtime->random[seedTimeseriesNumbers].next(); else @@ -747,7 +743,7 @@ Matrix* getFirstTSnumberInterModalMatrixFoundInArea( tsNumbersMtx = &(area.thermal.clusters[0]->series.timeseriesNumbers); else if (isTSintermodal[ts_to_tsIndex.at(timeSeriesRenewable)] && area.renewable.list.size() > 0) - tsNumbersMtx = &(area.renewable.list.clusters[0]->series.timeseriesNumbers); + tsNumbersMtx = &(area.renewable.list[0]->series.timeseriesNumbers); } assert(tsNumbersMtx); diff --git a/src/solver/variable/economy/productionByRenewablePlant.h b/src/solver/variable/economy/productionByRenewablePlant.h index a7eb726fca..e1b08a189f 100644 --- a/src/solver/variable/economy/productionByRenewablePlant.h +++ b/src/solver/variable/economy/productionByRenewablePlant.h @@ -327,7 +327,7 @@ class ProductionByRenewablePlant : public Variable::IVariablename(); + results.variableCaption = renewable.list[i]->name(); results.variableUnit = VCardType::Unit(); pValuesForTheCurrentYear[numSpace][i].template buildAnnualSurveyReport( results, fileLevel, precision); diff --git a/src/solver/variable/info.h b/src/solver/variable/info.h index 2fc48353f8..c07bf1ab60 100644 --- a/src/solver/variable/info.h +++ b/src/solver/variable/info.h @@ -407,7 +407,7 @@ struct VariableAccessor if (renewable_details) { auto& renewable = results.data.area->renewable; - results.variableCaption = renewable.list.clusters[idx]->name(); + results.variableCaption = renewable.list[idx]->name(); return true; } if (st_storage_details) diff --git a/src/ui/simulator/toolbox/components/datagrid/renderer/area/renewable.areasummary.cpp b/src/ui/simulator/toolbox/components/datagrid/renderer/area/renewable.areasummary.cpp index 46e3878002..db746f9632 100644 --- a/src/ui/simulator/toolbox/components/datagrid/renderer/area/renewable.areasummary.cpp +++ b/src/ui/simulator/toolbox/components/datagrid/renderer/area/renewable.areasummary.cpp @@ -51,7 +51,7 @@ RenewableClusterSummarySingleArea::~RenewableClusterSummarySingleArea() wxString RenewableClusterSummarySingleArea::rowCaption(int rowIndx) const { if (pArea) - return wxStringFromUTF8(pArea->renewable.list.clusters[rowIndx]->name()); + return wxStringFromUTF8(pArea->renewable.list[rowIndx]->name()); return wxEmptyString; } @@ -71,7 +71,7 @@ wxString RenewableClusterSummarySingleArea::columnCaption(int colIndx) const wxString RenewableClusterSummarySingleArea::cellValue(int x, int y) const { Data::RenewableCluster* cluster = (pArea and (uint) y < pArea->renewable.list.size()) - ? pArea->renewable.list.clusters[y].get() + ? pArea->renewable.list[y].get() : nullptr; switch (x) { @@ -90,7 +90,7 @@ wxString RenewableClusterSummarySingleArea::cellValue(int x, int y) const double RenewableClusterSummarySingleArea::cellNumericValue(int x, int y) const { Data::RenewableCluster* cluster = (pArea and (uint) y < pArea->renewable.list.size()) - ? pArea->renewable.list.clusters[y].get() + ? pArea->renewable.list[y].get() : nullptr; // gp : do we wish to have the line empty if cluster disabled // if (!cluster->enabled) @@ -112,7 +112,7 @@ double RenewableClusterSummarySingleArea::cellNumericValue(int x, int y) const bool RenewableClusterSummarySingleArea::cellValue(int x, int y, const String& v) { auto* cluster = (pArea and (uint) y < pArea->renewable.list.size()) - ? pArea->renewable.list.clusters[y].get() + ? pArea->renewable.list[y].get() : nullptr; if (cluster) diff --git a/src/ui/simulator/toolbox/components/datagrid/renderer/area/thermal.areasummary.cpp b/src/ui/simulator/toolbox/components/datagrid/renderer/area/thermal.areasummary.cpp index e36fad8189..ce87ecace2 100644 --- a/src/ui/simulator/toolbox/components/datagrid/renderer/area/thermal.areasummary.cpp +++ b/src/ui/simulator/toolbox/components/datagrid/renderer/area/thermal.areasummary.cpp @@ -51,7 +51,7 @@ ThermalClusterSummarySingleArea::~ThermalClusterSummarySingleArea() wxString ThermalClusterSummarySingleArea::rowCaption(int rowIndx) const { if (pArea) - return wxStringFromUTF8(pArea->thermal.list.clusters[rowIndx]->name()); + return wxStringFromUTF8(pArea->thermal.list[rowIndx]->name()); return wxEmptyString; } @@ -82,7 +82,7 @@ wxString ThermalClusterSummarySingleArea::columnCaption(int colIndx) const wxString ThermalClusterSummarySingleArea::cellValue(int x, int y) const { Data::ThermalCluster* cluster = (pArea and (uint) y < pArea->thermal.list.size()) - ? pArea->thermal.list.clusters[y].get() + ? pArea->thermal.list[y].get() : nullptr; if (!cluster->enabled) return wxEmptyString; @@ -125,7 +125,7 @@ wxString ThermalClusterSummarySingleArea::cellValue(int x, int y) const double ThermalClusterSummarySingleArea::cellNumericValue(int x, int y) const { Data::ThermalCluster* cluster = (pArea and (uint) y < pArea->thermal.list.size()) - ? pArea->thermal.list.clusters[y].get() + ? pArea->thermal.list[y].get() : nullptr; if (!cluster->enabled) return 0.; @@ -168,7 +168,7 @@ double ThermalClusterSummarySingleArea::cellNumericValue(int x, int y) const bool ThermalClusterSummarySingleArea::cellValue(int x, int y, const String& v) { auto* cluster = (pArea and (uint) y < pArea->thermal.list.size()) - ? pArea->thermal.list.clusters[y].get() + ? pArea->thermal.list[y].get() : nullptr; if (cluster) diff --git a/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-renewable-renderer.cpp b/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-renewable-renderer.cpp index c0265d2d24..f2af7d9660 100644 --- a/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-renewable-renderer.cpp +++ b/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-renewable-renderer.cpp @@ -54,7 +54,7 @@ wxString renewableScBuilderRenderer::rowCaption(int rowIndx) const && (uint)rowIndx < selectedArea()->renewable.list.size()) { return wxString() << wxT( - " ") << wxStringFromUTF8(selectedArea()->renewable.list.clusters[rowIndx]->name()) + " ") << wxStringFromUTF8(selectedArea()->renewable.list[rowIndx]->name()) << wxT(" "); } return wxEmptyString; @@ -70,7 +70,7 @@ bool renewableScBuilderRenderer::cellValue(int x, int y, const String& value) assert((uint)x < pRules->renewable[selectedArea()->index].height()); uint val = fromStringToTSnumber(value); pRules->renewable[selectedArea()->index].setTSnumber( - selectedArea()->renewable.list.clusters[y].get(), x, val); + selectedArea()->renewable.list[y].get(), x, val); return true; } return false; diff --git a/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-thermal-renderer.cpp b/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-thermal-renderer.cpp index a803ec2b3a..c8e333c1c8 100644 --- a/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-thermal-renderer.cpp +++ b/src/ui/simulator/toolbox/components/datagrid/renderer/scenario-builder-thermal-renderer.cpp @@ -54,7 +54,7 @@ wxString thermalScBuilderRenderer::rowCaption(int rowIndx) const && (uint)rowIndx < selectedArea()->thermal.list.size()) { return wxString() << wxT(" ") - << wxStringFromUTF8(selectedArea()->thermal.list.clusters[rowIndx]->name()) + << wxStringFromUTF8(selectedArea()->thermal.list[rowIndx]->name()) << wxT(" "); } return wxEmptyString; @@ -69,7 +69,7 @@ bool thermalScBuilderRenderer::cellValue(int x, int y, const String& value) assert((uint)y < pRules->thermal[selectedArea()->index].width()); assert((uint)x < pRules->thermal[selectedArea()->index].height()); uint val = fromStringToTSnumber(value); - pRules->thermal[selectedArea()->index].setTSnumber(selectedArea()->thermal.list.clusters[y].get(), x, val); + pRules->thermal[selectedArea()->index].setTSnumber(selectedArea()->thermal.list[y].get(), x, val); return true; } return false; From fff7e6051b67853f66bbd8dffc4d0123bc712ce2 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Mon, 18 Dec 2023 17:53:58 +0100 Subject: [PATCH 41/54] [DEV] study.cpp loop --- src/libs/antares/study/study.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/libs/antares/study/study.cpp b/src/libs/antares/study/study.cpp index 0615baa8b8..63a7a714b2 100644 --- a/src/libs/antares/study/study.cpp +++ b/src/libs/antares/study/study.cpp @@ -1527,10 +1527,8 @@ void Study::computePThetaInfForThermalClusters() const // Alias de la zone courant const auto& area = *(this->areas.byIndex[i]); - for (uint j = 0; j < area.thermal.list.size(); j++) + for (auto& cluster : area.thermal.list) { - // Alias du cluster courant - auto& cluster = area.thermal.list[j]; for (uint k = 0; k < HOURS_PER_YEAR; k++) cluster->PthetaInf[k] = cluster->modulation[Data::thermalMinGenModulation][k] * cluster->unitCount * cluster->nominalCapacity; From f2244f761af02e09a27b74c76dc49041d694d4d7 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Tue, 19 Dec 2023 10:24:35 +0100 Subject: [PATCH 42/54] [DEV] remove useless empty --- .../study/parts/common/cluster_list.cpp | 24 ++++--------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index 8350055ad6..2463762df0 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -110,17 +110,10 @@ template void ClusterList::resizeAllTimeseriesNumbers(uint n) { assert(n < 200000); // arbitrary number - if (not clusters.empty()) - { - if (0 == n) - { - each([&](Cluster& cluster) { cluster.series.timeseriesNumbers.clear(); }); - } - else - { - each([&](Cluster& cluster) { cluster.series.timeseriesNumbers.resize(1, n); }); - } - } + if (n == 0) + each([&](Cluster& cluster) { cluster.series.timeseriesNumbers.clear(); }); + else + each([&](Cluster& cluster) { cluster.series.timeseriesNumbers.resize(1, n); }); } #define SEP IO::Separator @@ -128,9 +121,6 @@ void ClusterList::resizeAllTimeseriesNumbers(uint n) template void ClusterList::storeTimeseriesNumbers(Solver::IResultWriter& writer) const { - if (clusters.empty()) - return; - TSNumbersPredicate predicate; Clob path; std::string ts_content; @@ -274,9 +264,6 @@ bool ClusterList::saveDataSeriesToFolder(const AnyString& folder) cons template bool ClusterList::saveDataSeriesToFolder(const AnyString& folder, const String& msg) const { - if (empty()) - return true; - bool ret = true; uint ticks = 0; @@ -295,9 +282,6 @@ bool ClusterList::loadDataSeriesFromFolder(Study& s, const StudyLoadOptions& options, const AnyString& folder) { - if (empty()) - return true; - bool ret = true; each([&](ClusterT& c) { From 716c8587305eead69ddedde01742506634081781 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Mon, 18 Dec 2023 17:39:34 +0100 Subject: [PATCH 43/54] [FIX] Adapt C++ 20 for win : make code compile when C++ 20 is forced --- src/libs/antares/sys/policy.cpp | 2 +- src/tools/yby-aggregator/job.cpp | 2 +- src/ui/simulator/windows/inspector/inspector.cpp | 2 +- src/ui/simulator/windows/output/spotlight-provider.cpp | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libs/antares/sys/policy.cpp b/src/libs/antares/sys/policy.cpp index c45de88af5..dabd748d10 100644 --- a/src/libs/antares/sys/policy.cpp +++ b/src/libs/antares/sys/policy.cpp @@ -75,7 +75,7 @@ static void OpenFromINIFileWL(const String& filename, const StringT& hostname) ini.each([&](const IniFile::Section& section) { // This section is dedicated to another host if (section.name == "*:*" or section.name == "*:" ANTARES_VERSION - or section.name == hostnameAll or section.name == hostnameVersion) + or section.name.equals(hostnameAll) or section.name == hostnameVersion) { section.each([&](const IniFile::Property& property) { key = property.key; diff --git a/src/tools/yby-aggregator/job.cpp b/src/tools/yby-aggregator/job.cpp index 95b75dd7f3..6e4b405ea2 100644 --- a/src/tools/yby-aggregator/job.cpp +++ b/src/tools/yby-aggregator/job.cpp @@ -378,7 +378,7 @@ bool JobFileReader::prepareJumpTable() const DataFile::ShortString& timeLevel = datafile->timeLevel; for (uint i = 0; i != list.size(); ++i) { - if (timeLevel == list[i]) + if (timeLevel.equals(list[i])) { startIndex = i + 1; break; diff --git a/src/ui/simulator/windows/inspector/inspector.cpp b/src/ui/simulator/windows/inspector/inspector.cpp index d895d26f1c..500ec48711 100644 --- a/src/ui/simulator/windows/inspector/inspector.cpp +++ b/src/ui/simulator/windows/inspector/inspector.cpp @@ -704,7 +704,7 @@ bool isConstraintSelected(const Yuni::String& constraintName) for (auto i = gData->constraints.begin(); i != end; ++i) { auto constraint = *i; - if (constraint->name() == constraintName) + if (constraint->name().equals(constraintName)) { return true; } diff --git a/src/ui/simulator/windows/output/spotlight-provider.cpp b/src/ui/simulator/windows/output/spotlight-provider.cpp index 0eb1cc5528..8f4877bf10 100644 --- a/src/ui/simulator/windows/output/spotlight-provider.cpp +++ b/src/ui/simulator/windows/output/spotlight-provider.cpp @@ -421,8 +421,8 @@ void SpotlightProviderGlobalSelection::search(Spotlight::IItem::Vector& out, auto aEnd = study.areas.end(); for (auto itArea = study.areas.begin(); itArea != aEnd; ++itArea) { - if (arealink->id == itArea->first) // this area is in the study (it is visible - // at least on layer 0) + if (arealink->id.equals(itArea->first)) // this area is in the study (it is visible + // at least on layer 0) { foundInALayer = true; break; @@ -482,7 +482,7 @@ void SpotlightProviderGlobalSelection::search(Spotlight::IItem::Vector& out, auto aEnd = study.areas.end(); for (auto itArea = study.areas.begin(); itArea != aEnd; ++itArea) { - if (arealink->id == itArea->first + if (arealink->id.equals(itArea->first) && itArea->second->isVisibleOnLayer( layerID)) // this area is in the study (it is visible at least on layer 0) { From a653b1ca73987d4a3861ed4dbebdadc3c7c27912 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Tue, 19 Dec 2023 16:28:17 +0100 Subject: [PATCH 44/54] [DEV] simplify common clusters : use algorithm instead of a loop --- .../study/parts/thermal/cluster_list.cpp | 54 +++++++------------ src/libs/antares/sys/policy.cpp | 2 +- 2 files changed, 21 insertions(+), 35 deletions(-) diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index 9bd2e85207..41a35e329c 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -1,6 +1,7 @@ #include "cluster_list.h" #include "cluster.h" #include "../../study.h" +#include namespace // anonymous { @@ -406,9 +407,6 @@ bool ThermalClusterList::saveToFolder(const AnyString& folder) const bool ThermalClusterList::savePreproToFolder(const AnyString& folder) const { - if (empty()) - return true; - Clob buffer; bool ret = true; @@ -425,9 +423,6 @@ bool ThermalClusterList::savePreproToFolder(const AnyString& folder) const bool ThermalClusterList::saveEconomicCosts(const AnyString& folder) const { - if (empty()) - return true; - Clob buffer; bool ret = true; @@ -443,46 +438,37 @@ bool ThermalClusterList::loadPreproFromFolder(Study& study, const StudyLoadOptions& options, const AnyString& folder) { - if (empty()) - return true; - const bool globalThermalTSgeneration - = study.parameters.timeSeriesToGenerate & timeSeriesThermal; + = study.parameters.timeSeriesToGenerate & timeSeriesThermal; Clob buffer; - bool ret = true; - - for (const auto& c : clusters) + auto hasPrepro = [&](auto c) + { + ++options.progressTicks; + options.pushProgressLogs(); + return (bool) c->prepro; + }; + + auto loadAndCheckPrepro = [&](auto c) { - if (c->prepro) - { - assert(c->parentArea && "cluster: invalid parent area"); - buffer.clear() << folder << SEP << c->parentArea->id << SEP << c->id(); - - bool result = c->prepro->loadFromFolder(study, buffer); + assert(c->parentArea && "cluster: invalid parent area"); + buffer.clear() << folder << SEP << c->parentArea->id << SEP << c->id(); - if (result && study.usedByTheSolver && c->doWeGenerateTS(globalThermalTSgeneration)) - { - // checking NPO max - result = c->prepro->normalizeAndCheckNPO(); - } + bool result = c->prepro->loadFromFolder(study, buffer); - ret = result && ret; + if (result && study.usedByTheSolver && c->doWeGenerateTS(globalThermalTSgeneration)) + { + result = c->prepro->normalizeAndCheckNPO(); } + return result; + }; - ++options.progressTicks; - options.pushProgressLogs(); - } - return ret; + return std::ranges::all_of(clusters | std::views::filter(hasPrepro), + loadAndCheckPrepro); } - bool ThermalClusterList::loadEconomicCosts(Study& study, const AnyString& folder) { - if (empty()) - return true; - - return std::ranges::all_of(clusters, [&study, folder](const auto& c) { assert(c->parentArea && "cluster: invalid parent area"); diff --git a/src/libs/antares/sys/policy.cpp b/src/libs/antares/sys/policy.cpp index dabd748d10..fd51aca74a 100644 --- a/src/libs/antares/sys/policy.cpp +++ b/src/libs/antares/sys/policy.cpp @@ -75,7 +75,7 @@ static void OpenFromINIFileWL(const String& filename, const StringT& hostname) ini.each([&](const IniFile::Section& section) { // This section is dedicated to another host if (section.name == "*:*" or section.name == "*:" ANTARES_VERSION - or section.name.equals(hostnameAll) or section.name == hostnameVersion) + or section.name.equals(hostnameAll) or section.name.equals(hostnameVersion)) { section.each([&](const IniFile::Property& property) { key = property.key; From e95d5a2cc206b219bb11f77a38169a20afb5e5b7 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Tue, 19 Dec 2023 16:56:16 +0100 Subject: [PATCH 45/54] [DEV] using ranges allof --- src/libs/antares/study/parts/common/cluster_list.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index 2463762df0..d2cea81da2 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -256,7 +256,7 @@ bool ClusterList::remove(const Data::ClusterName& id) template bool ClusterList::saveDataSeriesToFolder(const AnyString& folder) const { - return std::all_of(clusters.begin(), clusters.end(), [&folder](const auto& c){ + return std::ranges::all_of(clusters, [&folder](const auto& c){ return c->saveDataSeriesToFolder(folder); }); } @@ -264,17 +264,15 @@ bool ClusterList::saveDataSeriesToFolder(const AnyString& folder) cons template bool ClusterList::saveDataSeriesToFolder(const AnyString& folder, const String& msg) const { - bool ret = true; uint ticks = 0; - for (const auto& c : clusters) + return std::ranges::all_of(clusters, [&](const auto& c) { logs.info() << msg << " " << (ticks * 100 / (1 + this->clusters.size())) << "% complete"; - ret = c->saveDataSeriesToFolder(folder) && ret; ++ticks; - } - return ret; + return c->saveDataSeriesToFolder(folder); + }); } template From 4177cc3a0b20490b6dbb61e630c9d522e0fecca3 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Tue, 19 Dec 2023 16:58:34 +0100 Subject: [PATCH 46/54] [DEV] remove reference for operator overload --- src/libs/antares/study/parts/common/cluster_list.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.h b/src/libs/antares/study/parts/common/cluster_list.h index 84643c0caf..c63e9705f9 100644 --- a/src/libs/antares/study/parts/common/cluster_list.h +++ b/src/libs/antares/study/parts/common/cluster_list.h @@ -120,8 +120,8 @@ class ClusterList iterator end(); const_iterator end() const; - SharedPtr& operator[](std::size_t idx) { return clusters[idx]; } - const SharedPtr& operator[](std::size_t idx) const { return clusters[idx]; } + SharedPtr operator[](std::size_t idx) { return clusters[idx]; } + const SharedPtr operator[](std::size_t idx) const { return clusters[idx]; } /*! ** \brief Resize all matrices dedicated to the sampled timeseries numbers ** From e620d6e387ebe4745c2ca0c6e0e03beca36f0bef Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Tue, 19 Dec 2023 17:14:14 +0100 Subject: [PATCH 47/54] [DEV] remove detach function --- src/libs/antares/study/parts/common/cluster_list.cpp | 9 --------- src/libs/antares/study/parts/common/cluster_list.h | 9 --------- src/libs/antares/study/parts/thermal/container.cpp | 8 ++++---- src/ui/simulator/toolbox/components/map/manager.cpp | 2 +- 4 files changed, 5 insertions(+), 23 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index d2cea81da2..f853332197 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -73,15 +73,6 @@ const ClusterT* ClusterList::find(const ClusterT* p) const return (it != clusters.end()) ? it->get() : nullptr; } -template -typename std::shared_ptr ClusterList::detach(iterator i) -{ - SharedPtr c = *i; - clusters.erase(i); - rebuildIndex(); - return c; -} - template bool ClusterList::exists(const Data::ClusterName& id) const { diff --git a/src/libs/antares/study/parts/common/cluster_list.h b/src/libs/antares/study/parts/common/cluster_list.h index c63e9705f9..b26072a884 100644 --- a/src/libs/antares/study/parts/common/cluster_list.h +++ b/src/libs/antares/study/parts/common/cluster_list.h @@ -56,15 +56,6 @@ class ClusterList */ SharedPtr add(const SharedPtr clusters); - /*! - ** \brief Detach a clusters represented by an iterator - ** - ** The clusters will be removed from the list but _not_ - ** destroyed. - ** The iterator should considered as invalid after using this method. - ** \return A pointer to the clusters, NULL if an error has occured - */ - SharedPtr detach(iterator i); /*! ** \brief Try to find a clusters from its id (const) diff --git a/src/libs/antares/study/parts/thermal/container.cpp b/src/libs/antares/study/parts/thermal/container.cpp index e98f3c5c22..429d062bb6 100644 --- a/src/libs/antares/study/parts/thermal/container.cpp +++ b/src/libs/antares/study/parts/thermal/container.cpp @@ -96,12 +96,12 @@ uint PartThermal::prepareClustersInMustRunMode() do { mustContinue = false; - for (auto i = list.begin(); i != list.end(); ++i) + for (auto& c : clusters) { - if ((*i)->mustrun) + if (c->mustrun) { - // Detaching the thermal cluster from the main list... - std::shared_ptr cluster = list.detach(i); + list.remove(c->id()); + std::shared_ptr cluster(c); if (!cluster->enabled) continue; // ...and attaching it into the second list diff --git a/src/ui/simulator/toolbox/components/map/manager.cpp b/src/ui/simulator/toolbox/components/map/manager.cpp index d6030be21c..f5559641e0 100644 --- a/src/ui/simulator/toolbox/components/map/manager.cpp +++ b/src/ui/simulator/toolbox/components/map/manager.cpp @@ -768,7 +768,7 @@ void Manager::selectFromBoundingBox(const wxPoint& a, const wxPoint& b, const si for (Data::ThermalClusterList::iterator t = area->thermal.list.begin(); t != tend; ++t) - clusterlist.push_back((*t).get()); + clusterlist.push_back(t->get()); } continue; } From 601da5a6385162b1ab1863757d8e7bb3d4a66320 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Wed, 20 Dec 2023 11:07:59 +0100 Subject: [PATCH 48/54] [DEV] Add virtual func typeID back --- src/libs/antares/study/parts/common/cluster_list.cpp | 2 +- src/libs/antares/study/parts/common/cluster_list.h | 4 ++-- src/libs/antares/study/parts/renewable/cluster_list.cpp | 5 +++++ src/libs/antares/study/parts/renewable/cluster_list.h | 2 +- src/libs/antares/study/parts/thermal/cluster_list.cpp | 5 +++++ src/libs/antares/study/parts/thermal/cluster_list.h | 2 +- 6 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index f853332197..1604fe4812 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -117,7 +117,7 @@ void ClusterList::storeTimeseriesNumbers(Solver::IResultWriter& writer std::string ts_content; each([&](const Cluster& cluster) { - path.clear() << "ts-numbers" << SEP << typeID << SEP << cluster.parentArea->id << SEP + path.clear() << "ts-numbers" << SEP << typeID() << SEP << cluster.parentArea->id << SEP << cluster.id() << ".txt"; ts_content.clear(); // We must clear ts_content here, since saveToBuffer does not do it. cluster.series.timeseriesNumbers.saveToBuffer(ts_content, 0, true, predicate, true); diff --git a/src/libs/antares/study/parts/common/cluster_list.h b/src/libs/antares/study/parts/common/cluster_list.h index b26072a884..fee79c4dc7 100644 --- a/src/libs/antares/study/parts/common/cluster_list.h +++ b/src/libs/antares/study/parts/common/cluster_list.h @@ -182,10 +182,10 @@ class ClusterList /// The vector containing the clusters Vect clusters; -private: /// thermal, renewable, etc. - std::string typeID = "common"; + virtual std::string typeID() const = 0; +private: /// Sort the vector, set index value for each cluster void rebuildIndex(); diff --git a/src/libs/antares/study/parts/renewable/cluster_list.cpp b/src/libs/antares/study/parts/renewable/cluster_list.cpp index 16e5d494c2..e23f84fe2a 100644 --- a/src/libs/antares/study/parts/renewable/cluster_list.cpp +++ b/src/libs/antares/study/parts/renewable/cluster_list.cpp @@ -12,6 +12,11 @@ namespace Data #define SEP IO::Separator +std::string RenewableClusterList::typeID() const +{ + return "renewables"; +} + bool RenewableClusterList::saveToFolder(const AnyString& folder) const { // Make sure the folder is created diff --git a/src/libs/antares/study/parts/renewable/cluster_list.h b/src/libs/antares/study/parts/renewable/cluster_list.h index 7a6749ac94..21f50b3694 100644 --- a/src/libs/antares/study/parts/renewable/cluster_list.h +++ b/src/libs/antares/study/parts/renewable/cluster_list.h @@ -16,7 +16,7 @@ namespace Data class RenewableClusterList : public ClusterList { public: - std::string typeID = "renewables"; + std::string typeID() const override; bool loadFromFolder(const AnyString& folder, Area* area); bool saveToFolder(const AnyString& folder) const override; }; // class RenewableClusterList diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index 41a35e329c..3867bfeca4 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -33,6 +33,11 @@ ThermalClusterList::~ThermalClusterList() #define SEP IO::Separator +std::string ThermalClusterList::typeID() const +{ + return "thermal"; +} + static bool ThermalClusterLoadFromSection(const AnyString& filename, ThermalCluster& cluster, const IniFile::Section& section); diff --git a/src/libs/antares/study/parts/thermal/cluster_list.h b/src/libs/antares/study/parts/thermal/cluster_list.h index 79ade80003..b23164bfb0 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.h +++ b/src/libs/antares/study/parts/thermal/cluster_list.h @@ -13,7 +13,7 @@ namespace Data class ThermalClusterList : public ClusterList { public: - std::string typeID = "thermal"; + std::string typeID() const override; // Map container using Map = typename std::map>; From ea797e634e7c245f1d01a2fc23a5a0ab3cfd54d2 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Wed, 20 Dec 2023 11:15:05 +0100 Subject: [PATCH 49/54] [DEV] Clean save cluster function --- src/libs/antares/study/parts/common/cluster.cpp | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster.cpp b/src/libs/antares/study/parts/common/cluster.cpp index d10e116c9c..265b8f4d51 100644 --- a/src/libs/antares/study/parts/common/cluster.cpp +++ b/src/libs/antares/study/parts/common/cluster.cpp @@ -55,17 +55,12 @@ bool Cluster::saveDataSeriesToFolder(const AnyString& folder) const return true; Yuni::Clob buffer; - buffer.clear() << folder << SEP << parentArea->id << SEP << id(); - if (Yuni::IO::Directory::Create(buffer)) - { - bool ret = true; - buffer.clear() << folder << SEP << parentArea->id << SEP << id() << SEP << "series.txt"; - ret = series.timeSeries.saveToCSVFile(buffer, precision()) && ret; - - return ret; - } - return true; + if (!Yuni::IO::Directory::Create(buffer)) + return true; + + buffer.clear() << folder << SEP << parentArea->id << SEP << id() << SEP << "series.txt"; + return series.timeSeries.saveToCSVFile(buffer, precision()); } bool Cluster::loadDataSeriesFromFolder(Study& s, const AnyString& folder) From 9096788215692bce7f229cc5ef0ee375f5735ce7 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Wed, 20 Dec 2023 12:28:27 +0100 Subject: [PATCH 50/54] [DEV] simplify ts function --- src/libs/antares/study/parts/common/cluster_list.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index 1604fe4812..e0fed2b78e 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -100,11 +100,7 @@ void ClusterList::clear() template void ClusterList::resizeAllTimeseriesNumbers(uint n) { - assert(n < 200000); // arbitrary number - if (n == 0) - each([&](Cluster& cluster) { cluster.series.timeseriesNumbers.clear(); }); - else - each([&](Cluster& cluster) { cluster.series.timeseriesNumbers.resize(1, n); }); + each([&](Cluster& cluster) { cluster.series.timeseriesNumbers.resize(1, n); }); } #define SEP IO::Separator From f9a5d52bf5588cdb4dd8f1b04d22822ee0a1b989 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Wed, 20 Dec 2023 12:38:04 +0100 Subject: [PATCH 51/54] Revert "[DEV] remove detach function" This reverts commit e620d6e387ebe4745c2ca0c6e0e03beca36f0bef. --- src/libs/antares/study/parts/common/cluster_list.cpp | 9 +++++++++ src/libs/antares/study/parts/common/cluster_list.h | 9 +++++++++ src/libs/antares/study/parts/thermal/container.cpp | 8 ++++---- src/ui/simulator/toolbox/components/map/manager.cpp | 2 +- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index e0fed2b78e..a9ff4532ab 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -73,6 +73,15 @@ const ClusterT* ClusterList::find(const ClusterT* p) const return (it != clusters.end()) ? it->get() : nullptr; } +template +typename std::shared_ptr ClusterList::detach(iterator i) +{ + SharedPtr c = *i; + clusters.erase(i); + rebuildIndex(); + return c; +} + template bool ClusterList::exists(const Data::ClusterName& id) const { diff --git a/src/libs/antares/study/parts/common/cluster_list.h b/src/libs/antares/study/parts/common/cluster_list.h index fee79c4dc7..b7e8971897 100644 --- a/src/libs/antares/study/parts/common/cluster_list.h +++ b/src/libs/antares/study/parts/common/cluster_list.h @@ -56,6 +56,15 @@ class ClusterList */ SharedPtr add(const SharedPtr clusters); + /*! + ** \brief Detach a clusters represented by an iterator + ** + ** The clusters will be removed from the list but _not_ + ** destroyed. + ** The iterator should considered as invalid after using this method. + ** \return A pointer to the clusters, NULL if an error has occured + */ + SharedPtr detach(iterator i); /*! ** \brief Try to find a clusters from its id (const) diff --git a/src/libs/antares/study/parts/thermal/container.cpp b/src/libs/antares/study/parts/thermal/container.cpp index 429d062bb6..e98f3c5c22 100644 --- a/src/libs/antares/study/parts/thermal/container.cpp +++ b/src/libs/antares/study/parts/thermal/container.cpp @@ -96,12 +96,12 @@ uint PartThermal::prepareClustersInMustRunMode() do { mustContinue = false; - for (auto& c : clusters) + for (auto i = list.begin(); i != list.end(); ++i) { - if (c->mustrun) + if ((*i)->mustrun) { - list.remove(c->id()); - std::shared_ptr cluster(c); + // Detaching the thermal cluster from the main list... + std::shared_ptr cluster = list.detach(i); if (!cluster->enabled) continue; // ...and attaching it into the second list diff --git a/src/ui/simulator/toolbox/components/map/manager.cpp b/src/ui/simulator/toolbox/components/map/manager.cpp index f5559641e0..d6030be21c 100644 --- a/src/ui/simulator/toolbox/components/map/manager.cpp +++ b/src/ui/simulator/toolbox/components/map/manager.cpp @@ -768,7 +768,7 @@ void Manager::selectFromBoundingBox(const wxPoint& a, const wxPoint& b, const si for (Data::ThermalClusterList::iterator t = area->thermal.list.begin(); t != tend; ++t) - clusterlist.push_back(t->get()); + clusterlist.push_back((*t).get()); } continue; } From 486a64aab7f758c83a3bc608b03c44b97ea64077 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Wed, 20 Dec 2023 14:35:23 +0100 Subject: [PATCH 52/54] [DEV] remove find(cluster) --- .../study/parts/common/cluster_list.cpp | 8 ---- .../antares/study/parts/common/cluster_list.h | 44 ++++++++----------- 2 files changed, 18 insertions(+), 34 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index a9ff4532ab..cc8e1ce8b1 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -65,14 +65,6 @@ ClusterT* ClusterList::find(const Data::ClusterName& id) const return (it != clusters.end()) ? it->get() : nullptr; } -template -const ClusterT* ClusterList::find(const ClusterT* p) const -{ - const auto& it = std::ranges::find_if(clusters, [&p](const auto& c) { return c->id() == p->id(); }); - - return (it != clusters.end()) ? it->get() : nullptr; -} - template typename std::shared_ptr ClusterList::detach(iterator i) { diff --git a/src/libs/antares/study/parts/common/cluster_list.h b/src/libs/antares/study/parts/common/cluster_list.h index b7e8971897..f907b49a21 100644 --- a/src/libs/antares/study/parts/common/cluster_list.h +++ b/src/libs/antares/study/parts/common/cluster_list.h @@ -49,61 +49,53 @@ class ClusterList void clear(); /*! - ** \brief Add a clusters in the list + ** \brief Add a cluster in the list ** - ** \param t The clusters to add - ** \return True if the clusters has been added, false otherwise + ** \param t The cluster to add + ** \return True if the cluster has been added, false otherwise */ SharedPtr add(const SharedPtr clusters); /*! - ** \brief Detach a clusters represented by an iterator + ** \brief Detach a cluster represented by an iterator ** - ** The clusters will be removed from the list but _not_ + ** The cluster will be removed from the list but _not_ ** destroyed. ** The iterator should considered as invalid after using this method. - ** \return A pointer to the clusters, NULL if an error has occured + ** \return A pointer to the cluster, NULL if an error has occured */ SharedPtr detach(iterator i); /*! - ** \brief Try to find a clusters from its id (const) + ** \brief Try to find a cluster from its id (const) ** - ** \param id ID of the clusters to find - ** \return A pointer to a clusters. nullptr if not found + ** \param id ID of the cluster to find + ** \return A pointer to a cluster. nullptr if not found */ ClusterT* find(const Data::ClusterName& id) const; /*! - ** \brief Try to find a clusters from its pointer (const) + ** \brief Get if a cluster exists ** - ** \param p Pointer of the clusters to find - ** \return A pointer to a clusters. nullptr if not found - */ - const ClusterT* find(const ClusterT* p) const; - - /*! - ** \brief Get if a clusters exists - ** - ** \param id ID of the clusters to find - ** \return True if the clusters exists + ** \param id ID of the cluster to find + ** \return True if the cluster exists */ bool exists(const Data::ClusterName& id) const; /*! - ** \brief Rename a clusters + ** \brief Rename a cluster ** - ** \param idToFind ID of the clusters to rename - ** \param newName The new name for the clusters - ** \return True if the operation succeeded (the clusters has been renamed) - ** false otherwise (not found or if another clusters has the same name) + ** \param idToFind ID of the cluster to rename + ** \param newName The new name for the cluster + ** \return True if the operation succeeded (the cluster has been renamed) + ** false otherwise (not found or if another cluster has the same name) ** ** The indexes for clusters will be rebuilt. */ bool rename(Data::ClusterName idToFind, Data::ClusterName newName); /*! - ** \brief Remove properly a clusters + ** \brief Remove properly a cluster */ virtual bool remove(const Data::ClusterName& id); From dd96d283232accd40674b4bf87b537c31f943aca Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Wed, 20 Dec 2023 14:58:17 +0100 Subject: [PATCH 53/54] [DEV] remove constructor destructor --- .../antares/study/parts/common/cluster_list.cpp | 14 -------------- src/libs/antares/study/parts/common/cluster_list.h | 3 --- 2 files changed, 17 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index cc8e1ce8b1..e965a9c83d 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -80,18 +80,6 @@ bool ClusterList::exists(const Data::ClusterName& id) const return std::ranges::any_of(clusters, [&id](const auto& c){ return c->id() == id; }); } -template -Data::ClusterList::ClusterList() -{ -} - -template -Data::ClusterList::~ClusterList() -{ - // deleting all renewable clusters - clear(); -} - template void ClusterList::clear() { @@ -134,8 +122,6 @@ void ClusterList::rebuildIndex() c->index = indx++; } - - template typename ClusterList::SharedPtr ClusterList::add( const ClusterList::SharedPtr newcluster) diff --git a/src/libs/antares/study/parts/common/cluster_list.h b/src/libs/antares/study/parts/common/cluster_list.h index f907b49a21..f937e2eca6 100644 --- a/src/libs/antares/study/parts/common/cluster_list.h +++ b/src/libs/antares/study/parts/common/cluster_list.h @@ -29,9 +29,6 @@ class ClusterList using iterator = typename Vect::iterator; using const_iterator = typename Vect::const_iterator; - ClusterList(); - virtual ~ClusterList(); - /*! ** \brief Iterate through all clusters (const) */ From 8c55141e04296f4c94108f358dfac1fb9936fb2f Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Wed, 20 Dec 2023 15:05:08 +0100 Subject: [PATCH 54/54] [DEV] remove detach function --- .../study/parts/common/cluster_list.cpp | 9 ---- .../antares/study/parts/common/cluster_list.h | 10 ----- .../antares/study/parts/thermal/container.cpp | 44 +++++++++---------- 3 files changed, 22 insertions(+), 41 deletions(-) diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index e965a9c83d..bc5f8e5aa5 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -65,15 +65,6 @@ ClusterT* ClusterList::find(const Data::ClusterName& id) const return (it != clusters.end()) ? it->get() : nullptr; } -template -typename std::shared_ptr ClusterList::detach(iterator i) -{ - SharedPtr c = *i; - clusters.erase(i); - rebuildIndex(); - return c; -} - template bool ClusterList::exists(const Data::ClusterName& id) const { diff --git a/src/libs/antares/study/parts/common/cluster_list.h b/src/libs/antares/study/parts/common/cluster_list.h index f937e2eca6..9f3899aa8b 100644 --- a/src/libs/antares/study/parts/common/cluster_list.h +++ b/src/libs/antares/study/parts/common/cluster_list.h @@ -51,17 +51,7 @@ class ClusterList ** \param t The cluster to add ** \return True if the cluster has been added, false otherwise */ - SharedPtr add(const SharedPtr clusters); - /*! - ** \brief Detach a cluster represented by an iterator - ** - ** The cluster will be removed from the list but _not_ - ** destroyed. - ** The iterator should considered as invalid after using this method. - ** \return A pointer to the cluster, NULL if an error has occured - */ - SharedPtr detach(iterator i); /*! ** \brief Try to find a cluster from its id (const) diff --git a/src/libs/antares/study/parts/thermal/container.cpp b/src/libs/antares/study/parts/thermal/container.cpp index e98f3c5c22..a88bdf1e72 100644 --- a/src/libs/antares/study/parts/thermal/container.cpp +++ b/src/libs/antares/study/parts/thermal/container.cpp @@ -96,31 +96,31 @@ uint PartThermal::prepareClustersInMustRunMode() do { mustContinue = false; - for (auto i = list.begin(); i != list.end(); ++i) + for (auto cluster : list) { - if ((*i)->mustrun) + if (!cluster->mustrun) + continue; + + // Detaching the thermal cluster from the main list... + list.remove(cluster->id()); + if (!cluster->enabled) + continue; + // ...and attaching it into the second list + if (!mustrunList.add(cluster)) { - // Detaching the thermal cluster from the main list... - std::shared_ptr cluster = list.detach(i); - if (!cluster->enabled) - continue; - // ...and attaching it into the second list - if (!mustrunList.add(cluster)) - { - logs.error() << "Impossible to prepare the thermal cluster in 'must-run' mode: " - << cluster->parentArea->name << "::" << cluster->name(); - } - else - { - ++count; - logs.info() << "enabling 'must-run' mode for the cluster " - << cluster->parentArea->name << "::" << cluster->name(); - } - - // the iterator has been invalidated, loop again - mustContinue = true; - break; + logs.error() << "Impossible to prepare the thermal cluster in 'must-run' mode: " + << cluster->parentArea->name << "::" << cluster->name(); } + else + { + ++count; + logs.info() << "enabling 'must-run' mode for the cluster " + << cluster->parentArea->name << "::" << cluster->name(); + } + + // the iterator has been invalidated, loop again + mustContinue = true; + break; } } while (mustContinue);