22 #ifndef CRNIterativeClustering_HEADER
23 #define CRNIterativeClustering_HEADER
44 typename std::enable_if<
46 std::is_copy_assignable<T>::value &&
48 traits::HasLT<T>::value
63 inline const std::vector<std::set<T>>&
GetClusters()
const {
return clusters; }
75 auto found =
size_t{0};
77 for (
auto cluster =
size_t(0); cluster < clusters.size(); ++cluster)
79 if (clusters[cluster].find(v1) != clusters[cluster].end())
81 if (clusters[cluster].insert(v2).second)
91 if (clusters[cluster].find(v2) != clusters[cluster].end())
93 if (clusters[cluster].insert(v1).second)
106 clusters.push_back(std::set<T>());
107 clusters.back().insert(v1);
108 clusters.back().insert(v2);
112 for (
auto cluster = found + 1; cluster < clusters.size(); ++cluster)
114 if (clusters[cluster].find(leftover) != clusters[cluster].end())
116 clusters[found].insert(clusters[cluster].begin(), clusters[cluster].end());
117 clusters.erase(clusters.begin() + cluster);
131 for (
const auto &c : clusters)
134 for (
const auto& v : c)
145 std::vector<std::set<T>> clusters;
Operation Associate(const T &v1, const T &v2)
Associates two elements and merges clusters if needed.
crn::String ToString() const
Prints the clusters to a string.
IterativeClustering & operator=(const IterativeClustering &)=default
A UTF32 character string class.
const std::vector< std::set< T > > & GetClusters() const
Gets the current clusters.
A utility class to create clusters iteratively.
IterativeClustering()=default