Class DistributedProblem

java.lang.Object
org.moeaframework.problem.ProblemWrapper
org.moeaframework.util.distributed.DistributedProblem
All Implemented Interfaces:
AutoCloseable, Problem

public class DistributedProblem extends ProblemWrapper
Distributes the evaluate(Solution) method across multiple threads, cores or compute nodes using the provided ExecutorService. The ExecutorService defines the type and method of distribution. The problem must be Serializable if executing on remote nodes.
  • Constructor Details

    • DistributedProblem

      public DistributedProblem(Problem problem, ExecutorService executor)
      Decorates a problem for distributing the evaluation of the problem across multiple threads, cores or compute nodes as defined by the specified ExecutorService. This will not shutdown the executor and is equivalent to calling the constructor with shutdownWhenClosed set to false.
      Parameters:
      problem - the problem being distributed
      executor - the ExecutorService for distributing jobs across multiple threads, cores or compute nodes
    • DistributedProblem

      public DistributedProblem(Problem problem, ExecutorService executor, boolean shutdownWhenClosed)
      Decorates a problem for distributing the evaluation of the problem across multiple threads, cores or compute nodes as defined by the specified ExecutorService.
      Parameters:
      problem - the problem being distributed
      executor - the ExecutorService for distributing jobs across multiple threads, cores or compute nodes
      shutdownWhenClosed - true to shutdown the executor when this problem instance is closed; false otherwise
  • Method Details

    • from

      public static DistributedProblem from(Problem problem)
      Creates a distributed problem using the number of available processors on the local computer. Callers should ensure the returned problem is closed, preferably using a try-with-resources block, to clean up the underlying resources.
      Parameters:
      problem - the problem to distribute
      Returns:
      the distributed problem
    • from

      public static DistributedProblem from(Problem problem, int numberOfThreads)
      Creates a distributed problem using a fixed number of threads. Callers should ensure the returned problem is closed, preferably using a try-with-resources block, to clean up the underlying resources.
      Parameters:
      problem - the problem to distribute
      numberOfThreads - the number of threads
      Returns:
      the distributed 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
      Overrides:
      evaluate in class ProblemWrapper
      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
      Overrides:
      newSolution in class ProblemWrapper
      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.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Problem
      Overrides:
      close in class ProblemWrapper