diff --git a/examples/jssp/problem/crossover.rs b/examples/jssp/problem/crossover.rs index 5d28614..e708095 100644 --- a/examples/jssp/problem/crossover.rs +++ b/examples/jssp/problem/crossover.rs @@ -20,7 +20,7 @@ impl JsspCrossover { fn apply_single( &mut self, - _metadata: &Metrics, + _metrics: &Metrics, parent_1: &JsspIndividual, parent_2: &JsspIndividual, ) -> (JsspIndividual, JsspIndividual) { @@ -53,13 +53,13 @@ impl JsspCrossover { } impl CrossoverOperator for JsspCrossover { - fn apply(&mut self, metadata: &Metrics, selected: &[&JsspIndividual]) -> Vec { + fn apply(&mut self, metrics: &Metrics, selected: &[&JsspIndividual]) -> Vec { assert!(selected.len() & 1 == 0); let mut output = Vec::with_capacity(selected.len()); for parents in selected.chunks(2) { - let (child_1, child_2) = self.apply_single(metadata, parents[0], parents[1]); + let (child_1, child_2) = self.apply_single(metrics, parents[0], parents[1]); output.push(child_1); output.push(child_2); } @@ -77,7 +77,7 @@ impl NoopCrossover { fn apply_single( &mut self, - _metadata: &Metrics, + _metrics: &Metrics, parent_1: &JsspIndividual, parent_2: &JsspIndividual, ) -> (JsspIndividual, JsspIndividual) { @@ -86,13 +86,13 @@ impl NoopCrossover { } impl CrossoverOperator for NoopCrossover { - fn apply(&mut self, metadata: &Metrics, selected: &[&JsspIndividual]) -> Vec { + fn apply(&mut self, metrics: &Metrics, selected: &[&JsspIndividual]) -> Vec { assert!(selected.len() & 1 == 0); let mut output = Vec::with_capacity(selected.len()); for parents in selected.chunks(2) { - let (child_1, child_2) = self.apply_single(metadata, parents[0], parents[1]); + let (child_1, child_2) = self.apply_single(metrics, parents[0], parents[1]); output.push(child_1); output.push(child_2); } diff --git a/examples/jssp/problem/probe.rs b/examples/jssp/problem/probe.rs index a84ebf0..7ce76b5 100644 --- a/examples/jssp/problem/probe.rs +++ b/examples/jssp/problem/probe.rs @@ -84,7 +84,7 @@ impl Probe for JsspProbe { // iterinfo,,,,,,, #[inline] - fn on_start(&mut self, _metadata: &ecrs::ga::Metrics) { + fn on_start(&mut self, _metrics: &ecrs::ga::Metrics) { // Writing csv header to each file info!(target: "popmetrics", "event_name,generation,total_duration,population_size,diversity,distance_avg"); info!(target: "popgentime", "event_name,time"); @@ -93,7 +93,7 @@ impl Probe for JsspProbe { info!(target: "iterinfo", "event_name,generation,eval_time,sel_time,cross_time,mut_time,repl_time,iter_time"); } - fn on_initial_population_created(&mut self, metadata: &ecrs::ga::Metrics, population: &[JsspIndividual]) { + fn on_initial_population_created(&mut self, metrics: &ecrs::ga::Metrics, population: &[JsspIndividual]) { debug_assert_eq!(self.repeated.len(), 0); self.repeated.resize(population.len(), false); @@ -102,20 +102,20 @@ impl Probe for JsspProbe { let diversity = self.estimate_pop_diversity(population); let distance_avg = self.estimate_avg_distance(population); info!(target: "popmetrics", "diversity,0,0,{},{diversity},{distance_avg}", population.len()); - info!(target: "popgentime", "popgentime,{}", metadata.pop_gen_dur.unwrap().as_millis()); + info!(target: "popgentime", "popgentime,{}", metrics.pop_gen_dur.unwrap().as_millis()); } - fn on_new_best(&mut self, metadata: &ecrs::ga::Metrics, individual: &JsspIndividual) { + fn on_new_best(&mut self, metrics: &ecrs::ga::Metrics, individual: &JsspIndividual) { info!( target: "newbest", "newbest,{},{},{}", - metadata.generation, - metadata.total_dur.unwrap().as_millis(), + metrics.generation, + metrics.total_dur.unwrap().as_millis(), individual.fitness ); } - fn on_new_generation(&mut self, metadata: &ecrs::ga::Metrics, generation: &[JsspIndividual]) { + fn on_new_generation(&mut self, metrics: &ecrs::ga::Metrics, generation: &[JsspIndividual]) { // TODO: As this metric is useless right now I'm disabling it temporarily // let diversity = self.estimate_pop_diversity(generation); let diversity = self.estimate_pop_diversity(generation); @@ -123,43 +123,43 @@ impl Probe for JsspProbe { info!( target: "popmetrics", "diversity,{},{},{},{diversity},{distance_avg}", - metadata.generation, - metadata.total_dur.unwrap().as_millis(), + metrics.generation, + metrics.total_dur.unwrap().as_millis(), generation.len() ); } - fn on_best_fit_in_generation(&mut self, metadata: &ecrs::ga::Metrics, individual: &JsspIndividual) { + fn on_best_fit_in_generation(&mut self, metrics: &ecrs::ga::Metrics, individual: &JsspIndividual) { info!( target: "bestingen", "bestingen,{},{},{}", - metadata.generation, - metadata.total_dur.unwrap().as_millis(), + metrics.generation, + metrics.total_dur.unwrap().as_millis(), individual.fitness ); } #[inline] - fn on_iteration_start(&mut self, _metadata: &ecrs::ga::Metrics) { /* defaults to noop */ + fn on_iteration_start(&mut self, _metrics: &ecrs::ga::Metrics) { /* defaults to noop */ } #[inline] - fn on_iteration_end(&mut self, metadata: &ecrs::ga::Metrics) { + fn on_iteration_end(&mut self, metrics: &ecrs::ga::Metrics) { info!(target: "iterinfo", "iterinfo,{},{},{},{},{},{},{}", - metadata.generation, - metadata.pop_eval_dur.unwrap().as_millis(), - metadata.selection_dur.unwrap().as_millis(), - metadata.crossover_dur.unwrap().as_millis(), - metadata.mutation_dur.unwrap().as_millis(), - metadata.replacement_dur.unwrap().as_millis(), - metadata.iteration_dur.unwrap().as_millis() + metrics.generation, + metrics.pop_eval_dur.unwrap().as_millis(), + metrics.selection_dur.unwrap().as_millis(), + metrics.crossover_dur.unwrap().as_millis(), + metrics.mutation_dur.unwrap().as_millis(), + metrics.replacement_dur.unwrap().as_millis(), + metrics.iteration_dur.unwrap().as_millis() ); } #[inline] fn on_end( &mut self, - metadata: &ecrs::ga::Metrics, + metrics: &ecrs::ga::Metrics, _population: &[JsspIndividual], best_individual: &JsspIndividual, ) { @@ -201,8 +201,8 @@ impl Probe for JsspProbe { solution_string, hash: format!("{:x}", hash), fitness: best_individual.fitness, - generation_count: metadata.generation, - total_time: metadata.total_dur.unwrap().as_millis(), + generation_count: metrics.generation, + total_time: metrics.total_dur.unwrap().as_millis(), chromosome: best_individual.chromosome(), }; let serialized_object = serde_json::to_string_pretty(&outdata).unwrap(); diff --git a/examples/jssp/problem/replacement.rs b/examples/jssp/problem/replacement.rs index ad13596..0202b36 100644 --- a/examples/jssp/problem/replacement.rs +++ b/examples/jssp/problem/replacement.rs @@ -24,7 +24,7 @@ impl JsspReplacement { impl ReplacementOperator for JsspReplacement { fn apply( &mut self, - _metadata: &Metrics, + _metrics: &Metrics, mut population: Vec, mut children: Vec, ) -> Vec { @@ -80,7 +80,7 @@ impl ReplaceWithRandomPopulation { impl ReplacementOperator for ReplaceWithRandomPopulation { fn apply( &mut self, - _metadata: &Metrics, + _metrics: &Metrics, population: Vec, _children: Vec, ) -> Vec { diff --git a/examples/jssp/problem/selection.rs b/examples/jssp/problem/selection.rs index 498a0e7..f1ad7d3 100644 --- a/examples/jssp/problem/selection.rs +++ b/examples/jssp/problem/selection.rs @@ -13,7 +13,7 @@ impl EmptySelection { impl SelectionOperator for EmptySelection { fn apply<'a>( &mut self, - _metadata: &ecrs::ga::Metrics, + _metrics: &ecrs::ga::Metrics, _population: &'a [JsspIndividual], _count: usize, ) -> Vec<&'a JsspIndividual> { diff --git a/src/ga.rs b/src/ga.rs index 465d4a0..47b7400 100644 --- a/src/ga.rs +++ b/src/ga.rs @@ -223,7 +223,7 @@ where ProbeT: Probe, { config: GAConfig, - metadata: Metrics, + metrics: Metrics, timer: Timer, } @@ -244,7 +244,7 @@ where ) -> Self { GeneticSolver { config, - metadata: Metrics::new(None, None, 0), + metrics: Metrics::new(None, None, 0), timer: Timer::new(), } } @@ -270,60 +270,60 @@ where } pub fn run(&mut self) -> Option { - self.metadata.start_time = Some(std::time::Instant::now()); - self.config.probe.on_start(&self.metadata); + self.metrics.start_time = Some(std::time::Instant::now()); + self.config.probe.on_start(&self.metrics); self.timer.start(); let mut population = self.gen_pop(); - self.metadata.pop_gen_dur = Some(self.timer.elapsed()); + self.metrics.pop_gen_dur = Some(self.timer.elapsed()); self.timer.start(); self.eval_pop(&mut population); - self.metadata.pop_eval_dur = Some(self.timer.elapsed()); + self.metrics.pop_eval_dur = Some(self.timer.elapsed()); self.config .probe - .on_initial_population_created(&self.metadata, &population); + .on_initial_population_created(&self.metrics, &population); let mut best_individual_all_time = Self::find_best_individual(&population).clone(); - self.metadata.total_dur = Some(self.metadata.start_time.unwrap().elapsed()); + self.metrics.total_dur = Some(self.metrics.start_time.unwrap().elapsed()); self.config .probe - .on_new_best(&self.metadata, &best_individual_all_time); + .on_new_best(&self.metrics, &best_individual_all_time); let mut iteration_timer = Timer::new(); for generation_no in 1..=self.config.params.generation_limit { - self.metadata.generation = generation_no; - self.metadata.total_dur = Some(self.metadata.start_time.unwrap().elapsed()); + self.metrics.generation = generation_no; + self.metrics.total_dur = Some(self.metrics.start_time.unwrap().elapsed()); iteration_timer.start(); - self.config.probe.on_iteration_start(&self.metadata); + self.config.probe.on_iteration_start(&self.metrics); // 2. Evaluate fitness for each individual. self.timer.start(); self.eval_pop(&mut population); - self.metadata.pop_eval_dur = Some(self.timer.elapsed()); + self.metrics.pop_eval_dur = Some(self.timer.elapsed()); // 4. Create mating pool by applying selection operator. self.timer.start(); let mating_pool: Vec<&IndividualT> = self.config .selection_operator - .apply(&self.metadata, &population, population.len()); - self.metadata.selection_dur = Some(self.timer.elapsed()); + .apply(&self.metrics, &population, population.len()); + self.metrics.selection_dur = Some(self.timer.elapsed()); // 5. From mating pool create new generation (apply crossover & mutation). self.timer.start(); - let mut children = self.config.crossover_operator.apply(&self.metadata, &mating_pool); - self.metadata.crossover_dur = Some(self.timer.elapsed()); + let mut children = self.config.crossover_operator.apply(&self.metrics, &mating_pool); + self.metrics.crossover_dur = Some(self.timer.elapsed()); self.timer.start(); children .iter_mut() - .for_each(|child| self.config.mutation_operator.apply(&self.metadata, child)); - self.metadata.mutation_dur = Some(self.timer.elapsed()); + .for_each(|child| self.config.mutation_operator.apply(&self.metrics, child)); + self.metrics.mutation_dur = Some(self.timer.elapsed()); if self.config.replacement_operator.requires_children_fitness() { self.eval_pop(&mut children); @@ -334,8 +334,8 @@ where population = self .config .replacement_operator - .apply(&self.metadata, population, children); - self.metadata.replacement_dur = Some(self.timer.elapsed()); + .apply(&self.metrics, population, children); + self.metrics.replacement_dur = Some(self.timer.elapsed()); assert_eq!(population.len(), self.config.params.population_size, "There was change in population size from {} to {} in generation {}. Dynamic population size is currently not supported.", @@ -346,34 +346,34 @@ where // 7. Check for stop condition (Is good enough individual found)? If not goto 2. self.timer.start(); self.eval_pop(&mut population); - self.metadata.pop_eval_dur = Some(self.timer.elapsed()); + self.metrics.pop_eval_dur = Some(self.timer.elapsed()); - self.config.probe.on_new_generation(&self.metadata, &population); + self.config.probe.on_new_generation(&self.metrics, &population); let best_individual = Self::find_best_individual(&population); self.config .probe - .on_best_fit_in_generation(&self.metadata, best_individual); + .on_best_fit_in_generation(&self.metrics, best_individual); if *best_individual < best_individual_all_time { best_individual_all_time = best_individual.clone(); self.config .probe - .on_new_best(&self.metadata, &best_individual_all_time); + .on_new_best(&self.metrics, &best_individual_all_time); } - self.metadata.iteration_dur = Some(iteration_timer.elapsed()); - self.config.probe.on_iteration_end(&self.metadata); + self.metrics.iteration_dur = Some(iteration_timer.elapsed()); + self.config.probe.on_iteration_end(&self.metrics); - if self.metadata.start_time.unwrap().elapsed() >= self.config.params.max_duration { + if self.metrics.start_time.unwrap().elapsed() >= self.config.params.max_duration { break; } } - self.metadata.total_dur = Some(self.metadata.start_time.unwrap().elapsed()); + self.metrics.total_dur = Some(self.metrics.start_time.unwrap().elapsed()); self.config .probe - .on_end(&self.metadata, &population, &best_individual_all_time); + .on_end(&self.metrics, &population, &best_individual_all_time); Some(best_individual_all_time) } } @@ -383,7 +383,7 @@ mod tests { use super::Metrics; #[test] - fn gametadata_can_be_constructed_with_new_fn() { + fn metrics_can_be_constructed_with_new_fn() { Metrics::new(None, None, 0); } } diff --git a/src/ga/operators/crossover.rs b/src/ga/operators/crossover.rs index bd65df2..179f97e 100644 --- a/src/ga/operators/crossover.rs +++ b/src/ga/operators/crossover.rs @@ -14,7 +14,7 @@ pub trait CrossoverOperator { /// FIXME: Understand lifetimes here! // fn apply_iter<'i, InputIter, OutputIter>( // &mut self, - // metadata: &GAMetadata, + // metrics: &Metrics, // selected: InputIter, // ) -> OutputIter // where @@ -26,11 +26,11 @@ pub trait CrossoverOperator { /// /// ## Arguments /// - /// * `metadata` - metadata provided by the GA runtime, + /// * `metrics` - metrics provided by the GA runtime, /// * `selected` - result of running selection operator, /// /// ## Returns /// /// Vector of individuals created during the crossover stage. - fn apply(&mut self, metadata: &Metrics, selected: &[&IndividualT]) -> Vec; + fn apply(&mut self, metrics: &Metrics, selected: &[&IndividualT]) -> Vec; } diff --git a/src/ga/operators/crossover/impls/fixed_point.rs b/src/ga/operators/crossover/impls/fixed_point.rs index 46c3d8c..6cebafa 100644 --- a/src/ga/operators/crossover/impls/fixed_point.rs +++ b/src/ga/operators/crossover/impls/fixed_point.rs @@ -36,7 +36,7 @@ impl FixedPoint { /// * `parent_2` - Second parent to take part in recombination fn apply_single( &mut self, - _metadata: &Metrics, + _metrics: &Metrics, parent_1: &IndividualT, parent_2: &IndividualT, ) -> (IndividualT, IndividualT) @@ -71,15 +71,15 @@ where /// /// ## Arguments /// - /// * `metadata` - algorithm state metadata, see the structure details for more info, + /// * `metrics` - algorithm state metrics, see the structure details for more info, /// * `selected` - references to individuals selected during selection step. - fn apply(&mut self, metadata: &Metrics, selected: &[&IndividualT]) -> Vec { + fn apply(&mut self, metrics: &Metrics, selected: &[&IndividualT]) -> Vec { assert!(selected.len() & 1 == 0); let mut output = Vec::with_capacity(selected.len()); for parents in selected.chunks(2) { - let (child_1, child_2) = self.apply_single(metadata, parents[0], parents[1]); + let (child_1, child_2) = self.apply_single(metrics, parents[0], parents[1]); output.push(child_1); output.push(child_2); } diff --git a/src/ga/operators/crossover/impls/multi_point.rs b/src/ga/operators/crossover/impls/multi_point.rs index aea2388..a572446 100644 --- a/src/ga/operators/crossover/impls/multi_point.rs +++ b/src/ga/operators/crossover/impls/multi_point.rs @@ -64,7 +64,7 @@ impl MultiPoint { /// * `parent_2` - Second parent to take part in recombination fn apply_single( &mut self, - _metadata: &Metrics, + _metrics: &Metrics, parent_1: &IndividualT, parent_2: &IndividualT, ) -> (IndividualT, IndividualT) @@ -134,15 +134,15 @@ where /// /// ## Arguments /// - /// * `metadata` - algorithm state metadata, see the structure details for more info, + /// * `metrics` - algorithm state metrics, see the structure details for more info, /// * `selected` - references to individuals selected during selection step. - fn apply(&mut self, metadata: &Metrics, selected: &[&IndividualT]) -> Vec { + fn apply(&mut self, metrics: &Metrics, selected: &[&IndividualT]) -> Vec { assert!(selected.len() & 1 == 0); let mut output = Vec::with_capacity(selected.len()); for parents in selected.chunks(2) { - let (child_1, child_2) = self.apply_single(metadata, parents[0], parents[1]); + let (child_1, child_2) = self.apply_single(metrics, parents[0], parents[1]); output.push(child_1); output.push(child_2); } diff --git a/src/ga/operators/crossover/impls/ordered.rs b/src/ga/operators/crossover/impls/ordered.rs index e126a21..e14ca9a 100644 --- a/src/ga/operators/crossover/impls/ordered.rs +++ b/src/ga/operators/crossover/impls/ordered.rs @@ -109,7 +109,7 @@ impl OrderedCrossover { /// * `parent_2` - Second parent to take part in crossover fn apply_single( &mut self, - _metadata: &Metrics, + _metrics: &Metrics, parent_1: &IndividualT, parent_2: &IndividualT, ) -> (IndividualT, IndividualT) @@ -161,15 +161,15 @@ where /// /// ## Arguments /// - /// * `metadata` - algorithm state metadata, see the structure details for more info, + /// * `metrics` - algorithm state metrics, see the structure details for more info, /// * `selected` - references to individuals selected during selection step. - fn apply(&mut self, metadata: &Metrics, selected: &[&IndividualT]) -> Vec { + fn apply(&mut self, metrics: &Metrics, selected: &[&IndividualT]) -> Vec { assert!(selected.len() & 1 == 0); let mut output = Vec::with_capacity(selected.len()); for parents in selected.chunks(2) { - let (child_1, child_2) = self.apply_single(metadata, parents[0], parents[1]); + let (child_1, child_2) = self.apply_single(metrics, parents[0], parents[1]); output.push(child_1); output.push(child_2); } diff --git a/src/ga/operators/crossover/impls/pmx.rs b/src/ga/operators/crossover/impls/pmx.rs index ee4f0a3..a679875 100644 --- a/src/ga/operators/crossover/impls/pmx.rs +++ b/src/ga/operators/crossover/impls/pmx.rs @@ -148,7 +148,7 @@ impl Pmx { /// * `parent_2` - Second parent to take part in crossover fn apply_single( &mut self, - _metadata: &Metrics, + _metrics: &Metrics, parent_1: &IndividualT, parent_2: &IndividualT, ) -> (IndividualT, IndividualT) @@ -205,15 +205,15 @@ where /// /// ## Arguments /// - /// * `metadata` - algorithm state metadata, see the structure details for more info, + /// * `metrics` - algorithm state metrics, see the structure details for more info, /// * `selected` - references to individuals selected during selection step. - fn apply(&mut self, metadata: &Metrics, selected: &[&IndividualT]) -> Vec { + fn apply(&mut self, metrics: &Metrics, selected: &[&IndividualT]) -> Vec { assert!(selected.len() & 1 == 0); let mut output = Vec::with_capacity(selected.len()); for parents in selected.chunks(2) { - let (child_1, child_2) = self.apply_single(metadata, parents[0], parents[1]); + let (child_1, child_2) = self.apply_single(metrics, parents[0], parents[1]); output.push(child_1); output.push(child_2); } diff --git a/src/ga/operators/crossover/impls/ppx.rs b/src/ga/operators/crossover/impls/ppx.rs index 0624764..4e6e6cc 100644 --- a/src/ga/operators/crossover/impls/ppx.rs +++ b/src/ga/operators/crossover/impls/ppx.rs @@ -109,7 +109,7 @@ impl Ppx { /// * `parent_2` - one of the parents to take part in crossover fn apply_single( &mut self, - _metadata: &Metrics, + _metrics: &Metrics, parent_1: &IndividualT, parent_2: &IndividualT, ) -> (IndividualT, IndividualT) @@ -164,15 +164,15 @@ where /// /// ## Arguments /// - /// * `metadata` - algorithm state metadata, see the structure details for more info, + /// * `metrics` - algorithm state metrics, see the structure details for more info, /// * `selected` - references to individuals selected during selection step. - fn apply(&mut self, metadata: &Metrics, selected: &[&IndividualT]) -> Vec { + fn apply(&mut self, metrics: &Metrics, selected: &[&IndividualT]) -> Vec { assert!(selected.len() & 1 == 0); let mut output = Vec::with_capacity(selected.len()); for parents in selected.chunks(2) { - let (child_1, child_2) = self.apply_single(metadata, parents[0], parents[1]); + let (child_1, child_2) = self.apply_single(metrics, parents[0], parents[1]); output.push(child_1); output.push(child_2); } diff --git a/src/ga/operators/crossover/impls/shuffle.rs b/src/ga/operators/crossover/impls/shuffle.rs index 3082c66..f206a5e 100644 --- a/src/ga/operators/crossover/impls/shuffle.rs +++ b/src/ga/operators/crossover/impls/shuffle.rs @@ -56,7 +56,7 @@ impl Shuffle { /// * `parent_2` - Second parent to take part in recombination fn apply_single( &mut self, - _metadata: &Metrics, + _metrics: &Metrics, parent_1: &IndividualT, parent_2: &IndividualT, ) -> (IndividualT, IndividualT) @@ -109,15 +109,15 @@ where /// /// ## Arguments /// - /// * `metadata` - algorithm state metadata, see the structure details for more info, + /// * `metrics` - algorithm state metrics, see the structure details for more info, /// * `selected` - references to individuals selected during selection step. - fn apply(&mut self, metadata: &Metrics, selected: &[&IndividualT]) -> Vec { + fn apply(&mut self, metrics: &Metrics, selected: &[&IndividualT]) -> Vec { assert!(selected.len() & 1 == 0); let mut output = Vec::with_capacity(selected.len()); for parents in selected.chunks(2) { - let (child_1, child_2) = self.apply_single(metadata, parents[0], parents[1]); + let (child_1, child_2) = self.apply_single(metrics, parents[0], parents[1]); output.push(child_1); output.push(child_2); } diff --git a/src/ga/operators/crossover/impls/single_point.rs b/src/ga/operators/crossover/impls/single_point.rs index 76f51d8..1c59b87 100644 --- a/src/ga/operators/crossover/impls/single_point.rs +++ b/src/ga/operators/crossover/impls/single_point.rs @@ -51,7 +51,7 @@ impl SinglePoint { /// * `parent_2` - Second parent to take part in recombination fn apply_single( &mut self, - _metadata: &Metrics, + _metrics: &Metrics, parent_1: &IndividualT, parent_2: &IndividualT, ) -> (IndividualT, IndividualT) @@ -98,15 +98,15 @@ where /// /// ## Arguments /// - /// * `metadata` - algorithm state metadata, see the structure details for more info, + /// * `metrics` - algorithm state metrics, see the structure details for more info, /// * `selected` - references to individuals selected during selection step. - fn apply(&mut self, metadata: &Metrics, selected: &[&IndividualT]) -> Vec { + fn apply(&mut self, metrics: &Metrics, selected: &[&IndividualT]) -> Vec { assert!(selected.len() & 1 == 0); let mut output = Vec::with_capacity(selected.len()); for parents in selected.chunks(2) { - let (child_1, child_2) = self.apply_single(metadata, parents[0], parents[1]); + let (child_1, child_2) = self.apply_single(metrics, parents[0], parents[1]); output.push(child_1); output.push(child_2); } diff --git a/src/ga/operators/crossover/impls/two_point.rs b/src/ga/operators/crossover/impls/two_point.rs index f7c469d..66eae79 100644 --- a/src/ga/operators/crossover/impls/two_point.rs +++ b/src/ga/operators/crossover/impls/two_point.rs @@ -52,7 +52,7 @@ impl TwoPoint { /// * `parent_2` - Second parent to take part in recombination fn apply_single( &mut self, - _metadata: &Metrics, + _metrics: &Metrics, parent_1: &IndividualT, parent_2: &IndividualT, ) -> (IndividualT, IndividualT) @@ -120,15 +120,15 @@ where /// /// ## Arguments /// - /// * `metadata` - algorithm state metadata, see the structure details for more info, + /// * `metrics` - algorithm state metrics, see the structure details for more info, /// * `selected` - references to individuals selected during selection step. - fn apply(&mut self, metadata: &Metrics, selected: &[&IndividualT]) -> Vec { + fn apply(&mut self, metrics: &Metrics, selected: &[&IndividualT]) -> Vec { assert!(selected.len() & 1 == 0); let mut output = Vec::with_capacity(selected.len()); for parents in selected.chunks(2) { - let (child_1, child_2) = self.apply_single(metadata, parents[0], parents[1]); + let (child_1, child_2) = self.apply_single(metrics, parents[0], parents[1]); output.push(child_1); output.push(child_2); } diff --git a/src/ga/operators/crossover/impls/uniform.rs b/src/ga/operators/crossover/impls/uniform.rs index ca275cb..11915f2 100644 --- a/src/ga/operators/crossover/impls/uniform.rs +++ b/src/ga/operators/crossover/impls/uniform.rs @@ -49,7 +49,7 @@ where /// * `parent_2` - Second parent to take part in recombination fn apply_single( &mut self, - _metadata: &Metrics, + _metrics: &Metrics, parent_1: &IndividualT, parent_2: &IndividualT, ) -> (IndividualT, IndividualT) @@ -104,15 +104,15 @@ where /// /// ## Arguments /// - /// * `metadata` - algorithm state metadata, see the structure details for more info, + /// * `metrics` - algorithm state metrics, see the structure details for more info, /// * `selected` - references to individuals selected during selection step. - fn apply(&mut self, metadata: &Metrics, selected: &[&IndividualT]) -> Vec { + fn apply(&mut self, metrics: &Metrics, selected: &[&IndividualT]) -> Vec { assert!(selected.len() & 1 == 0); let mut output = Vec::with_capacity(selected.len()); for parents in selected.chunks(2) { - let (child_1, child_2) = self.apply_single(metadata, parents[0], parents[1]); + let (child_1, child_2) = self.apply_single(metrics, parents[0], parents[1]); output.push(child_1); output.push(child_2); } diff --git a/src/ga/operators/crossover/impls/uniform_parameterized.rs b/src/ga/operators/crossover/impls/uniform_parameterized.rs index cbbd312..239ec57 100644 --- a/src/ga/operators/crossover/impls/uniform_parameterized.rs +++ b/src/ga/operators/crossover/impls/uniform_parameterized.rs @@ -55,7 +55,7 @@ where /// * `parent_2` - Second parent to take part in recombination fn apply_single( &mut self, - _metadata: &Metrics, + _metrics: &Metrics, parent_1: &IndividualT, parent_2: &IndividualT, ) -> (IndividualT, IndividualT) @@ -106,15 +106,15 @@ where /// /// ## Arguments /// - /// * `metadata` - algorithm state metadata, see the structure details for more info, + /// * `metrics` - algorithm state metrics, see the structure details for more info, /// * `selected` - references to individuals selected during selection step. - fn apply(&mut self, metadata: &Metrics, selected: &[&IndividualT]) -> Vec { + fn apply(&mut self, metrics: &Metrics, selected: &[&IndividualT]) -> Vec { assert!(selected.len() & 1 == 0); let mut output = Vec::with_capacity(selected.len()); for parents in selected.chunks(2) { - let (child_1, child_2) = self.apply_single(metadata, parents[0], parents[1]); + let (child_1, child_2) = self.apply_single(metrics, parents[0], parents[1]); output.push(child_1); output.push(child_2); } diff --git a/src/ga/operators/mutation.rs b/src/ga/operators/mutation.rs index cbd58e1..e762043 100644 --- a/src/ga/operators/mutation.rs +++ b/src/ga/operators/mutation.rs @@ -15,5 +15,5 @@ pub trait MutationOperator { /// ## Arguments /// /// * `individual` - mutable reference to to-be-mutated individual - fn apply(&mut self, metadata: &Metrics, individual: &mut IndividualT); + fn apply(&mut self, metrics: &Metrics, individual: &mut IndividualT); } diff --git a/src/ga/operators/mutation/impls.rs b/src/ga/operators/mutation/impls.rs index 66718b9..d83b9bb 100644 --- a/src/ga/operators/mutation/impls.rs +++ b/src/ga/operators/mutation/impls.rs @@ -24,7 +24,7 @@ impl Identity { } impl MutationOperator for Identity { - fn apply(&mut self, _metadata: &Metrics, _individual: &mut IndividualT) {} + fn apply(&mut self, _metrics: &Metrics, _individual: &mut IndividualT) {} } /// ### Flilp bit mutation operator @@ -67,7 +67,7 @@ where /// /// * `individual` - mutable reference to to-be-mutated individual /// * `mutation_rate` - probability of gene mutation - fn apply(&mut self, _metadata: &Metrics, individual: &mut IndividualT) { + fn apply(&mut self, _metrics: &Metrics, individual: &mut IndividualT) { let distribution = rand::distributions::Uniform::from(0.0..1.0); let chromosome_ref = individual.chromosome_mut(); let chromosome_len = chromosome_ref.len(); @@ -120,7 +120,7 @@ where /// ## Arguments /// /// * `individual` - mutable reference to to-be-mutated individual - fn apply(&mut self, _metadata: &Metrics, individual: &mut IndividualT) { + fn apply(&mut self, _metrics: &Metrics, individual: &mut IndividualT) { let chromosome_ref = individual.chromosome_mut(); let chromosome_len = chromosome_ref.len(); @@ -178,7 +178,7 @@ where /// ## Arguments /// /// * `individual` - mutable reference to to-be-mutated individual - fn apply(&mut self, _metadata: &Metrics, individual: &mut IndividualT) { + fn apply(&mut self, _metrics: &Metrics, individual: &mut IndividualT) { let dist = rand::distributions::Uniform::from(0.0..1.0); let chromosome_ref = individual.chromosome_mut(); let chromosome_len = chromosome_ref.len(); @@ -237,7 +237,7 @@ where /// ## Arguments /// /// * `individual` - mutable reference to to-be-mutated individual - fn apply(&mut self, _metadata: &Metrics, individual: &mut IndividualT) { + fn apply(&mut self, _metrics: &Metrics, individual: &mut IndividualT) { let _marker: PhantomData = PhantomData; let r: f64 = self.rng.gen(); diff --git a/src/ga/operators/replacement.rs b/src/ga/operators/replacement.rs index 7238c88..ea6db0f 100644 --- a/src/ga/operators/replacement.rs +++ b/src/ga/operators/replacement.rs @@ -36,7 +36,7 @@ pub trait ReplacementOperator { /// * `children` - Result of the crossover phase. fn apply( &mut self, - metadata: &Metrics, + metrics: &Metrics, population: Vec, children: Vec, ) -> Vec; diff --git a/src/ga/operators/replacement/impls.rs b/src/ga/operators/replacement/impls.rs index 72fc262..f4a3747 100644 --- a/src/ga/operators/replacement/impls.rs +++ b/src/ga/operators/replacement/impls.rs @@ -38,7 +38,7 @@ impl ReplacementOperator for BothPare #[inline(always)] fn apply( &mut self, - _metadata: &Metrics, + _metrics: &Metrics, _population: Vec, children: Vec, ) -> Vec { @@ -73,7 +73,7 @@ impl ReplacementOperator for Noop { #[inline(always)] fn apply( &mut self, - _metadata: &Metrics, + _metrics: &Metrics, population: Vec, _children: Vec, ) -> Vec { @@ -141,7 +141,7 @@ impl ReplacementOperator for WeakPare /// * `children` - Result of the crossover phase fn apply( &mut self, - _metadata: &Metrics, + _metrics: &Metrics, mut population: Vec, mut children: Vec, ) -> Vec { diff --git a/src/ga/operators/selection/impls.rs b/src/ga/operators/selection/impls.rs index b0972c7..a977197 100644 --- a/src/ga/operators/selection/impls.rs +++ b/src/ga/operators/selection/impls.rs @@ -58,12 +58,12 @@ where /// /// ### Arguments /// - /// * `metadata` - [crate::ga::GAMetadata] information on current stage of the algorithm (iteration, elapsed time, etc.) + /// * `metrics` - [crate::ga::Metrics] information on current stage of the algorithm (iteration, elapsed time, etc.) /// * `population` - individuals to choose mating pool from /// * `count` - target number of individuals in mating pool fn apply<'a>( &mut self, - _metadata: &Metrics, + _metrics: &Metrics, population: &'a [IndividualT], count: usize, ) -> Vec<&'a IndividualT> { @@ -122,12 +122,12 @@ impl SelectionOperator for Ra /// /// ### Arguments /// - /// * `metadata` - [crate::ga::GAMetadata] information on current stage of the algorithm (iteration, elapsed time, etc.) + /// * `metrics` - [crate::ga::Metrics] information on current stage of the algorithm (iteration, elapsed time, etc.) /// * `population` - individuals to choose mating pool from /// * `count` - target number of individuals in mating pool fn apply<'a>( &mut self, - _metadata: &Metrics, + _metrics: &Metrics, population: &'a [IndividualT], count: usize, ) -> Vec<&'a IndividualT> { @@ -181,12 +181,12 @@ where /// /// ### Arguments /// - /// * `metadata` - [crate::ga::GAMetadata] information on current stage of the algorithm (iteration, elapsed time, etc.) + /// * `metrics` - [crate::ga::Metrics] information on current stage of the algorithm (iteration, elapsed time, etc.) /// * `population` - individuals to choose mating pool from /// * `count` - target number of individuals in mating pool fn apply<'a>( &mut self, - _metadata: &Metrics, + _metrics: &Metrics, population: &'a [IndividualT], count: usize, ) -> Vec<&'a IndividualT> { @@ -261,12 +261,12 @@ impl SelectionOperator for Ra /// /// ### Arguments /// - /// * `metadata` - [crate::ga::GAMetadata] information on current stage of the algorithm (iteration, elapsed time, etc.) + /// * `metrics` - [crate::ga::Metrics] information on current stage of the algorithm (iteration, elapsed time, etc.) /// * `population` - individuals to choose mating pool from /// * `count` - target number of individuals in mating pool fn apply<'a>( &mut self, - _metadata: &Metrics, + _metrics: &Metrics, population: &'a [IndividualT], count: usize, ) -> Vec<&'a IndividualT> { @@ -343,12 +343,12 @@ impl SelectionOperator for To /// /// ### Arguments /// - /// * `metadata` - [crate::ga::GAMetadata] information on current stage of the algorithm (iteration, elapsed time, etc.) + /// * `metrics` - [crate::ga::Metrics] information on current stage of the algorithm (iteration, elapsed time, etc.) /// * `population` - individuals to choose mating pool from /// * `count` - target number of individuals in mating pool fn apply<'a>( &mut self, - _metadata: &Metrics, + _metrics: &Metrics, population: &'a [IndividualT], count: usize, ) -> Vec<&'a IndividualT> { @@ -439,12 +439,12 @@ impl, R: Rng> SelectionOperato /// /// ### Arguments /// - /// * `metadata` - [crate::ga::GAMetadata] information on current stage of the algorithm (iteration, elapsed time, etc.) + /// * `metrics` - [crate::ga::Metrics] information on current stage of the algorithm (iteration, elapsed time, etc.) /// * `population` - individuals to choose mating pool from /// * `count` - target number of individuals in mating pool fn apply<'a>( &mut self, - _metadata: &Metrics, + _metrics: &Metrics, population: &'a [IndividualT], count: usize, ) -> Vec<&'a IndividualT> { @@ -538,14 +538,14 @@ where { fn apply<'a>( &mut self, - metadata: &Metrics, + metrics: &Metrics, population: &'a [IndividualT], count: usize, ) -> Vec<&'a IndividualT> { let mut selected: Vec<&IndividualT> = Vec::with_capacity(count); let mut weights: Vec = Vec::with_capacity(count); - let k = 1.0 + 100.0 * (metadata.generation as f64) / (self.max_gen_count as f64); + let k = 1.0 + 100.0 * (metrics.generation as f64) / (self.max_gen_count as f64); let temp = self.temp_0 * (1.0 - self.alpha).powf(k); for idv in population { diff --git a/src/ga/probe.rs b/src/ga/probe.rs index 6266120..c4f9cd5 100644 --- a/src/ga/probe.rs +++ b/src/ga/probe.rs @@ -27,10 +27,10 @@ pub trait Probe { /// /// ### Arguments /// - /// * `metadata` - Structure containing metadata information on genetic algorithm. - /// See [GAMetadata] for reference. When running this method only `start_time` + /// * `metrics` - Structure containing metrics information on genetic algorithm. + /// See [Metrics] for reference. When running this method only `start_time` /// field has meaningful value. - fn on_start(&mut self, _metadata: &Metrics) { /* defaults to noop */ + fn on_start(&mut self, _metrics: &Metrics) { /* defaults to noop */ } /// This method is called directly after initial populationn is created and fitness @@ -41,7 +41,7 @@ pub trait Probe { /// ### Arguments /// /// * `population` - Freshly generated population - fn on_initial_population_created(&mut self, _metadata: &Metrics, _population: &[IndividualT]) { + fn on_initial_population_created(&mut self, _metrics: &Metrics, _population: &[IndividualT]) { /* defaults to noop */ } @@ -51,10 +51,10 @@ pub trait Probe { /// /// ### Arguments /// - /// * `metadata` - Structure containing metadata information on genetic algorithm. - /// See [GAMetadata] for reference. + /// * `metrics` - Structure containing metrics information on genetic algorithm. + /// See [Metrics] for reference. /// * `individual` - New best individual - fn on_new_best(&mut self, _metadata: &Metrics, _individual: &IndividualT) { + fn on_new_best(&mut self, _metrics: &Metrics, _individual: &IndividualT) { /* defaults to noop */ } @@ -64,10 +64,10 @@ pub trait Probe { /// /// ### Arguments /// - /// * `metadata` - Structure containing metadata information on genetic algorithm. - /// See [GAMetadata] for reference. + /// * `metrics` - Structure containing metrics information on genetic algorithm. + /// See [Metrics] for reference. /// * `generation` - Newly created generation - fn on_new_generation(&mut self, _metadata: &Metrics, _generation: &[IndividualT]) { + fn on_new_generation(&mut self, _metrics: &Metrics, _generation: &[IndividualT]) { /* defaults to noop */ } @@ -77,10 +77,10 @@ pub trait Probe { /// /// ### Arguments /// - /// * `metadata` - Structure containing metadata information on genetic algorithm. - /// See [GAMetadata] for reference. + /// * `metrics` - Structure containing metrics information on genetic algorithm. + /// See [Metrics] for reference. /// * `individual` - Best individual in current generation - fn on_best_fit_in_generation(&mut self, _metadata: &Metrics, _individual: &IndividualT) { + fn on_best_fit_in_generation(&mut self, _metrics: &Metrics, _individual: &IndividualT) { /* defaults to noop */ } @@ -90,9 +90,9 @@ pub trait Probe { /// /// ### Arguments /// - /// * `metadata` - Structure containing metadata information on genetic algorithm. - /// See [GAMetadata] for reference. - fn on_iteration_start(&mut self, _metadata: &Metrics) { /* defaults to noop */ + /// * `metrics` - Structure containing metrics information on genetic algorithm. + /// See [Metrics] for reference. + fn on_iteration_start(&mut self, _metrics: &Metrics) { /* defaults to noop */ } /// This method is called in the very end of algorithm's main loop, just before @@ -100,9 +100,9 @@ pub trait Probe { /// /// ### Arguments /// - /// * `metadata` - Structure containing metadata information on genetic algorithm. - /// See [GAMetadata] for reference. - fn on_iteration_end(&mut self, _metadata: &Metrics) { /* defaults to noop */ + /// * `metrics` - Structure containing metrics information on genetic algorithm. + /// See [Metrics] for reference. + fn on_iteration_end(&mut self, _metrics: &Metrics) { /* defaults to noop */ } /// This method is called after algorithm 's main loop is exited, just before the `run` @@ -112,11 +112,11 @@ pub trait Probe { /// /// ### Arguments /// - /// * `metadata` - Structure containing metadata information on genetic algorithm. - /// See [GAMetadata] for reference. + /// * `metrics` - Structure containing metrics information on genetic algorithm. + /// See [Metrics] for reference. /// * `population` - Final population /// * `best_individual` - Best individual found by algorithm - fn on_end(&mut self, _metadata: &Metrics, _population: &[IndividualT], _best_individual: &IndividualT) { + fn on_end(&mut self, _metrics: &Metrics, _population: &[IndividualT], _best_individual: &IndividualT) { /* defaults to noop */ } } @@ -135,48 +135,48 @@ pub trait Probe { /// /// ``` /// # use ecrs::ga::individual::IndividualTrait; -/// # use ecrs::ga::GAMetadata; +/// # use ecrs::ga::Metrics; /// # use ecrs::ga::probe::ProbingPolicy; /// /// struct EvenIteration; /// /// impl ProbingPolicy for EvenIteration { -/// fn on_start(&mut self, _metadata: &GAMetadata) -> bool { +/// fn on_start(&mut self, _metrics: &Metrics) -> bool { /// // We want to always log on start /// true /// } /// -/// fn on_initial_population_created(&mut self, _metadata: &GAMetadata, _population: &[IndividualT]) -> bool { +/// fn on_initial_population_created(&mut self, _metrics: &Metrics, _population: &[IndividualT]) -> bool { /// // We want to log initial population /// true /// } /// -/// fn on_new_best(&mut self, _metadata: &GAMetadata, _individual: &IndividualT) -> bool { +/// fn on_new_best(&mut self, _metrics: &Metrics, _individual: &IndividualT) -> bool { /// // We want to see when algorithm improves /// true /// } /// -/// fn on_new_generation(&mut self, metadata: &GAMetadata, _generation: &[IndividualT]) -> bool { +/// fn on_new_generation(&mut self, metrics: &Metrics, _generation: &[IndividualT]) -> bool { /// // Only on even iterations -/// metadata.generation % 2 == 0 +/// metrics.generation % 2 == 0 /// } /// -/// fn on_best_fit_in_generation(&mut self, metadata: &GAMetadata, _individual: &IndividualT) -> bool { +/// fn on_best_fit_in_generation(&mut self, metrics: &Metrics, _individual: &IndividualT) -> bool { /// // Only on even iterations -/// metadata.generation % 2 == 0 +/// metrics.generation % 2 == 0 /// } /// -/// fn on_iteration_start(&mut self, metadata: &GAMetadata) -> bool { -/// metadata.generation % 2 == 0 +/// fn on_iteration_start(&mut self, metrics: &Metrics) -> bool { +/// metrics.generation % 2 == 0 /// } /// -/// fn on_iteration_end(&mut self, metadata: &GAMetadata) -> bool { -/// metadata.generation % 2 == 0 +/// fn on_iteration_end(&mut self, metrics: &Metrics) -> bool { +/// metrics.generation % 2 == 0 /// } /// /// fn on_end( /// &mut self, -/// _metadata: &GAMetadata, +/// _metrics: &Metrics, /// _population: &[IndividualT], /// _best_individual: &IndividualT, /// ) -> bool { @@ -188,16 +188,16 @@ pub trait Probe { /// /// Later you can use it with [PolicyDrivenProbe] pub trait ProbingPolicy { - fn on_start(&mut self, _metadata: &Metrics) -> bool; - fn on_initial_population_created(&mut self, _metadata: &Metrics, _population: &[IndividualT]) -> bool; - fn on_new_best(&mut self, _metadata: &Metrics, _individual: &IndividualT) -> bool; - fn on_new_generation(&mut self, _metadata: &Metrics, _generation: &[IndividualT]) -> bool; - fn on_best_fit_in_generation(&mut self, _metadata: &Metrics, _individual: &IndividualT) -> bool; - fn on_iteration_start(&mut self, _metadata: &Metrics) -> bool; - fn on_iteration_end(&mut self, _metadata: &Metrics) -> bool; + fn on_start(&mut self, _metrics: &Metrics) -> bool; + fn on_initial_population_created(&mut self, _metrics: &Metrics, _population: &[IndividualT]) -> bool; + fn on_new_best(&mut self, _metrics: &Metrics, _individual: &IndividualT) -> bool; + fn on_new_generation(&mut self, _metrics: &Metrics, _generation: &[IndividualT]) -> bool; + fn on_best_fit_in_generation(&mut self, _metrics: &Metrics, _individual: &IndividualT) -> bool; + fn on_iteration_start(&mut self, _metrics: &Metrics) -> bool; + fn on_iteration_end(&mut self, _metrics: &Metrics) -> bool; fn on_end( &mut self, - _metadata: &Metrics, + _metrics: &Metrics, _population: &[IndividualT], _best_individual: &IndividualT, ) -> bool; diff --git a/src/ga/probe/aggregated_probe.rs b/src/ga/probe/aggregated_probe.rs index e015de1..a728986 100644 --- a/src/ga/probe/aggregated_probe.rs +++ b/src/ga/probe/aggregated_probe.rs @@ -46,12 +46,12 @@ impl Probe for AggregatedProbe Probe for AggregatedProbe Probe for AggregatedProbe Probe for AggregatedProbe Probe for AggregatedProbe Probe for AggregatedProbe Probe for AggregatedProbe Probe for AggregatedProbe, Pr: Probe, Pr: Probe, Pr: Probe, Pr: Probe, Pr: Probe, Pr: Probe, Pr: Probe, Pr: Probe ProbingPolicy for GenerationInterval { #[inline(always)] - fn on_start(&mut self, _metadata: &crate::ga::Metrics) -> bool { + fn on_start(&mut self, _metrics: &crate::ga::Metrics) -> bool { true } #[inline(always)] - fn on_initial_population_created(&mut self, _metadata: &Metrics, _population: &[IndividualT]) -> bool { + fn on_initial_population_created(&mut self, _metrics: &Metrics, _population: &[IndividualT]) -> bool { true } #[inline(always)] - fn on_new_best(&mut self, _metadata: &crate::ga::Metrics, _individual: &IndividualT) -> bool { + fn on_new_best(&mut self, _metrics: &crate::ga::Metrics, _individual: &IndividualT) -> bool { true } #[inline(always)] - fn on_new_generation(&mut self, _metadata: &Metrics, _generation: &[IndividualT]) -> bool { + fn on_new_generation(&mut self, _metrics: &Metrics, _generation: &[IndividualT]) -> bool { self.should_log } #[inline(always)] fn on_best_fit_in_generation( &mut self, - _metadata: &crate::ga::Metrics, + _metrics: &crate::ga::Metrics, _individual: &IndividualT, ) -> bool { self.should_log } #[inline] - fn on_iteration_start(&mut self, metadata: &Metrics) -> bool { - if metadata.generation >= self.threshold { + fn on_iteration_start(&mut self, metrics: &Metrics) -> bool { + if metrics.generation >= self.threshold { self.threshold += self.interval; self.should_log = true; true @@ -68,7 +68,7 @@ impl ProbingPolicy for GenerationInte } #[inline(always)] - fn on_iteration_end(&mut self, _metadata: &Metrics) -> bool { + fn on_iteration_end(&mut self, _metrics: &Metrics) -> bool { let prev = self.should_log; self.should_log = false; prev @@ -77,7 +77,7 @@ impl ProbingPolicy for GenerationInte #[inline(always)] fn on_end( &mut self, - _metadata: &crate::ga::Metrics, + _metrics: &crate::ga::Metrics, _population: &[IndividualT], _best_individual: &IndividualT, ) -> bool { @@ -109,36 +109,36 @@ impl ElapsedTime { impl ProbingPolicy for ElapsedTime { #[inline(always)] - fn on_start(&mut self, _metadata: &crate::ga::Metrics) -> bool { + fn on_start(&mut self, _metrics: &crate::ga::Metrics) -> bool { true } #[inline(always)] - fn on_initial_population_created(&mut self, _metadata: &Metrics, _population: &[IndividualT]) -> bool { + fn on_initial_population_created(&mut self, _metrics: &Metrics, _population: &[IndividualT]) -> bool { true } #[inline(always)] - fn on_new_best(&mut self, _metadata: &crate::ga::Metrics, _individual: &IndividualT) -> bool { + fn on_new_best(&mut self, _metrics: &crate::ga::Metrics, _individual: &IndividualT) -> bool { true } #[inline(always)] - fn on_new_generation(&mut self, _metadata: &Metrics, _generation: &[IndividualT]) -> bool { + fn on_new_generation(&mut self, _metrics: &Metrics, _generation: &[IndividualT]) -> bool { self.should_log } #[inline(always)] fn on_best_fit_in_generation( &mut self, - _metadata: &crate::ga::Metrics, + _metrics: &crate::ga::Metrics, _individual: &IndividualT, ) -> bool { self.should_log } - fn on_iteration_start(&mut self, metadata: &Metrics) -> bool { - if metadata.total_dur.unwrap() >= self.threshold { + fn on_iteration_start(&mut self, metrics: &Metrics) -> bool { + if metrics.total_dur.unwrap() >= self.threshold { self.should_log = true; self.threshold += self.interval; true @@ -148,7 +148,7 @@ impl ProbingPolicy for ElapsedTime { } #[inline] - fn on_iteration_end(&mut self, _metadata: &Metrics) -> bool { + fn on_iteration_end(&mut self, _metrics: &Metrics) -> bool { let prev = self.should_log; self.should_log = false; prev @@ -157,7 +157,7 @@ impl ProbingPolicy for ElapsedTime { #[inline(always)] fn on_end( &mut self, - _metadata: &crate::ga::Metrics, + _metrics: &crate::ga::Metrics, _population: &[IndividualT], _best_individual: &IndividualT, ) -> bool { diff --git a/src/ga/probe/stdout_probe.rs b/src/ga/probe/stdout_probe.rs index 2e5c3e9..1d93e17 100644 --- a/src/ga/probe/stdout_probe.rs +++ b/src/ga/probe/stdout_probe.rs @@ -11,44 +11,44 @@ impl StdoutProbe { } impl Probe for StdoutProbe { - fn on_start(&mut self, _metadata: &Metrics) { + fn on_start(&mut self, _metrics: &Metrics) { info!("[START] time,generation,chromosome,fitness"); } - fn on_new_best(&mut self, metadata: &Metrics, individual: &IndividualT) { + fn on_new_best(&mut self, metrics: &Metrics, individual: &IndividualT) { info!( "[NEW_BEST] {},{},{:?},{}", - metadata + metrics .total_dur .unwrap_or(std::time::Duration::from_millis(0)) .as_millis(), - metadata.generation, + metrics.generation, individual.chromosome(), individual.fitness() ); } - fn on_new_generation(&mut self, _metadata: &Metrics, _generation: &[IndividualT]) { + fn on_new_generation(&mut self, _metrics: &Metrics, _generation: &[IndividualT]) { // TODO: Take reference to whole generation as a parameter and display it here! // We don't want to print anything on new generation right now } - fn on_best_fit_in_generation(&mut self, metadata: &Metrics, individual: &IndividualT) { + fn on_best_fit_in_generation(&mut self, metrics: &Metrics, individual: &IndividualT) { // TODO: Take reference to the best chromosome & display it here! info!( "[BEST_IN_GEN] {},{},{:?},{}", - metadata.total_dur.unwrap().as_millis(), - metadata.generation, + metrics.total_dur.unwrap().as_millis(), + metrics.generation, individual.chromosome(), individual.fitness() ); } - fn on_end(&mut self, metadata: &Metrics, _population: &[IndividualT], best_individual: &IndividualT) { + fn on_end(&mut self, metrics: &Metrics, _population: &[IndividualT], best_individual: &IndividualT) { info!( "[END] {},{},{:?},{}", - metadata.total_dur.unwrap().as_millis(), - metadata.generation, + metrics.total_dur.unwrap().as_millis(), + metrics.generation, best_individual.chromosome(), best_individual.fitness() ); diff --git a/tests/selection_tests.rs b/tests/selection_tests.rs index a99cdd1..173e4eb 100644 --- a/tests/selection_tests.rs +++ b/tests/selection_tests.rs @@ -22,11 +22,11 @@ fn random_selection_returns_demanded_size() { ); // FIXME: We must add mocking! - let metadata = Metrics::default(); + let metrics = Metrics::default(); let expected_selection_size = expected_population_size / 2; - let selected = Random::new().apply(&metadata, &population, expected_selection_size); + let selected = Random::new().apply(&metrics, &population, expected_selection_size); assert_eq!( expected_selection_size, @@ -47,11 +47,11 @@ fn roulette_whell_returns_demanded_size() { ); // FIXME: We must add mocking! - let metadata = Metrics::default(); + let metrics = Metrics::default(); let expected_selection_size = expected_population_size / 2; - let selected = RouletteWheel::new().apply(&metadata, &population, expected_selection_size); + let selected = RouletteWheel::new().apply(&metrics, &population, expected_selection_size); assert_eq!( expected_selection_size, @@ -72,11 +72,11 @@ fn rank_returns_demanded_size() { ); // FIXME: We must add mocking! - let metadata = Metrics::default(); + let metrics = Metrics::default(); let expected_selection_size = expected_population_size / 2; - let selected = Rank::new().apply(&metadata, &population, expected_selection_size); + let selected = Rank::new().apply(&metrics, &population, expected_selection_size); assert_eq!( expected_selection_size, @@ -97,11 +97,11 @@ fn rankr_returns_demanded_size() { ); // FIXME: We must add mocking! - let metadata = Metrics::default(); + let metrics = Metrics::default(); let expected_selection_size = expected_population_size / 2; - let selected = RankR::new(0.5).apply(&metadata, &population, expected_selection_size); + let selected = RankR::new(0.5).apply(&metrics, &population, expected_selection_size); assert_eq!( expected_selection_size, @@ -122,11 +122,11 @@ fn tournament_returns_demanded_size() { ); // FIXME: We must add mocking! - let metadata = Metrics::default(); + let metrics = Metrics::default(); let expected_selection_size = expected_population_size / 2; - let selected = Tournament::new(0.2).apply(&metadata, &population, expected_selection_size); + let selected = Tournament::new(0.2).apply(&metrics, &population, expected_selection_size); assert_eq!( expected_selection_size, @@ -152,11 +152,11 @@ fn sus_returns_demanded_size_when_fitness_positive() { ); // FIXME: We must add mocking! - let metadata = Metrics::default(); + let metrics = Metrics::default(); let expected_selection_size = expected_population_size / 2; - let selected = StochasticUniversalSampling::new().apply(&metadata, &population, expected_selection_size); + let selected = StochasticUniversalSampling::new().apply(&metrics, &population, expected_selection_size); assert_eq!( expected_selection_size, @@ -186,9 +186,9 @@ fn boltzmann_returns_demanded_size() { ); // FIXME: We must add mocking! - let metadata = Metrics::new(Some(std::time::Instant::now()), None, 40); + let metrics = Metrics::new(Some(std::time::Instant::now()), None, 40); - let selected = Boltzmann::new(0.2, 6.0, 300, true).apply(&metadata, &population, expected_selection_size); + let selected = Boltzmann::new(0.2, 6.0, 300, true).apply(&metrics, &population, expected_selection_size); assert_eq!( expected_selection_size,