Struct SimulationBuilder

Source
pub struct SimulationBuilder<T: Individual + Send + Sync> { /* private fields */ }
Expand description

This is a helper struct in order to build (configure) a valid simulation. See builder pattern: https://en.wikipedia.org/wiki/Builder_pattern

Maybe use phantom types, see https://github.com/willi-kappler/darwin-rs/issues/9

Implementations§

Source§

impl<T: Individual + Send + Sync> SimulationBuilder<T>

This implementation contains all the helper method to build (configure) a valid simulation.

Source

pub fn new() -> SimulationBuilder<T>

Start with this method, it must always be called as the first one. It creates a default simulation with some dummy (but invalid) values.

Source

pub fn iterations(self, iterations: u32) -> SimulationBuilder<T>

Set the total number of iterations for the simulation and thus sets the simulation type to EndIteration. (Only usefull in combination with EndIteration).

Source

pub fn factor(self, factor: f64) -> SimulationBuilder<T>

Set the improvement factor stop criteria for the simulation and thus sets the simulation type to EndFactor. (Only usefull in combination with EndFactor).

Source

pub fn fitness(self, fitness: f64) -> SimulationBuilder<T>

Set the minimum fitness stop criteria for the simulation and thus sets the simulation type to EndFitness. (Only usefull in combination with EndFactor).

Source

pub fn threads(self, threads: usize) -> SimulationBuilder<T>

Sets the number of threads in order to speed up the simulation.

Source

pub fn add_population(self, population: Population<T>) -> SimulationBuilder<T>

Add a population to the simulation.

Source

pub fn add_multiple_populations( self, multiple_populations: Vec<Population<T>>, ) -> SimulationBuilder<T>

Add multiple populations to the simulation.

Source

pub fn share_fittest(self) -> SimulationBuilder<T>

If this option is enabled (default: off), then the fittest individual of all populations is shared between all populations.

Source

pub fn num_of_global_fittest( self, num_of_global_fittest: usize, ) -> SimulationBuilder<T>

How many global fittest should be kept ? (The size of the “high score list”)

Source

pub fn output_every(self, output_every: u32) -> SimulationBuilder<T>

Do not output every time a new individual is found, only every nth time. n == output_every

Source

pub fn share_every(self, share_every: u32) -> SimulationBuilder<T>

If share fittest is enabled and the number share_every of iteration has passed then the fittest individual is shared between all populations

Source

pub fn finalize(self) -> Result<Simulation<T>>

This checks the configuration of the simulation and returns an error or Ok if no errors where found.

Auto Trait Implementations§

§

impl<T> Freeze for SimulationBuilder<T>

§

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

§

impl<T> Send for SimulationBuilder<T>

§

impl<T> Sync for SimulationBuilder<T>

§

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

§

impl<T> UnwindSafe for SimulationBuilder<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> 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.