Class Instrumenter

java.lang.Object
org.moeaframework.analysis.runtime.Instrumenter

public class Instrumenter extends Object
Instruments algorithms to record runtime information.

The instrumenter walks the object graph of an algorithm to determine its composition. Upon finding objects that can be instrumented, it attaches the corresponding collector. The returned InstrumentedAlgorithm orchestrates the collection of runtime information as the algorithm is executed.

Note: this will not scan the contents of Solution or Problem.

See Also:
  • Constructor Details

    • Instrumenter

      public Instrumenter()
      Constructs a new instrumenter instance, initially with no collectors.
  • Method Details

    • getReferenceSet

      public NondominatedPopulation getReferenceSet()
      Returns the reference set that was configured with this instrumenter.
      Returns:
      the reference set
    • addExcludedPackage

      public Instrumenter addExcludedPackage(String packageName)
      Adds an excluded package that will not be walked by this instrumenter.
      Parameters:
      packageName - the package name
      Returns:
      a reference to this instrumenter
    • removeExcludedPackage

      public Instrumenter removeExcludedPackage(String packageName)
      Removes an excluded package from this instrumenter.
      Parameters:
      packageName - the package name
      Returns:
      a reference to this instrumenter
    • withFrequency

      public Instrumenter withFrequency(Frequency frequency)
      Sets the frequency that data is collected.
      Parameters:
      frequency - the frequency
      Returns:
      a reference to this instrumenter
    • attach

      public Instrumenter attach(Collector collector)
      Includes the specified collector when instrumenting algorithms.
      Parameters:
      collector - the collector to include when instrumenting algorithms
      Returns:
      a reference to this instrumenter
    • attachHypervolumeCollector

      public Instrumenter attachHypervolumeCollector()
      Includes the hypervolume collector when instrumenting algorithms.
      Returns:
      a reference to this instrumenter
    • attachGenerationalDistanceCollector

      public Instrumenter attachGenerationalDistanceCollector()
      Includes the generational distance collector when instrumenting algorithms.
      Returns:
      a reference to this instrumenter
    • attachGenerationalDistancePlusCollector

      public Instrumenter attachGenerationalDistancePlusCollector()
      Includes the generational distance plus collector when instrumenting algorithms.
      Returns:
      a reference to this instrumenter
    • attachInvertedGenerationalDistanceCollector

      public Instrumenter attachInvertedGenerationalDistanceCollector()
      Includes the inverted generational distance collector when instrumenting algorithms.
      Returns:
      a reference to this instrumenter
    • attachInvertedGenerationalDistancePlusCollector

      public Instrumenter attachInvertedGenerationalDistancePlusCollector()
      Includes the inverted generational distance plus collector when instrumenting algorithms.
      Returns:
      a reference to this instrumenter
    • attachSpacingCollector

      public Instrumenter attachSpacingCollector()
      Includes the spacing collector when instrumenting algorithms.
      Returns:
      a reference to this instrumenter
    • attachAdditiveEpsilonIndicatorCollector

      public Instrumenter attachAdditiveEpsilonIndicatorCollector()
      Includes the additive ε-indicator collector when instrumenting algorithms.
      Returns:
      a reference to this instrumenter
    • attachContributionCollector

      public Instrumenter attachContributionCollector()
      Includes the contribution collector when instrumenting algorithms.
      Returns:
      a reference to this instrumenter
    • attachMaximumParetoFrontErrorCollector

      public Instrumenter attachMaximumParetoFrontErrorCollector()
      Includes the maximum Pareto front error collector when instrumenting algorithms.
      Returns:
      a reference to this instrumenter
    • attachR1Collector

      public Instrumenter attachR1Collector()
      Includes the R1 collector when instrumenting algorithms.
      Returns:
      a reference to this instrumenter
    • attachR2Collector

      public Instrumenter attachR2Collector()
      Includes the R2 collector when instrumenting algorithms.
      Returns:
      a reference to this instrumenter
    • attachR3Collector

      public Instrumenter attachR3Collector()
      Includes the R3 collector when instrumenting algorithms.
      Returns:
      a reference to this instrumenter
    • attachAllMetricCollectors

      public Instrumenter attachAllMetricCollectors()
      Includes all indicator collectors when instrumenting algorithms.
      Returns:
      a reference to this instrumenter
    • attachEpsilonProgressCollector

      public Instrumenter attachEpsilonProgressCollector()
      Includes the ε-progress collector when instrumenting algorithms.
      Returns:
      a reference to this instrumenter
    • attachAdaptiveMultimethodVariationCollector

      public Instrumenter attachAdaptiveMultimethodVariationCollector()
      Includes the adaptive multimethod variation collector when instrumenting algorithms.
      Returns:
      a reference to this instrumenter
    • attachAdaptiveTimeContinuationCollector

      public Instrumenter attachAdaptiveTimeContinuationCollector()
      Includes the adaptive time continuation collector when instrumenting algorithms.
      Returns:
      a reference to this instrumenter
    • attachElapsedTimeCollector

      public Instrumenter attachElapsedTimeCollector()
      Includes the elapsed time collector when instrumenting algorithms.
      Returns:
      a reference to this instrumenter
    • attachPopulationSizeCollector

      public Instrumenter attachPopulationSizeCollector()
      Includes the population size collector when instrumenting algorithms.
      Returns:
      a reference to this instrumenter
    • attachAll

      public Instrumenter attachAll()
      Includes all collectors when instrumenting algorithms.
      Returns:
      a reference to this instrumenter
    • withReferenceSet

      public Instrumenter withReferenceSet(File referenceSetFile) throws IOException
      Loads a reference set from file. Only required when computing performance indicators.
      Parameters:
      referenceSetFile - the reference set file
      Returns:
      a reference to this instrumenter
      Throws:
      IOException - if an I/O error occurred
    • withReferenceSet

      public Instrumenter withReferenceSet(String resource) throws IOException
      Loads a reference set from a resource available in the file system or bundled in a JAR. Only required when computing performance indicators.
      Parameters:
      resource - the reference set resource name
      Returns:
      a reference to this instrumenter
      Throws:
      IOException - if an I/O error occurred
    • withReferenceSet

      public Instrumenter withReferenceSet(NondominatedPopulation referenceSet)
      Configures a reference set to use for this problem. Only required when computing performance indicators.
      Parameters:
      referenceSet - the reference set
      Returns:
      a reference to this instrumenter
    • withEpsilon

      public Instrumenter withEpsilon(double... epsilon)
      Sets the ε values used by this instrumenter.
      Parameters:
      epsilon - the ε values
      Returns:
      a reference to this builder
    • withEpsilons

      public Instrumenter withEpsilons(Epsilons epsilons)
      Sets the ε values used by this instrumenter.
      Parameters:
      epsilons - the ε values
      Returns:
      a reference to this builder
    • instrument

      protected void instrument(Algorithm algorithm, InstrumentedExtension extension, List<Collector> collectors, Set<Object> visited, Stack<Object> parents, Object object, Class<?> type)
      Recursively walks the object graph to 1) determine the nesting of objects to help determine which objects are to be instrumented; and 2) attach the Collectors to any matching objects.

      In order to avoid cycles in the object graph, objects are only traversed the first time they are encountered. If an object appears multiple times in the object graph, the instrument method will only be invoked once.

      When generating the nesting of objects, anonymous classes are given the placeholder type "(Anonymous)", without quotes. While the contents of arrays and Collections are listed in the nesting, the array/collection object itself is not listed. For example, the nesting will show CompoundVariation >> PM instead of CompoundVariation >> ArrayList >> Object[] >> PM.

      This method is reentrant.

      Parameters:
      algorithm - the algorithm
      extension - the extension responsible for collecting the data
      collectors - the collectors to be attached
      visited - the set of visited objects, which may include the current object when traversing its superclasses
      parents - the objects in which the current object is contained
      object - the current object undergoing reflection
      type - the superclass whose members are being reflected; or null if the base type is to be used
    • instrument

      public <T extends Algorithm> InstrumentedAlgorithm<T> instrument(T algorithm)
      Instruments the specified algorithm, returning an InstrumentedAlgorithm to be used to execute the algorithm and store the data produced by any attached instruments.
      Type Parameters:
      T - the type of the algorithm
      Parameters:
      algorithm - the algorithm to instrument
      Returns:
      the instrumented algorithm
      Throws:
      IllegalArgumentException - if no reference set is available or could not be loaded