Package org.moeaframework.core
Class PeriodicAction
java.lang.Object
org.moeaframework.core.PeriodicAction
- Direct Known Subclasses:
AdaptiveTimeContinuation
,Checkpoints
,InstrumentedAlgorithm
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
Modifier and TypeClassDescriptionstatic enum
Defines the type of frequency. -
Field Summary
Modifier and TypeFieldDescriptionprotected final Algorithm
The underlying algorithm being decorated.protected int
The frequency that thedoAction()
method is invoked.protected final PeriodicAction.FrequencyType
The type of frequency.protected int
The number of invocations of theAlgorithm.step()
method.protected int
The last invocationdoAction()
was invoked, either as iterations or evaluations depending on the frequency type. -
Constructor Summary
ConstructorDescriptionPeriodicAction
(Algorithm algorithm, int frequency, PeriodicAction.FrequencyType frequencyType) Decorates an algorithm to perform a period action. -
Method Summary
Modifier and TypeMethodDescriptionabstract void
doAction()
Invoked periodically by this class to perform some function.void
Evaluates the specified solution for the problem being solved by this algorithm.protected Algorithm
Returns the algorithm that is wrapped by this periodic action.int
Returns the number of times theevaluate
method was invoked.Returns the problem being solved by this algorithm.Returns the current best-known result.boolean
Returnstrue
if this algorithm is terminated;false
otherwise.void
loadState
(ObjectInputStream stream) Loads the state of this object from the stream.void
saveState
(ObjectOutputStream stream) Writes the state of this object to the stream.void
step()
Performs one logical step of this algorithm.void
Terminates this algorithm.
-
Field Details
-
algorithm
The underlying algorithm being decorated. -
frequency
protected int frequencyThe frequency that thedoAction()
method is invoked. -
frequencyType
The type of frequency. -
iteration
protected int iterationThe number of invocations of theAlgorithm.step()
method. Only used if the frequency type isSTEPS
. -
lastInvocation
protected int lastInvocationThe last invocationdoAction()
was invoked, either as iterations or evaluations depending on the frequency type. A value of-1
indicates the run hasn't started yet.
-
-
Constructor Details
-
PeriodicAction
public PeriodicAction(Algorithm algorithm, int frequency, PeriodicAction.FrequencyType frequencyType) Decorates an algorithm to perform a period action.- Parameters:
algorithm
- the algorithm being decoratedfrequency
- the frequency thedoAction()
method is invokedfrequencyType
- the type of frequency
-
-
Method Details
-
getAlgorithm
Returns the algorithm that is wrapped by this periodic action.- Returns:
- the inner algorithm
-
getProblem
Description copied from interface:Algorithm
Returns the problem being solved by this algorithm.- Specified by:
getProblem
in interfaceAlgorithm
- Returns:
- the problem being solved by this algorithm
-
getResult
Description copied from 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()
returnstrue
. -
evaluate
Description copied from interface:Algorithm
Evaluates the specified solution for the problem being solved by this algorithm. -
getNumberOfEvaluations
public int getNumberOfEvaluations()Description copied from interface:Algorithm
Returns the number of times theevaluate
method was invoked. This is the primary measure of runtime for optimization algorithms.- Specified by:
getNumberOfEvaluations
in interfaceAlgorithm
- Returns:
- the number of times the
evaluate
method was invoked
-
isTerminated
public boolean isTerminated()Description copied from interface:Algorithm
Returnstrue
if this algorithm is terminated;false
otherwise.- Specified by:
isTerminated
in interfaceAlgorithm
- Returns:
true
if this algorithm is terminated;false
otherwise- See Also:
-
terminate
public void terminate()Description copied from interface:Algorithm
Terminates this algorithm. Implementations should use this method to free any underlying resources; however, theAlgorithm.getResult()
andAlgorithm.getNumberOfEvaluations()
methods are still required to work after termination. -
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. -
saveState
Description copied from interface:Stateful
Writes the state of this object to the stream. The order that objects are written to the stream is important. We recommend first callingsuper.saveState(stream)
followed by writing each field.- Specified by:
saveState
in interfaceStateful
- Parameters:
stream
- the stream- Throws:
IOException
- if an I/O error occurred
-
loadState
Description copied from interface:Stateful
Loads the state of this object from the stream. The order for reading objects from the stream must match the order they are written to the stream inStateful.saveState(ObjectOutputStream)
.- Specified by:
loadState
in interfaceStateful
- Parameters:
stream
- the stream- Throws:
IOException
- if an I/O error occurredClassNotFoundException
- if the stream referenced a class that is not defined
-