Class AbstractAlgorithm
- java.lang.Object
-
- ai.libs.jaicore.ea.algorithm.moea.moeaframework.AbstractAlgorithm
-
- All Implemented Interfaces:
org.moeaframework.core.Algorithm
- Direct Known Subclasses:
AEvolutionaryAlgorithm
public abstract class AbstractAlgorithm extends java.lang.Object implements org.moeaframework.core.AlgorithmAbstract class providing default implementations for severalAlgorithmmethods. All method extending this class must use theevaluate(org.moeaframework.core.Solution)method to evaluate a solution. This is mandatory to ensure thegetNumberOfEvaluations()method returns the correct result.Subclasses should avoid overriding the
step()method and instead override theinitialize()anditerate()methods individually.
-
-
Field Summary
Fields Modifier and Type Field Description protected booleaninitializedprotected intnumberOfEvaluationsThe number of times theevaluate(org.moeaframework.core.Solution)method was invoked.protected org.moeaframework.core.ProblemproblemThe problem being solved.protected booleanterminated
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractAlgorithm(org.moeaframework.core.Problem problem)Constructs an abstract algorithm for solving the specified problem.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidevaluate(org.moeaframework.core.Solution solution)voidevaluateAll(java.lang.Iterable<org.moeaframework.core.Solution> solutions)Evaluates the specified solutions.voidevaluateAll(org.moeaframework.core.Solution[] solutions)Evaluates the specified solutions.intgetNumberOfEvaluations()org.moeaframework.core.ProblemgetProblem()java.io.SerializablegetState()protected voidinitialize()Performs any initialization that is required by this algorithm.booleanisInitialized()booleanisTerminated()protected abstract voiditerate()Performs one iteration of the algorithm.voidsetState(java.lang.Object state)voidstep()This method first checks if the algorithm is initialized.voidterminate()Implementations should always invokesuper.terminate()to ensure the hierarchy is terminated correctly.
-
-
-
Field Detail
-
problem
protected final org.moeaframework.core.Problem problem
The problem being solved.
-
numberOfEvaluations
protected int numberOfEvaluations
The number of times theevaluate(org.moeaframework.core.Solution)method was invoked.
-
initialized
protected boolean initialized
-
terminated
protected boolean terminated
-
-
Method Detail
-
evaluateAll
public void evaluateAll(java.lang.Iterable<org.moeaframework.core.Solution> solutions)
Evaluates the specified solutions. This method callsevaluate(Solution)on each of the solutions. Subclasses should prefer calling this method overevaluatewhenever possible, as this ensures the solutions can be evaluated in parallel.- Parameters:
solutions- the solutions to evaluate
-
evaluateAll
public void evaluateAll(org.moeaframework.core.Solution[] solutions)
Evaluates the specified solutions. This method is equivalent toevaluateAll(Arrays.asList(solutions)).- Parameters:
solutions- the solutions to evaluate
-
evaluate
public void evaluate(org.moeaframework.core.Solution solution)
- Specified by:
evaluatein interfaceorg.moeaframework.core.Algorithm
-
getNumberOfEvaluations
public int getNumberOfEvaluations()
- Specified by:
getNumberOfEvaluationsin interfaceorg.moeaframework.core.Algorithm
-
getProblem
public org.moeaframework.core.Problem getProblem()
- Specified by:
getProblemin interfaceorg.moeaframework.core.Algorithm
-
initialize
protected void initialize()
Performs any initialization that is required by this algorithm. This method is called automatically by the first invocation ofstep(), but may also be called manually prior to any invocations ofstep. Implementations should always invokesuper.initialize()to ensure the hierarchy is initialized correctly.- Throws:
org.moeaframework.algorithm.AlgorithmInitializationException- if the algorithm has already been initialized
-
isInitialized
public boolean isInitialized()
- Returns:
trueif theinitialize()method has been invoked;falseotherwise
-
step
public void step()
This method first checks if the algorithm is initialized. If not, theinitialize()method is invoked. If initialized, all calls tostepinvokeiterate(). Implementations should override theinitializeanditeratemethods in preference to modifying this method.- Specified by:
stepin interfaceorg.moeaframework.core.Algorithm- Throws:
org.moeaframework.algorithm.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()
- Specified by:
isTerminatedin interfaceorg.moeaframework.core.Algorithm
-
terminate
public void terminate()
Implementations should always invokesuper.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:
terminatein interfaceorg.moeaframework.core.Algorithm- Throws:
org.moeaframework.algorithm.AlgorithmTerminationException- if the algorithm has already terminated
-
getState
public java.io.Serializable getState() throws java.io.NotSerializableException- Specified by:
getStatein interfaceorg.moeaframework.core.Algorithm- Throws:
java.io.NotSerializableException
-
setState
public void setState(java.lang.Object state) throws java.io.NotSerializableException- Specified by:
setStatein interfaceorg.moeaframework.core.Algorithm- Throws:
java.io.NotSerializableException
-
-