1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
pub(crate) use std::collections::HashMap;

use crate::configuration::SelectionConfiguration;
use crate::traits::GenotypeT;

use self::random::random;
use self::fitness_proportionate::roulette_wheel_selection;
use self::fitness_proportionate::stochastic_universal_sampling;
use self::tournament::tournament;

use super::Selection;

pub mod random;
pub mod fitness_proportionate;
pub mod tournament;

pub fn factory<U>(individuals: &Vec<U>, configuration: SelectionConfiguration, number_of_threads: i32) -> HashMap<usize, usize>
where
U: GenotypeT + Sync + Send + 'static + Clone
{
    match configuration.method {
        Selection::Random => {random(individuals)},
        Selection::RouletteWheel => {roulette_wheel_selection(individuals)},
        Selection::StochasticUniversalSampling => {stochastic_universal_sampling(individuals, configuration.number_of_couples.unwrap())},
        Selection::Tournament => {tournament(individuals, configuration.number_of_couples.unwrap(), number_of_threads)},
    }
}