Skip to main content

PopulationBuilder

Struct PopulationBuilder 

Source
pub struct PopulationBuilder<G, S, C, F, R> { /* private fields */ }
Expand description

Builder for a Population

Implementations§

Source§

impl<G, S, C, F, R> PopulationBuilder<G, S, C, F, R>
where G: Gene, S: Selection<G>, C: Crossover<G>, F: FnMut(&Chromosome<G>, &[Chromosome<G>]) -> f64, R: Rng + Default,

Source

pub fn new(population: Option<Vec<Chromosome<G>>>, eval_fn: F) -> Self

Creates a new PopulationBuilder

§Arguments
  • population - The population to use
  • eval_fn - The evaluation function
§Returns

A new PopulationBuilder

Source

pub fn with_chromo_size(self, chromo_size: usize) -> Self

Sets the chromosome size, how many genes

§Arguments
  • chromo_size - The chromosome size
Source

pub fn with_population_size(self, pop_size: usize) -> Self

Sets the population size

§Arguments
  • pop_size - The population size
Source

pub fn with_mutation_rate(self, mutation_rate: f64) -> Self

Sets the mutation rate

§Arguments
  • mutation_rate - The mutation rate
Source

pub fn with_elitism(self, elitism: bool) -> Self

Sets the elitism flag

§Arguments
  • elitism - Whether or not to use elitism (keep the best chromosome)
Source

pub fn with_print(self, print: bool) -> Self

Sets the print flag

§Arguments
  • print - The print flag
Source

pub fn with_rng(self, rng: R) -> Self

Sets the random number generator

§Arguments
  • rng - The random number generator to use
Source

pub fn with_selection(self, selection: S) -> Self

Sets the selection method

§Arguments
  • selection - The selection method
Source

pub fn with_crossover(self, crossover: C) -> Self

Sets the crossover method

§Arguments
  • crossover - The crossover method
Source

pub fn build(self) -> Result<Population<G, S, C, F, R>>

Builds the Population

§Errors

Trait Implementations§

Source§

impl<G: Debug, S: Debug, C: Debug, F: Debug, R: Debug> Debug for PopulationBuilder<G, S, C, F, R>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<G, S, C, F, R> Freeze for PopulationBuilder<G, S, C, F, R>
where F: Freeze, S: Freeze, C: Freeze, R: Freeze,

§

impl<G, S, C, F, R> RefUnwindSafe for PopulationBuilder<G, S, C, F, R>

§

impl<G, S, C, F, R> Send for PopulationBuilder<G, S, C, F, R>
where F: Send, S: Send, C: Send, R: Send, G: Send,

§

impl<G, S, C, F, R> Sync for PopulationBuilder<G, S, C, F, R>
where F: Sync, S: Sync, C: Sync, R: Sync, G: Sync,

§

impl<G, S, C, F, R> Unpin for PopulationBuilder<G, S, C, F, R>
where F: Unpin, S: Unpin, C: Unpin, R: Unpin, G: Unpin,

§

impl<G, S, C, F, R> UnsafeUnpin for PopulationBuilder<G, S, C, F, R>

§

impl<G, S, C, F, R> UnwindSafe for PopulationBuilder<G, S, C, F, R>

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