use age::AgeFunctions::*;
pub trait Age: Send + Sync {
fn age_threshold(&self) -> u64;
fn age_unfitness(&self, age_generations: u64, fitness: f64) -> f64;
}
pub struct AgeThreshold(pub u64);
pub struct AgeSlope(pub f64);
pub enum AgeFunctions {
None,
Linear(AgeThreshold, AgeSlope),
Quadratic(AgeThreshold, AgeSlope),
}
impl Age for AgeFunctions {
fn age_threshold(&self) -> u64 {
match self {
None => 0,
Linear(threshold, _) => threshold.0,
Quadratic(threshold, _) => threshold.0,
}
}
fn age_unfitness(&self, age_generations: u64, fitness: f64) -> f64 {
match self {
None => fitness,
Linear(_, sp) => fitness - sp.0 * age_generations as f64,
Quadratic(_, sp) => fitness - sp.0 * age_generations as f64 * age_generations as f64,
}
}
}