AssociatedPairDataSetBuilder dataset = (AssociatedPairDataSetBuilder)algorithm.getOptimisationProblem().getDataSetBuilder();    for(int i = 0; i < clusters; i++) { double minimum = Double.MAX_VALUE;  Vector centroid = centroidFromParticle(particle, i); for(int j = 0; j < dataset.getNumberOfPatterns(); j++) {  double distance = distanceMeasure.distance(centroid, dataset.getPattern(j)); if(distance < minimum) { minimum = distance;  dataset.setKey(j, new Int(i)); } } }
ClusterableDataSet dataset = (ClusterableDataSet)(algorithm.getOptimisationProblem().getDataSetBuilder());  dataset.assign(centroids);
	public double evaluate(Vector particle) {		PopulationBasedAlgorithm algorithm = (PopulationBasedAlgorithm) Algorithm.get();		AssociatedPairDataSetBuilder dataset = (AssociatedPairDataSetBuilder)algorithm.getOptimisationProblem().getDataSetBuilder();		//update pattern assignations (determine in which cluster a pattern belongs based on its closest centroid)		//run through the entire particle vector (i.e. all the clusters)		for(int i = 0; i < clusters; i++) {			double minimum = Double.MAX_VALUE;			//determine which part of the particle (i.e. which centroid) the patterns should be compared to			Vector centroid = centroidFromParticle(particle, i);			for(int j = 0; j < dataset.getNumberOfPatterns(); j++) {//				System.out.println("centroid size = " + centroid.size() + "; pattern size = " + dataset.getPattern(j).size());				double distance = distanceMeasure.distance(centroid, dataset.getPattern(j));				if(distance < minimum) {					minimum = distance;					//assign pattern j to cluster i					dataset.setKey(j, new Int(i));				}			}		}				//build up a list (Vector) of all the patterns that belong to a certain cluster		//only the patterns that belong to a certain cluster must be used in quantisation error calculation		Vector patternsInCluster = new MixedVector();		double quantisationError = 0.0;		for(int i = 0; i < clusters; i++) {			for(int j = 0; j < dataset.getNumberOfPatterns(); j++) {				if(dataset.getKey(j).getInt() == i) {					patternsInCluster.add(dataset.getPattern(j));				}			}			//no need to do the following if no patterns belong to this cluster (save some time)			if(patternsInCluster.size() > 0) {				//determine which part of the particle (i.e. which centroid) the patterns belonging to this cluster should be compared to				Vector centroid = centroidFromParticle(particle, i);				double averageDistance = 0.0;				for(int j = 0; j < patternsInCluster.size(); j++) {					averageDistance += distanceMeasure.distance(centroid, (Vector)patternsInCluster.get(j));				}//				averageDistance /=  patternsInCluster.size();				quantisationError += averageDistance;				quantisationError /= patternsInCluster.size();				patternsInCluster.clear();			}		}		quantisationError /= clusters;//		System.out.println(quantisationError);		return quantisationError;	}