mod composite;
mod novelty;
use crate::Score;
pub use composite::CompositeFitnessFn;
pub use novelty::{Novelty, NoveltySearch};
pub trait FitnessFunction<T, S = f32>: Send + Sync
where
S: Into<Score>,
{
fn evaluate(&self, individual: T) -> S;
}
pub trait BatchFitnessFunction<T, S = f32>: Send + Sync
where
S: Into<Score>,
{
fn evaluate(&self, individuals: Vec<T>) -> Vec<S>;
}
impl<T, S, F> FitnessFunction<T, S> for F
where
F: Fn(T) -> S + Send + Sync,
S: Into<Score>,
{
fn evaluate(&self, individual: T) -> S {
self(individual)
}
}
impl<T, S, F> BatchFitnessFunction<T, S> for F
where
F: for<'a> Fn(&'a [T]) -> Vec<S> + Send + Sync,
S: Into<Score>,
{
fn evaluate(&self, individuals: Vec<T>) -> Vec<S> {
self(&individuals)
}
}