public class Instrumenter
extends java.lang.Object
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 and Description |
---|
Instrumenter()
Constructs a new instrumenter instance, initially with no collectors.
|
Modifier and Type | Method and Description |
---|---|
Instrumenter |
addExcludedPackage(java.lang.String packageName)
Adds an excluded package that will not be walked by this instrumenter.
|
Instrumenter |
attach(Collector collector)
Includes the specified collector when instrumenting algorithms.
|
Instrumenter |
attachAdaptiveMultimethodVariationCollector()
Includes the adaptive multimethod variation collector when instrumenting
algorithms.
|
Instrumenter |
attachAdaptiveTimeContinuationCollector()
Includes the adaptive time continuation collector when instrumenting
algorithms.
|
Instrumenter |
attachAdditiveEpsilonIndicatorCollector()
Includes the additive ε-indicator collector when instrumenting
algorithms.
|
Instrumenter |
attachAll()
Includes all collectors when instrumenting algorithms.
|
Instrumenter |
attachAllMetricCollectors()
Includes all indicator collectors when instrumenting algorithms.
|
Instrumenter |
attachApproximationSetCollector()
Includes the approximation set collector when instrumenting algorithms.
|
Instrumenter |
attachContributionCollector()
Includes the contribution collector when instrumenting algorithms.
|
Instrumenter |
attachElapsedTimeCollector()
Includes the elapsed time collector when instrumenting algorithms.
|
Instrumenter |
attachEpsilonProgressCollector()
Includes the ε-progress collector when instrumenting algorithms.
|
Instrumenter |
attachGenerationalDistanceCollector()
Includes the generational distance collector when instrumenting
algorithms.
|
Instrumenter |
attachHypervolumeCollector()
Includes the hypervolume collector when instrumenting algorithms.
|
Instrumenter |
attachInvertedGenerationalDistanceCollector()
Includes the inverted generational distance collector when instrumenting
algorithms.
|
Instrumenter |
attachPopulationCollector()
Includes the population collector when instrumenting algorithms.
|
Instrumenter |
attachPopulationSizeCollector()
Includes the population size collector when instrumenting algorithms.
|
Instrumenter |
attachR1Collector()
Includes the R1 collector when instrumenting algorithms.
|
Instrumenter |
attachR2Collector()
Includes the R2 collector when instrumenting algorithms.
|
Instrumenter |
attachR3Collector()
Includes the R3 collector when instrumenting algorithms.
|
Instrumenter |
attachSpacingCollector()
Includes the spacing collector when instrumenting algorithms.
|
Observations |
getObservations()
Returns the observations from the last instrumented algorithm.
|
NondominatedPopulation |
getReferenceSet()
Returns the reference set used by this builder.
|
InstrumentedAlgorithm |
instrument(Algorithm algorithm)
Instruments the specified algorithm, returning an
InstrumentedAlgorithm to be used to execute the algorithm and
store the data produced by any attached instruments. |
protected void |
instrument(InstrumentedAlgorithm algorithm,
java.util.List<Collector> collectors,
java.util.Set<java.lang.Object> visited,
java.util.Stack<java.lang.Object> parents,
java.lang.Object object,
java.lang.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
collector s to any matching objects. |
Instrumenter |
removeExcludedPackage(java.lang.String packageName)
Removes an excluded package from this instrumenter.
|
Instrumenter |
usingProblemFactory(ProblemFactory problemFactory)
Sets the problem factory used by this builder.
|
Instrumenter |
withEpsilon(double... epsilon)
Sets the ε values used by this builder, specifying the archive
returned by
newArchive() . |
Instrumenter |
withFrequency(int frequency)
Sets the frequency that data is collected.
|
Instrumenter |
withFrequencyType(PeriodicAction.FrequencyType frequencyType)
Indicates if the frequency is defined in terms of the number of
evaluations or number of steps (iterations).
|
Instrumenter |
withProblem(Problem problemInstance)
Sets the problem instance used by this builder.
|
Instrumenter |
withProblem(java.lang.String problemName)
Sets the problem used by this builder.
|
Instrumenter |
withProblemClass(java.lang.Class<?> problemClass,
java.lang.Object... problemArguments)
Sets the problem used by this builder.
|
Instrumenter |
withProblemClass(java.lang.String problemClassName,
java.lang.Object... problemArguments)
Sets the problem used by this builder.
|
Instrumenter |
withReferenceSet(java.io.File referenceSetFile)
Loads a reference set from file.
|
Instrumenter |
withSameProblemAs(org.moeaframework.ProblemBuilder builder)
Configures this builder to use the same problem, reference set, ε
values and
ProblemFactory as the specified instance. |
public Instrumenter()
public Observations getObservations()
public Instrumenter addExcludedPackage(java.lang.String packageName)
packageName
- the package namepublic Instrumenter removeExcludedPackage(java.lang.String packageName)
packageName
- the package namepublic Instrumenter withFrequency(int frequency)
frequency
- the frequencypublic Instrumenter withFrequencyType(PeriodicAction.FrequencyType frequencyType)
frequencyType
- the frequency type, either EVALUATIONS or STEPSpublic Instrumenter attach(Collector collector)
collector
- the collector to include when instrumenting algorithmspublic Instrumenter attachHypervolumeCollector()
public Instrumenter attachGenerationalDistanceCollector()
public Instrumenter attachInvertedGenerationalDistanceCollector()
public Instrumenter attachSpacingCollector()
public Instrumenter attachAdditiveEpsilonIndicatorCollector()
public Instrumenter attachContributionCollector()
public Instrumenter attachR1Collector()
public Instrumenter attachR2Collector()
public Instrumenter attachR3Collector()
public Instrumenter attachAllMetricCollectors()
public Instrumenter attachEpsilonProgressCollector()
public Instrumenter attachAdaptiveMultimethodVariationCollector()
public Instrumenter attachAdaptiveTimeContinuationCollector()
public Instrumenter attachElapsedTimeCollector()
public Instrumenter attachApproximationSetCollector()
public Instrumenter attachPopulationCollector()
public Instrumenter attachPopulationSizeCollector()
public Instrumenter attachAll()
public Instrumenter withSameProblemAs(org.moeaframework.ProblemBuilder builder)
ProblemFactory
as the specified instance.builder
- the instance whose problem, reference set, ε
values and ProblemFactory
are to be copiedpublic Instrumenter usingProblemFactory(ProblemFactory problemFactory)
problemFactory
- the problem factorypublic Instrumenter withProblem(java.lang.String problemName)
problemName
- the problem namepublic Instrumenter withProblem(Problem problemInstance)
withProblem
methods, using a problem instance will not close the
problem. It is the responsibility of the user to ensure any problems
holding resources are properly closed.problemInstance
- the problem instancepublic Instrumenter withProblemClass(java.lang.Class<?> problemClass, java.lang.Object... problemArguments)
Class.newInstance()
method. Ensure the problem
class satisfies all the conditions of newInstance()
, otherwise
exceptions may be thrown when attempting to create an instance of the
problem.problemClass
- the problem classproblemArguments
- the arguments passed to the problem constructorpublic Instrumenter withProblemClass(java.lang.String problemClassName, java.lang.Object... problemArguments) throws java.lang.ClassNotFoundException
Class.newInstance()
method. Ensure the problem
class satisfies all the conditions of newInstance()
, otherwise
exceptions may be thrown when attempting to create an instance of the
problem.problemClassName
- the problem class nameproblemArguments
- the arguments passed to the problem constructorjava.lang.ClassNotFoundException
- if the specified problem class name could
not be foundpublic Instrumenter withReferenceSet(java.io.File referenceSetFile)
referenceSetFile
- the reference set filepublic Instrumenter withEpsilon(double... epsilon)
newArchive()
.epsilon
- the ε valuespublic NondominatedPopulation getReferenceSet()
withReferenceSet(NondominatedPopulation)
or
withReferenceSet(File)
;
ProblemFactory.getReferenceSet(String)
method;
protected void instrument(InstrumentedAlgorithm algorithm, java.util.List<Collector> collectors, java.util.Set<java.lang.Object> visited, java.util.Stack<java.lang.Object> parents, java.lang.Object object, java.lang.Class<?> type)
collector
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 and Collection
s 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.
algorithm
- the instrumented algorithmcollectors
- 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; or
null
if the base type is to be usedpublic InstrumentedAlgorithm instrument(Algorithm algorithm)
InstrumentedAlgorithm
to be used to execute the algorithm and
store the data produced by any attached instruments.algorithm
- the algorithm to instrumentjava.lang.IllegalArgumentException
- if no reference set is available or
could not be loadedCopyright 2009-2024 David Hadka and other contributors. All rights reserved.
Licensed under the GNU Lesser General Public License.
Return to the MOEA Framework homepage.