use crate::core::{Problem, Solution};
use serde::{Deserialize, Serialize};
use std::sync::Arc;
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct SolutionRecord {
pub solution: Vec<f64>,
pub objective_fitness_values: Vec<f64>,
pub constraint_values: Vec<f64>,
pub constraint_violation: usize,
#[serde(default)]
pub constraint_violation_magnitude: f64,
pub feasible: bool,
pub evaluated: bool,
}
impl SolutionRecord {
pub fn from_solution(s: &Solution) -> Self {
SolutionRecord {
solution: s.solution.clone(),
objective_fitness_values: s.objective_fitness_values.to_vec(),
constraint_values: s.constraint_values.to_vec(),
constraint_violation: s.constraint_violation,
constraint_violation_magnitude: s.constraint_violation_magnitude,
feasible: s.feasible,
evaluated: s.evaluated,
}
}
pub fn into_solution(self, problem: Arc<Problem>) -> Solution {
Solution {
problem,
solution: self.solution,
objective_fitness_values: self.objective_fitness_values.into(),
constraint_values: self.constraint_values.into(),
constraint_violation: self.constraint_violation,
constraint_violation_magnitude: self.constraint_violation_magnitude,
feasible: self.feasible,
evaluated: self.evaluated,
}
}
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct GaState {
pub population: Vec<SolutionRecord>,
pub archive: Vec<SolutionRecord>,
pub nfe: usize,
}