GeneticEngineBuilder

Struct GeneticEngineBuilder 

Source
pub struct GeneticEngineBuilder<C, T>
where C: Chromosome + Clone + 'static, T: Clone + 'static,
{ /* 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 the Chromosome trait.
  • T: The type of the best individual in the population.

Implementations§

Source§

impl<C, T> GeneticEngineBuilder<C, T>
where C: Chromosome + PartialEq + Clone, T: Clone + Send,

Source

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.

Source

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.

Source

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

Source

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

Source

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>
where C: Chromosome + PartialEq + Clone, T: Clone + Send,

Source

pub fn evaluator<V>(self, evaluator: V) -> GeneticEngineBuilder<C, T>
where V: Evaluator<C, T> + 'static,

Source

pub fn executor(self, executor: Executor) -> GeneticEngineBuilder<C, T>

Source

pub fn fitness_executor( self, executor: impl Into<Arc<Executor>>, ) -> GeneticEngineBuilder<C, T>

Source

pub fn species_executor( self, executor: impl Into<Arc<Executor>>, ) -> GeneticEngineBuilder<C, T>

Source

pub fn bus_executor( self, executor: impl Into<Arc<Executor>>, ) -> GeneticEngineBuilder<C, T>

Source§

impl<C, T> GeneticEngineBuilder<C, T>
where C: Chromosome + PartialEq + Clone, T: Clone + Send,

Source

pub fn minimizing(self) -> GeneticEngineBuilder<C, T>

Set the optimization goal of the genetic engine to minimize the fitness function.

Source

pub fn maximizing(self) -> GeneticEngineBuilder<C, T>

Set the optimization goal of the genetic engine to maximize the fitness function.

Source

pub fn multi_objective( self, objectives: Vec<Optimize>, ) -> GeneticEngineBuilder<C, T>

Source

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>
where C: Chromosome + PartialEq + Clone, T: Clone + Send,

Source

pub fn population_size( self, population_size: usize, ) -> GeneticEngineBuilder<C, T>

Set the population size of the genetic engine. Default is 100.

Source

pub fn max_age(self, max_age: usize) -> GeneticEngineBuilder<C, T>

Set the maximum age of an individual in the population. Default is 25.

Source

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>
where C: Chromosome + PartialEq + Clone, T: Clone + Send,

Source

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.

Source

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.

Source

pub fn fitness_fn<S>( self, fitness_func: impl FitnessFunction<T, S> + 'static, ) -> GeneticEngineBuilder<C, T>
where S: Into<Score>,

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.

Source

pub fn batch_fitness_fn<S>( self, batch_fitness_func: impl BatchFitnessFunction<T, S> + 'static, ) -> GeneticEngineBuilder<C, T>
where S: Into<Score>,

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>
where C: Chromosome + PartialEq + Clone, T: Clone + Send,

Source

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.

Source

pub fn boxed_survivor_selector( self, selector: Box<dyn Select<C>>, ) -> GeneticEngineBuilder<C, T>

Source

pub fn boxed_offspring_selector( self, selector: Box<dyn Select<C>>, ) -> GeneticEngineBuilder<C, T>

Source

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.

Source

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>
where C: Chromosome + PartialEq + Clone, T: Clone + Send,

Source

pub fn boxed_diversity( self, diversity: Option<Box<dyn Diversity<C>>>, ) -> GeneticEngineBuilder<C, T>

Source

pub fn diversity<D>(self, diversity: D) -> GeneticEngineBuilder<C, T>
where D: Diversity<C> + 'static,

Source

pub fn species_threshold(self, threshold: f32) -> GeneticEngineBuilder<C, T>

Source

pub fn max_species_age( self, max_species_age: usize, ) -> GeneticEngineBuilder<C, T>

Source§

impl<C, T> GeneticEngineBuilder<C, T>
where C: Chromosome + PartialEq + Clone, T: Clone + Send,

Source

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.

Source

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>
where C: Chromosome + Clone + PartialEq + 'static, T: Clone + Send + Sync + 'static,

Static step builder for the genetic engine.

Source

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>
where C: Clone + Chromosome + 'static, T: Clone + 'static,

Source§

fn clone(&self) -> GeneticEngineBuilder<C, T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<C, T> Default for GeneticEngineBuilder<C, T>
where C: Chromosome + Clone + 'static, T: Clone + Send + 'static,

Source§

fn default() -> GeneticEngineBuilder<C, T>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<C, T> Freeze for GeneticEngineBuilder<C, T>

§

impl<C, T> !RefUnwindSafe for GeneticEngineBuilder<C, T>

§

impl<C, T> !Send for GeneticEngineBuilder<C, T>

§

impl<C, T> !Sync for GeneticEngineBuilder<C, T>

§

impl<C, T> Unpin for GeneticEngineBuilder<C, T>

§

impl<C, T> !UnwindSafe for GeneticEngineBuilder<C, T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more