Struct darwin_rs::population::Population [] [src]

pub struct Population<T: Individual> {
    pub num_of_individuals: u32,
    pub population: Vec<IndividualWrapper<T>>,
    pub reset_limit: u32,
    pub reset_limit_start: u32,
    pub reset_limit_end: u32,
    pub reset_limit_increment: u32,
    pub reset_counter: u32,
    pub id: u32,
    pub fitness_counter: u64,

The Population type. Contains the actual individuals (through a wrapper) and informations like the reset_limit. Use the PopulationBuilder in your main program to create populations.


The number of individuals for this population.

The actual population (vector of individuals).

The amount of iteration to wait until all individuals will be resetted. This calls the reset method for each individual.

The start value of the reset limit.

The end value of the reset limit, if reset_limit >= reset_limit_end, then the reset_limit will be resettet to the start value reset_limit_start. If reset_limit_end == 0, this feature will be disabled.

The increment for the reset_limit. After the reset_limit value is reached, it will be increased by the value of reset_limit_increment.

The reset counter, if reset_counter >= reset_limit, all the individuals are discarded and the simulation restarts anew with an increased reset_limit. This prevents local minima, but also discards the current fittest individual.

The ID of the population, only used for statistics. For example: which population does have the most fittest individuals ? This may help you to set the correct parameters for your simulations.

Count how often this population has created (found) the fittest individual. This may help you to fine tune the parameters for the population and the simulation in general.


impl<T: Individual + Send + Sync + Clone> Population<T>

Just calculates the fitness for each individual. Usually this is the most computational expensive operation, so optimize the calculate_fitness method of your data structure ;-)

This is the body that gets called for every iteration. This function does the following:

  1. Check if the reset limit is reached. If it is, this whole population is discarded and re-initialized from the start. All the information about the current fittest individual is lost. This is done to avoid local minima.

  2. Clone the current population.

  3. Mutate the current population using the mutate_population function.

  4. Merge the newly mutated population and the original cloned population into one big population twice the size.

  5. Sort this new big population by fitness. So the fittest individual is at position 0.

  6. Truncated the big population to its original size and thus gets rid of all the less fittest individuals (they "die").

  7. Check if the fittest individual (at index 0) in the current sorted population is better (= fitter) than the global fittest individual of the whole simulation. If yes, the global fittest individual is replaced.

  8. Calculate the new improvement factor and prepare for the next iteration.

Trait Implementations

impl<T: Clone + Individual> Clone for Population<T>

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more