Class DistributedProblem
java.lang.Object
org.moeaframework.problem.ProblemWrapper
org.moeaframework.util.distributed.DistributedProblem
- All Implemented Interfaces:
AutoCloseable
,Problem
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.-
Field Summary
Fields inherited from class org.moeaframework.problem.ProblemWrapper
problem
-
Constructor Summary
ConstructorDescriptionDistributedProblem
(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 specifiedExecutorService
.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 specifiedExecutorService
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes any underlying resources used by this problem.void
Evaluates the solution, updating the solution's objectives in place.static DistributedProblem
Creates a distributed problem using the number of available processors on the local computer.static DistributedProblem
Creates a distributed problem using a fixed number of threads.Returns a new solution for this problem.Methods inherited from class org.moeaframework.problem.ProblemWrapper
getName, getNumberOfConstraints, getNumberOfObjectives, getNumberOfVariables
-
Constructor Details
-
DistributedProblem
Decorates a problem for distributing the evaluation of the problem across multiple threads, cores or compute nodes as defined by the specifiedExecutorService
. This will not shutdown the executor and is equivalent to calling the constructor withshutdownWhenClosed
set tofalse
.- Parameters:
problem
- the problem being distributedexecutor
- theExecutorService
for distributing jobs across multiple threads, cores or compute nodes
-
DistributedProblem
Decorates a problem for distributing the evaluation of the problem across multiple threads, cores or compute nodes as defined by the specifiedExecutorService
.- Parameters:
problem
- the problem being distributedexecutor
- theExecutorService
for distributing jobs across multiple threads, cores or compute nodesshutdownWhenClosed
-true
to shutdown the executor when this problem instance is closed;false
otherwise
-
-
Method Details
-
from
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
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 distributenumberOfThreads
- the number of threads- Returns:
- the distributed problem
-
evaluate
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 interfaceProblem
- Overrides:
evaluate
in classProblemWrapper
- Parameters:
solution
- the solution to be evaluated
-
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 interfaceProblem
- Overrides:
newSolution
in classProblemWrapper
- 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 interfaceAutoCloseable
- Specified by:
close
in interfaceProblem
- Overrides:
close
in classProblemWrapper
-