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
| Aspect | Reporter | GaObserver |
|---|---|---|
| Storage | Box<dyn Reporter + Send> | Arc<dyn GaObserver + Send + Sync> |
| Mutability | &mut self | &self |
| Hooks | 4 lifecycle | 12 (lifecycle + operator + special) |
| Thread safety | Send only | Send + Sync |
Provided Methods§
Sourcefn on_run_start(&self)
fn on_run_start(&self)
Called once before the first generation.
Sourcefn on_generation_start(&self, _generation: usize)
fn on_generation_start(&self, _generation: usize)
Called at the start of each generation, before any operators run.
Sourcefn on_selection_complete(
&self,
_generation: usize,
_duration: Duration,
_population_size: usize,
)
fn on_selection_complete( &self, _generation: usize, _duration: Duration, _population_size: usize, )
Called after parent selection completes.
Sourcefn on_crossover_complete(
&self,
_generation: usize,
_duration: Duration,
_offspring_count: usize,
)
fn on_crossover_complete( &self, _generation: usize, _duration: Duration, _offspring_count: usize, )
Called after crossover produces offspring.
Sourcefn on_mutation_complete(
&self,
_generation: usize,
_duration: Duration,
_population_size: usize,
)
fn on_mutation_complete( &self, _generation: usize, _duration: Duration, _population_size: usize, )
Called after mutation is applied to offspring.
Sourcefn on_fitness_evaluation_complete(
&self,
_generation: usize,
_duration: Duration,
_population_size: usize,
)
fn on_fitness_evaluation_complete( &self, _generation: usize, _duration: Duration, _population_size: usize, )
Called after fitness evaluation of the new population.
Sourcefn on_survivor_selection_complete(
&self,
_generation: usize,
_duration: Duration,
_population_size: usize,
)
fn on_survivor_selection_complete( &self, _generation: usize, _duration: Duration, _population_size: usize, )
Called after survivor selection prunes the population.
Sourcefn on_new_best(&self, _generation: usize, _best: U)
fn on_new_best(&self, _generation: usize, _best: U)
Called when the population’s best fitness improves.
Sourcefn on_stagnation(&self, _generation: usize, _stagnation_count: usize)
fn on_stagnation(&self, _generation: usize, _stagnation_count: usize)
Called each time the stagnation counter increments.
Sourcefn on_extension_triggered(&self, _event: ExtensionEvent)
fn on_extension_triggered(&self, _event: ExtensionEvent)
Called when an extension strategy fires due to low diversity.
Sourcefn on_generation_end(&self, _stats: &GenerationStats)
fn on_generation_end(&self, _stats: &GenerationStats)
Called at the end of each generation, after statistics are collected.
Sourcefn on_run_end(&self, _cause: TerminationCause, _all_stats: &[GenerationStats])
fn on_run_end(&self, _cause: TerminationCause, _all_stats: &[GenerationStats])
Called once after the GA loop exits.