Class ProblemWrapper

java.lang.Object
org.moeaframework.problem.ProblemWrapper
All Implemented Interfaces:
AutoCloseable, Named, Problem
Direct Known Subclasses:
DistributedProblem, RotatedProblem, ScaledProblem

public abstract class ProblemWrapper extends Object implements Problem
Wraps a problem instance to modify or extend its functionality.

All methods invoke the corresponding method on the inner problem. Subclasses need only override the methods they need to change.

  • Field Details

    • problem

      protected final Problem problem
      The original problem instance.
  • Constructor Details

    • ProblemWrapper

      protected ProblemWrapper(Problem problem)
      Constructs a new problem wrapper to modify or extend the functionality of the given problem.
      Parameters:
      problem - the problem being modified or extended
  • Method Details

    • getName

      public String getName()
      Description copied from interface: Problem
      Returns the name of this problem. Whenever possible, this name should match the name recognized by ProblemFactory.
      Specified by:
      getName in interface Named
      Specified by:
      getName in interface Problem
      Returns:
      the name of this problem
    • getNumberOfVariables

      public int getNumberOfVariables()
      Description copied from interface: Problem
      Returns the number of decision variables defined by this problem.
      Specified by:
      getNumberOfVariables in interface Problem
      Returns:
      the number of decision variables defined by this problem
    • getNumberOfObjectives

      public int getNumberOfObjectives()
      Description copied from interface: Problem
      Returns the number of objectives defined by this problem.
      Specified by:
      getNumberOfObjectives in interface Problem
      Returns:
      the number of objectives defined by this problem
    • getNumberOfConstraints

      public int getNumberOfConstraints()
      Description copied from interface: Problem
      Returns the number of constraints defined by this problem.
      Specified by:
      getNumberOfConstraints in interface Problem
      Returns:
      the number of constraints defined by this problem
    • evaluate

      public void evaluate(Solution solution)
      Description copied from interface: Problem
      Evaluates the solution, updating the solution's objectives in place. Algorithms must explicitly call this method when appropriate to evaluate new solutions or reevaluate modified solutions.
      Specified by:
      evaluate in interface Problem
      Parameters:
      solution - the solution to be evaluated
    • newSolution

      public Solution newSolution()
      Description copied from interface: Problem
      Returns a new solution for this problem. Implementations must initialize the variables so that the valid range of values is defined, but typically leave the actual value at a default or undefined state.
      Specified by:
      newSolution in interface Problem
      Returns:
      a new solution for this problem
    • close

      public void close()
      Description copied from interface: Problem
      Closes any underlying resources used by this problem. Once closed, further invocations of any methods on this problem may throw exceptions.

      While most problems do not use any disposable resources and this method can simply no-op, the best practice is wrapping the constructed problem instance inside a try-with-resources block so it is automatically closed. Java may flag offending code with a warning. Implementations that do require closing should indicate this in any documentation.

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Problem