Class RandomSearch

java.lang.Object
org.moeaframework.algorithm.AbstractAlgorithm
org.moeaframework.algorithm.RandomSearch
All Implemented Interfaces:
Extensible, Algorithm, Configurable, Stateful

public class RandomSearch extends AbstractAlgorithm implements Configurable
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.
  • Constructor Details

    • RandomSearch

      public RandomSearch(Problem problem)
      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 solved
      sampleSize - the number of solutions sampled each iteration
      generator - the initialization routine used to generate random solutions
      archive - 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

      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
    • 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 throw AlgorithmInitializationException if called multiple times.

      Implementations should always call super.initialize() to ensure the algorithm is initialized correctly.

      Specified by:
      initialize in interface Algorithm
      Overrides:
      initialize in class AbstractAlgorithm
    • 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 class AbstractAlgorithm
    • saveState

      public void saveState(ObjectOutputStream stream) throws IOException
      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 calling super.saveState(stream) followed by writing each field.
      Specified by:
      saveState in interface Stateful
      Overrides:
      saveState in class AbstractAlgorithm
      Parameters:
      stream - the stream
      Throws:
      IOException - if an I/O error occurred
    • loadState

      public void loadState(ObjectInputStream stream) throws IOException, ClassNotFoundException
      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 in Stateful.saveState(ObjectOutputStream).
      Specified by:
      loadState in interface Stateful
      Overrides:
      loadState in class AbstractAlgorithm
      Parameters:
      stream - the stream
      Throws:
      IOException - if an I/O error occurred
      ClassNotFoundException - if the stream referenced a class that is not defined