Skip to main content

GaObserver

Trait GaObserver 

Source
pub trait GaObserver<U: ChromosomeT>: Send + Sync {
    // Provided methods
    fn on_run_start(&self) { ... }
    fn on_generation_start(&self, _generation: usize) { ... }
    fn on_selection_complete(
        &self,
        _generation: usize,
        _duration: Duration,
        _population_size: usize,
    ) { ... }
    fn on_crossover_complete(
        &self,
        _generation: usize,
        _duration: Duration,
        _offspring_count: usize,
    ) { ... }
    fn on_mutation_complete(
        &self,
        _generation: usize,
        _duration: Duration,
        _population_size: usize,
    ) { ... }
    fn on_fitness_evaluation_complete(
        &self,
        _generation: usize,
        _duration: Duration,
        _population_size: usize,
    ) { ... }
    fn on_survivor_selection_complete(
        &self,
        _generation: usize,
        _duration: Duration,
        _population_size: usize,
    ) { ... }
    fn on_new_best(&self, _generation: usize, _best: U) { ... }
    fn on_stagnation(&self, _generation: usize, _stagnation_count: usize) { ... }
    fn on_extension_triggered(&self, _event: ExtensionEvent) { ... }
    fn on_generation_end(&self, _stats: &GenerationStats) { ... }
    fn on_run_end(
        &self,
        _cause: TerminationCause,
        _all_stats: &[GenerationStats],
    ) { ... }
}
Expand description

Structured lifecycle observer for Ga<U>.

All methods have default no-op implementations — implement only the hooks you need. The Send + Sync supertraits are required for safe sharing across rayon threads (island model) via Arc.

§Differences from Reporter

AspectReporterGaObserver
StorageBox<dyn Reporter + Send>Arc<dyn GaObserver + Send + Sync>
Mutability&mut self&self
Hooks4 lifecycle12 (lifecycle + operator + special)
Thread safetySend onlySend + Sync

Provided Methods§

Source

fn on_run_start(&self)

Called once before the first generation.

Source

fn on_generation_start(&self, _generation: usize)

Called at the start of each generation, before any operators run.

Source

fn on_selection_complete( &self, _generation: usize, _duration: Duration, _population_size: usize, )

Called after parent selection completes.

Source

fn on_crossover_complete( &self, _generation: usize, _duration: Duration, _offspring_count: usize, )

Called after crossover produces offspring.

Source

fn on_mutation_complete( &self, _generation: usize, _duration: Duration, _population_size: usize, )

Called after mutation is applied to offspring.

Source

fn on_fitness_evaluation_complete( &self, _generation: usize, _duration: Duration, _population_size: usize, )

Called after fitness evaluation of the new population.

Source

fn on_survivor_selection_complete( &self, _generation: usize, _duration: Duration, _population_size: usize, )

Called after survivor selection prunes the population.

Source

fn on_new_best(&self, _generation: usize, _best: U)

Called when the population’s best fitness improves.

Source

fn on_stagnation(&self, _generation: usize, _stagnation_count: usize)

Called each time the stagnation counter increments.

Source

fn on_extension_triggered(&self, _event: ExtensionEvent)

Called when an extension strategy fires due to low diversity.

Source

fn on_generation_end(&self, _stats: &GenerationStats)

Called at the end of each generation, after statistics are collected.

Source

fn on_run_end(&self, _cause: TerminationCause, _all_stats: &[GenerationStats])

Called once after the GA loop exits.

Implementors§