Package org.moeaframework.analysis.io
Class MetricFileWriter
java.lang.Object
org.moeaframework.analysis.io.MetricFileWriter
- All Implemented Interfaces:
Closeable
,AutoCloseable
,OutputWriter
Writes metric files. A metric file is the output of
Evaluator
and contains on each line one or more
metrics separated by whitespace from one parameterization.
This writer can append the results to the file, if a previous file exists. By reading the previous file with a
MetricFileReader
, this writer will begin appending after the last valid entry. Query the
getNumberOfEntries()
to determine how many valid entries are contained in the file.
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Enumeration of metrics that are written to the metric file.static class
The settings used when writing metric files.Nested classes/interfaces inherited from interface org.moeaframework.analysis.io.OutputWriter
OutputWriter.OutputWriterSettings
-
Constructor Summary
ConstructorDescriptionMetricFileWriter
(Indicators indicators, File file, MetricFileWriter.MetricFileWriterSettings settings) Constructs an output writer for writing metric files to the specified file. -
Method Summary
Modifier and TypeMethodDescriptionvoid
append
(ResultEntry entry) Evaluates the specified non-dominated population and outputs the resulting metrics to the file.static MetricFileWriter
append
(Indicators indicators, File file) Opens the metric file in append mode.void
close()
static int
getMetricIndex
(String value) Gets the index of the metric, either from its name or the column index.int
Returns the number of entries in the file.static MetricFileWriter
overwrite
(Indicators indicators, File file) Opens the metric file in overwrite mode.
-
Constructor Details
-
MetricFileWriter
public MetricFileWriter(Indicators indicators, File file, MetricFileWriter.MetricFileWriterSettings settings) throws IOException Constructs an output writer for writing metric files to the specified file. If the file already exists, a cleanup operation is first performed. The cleanup operation removes any invalid entries from the file. ThegetNumberOfEntries()
can then be used to resume evaluation from the last recorded entry.- Parameters:
indicators
- the indicators to evaluatefile
- the file to which the metrics are writtensettings
- the settings for writing metric files- Throws:
IOException
- if an I/O error occurred
-
-
Method Details
-
getNumberOfEntries
public int getNumberOfEntries()Description copied from interface:OutputWriter
Returns the number of entries in the file. If the file already existed, this returns the number of complete entries in the output file. This value is incremented on every invocation to theOutputWriter.append(org.moeaframework.analysis.io.ResultEntry)
method.- Specified by:
getNumberOfEntries
in interfaceOutputWriter
- Returns:
- the number of entries in the file
-
append
Evaluates the specified non-dominated population and outputs the resulting metrics to the file.- Specified by:
append
in interfaceOutputWriter
- Parameters:
entry
- the non-dominated population and optional attributes
-
getMetricIndex
Gets the index of the metric, either from its name or the column index. This should match the order of values inMetricFileWriter.Metric
.- Parameters:
value
- the metric name or column index- Returns:
- the index of the metric
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
append
Opens the metric 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:
indicators
- the indicators to evaluatefile
- the file- Returns:
- the metric file writer
- Throws:
IOException
- if an I/O error occurred
-
overwrite
Opens the metric file in overwrite mode. Any existing file will be deleted.- Parameters:
indicators
- the indicators to evaluatefile
- the file- Returns:
- the metric file writer
- Throws:
IOException
- if an I/O error occurred
-