pub trait Crossover<C: Chromosome>: Send + Sync {
// Provided methods
fn name(&self) -> String { ... }
fn update(&self, _: usize) { ... }
fn rate(&self) -> f32 { ... }
fn alterer(self) -> AlterAction<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, upon which genetic algorithms are based.
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. This is the case with the UniformCrossover
struct.