Package org.opt4j.common.logger
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
TheTsvLogger
writes allIndividual
s from theArchive
to the specified file. It can be configured to write the data eachiterationStep
iterations or eachevaluationStep
evaluations. The file format is TSV (tab separated values), according to the Definition of tab-separated-values (tsv) by IANA.
-
-
Field Summary
Fields Modifier and Type Field Description protected Archive
archive
-
Fields inherited from class org.opt4j.common.logger.AbstractLogger
evaluationCount, evaluationCountLast, evaluationStep, isFirst, iterationStep
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected String
getColumnDelimiter()
TheString
separating two columns.protected String
getCommentDelimiter()
TheString
starting a line comment.protected String
getIndividual(Individual individual)
Creates aString
representation of the givenIndividual
.protected String
getStatistics(int iteration, int evaluation, double time)
Statistics for the giveniteration
andevaluation
.protected PrintWriter
initWriter(String filename)
Initialize the print write from a filenamevoid
logEvent(int iteration, int evaluation)
Callback method called if the specific number of iterations or evaluations is reached.void
logHeader(Collection<Objective> objectives)
Writes the header.void
optimizationStarted()
Callback method invoked once the optimization starts.void
optimizationStopped()
Callback method invoked once the optimization stops.-
Methods inherited from class org.opt4j.common.logger.AbstractLogger
inidividualStateChanged, iterationComplete, optimizationStarted, optimizationStopped
-
-
-
-
Field Detail
-
archive
protected final Archive archive
-
-
Method Detail
-
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 classAbstractLogger
-
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 classAbstractLogger
- Parameters:
iteration
- the current iteration numberevaluation
- the current evaluation number
-
optimizationStopped
public void optimizationStopped()
Description copied from class:AbstractLogger
Callback method invoked once the optimization stops.- Specified by:
optimizationStopped
in classAbstractLogger
-
logHeader
public void logHeader(Collection<Objective> objectives)
Description copied from class:AbstractLogger
Writes the header.- Specified by:
logHeader
in classAbstractLogger
- Parameters:
objectives
- a collection of objectives
-
getColumnDelimiter
protected String getColumnDelimiter()
TheString
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 aString
representation of the givenIndividual
. Per default, theValue
s of allObjectives
of the individual, separated bygetColumnDelimiter()
, are returned. TheString
representation of aValue
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 giveniteration
andevaluation
. Per default, the iteration, the number of evaluations and the optimization run time in milliseconds, separated bygetColumnDelimiter()
, are returned.- Parameters:
iteration
- the current iterationevaluation
- the current number of evaluationstime
- the current runtime of the optimization- Returns:
- the corresponding string
-
-