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

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

A Simulation is an execution of a genetic algorithm.

Associated Types

type B: Builder<Self>

A Builder is used to create instances of a Simulation.

Required Methods

fn builder() -> Self::B where Self: Sized

Create a Builder to create an instance.

fn run(&mut self) -> RunResult

Run the simulation completely.

fn step(&mut self) -> StepResult

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: This function is mostly useful for making illustrations of the evolution.

fn get(&self) -> SimResult<T>

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.

fn time(&self) -> Option<NanoSecond>

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.

fn iterations(&self) -> u64

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.

Implementors