Struct Population

Source
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,
}
Expand description

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: u32

The number of individuals for this population.

§population: Vec<IndividualWrapper<T>>

The actual population (vector of individuals).

§reset_limit: u32

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

§reset_limit_start: u32

The start value of the reset limit.

§reset_limit_end: u32

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: u32

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: u32

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: u32

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.

§fitness_counter: u64

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.

Implementations§

Source§

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

Source

pub fn calculate_fitness(&mut self)

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 ;-)

Source

pub fn run_body(&mut self)

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§

Source§

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

Source§

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

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Population<T>

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for Population<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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.