pub struct Evolution<T: Individual> {
pub metrics: Metrics,
/* private fields */
}Expand description
This is the struct that does the evolution magic. It has the methods needed to start and iterate through the evolution.
§Example:
// You can start the evolution with the `start` method:
evolution.start();
// and iterate through the evolution with the `next` method:
evolution.next();
// or you can run it until the stop condition is met with the `run` method:
evolution.run();Fields§
§metrics: MetricsImplementations§
Source§impl<T: Individual> Evolution<T>
impl<T: Individual> Evolution<T>
pub fn new( title: String, config: EvolutionConfig<T>, fitness: Box<dyn Fitness<T>>, selection: Box<dyn Selection<T>>, crossover: Box<dyn Crossover<T>>, mutation: Box<dyn Mutation<T>>, elitism: u32, stop_condition: Arc<dyn Fn(f64, u32, u32) -> bool + Send + Sync>, ) -> Self
Sourcepub fn start(&mut self)
pub fn start(&mut self)
Starts the evolution, generating the initial population and calculating the fitness of each individual.
Sourcepub fn next(&mut self)
pub fn next(&mut self)
This method runs one generation of the evolution. It selects the mating pool, crossover, mutate and calculates the fitness of the new population.
Sourcepub fn run(&mut self)
pub fn run(&mut self)
This method runs the evolution, generation over generation, until the stop condition is met.
pub fn population_digest(&self)
Sourcepub fn time_digest(&self)
pub fn time_digest(&self)
Prints total time and the time spent in each step of the evolution. In the following format:
------------ Time Digest ------------
Total time: X.XXXXs
Selection time: X.XXXXs (XX.XX%)
Crossover time: X.XXXXs (XX.XX%)
Mutation time: X.XXXXs (XX.XX%)
Fitness time: X.XXXXs (XX.XX%)
---------------------------------------Sourcepub fn current_best(&self) -> &T
pub fn current_best(&self) -> &T
Returns the best individual of the current population.
Sourcepub fn current_population(&self) -> Vec<T>
pub fn current_population(&self) -> Vec<T>
Returns a copy of the current population sorted by fitness.
Sourcepub fn reached_stop_condition(&self) -> bool
pub fn reached_stop_condition(&self) -> bool
Returns if the stop condition was already met for this evolution object.
pub fn current_best_fitness(&self) -> f64
pub fn current_fitness_average(&self) -> f64
pub fn plot_chart( &self, path: impl Into<String>, test_name: impl Into<String>, ) -> Result<(), Box<dyn Error>>
Auto Trait Implementations§
impl<T> Freeze for Evolution<T>
impl<T> !RefUnwindSafe for Evolution<T>
impl<T> Send for Evolution<T>
impl<T> Sync for Evolution<T>
impl<T> Unpin for Evolution<T>
impl<T> !UnwindSafe for Evolution<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more