[][src]Trait oxigen::genotype::Genotype

pub trait Genotype<T: PartialEq>: Display + Clone + Send + Sync {
    type ProblemSize: Default + Send + Sync;
    pub fn iter(&self) -> Iter<'_, T>;
pub fn into_iter(self) -> IntoIter<T>;
pub fn from_iter<I: Iterator<Item = T>>(&mut self, _: I);
pub fn generate(size: &Self::ProblemSize) -> Self;
pub fn fitness(&self) -> f64;
pub fn mutate(&mut self, rgen: &mut SmallRng, index: usize);
pub fn is_solution(&self, fitness: f64) -> bool; pub fn fix(&mut self) -> bool { ... }
pub fn distance(&self, other: &Self) -> f64 { ... } }

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.

Associated Types

type ProblemSize: Default + Send + Sync[src]

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).

Loading content...

Required methods

pub fn iter(&self) -> Iter<'_, T>[src]

Returns an iterator over the genes of the individual.

pub fn into_iter(self) -> IntoIter<T>[src]

Consumes the individual into an iterator over its genes.

pub fn from_iter<I: Iterator<Item = T>>(&mut self, _: I)[src]

Set the genes of the individual from an iterator.

pub fn generate(size: &Self::ProblemSize) -> Self[src]

Randomly initializes an individual.

pub fn fitness(&self) -> f64[src]

Returns a fitness value for an individual.

pub fn mutate(&mut self, rgen: &mut SmallRng, index: usize)[src]

Defines the manner in which an individual is mutated when an element of the individual is selected to mutate.

pub fn is_solution(&self, fitness: f64) -> bool[src]

Defines if an individual is a valid solution to the problem.

Loading content...

Provided methods

pub fn fix(&mut self) -> bool[src]

Fix the individual to satisfy the problem restrictions. The default implementation is to remain the individual unmodified always.

Returns

true if the individual has changed and false otherwise. If this function returns true the fitness is recomputed.

pub fn distance(&self, other: &Self) -> f64[src]

A function to define how different is the individual from another one. The default implementation sums the number of different genes and divides it by the total number of genes. If one individual is shorter than another, to this value the difference in length is added, and the sum is divided by the length of the longer individual. This function is used to determine if solutions are different and in some survival pressure functions.

Loading content...

Implementors

Loading content...