Skip to main content

Ecosystem

Struct Ecosystem 

Source
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>

Source

pub fn new(population: Population<C>) -> Self

Source

pub fn shared_count(&self) -> usize

Get the number of shared phenotypes in the population. A shared phenotype is one that is reference cloned and held by another structure, such as a Species. The only time the shared count should ever be > 0 is when the ecosystem has Species that hold references to phenotypes in the main population.

Source

pub fn is_shared(&self) -> bool

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.

Source

pub fn population(&self) -> &Population<C>

Source

pub fn population_mut(&mut self) -> &mut Population<C>

Source

pub fn species(&self) -> Option<&Vec<Species<C>>>

Source

pub fn species_mut(&mut self) -> Option<&mut Vec<Species<C>>>

Source

pub fn get_phenotype(&self, index: usize) -> Option<&Phenotype<C>>

Source

pub fn get_phenotype_mut(&mut self, index: usize) -> Option<&mut Phenotype<C>>

Source

pub fn get_genotype(&self, index: usize) -> Option<&Genotype<C>>

Source

pub fn get_genotype_mut(&mut self, index: usize) -> Option<&mut Genotype<C>>

Source

pub fn get_species(&self, index: usize) -> Option<&Species<C>>

Source

pub fn get_species_mut(&mut self, index: usize) -> Option<&mut Species<C>>

Source

pub fn species_mascots(&self) -> Vec<&Phenotype<C>>

Source

pub fn push_species(&mut self, species: Species<C>)

Source

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.

Source

pub fn remove_dead_species(&mut self) -> usize

Trait Implementations§

Source§

impl<C: Chromosome + Clone> Clone for Ecosystem<C>

Source§

fn clone(&self) -> Self

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 + Chromosome> Debug for Ecosystem<C>

Source§

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

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

impl<C: Default + Chromosome> Default for Ecosystem<C>

Source§

fn default() -> Ecosystem<C>

Returns the “default value” for a type. Read more
Source§

impl<C: Chromosome> From<Population<C>> for Ecosystem<C>

Source§

fn from(population: Population<C>) -> Self

Converts to this type from the input type.
Source§

impl<C: Chromosome> From<Vec<Phenotype<C>>> for Ecosystem<C>

Source§

fn from(phenotypes: Vec<Phenotype<C>>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<C> Freeze for Ecosystem<C>

§

impl<C> !RefUnwindSafe for Ecosystem<C>

§

impl<C> Send for Ecosystem<C>

§

impl<C> Sync for Ecosystem<C>

§

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

§

impl<C> UnsafeUnpin for Ecosystem<C>

§

impl<C> !UnwindSafe for Ecosystem<C>

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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.