Skip to content

Commit

Permalink
Fix fmt and clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
HeleNoir committed May 28, 2024
1 parent 4a042da commit d000da9
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 36 deletions.
8 changes: 5 additions & 3 deletions src/components/archive.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
//! Archive for specified parts of population.
use better_any::{Tid, TidAble};

use serde::{Deserialize, Serialize};
use std::cell::Ref;

use crate::{
component::ExecResult, components::Component, problems::SingleObjectiveProblem,
state::StateReq, CustomState, Individual, Problem, State,
};
use better_any::{Tid, TidAble};
use serde::{Deserialize, Serialize};
use std::cell::Ref;

/// An archive for storing elitist individuals.
#[derive(Default, Tid)]
Expand Down
20 changes: 12 additions & 8 deletions src/components/measures/convergence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,21 @@
//! Artif Intell Rev 54, 2323–2409 (2021).
//! DOI: <https://doi.org/10.1007/s10462-020-09906-6>
use crate::component::AnyComponent;
use crate::components::archive;
use crate::lens::{AnyLens, Lens, LensMap};
use crate::logging::extractor::{EntryExtractor, EntryName};
use crate::problems::{KnownOptimumProblem, VectorProblem};
use crate::utils::SerializablePhantom;
use crate::{Component, CustomState, ExecResult, Problem, SingleObjectiveProblem, State};
use std::{any::type_name, marker::PhantomData};

use better_any::{Tid, TidAble};
use derivative::Derivative;
use serde::Serialize;
use std::{any::type_name, marker::PhantomData};

use crate::{
component::AnyComponent,
components::archive,
lens::{AnyLens, Lens, LensMap},
logging::extractor::{EntryExtractor, EntryName},
problems::{KnownOptimumProblem, VectorProblem},
utils::SerializablePhantom,
Component, CustomState, ExecResult, Problem, SingleObjectiveProblem, State,
};

/// Trait for representing a component that measures the convergence rate.
pub trait ConvergenceRateMeasure<P: Problem>: AnyComponent {
Expand Down
27 changes: 14 additions & 13 deletions src/components/measures/improvement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@
//! On the analysis, classification and prediction of metaheuristic algorithm behavior for combinatorial optimization problems.
//! 24th European Modeling and Simulation Symposium, EMSS 1, (2012), 368-372
use crate::component::AnyComponent;
use crate::components::archive;
use crate::lens::{AnyLens, Lens, LensMap};
use crate::logging::extractor::{EntryExtractor, EntryName};
use crate::problems::{LimitedVectorProblem, VectorProblem};
use crate::utils::SerializablePhantom;
use crate::{
Component, CustomState, ExecResult, Individual, Problem, SingleObjectiveProblem, State,
};
use std::{any::type_name, marker::PhantomData};

use better_any::{Tid, TidAble};
use derivative::Derivative;
use serde::Serialize;
use std::any::type_name;
use std::marker::PhantomData;

use crate::{
component::AnyComponent,
components::archive,
lens::{AnyLens, Lens, LensMap},
logging::extractor::{EntryExtractor, EntryName},
problems::{LimitedVectorProblem, VectorProblem},
utils::SerializablePhantom,
Component, CustomState, ExecResult, Individual, Problem, SingleObjectiveProblem, State,
};

/// Trait for representing a component that measures the improvement of the solutions an operator caused.
pub trait ImprovementMeasure<P: Problem>: AnyComponent {
Expand Down Expand Up @@ -82,8 +83,8 @@ impl<I: AnyComponent> Improvement<I> {
/// Updates the improvement using the total and the percentage vectors.
pub fn update(&mut self, improvement: (Vec<f64>, Vec<f64>)) {
let (a, b) = improvement;
self.percent_improvement = a.clone();
self.total_improvement = b.clone();
self.percent_improvement.clone_from(&a);
self.total_improvement.clone_from(&b);
}
}

Expand Down
27 changes: 15 additions & 12 deletions src/components/measures/stepsize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,23 @@
//! On the analysis, classification and prediction of metaheuristic algorithm behavior for combinatorial optimization problems.
//! 24th European Modeling and Simulation Symposium, EMSS 1, (2012), 368-372
use crate::component::AnyComponent;
use crate::components::archive;
use crate::lens::{AnyLens, Lens, LensMap};
use crate::logging::extractor::{EntryExtractor, EntryName};
use crate::population::AsSolutions;
use crate::problems::VectorProblem;
use crate::utils::{squared_euclidean, SerializablePhantom};
use crate::{Component, CustomState, ExecResult, Problem, State};
use std::{any::type_name, marker::PhantomData};

use better_any::{Tid, TidAble};
use derivative::Derivative;
use serde::Serialize;
use statrs::statistics::Statistics;
use std::any::type_name;
use std::marker::PhantomData;

use crate::{
component::AnyComponent,
components::archive,
lens::{AnyLens, Lens, LensMap},
logging::extractor::{EntryExtractor, EntryName},
population::AsSolutions,
problems::VectorProblem,
utils::{squared_euclidean, SerializablePhantom},
Component, CustomState, ExecResult, Problem, State,
};

/// Trait for representing a component that measures the step size of the change caused by an operator.
pub trait StepSizeMeasure<P: Problem>: AnyComponent {
Expand Down Expand Up @@ -86,8 +89,8 @@ impl<I: AnyComponent> StepSize<I> {
/// Updates the step size using the step size vector.
pub fn update(&mut self, all_steps: (Vec<f64>, Vec<f64>)) {
let (a, b) = all_steps;
self.all_steps = a.clone();
self.all_var = b.clone();
self.all_steps.clone_from(&a);
self.all_var.clone_from(&b);
self.variance = a.clone().variance();
self.step_size = a.mean();
}
Expand Down

0 comments on commit d000da9

Please sign in to comment.