Package org.moeaframework.problem
Class ExternalProblem
java.lang.Object
org.moeaframework.problem.ExternalProblem
- All Implemented Interfaces:
AutoCloseable
,Named
,Problem
Evaluate solutions using an externally-defined problem. Two modes of operation are supported: standard I/O and
sockets.
Communication Protocol
Each solution is evaluated serially by writing the decision variables to the process or socket, waiting for a response, and reading the objectives and constraints. Values are formatted using theVariable.toString()
method and separated by whitespace, typically a single space character, and sent on a single line terminated by the
new line character (which depending on the platform can be "\n"
, "\r"
, or "\r\n"
). This
process repeats in a loop until all solutions are evaluated, at which point the stream is closed. We strongly
recommend flushing the output stream after writing each line to prevent buffering.
Standard I/O
When using Standard I/O, a process is started and the data is transmitted over the standard input/output streams. One limitation of this approach is the process can not use standard input/output for any other purpose, as that will interfere with the communication. Consider using sockets instead.Sockets
When using Sockets, data is transmitted over the network. Typically, this talks to a local process using a specific port. However, this can also connect to a remote process over a local-area network or the Internet.
Users are required to call close()
to ensure the process and any resources are shutdown and
disposed. Failure to do so could leave any spawned processes running in the background. We recommend
using a try-with-resources block to automatically close the problem.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Builder for defining the process or connection to the external problem.protected static class
Instance of the external problem. -
Field Summary
Modifier and TypeFieldDescriptionstatic final int
The default port used by the MOEA Framework to connect to remote evaluation processes via sockets.protected final ExternalProblem.Instance
The instance backing this external problem, which manages the underlying resources including the process, socket, and streams. -
Constructor Summary
ConstructorDescriptionExternalProblem
(ExternalProblem.Builder builder) Constructs an external problem using the specified builder. -
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.moeaframework.problem.Problem
getName, getNumberOfConstraints, getNumberOfObjectives, getNumberOfVariables, isType, newSolution
-
Field Details
-
DEFAULT_PORT
public static final int DEFAULT_PORTThe default port used by the MOEA Framework to connect to remote evaluation processes via sockets.- See Also:
-
instance
The instance backing this external problem, which manages the underlying resources including the process, socket, and streams.
-
-
Constructor Details
-
ExternalProblem
Constructs an external problem using the specified builder.- Parameters:
builder
- the builder that defines the process and/or socket address
-
-
Method Details
-
close
public void close()Closes the connection to the process. No further invocations ofevaluate
are permitted.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceProblem
-
evaluate
Evaluates the specified solution using the process defined by this class' constructor.- Specified by:
evaluate
in interfaceProblem
- Parameters:
solution
- the solution to evaluate- Throws:
ProblemException
-