Trait rsgenetic::sim::Simulation
[−]
[src]
pub trait Simulation<'a, T: Phenotype> { 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 get(&'a self) -> SimResult<'a, T>; fn time(&self) -> Option<NanoSecond>; fn iterations(&self) -> u64; }
A Simulation
is an execution of a genetic algorithm.
Associated Types
Required Methods
fn builder(population: &'a mut Vec<T>) -> Self::B where Self: Sized
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.
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 ofget()
.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(&'a self) -> SimResult<'a, 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.