MOEA Framework 2.12
API Specification

org.moeaframework.analysis.sensitivity
Class ResultFileWriter

java.lang.Object
  extended by org.moeaframework.analysis.sensitivity.ResultFileWriter
All Implemented Interfaces:
Closeable, OutputWriter

public class ResultFileWriter
extends Object
implements OutputWriter

Writes result files. A result file contains one or more entries consisting of a non-dominated population and optional properties. Entries are separated by one or more consecutive lines starting with the # character. Text contained on these lines after the # character are ignored.

An entry contains two pieces of data: 1) properties which are defined on lines starting with // in the same format as Properties; and 2) lines containing a sequence of floating-point numbers listing, in order, the real-valued decision variables and objectives. Each decision variable is separated by one or more whitespace characters. Decision variables that can not be encoded appear as -. The writer will attempt to output the data in a human-readable format, but falls back on Base64 encoded serialized objects to store serializable variables.

Complete entries are always terminated by a line starting with the # character. Incomplete entries, such as those with the incorrect number of decision variables or objectives, are automatically removed.

This writer will append the results to the file, if a previous file exists. By reading the previous file with a ResultFileReader, this writer will being appending after the last valid entry. Query the getNumberOfEntries() method to determine how many valid entries are contained in the file.

See Also:
ResultFileReader

Field Summary
protected static String ENCODING_WARNING
          The message displayed when an unsupported decision variable type is encountered.
protected static String EXISTING_FILE
          The message displayed when an unclean file exists from a previous run.
protected static String NO_VARIABLES_WARNING
          The message displayed when excluding the decision variables when saving a result file.
 
Constructor Summary
ResultFileWriter(Problem problem, File file)
          Equivalent to ResultWriter(problem, file, true).
ResultFileWriter(Problem problem, File file, boolean includeVariables)
          Constructs an output writer for writing the decision variables and objectives of a sequence of non-dominated populations to a file.
 
Method Summary
 void append(ResultEntry entry)
          Appends the decision variables, objectives and optional properties to the output file.
 void close()
           
 String encode(Variable variable)
          Encodes the decision variable into a string representation that can be safely written to a result file.
 int getNumberOfEntries()
          Returns the number of entries written to the result file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ENCODING_WARNING

protected static final String ENCODING_WARNING
The message displayed when an unsupported decision variable type is encountered.

See Also:
Constant Field Values

NO_VARIABLES_WARNING

protected static final String NO_VARIABLES_WARNING
The message displayed when excluding the decision variables when saving a result file.

See Also:
Constant Field Values

EXISTING_FILE

protected static final String EXISTING_FILE
The message displayed when an unclean file exists from a previous run.

See Also:
Constant Field Values
Constructor Detail

ResultFileWriter

public ResultFileWriter(Problem problem,
                        File file)
                 throws IOException
Equivalent to ResultWriter(problem, file, true).

Parameters:
problem - the problem
file - the file to which the results are stored
Throws:
IOException

ResultFileWriter

public ResultFileWriter(Problem problem,
                        File file,
                        boolean includeVariables)
                 throws IOException
Constructs an output writer for writing the decision variables and objectives of a sequence of non-dominated populations to a file. If the file already exists, any valid entries are retained and getNumberOfEntries() returns the number of valid entries. This allows resuming evaluation at the last valid result.

It is recommended to avoid setting includeVariables to false. Any computations requiring decision variables may result in unexpected and hard to trace errors.

Parameters:
problem - the problem
file - the file to which the results are stored
includeVariables - true if this writer should save the decision variables; false otherwise.
Throws:
IOException
Method Detail

getNumberOfEntries

public int getNumberOfEntries()
Returns the number of entries written to the result file. Querying this method immediately after the constructor in which the result file already existed returns the number of valid entries contained in the result file.

Specified by:
getNumberOfEntries in interface OutputWriter
Returns:
the number of entries written to the result file

append

public void append(ResultEntry entry)
            throws IOException
Appends the decision variables, objectives and optional properties to the output file. Constraint violating solutions are not recorded.

Specified by:
append in interface OutputWriter
Parameters:
entry - the entry to write
Throws:
IOException - if an I/O error occurred

close

public void close()
Specified by:
close in interface Closeable

encode

public String encode(Variable variable)
Encodes the decision variable into a string representation that can be safely written to a result file. The resulting strings must not contain any whitespace characters. For decision variables that do not support a valid encoding, the string "-" will be returned and a warning message printed.

Parameters:
variable - the decision variable to encode
Returns:
the string representation of the decision variable

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!