MOEA Framework 2.12
API Specification

org.moeaframework
Class Executor

java.lang.Object
  extended by org.moeaframework.Executor

public class Executor
extends Object

Configures and executes algorithms while hiding the underlying boilerplate code needed to setup and safely execute an algorithm. For example, the following demonstrates its typical use:

   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 Summary
Executor()
          Constructs a new executor initialized with default settings.
 
Method Summary
 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(ExecutorService executorService)
          Sets the ExecutorService used by this executor to distribute solution evaluations.
 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(String key)
          Unsets a property.
 Executor resetCheckpointFile()
          Deletes the checkpoint file if it exists.
 NondominatedPopulation run()
          Runs this executor with its configured settings.
 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, TerminationCondition terminationCondition)
          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(String algorithmName)
          Sets the algorithm used by this executor.
 Executor withCheckpointFile(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(String problemName)
          Sets the problem used by this builder.
 Executor withProblemClass(Class<?> problemClass, Object... problemArguments)
          Sets the problem used by this builder.
 Executor withProblemClass(String problemClassName, 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(Properties properties)
          Sets all properties.
 Executor withProperty(String key, boolean value)
          Sets a boolean property.
 Executor withProperty(String key, byte value)
          Sets a byte property.
 Executor withProperty(String key, byte[] values)
          Sets a byte array property.
 Executor withProperty(String key, double value)
          Sets a double property.
 Executor withProperty(String key, double[] values)
          Sets a double array property.
 Executor withProperty(String key, float value)
          Sets a float property.
 Executor withProperty(String key, float[] values)
          Sets a float array property.
 Executor withProperty(String key, int value)
          Sets an int property.
 Executor withProperty(String key, int[] values)
          Sets an int array property.
 Executor withProperty(String key, long value)
          Sets a long property.
 Executor withProperty(String key, long[] values)
          Sets a long array property.
 Executor withProperty(String key, short value)
          Sets a short property.
 Executor withProperty(String key, short[] values)
          Sets a short array property.
 Executor withProperty(String key, String value)
          Sets a property.
 Executor withProperty(String key, 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)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Executor

public Executor()
Constructs a new executor initialized with default settings.

Method Detail

cancel

public void cancel()
Informs this executor to stop processing and returns any results collected thus far. This method is thread-safe.


isCanceled

public boolean isCanceled()
Returns 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.

Returns:
true if the canceled flag is set; false otherwise

withInstrumenter

public Executor withInstrumenter(Instrumenter instrumenter)
Sets the instrumenter used to record information about the runtime behavior of algorithms executed by this executor.

Parameters:
instrumenter - the instrumeter
Returns:
a reference to this executor

getInstrumenter

public Instrumenter getInstrumenter()
Returns the instrumenter used by this executor; or null if no instrumenter has been assigned.

Returns:
the instrumenter used by this executor; or null if no instrumenter has been assigned

usingAlgorithmFactory

public Executor usingAlgorithmFactory(AlgorithmFactory algorithmFactory)
Sets the algorithm factory used by this executor.

Parameters:
algorithmFactory - the algorithm factory
Returns:
a reference to this executor

withSameProblemAs

public Executor withSameProblemAs(org.moeaframework.ProblemBuilder builder)
Configures this builder to use the same problem, reference set, ε values and ProblemFactory as the specified instance.

Parameters:
builder - the instance whose problem, reference set, ε values and ProblemFactory are to be copied
Returns:
a reference to this builder

usingProblemFactory

public Executor usingProblemFactory(ProblemFactory problemFactory)
Sets the problem factory used by this builder.

Parameters:
problemFactory - the problem factory
Returns:
a reference to this builder

withProblem

public Executor withProblem(String problemName)
Sets the problem used by this builder.

Parameters:
problemName - the problem name
Returns:
a reference to this builder

withProblem

public Executor withProblem(Problem problemInstance)
Sets the problem instance used by this builder. Until the other 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.

Parameters:
problemInstance - the problem instance
Returns:
a reference to this builder

withProblemClass

public Executor withProblemClass(Class<?> problemClass,
                                 Object... problemArguments)
Sets the problem used by this builder. Instances of the problem are created using the 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.

Parameters:
problemClass - the problem class
problemArguments - the arguments passed to the problem constructor
Returns:
a reference to this builder

withProblemClass

public Executor withProblemClass(String problemClassName,
                                 Object... problemArguments)
                          throws ClassNotFoundException
Sets the problem used by this builder. Instances of the problem are created using the 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.

Parameters:
problemClassName - the problem class name
problemArguments - the arguments passed to the problem constructor
Returns:
a reference to this builder
Throws:
ClassNotFoundException - if the specified problem class name could not be found

withTerminationCondition

public Executor withTerminationCondition(TerminationCondition condition)

withAlgorithm

public Executor withAlgorithm(String algorithmName)
Sets the algorithm used by this executor.

Parameters:
algorithmName - the algorithm name
Returns:
a reference to this executor

distributeWith

public Executor distributeWith(ExecutorService executorService)
Sets the ExecutorService used by this executor to distribute solution evaluations. The caller is responsible for ensuring the executor service is shutdown after use.

Parameters:
executorService - the executor service
Returns:
a reference to this executor

distributeOn

public Executor distributeOn(int numberOfThreads)
Enables this executor to distribute solution evaluations across the specified number of threads.

Parameters:
numberOfThreads - the number of threads
Returns:
a reference to this executor
Throws:
IllegalArgumentException - if numberOfThreads <= 0

distributeOnAllCores

public Executor distributeOnAllCores()
Enables this executor to distribute solution evaluations across all processors on the local host.

Returns:
a reference to this executor

withCheckpointFile

public Executor withCheckpointFile(File checkpointFile)
Sets the checkpoint file where the algorithm state is stored. This method must be invoked in order to enable checkpoints.

Parameters:
checkpointFile - the checkpoint file
Returns:
a reference to this executor

withCheckpointFrequency

public Executor withCheckpointFrequency(int checkpointFrequency)
Sets the frequency at which this executor saves checkpoints.

Parameters:
checkpointFrequency - the checkpoint frequency, specifying the number of evaluations between checkpoints
Returns:
a reference to this executor

checkpointEveryIteration

public Executor checkpointEveryIteration()
Enables this executor to save checkpoints after every iteration of the algorithm.

Returns:
a reference to this executor

resetCheckpointFile

public Executor resetCheckpointFile()
                             throws IOException
Deletes the checkpoint file if it exists.

Returns:
a reference to this executor
Throws:
IOException - if the checkpoint file could not be deleted

withEpsilon

public Executor withEpsilon(double... epsilon)
Sets the ε values; equivalent to setting the property epsilon.

Parameters:
epsilon - the ε values
Returns:
a reference to this executor

withMaxEvaluations

public Executor withMaxEvaluations(int maxEvaluations)
Sets the maximum number of evaluations; equivalent to setting the property maxEvaluations.

Parameters:
maxEvaluations - the maximum number of evaluations
Returns:
a reference to this executor

withMaxTime

public Executor withMaxTime(long maxTime)
Sets the maximum elapsed time in milliseconds; equivalent to setting the property maxTime.

Parameters:
maxTime - the maximum elapsed time in milliseconds
Returns:
a reference to this executor

removeProperty

public Executor removeProperty(String key)
Unsets a property.

Parameters:
key - the property key
Returns:
a reference to this executor

withProperty

public Executor withProperty(String key,
                             String value)
Sets a property.

Parameters:
key - the property key
value - the property value
Returns:
a reference to this executor

withProperty

public Executor withProperty(String key,
                             float value)
Sets a float property.

Parameters:
key - the property key
value - the property value
Returns:
a reference to this executor

withProperty

public Executor withProperty(String key,
                             double value)
Sets a double property.

Parameters:
key - the property key
value - the property value
Returns:
a reference to this executor

withProperty

public Executor withProperty(String key,
                             byte value)
Sets a byte property.

Parameters:
key - the property key
value - the property value
Returns:
a reference to this executor

withProperty

public Executor withProperty(String key,
                             short value)
Sets a short property.

Parameters:
key - the property key
value - the property value
Returns:
a reference to this executor

withProperty

public Executor withProperty(String key,
                             int value)
Sets an int property.

Parameters:
key - the property key
value - the property value
Returns:
a reference to this executor

withProperty

public Executor withProperty(String key,
                             long value)
Sets a long property.

Parameters:
key - the property key
value - the property value
Returns:
a reference to this executor

withProperty

public Executor withProperty(String key,
                             boolean value)
Sets a boolean property.

Parameters:
key - the property key
value - the property value
Returns:
a reference to this executor

withProperty

public Executor withProperty(String key,
                             String[] values)
Sets a String array property.

Parameters:
key - the property key
values - the property value
Returns:
a reference to this executor

withProperty

public Executor withProperty(String key,
                             float[] values)
Sets a float array property.

Parameters:
key - the property key
values - the property value
Returns:
a reference to this executor

withProperty

public Executor withProperty(String key,
                             double[] values)
Sets a double array property.

Parameters:
key - the property key
values - the property value
Returns:
a reference to this executor

withProperty

public Executor withProperty(String key,
                             byte[] values)
Sets a byte array property.

Parameters:
key - the property key
values - the property value
Returns:
a reference to this executor

withProperty

public Executor withProperty(String key,
                             short[] values)
Sets a short array property.

Parameters:
key - the property key
values - the property value
Returns:
a reference to this executor

withProperty

public Executor withProperty(String key,
                             int[] values)
Sets an int array property.

Parameters:
key - the property key
values - the property value
Returns:
a reference to this executor

withProperty

public Executor withProperty(String key,
                             long[] values)
Sets a long array property.

Parameters:
key - the property key
values - the property value
Returns:
a reference to this executor

clearProperties

public Executor clearProperties()
Clears the properties.

Returns:
a reference to this executor

withProperties

public Executor withProperties(Properties properties)
Sets all properties. This will clear any existing properties, including the maxEvaluations or maxTime.

Parameters:
properties - the properties
Returns:
a reference to this executor

withProgressListener

public Executor withProgressListener(ProgressListener listener)
Adds the given progress listener to receive periodic progress reports.

Parameters:
listener - the progress listener to add
Returns:
a reference to this executor

createTerminationCondition

protected TerminationCondition createTerminationCondition()
Returns the termination condition for this executor.

Returns:
the termination condition

runSeeds

public List<NondominatedPopulation> runSeeds(int numberOfSeeds)
Runs this executor with its configured settings multiple times, returning the individual end-of-run approximation sets. If the run is canceled, the list contains any complete seeds that finished prior to cancellation.

Parameters:
numberOfSeeds - the number of seeds to run
Returns:
the individual end-of-run approximation sets

run

public NondominatedPopulation run()
Runs this executor with its configured settings.

Returns:
the end-of-run approximation set; or null if canceled

runSingleSeed

protected NondominatedPopulation runSingleSeed(int seed,
                                               int numberOfSeeds,
                                               TerminationCondition terminationCondition)
Runs this executor with its configured settings.

Parameters:
seed - the current seed being run, such that 1 <= seed <= numberOfSeeds
numberOfSeeds - to total number of seeds being run
terminationCondition - the termination conditions for the run
Returns:
the end-of-run approximation set; or null if canceled

MOEA Framework 2.12
API Specification

Copyright 2009-2016 MOEA Framework. All rights reserved.
Licensed under the GNU Lesser General Public License.
Return to the MOEA Framework homepage. Visit us on Github!