pub struct Ecosystem<C: Chromosome> {
pub population: Population<C>,
pub species: Option<Vec<Species<C>>>,
}Expand description
An ecosystem containing a population and optional species. This structure is the main container for solutions generated throughout the evolutionary process. The optional species field allows for organizing the population into distinct groups, each represented by a mascot phenotype.
When using Species within the ecosystem, it is important to manage the population members appropriately. Species hold shared references to phenotypes in the main population, so any modifications to the population should ensure that these references remain valid.
§Example
use radiate_core::*;
// Create a simple ecosystem
let codec = FloatCodec::vector(10, 0.0_f64..1.0_f64);
let population = (0..100)
.map(|_| Phenotype::from((codec.encode(), 0)))
.collect::<Population<FloatChromosome<f64>>>();
let ecosystem = Ecosystem::new(population);Fields§
§population: Population<C>§species: Option<Vec<Species<C>>>Implementations§
Source§impl<C: Chromosome> Ecosystem<C>
impl<C: Chromosome> Ecosystem<C>
pub fn new(population: Population<C>) -> Self
Like Ecosystem::shared_count, but returns true if there are any shared phenotypes in the population. This should only be true when the ecosystem has Species that hold references to phenotypes in the main population.
pub fn population(&self) -> &Population<C>
pub fn population_mut(&mut self) -> &mut Population<C>
pub fn species(&self) -> Option<&Vec<Species<C>>>
pub fn species_mut(&mut self) -> Option<&mut Vec<Species<C>>>
pub fn get_phenotype(&self, index: usize) -> Option<&Phenotype<C>>
pub fn get_phenotype_mut(&mut self, index: usize) -> Option<&mut Phenotype<C>>
pub fn get_genotype(&self, index: usize) -> Option<&Genotype<C>>
pub fn get_genotype_mut(&mut self, index: usize) -> Option<&mut Genotype<C>>
pub fn get_species(&self, index: usize) -> Option<&Species<C>>
pub fn get_species_mut(&mut self, index: usize) -> Option<&mut Species<C>>
pub fn species_mascots(&self) -> Vec<&Phenotype<C>>
pub fn push_species(&mut self, species: Species<C>)
Sourcepub fn add_species_member(&mut self, species_idx: usize, member_idx: usize)where
C: Clone,
pub fn add_species_member(&mut self, species_idx: usize, member_idx: usize)where
C: Clone,
Add a member to a species given the species index and member index in the population.
The member is reference cloned from the population and added to the species’ population.
Just like with the Ecosystem’s clone_ref method, this creates a shared reference so
any modifications to the phenotype within the Species will be reflected in the main Population.