[][src]Trait rsgenetic::sim::Simulation

pub trait Simulation<'a, T, F> where
    T: Phenotype<F>,
    F: Fitness
{ type B: Builder<Self>; pub fn builder(population: &'a mut Vec<T>) -> Self::B
    where
        Self: Sized
;
pub fn run(&mut self) -> RunResult;
pub fn step(&mut self) -> StepResult;
pub fn checked_step(&mut self) -> StepResult;
pub fn get(&'a self) -> SimResult<'a, T>;
pub fn time(&self) -> Option<NanoSecond>;
pub fn iterations(&self) -> u64;
pub fn population(&self) -> Vec<T>; }

A Simulation is an execution of a genetic algorithm.

Associated Types

type B: Builder<Self>[src]

A Builder is used to create instances of a Simulation.

Loading content...

Required methods

pub fn builder(population: &'a mut Vec<T>) -> Self::B where
    Self: Sized
[src]

Create a Builder to create an instance.

population is a required parameter of any Simulation, which is why it is a parameter of this function.

pub fn run(&mut self) -> RunResult[src]

Run the simulation completely.

pub fn step(&mut self) -> StepResult[src]

👎 Deprecated since 1.7.0:

To encourage checking the StepResult while maintaining backwards compatibility, this function has been deprecated in favour of checked_step.

Make one step in the simulation. This function returns a StepResult:

  • StepResult::Success when a step was successful, but the simulation is not done.
  • StepResult::Failure when an error occurred. Check the result of get().
  • StepResult::Done on convergence or reaching the maximum iterations.

Be careful to check for failures when running step() in a loop, to avoid infinite loops. To run the simulation until convergence or until reaching a maximum number of iterations, consider using run() instead:

pub fn checked_step(&mut self) -> StepResult[src]

Make one step in the simulation. This function returns a StepResult:

  • StepResult::Success when a step was successful, but the simulation is not done.
  • StepResult::Failure when an error occurred. Check the result of get().
  • StepResult::Done on convergence or reaching the maximum iterations.

Unlike step, this function will panic if it is called after a failure. To avoid this panic, match StepResult for StepResult::Failure and exit gracefully.

pub fn get(&'a self) -> SimResult<'a, T>[src]

Get the result of the latest step or of a complete run.

This function will either return the best performing individual, or an error string indicating what went wrong.

pub fn time(&self) -> Option<NanoSecond>[src]

Get the number of nanoseconds spent running, or None in case of an overflow.

When Self is par::Simulator, i.e. a parallel simulator is used, the duration is the average duration of all child simulators.

pub fn iterations(&self) -> u64[src]

Get the number of iterations the Simulator has executed so far.

When Self is par::Simulator, i.e. a parallel simulator is used, this returns the number of iterations made by the parallel simulator itself.

pub fn population(&self) -> Vec<T>[src]

Get the current population.

Using this function clones the population out of the Simulation, so use it sparingly.

Loading content...

Implementors

impl<'a, T, F> Simulation<'a, T, F> for Simulator<'a, T, F> where
    T: Phenotype<F>,
    F: Fitness
[src]

type B = SimulatorBuilder<'a, T, F>

pub fn builder(population: &'a mut Vec<T>) -> SimulatorBuilder<'a, T, F>[src]

Create builder.

Loading content...