Class CachedDistanceMeasure<T>

java.lang.Object
org.moeaframework.util.clustering.CachedDistanceMeasure<T>
Type Parameters:
T - the type of object being stored
All Implemented Interfaces:
DistanceMeasure<T>

public class CachedDistanceMeasure<T> extends Object implements DistanceMeasure<T>
Wraps a DistanceMeasure to cache or memoize the calculations in memory. This is similar to using a precomputed distance matrix, except the distance calculations are performed lazily.
  • Constructor Details

    • CachedDistanceMeasure

      public CachedDistanceMeasure(DistanceMeasure<T> distanceMeasure, boolean isSymmetric)
      Wraps the provided distance measure with a cached version.
      Parameters:
      distanceMeasure - the uncached distance measure
      isSymmetric - true if the distance measure is symmetric; see CachedDistanceMeasure for the definition of symmetry.
  • Method Details

    • compute

      public double compute(T first, T second)
      Description copied from interface: DistanceMeasure
      Returns the distance between the two objects.
      Specified by:
      compute in interface DistanceMeasure<T>
      Parameters:
      first - the first object
      second - the second object
      Returns:
      the distance