use std::convert::Infallible; use crate::binary_string::{BinaryString, BinaryStringConversionError, Bounds}; pub mod labs; pub mod one_max; pub mod rosenbrock; pub mod sphere; pub trait FitnessFunction { type In; type Out; type Err; fn fit(self: &Self, inp: &Self::In) -> Result; } pub struct BinaryFitnessWrapper { bounds: Vec, fitting_function: TFitness, } impl BinaryFitnessWrapper { pub fn new(fitting_function: TFitness, bounds: Vec) -> Self { BinaryFitnessWrapper { fitting_function, bounds, } } } impl FitnessFunction for BinaryFitnessWrapper where TFitness: FitnessFunction, Out = f64, Err = Infallible> { type In = BinaryString; type Out = f64; type Err = BinaryStringConversionError; fn fit(self: &Self, inp: &BinaryString) -> Result { Ok(self.fitting_function.fit(&inp.to_real(&self.bounds)?).unwrap()) } }