Class Cluster
java.lang.Object
org.moeaframework.util.clustering.Cluster
- All Implemented Interfaces:
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 Summary
Modifier and TypeMethodDescriptionvoid
add
(ClusterableSolution solution) Adds a new clusterable solution to this cluster.void
addAll
(Iterable<ClusterableSolution> solutions) Adds a collection of clusterable solutions to this cluster.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.get
(int index) Returns the clusterable solution at the given index.double[]
Returns the center, or centroid, of this cluster.Returns the solution defined to represent this cluster.iterator()
Merges this cluster with another.int
size()
Returns the number of points or elements contained in this cluster.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Method Details
-
size
public int size()Returns the number of points or elements contained in this cluster.- Returns:
- the size of the cluster
-
iterator
- Specified by:
iterator
in interfaceIterable<ClusterableSolution>
-
add
Adds a new clusterable solution to this cluster.- Parameters:
solution
- the solution to add
-
addAll
Adds a collection of clusterable solutions to this cluster.- Parameters:
solutions
- the solutions to add
-
get
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
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
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
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
-