public abstract class AbstractAlgorithm
extends java.lang.Object
implements org.moeaframework.core.Algorithm
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.
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
initialized
|
protected int |
numberOfEvaluations
The number of times the
evaluate(org.moeaframework.core.Solution) method was invoked. |
protected org.moeaframework.core.Problem |
problem
The problem being solved.
|
protected boolean |
terminated
|
| Constructor and Description |
|---|
AbstractAlgorithm(org.moeaframework.core.Problem problem)
Constructs an abstract algorithm for solving the specified problem.
|
| Modifier and Type | Method and Description |
|---|---|
void |
evaluate(org.moeaframework.core.Solution solution) |
void |
evaluateAll(java.lang.Iterable<org.moeaframework.core.Solution> solutions)
Evaluates the specified solutions.
|
void |
evaluateAll(org.moeaframework.core.Solution[] solutions)
Evaluates the specified solutions.
|
int |
getNumberOfEvaluations() |
org.moeaframework.core.Problem |
getProblem() |
java.io.Serializable |
getState() |
protected void |
initialize()
Performs any initialization that is required by this algorithm.
|
boolean |
isInitialized()
|
boolean |
isTerminated() |
protected abstract void |
iterate()
Performs one iteration of the algorithm.
|
void |
setState(java.lang.Object state) |
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. |
protected final org.moeaframework.core.Problem problem
protected int numberOfEvaluations
evaluate(org.moeaframework.core.Solution) method was invoked.protected boolean initialized
protected boolean terminated
public AbstractAlgorithm(org.moeaframework.core.Problem problem)
problem - the problem being solvedpublic void evaluateAll(java.lang.Iterable<org.moeaframework.core.Solution> solutions)
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.solutions - the solutions to evaluatepublic void evaluateAll(org.moeaframework.core.Solution[] solutions)
evaluateAll(Arrays.asList(solutions)).solutions - the solutions to evaluatepublic void evaluate(org.moeaframework.core.Solution solution)
evaluate in interface org.moeaframework.core.Algorithmpublic int getNumberOfEvaluations()
getNumberOfEvaluations in interface org.moeaframework.core.Algorithmpublic org.moeaframework.core.Problem getProblem()
getProblem in interface org.moeaframework.core.Algorithmprotected void initialize()
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.org.moeaframework.algorithm.AlgorithmInitializationException - if the algorithm has already
been initializedpublic boolean isInitialized()
true if the initialize() method has been
invoked; false otherwisepublic void step()
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.step in interface org.moeaframework.core.Algorithmorg.moeaframework.algorithm.AlgorithmTerminationException - if the algorithm has already
terminatedprotected abstract void iterate()
public boolean isTerminated()
isTerminated in interface org.moeaframework.core.Algorithmpublic void terminate()
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.terminate in interface org.moeaframework.core.Algorithmorg.moeaframework.algorithm.AlgorithmTerminationException - if the algorithm has already
terminatedpublic java.io.Serializable getState()
throws java.io.NotSerializableException
getState in interface org.moeaframework.core.Algorithmjava.io.NotSerializableExceptionpublic void setState(java.lang.Object state)
throws java.io.NotSerializableException
setState in interface org.moeaframework.core.Algorithmjava.io.NotSerializableException