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.
impl<T: Individual + Clone> PopulationBuilder<T>
This implementation contains all the helper method to build (configure) a valid population.
Sourcepub fn new() -> PopulationBuilder<T>
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.
Sourcepub fn initial_population(self, individuals: &[T]) -> PopulationBuilder<T>
pub fn initial_population(self, individuals: &[T]) -> PopulationBuilder<T>
Sets the initial population provided inside a vector, length must be >= 3
Sourcepub fn increasing_mutation_rate(self) -> PopulationBuilder<T>
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.
Sourcepub fn increasing_exp_mutation_rate(self, base: f64) -> PopulationBuilder<T>
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.
Sourcepub fn mutation_rate(self, mutation_rate: Vec<u32>) -> PopulationBuilder<T>
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.
Sourcepub fn reset_limit_start(self, reset_limit_start: u32) -> PopulationBuilder<T>
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.
Sourcepub fn reset_limit_end(self, reset_limit_end: u32) -> PopulationBuilder<T>
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.
Sourcepub fn reset_limit_increment(
self,
reset_limit_increment: u32,
) -> PopulationBuilder<T>
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.
Sourcepub fn set_id(self, id: u32) -> PopulationBuilder<T>
pub fn set_id(self, id: u32) -> PopulationBuilder<T>
Set the population id. Currently this is only used for statistics.
Sourcepub fn finalize(self) -> Result<Population<T>>
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.