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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
use genetic_algorithm::GeneticAlgorithmParams; #[derive(Debug)] pub struct GeneticAlgorithmParamsBuilder<CR, MA, MU, S> { crossover: Option<CR>, mating_selection: Option<MA>, mutation: Option<MU>, survivor_selection: Option<S>, } impl<CR, MA, MU, S> GeneticAlgorithmParamsBuilder<CR, MA, MU, S> { pub fn new() -> Self { GeneticAlgorithmParamsBuilder::default() } pub fn build(self) -> GeneticAlgorithmParams<CR, MA, MU, S> { GeneticAlgorithmParams { crossover: self.crossover.unwrap(), mating_selection: self.mating_selection.unwrap(), mutation: self.mutation.unwrap(), survivor_selection: self.survivor_selection.unwrap(), } } pub fn crossover(mut self, crossover: CR) -> Self { self.crossover = Some(crossover); self } pub fn mating_selection(mut self, mating_selection: MA) -> Self { self.mating_selection = Some(mating_selection); self } pub fn mutation(mut self, mutation: MU) -> Self { self.mutation = Some(mutation); self } pub fn survivor_selection(mut self, survivor_selection: S) -> Self { self.survivor_selection = Some(survivor_selection); self } } impl<CR, MA, MU, S> Default for GeneticAlgorithmParamsBuilder<CR, MA, MU, S> { fn default() -> Self { GeneticAlgorithmParamsBuilder { crossover: None, mating_selection: None, mutation: None, survivor_selection: None, } } }