genetic_algorithm::chromosome

Trait Chromosome

source
pub trait Chromosome: Clone + Send {
    // Required methods
    fn age(&self) -> usize;
    fn reset_age(&mut self);
    fn increment_age(&mut self);
    fn fitness_score(&self) -> Option<FitnessValue>;
    fn set_fitness_score(&mut self, fitness_score: Option<FitnessValue>);
    fn taint(&mut self);
    fn copy_fields_from(&mut self, other: &Self);

    // Provided method
    fn clone_and_taint(&self) -> Self { ... }
}
Expand description

The Chromosome is used as an individual in the Population. Chromosomes select, crossover and mutate with each other in the Evolve strategy. Each Genotype has its own associated Chromosome type.

Chromosomes who implement GenesOwner own their genes. Chromosomes who implement GenesPointer don’t and just point to genes owned by the Genotype. Therefore the chromosome itself doesn’t have a global interface regarding it’s genes and use of Evolve::best_chromosome(), HillCllimb::best_chromosome() and Permutate::best_chromosome() on the Strategy are discouraged (although they are available when using a Genotype with a GenesOwner chromosome). Use Strategy::best_genes() or Strategy::best_genes_and_fitness_score() instead.

In the Fitness context an associated Genotype type is set. And in that contest the ownership model of the genes is known, so we can use the Chromosome struct without ambiguity.

Required Methods§

source

fn age(&self) -> usize

source

fn reset_age(&mut self)

source

fn increment_age(&mut self)

source

fn fitness_score(&self) -> Option<FitnessValue>

source

fn set_fitness_score(&mut self, fitness_score: Option<FitnessValue>)

source

fn taint(&mut self)

source

fn copy_fields_from(&mut self, other: &Self)

Provided Methods§

source

fn clone_and_taint(&self) -> Self

Object Safety§

This trait is not object safe.

Implementors§