MOEA Framework 2.5
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

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()
          Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
 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
Description copied from class: java.lang.Object
Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. A subclass overrides the finalize method to dispose of system resources or to perform other cleanup.

The general contract of finalize is that it is invoked if and when the JavaTM virtual machine has determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, except as a result of an action taken by the finalization of some other object or class which is ready to be finalized. The finalize method may take any action, including making this object available again to other threads; the usual purpose of finalize, however, is to perform cleanup actions before the object is irrevocably discarded. For example, the finalize method for an object that represents an input/output connection might perform explicit I/O transactions to break the connection before the object is permanently discarded.

The finalize method of class Object performs no special action; it simply returns normally. Subclasses of Object may override this definition.

The Java programming language does not guarantee which thread will invoke the finalize method for any given object. It is guaranteed, however, that the thread that invokes finalize will not be holding any user-visible synchronization locks when finalize is invoked. If an uncaught exception is thrown by the finalize method, the exception is ignored and finalization of that object terminates.

After the finalize method has been invoked for an object, no further action is taken until the Java virtual machine has again determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, including possible actions by other objects or classes which are ready to be finalized, at which point the object may be discarded.

The finalize method is never invoked more than once by a Java virtual machine for any given object.

Any exception thrown by the finalize method causes the finalization of this object to be halted, but is otherwise ignored.

Overrides:
finalize in class Object
Throws:
Throwable - the Exception raised by this method

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.5
API Specification

Copyright 2009-2015 MOEA Framework. All rights reserved.
Licensed under the GNU Lesser General Public License.
Return to the MOEA Framework homepage. Hosted by Get MOEA Framework at SourceForge.net. Fast, secure and Free Open Source software downloads