Class ResultFileWriter
- All Implemented Interfaces:
Closeable
,AutoCloseable
,OutputWriter
#
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 TypedProperties
; 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.
When appending is enabled, this will attempt to recover any valid records from the previous file. Query the
getNumberOfEntries()
method to determine how many valid entries were recovered.
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
The settings used when writing result files.Nested classes/interfaces inherited from interface org.moeaframework.analysis.io.OutputWriter
OutputWriter.OutputWriterSettings
-
Constructor Summary
ConstructorDescriptionResultFileWriter
(Problem problem, File file, ResultFileWriter.ResultFileWriterSettings settings) Constructs a result file writer for writing the decision variables and objectives of a sequence of non-dominated populations to a file. -
Method Summary
Modifier and TypeMethodDescriptionvoid
append
(ResultEntry entry) Appends the decision variables, objectives and optional properties to the output file.static ResultFileWriter
Opens the result file in append mode.void
close()
Encodes the decision variable into a string representation that can be safely written to a result file.int
Returns the number of entries written to the result file.static ResultFileWriter
Opens the result file in overwrite mode.
-
Constructor Details
-
ResultFileWriter
public ResultFileWriter(Problem problem, File file, ResultFileWriter.ResultFileWriterSettings settings) throws IOException Constructs a result file writer for writing the decision variables and objectives of a sequence of non-dominated populations to a file.- Parameters:
problem
- the problemfile
- the file to which the results are storedsettings
- the settings to use when writing the result file- Throws:
IOException
- if an I/O error occurred
-
-
Method Details
-
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 that were recovered.- Specified by:
getNumberOfEntries
in interfaceOutputWriter
- Returns:
- the number of entries written to the result file thus far
-
append
Appends the decision variables, objectives and optional properties to the output file. Constraint violating solutions are not recorded.- Specified by:
append
in interfaceOutputWriter
- Parameters:
entry
- the entry to write- Throws:
IOException
- if an I/O error occurred
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
encode
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
-
append
Opens the result file in append mode. If the file already exists, this writer will validate the contents, remove any invalid entries at the end of the file, and report the number of valid entries in the file.- Parameters:
problem
- the problemfile
- the file- Returns:
- the result file writer
- Throws:
IOException
- if an I/O error occurred
-
overwrite
Opens the result file in overwrite mode. Any existing file will be deleted.- Parameters:
problem
- the problemfile
- the file- Returns:
- the result file writer
- Throws:
IOException
- if an I/O error occurred
-