pub trait Genotype<T>: FromIterator<T> + Display + Clone + Send + Sync {
type ProblemSize: Default + Send + Sync;
fn iter(&self) -> Iter<'_, T>;
fn into_iter(self) -> IntoIter<T>;
fn generate(size: &Self::ProblemSize) -> Self;
fn fitness(&self) -> f64;
fn mutate(&mut self, rgen: &mut SmallRng, index: usize);
fn is_solution(&self, fitness: f64) -> bool;
fn fix(&mut self) { ... }
}
Expand description
This trait defines an individual of a population in the genetic algorithm. It defines the fitness and mutation functions and the type of the individual representation.
Required Associated Types§
sourcetype ProblemSize: Default + Send + Sync
type ProblemSize: Default + Send + Sync
The type that represents the problem size of the genotype. For example,
in the N Queens problem the size of the ProblemSize
is a numeric type
(the number of queens).
Required Methods§
sourcefn generate(size: &Self::ProblemSize) -> Self
fn generate(size: &Self::ProblemSize) -> Self
Randomly initiailzes an individual.
sourcefn mutate(&mut self, rgen: &mut SmallRng, index: usize)
fn mutate(&mut self, rgen: &mut SmallRng, index: usize)
Defines the manner in which an individual is mutated when an elemennt of the individual is selected to mutate.
sourcefn is_solution(&self, fitness: f64) -> bool
fn is_solution(&self, fitness: f64) -> bool
Defines if an individual is a valid solution to the problem.