Class MetricFileWriter

java.lang.Object
org.moeaframework.analysis.io.ResultWriter
org.moeaframework.analysis.io.MetricFileWriter
All Implemented Interfaces:
Closeable, AutoCloseable

public class MetricFileWriter extends ResultWriter
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.
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    Enumeration of metrics that are written to the metric file.
  • Constructor Summary

    Constructors
    Constructor
    Description
    MetricFileWriter(Indicators indicators, File file)
    Constructs an output writer for writing metric files to the specified file.
    MetricFileWriter(Indicators indicators, Writer writer)
    Constructs an output writer for writing metric files to the specified file.
  • Method Summary

    Modifier and Type
    Method
    Description
    append(Indicators indicators, File file)
    Opens the metric file in append mode.
    void
     
    static int
    Gets the index of the metric, either from its name or the column index.
    int
    Returns the number of entries in the file.
    open(Indicators indicators, File file)
    Opens the metric file.
    protected void
    Writes the header line to the file.
    static int
    repair(File file)
    Repairs the contents of the metric file, removing any incomplete or invalid entries from the file.
    protected void
    write(double[] values)
    Writes a line to the metric file containing the given decimal values separated by whitespace.
    protected void
    write(String[] values)
    Writes a line to the metric file containing the given strings separated by whitespace.
    void
    Evaluates the specified non-dominated population and outputs the resulting metrics to the file.

    Methods inherited from class org.moeaframework.analysis.io.ResultWriter

    failIfOutdated, replace

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MetricFileWriter

      public MetricFileWriter(Indicators indicators, File file) 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. The getNumberOfEntries() can then be used to resume evaluation from the last recorded entry.
      Parameters:
      indicators - the indicators to evaluate
      file - the file to which the metrics are written
      Throws:
      IOException - if an I/O error occurred
    • MetricFileWriter

      public MetricFileWriter(Indicators indicators, Writer writer) 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. The getNumberOfEntries() can then be used to resume evaluation from the last recorded entry.
      Parameters:
      indicators - the indicators to evaluate
      writer - the writer
      Throws:
      IOException - if an I/O error occurred
  • Method Details

    • getNumberOfEntries

      public int getNumberOfEntries()
      Description copied from class: ResultWriter
      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 the ResultWriter.write(org.moeaframework.analysis.series.ResultEntry) method.
      Specified by:
      getNumberOfEntries in class ResultWriter
      Returns:
      the number of entries in the file
    • write

      public void write(ResultEntry entry)
      Evaluates the specified non-dominated population and outputs the resulting metrics to the file.
      Specified by:
      write in class ResultWriter
      Parameters:
      entry - the non-dominated population and optional attributes
    • write

      protected void write(double[] values)
      Writes a line to the metric file containing the given decimal values separated by whitespace.
      Parameters:
      values - the values
    • write

      protected void write(String[] values)
      Writes a line to the metric file containing the given strings separated by whitespace.
      Parameters:
      values - the values
    • printHeader

      protected void printHeader()
      Writes the header line to the file.
    • getMetricIndex

      public static int getMetricIndex(String value)
      Gets the index of the metric, either from its name or the column index. This should match the order of values in MetricFileWriter.Metric.
      Parameters:
      value - the metric name or column index
      Returns:
      the index of the metric
    • close

      public void close()
    • append

      public static MetricFileWriter append(Indicators indicators, File file) throws IOException
      Opens the metric file in append mode. If the file already exists, any invalid entries will be removed by calling repair(File). Check getNumberOfEntries() to determine the number of valid entries in the file.
      Parameters:
      indicators - the indicators to evaluate
      file - the file
      Returns:
      the metric file writer
      Throws:
      IOException - if an I/O error occurred
    • open

      public static MetricFileWriter open(Indicators indicators, File file) throws IOException
      Opens the metric file. Any existing file will be replaced.
      Parameters:
      indicators - the indicators to evaluate
      file - the file
      Returns:
      the metric file writer
      Throws:
      IOException - if an I/O error occurred
    • repair

      public static int repair(File file) throws IOException
      Repairs the contents of the metric 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