Class TsvLogger

java.lang.Object
org.opt4j.common.logger.AbstractLogger
org.opt4j.common.logger.TsvLogger
All Implemented Interfaces:
Logger, IndividualStateListener, OptimizerIterationListener, OptimizerStateListener

public class TsvLogger extends AbstractLogger implements Logger
The TsvLogger writes all Individuals from the Archive to the specified file. It can be configured to write the data each iterationStep iterations or each evaluationStep evaluations. The file format is TSV (tab separated values), according to the Definition of tab-separated-values (tsv) by IANA.
  • Field Details

    • archive

      protected final Archive archive
  • Constructor Details

    • TsvLogger

      @Inject public TsvLogger(Archive archive, String filename, int evaluationStep, int iterationStep)
      Creates an TsvLogger.
      Parameters:
      archive - the archive
      filename - the filename (using namespace TsvLogger)
      evaluationStep - the number of evaluations between two logging events (using namespace TsvLogger)
      iterationStep - the number of iterations between two logging events (using namespace TsvLogger)
  • Method Details

    • initWriter

      protected PrintWriter initWriter(String filename)
      Initialize the print write from a filename
      Parameters:
      filename - the filename
      Returns:
      the print writer
    • optimizationStarted

      public void optimizationStarted()
      Description copied from class: AbstractLogger
      Callback method invoked once the optimization starts.
      Specified by:
      optimizationStarted in class AbstractLogger
    • logEvent

      public void logEvent(int iteration, int evaluation)
      Description copied from class: AbstractLogger
      Callback method called if the specific number of iterations or evaluations is reached.
      Specified by:
      logEvent in class AbstractLogger
      Parameters:
      iteration - the current iteration number
      evaluation - the current evaluation number
    • optimizationStopped

      public void optimizationStopped()
      Description copied from class: AbstractLogger
      Callback method invoked once the optimization stops.
      Specified by:
      optimizationStopped in class AbstractLogger
    • logHeader

      public void logHeader(Collection<Objective> objectives)
      Description copied from class: AbstractLogger
      Writes the header.
      Specified by:
      logHeader in class AbstractLogger
      Parameters:
      objectives - a collection of objectives
    • getColumnDelimiter

      protected String getColumnDelimiter()
      The String separating two columns. The tab character ("\t") is the default, which leads to a tab separated values file format (TSV).
      Returns:
      the delimiter
    • getIndividual

      protected String getIndividual(Individual individual)
      Creates a String representation of the given Individual. Per default, the Values of all Objectives of the individual, separated by getColumnDelimiter(), are returned. The String representation of a Value must not contain the tab character.
      Parameters:
      individual - the individual
      Returns:
      the corresponding string
    • getStatistics

      protected String getStatistics(int iteration, int evaluation, double time)
      Statistics for the given iteration and evaluation. Per default, the iteration, the number of evaluations and the optimization run time in milliseconds, separated by getColumnDelimiter(), are returned.
      Parameters:
      iteration - the current iteration
      evaluation - the current number of evaluations
      time - the current runtime of the optimization
      Returns:
      the corresponding string
    • getCommentDelimiter

      protected String getCommentDelimiter()
      The String starting a line comment. Default is the empty String ("") according to the TSV specification.
      Returns:
      the comment delimiter