#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum ObjectiveDirection {
Minimize,
Maximize,
}
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Nsga2Configuration {
pub num_objectives: usize,
pub population_size: usize,
pub max_generations: usize,
pub objective_directions: Vec<ObjectiveDirection>,
}
impl Default for Nsga2Configuration {
fn default() -> Self {
Nsga2Configuration {
num_objectives: 2,
population_size: 100,
max_generations: 200,
objective_directions: Vec::new(),
}
}
}
impl Nsga2Configuration {
pub fn new() -> Self {
Self::default()
}
pub fn with_num_objectives(mut self, n: usize) -> Self {
self.num_objectives = n;
self
}
pub fn with_population_size(mut self, size: usize) -> Self {
self.population_size = size;
self
}
pub fn with_max_generations(mut self, gens: usize) -> Self {
self.max_generations = gens;
self
}
pub fn with_objective_directions(mut self, directions: Vec<ObjectiveDirection>) -> Self {
self.objective_directions = directions;
self
}
pub fn effective_directions(&self) -> Vec<ObjectiveDirection> {
if self.objective_directions.is_empty() {
vec![ObjectiveDirection::Minimize; self.num_objectives]
} else {
self.objective_directions.clone()
}
}
}