Package org.moeaframework.algorithm
Class RandomSearch
java.lang.Object
org.moeaframework.algorithm.AbstractAlgorithm
org.moeaframework.algorithm.RandomSearch
- All Implemented Interfaces:
Extensible
,Algorithm
,Configurable
,Stateful
Random search implementation. An
Initialization
instance is used to generate random solutions, which are
evaluated and all non-dominated solutions retained. The result is the set of all non-dominated solutions.-
Field Summary
Fields inherited from class org.moeaframework.algorithm.AbstractAlgorithm
initialized, numberOfEvaluations, problem, terminated
-
Constructor Summary
ConstructorDescriptionRandomSearch
(Problem problem) Constructs a new random search procedure with default settings.RandomSearch
(Problem problem, int sampleSize, Initialization generator, NondominatedPopulation archive) Constructs a new random search procedure for the given problem. -
Method Summary
Modifier and TypeMethodDescriptionReturns the current best-known result.int
Returns the number of solutions sampled each iteration.void
Performs any initialization that is required by this algorithm.protected void
iterate()
Performs one iteration of the algorithm.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
setSampleSize
(int sampleSize) Sets the number of solutions sampled each iteration.Methods inherited from class org.moeaframework.algorithm.AbstractAlgorithm
assertNotInitialized, evaluate, getExtensions, getNumberOfEvaluations, getProblem, isInitialized, isTerminated, step, terminate
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.moeaframework.core.Algorithm
evaluateAll, evaluateAll, run, run
Methods inherited from interface org.moeaframework.core.configuration.Configurable
applyConfiguration, getConfiguration
Methods inherited from interface org.moeaframework.algorithm.extension.Extensible
addExtension, removeExtension
-
Constructor Details
-
RandomSearch
Constructs a new random search procedure with default settings.- Parameters:
problem
- the problem being solved
-
RandomSearch
public RandomSearch(Problem problem, int sampleSize, Initialization generator, NondominatedPopulation archive) Constructs a new random search procedure for the given problem.- Parameters:
problem
- the problem being solvedsampleSize
- the number of solutions sampled each iterationgenerator
- the initialization routine used to generate random solutionsarchive
- the archive of non-dominated solutions
-
-
Method Details
-
getSampleSize
public int getSampleSize()Returns the number of solutions sampled each iteration.- Returns:
- the sample size
-
setSampleSize
public void setSampleSize(int sampleSize) Sets the number of solutions sampled each iteration. The main reason to set the sample size is when distributed solution evaluations, as the sample size at least the number of threads. The default value is 100.- Parameters:
sampleSize
- the sample size
-
getResult
Description copied from interface:Algorithm
Returns the current best-known result. -
initialize
public void initialize()Description copied from interface:Algorithm
Performs any initialization that is required by this algorithm. This method should only be called once, though the specific implementation may choose to no-op or throwAlgorithmInitializationException
if called multiple times.Implementations should always call
super.initialize()
to ensure the algorithm is initialized correctly.- Specified by:
initialize
in interfaceAlgorithm
- Overrides:
initialize
in classAbstractAlgorithm
-
iterate
protected void iterate()Description copied from class:AbstractAlgorithm
Performs one iteration of the algorithm. This method should be overridden by implementations to perform each logical iteration of the algorithm.- Specified by:
iterate
in classAbstractAlgorithm
-
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
- Overrides:
saveState
in classAbstractAlgorithm
- 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
- Overrides:
loadState
in classAbstractAlgorithm
- Parameters:
stream
- the stream- Throws:
IOException
- if an I/O error occurredClassNotFoundException
- if the stream referenced a class that is not defined
-