From 1423714f87714f1a7eb9a9de45cde559a61a3c8e Mon Sep 17 00:00:00 2001 From: Kacper Kafara Date: Wed, 30 Nov 2022 11:00:41 +0100 Subject: [PATCH 1/4] Add docs for GAParams --- src/ga.rs | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/ga.rs b/src/ga.rs index 576b6090..b486eee5 100644 --- a/src/ga.rs +++ b/src/ga.rs @@ -19,26 +19,35 @@ use self::{ type FitnessFn = fn(&S) -> f64; +/// Parameters for the genetic algorithm pub struct GAParams { + /// **Unused for now** pub selection_rate: f64, + + /// Describes chance of a individual gene to be mutated + /// + /// This parameter is passed down to a mutation operator + /// + /// Must be in range [0, 1] pub mutation_rate: f64, + + /// Number of individuals in population + /// + /// In current implementation of the algorithm the size of population + /// is constant throughout generations pub population_size: usize, + + /// Maximum number of generations (search termination) + /// + /// This works interchangeably with `max_duration` - first limit hit terminates the algorithm pub generation_limit: usize, + + /// Maximum duration of computations (search termination) + /// + /// This works interchangeably with `generation_limit` - first limit hit terminates the algorithm pub max_duration: std::time::Duration, } -// impl Default for GAParams { -// fn default() -> Self { -// Self { -// selection_rate: 0.5f64, -// mutation_rate: 0.05, -// population_size: 100, -// generation_limit: 200, -// max_duration: None, -// } -// } -// } - pub struct GAConfig where T: Chromosome, From dcb8037df58728ffacfbd9fedcb58029fe911826 Mon Sep 17 00:00:00 2001 From: Kacper Kafara Date: Wed, 30 Nov 2022 11:10:24 +0100 Subject: [PATCH 2/4] Docs for GA config --- src/ga.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/ga.rs b/src/ga.rs index b486eee5..889f81c6 100644 --- a/src/ga.rs +++ b/src/ga.rs @@ -48,6 +48,11 @@ pub struct GAParams { pub max_duration: std::time::Duration, } +/// Configuration for the genetic algorithm +/// +/// It describes initial parameters & operators for the algorithm +/// +/// Configuration of genetic algorithm is done via builder interface though pub struct GAConfig where T: Chromosome, @@ -57,13 +62,26 @@ where P: PopulationGenerator, Pr: Probe, { + /// Set of parameters for the genetic algorithm. See [GAParams] for details. pub params: GAParams, - // pub ops: GAOps, + + /// Fitness function. It must operate on a solution representation - chromosome. Should return `f64`. + /// Please note that some of the genetic operators require fitness function to be positive. pub fitness_fn: FitnessFn, + + /// Mutation operator. See [MutationOperator](crate::ga::operators::mutation::MutationOperator) for details. pub mutation_operator: M, + + /// Crossover operator. See [CrossoverOperator](create::ga::operators::crossover::CrossoverOperator) for details. pub crossover_operator: C, + + /// Selection operator. See [SelectionOperator](crate::ga::operators::selection::SelectionOperator) for details. pub selection_operator: S, + + /// Population generator. See [PopulationGenerator](crate::ga::population::PopulationGenerator) for details. pub population_factory: P, + + pub probe: Pr, } From 17877746beff6dee4533f2ba91921864ed5155eb Mon Sep 17 00:00:00 2001 From: Kacper Kafara Date: Wed, 30 Nov 2022 22:41:08 +0100 Subject: [PATCH 3/4] Continue work on docs --- src/ga.rs | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/ga.rs b/src/ga.rs index 889f81c6..8238c4f9 100644 --- a/src/ga.rs +++ b/src/ga.rs @@ -25,33 +25,33 @@ pub struct GAParams { pub selection_rate: f64, /// Describes chance of a individual gene to be mutated - /// + /// /// This parameter is passed down to a mutation operator - /// + /// /// Must be in range [0, 1] pub mutation_rate: f64, /// Number of individuals in population - /// + /// /// In current implementation of the algorithm the size of population /// is constant throughout generations pub population_size: usize, /// Maximum number of generations (search termination) - /// + /// /// This works interchangeably with `max_duration` - first limit hit terminates the algorithm pub generation_limit: usize, /// Maximum duration of computations (search termination) - /// + /// /// This works interchangeably with `generation_limit` - first limit hit terminates the algorithm pub max_duration: std::time::Duration, } /// Configuration for the genetic algorithm -/// +/// /// It describes initial parameters & operators for the algorithm -/// +/// /// Configuration of genetic algorithm is done via builder interface though pub struct GAConfig where @@ -66,7 +66,7 @@ where pub params: GAParams, /// Fitness function. It must operate on a solution representation - chromosome. Should return `f64`. - /// Please note that some of the genetic operators require fitness function to be positive. + /// Please note that some of the genetic operators require fitness function to be positive. pub fitness_fn: FitnessFn, /// Mutation operator. See [MutationOperator](crate::ga::operators::mutation::MutationOperator) for details. @@ -81,14 +81,23 @@ where /// Population generator. See [PopulationGenerator](crate::ga::population::PopulationGenerator) for details. pub population_factory: P, - + /// Probe. See [Probe](crate::ga::probe::Probe) for details. pub probe: Pr, } +/// Structure representing advancement of the computations +/// +/// This struct is passed to probes, so they can make better decisions whether to log or not. #[derive(Default)] pub struct GAMetadata { + /// Computations start time. This field is filled just after GA's `run` method starts executing. + /// You can expect it to be always defined (the value is `Some`). pub start_time: Option, + + /// Duration of the computations. Measured in the very beginning of main loop (each iteration). pub duration: Option, + + /// Current generation number. Before entering the main loop it is equal to `0`. pub generation: usize, } @@ -106,6 +115,9 @@ impl GAMetadata { } } +/// Custom implementation of genetic algorithm. +/// +/// TODO: Extensive description pub struct GeneticAlgorithm where T: Chromosome, From 373e76e7c5543560cf9faad596f03ddec8c07747 Mon Sep 17 00:00:00 2001 From: Kacper Kafara Date: Wed, 30 Nov 2022 22:48:24 +0100 Subject: [PATCH 4/4] Cargo fmt --- src/ga.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ga.rs b/src/ga.rs index 8238c4f9..a71ae78e 100644 --- a/src/ga.rs +++ b/src/ga.rs @@ -81,7 +81,7 @@ where /// Population generator. See [PopulationGenerator](crate::ga::population::PopulationGenerator) for details. pub population_factory: P, - /// Probe. See [Probe](crate::ga::probe::Probe) for details. + /// Probe. See [Probe](crate::ga::probe::Probe) for details. pub probe: Pr, } @@ -90,14 +90,14 @@ where /// This struct is passed to probes, so they can make better decisions whether to log or not. #[derive(Default)] pub struct GAMetadata { - /// Computations start time. This field is filled just after GA's `run` method starts executing. - /// You can expect it to be always defined (the value is `Some`). + /// Computations start time. This field is filled just after GA's `run` method starts executing. + /// You can expect it to be always defined (the value is `Some`). pub start_time: Option, - /// Duration of the computations. Measured in the very beginning of main loop (each iteration). + /// Duration of the computations. Measured in the very beginning of main loop (each iteration). pub duration: Option, - /// Current generation number. Before entering the main loop it is equal to `0`. + /// Current generation number. Before entering the main loop it is equal to `0`. pub generation: usize, }