Class ExternalProblem

java.lang.Object
org.moeaframework.problem.ExternalProblem
All Implemented Interfaces:
AutoCloseable, Named, Problem

public abstract class ExternalProblem extends Object implements 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 the Variable.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.

  • Field Details

    • DEFAULT_PORT

      public static final int DEFAULT_PORT
      The default port used by the MOEA Framework to connect to remote evaluation processes via sockets.
      See Also:
    • instance

      protected final ExternalProblem.Instance instance
      The instance backing this external problem, which manages the underlying resources including the process, socket, and streams.
  • Constructor Details

    • ExternalProblem

      public ExternalProblem(ExternalProblem.Builder builder)
      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 of evaluate are permitted.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Problem
    • evaluate

      public void evaluate(Solution solution) throws ProblemException
      Evaluates the specified solution using the process defined by this class' constructor.
      Specified by:
      evaluate in interface Problem
      Parameters:
      solution - the solution to evaluate
      Throws:
      ProblemException