MOEA Framework 2.12
API Specification

org.moeaframework.problem
Class ExternalProblem

java.lang.Object
  extended by org.moeaframework.problem.ExternalProblem
All Implemented Interfaces:
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.

Standard I/O Mode

Standard I/O is the easiest mode to setup and run. First, an executable program on the computer is launched by invoking the constructor with the program name (and any optional arguments):
   new ExternalProblem("./problem.exe", "arg1", "arg2") { ... }
 
Then, solutions are sent to the process on its standard input (stdin) stream, and the objectives and constraints are read from its standard output (stdout) stream.

The program can not use the standard I/O for any other purpose. Programs which read from or write to the standard I/O streams should instead use sockets, as discussed below.

Socket Mode

Socket mode is more complicated to setup, but is more flexible and robust. It has the ability to not only evaluate the problem on the host computer, but can be spread across a computer network. To use sockets, use either the ExternalProblem(String, int) or ExternalProblem(InetAddress, int) constructor.

C/C++ Interface

A C/C++ interface is provided for implementing problems. This interface supports both modes of communication, depending on which initialization routine is invoked. See the moeaframework.c and moeaframework.h files in the examples/ folder for details. This interface conforms to the communication protocol described below.

The communication protocol consists of sending decision variables to the external process, and the process responding with the objectives and constraints. The decision variables line consists of one or more variables separated by whitespace and terminated by a newline. The process evaluates the problem for the given variables and outputs the objectives separated by whitespace and terminated by a newline. If the problem also has constraints, each constraint is returned after the objectives on the same line. The process must only terminate when the end of stream is reached. In addition, the process should flush the output stream to ensure the output is processed immediately.

Whitespace is one or more spaces, tabs or any combination thereof. The newline is either the line feed ('\n'), carriage return ('\r') or a carriage return followed immediately by a line feed ("\r\n").

It is critical that the close() method be invoked to ensure the external process is shutdown cleanly.


Field Summary
static int DEFAULT_PORT
          The default port used by the MOEA Framework to connect to remote evaluation processes via sockets.
 
Constructor Summary
ExternalProblem(InetAddress address, int port)
          Constructs an external problem that connects to a remote process via sockets.
ExternalProblem(String... command)
          Constructs an external problem using new ProcessBuilder(command).start().
ExternalProblem(String host, int port)
          Constructs an external problem that connects to a remote process via sockets.
 
Method Summary
 void close()
          Closes the connection to the process.
 void evaluate(Solution solution)
          Evaluates the specified solution using the process defined by this class' constructor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.moeaframework.core.Problem
getName, getNumberOfConstraints, getNumberOfObjectives, getNumberOfVariables, newSolution
 

Field Detail

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:
Constant Field Values
Constructor Detail

ExternalProblem

public ExternalProblem(String... command)
                throws IOException
Constructs an external problem using new ProcessBuilder(command).start(). If the command contains arguments, the arguments should be passed in as separate strings, such as
   new ExternalProblem("command", "arg1", "arg2");
 

Parameters:
command - a specified system command
Throws:
IOException - if an I/O error occured

ExternalProblem

public ExternalProblem(String host,
                       int port)
                throws IOException,
                       UnknownHostException
Constructs an external problem that connects to a remote process via sockets. The remote process should be instantiated and already listening to the designated port number prior to invoking this constructor.

Parameters:
host - the host name of the remote system; or null to use the local host
port - the port number
Throws:
UnknownHostException - if the IP address of the specified host could not be determined
IOException - if an I/O error occurred

ExternalProblem

public ExternalProblem(InetAddress address,
                       int port)
                throws IOException
Constructs an external problem that connects to a remote process via sockets. The remote process should be instantiated and already listening to the designated port number prior to invoking this constructor.

Parameters:
address - the IP address of the remote system
port - the port number
Throws:
IOException - if an I/O error occurred
Method Detail

close

public void close()
Closes the connection to the process. No further invocations of evaluate are permitted.

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

MOEA Framework 2.12
API Specification

Copyright 2009-2016 MOEA Framework. All rights reserved.
Licensed under the GNU Lesser General Public License.
Return to the MOEA Framework homepage. Visit us on Github!