Index: branches/HeuristicLab.VRPEnhancements/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Creators/Cluster.cs
===================================================================
--- branches/HeuristicLab.VRPEnhancements/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Creators/Cluster.cs	(revision 14442)
+++ branches/HeuristicLab.VRPEnhancements/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Creators/Cluster.cs	(revision 14447)
@@ -7,15 +7,17 @@
 namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin {
 
-  public class ClusterAlgorithm<C,CO> where C : Cluster<CO> where CO : ClusterElement {
-
-    public static List<C> KMeans(IRandom random, List<CO> clusterElements, int k, double changeThreshold) {
+  public class ClusterAlgorithm<TCluster,TClusterElement> 
+    where TCluster : Cluster<TClusterElement>, new() 
+    where TClusterElement : ClusterElement, new() {
+
+    public static List<TCluster> KMeans(IRandom random, List<TClusterElement> clusterElements, 
+      int k, double changeThreshold) {
       HashSet<int> initMeans = new HashSet<int>();
       int nextMean = -1;
-
-      List<C> clusters = CreateCList();
+      List<TCluster> clusters = CreateCList();
 
       // (1) initialize each cluster with a random element as mean
       for (int i = 0; i < k && i < clusterElements.Count; i++) {
-        C cluster = (C)Activator.CreateInstance(typeof(C));
+        TCluster cluster = new TCluster();
         cluster.Id = i;
 
@@ -30,5 +32,4 @@
       // (2) repeat clustering until change rate is below threshold
       double changeRate = 0.0;
-
       do {
         int changes = KMeansRun(clusters, clusterElements);
@@ -39,9 +40,8 @@
       // remove empty clusters
       clusters.RemoveAll(c => c.Elements.Count.Equals(0));
-
       return clusters;
     }
 
-    private static int KMeansRun(List<C> clusters, List<CO> clusterElements) {
+    private static int KMeansRun(List<TCluster> clusters, List<TClusterElement> clusterElements) {
       int changes = 0;
 
@@ -62,5 +62,5 @@
           }
         }
-        if (clusters[optClusterIdx].AddObject(e)) {
+        if (clusters[optClusterIdx].AddElement(e)) {
           changes++;
         }
@@ -76,8 +76,8 @@
     }
 
-    private static List<C> CreateCList() {
+    private static List<TCluster> CreateCList() {
       var listType = typeof(List<>);
-      var constructedListType = listType.MakeGenericType(typeof(C));
-      return (List<C>)Activator.CreateInstance(constructedListType);
+      var constructedListType = listType.MakeGenericType(typeof(TCluster));
+      return (List<TCluster>)Activator.CreateInstance(constructedListType);
     }
   }
@@ -86,31 +86,23 @@
   public interface ICluster<T> where T : ClusterElement {
     void SetMean(T o);
-    bool AddObject(T o);
+    bool AddElement(T o);
     void CalculateMean();
     void CalculateVariance();
     double CalculateImpact(T e);
     double CalculateDistance(T e1, T e2);
-
-  }
-  public abstract class Cluster<T> : ICluster<T> where T : ClusterElement {
+  }
+  public abstract class Cluster<T> : ICluster<T> where T : ClusterElement, new() {
     public int Id;
-
     public List<T> Elements { get; private set; }
-
     public T Mean { get; set; }
-
     public double Variance { get; set; }
-
     protected Cluster() {
       Elements = new List<T>();
     }
-
     protected Cluster(int id) {
       Id = id;
       Elements = new List<T>();
-
-    }
-
-    public bool AddObject(T e) {
+    }
+    public bool AddElement(T e) {
       Elements.Add(e);
 
@@ -119,14 +111,10 @@
       return clusterChanged;
     }
-
     public void SetMean(T e) {
       Mean = e;
       Mean.ClusterId = Id;
     }
-
     public abstract void CalculateMean();
-
     public abstract double CalculateDistance(T e1, T e2);
-
     public virtual void CalculateVariance() {
       if (Mean == null)
@@ -139,5 +127,4 @@
       Variance /= Elements.Count;
     }
-
     public virtual double CalculateImpact(T e) {
       if (Mean == null)
@@ -147,5 +134,4 @@
       return newVariance - Variance;
     }
-
   }
   public class SpatialDistanceCluster : Cluster<SpatialDistanceClusterElement> {
@@ -155,5 +141,4 @@
     public SpatialDistanceCluster(int id) : base(id) {
     }
-
     public override void CalculateMean() {
       int dimensions = (Mean != null) ? Mean.Coordinates.Length : (Elements.Count > 0) ? Elements[0].Coordinates.Length : 0;
@@ -166,5 +151,4 @@
       Mean = mean;
     }
-
     public override double CalculateDistance(SpatialDistanceClusterElement e1, SpatialDistanceClusterElement e2) {
       if (!e1.Coordinates.Length.Equals(e2.Coordinates.Length)) {
@@ -176,16 +160,12 @@
         distance += Math.Pow(e1.Coordinates[i] - e2.Coordinates[i], 2);
       }
-
       return Math.Sqrt(distance);
     }
   }
-
   public class TemporalDistanceCluster : Cluster<TemporalDistanceClusterElement> {
     public TemporalDistanceCluster() : base() {
     }
-
     public TemporalDistanceCluster(int id) : base(id) {
     }
-
     public override void CalculateMean() {
       TemporalDistanceClusterElement mean = new TemporalDistanceClusterElement(-1, Id);
@@ -196,5 +176,4 @@
       Mean = mean;
     }
-
     public override double CalculateDistance(TemporalDistanceClusterElement e1, TemporalDistanceClusterElement e2) {
       double distance = 0.0;
@@ -206,5 +185,4 @@
     }
   }
-
   #endregion Cluster
 
@@ -213,9 +191,7 @@
     public int Id { get; set; }
     public int ClusterId { get; set; }
-
     protected ClusterElement() {
       ClusterId = -1;
     }
-
     public ClusterElement(int id, int clusterId = -1) {
       Id = id;
@@ -224,33 +200,23 @@
   }
   public class SpatialDistanceClusterElement : ClusterElement {
-
     public double[] Coordinates { get; set; }
-
     public SpatialDistanceClusterElement() : base() {
     }
-
     public SpatialDistanceClusterElement(int id, int clusterId = -1) : base(id, clusterId) {
     }
-
     public SpatialDistanceClusterElement(int id, double[] coordinates, int clusterId = -1) : base(id, clusterId) {
       Coordinates = coordinates;
     }
-
     public SpatialDistanceClusterElement(int id, int dimensions, int clusterId = -1) : base(id, clusterId) { 
       Coordinates = new double[dimensions];
     }
-
-  }
-
+  }
   public class TemporalDistanceClusterElement : ClusterElement {
     public double ReadyTime { get; set; }
     public double DueTime { get; set; }
-
     public TemporalDistanceClusterElement() : base() {
     }
-
     public TemporalDistanceClusterElement(int id, int clusterId = -1) : base(id, clusterId) {
     }
-
     public TemporalDistanceClusterElement(int id, double readyTime, double dueTime, int clusterId = -1) : base(id, clusterId) {
       ReadyTime = readyTime;
