use crate::configuration::ProblemSolving;
#[derive(Debug, Clone, PartialEq)]
pub enum DeMutationStrategy {
Rand1,
Best1,
CurrentToBest1,
Rand2,
Best2,
}
#[derive(Debug, Clone, PartialEq)]
pub enum DeCrossoverMode {
Binomial,
Exponential,
}
#[derive(Debug, Clone, PartialEq)]
pub enum DeAdaptive {
None,
Jade { p: f64, c: f64 },
LShade { history_size: usize },
}
#[derive(Debug, Clone)]
pub struct DeConfiguration {
pub population_size: usize,
pub max_generations: usize,
pub mutation_factor: f64,
pub crossover_rate: f64,
pub mutation_strategy: DeMutationStrategy,
pub crossover_mode: DeCrossoverMode,
pub adaptive: DeAdaptive,
pub problem_solving: ProblemSolving,
pub fitness_target: Option<f64>,
pub fitness_cache_size: Option<usize>,
}
impl Default for DeConfiguration {
fn default() -> Self {
Self {
population_size: 50,
max_generations: 1000,
mutation_factor: 0.8,
crossover_rate: 0.9,
mutation_strategy: DeMutationStrategy::Rand1,
crossover_mode: DeCrossoverMode::Binomial,
adaptive: DeAdaptive::None,
problem_solving: ProblemSolving::Minimization,
fitness_target: None,
fitness_cache_size: None,
}
}
}
impl DeConfiguration {
pub fn with_population_size(mut self, n: usize) -> Self {
self.population_size = n;
self
}
pub fn with_max_generations(mut self, n: usize) -> Self {
self.max_generations = n;
self
}
pub fn with_mutation_factor(mut self, f: f64) -> Self {
self.mutation_factor = f;
self
}
pub fn with_crossover_rate(mut self, cr: f64) -> Self {
self.crossover_rate = cr;
self
}
pub fn with_mutation_strategy(mut self, s: DeMutationStrategy) -> Self {
self.mutation_strategy = s;
self
}
pub fn with_crossover_mode(mut self, m: DeCrossoverMode) -> Self {
self.crossover_mode = m;
self
}
pub fn with_adaptive(mut self, a: DeAdaptive) -> Self {
self.adaptive = a;
self
}
pub fn with_problem_solving(mut self, ps: ProblemSolving) -> Self {
self.problem_solving = ps;
self
}
pub fn with_fitness_target(mut self, t: f64) -> Self {
self.fitness_target = Some(t);
self
}
pub fn with_fitness_cache_size(mut self, size: usize) -> Self {
self.fitness_cache_size = Some(size);
self
}
}