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,
}

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.

Fields

num_of_individuals

The number of individuals for this population.

population

The actual population (vector of individuals).

reset_limit

The amount of iteration to wait until all individuals will be resetted.

reset_limit_start

The start value of the reset limit

reset_limit_end

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.

reset_limit_increment

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

reset_counter

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.

id

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.

Methods

impl<T: Individual + Send + Sync + Clone> Population<T>
[src]

fn calculate_fitness(&mut self)

Just calculates the fitness for each individual.

fn run_body(&mut self, simulation_result: &Mutex<SimulationResult<T>>, iteration_counter: u32)

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

Derived Implementations

impl<T: Clone + Individual> Clone for Population<T>
[src]

fn clone(&self) -> Population<T>

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)
1.0.0

Performs copy-assignment from source. Read more