use crate::configuration::ProblemSolving;
use crate::operations::{Crossover, GaussianParams, Mutation, Selection};
#[derive(Debug, Clone, PartialEq)]
pub enum Neighborhood {
VonNeumann,
Moore,
CompactR2,
Linear,
}
#[derive(Debug, Clone, PartialEq)]
pub enum UpdateMode {
Synchronous,
Asynchronous,
}
#[derive(Debug, Clone)]
pub struct CellularConfiguration {
pub rows: usize,
pub cols: usize,
pub neighborhood: Neighborhood,
pub update_mode: UpdateMode,
pub max_generations: usize,
pub selection: Selection,
pub crossover: Crossover,
pub mutation: Mutation,
pub problem_solving: ProblemSolving,
pub fitness_target: Option<f64>,
}
impl Default for CellularConfiguration {
fn default() -> Self {
Self {
rows: 10,
cols: 10,
neighborhood: Neighborhood::Moore,
update_mode: UpdateMode::Asynchronous,
max_generations: 1000,
selection: Selection::Tournament,
crossover: Crossover::Uniform,
mutation: Mutation::Gaussian(GaussianParams { sigma: Some(0.1) }),
problem_solving: ProblemSolving::Minimization,
fitness_target: None,
}
}
}
impl CellularConfiguration {
pub fn with_grid(mut self, rows: usize, cols: usize) -> Self {
self.rows = rows;
self.cols = cols;
self
}
pub fn with_neighborhood(mut self, n: Neighborhood) -> Self {
self.neighborhood = n;
self
}
pub fn with_update_mode(mut self, m: UpdateMode) -> Self {
self.update_mode = m;
self
}
pub fn with_max_generations(mut self, n: usize) -> Self {
self.max_generations = n;
self
}
pub fn with_selection(mut self, s: Selection) -> Self {
self.selection = s;
self
}
pub fn with_crossover(mut self, c: Crossover) -> Self {
self.crossover = c;
self
}
pub fn with_mutation(mut self, m: Mutation) -> Self {
self.mutation = m;
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 population_size(&self) -> usize {
self.rows * self.cols
}
}