Class CSVEvolutionListener<T extends Comparable<T>,U>
java.lang.Object
net.bmahe.genetics4j.extras.evolutionlisteners.CSVEvolutionListener<T,U>
- Type Parameters:
T- Fitness typeU- Data type written to the CSV
- All Implemented Interfaces:
EvolutionListener<T>
- Direct Known Subclasses:
ImmutableCSVEvolutionListener
@Immutable
public abstract class CSVEvolutionListener<T extends Comparable<T>,U>
extends Object
implements EvolutionListener<T>
Evolution Listener which writes the output of each generation to a CSV file
- Author:
- bruno
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classCSVEvolutionListener.Builder<T extends Comparable<T>,U> -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate org.apache.commons.csv.CSVPrinterstatic final booleanstatic final org.apache.logging.log4j.Logger -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanWhether or not the CSV writer has auto flush enabled.abstract List<ColumnExtractor<T, U>> List of Column Extractors.User defined function to provide some additional information when computing the value to write.abstract Stringfilename()Destination file name for the CSV fileFunction<Stream<EvolutionStep<T, U>>, Stream<EvolutionStep<T, U>>> filter()Users can supply an optional set of filters to control which individuals get written and in which order.static <T extends Comparable<T>,U>
CSVEvolutionListener<T, U> of(String filename, Iterable<? extends ColumnExtractor<T, U>> columnExtractors) static <T extends Comparable<T>,U>
CSVEvolutionListener<T, U> of(String filename, List<ColumnExtractor<T, U>> columnExtractors) static <T extends Comparable<T>,U>
CSVEvolutionListener<T, U> of(String filename, GenerationFunction<T, U> evolutionContextSupplier, Iterable<? extends ColumnExtractor<T, U>> columnExtractors) static <T extends Comparable<T>,U>
CSVEvolutionListener<T, U> of(String filename, GenerationFunction<T, U> evolutionContextSupplier, Iterable<? extends ColumnExtractor<T, U>> columnExtractors, int skipN) static <T extends Comparable<T>,U>
CSVEvolutionListener<T, U> ofTopN(String filename, GenerationFunction<T, U> evolutionContextSupplier, Iterable<? extends ColumnExtractor<T, U>> columnExtractors, int topN) static <T extends Comparable<T>,U>
CSVEvolutionListener<T, U> ofTopN(String filename, GenerationFunction<T, U> evolutionContextSupplier, Iterable<? extends ColumnExtractor<T, U>> columnExtractors, Comparator<T> comparator, int topN) voidonEvolution(long generation, List<Genotype> population, List<T> fitness, boolean isDone) Called after each generation to notify about evolution progress.protected org.apache.commons.csv.CSVPrinterintskipN()How many generations to skip between each writes.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.bmahe.genetics4j.core.evolutionlisteners.EvolutionListener
postEvaluation, preEvaluation
-
Field Details
-
logger
public static final org.apache.logging.log4j.Logger logger -
DEFAULT_AUTO_FLUSH
public static final boolean DEFAULT_AUTO_FLUSH- See Also:
-
csvPrinter
private org.apache.commons.csv.CSVPrinter csvPrinter
-
-
Constructor Details
-
CSVEvolutionListener
public CSVEvolutionListener()
-
-
Method Details
-
openPrinter
protected org.apache.commons.csv.CSVPrinter openPrinter() -
autoFlush
@Default public boolean autoFlush()- Returns:
-
evolutionContextSupplier
User defined function to provide some additional information when computing the value to write. Defaults to null- Returns:
-
skipN
@Default public int skipN()How many generations to skip between each writes. Defaults to writing every generations- Returns:
-
filter
Users can supply an optional set of filters to control which individuals get written and in which order. Default to have no impact.- Returns:
-
filename
Destination file name for the CSV file- Returns:
-
columnExtractors
List of Column Extractors. They specify how and what to write from each individual at a given generation- Returns:
-
onEvolution
public void onEvolution(long generation, List<Genotype> population, List<T> fitness, boolean isDone) Description copied from interface:EvolutionListenerCalled after each generation to notify about evolution progress.This method is invoked by the evolutionary algorithm after each generation has been completed, providing access to the current population state and fitness values. The implementation can use this information for monitoring, logging, or adaptive control.
The method is called with:
- Current generation number (starting from 0)
- Complete population of genotypes for this generation
- Corresponding fitness values for each individual
- Flag indicating whether evolution has completed
Important notes:
- Population and fitness lists are guaranteed to have the same size
- Fitness values correspond to genotypes at the same index
- Data may be shared with the evolution algorithm; avoid modification
- Method should execute quickly to avoid impacting evolution performance
- Specified by:
onEvolutionin interfaceEvolutionListener<T extends Comparable<T>>- Parameters:
generation- the current generation number (0-based)population- the list of genotypes in the current generationfitness- the list of fitness values corresponding to each genotypeisDone-trueif the evolution has completed,falseotherwise
-
of
public static <T extends Comparable<T>,U> CSVEvolutionListener<T,U> of(String filename, List<ColumnExtractor<T, U>> columnExtractors) -
of
public static <T extends Comparable<T>,U> CSVEvolutionListener<T,U> of(String filename, Iterable<? extends ColumnExtractor<T, U>> columnExtractors) -
of
public static <T extends Comparable<T>,U> CSVEvolutionListener<T,U> of(String filename, GenerationFunction<T, U> evolutionContextSupplier, Iterable<? extends ColumnExtractor<T, U>> columnExtractors) -
of
public static <T extends Comparable<T>,U> CSVEvolutionListener<T,U> of(String filename, GenerationFunction<T, U> evolutionContextSupplier, Iterable<? extends ColumnExtractor<T, U>> columnExtractors, int skipN) -
ofTopN
public static <T extends Comparable<T>,U> CSVEvolutionListener<T,U> ofTopN(String filename, GenerationFunction<T, U> evolutionContextSupplier, Iterable<? extends ColumnExtractor<T, U>> columnExtractors, Comparator<T> comparator, int topN) -
ofTopN
public static <T extends Comparable<T>,U> CSVEvolutionListener<T,U> ofTopN(String filename, GenerationFunction<T, U> evolutionContextSupplier, Iterable<? extends ColumnExtractor<T, U>> columnExtractors, int topN)
-