pub trait Crossover<C: Chromosome>: Send + Sync {
// Provided methods
fn name(&self) -> String { ... }
fn rate(&self) -> Rate { ... }
fn alterer(self) -> Alterer<C>
where Self: Sized + 'static { ... }
fn crossover(
&self,
population: &mut Population<C>,
generation: usize,
rate: f32,
) -> AlterResult { ... }
fn cross(
&self,
population: &mut Population<C>,
parent_indexes: &[usize],
generation: usize,
rate: f32,
) -> AlterResult { ... }
fn cross_chromosomes(
&self,
chrom_one: &mut C,
chrom_two: &mut C,
rate: f32,
) -> AlterResult { ... }
}Expand description
The Crossover trait is used to define the crossover operation for a genetic algorithm.
In a genetic algorithm, crossover is a genetic operator used to vary the programming of a chromosome or chromosomes from one generation to the next. It is analogous to reproduction and biological crossover.
A Crossover typically takes two parent Chromosomes and produces two or more offspring Chromosomes. This trait allows you to define your own crossover operation on either the entire population or a subset of the population. If a struct implements the Crossover trait but does not override any of the methods, the default implementation will perform a simple crossover operation on the entire population.