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_increment | The increment for the |
reset_counter | The reset counter, if |
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:
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.
Clone the current population.
Mutate the current population using the
mutate_population
function.Merge the newly mutated population and the original cloned population into one big population twice the size.
Sort this new big population by fitness. So the fittest individual is at position 0.
Truncated the big population to its original size and thus gets rid of all the less fittest individuals (they "die").
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.
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