Package org.moeaframework
Class Instrumenter
java.lang.Object
org.moeaframework.Instrumenter
Instruments algorithms with
Collector
s 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 Summary
ConstructorDescriptionConstructs a new instrumenter instance, initially with no collectors. -
Method Summary
Modifier and TypeMethodDescriptionaddExcludedPackage
(String packageName) Adds an excluded package that will not be walked by this instrumenter.Includes the specified collector when instrumenting algorithms.Includes the adaptive multimethod variation collector when instrumenting algorithms.Includes the adaptive time continuation collector when instrumenting algorithms.Includes the additive ε-indicator collector when instrumenting algorithms.Includes all collectors when instrumenting algorithms.Includes all indicator collectors when instrumenting algorithms.Includes the approximation set collector when instrumenting algorithms.Includes the contribution collector when instrumenting algorithms.Includes the elapsed time collector when instrumenting algorithms.Includes the ε-progress collector when instrumenting algorithms.Includes the generational distance collector when instrumenting algorithms.Includes the generational distance plus collector when instrumenting algorithms.Includes the hypervolume collector when instrumenting algorithms.Includes the inverted generational distance collector when instrumenting algorithms.Includes the inverted generational distance plus collector when instrumenting algorithms.Includes the maximum Pareto front error collector when instrumenting algorithms.Includes the population collector when instrumenting algorithms.Includes the population size collector when instrumenting algorithms.Includes the R1 collector when instrumenting algorithms.Includes the R2 collector when instrumenting algorithms.Includes the R3 collector when instrumenting algorithms.Includes the spacing collector when instrumenting algorithms.Returns the observations from the last instrumented algorithm.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 theCollector
s to any matching objects.<T extends Algorithm>
InstrumentedAlgorithm<T>instrument
(T algorithm) Instruments the specified algorithm, returning anInstrumentedAlgorithm
to be used to execute the algorithm and store the data produced by any attached instruments.removeExcludedPackage
(String packageName) Removes an excluded package from this instrumenter.usingProblemFactory
(ProblemFactory problemFactory) withEpsilon
(double... epsilon) withEpsilons
(Epsilons epsilons) withFrequency
(int frequency) Sets the frequency that data is collected.withFrequencyType
(FrequencyType frequencyType) Indicates if the frequency is defined in terms of the number of evaluations or number of steps (iterations).withProblem
(String problemName) withProblem
(Problem problemInstance) withProblemClass
(Class<?> problemClass, Object... problemArguments) withProblemClass
(String problemClassName, Object... problemArguments) withReferenceSet
(File referenceSetFile) withReferenceSet
(NondominatedPopulation referenceSet) withSameProblemAs
(org.moeaframework.ProblemBuilder builder)
-
Constructor Details
-
Instrumenter
public Instrumenter()Constructs a new instrumenter instance, initially with no collectors.
-
-
Method Details
-
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
Adds an excluded package that will not be walked by this instrumenter.- Parameters:
packageName
- the package name- Returns:
- a reference to this instrumenter
-
removeExcludedPackage
Removes an excluded package from this instrumenter.- Parameters:
packageName
- the package name- Returns:
- a reference to this instrumenter
-
withFrequency
Sets the frequency that data is collected.- Parameters:
frequency
- the frequency- Returns:
- a reference to this instrumenter
-
withFrequencyType
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
Includes the specified collector when instrumenting algorithms.- Parameters:
collector
- the collector to include when instrumenting algorithms- Returns:
- a reference to this instrumenter
-
attachHypervolumeCollector
Includes the hypervolume collector when instrumenting algorithms.- Returns:
- a reference to this instrumenter
-
attachGenerationalDistanceCollector
Includes the generational distance collector when instrumenting algorithms.- Returns:
- a reference to this instrumenter
-
attachGenerationalDistancePlusCollector
Includes the generational distance plus collector when instrumenting algorithms.- Returns:
- a reference to this instrumenter
-
attachInvertedGenerationalDistanceCollector
Includes the inverted generational distance collector when instrumenting algorithms.- Returns:
- a reference to this instrumenter
-
attachInvertedGenerationalDistancePlusCollector
Includes the inverted generational distance plus collector when instrumenting algorithms.- Returns:
- a reference to this instrumenter
-
attachSpacingCollector
Includes the spacing collector when instrumenting algorithms.- Returns:
- a reference to this instrumenter
-
attachAdditiveEpsilonIndicatorCollector
Includes the additive ε-indicator collector when instrumenting algorithms.- Returns:
- a reference to this instrumenter
-
attachContributionCollector
Includes the contribution collector when instrumenting algorithms.- Returns:
- a reference to this instrumenter
-
attachMaximumParetoFrontErrorCollector
Includes the maximum Pareto front error collector when instrumenting algorithms.- Returns:
- a reference to this instrumenter
-
attachR1Collector
Includes the R1 collector when instrumenting algorithms.- Returns:
- a reference to this instrumenter
-
attachR2Collector
Includes the R2 collector when instrumenting algorithms.- Returns:
- a reference to this instrumenter
-
attachR3Collector
Includes the R3 collector when instrumenting algorithms.- Returns:
- a reference to this instrumenter
-
attachAllMetricCollectors
Includes all indicator collectors when instrumenting algorithms.- Returns:
- a reference to this instrumenter
-
attachEpsilonProgressCollector
Includes the ε-progress collector when instrumenting algorithms.- Returns:
- a reference to this instrumenter
-
attachAdaptiveMultimethodVariationCollector
Includes the adaptive multimethod variation collector when instrumenting algorithms.- Returns:
- a reference to this instrumenter
-
attachAdaptiveTimeContinuationCollector
Includes the adaptive time continuation collector when instrumenting algorithms.- Returns:
- a reference to this instrumenter
-
attachElapsedTimeCollector
Includes the elapsed time collector when instrumenting algorithms.- Returns:
- a reference to this instrumenter
-
attachApproximationSetCollector
Includes the approximation set collector when instrumenting algorithms.- Returns:
- a reference to this instrumenter
-
attachPopulationCollector
Includes the population collector when instrumenting algorithms.- Returns:
- a reference to this instrumenter
-
attachPopulationSizeCollector
Includes the population size collector when instrumenting algorithms.- Returns:
- a reference to this instrumenter
-
attachAll
Includes all collectors when instrumenting algorithms.- Returns:
- a reference to this instrumenter
-
withSameProblemAs
-
usingProblemFactory
-
withProblem
-
withProblem
-
withProblemClass
-
withProblemClass
public Instrumenter withProblemClass(String problemClassName, Object... problemArguments) throws ClassNotFoundException - Throws:
ClassNotFoundException
-
withReferenceSet
-
withReferenceSet
-
withEpsilon
-
withEpsilons
-
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 theCollector
s 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 andCollection
s are listed in the nesting, the array/collection object itself is not listed. For example, the nesting will showCompoundVariation >> PM
instead ofCompoundVariation >> ArrayList >> Object[] >> PM
.This method is reentrant.
- Parameters:
algorithm
- the algorithmextension
- the extension responsible for collecting the datacollectors
- the collectors to be attachedvisited
- the set of visited objects, which may include the current object when traversing its superclassesparents
- the objects in which the current object is containedobject
- the current object undergoing reflectiontype
- the superclass whose members are being reflected; ornull
if the base type is to be used
-
instrument
Instruments the specified algorithm, returning anInstrumentedAlgorithm
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
-