Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor common ClusterList class #1813

Merged
merged 58 commits into from
Dec 20, 2023
Merged
Changes from 1 commit
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
695d608
[DEV] Use vect instead of map
payetvin Dec 7, 2023
4ec8de1
[DEV] Change iterator typedef with vector iterator
payetvin Dec 8, 2023
dc72732
[DEV] FIx renewable
payetvin Dec 8, 2023
228280f
[DEV] More modif in common cluster_list
payetvin Dec 8, 2023
e68f7ed
[DEV] no error common clusterlist
payetvin Dec 8, 2023
8eeeb38
[FIX] compile cleaner-v20
payetvin Dec 8, 2023
0c2cc7b
[FIX] compile RenewableTSNumberData
payetvin Dec 8, 2023
5891cec
[FIX] compile thermal container
payetvin Dec 8, 2023
50d64f5
[FIX] compile thermal clusterlist
payetvin Dec 8, 2023
586c124
[FIX] compile ui, output var
payetvin Dec 8, 2023
d84cc59
[FIX] timeseries-numbers.cpp
payetvin Dec 8, 2023
35fda32
[FIX] common eco adq
payetvin Dec 8, 2023
1adcf49
[FIX] ui compile
payetvin Dec 8, 2023
039ddbf
[FIX] final compile
payetvin Dec 8, 2023
dd22673
[DEV] Sort cluster
payetvin Dec 8, 2023
d46d034
[DEV] removed byIndex
payetvin Dec 8, 2023
a7c8010
[DEV] small fix on add function
payetvin Dec 11, 2023
058a5b7
[DEV] code smells
payetvin Dec 11, 2023
66053ae
[DEV] comments 1
payetvin Dec 13, 2023
0249803
[DEV] change return type to bool
payetvin Dec 13, 2023
61fb467
[DEV] use std::all_of
payetvin Dec 13, 2023
758b349
[DEV] comments in renewables
payetvin Dec 13, 2023
ea38e89
[DEV] comments 2
payetvin Dec 13, 2023
2399d09
[DEV] refactor removeDisabledClusters by moving it in common
payetvin Dec 13, 2023
e653013
[DEV] comments ui
payetvin Dec 13, 2023
2c87746
[DEV] simplify common clusters : remove 2 useless find functions
guilpier-code Dec 14, 2023
04ce1bc
[DEV] simplify common clusters : "remove" function removal, because u…
guilpier-code Dec 14, 2023
0b42f10
[DEV] simplify common clusters : gathering find(...) functions defini…
guilpier-code Dec 18, 2023
c0de802
Merge branch 'fix/renew-lists' into fix/common-list
payetvin Dec 18, 2023
731076f
[DEV] simplify common clusters : we don't need to handle separately t…
guilpier-code Dec 18, 2023
7000fb1
Merge remote-tracking branch 'remotes/origin/fix/common-list' into fi…
guilpier-code Dec 18, 2023
64f31a3
[DEV] Using ranges and cpp 20 algo
payetvin Dec 18, 2023
e025643
Merge branch 'fix/common-list' of https://github.com/AntaresSimulator…
payetvin Dec 18, 2023
a200914
[DEV] renamed cluster into clusters
payetvin Dec 18, 2023
557201b
[FIX] compile
payetvin Dec 18, 2023
824282e
[DEV] Comments, removed groupCount
payetvin Dec 18, 2023
a52ea67
[DEV] more comments
payetvin Dec 18, 2023
92b2896
[DEV] rebuildIndex protected
payetvin Dec 18, 2023
e7f28c3
[DEV] doxygen comments
payetvin Dec 18, 2023
66a1852
[DEV] std::string typeID
payetvin Dec 18, 2023
1dffea3
[DEV] Remove non const each(predicate), use std::for_each for const one
payetvin Dec 18, 2023
2afb811
[DEV] add operator overload
payetvin Dec 18, 2023
334928e
[DEV] vector clusters protected
payetvin Dec 18, 2023
fff7e60
[DEV] study.cpp loop
payetvin Dec 18, 2023
f2244f7
[DEV] remove useless empty
payetvin Dec 19, 2023
716c858
[FIX] Adapt C++ 20 for win : make code compile when C++ 20 is forced
guilpier-code Dec 18, 2023
a653b1c
[DEV] simplify common clusters : use algorithm instead of a loop
guilpier-code Dec 19, 2023
e95d5a2
[DEV] using ranges allof
payetvin Dec 19, 2023
4177cc3
[DEV] remove reference for operator overload
payetvin Dec 19, 2023
e620d6e
[DEV] remove detach function
payetvin Dec 19, 2023
5545b12
Merge branch 'fix/common-list' of https://github.com/AntaresSimulator…
payetvin Dec 19, 2023
601da5a
[DEV] Add virtual func typeID back
payetvin Dec 20, 2023
ea797e6
[DEV] Clean save cluster function
payetvin Dec 20, 2023
9096788
[DEV] simplify ts function
payetvin Dec 20, 2023
f9a5d52
Revert "[DEV] remove detach function"
payetvin Dec 20, 2023
486a64a
[DEV] remove find(cluster)
payetvin Dec 20, 2023
dd96d28
[DEV] remove constructor destructor
payetvin Dec 20, 2023
8c55141
[DEV] remove detach function
payetvin Dec 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[DEV] renamed cluster into clusters
payetvin committed Dec 18, 2023
commit a20091489fee31aebda3e0c10520ac79ef1cbdc5
56 changes: 28 additions & 28 deletions src/libs/antares/study/parts/common/cluster_list.cpp
Original file line number Diff line number Diff line change
@@ -24,43 +24,43 @@ using namespace Antares;
template<class ClusterT>
inline uint ClusterList<ClusterT>::size() const
{
return (uint)cluster.size();
return (uint)clusters.size();
}

