pub struct Population<C>where
C: Chromosome,{ /* private fields */ }Expand description
A Population is a collection of Phenotype instances.
This struct is the core collection of individuals
being evolved by the GeneticEngine. It can be thought of as a Vec of Phenotypes and
is essentially a light wrapper around such a Vec. The Population struct, however, has some
additional functionality that allows for sorting and iteration over the individuals in the population.
Note: Although the Population offers mut methods to mut the individuals in the population, the Population
itself offers no way to increase or decrease the number of individuals in the population. As such, the Population
should be thought of as an ‘immutable’ data structure. If you need to add or remove individuals from the population,
you should create a new Population instance with the new individuals. To further facilitate this way of
thinking, the Population struct and everything it contains implements the Clone trait.
§Note
A raw call to clone of the population will NOT clone the individuals themselves, but rather the
references to them. This means that if you mutate an individual in one population, the change
will be reflected in the other population as well. To deep clone a population, you must clone
each individual within it. The simplest way to do this is by:
let deep_cloned_population = Population::from(&original_population);§Type Parameters
C: The type of chromosome used in the genotype, which must implement theChromosometrait.
Implementations§
Source§impl<C> Population<C>where
C: Chromosome,
impl<C> Population<C>where
C: Chromosome,
pub fn new(individuals: Vec<Phenotype<C>>) -> Population<C>
pub fn members(&self) -> &[Member<C>]
pub fn get(&self, index: usize) -> Option<&Phenotype<C>>
pub fn get_mut(&mut self, index: usize) -> Option<&mut Phenotype<C>>
pub fn get_cell_mut(&mut self, index: usize) -> Option<&mut Member<C>>
pub fn get_cell(&self, index: usize) -> Option<&Member<C>>
pub fn push(&mut self, individual: impl Into<Member<C>>)
pub fn iter(&self) -> impl Iterator<Item = &Phenotype<C>>
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut Phenotype<C>>
pub fn len(&self) -> usize
pub fn clear(&mut self)
pub fn is_empty(&self) -> bool
pub fn get_scores(&self) -> Vec<&Score>
pub fn get_pair_mut( &mut self, first: usize, second: usize, ) -> Option<(&mut Phenotype<C>, &mut Phenotype<C>)>
Trait Implementations§
Source§impl<C> AsMut<[Member<C>]> for Population<C>where
C: Chromosome,
impl<C> AsMut<[Member<C>]> for Population<C>where
C: Chromosome,
Source§impl<C> AsRef<[Member<C>]> for Population<C>where
C: Chromosome,
impl<C> AsRef<[Member<C>]> for Population<C>where
C: Chromosome,
Source§impl<C> Clone for Population<C>where
C: Clone + Chromosome,
impl<C> Clone for Population<C>where
C: Clone + Chromosome,
Source§fn clone(&self) -> Population<C>
fn clone(&self) -> Population<C>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<C> Debug for Population<C>where
C: Chromosome + Debug,
impl<C> Debug for Population<C>where
C: Chromosome + Debug,
Source§impl<C> Default for Population<C>where
C: Default + Chromosome,
impl<C> Default for Population<C>where
C: Default + Chromosome,
Source§fn default() -> Population<C>
fn default() -> Population<C>
Source§impl<C> From<&Population<C>> for Population<C>where
C: Chromosome + Clone,
impl<C> From<&Population<C>> for Population<C>where
C: Chromosome + Clone,
Source§fn from(population: &Population<C>) -> Population<C>
fn from(population: &Population<C>) -> Population<C>
Source§impl<C, F> From<(usize, F)> for Population<C>
Create a new instance of the Population from the given size and closure.
This will iterate the given closure size times and collect
the results into a Vec of new individuals.
impl<C, F> From<(usize, F)> for Population<C>
Create a new instance of the Population from the given size and closure.
This will iterate the given closure size times and collect
the results into a Vec of new individuals.