Class Cluster

java.lang.Object
org.moeaframework.util.clustering.Cluster
All Implemented Interfaces:
Iterable<ClusterableSolution>

public class Cluster extends Object implements Iterable<ClusterableSolution>
Defines a cluster of solutions along with the distance measure used to form the cluster. Note that by definition a cluster must contain at least one point.
  • Method Details

    • size

      public int size()
      Returns the number of points or elements contained in this cluster.
      Returns:
      the size of the cluster
    • iterator

      public Iterator<ClusterableSolution> iterator()
      Specified by:
      iterator in interface Iterable<ClusterableSolution>
    • add

      public void add(ClusterableSolution solution)
      Adds a new clusterable solution to this cluster.
      Parameters:
      solution - the solution to add
    • addAll

      public void addAll(Iterable<ClusterableSolution> solutions)
      Adds a collection of clusterable solutions to this cluster.
      Parameters:
      solutions - the solutions to add
    • get

      public ClusterableSolution get(int index)
      Returns the clusterable solution at the given index.
      Parameters:
      index - the index
      Returns:
      the clusterable solution at the given index
      Throws:
      IndexOutOfBoundsException - if the index is out of bounds
    • merge

      public Cluster merge(Cluster otherCluster)
      Merges this cluster with another. Note that this produces a new cluster, leaving the two original clusters unchanged.
      Parameters:
      otherCluster - the other cluster to merge with
      Returns:
      the merged cluster
    • getCenter

      public double[] getCenter()
      Returns the center, or centroid, of this cluster. While there are various definitions of a "centroid", here we compute the average value in each dimension. This minimizes the sum-of-squared distances from the centroid to each point in the cluster.
      Returns:
      the center point
    • distanceTo

      public double distanceTo(Cluster cluster)
      Returns the distance between two clusters, which is defined as the minimum value found when computing all pairwise distances between individual points.
      Parameters:
      cluster - the other cluster
      Returns:
      the minimum distance
    • getRepresentativeMember

      public ClusterableSolution getRepresentativeMember()
      Returns the solution defined to represent this cluster. This implementation returns the solution with the smallest crowding distance, measured as the sum of distances to all other solutions within the cluster.
      Returns:
      the representative solution in this cluster