use crate::{
component::ExecResult,
components::{boundary, initialization, mutation, replacement, selection},
conditions::Condition,
configuration::Configuration,
identifier::{Global, Identifier},
logging::Logger,
problems::{LimitedVectorProblem, SingleObjectiveProblem},
Component,
};
pub struct RealProblemParameters {
pub population_size: u32,
pub lambda: u32,
pub deviation: f64,
}
pub fn real_mu_plus_lambda_es<P, O>(
params: RealProblemParameters,
condition: Box<dyn Condition<P>>,
) -> ExecResult<Configuration<P>>
where
P: SingleObjectiveProblem + LimitedVectorProblem<Element = f64>,
{
let RealProblemParameters {
population_size,
lambda,
deviation,
} = params;
Ok(Configuration::builder()
.do_(initialization::RandomSpread::new(population_size))
.evaluate()
.update_best_individual()
.do_(es::<P, Global>(
Parameters {
selection: selection::FullyRandom::new(lambda),
mutation: mutation::NormalMutation::new_dev(deviation),
constraints: boundary::Saturation::new(),
archive: None,
replacement: replacement::MuPlusLambda::new(population_size),
},
condition,
))
.build())
}
pub struct Parameters<P> {
pub selection: Box<dyn Component<P>>,
pub mutation: Box<dyn Component<P>>,
pub constraints: Box<dyn Component<P>>,
pub archive: Option<Box<dyn Component<P>>>,
pub replacement: Box<dyn Component<P>>,
}
pub fn es<P, I>(params: Parameters<P>, condition: Box<dyn Condition<P>>) -> Box<dyn Component<P>>
where
P: SingleObjectiveProblem,
I: Identifier,
{
let Parameters {
selection,
mutation,
constraints,
archive,
replacement,
} = params;
Configuration::builder()
.while_(condition, |builder| {
builder
.do_(selection)
.do_(mutation)
.do_(constraints)
.evaluate_with::<I>()
.update_best_individual()
.do_if_some_(archive)
.do_(replacement)
.do_(Logger::new())
})
.build_component()
}