template<class ClusterT>
inline bool ClusterList<ClusterT>::empty() const
{
return cluster.empty();
return clusters.empty();
}

template<class ClusterT>
typename ClusterList<ClusterT>::iterator ClusterList<ClusterT>::begin()
{
return std::begin(cluster);
return std::begin(clusters);
}

template<class ClusterT>
typename ClusterList<ClusterT>::const_iterator ClusterList<ClusterT>::begin() const
{
return std::begin(cluster);
return std::begin(clusters);
}

template<class ClusterT>
typename ClusterList<ClusterT>::iterator ClusterList<ClusterT>::end()
{
return std::end(cluster);
return std::end(clusters);
}

template<class ClusterT>
typename ClusterList<ClusterT>::const_iterator ClusterList<ClusterT>::end() const
{
return std::end(cluster);
return std::end(clusters);
}

template<class ClusterT>
ClusterT* ClusterList<ClusterT>::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<ClusterT>::find(const Data::ClusterName& id) const
template<class ClusterT>
const ClusterT* ClusterList<ClusterT>::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<class ClusterT>
typename std::shared_ptr<ClusterT> ClusterList<ClusterT>::detach(iterator i)
{
SharedPtr c = *i;
cluster.erase(i);
clusters.erase(i);
return c;
}

template<class ClusterT>
bool ClusterList<ClusterT>::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<class ClusterT>
@@ -106,14 +106,14 @@ Data::ClusterList<ClusterT>::~ClusterList()
template<class ClusterT>
void ClusterList<ClusterT>::clear()
{
cluster.clear();
clusters.clear();
}

template<class ClusterT>
void ClusterList<ClusterT>::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<ClusterT>::resizeAllTimeseriesNumbers(uint n)
template<class ClusterT>
void ClusterList<ClusterT>::storeTimeseriesNumbers(Solver::IResultWriter& writer) const
{
if (cluster.empty())
if (clusters.empty())
return;

TSNumbersPredicate predicate;
@@ -150,12 +150,12 @@ void ClusterList<ClusterT>::storeTimeseriesNumbers(Solver::IResultWriter& writer
template<class ClusterT>
void ClusterList<ClusterT>::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<ClusterT>::SharedPtr ClusterList<ClusterT>::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<ClusterT>::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<ClusterT>::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<ClusterT>::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<ClusterT>::rename(Data::ClusterName idToFind, Data::ClusterName
template<class ClusterT>
bool ClusterList<ClusterT>::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<ClusterT>::forceReload(bool reload) const
template<class ClusterT>
void ClusterList<ClusterT>::markAsModified() const
{
for (const auto& c : cluster)
for (const auto& c : clusters)
c->markAsModified();
}

template<class ClusterT>
bool ClusterList<ClusterT>::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<ClusterT>::remove(const Data::ClusterName& id)
template<class ClusterT>
bool ClusterList<ClusterT>::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<ClusterT>::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<ClusterT>::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<ClusterT>::retrieveTotalCapacityAndUnitCount(double& total, uin
template<class ClusterT>
uint ClusterList<ClusterT>::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();

64 changes: 32 additions & 32 deletions src/libs/antares/study/parts/common/cluster_list.h
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ class ClusterList
template<class PredicateT>
void each(const PredicateT& predicate)
{
for (auto& c : cluster)
for (auto& c : clusters)
predicate(*c);
}
/*!
@@ -61,73 +61,73 @@ class ClusterList
template<class PredicateT>
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
*/
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,15 +167,15 @@ class ClusterList
bool forceReload(bool reload = false) const;

/*!
** \brief Mark the cluster as modified
** \brief Mark the clusters as modified
*/
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 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;
Loading