Class Instrumenter

java.lang.Object
org.moeaframework.Instrumenter

public class Instrumenter extends Object
Instruments algorithms with Collectors which record information about the runtime behavior of algorithms. First, the instrumenter walks the object graph of an algorithm to determine its composition. Upon finding objects which can be instrumented, it attaches the corresponding collector. Next, the instrumenter returns an InstrumentedAlgorithm, which orchestrates the collection of runtime information as the algorithm is executed. Lastly, the InstrumentedAlgorithm stores the runtime information, which can subsequently be accessed and analyzed.
   Instrumenter instrumenter = new Instrumenter()
     .withProblem(problemName)
     .attachAll();
 
   NondominatedPopulation result = new Executor()
     .withProblem(problemName)
     .withAlgorithm(algorithmName)
     .withMaxEvaluations(numberOfEvaluations)
     .withInstrumenter(instrumenter)
     .run();
 
   Observations observations = instrumenter.getObservations();
 
Note that the Instrumenter will not scan the contents of Solution or Problem. Instead, use the Instrumenter to enumerate these objects and access their properties programmatically.
  • Constructor Details

    • Instrumenter

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

    • getObservations

      public Observations getObservations()
      Returns the observations from the last instrumented algorithm. The observations will be filled with the runtime information as the algorithm is executed.
      Returns:
      the observations from the last instrumented algorithm
    • 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(int frequency)
      Sets the frequency that data is collected.
      Parameters:
      frequency - the frequency
      Returns:
      a reference to this instrumenter
    • withFrequencyType

      public Instrumenter withFrequencyType(FrequencyType frequencyType)
      Indicates if the frequency is defined in terms of the number of evaluations or number of steps (iterations).
      Parameters:
      frequencyType - the frequency type, either EVALUATIONS or STEPS
      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
    • attachApproximationSetCollector

      public Instrumenter attachApproximationSetCollector()
      Includes the approximation set collector when instrumenting algorithms.
      Returns:
      a reference to this instrumenter
    • attachPopulationCollector

      public Instrumenter attachPopulationCollector()
      Includes the population 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
    • withSameProblemAs

      public Instrumenter withSameProblemAs(org.moeaframework.ProblemBuilder builder)
    • usingProblemFactory

      public Instrumenter usingProblemFactory(ProblemFactory problemFactory)
    • withProblem

      public Instrumenter withProblem(String problemName)
    • withProblem

      public Instrumenter withProblem(Problem problemInstance)
    • withProblemClass

      public Instrumenter withProblemClass(Class<?> problemClass, Object... problemArguments)
    • withProblemClass

      public Instrumenter withProblemClass(String problemClassName, Object... problemArguments) throws ClassNotFoundException
      Throws:
      ClassNotFoundException
    • withReferenceSet

      public Instrumenter withReferenceSet(File referenceSetFile)
    • withReferenceSet

      public Instrumenter withReferenceSet(NondominatedPopulation referenceSet)
    • withEpsilon

      public Instrumenter withEpsilon(double... epsilon)
    • withEpsilons

      public Instrumenter withEpsilons(Epsilons epsilons)
    • getReferenceSet

      public NondominatedPopulation getReferenceSet()
    • 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.
      Parameters:
      algorithm - the algorithm to instrument
      Returns:
      the instrumented algorithm
      Throws:
      IllegalArgumentException - if no reference set is available or could not be loaded