moors/algorithms/helpers/
context.rs

1use derive_builder::Builder;
2
3/// Holds runtime state information for the genetic algorithm, passed to genetic operators during each iteration.
4/// Contains details such as population size and current iteration, which some operators use to adapt their behavior dynamically.
5#[derive(Debug, Clone, Default, Builder)]
6#[builder(pattern = "owned")]
7#[builder(default)]
8pub struct AlgorithmContext {
9    pub num_vars: usize,
10    pub population_size: usize,
11    pub num_offsprings: usize,
12    pub num_iterations: usize,
13    pub current_iteration: usize,
14    pub upper_bound: Option<f64>,
15    pub lower_bound: Option<f64>,
16}
17
18impl AlgorithmContext {
19    /// Updates the current iteration in the context.
20    pub fn set_current_iteration(&mut self, current_iteration: usize) {
21        self.current_iteration = current_iteration;
22    }
23}