Skip to main content

Phenotype

Struct Phenotype 

Source
pub struct Phenotype<C>
where C: Chromosome,
{ /* private fields */ }
Expand description

A Phenotype is a representation of an individual in the population. It contains:

  • Genotype - the genetic representation of the individual
  • Score - the score (fitness) of the individual as calculated by the fitness function
  • Generation - the generation in which the individual was created
  • id - a unique identifier for the Phenotype

The Phenotype is a wrapper around the Genotype that adds additional information about the individual. In traditional (biological) genetics, a phenotype is “the set of observable characteristics of an individual resulting from the interaction of its genotype with the environment”. As such, the Phenotype is the ‘observable’ part of the individual (Genotype) that is being evolved by the genetic algorithm, hence the Score and generation fields. This allows the Phenotype to be sorted and compared based on the fitness (Score) of the individual (Genotype)

§Type Parameters

  • C: The type of chromosome used in the genotype, which must implement the Chromosome trait.

Implementations§

Source§

impl<C> Phenotype<C>
where C: Chromosome,

Source

pub fn genotype(&self) -> &Genotype<C>

Source

pub fn genotype_mut(&mut self) -> &mut Genotype<C>

Source

pub fn take_genotype(&mut self) -> Result<Genotype<C>, RadiateError>

Source

pub fn set_genotype(&mut self, genotype: Genotype<C>)

Source

pub fn set_score(&mut self, score: Option<Score>)

Source

pub fn generation(&self) -> usize

Source

pub fn score(&self) -> Option<&Score>

Source

pub fn id(&self) -> PhenotypeId

Source

pub fn family(&self) -> FamilyId

Source

pub fn invalidate(&mut self, generation: usize)

Source

pub fn age(&self, generation: usize) -> usize

Get the age of the individual in generations. The age is calculated as the difference between the given generation and the generation in which the individual was created.

Trait Implementations§

Source§

impl<C> AsRef<[f32]> for Phenotype<C>
where C: Chromosome,

Implement the AsRef<[f32]> trait for the Phenotype. This allows the Phenotype to be converted to a slice of f32 which will be the Score of the Phenotype. This is used when adding a Phenotype to a pareto Front for sorting.

Source§

fn as_ref(&self) -> &[f32]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<C> Clone for Phenotype<C>
where C: Clone + Chromosome,

Source§

fn clone(&self) -> Phenotype<C>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<C> Debug for Phenotype<C>
where C: Debug + Chromosome,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<C> Distance<Phenotype<C>> for DistanceDiversityAdapter<C>
where C: Chromosome,

Source§

fn distance(&self, one: &Phenotype<C>, two: &Phenotype<C>) -> f32

Source§

impl<C> From<(Genotype<C>, usize)> for Phenotype<C>
where C: Chromosome,

Source§

fn from(_: (Genotype<C>, usize)) -> Phenotype<C>

Converts to this type from the input type.
Source§

impl<C> From<(Vec<C>, usize)> for Phenotype<C>
where C: Chromosome,

This is a convenience method that allows you to create a Phenotype from a list of Chromosomes. Without it, we end up needing to create a list of Gene’s then a list of Chromosomes then a Genotype, it’s just a lot. This method allows you to create a Phenotype from a list of chromosomes directly.

Source§

fn from(_: (Vec<C>, usize)) -> Phenotype<C>

Converts to this type from the input type.
Source§

impl<C> From<Genotype<C>> for Phenotype<C>
where C: Chromosome,

Source§

fn from(genotype: Genotype<C>) -> Phenotype<C>

Converts to this type from the input type.
Source§

impl<C> From<Phenotype<C>> for Member<C>
where C: Chromosome,

Source§

fn from(p: Phenotype<C>) -> Member<C>

Converts to this type from the input type.
Source§

impl<C> FromIterator<Phenotype<C>> for Population<C>
where C: Chromosome,

Source§

fn from_iter<I>(iter: I) -> Population<C>
where I: IntoIterator<Item = Phenotype<C>>,

Creates a value from an iterator. Read more
Source§

impl<C> Hash for Phenotype<C>
where C: Chromosome,

Source§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<C> PartialEq for Phenotype<C>
where C: PartialEq + Chromosome,

Source§

fn eq(&self, other: &Phenotype<C>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<C> PartialOrd for Phenotype<C>
where C: Chromosome + PartialEq,

Implement the PartialOrd trait for the Phenotype. This allows the Phenotype to be compared with other Phenotype instances. The comparison is based on the Score (fitness) of the Phenotype.

Source§

fn partial_cmp(&self, other: &Phenotype<C>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<C> Scored for Phenotype<C>
where C: Chromosome,

Source§

fn score(&self) -> Option<&Score>

Source§

impl<C> Valid for Phenotype<C>
where C: Chromosome,

Implement the Valid trait for the Phenotype. This allows the Phenotype to be checked for validity. A Phenotype is valid if the Genotype is valid. The GeneticEngine checks the validity of the Phenotype and will remove any invalid individuals from the population, replacing them with new individuals at the given generation.

Source§

fn is_valid(&self) -> bool

Source§

impl<C> Eq for Phenotype<C>
where C: Chromosome + PartialEq,

Source§

impl<C> StructuralPartialEq for Phenotype<C>
where C: Chromosome,

Auto Trait Implementations§

§

impl<C> Freeze for Phenotype<C>

§

impl<C> RefUnwindSafe for Phenotype<C>
where C: RefUnwindSafe,

§

impl<C> Send for Phenotype<C>

§

impl<C> Sync for Phenotype<C>

§

impl<C> Unpin for Phenotype<C>
where C: Unpin,

§

impl<C> UnsafeUnpin for Phenotype<C>

§

impl<C> UnwindSafe for Phenotype<C>
where C: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more