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

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

A Simulation is an execution of a genetic algorithm.

Associated Types

A Builder is used to create instances of a Simulation.

Required Methods

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.

Run the simulation completely.

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:

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.

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.

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.

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.

Get the current population.

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

Implementors