pub struct Context<'a, Fe, R, C> {
fitness: &'a Fe,
rng: &'a mut R,
comparator: &'a C,
#[cfg(feature = "parallel")]
runtime: &'a pooled::Runtime,
}
impl<'a, Fe, R, C> Context<'a, Fe, R, C> {
#[cfg(not(feature = "parallel"))]
pub fn new(fitness: &'a Fe, rng: &'a mut R, comparator: &'a C) -> Self {
Self {
fitness,
rng,
comparator,
}
}
#[cfg(feature = "parallel")]
pub fn new(
fitness: &'a Fe,
rng: &'a mut R,
comparator: &'a C,
runtime: &'a pooled::Runtime,
) -> Self {
Self {
fitness,
rng,
comparator,
runtime,
}
}
pub fn fitness_evaluator(&self) -> &Fe {
self.fitness
}
pub fn rng(&mut self) -> &mut R {
self.rng
}
pub fn comparator(&self) -> &C {
self.comparator
}
#[cfg(feature = "parallel")]
pub fn pool(&self) -> pooled::map::MapPool<'_> {
self.runtime.map_pool()
}
#[cfg(feature = "parallel")]
pub fn runtime(&self) -> &pooled::Runtime {
self.runtime
}
}
impl<'a, Fe, R, C> std::fmt::Debug for Context<'a, Fe, R, C>
where
Fe: std::fmt::Debug,
R: std::fmt::Debug,
C: std::fmt::Debug,
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Context")
.field("fitness", &self.fitness)
.field("rng", &self.rng)
.field("comparator", &self.comparator)
.finish_non_exhaustive()
}
}