pub struct StochasticUniversalSampling<R: Rng> { /* private fields */ }Expand description
§Stochastic universal sampling selection operator
This struct implements SelectionOperator trati and can be used with GA
Note: This selection operator requires positive fitenss function. No runtime checks are performed to assert this invariant. If aggregated fitenss in whole population is <= the behaviour is undefined, implementation dependent and might change without any notice.
Note: The same individual can be selected multiple times
Individuals are selected in process similar to described below:
- Individuals are laid on real axis, in order they appear in population,
to interval [0,
total_fitness]; each individual is represented by sub interval of lengths equal to its fitness countvirtual pointers are placed along interval [0,total_fitness]; distance between pointersdistotal_fitness/mating_pool_size; first pointer position is selected randomly from interval [0,d]- Iterate over the pointers and select the individuals they point to
See the source code for implemenation details
Implementations§
Source§impl StochasticUniversalSampling<ThreadRng>
impl StochasticUniversalSampling<ThreadRng>
Sourcepub fn new() -> Self
pub fn new() -> Self
Returns new instance of StochasticUniversalSampling selection operator with default RNG
Source§impl<R: Rng> StochasticUniversalSampling<R>
impl<R: Rng> StochasticUniversalSampling<R>
Sourcepub fn with_rng(rng: R) -> Self
pub fn with_rng(rng: R) -> Self
Returns new instance of StochasticUniversalSampling selection operator with custom RNG
Trait Implementations§
Source§impl<IndividualT: IndividualTrait<FitnessValueT = f64>, R: Rng> SelectionOperator<IndividualT> for StochasticUniversalSampling<R>
impl<IndividualT: IndividualTrait<FitnessValueT = f64>, R: Rng> SelectionOperator<IndividualT> for StochasticUniversalSampling<R>
Source§fn apply<'a>(
&mut self,
_metadata: &GAMetadata,
population: &'a [IndividualT],
count: usize,
) -> Vec<&'a IndividualT>
fn apply<'a>( &mut self, _metadata: &GAMetadata, population: &'a [IndividualT], count: usize, ) -> Vec<&'a IndividualT>
Returns a vector of references to individuals selected to mating pool
Note: This selection operator requires positive fitenss function. No runtime checks are performed to assert this invariant. If aggregated fitenss in whole population is <= the behaviour is undefined, implementation dependent and might change without any notice.
Note: The same individual can be selected multiple times
Individuals are selected in process similar to described below:
- Individuals are laid on real axis, in order they appear in population,
to interval [0,
total_fitness]; each individual is represented by sub interval of lengths equal to its fitness countvirtual pointers are placed along interval [0,total_fitness]; distance between pointersdistotal_fitness/mating_pool_size; first pointer position is selected randomly from interval [0,d]- Iterate over the pointers and select the individuals they point to
See the source code for implemenation details
§Arguments
metadata- crate::ga::GAMetadata information on current stage of the algorithm (iteration, elapsed time, etc.)population- individuals to choose mating pool fromcount- target number of individuals in mating pool
Auto Trait Implementations§
impl<R> Freeze for StochasticUniversalSampling<R>where
R: Freeze,
impl<R> RefUnwindSafe for StochasticUniversalSampling<R>where
R: RefUnwindSafe,
impl<R> Send for StochasticUniversalSampling<R>where
R: Send,
impl<R> Sync for StochasticUniversalSampling<R>where
R: Sync,
impl<R> Unpin for StochasticUniversalSampling<R>where
R: Unpin,
impl<R> UnsafeUnpin for StochasticUniversalSampling<R>where
R: UnsafeUnpin,
impl<R> UnwindSafe for StochasticUniversalSampling<R>where
R: UnwindSafe,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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> ⓘ
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> ⓘ
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