Struct PopulationBuilder

Source
pub struct PopulationBuilder<T: Individual> { /* private fields */ }
Expand description

This is a helper struct in order to build (configure) a valid population. See builder pattern: https://en.wikipedia.org/wiki/Builder_pattern

Maybe use phantom types, see https://github.com/willi-kappler/darwin-rs/issues/9

Implementations§

Source§

impl<T: Individual + Clone> PopulationBuilder<T>

This implementation contains all the helper method to build (configure) a valid population.

Source

pub fn new() -> PopulationBuilder<T>

Start with this method, it must always be called as the first one. It creates a default population with some dummy (but invalid) values.

Source

pub fn initial_population(self, individuals: &[T]) -> PopulationBuilder<T>

Sets the initial population provided inside a vector, length must be >= 3

Source

pub fn increasing_mutation_rate(self) -> PopulationBuilder<T>

Configures the mutation rates (number of mutation runs) for all the individuals in the population: The first individual will mutate once, the second will mutate twice, the nth individual will Mutate n-times per iteration.

Source

pub fn increasing_exp_mutation_rate(self, base: f64) -> PopulationBuilder<T>

Configures the mutation rates (number of mutation runs) for all the individuals in the population: Instead of a linear growing mutation rate like in the increasing_mutation_rate function above this sets an exponention mutation rate for all the individuals. The first individual will mutate base^1 times, the second will mutate base^2 times, and nth will mutate base^n times per iteration.

Source

pub fn mutation_rate(self, mutation_rate: Vec<u32>) -> PopulationBuilder<T>

Configures the mutation rates (number of mutation runs) for all the individuals in the population: This allows to specify an arbitrary mutation scheme for each individual. The number of rates must be equal to the number of individuals.

Source

pub fn reset_limit_start(self, reset_limit_start: u32) -> PopulationBuilder<T>

Configures the reset limit for the population. If reset_limit_end is greater than zero then a reset counter is increased each iteration. If that counter is greater than the limit, all individuals will be resetted, the limit will be increased by 1000 and the counter is set back to zero. Default value for reset_limit_start is 1000.

Source

pub fn reset_limit_end(self, reset_limit_end: u32) -> PopulationBuilder<T>

Configures the end value for the reset_limit. If the reset_limit >= reset_limit_end then the reset_limit will be resetted to the start value reset_limit_start. Default value for reset_limit_end is 100000. If reset_limit_end == 0 then the reset limit feature will be disabled.

Source

pub fn reset_limit_increment( self, reset_limit_increment: u32, ) -> PopulationBuilder<T>

Configure the increment for the reset_limit. If the reset_limit is reached, its value is incrementet by the amount of reset_limit_increment.

Source

pub fn set_id(self, id: u32) -> PopulationBuilder<T>

Set the population id. Currently this is only used for statistics.

Source

pub fn finalize(self) -> Result<Population<T>>

This checks the configuration of the simulation and returns an PopError or Ok if no PopErrors where found.

Auto Trait Implementations§

§

impl<T> Freeze for PopulationBuilder<T>

§

impl<T> RefUnwindSafe for PopulationBuilder<T>
where T: RefUnwindSafe,

§

impl<T> Send for PopulationBuilder<T>
where T: Send,

§

impl<T> Sync for PopulationBuilder<T>
where T: Sync,

§

impl<T> Unpin for PopulationBuilder<T>
where T: Unpin,

§

impl<T> UnwindSafe for PopulationBuilder<T>
where T: 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> 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, 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.