MOEA Framework 2.12
API Specification

org.moeaframework.algorithm
Class PeriodicAction

java.lang.Object
  extended by org.moeaframework.algorithm.PeriodicAction
All Implemented Interfaces:
Algorithm
Direct Known Subclasses:
AdaptiveTimeContinuation, Checkpoints, InstrumentedAlgorithm

public abstract class PeriodicAction
extends Object
implements Algorithm

Decorates an algorithm to perform some action periodically throughout the execution of the algorithm. Note that due to the underlying implementation of the algorithm, the action may be invoked less frequently than requested or not at all.


Nested Class Summary
static class PeriodicAction.FrequencyType
          Defines the type of frequency.
 
Field Summary
protected  Algorithm algorithm
          The underlying algorithm being decorated.
protected  int frequency
          The frequency that the doAction() method is invoked.
protected  PeriodicAction.FrequencyType frequencyType
          The type of frequency.
protected  int iteration
          The number of invocations of the Algorithm.step() method.
protected  int lastInvocation
          The last invocation doAction() was invoked.
 
Constructor Summary
PeriodicAction(Algorithm algorithm, int frequency, PeriodicAction.FrequencyType frequencyType)
          Decorates an algorithm to perform a period action.
 
Method Summary
abstract  void doAction()
          Invoked periodically by this class to perform some function.
 void evaluate(Solution solution)
          Evaluates the specified solution for the problem being solved by this algorithm.
 int getNumberOfEvaluations()
          Returns the number of times the evaluate method was invoked.
 Problem getProblem()
          Returns the problem being solved by this algorithm.
 NondominatedPopulation getResult()
          Returns the current best-known result.
 Serializable getState()
          Returns a Serializable object representing the internal state of this algorithm.
 boolean isTerminated()
          Returns true if this algorithm is terminated; false otherwise.
 void setState(Object state)
          Sets the internal state of of this algorithm.
 void step()
          Performs one logical step of this algorithm.
 void terminate()
          Terminates this algorithm.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

algorithm

protected final Algorithm algorithm
The underlying algorithm being decorated.


frequency

protected final int frequency
The frequency that the doAction() method is invoked.


frequencyType

protected final PeriodicAction.FrequencyType frequencyType
The type of frequency.


iteration

protected int iteration
The number of invocations of the Algorithm.step() method. Only used if the frequency type is STEPS.


lastInvocation

protected int lastInvocation
The last invocation doAction() was invoked. Only used if the frequency type is STEPS.

Constructor Detail

PeriodicAction

public PeriodicAction(Algorithm algorithm,
                      int frequency,
                      PeriodicAction.FrequencyType frequencyType)
Decorates an algorithm to perform a period action.

Parameters:
algorithm - the algorithm being decorated
frequency - the frequency the doAction() method is invoked
frequencyType - the type of frequency
Method Detail

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

getResult

public NondominatedPopulation getResult()
Description copied from interface: Algorithm
Returns the current best-known result.

Specified by:
getResult in interface Algorithm
Returns:
the current best-known result

step

public void step()
Description copied from interface: Algorithm
Performs one logical step of this algorithm. The amount of work performed depends on the implementation. One invocation of this method may produce one or many trial solutions.

This method should not be invoked when Algorithm.isTerminated() returns true.

Specified by:
step in interface Algorithm

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

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()
Description copied from interface: Algorithm
Terminates this algorithm. Implementations should use this method to free any underlying resources; however, the Algorithm.getResult() and Algorithm.getNumberOfEvaluations() methods are still required to work after termination.

Specified by:
terminate in interface Algorithm

doAction

public abstract void doAction()
Invoked periodically by this class to perform some function. This function should not depend on the frequency that it is invoked, since it is not guaranteed that this method is invoked at any specific frequency and, in some cases, may not be invoked at all.


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!