pub struct GeneticEngineBuilder<C, T>{ /* private fields */ }
Expand description
Parameters for the genetic engine. This struct is used to configure the genetic engine before it is created.
When the GeneticEngineParams
calls the build
method, it will create a new instance
of the GeneticEngine
with the given parameters. If any of the required parameters are not
set, the build
method will panic. At a minimum, the codec
and fitness_fn
must be set.
The GeneticEngineParams
struct is a builder pattern that allows you to set the parameters of
the GeneticEngine
in a fluent and functional way.
§Type Parameters
C
: The type of chromosome used in the genotype, which must implement theChromosome
trait.T
: The type of the best individual in the population.
Implementations§
Source§impl<C, T> GeneticEngineBuilder<C, T>
impl<C, T> GeneticEngineBuilder<C, T>
Sourcepub fn alter(
self,
alterers: Vec<Box<dyn Alter<C>>>,
) -> GeneticEngineBuilder<C, T>
pub fn alter( self, alterers: Vec<Box<dyn Alter<C>>>, ) -> GeneticEngineBuilder<C, T>
Set the alterer of the genetic engine. This is the alterer that will be used to alter the offspring of the population. The alterer is used to apply mutations and crossover operations to the offspring and will be used to create the next generation of the population. Note: the order of the alterers is important - the alterers will be applied in the order they are provided.
Sourcepub fn mutator<M>(self, mutator: M) -> GeneticEngineBuilder<C, T>where
M: Mutate<C> + 'static,
pub fn mutator<M>(self, mutator: M) -> GeneticEngineBuilder<C, T>where
M: Mutate<C> + 'static,
Define a single mutator for the genetic engine - this will be converted to
a Box<dyn Alter<C>>
and added to the list of alterers. Note: The order in which
mutators and crossovers are added is the order in which they will be applied during
the evolution process.
Sourcepub fn mutators(
self,
mutators: Vec<Box<dyn Mutate<C>>>,
) -> GeneticEngineBuilder<C, T>
pub fn mutators( self, mutators: Vec<Box<dyn Mutate<C>>>, ) -> GeneticEngineBuilder<C, T>
Define a list of mutators for the genetic engine - this will be converted to a list
of Box<dyn Alter<C>>
and added to the list of alterers. Just like adding a single mutator,
the order in which mutators and crossovers are added is the order in which they will be applied
during the evolution process.s
Sourcepub fn crossover<R>(self, crossover: R) -> GeneticEngineBuilder<C, T>where
R: Crossover<C> + 'static,
pub fn crossover<R>(self, crossover: R) -> GeneticEngineBuilder<C, T>where
R: Crossover<C> + 'static,
Define a single crossover for the genetic engine - this will be converted to
a Box<dyn Alter<C>>
and added to the list of alterers. Note: The order in which
mutators and crossovers are added is the order in which they will be applied during
the evolution process.s
Sourcepub fn crossovers(
self,
crossovers: Vec<Box<dyn Crossover<C>>>,
) -> GeneticEngineBuilder<C, T>
pub fn crossovers( self, crossovers: Vec<Box<dyn Crossover<C>>>, ) -> GeneticEngineBuilder<C, T>
Define a list of crossovers for the genetic engine - this will be converted to a list
of Box<dyn Alter<C>>
and added to the list of alterers. Just like adding a single crossover,
the order in which mutators and crossovers are added is the order in which they will be applied
during the evolution process.
Source§impl<C, T> GeneticEngineBuilder<C, T>
impl<C, T> GeneticEngineBuilder<C, T>
pub fn evaluator<V>(self, evaluator: V) -> GeneticEngineBuilder<C, T>where
V: Evaluator<C, T> + 'static,
pub fn executor(self, executor: Executor) -> GeneticEngineBuilder<C, T>
pub fn fitness_executor( self, executor: impl Into<Arc<Executor>>, ) -> GeneticEngineBuilder<C, T>
pub fn species_executor( self, executor: impl Into<Arc<Executor>>, ) -> GeneticEngineBuilder<C, T>
pub fn bus_executor( self, executor: impl Into<Arc<Executor>>, ) -> GeneticEngineBuilder<C, T>
Source§impl<C, T> GeneticEngineBuilder<C, T>
impl<C, T> GeneticEngineBuilder<C, T>
Sourcepub fn minimizing(self) -> GeneticEngineBuilder<C, T>
pub fn minimizing(self) -> GeneticEngineBuilder<C, T>
Set the optimization goal of the genetic engine to minimize the fitness function.
Sourcepub fn maximizing(self) -> GeneticEngineBuilder<C, T>
pub fn maximizing(self) -> GeneticEngineBuilder<C, T>
Set the optimization goal of the genetic engine to maximize the fitness function.
pub fn multi_objective( self, objectives: Vec<Optimize>, ) -> GeneticEngineBuilder<C, T>
Sourcepub fn front_size(self, range: Range<usize>) -> GeneticEngineBuilder<C, T>
pub fn front_size(self, range: Range<usize>) -> GeneticEngineBuilder<C, T>
Set the minimum and maximum size of the pareto front. This is used for multi-objective optimization problems where the goal is to find the best solutions that are not dominated by any other solution.
Source§impl<C, T> GeneticEngineBuilder<C, T>
impl<C, T> GeneticEngineBuilder<C, T>
Sourcepub fn population_size(
self,
population_size: usize,
) -> GeneticEngineBuilder<C, T>
pub fn population_size( self, population_size: usize, ) -> GeneticEngineBuilder<C, T>
Set the population size of the genetic engine. Default is 100.
Sourcepub fn max_age(self, max_age: usize) -> GeneticEngineBuilder<C, T>
pub fn max_age(self, max_age: usize) -> GeneticEngineBuilder<C, T>
Set the maximum age of an individual in the population. Default is 25.
Sourcepub fn population(
self,
population: impl Into<Population<C>>,
) -> GeneticEngineBuilder<C, T>
pub fn population( self, population: impl Into<Population<C>>, ) -> GeneticEngineBuilder<C, T>
Set the population of the genetic engine. This is useful if you want to provide a custom population.
If this is not set, the genetic engine will create a new population of population_size
using the codec.
Source§impl<C, T> GeneticEngineBuilder<C, T>
impl<C, T> GeneticEngineBuilder<C, T>
Sourcepub fn codec<D>(self, codec: D) -> GeneticEngineBuilder<C, T>where
D: Codec<C, T> + 'static,
pub fn codec<D>(self, codec: D) -> GeneticEngineBuilder<C, T>where
D: Codec<C, T> + 'static,
Set the codec that will be used to encode and decode the genotype of the population.
Sourcepub fn problem<P>(self, problem: P) -> GeneticEngineBuilder<C, T>where
P: Problem<C, T> + 'static,
pub fn problem<P>(self, problem: P) -> GeneticEngineBuilder<C, T>where
P: Problem<C, T> + 'static,
Set the problem of the genetic engine. This is useful if you want to provide a custom problem.
Sourcepub fn fitness_fn<S>(
self,
fitness_func: impl FitnessFunction<T, S> + 'static,
) -> GeneticEngineBuilder<C, T>
pub fn fitness_fn<S>( self, fitness_func: impl FitnessFunction<T, S> + 'static, ) -> GeneticEngineBuilder<C, T>
Set the fitness function of the genetic engine. This is the function that will be
used to evaluate the fitness of each individual in the population. This function should
take a single argument of type T and return a Score
. The Score
is used to
evaluate or rank the fitness of the individual.
This method is required and must be set before calling the build
method.
Sourcepub fn batch_fitness_fn<S>(
self,
batch_fitness_func: impl BatchFitnessFunction<T, S> + 'static,
) -> GeneticEngineBuilder<C, T>
pub fn batch_fitness_fn<S>( self, batch_fitness_func: impl BatchFitnessFunction<T, S> + 'static, ) -> GeneticEngineBuilder<C, T>
Set the batch fitness function of the genetic engine. This function will be used to
evaluate the fitness of a batch of individuals in the population. This function should
take a slice of type &[T]
and return a Vec<Score>
. The Score is used to
evaluate or rank the fitness of the individuals.
This method is optional and can be set after calling the build
method.
Source§impl<C, T> GeneticEngineBuilder<C, T>
impl<C, T> GeneticEngineBuilder<C, T>
Sourcepub fn offspring_fraction(
self,
offspring_fraction: f32,
) -> GeneticEngineBuilder<C, T>
pub fn offspring_fraction( self, offspring_fraction: f32, ) -> GeneticEngineBuilder<C, T>
Set the fraction of the population that will be replaced by offspring each generation. Default is 0.8. This is a value from 0…=1 that represents the fraction of population that will be replaced by offspring each generation. The remainder will ‘survive’ to the next generation.
pub fn boxed_survivor_selector( self, selector: Box<dyn Select<C>>, ) -> GeneticEngineBuilder<C, T>
pub fn boxed_offspring_selector( self, selector: Box<dyn Select<C>>, ) -> GeneticEngineBuilder<C, T>
Sourcepub fn survivor_selector<S>(self, selector: S) -> GeneticEngineBuilder<C, T>where
S: Select<C> + 'static,
pub fn survivor_selector<S>(self, selector: S) -> GeneticEngineBuilder<C, T>where
S: Select<C> + 'static,
Set the survivor selector of the genetic engine. This is the selector that will
be used to select the survivors of the population. Default is TournamentSelector
with a group size of 3.
Sourcepub fn offspring_selector<S>(self, selector: S) -> GeneticEngineBuilder<C, T>where
S: Select<C> + 'static,
pub fn offspring_selector<S>(self, selector: S) -> GeneticEngineBuilder<C, T>where
S: Select<C> + 'static,
Set the offspring selector of the genetic engine. This is the selector that will
be used to select the offspring of the population. Default is RouletteSelector
.
Source§impl<C, T> GeneticEngineBuilder<C, T>
impl<C, T> GeneticEngineBuilder<C, T>
pub fn boxed_diversity( self, diversity: Option<Box<dyn Diversity<C>>>, ) -> GeneticEngineBuilder<C, T>
pub fn diversity<D>(self, diversity: D) -> GeneticEngineBuilder<C, T>where
D: Diversity<C> + 'static,
pub fn species_threshold(self, threshold: f32) -> GeneticEngineBuilder<C, T>
pub fn max_species_age( self, max_species_age: usize, ) -> GeneticEngineBuilder<C, T>
Source§impl<C, T> GeneticEngineBuilder<C, T>
impl<C, T> GeneticEngineBuilder<C, T>
Sourcepub fn replace_strategy<R>(self, replace: R) -> GeneticEngineBuilder<C, T>where
R: ReplacementStrategy<C> + 'static,
pub fn replace_strategy<R>(self, replace: R) -> GeneticEngineBuilder<C, T>where
R: ReplacementStrategy<C> + 'static,
The ReplacementStrategy is used to determine how a new individual is added to the Population if an individual is deemed to be either invalid or reaches the maximum age.
Default is EncodeReplace, which means that a new individual will be created
be using the Codec
to encode a new individual from scratch.
Sourcepub fn subscribe<H>(self, handler: H) -> GeneticEngineBuilder<C, T>where
H: EventHandler<EngineEvent<T>> + 'static,
pub fn subscribe<H>(self, handler: H) -> GeneticEngineBuilder<C, T>where
H: EventHandler<EngineEvent<T>> + 'static,
Subscribe to engine events with the given event handler. The event handler will be called whenever an event is emitted by the engine. You can use this to log events, or to perform custom actions based on the events emitted by the engine.
Source§impl<C, T> GeneticEngineBuilder<C, T>
Static step builder for the genetic engine.
impl<C, T> GeneticEngineBuilder<C, T>
Static step builder for the genetic engine.
Sourcepub fn build(self) -> GeneticEngine<C, T>
pub fn build(self) -> GeneticEngine<C, T>
Build the genetic engine with the given parameters. This will create a new
instance of the GeneticEngine
with the given parameters.
Trait Implementations§
Source§impl<C, T> Clone for GeneticEngineBuilder<C, T>
impl<C, T> Clone for GeneticEngineBuilder<C, T>
Source§fn clone(&self) -> GeneticEngineBuilder<C, T>
fn clone(&self) -> GeneticEngineBuilder<C, T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more