4 #include "../base/algorithm.h"
5 #include "../base/inputsetter.h"
6 #include "../base/measuresetter.h"
7 #include "../base/proxygenerator.h"
8 #include "../base/dissimilaritymeasure.h"
9 #include "../base/solutionprovider.h"
10 #include "../datastructure/doublesolution.h"
12 #include "../exception/invalidruntimeconfigurationexception.h"
41 Lloydtype(std::vector<T>
const& seeds, std::vector<T*>
const* data = NULL,
47 Lloydtype(std::vector<T*>
const& seeds, std::vector<T*>
const* data = NULL,
62 virtual void setInput(std::vector<T*>
const*);
84 generator(g==NULL?NULL:g->clone()), measure(m==NULL?NULL:m->clone()), maxiterations(i)
90 unsigned int i) : seeding(seeds), input(data), generator(g==NULL?NULL:g->clone()),
91 measure(m==NULL?NULL:m->clone()), maxiterations(i)
97 unsigned int i) : input(data), generator(g==NULL?NULL:g->clone()),
98 measure(m==NULL?NULL:m->clone()), maxiterations(i)
104 Algorithm(rhs), input(rhs.input), seeding(rhs.seeding),
105 generator(rhs.generator==NULL?NULL:rhs.generator->clone()),
106 measure(rhs.measure==NULL?NULL:rhs.measure->clone()), maxiterations(rhs.maxiterations)
112 Algorithm::operator=(rhs);
115 delete this->generator;
116 this->generator = pg;
117 delete this->measure;
119 this->input = rhs.
input;
127 delete this->measure;
128 delete this->generator;
133 if (this->input==NULL)
135 if (this->generator==NULL)
137 if (this->measure==NULL)
145 unsigned int k = this->seeding.size();
149 std::set<unsigned int> altered_clusters;
150 for (
unsigned int i=0; i<k; i++)
151 altered_clusters.insert(i);
153 std::vector<std::vector<T*> > partitionzero(k);
154 partitionzero[0] = *this->input;
155 solution->
partitions.push_back(partitionzero);
156 solution->
proxysets.push_back(this->seeding);
159 unsigned int iterations = 0;
166 std::vector<std::vector<T*> > previous = solution->
partitions[0];
167 solution->
partitions[0] = std::vector<std::vector<T*> >(k);
169 for (
unsigned int i=0; i<k; i++)
173 unsigned int size = previous[i].size();
174 for (
unsigned int j=0; j<size; j++)
178 double min = this->measure->dissimilarity(*previous[i][j], solution->
proxysets[0][i]);
180 for (
unsigned int l=0;l<k;l++)
182 double d = this->measure->dissimilarity(*previous[i][j], solution->
proxysets[0][l]);
193 altered_clusters.insert(i);
194 altered_clusters.insert(c);
196 solution->
partitions[0][c].push_back(previous[i][j]);
202 for (std::set<unsigned int>::iterator iter=altered_clusters.begin(); iter!=altered_clusters.end(); ++iter)
208 altered_clusters.clear();
210 if (this->maxiterations>0 && iterations>=this->maxiterations)
232 this->seeding = seeds;
237 this->seeding.clear();
238 unsigned int size = seeds.size();
239 for (
unsigned int i=0;i<size;i++)
240 this->seeding.push_back(*seeds[i]);
245 this->generator = g==NULL?NULL:g->
clone();
250 this->measure = m==NULL?NULL:m->
clone();
Data structure for partitions and proxies.
Lloydtype(std::vector< T * > const *data=NULL, ProxyGenerator< T > *g=NULL, DissimilarityMeasure< T > *m=NULL, unsigned int maxIterations=0)
Constructor initializing input, seeding the centers and configuring the algorithm.
virtual void setMeasure(DissimilarityMeasure< T > const *)
ProxyGenerator< T > * generator
Lloydtype< T > & operator=(const Lloydtype< T > &)
virtual ProxyGenerator< T > * clone() const =0
void setGenerator(ProxyGenerator< T > *)
unsigned int maxiterations
Abstract base class for mechanisms that compute a proxy or representative object for a given set of o...
virtual DissimilarityMeasure< T > * clone() const =0
virtual void setInput(std::vector< T * > const *)
static Lloydtype< T > * toLloydtype(Algorithm *a)
does a dynamic cast of the given Algorithm to Lloydtype
Abstract base class for algorithms.
std::vector< T * > const * input
void setSeeding(std::vector< T > const &)
Interface to propagate the ability to set a DissimilarityMeasure.
DissimilarityMeasure< T > * measure
std::vector< std::vector< T > > proxysets
virtual DoubleSolution< T > * compute()
Abstract base class for dissimilarity measurement.
Indicates that a computation entered an invalid configuration state.
std::vector< std::vector< std::vector< T * > > > partitions