Package org.moeaframework.analysis.io
Class ResultFileWriter
java.lang.Object
org.moeaframework.analysis.io.ResultWriter
org.moeaframework.analysis.io.ResultFileWriter
- All Implemented Interfaces:
Closeable
,AutoCloseable
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.
Each entry consists of properties, on lines starting with "//"
, and solutions, on all remaining lines.
Properties are stored using the same format as TypedProperties.save(Writer)
. The decision variables,
objectives, and constraints for each solution are separated by whitespace. Each decision variable is encoded using
Variable.encode()
. In the event an error occurs while encoding a decision variable, "-"
is written
and a warning issued.
Complete entries are always terminated by a line starting with the #
character.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionResultFileWriter
(Problem problem, File file) Constructs a result file writer for writing the decision variables and objectives of a sequence of non-dominated populations to a file.ResultFileWriter
(Problem problem, Writer writer) Constructs a result file writer for writing the decision variables and objectives of a sequence of non-dominated populations to a writer. -
Method Summary
Modifier and TypeMethodDescriptionstatic 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.Returns the error handler used by this reader.int
Returns the number of entries written to the result file.static ResultFileWriter
Opens the result file for writing.protected void
printHeader
(Problem problem) Writes the header section to the output.static int
Repairs the contents of the result file, removing any incomplete or invalid entries from the file.static int
Repairs the contents of the result file, removing any incomplete or invalid entries from the file.protected void
setExcludeVariables
(boolean excludeVariables) If set, excludes decision variables from the output.void
write
(ResultEntry entry) Writes the decision variables, objectives and optional properties to the output file.Methods inherited from class org.moeaframework.analysis.io.ResultWriter
failIfOutdated, replace
-
Constructor Details
-
ResultFileWriter
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 stored- Throws:
IOException
- if an I/O error occurred
-
ResultFileWriter
Constructs a result file writer for writing the decision variables and objectives of a sequence of non-dominated populations to a writer.- Parameters:
problem
- the problemwriter
- the output writer- Throws:
IOException
- if an I/O error occurred
-
-
Method Details
-
setExcludeVariables
protected void setExcludeVariables(boolean excludeVariables) If set, excludes decision variables from the output. In general, excluding variables is not recommended as it is then impossible to recover the original solution.- Parameters:
excludeVariables
-true
to exclude decision variables;false
otherwise
-
printHeader
Writes the header section to the output.- Parameters:
problem
- the problem- Throws:
IOException
- if an I/O error occurred
-
getErrorHandler
Returns the error handler used by this reader.- Returns:
- the error handler
-
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 classResultWriter
- Returns:
- the number of entries written to the result file thus far
-
write
Writes the decision variables, objectives and optional properties to the output file. Constraint violating solutions are not recorded.- Specified by:
write
in classResultWriter
- Parameters:
entry
- the entry to write- Throws:
IOException
- if an I/O error occurred
-
close
public void close() -
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
- Throws:
IOException
- if an error occurred during encoding and the error handler is configured to throw
-
open
Opens the result file for writing. Any existing file will be overwritten.- Parameters:
problem
- the problemfile
- the file- Returns:
- the result file writer
- Throws:
IOException
- if an I/O error occurred
-
append
Opens the result file in append mode. If the file already exists, any invalid entries will be removed by callingrepair(Problem, File)
. CheckgetNumberOfEntries()
to determine 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
-
repair
Repairs the contents of the result file, removing any incomplete or invalid entries from the file.- Parameters:
file
- the file- Returns:
- the number of valid entries in the file
- Throws:
IOException
- if an I/O error occurred
-
repair
Repairs the contents of the result file, removing any incomplete or invalid entries from the file.- Parameters:
problem
- the problem, ornull
to derive the problem from the result filefile
- the file- Returns:
- the number of valid entries in the file
- Throws:
IOException
- if an I/O error occurred
-