MOEA Framework 2.12
API Specification

org.moeaframework.algorithm
Class AbstractAlgorithm

java.lang.Object
  extended by org.moeaframework.algorithm.AbstractAlgorithm
All Implemented Interfaces:
Algorithm
Direct Known Subclasses:
AbstractEvolutionaryAlgorithm, AbstractPSOAlgorithm, CMAES, MOEAD, PISAAlgorithm, RandomSearch, RepeatedSingleObjective

public abstract class AbstractAlgorithm
extends Object
implements Algorithm

Abstract class providing default implementations for several Algorithm methods. All method extending this class must use the evaluate(org.moeaframework.core.Solution) method to evaluate a solution. This is mandatory to ensure the getNumberOfEvaluations() method returns the correct result.

Subclasses should avoid overriding the step() method and instead override the initialize() and iterate() methods individually.


Field Summary
protected  boolean initialized
          true if the initialize() method has been invoked; false otherwise.
protected  int numberOfEvaluations
          The number of times the evaluate(org.moeaframework.core.Solution) method was invoked.
protected  Problem problem
          The problem being solved.
protected  boolean terminated
          true if the terminate() method has been invoked; false otherwise.
 
Constructor Summary
AbstractAlgorithm(Problem problem)
          Constructs an abstract algorithm for solving the specified problem.
 
Method Summary
 void evaluate(Solution solution)
          Evaluates the specified solution for the problem being solved by this algorithm.
 void evaluateAll(Iterable<Solution> solutions)
          Evaluates the specified solutions.
 void evaluateAll(Solution[] solutions)
          Evaluates the specified solutions.
protected  void finalize()
           
 int getNumberOfEvaluations()
          Returns the number of times the evaluate method was invoked.
 Problem getProblem()
          Returns the problem being solved by this algorithm.
 Serializable getState()
          Returns a Serializable object representing the internal state of this algorithm.
protected  void initialize()
          Performs any initialization that is required by this algorithm.
 boolean isInitialized()
          Returns true if the initialize() method has been invoked; false otherwise.
 boolean isTerminated()
          Returns true if this algorithm is terminated; false otherwise.
protected abstract  void iterate()
          Performs one iteration of the algorithm.
 void setState(Object state)
          Sets the internal state of of this algorithm.
 void step()
          This method first checks if the algorithm is initialized.
 void terminate()
          Implementations should always invoke super.terminate() to ensure the hierarchy is terminated correctly.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.moeaframework.core.Algorithm
getResult
 

Field Detail

problem

protected final Problem problem
The problem being solved.


numberOfEvaluations

protected int numberOfEvaluations
The number of times the evaluate(org.moeaframework.core.Solution) method was invoked.


initialized

protected boolean initialized
true if the initialize() method has been invoked; false otherwise.


terminated

protected boolean terminated
true if the terminate() method has been invoked; false otherwise.

Constructor Detail

AbstractAlgorithm

public AbstractAlgorithm(Problem problem)
Constructs an abstract algorithm for solving the specified problem.

Parameters:
problem - the problem being solved
Method Detail

evaluateAll

public void evaluateAll(Iterable<Solution> solutions)
Evaluates the specified solutions. This method calls evaluate(Solution) on each of the solutions. Subclasses should prefer calling this method over evaluate whenever possible, as this ensures the solutions can be evaluated in parallel.

Parameters:
solutions - the solutions to evaluate

evaluateAll

public void evaluateAll(Solution[] solutions)
Evaluates the specified solutions. This method is equivalent to evaluateAll(Arrays.asList(solutions)).

Parameters:
solutions - the solutions to evaluate

evaluate

public void evaluate(Solution solution)
Description copied from interface: Algorithm
Evaluates the specified solution for the problem being solved by this algorithm.

Specified by:
evaluate in interface Algorithm
Parameters:
solution - the solution to be evaluated
See Also:
Problem.evaluate(Solution)

getNumberOfEvaluations

public int getNumberOfEvaluations()
Description copied from interface: Algorithm
Returns the number of times the evaluate method was invoked. This is the primary measure of runtime for optimization algorithms.

Specified by:
getNumberOfEvaluations in interface Algorithm
Returns:
the number of times the evaluate method was invoked

getProblem

public Problem getProblem()
Description copied from interface: Algorithm
Returns the problem being solved by this algorithm.

Specified by:
getProblem in interface Algorithm
Returns:
the problem being solved by this algorithm

initialize

protected void initialize()
Performs any initialization that is required by this algorithm. This method is called automatically by the first invocation of step(), but may also be called manually prior to any invocations of step. Implementations should always invoke super.initialize() to ensure the hierarchy is initialized correctly.

Throws:
AlgorithmInitializationException - if the algorithm has already been initialized

isInitialized

public boolean isInitialized()
Returns true if the initialize() method has been invoked; false otherwise.

Returns:
true if the initialize() method has been invoked; false otherwise

step

public void step()
This method first checks if the algorithm is initialized. If not, the initialize() method is invoked. If initialized, all calls to step invoke iterate(). Implementations should override the initialize and iterate methods in preference to modifying this method.

Specified by:
step in interface Algorithm
Throws:
AlgorithmTerminationException - if the algorithm has already terminated

iterate

protected abstract void iterate()
Performs one iteration of the algorithm. This method should be overridden by implementations to perform each logical iteration of the algorithm.


isTerminated

public boolean isTerminated()
Description copied from interface: Algorithm
Returns true if this algorithm is terminated; false otherwise.

Specified by:
isTerminated in interface Algorithm
Returns:
true if this algorithm is terminated; false otherwise
See Also:
Algorithm.terminate()

terminate

public void terminate()
Implementations should always invoke super.terminate() to ensure the hierarchy is terminated correctly. This method is automatically invoked during finalization, and need only be called directly if non-Java resources are in use.

Specified by:
terminate in interface Algorithm
Throws:
AlgorithmTerminationException - if the algorithm has already terminated

finalize

protected void finalize()
                 throws Throwable
Overrides:
finalize in class Object
Throws:
Throwable

getState

public Serializable getState()
                      throws NotSerializableException
Description copied from interface: Algorithm
Returns a Serializable object representing the internal state of this algorithm.

Specified by:
getState in interface Algorithm
Returns:
a Serializable object representing the internal state of this algorithm
Throws:
NotSerializableException - if this algorithm does not support serialization

setState

public void setState(Object state)
              throws NotSerializableException
Description copied from interface: Algorithm
Sets the internal state of of this algorithm.

Specified by:
setState in interface Algorithm
Parameters:
state - the internal state of this algorithm
Throws:
NotSerializableException - if this algorithm does not support serialization

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!