Antares Simulator
Power System Simulator
cluster_list.h
1 /*
2  * Copyright 2007-2025, RTE (https://www.rte-france.com)
3  * See AUTHORS.txt
4  * SPDX-License-Identifier: MPL-2.0
5  * This file is part of Antares-Simulator,
6  * Adequacy and Performance assessment for interconnected energy networks.
7  *
8  * Antares_Simulator is free software: you can redistribute it and/or modify
9  * it under the terms of the Mozilla Public Licence 2.0 as published by
10  * the Mozilla Foundation, either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * Antares_Simulator is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * Mozilla Public Licence 2.0 for more details.
17  *
18  * You should have received a copy of the Mozilla Public Licence 2.0
19  * along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>.
20  */
21 #ifndef __ANTARES_LIBS_STUDY_PARTS_COMMON_CLUSTER_LIST_H__
22 #define __ANTARES_LIBS_STUDY_PARTS_COMMON_CLUSTER_LIST_H__
23 
24 #include <algorithm>
25 #include <memory>
26 #include <ranges>
27 #include <vector>
28 
29 #include <antares/logs/logs.h>
30 #include <antares/writer/i_writer.h>
31 
32 #include "../../fwd.h"
33 
34 namespace Antares::Data
35 {
36 
37 // TODO VP: remove template, we can have a regular class in this use case
44 template<class ClusterT>
46 {
47 public:
48  using SharedPtr = typename std::shared_ptr<ClusterT>;
49 
50  void clearAll();
51  bool empty() const;
52 
59  ClusterT* findInAll(std::string_view id) const;
60 
67  bool exists(const std::string& id) const;
68 
69  auto each_enabled() const
70  {
71  return allClusters_ | std::views::filter(&ClusterT::isEnabled);
72  }
73 
74  std::vector<std::shared_ptr<ClusterT>> all() const;
75 
86  bool rename(std::string idToFind, std::string newName);
87 
91  virtual bool remove(const std::string& id);
92 
94 
95  SharedPtr operator[](std::size_t idx)
96  {
97  return allClusters_[idx];
98  }
99 
100  SharedPtr operator[](std::size_t idx) const
101  {
102  return allClusters_[idx];
103  }
104 
105  SharedPtr enabledClusterAt(unsigned int index) const;
111  void resizeAllTimeseriesNumbers(uint n) const;
112 
113  void storeTimeseriesNumbers(Solver::IResultWriter& writer) const;
114 
116 
120  bool forceReload(bool reload = false) const;
121 
125  void markAsModified() const;
126 
129  bool loadDataSeriesFromFolder(Study& study, const std::filesystem::path& folder);
130 
131  bool saveDataSeriesToFolder(const AnyString& folder) const;
132 #ifdef BUILD_UI
133  virtual bool saveToFolder(const AnyString& folder) const = 0;
134 #endif
136 
147  void retrieveTotalCapacityAndUnitCount(double& total, uint& unitCount) const;
148 
149  unsigned int enabledCount() const;
150  unsigned int allClustersCount() const;
151  void addToCompleteList(std::shared_ptr<ClusterT> cluster);
152  void sortCompleteList();
153 
154 protected:
155  std::vector<std::shared_ptr<ClusterT>> allClusters_;
156 
157  virtual std::string typeID() const = 0;
158 
159  // Give a special index to enabled clusters (thermal / renewable)
160  void rebuildIndexes();
161 
162 private:
163  bool alreadyInAllClusters(std::string clusterName);
164 
165 }; // class ClusterList
166 } // namespace Antares::Data
167 #endif /* __ANTARES_LIBS_STUDY_PARTS_COMMON_CLUSTER_LIST_H__ */
Generic list of clustersThis class implements the base functions for a list of cluster It's used for ...
Definition: cluster_list.h:46
void resizeAllTimeseriesNumbers(uint n) const
Resize all matrices dedicated to the sampled timeseries numbers.
Definition: cluster_list.cpp:83
void markAsModified() const
Mark the clusters as modified.
Definition: cluster_list.cpp:228
bool exists(const std::string &id) const
Get if a cluster exists.
Definition: cluster_list.cpp:71
bool rename(std::string idToFind, std::string newName)
Rename a cluster.
Definition: cluster_list.cpp:163
bool forceReload(bool reload=false) const
Invalidate all clusters.
Definition: cluster_list.cpp:221
virtual bool remove(const std::string &id)
Remove properly a cluster.
Definition: cluster_list.cpp:237
ClusterT * findInAll(std::string_view id) const
Try to find a cluster from its id (const) in the complete cluster list.
Definition: cluster_list.cpp:52
void retrieveTotalCapacityAndUnitCount(double &total, uint &unitCount) const
Retrieve the total capacity and the total unit count.
Definition: cluster_list.cpp:265
Definition: study.h:57
Definition: i_writer.h:32