public class Executor
extends java.lang.Object
NondominatedPopulation result = new Executor() .withAlgorithm("NSGAII") .withProblem("DTLZ2_2") .withMaxEvaluations(10000) .run();
The problem and algorithm must be specified prior to calling run()
.
Additional parameters for each algorithm can be assigned using the
withProperty
methods:
NondominatedPopulation result = new Executor() .withAlgorithm("NSGAII") .withProblem("DTLZ2_2") .withMaxEvaluations(10000) .withProperty("populationSize", 100) .withProperty("sbx.rate", 1.0) .withProperty("sbx.distributionIndex", 15.0) .withProperty("pm.rate", 0.05) .withProperty("pm.distributionIndex", 20.0) .run();
The evaluation of function evaluations can be distributed across multiple
cores or computers by using distributeOnAllCores()
,
distributeOn(int)
, or distributeWith(ExecutorService)
.
Checkpoint files can be saved in order to resume interrupted runs using the
withCheckpointFrequency(int)
and withCheckpointFile(File)
methods. For example:
NondominatedPopulation result = new Executor() .withAlgorithm("NSGAII") .withProblem("DTLZ2_2") .withMaxEvaluations(100000) .distributeOnAllCores() .withCheckpointFrequency(1000) .withCheckpointFile(new File("example.state")) .run();
Constructor and Description |
---|
Executor()
Constructs a new executor initialized with default settings.
|
Modifier and Type | Method and Description |
---|---|
void |
cancel()
Informs this executor to stop processing and returns any results
collected thus far.
|
Executor |
checkpointEveryIteration()
Enables this executor to save checkpoints after every iteration of the
algorithm.
|
Executor |
clearProperties()
Clears the properties.
|
protected TerminationCondition |
createTerminationCondition()
Returns the termination condition for this executor.
|
Executor |
distributeOn(int numberOfThreads)
Enables this executor to distribute solution evaluations across the
specified number of threads.
|
Executor |
distributeOnAllCores()
Enables this executor to distribute solution evaluations across all
processors on the local host.
|
Executor |
distributeWith(java.util.concurrent.ExecutorService executorService)
Sets the
ExecutorService used by this executor to distribute
solution evaluations. |
protected Problem |
getDistributedProblemInstance()
When configured to run on multiple threads or with an
ExecutorService ,
will wrap the problem instance in a distributed problem. |
Instrumenter |
getInstrumenter()
Returns the instrumenter used by this executor; or
null if no
instrumenter has been assigned. |
boolean |
isCanceled()
Returns
true if the canceled flag is set; false
otherwise. |
Executor |
removeProperty(java.lang.String key)
Unsets a property.
|
Executor |
resetCheckpointFile()
Deletes the checkpoint file if it exists.
|
NondominatedPopulation |
run()
Runs this executor with its configured settings.
|
java.util.List<NondominatedPopulation> |
runSeeds(int numberOfSeeds)
Runs this executor with its configured settings multiple times,
returning the individual end-of-run approximation sets.
|
protected NondominatedPopulation |
runSingleSeed(int seed,
int numberOfSeeds)
Runs this executor with its configured settings.
|
Executor |
usingAlgorithmFactory(AlgorithmFactory algorithmFactory)
Sets the algorithm factory used by this executor.
|
Executor |
usingProblemFactory(ProblemFactory problemFactory)
Sets the problem factory used by this builder.
|
Executor |
withAlgorithm(java.lang.String algorithmName)
Sets the algorithm used by this executor.
|
Executor |
withCheckpointFile(java.io.File checkpointFile)
Sets the checkpoint file where the algorithm state is stored.
|
Executor |
withCheckpointFrequency(int checkpointFrequency)
Sets the frequency at which this executor saves checkpoints.
|
Executor |
withEpsilon(double... epsilon)
Sets the ε values; equivalent to setting the property
epsilon . |
Executor |
withInstrumenter(Instrumenter instrumenter)
Sets the instrumenter used to record information about the runtime
behavior of algorithms executed by this executor.
|
Executor |
withMaxEvaluations(int maxEvaluations)
Sets the maximum number of evaluations; equivalent to setting the
property
maxEvaluations . |
Executor |
withMaxTime(long maxTime)
Sets the maximum elapsed time in milliseconds; equivalent to setting the
property
maxTime . |
Executor |
withProblem(Problem problemInstance)
Sets the problem instance used by this builder.
|
Executor |
withProblem(java.lang.String problemName)
Sets the problem used by this builder.
|
Executor |
withProblemClass(java.lang.Class<?> problemClass,
java.lang.Object... problemArguments)
Sets the problem used by this builder.
|
Executor |
withProblemClass(java.lang.String problemClassName,
java.lang.Object... problemArguments)
Sets the problem used by this builder.
|
Executor |
withProgressListener(ProgressListener listener)
Adds the given progress listener to receive periodic progress reports.
|
Executor |
withProperties(TypedProperties properties)
Sets all properties.
|
Executor |
withProperty(java.lang.String key,
boolean value)
Sets a
boolean property. |
Executor |
withProperty(java.lang.String key,
byte value)
Sets a
byte property. |
Executor |
withProperty(java.lang.String key,
byte[] values)
Sets a
byte array property. |
Executor |
withProperty(java.lang.String key,
double value)
Sets a
double property. |
Executor |
withProperty(java.lang.String key,
double[] values)
Sets a
double array property. |
Executor |
withProperty(java.lang.String key,
float value)
Sets a
float property. |
Executor |
withProperty(java.lang.String key,
float[] values)
Sets a
float array property. |
Executor |
withProperty(java.lang.String key,
int value)
Sets an
int property. |
Executor |
withProperty(java.lang.String key,
int[] values)
Sets an
int array property. |
Executor |
withProperty(java.lang.String key,
long value)
Sets a
long property. |
Executor |
withProperty(java.lang.String key,
long[] values)
Sets a
long array property. |
Executor |
withProperty(java.lang.String key,
short value)
Sets a
short property. |
Executor |
withProperty(java.lang.String key,
short[] values)
Sets a
short array property. |
Executor |
withProperty(java.lang.String key,
java.lang.String value)
Sets a property.
|
Executor |
withProperty(java.lang.String key,
java.lang.String[] values)
Sets a
String array property. |
Executor |
withSameProblemAs(org.moeaframework.ProblemBuilder builder)
Configures this builder to use the same problem, reference set, ε
values and
ProblemFactory as the specified instance. |
Executor |
withTerminationCondition(TerminationCondition condition)
Adds a custom termination condition for use with this executor.
|
public Executor()
public void cancel()
public boolean isCanceled()
true
if the canceled flag is set; false
otherwise. After canceling a run, the flag will remain set to
true
until another run is started. This method is thread-safe.true
if the canceled flag is set; false
otherwisepublic Executor withInstrumenter(Instrumenter instrumenter)
instrumenter
- the instrumeterpublic Instrumenter getInstrumenter()
null
if no
instrumenter has been assigned.null
if no
instrumenter has been assignedpublic Executor usingAlgorithmFactory(AlgorithmFactory algorithmFactory)
algorithmFactory
- the algorithm factorypublic Executor withSameProblemAs(org.moeaframework.ProblemBuilder builder)
ProblemFactory
as the specified instance.builder
- the instance whose problem, reference set, ε
values and ProblemFactory
are to be copiedpublic Executor usingProblemFactory(ProblemFactory problemFactory)
problemFactory
- the problem factorypublic Executor withProblem(java.lang.String problemName)
problemName
- the problem namepublic Executor 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 Executor 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 Executor 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 Executor withTerminationCondition(TerminationCondition condition)
withMaxEvaluations(int)
and withMaxTime(long)
to set
NFE or time limits.condition
- the termination condition to addpublic Executor withAlgorithm(java.lang.String algorithmName)
algorithmName
- the algorithm namepublic Executor distributeWith(java.util.concurrent.ExecutorService executorService)
ExecutorService
used by this executor to distribute
solution evaluations. The caller is responsible for ensuring the
executor service is shutdown after use.executorService
- the executor servicepublic Executor distributeOn(int numberOfThreads)
numberOfThreads
- the number of threadsjava.lang.IllegalArgumentException
- if numberOfThreads <= 0
public Executor distributeOnAllCores()
public Executor withCheckpointFile(java.io.File checkpointFile)
checkpointFile
- the checkpoint filepublic Executor withCheckpointFrequency(int checkpointFrequency)
checkpointFrequency
- the checkpoint frequency, specifying the
number of evaluations between checkpointspublic Executor checkpointEveryIteration()
public Executor resetCheckpointFile() throws java.io.IOException
java.io.IOException
- if the checkpoint file could not be deletedpublic Executor withEpsilon(double... epsilon)
epsilon
.epsilon
- the ε valuespublic Executor withMaxEvaluations(int maxEvaluations)
maxEvaluations
.maxEvaluations
- the maximum number of evaluationspublic Executor withMaxTime(long maxTime)
maxTime
.maxTime
- the maximum elapsed time in millisecondspublic Executor removeProperty(java.lang.String key)
key
- the property keypublic Executor withProperty(java.lang.String key, java.lang.String value)
key
- the property keyvalue
- the property valuepublic Executor withProperty(java.lang.String key, float value)
float
property.key
- the property keyvalue
- the property valuepublic Executor withProperty(java.lang.String key, double value)
double
property.key
- the property keyvalue
- the property valuepublic Executor withProperty(java.lang.String key, byte value)
byte
property.key
- the property keyvalue
- the property valuepublic Executor withProperty(java.lang.String key, short value)
short
property.key
- the property keyvalue
- the property valuepublic Executor withProperty(java.lang.String key, int value)
int
property.key
- the property keyvalue
- the property valuepublic Executor withProperty(java.lang.String key, long value)
long
property.key
- the property keyvalue
- the property valuepublic Executor withProperty(java.lang.String key, boolean value)
boolean
property.key
- the property keyvalue
- the property valuepublic Executor withProperty(java.lang.String key, java.lang.String[] values)
String
array property.key
- the property keyvalues
- the property valuepublic Executor withProperty(java.lang.String key, float[] values)
float
array property.key
- the property keyvalues
- the property valuepublic Executor withProperty(java.lang.String key, double[] values)
double
array property.key
- the property keyvalues
- the property valuepublic Executor withProperty(java.lang.String key, byte[] values)
byte
array property.key
- the property keyvalues
- the property valuepublic Executor withProperty(java.lang.String key, short[] values)
short
array property.key
- the property keyvalues
- the property valuepublic Executor withProperty(java.lang.String key, int[] values)
int
array property.key
- the property keyvalues
- the property valuepublic Executor withProperty(java.lang.String key, long[] values)
long
array property.key
- the property keyvalues
- the property valuepublic Executor clearProperties()
public Executor withProperties(TypedProperties properties)
maxEvaluations
or maxTime
.properties
- the propertiespublic Executor withProgressListener(ProgressListener listener)
listener
- the progress listener to addprotected TerminationCondition createTerminationCondition()
public java.util.List<NondominatedPopulation> runSeeds(int numberOfSeeds)
numberOfSeeds
- the number of seeds to runpublic NondominatedPopulation run()
null
if canceledprotected Problem getDistributedProblemInstance()
ExecutorService
,
will wrap the problem instance in a distributed problem.protected NondominatedPopulation runSingleSeed(int seed, int numberOfSeeds)
seed
- the current seed being run, such that
1 <= seed <= numberOfSeeds
numberOfSeeds
- to total number of seeds being runnull
if canceledCopyright 2009-2024 David Hadka and other contributors. All rights reserved.
Licensed under the GNU Lesser General Public License.
Return to the MOEA Framework homepage.