Struct genevo::selection::tournament::TournamentSelector
source · [−]pub struct TournamentSelector { /* private fields */ }
Expand description
The TournamentSelector
implements the tournament selection method.
It runs tournaments with a small size of participants and pick the best
performing individuals from each tournament.
The number of participants in each tournament is configurable by the
tournament_size
field. A tournament size of 1 is called 1-way tournament
and is equivalent to random selection.
The final selection is picked from the best performing participants in each
tournament but with a probability. The probability gives also chances to
the second best, third best and so on. The probability is configurable by
the probability
field. A probability of 1.0 means the tournament is
deterministic. The best and only the best individual of each tournament is
selected.
To avoid that candidates chosen once are selected again they are removed
from the list of candidates. Though this can be configured as well. The
field remove_selected_individuals
controls whether selected candidates
are removed or not.
This TournamentSelector
can be used for single-objective fitness values
as well as multi-objective fitness values.
Implementations
sourceimpl TournamentSelector
impl TournamentSelector
sourcepub fn new(
selection_ratio: f64,
num_individuals_per_parents: usize,
tournament_size: usize,
probability: f64,
remove_selected_individuals: bool
) -> Self
pub fn new(
selection_ratio: f64,
num_individuals_per_parents: usize,
tournament_size: usize,
probability: f64,
remove_selected_individuals: bool
) -> Self
Constructs a new instance of the TournamentSelector
.
sourcepub fn selection_ratio(&self) -> f64
pub fn selection_ratio(&self) -> f64
Returns the selection ratio.
The selection ratio is the fraction of number of parents that are
selected on every call of the select_from
function and the number
of individuals in the population.
sourcepub fn set_selection_ratio(&mut self, value: f64)
pub fn set_selection_ratio(&mut self, value: f64)
Sets the selection ratio to a new value.
The selection ratio is the fraction of number of parents that are
selected on every call of the select_from
function and the number
of individuals in the population.
sourcepub fn num_individuals_per_parents(&self) -> usize
pub fn num_individuals_per_parents(&self) -> usize
Returns the number of individuals per parents use by this selector.
sourcepub fn set_num_individuals_per_parents(&mut self, value: usize)
pub fn set_num_individuals_per_parents(&mut self, value: usize)
Sets the number of individuals per parents to the given value.
sourcepub fn tournament_size(&self) -> usize
pub fn tournament_size(&self) -> usize
Returns the size of one tournament.
sourcepub fn set_tournament_size(&mut self, value: usize)
pub fn set_tournament_size(&mut self, value: usize)
Sets the size of one tournament to a given value. The value must be a positive integer greater 0.
A tournament size of 1 is called 1-way tournament and is equivalent to random selection.
sourcepub fn probability(&self) -> f64
pub fn probability(&self) -> f64
Returns the probability to pick candidates from one tournament.
sourcepub fn set_probability(&mut self, value: f64)
pub fn set_probability(&mut self, value: f64)
Set the probability to pick candidates from one tournament to the given value. The value must be between 0 and 1.0 (inclusive).
A probability of 1.0 means the tournament is deterministic. The best and only the best individual of each tournament is selected.
sourcepub fn is_remove_selected_individuals(&self) -> bool
pub fn is_remove_selected_individuals(&self) -> bool
Returns whether individuals are removed from the list of candidates after they have been picked once.
sourcepub fn set_remove_selected_individuals(&mut self, value: bool)
pub fn set_remove_selected_individuals(&mut self, value: bool)
Sets whether individuals shall be removed from the list of candidates after they have been picked once.
Trait Implementations
sourceimpl Clone for TournamentSelector
impl Clone for TournamentSelector
sourcefn clone(&self) -> TournamentSelector
fn clone(&self) -> TournamentSelector
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for TournamentSelector
impl Debug for TournamentSelector
sourceimpl GeneticOperator for TournamentSelector
impl GeneticOperator for TournamentSelector
sourceimpl PartialEq<TournamentSelector> for TournamentSelector
impl PartialEq<TournamentSelector> for TournamentSelector
sourcefn eq(&self, other: &TournamentSelector) -> bool
fn eq(&self, other: &TournamentSelector) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &TournamentSelector) -> bool
fn ne(&self, other: &TournamentSelector) -> bool
This method tests for !=
.
sourceimpl<G, F> SelectionOp<G, F> for TournamentSelector where
G: Genotype,
F: Fitness,
impl<G, F> SelectionOp<G, F> for TournamentSelector where
G: Genotype,
F: Fitness,
sourcefn select_from<R>(
&self,
evaluated: &EvaluatedPopulation<G, F>,
rng: &mut R
) -> Vec<Parents<G>> where
R: Rng + Sized,
fn select_from<R>(
&self,
evaluated: &EvaluatedPopulation<G, F>,
rng: &mut R
) -> Vec<Parents<G>> where
R: Rng + Sized,
Selects individuals from the given population according to the implemented selection strategy. Read more
impl MultiObjective for TournamentSelector
Can be used for multi-objective optimization
impl SingleObjective for TournamentSelector
Can be used for single-objective optimization
impl StructuralPartialEq for TournamentSelector
Auto Trait Implementations
impl RefUnwindSafe for TournamentSelector
impl Send for TournamentSelector
impl Sync for TournamentSelector
impl Unpin for TournamentSelector
impl UnwindSafe for TournamentSelector
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T> Pointable for T
impl<T> Pointable for T
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more