Class AlgorithmWrapper<T extends Algorithm>

java.lang.Object
org.moeaframework.algorithm.extension.AlgorithmWrapper<T>
Type Parameters:
T - the type of the wrapped algorithm
All Implemented Interfaces:
Extensible, Algorithm, Configurable, Stateful
Direct Known Subclasses:
InstrumentedAlgorithm

public class AlgorithmWrapper<T extends Algorithm> extends Object implements Algorithm, Configurable
Wrapper for an algorithm. Unless overridden, all methods call the same method on the wrapped instance.
  • Constructor Details

    • AlgorithmWrapper

      public AlgorithmWrapper(T algorithm)
      Wraps the given algorithm.
      Parameters:
      algorithm - the algorithm to wrap
  • Method Details

    • getAlgorithm

      public T getAlgorithm()
      Returns the wrapped instance.
      Returns:
      the wrapped instance
    • evaluate

      public void evaluate(Solution solution)
      Description copied from interface: Algorithm
      Evaluates the specified solution for the problem being solved by this algorithm.
      Specified by:
      evaluate in interface Algorithm
      Parameters:
      solution - the solution to be evaluated
      See Also:
    • getNumberOfEvaluations

      public int getNumberOfEvaluations()
      Description copied from interface: Algorithm
      Returns the number of times the evaluate method was invoked. This is the primary measure of runtime for optimization algorithms.
      Specified by:
      getNumberOfEvaluations in interface Algorithm
      Returns:
      the number of times the evaluate method was invoked
    • getProblem

      public Problem getProblem()
      Description copied from interface: Algorithm
      Returns the problem being solved by this algorithm.
      Specified by:
      getProblem in interface Algorithm
      Returns:
      the problem being solved by this algorithm
    • 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
    • isInitialized

      public boolean isInitialized()
      Description copied from interface: Algorithm
      Returns true if this algorithm has been initialized; false otherwise.
      Specified by:
      isInitialized in interface Algorithm
      Returns:
      true if this algorithm has been initialized; false otherwise
      See Also:
    • 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.

      In general, calling this method after Algorithm.terminate() is permitted. When this happens, Algorithm.isTerminated() is reset. We recommend checking Algorithm.isTerminated() after each step to detect when termination conditions are reached. However, if the implementation is unable to continue, this method should throw AlgorithmTerminationException.

      Specified by:
      step in interface Algorithm
    • isTerminated

      public boolean isTerminated()
      Description copied from interface: Algorithm
      Returns true if this algorithm has reached its termination condition; false otherwise.
      Specified by:
      isTerminated in interface Algorithm
      Returns:
      true if this algorithm has reached its termination condition; false otherwise
      See Also:
    • terminate

      public void terminate()
      Description copied from interface: Algorithm
      Called when the termination condition is reached and the run is complete. This method is automatically called when using Algorithm.run(TerminationCondition), but can also be invoked directly if executing the algorithm step-by-step with Algorithm.step().

      Implementations should always call super.terminate() to ensure the algorithm is terminated correctly.

      Specified by:
      terminate in interface Algorithm
    • 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
    • getExtensions

      public Extensions getExtensions()
      Description copied from interface: Extensible
      Returns the extensions associated with the algorithm.
      Specified by:
      getExtensions in interface Extensible
      Returns:
      the extensions
    • 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
      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
      Parameters:
      stream - the stream
      Throws:
      IOException - if an I/O error occurred
      ClassNotFoundException - if the stream referenced a class that is not defined