reallocate method
Associate this instance with the nearest cluster
in clusters
.
Implementation
void reallocate(List<Cluster> clusters) {
num? min;
late Cluster argMin;
for (Cluster c in clusters) {
num d = distanceFrom(c);
if (min == null || min > d) {
min = d;
argMin = c;
}
}
if (cluster != null) {
cluster!.instances.remove(this);
}
cluster = argMin;
cluster!.instances.add(this);
}