ecrs 0.1.0-beta.4

Evolutionary computation tools & algorithms
Documentation
#[cfg(feature = "ga")]
use ecrs::{
    ga::{self, individual::RealValueIndividual, probe::AggregatedProbe},
    prelude::{
        crossover::SinglePoint, fitness::FnBasedFitness, mutation::Identity, population::RandomPoints,
        replacement::WeakParent, selection::Boltzmann,
    },
};

#[cfg(feature = "ga")]
mod util;

#[cfg(feature = "ga")]
fn rastrigin_fitness(chromosome: &Vec<f64>) -> f64 {
    1000.0 * f64::exp(-ecrs::test_functions::rastrigin(chromosome))
}

#[cfg(feature = "ga")]
fn main() {
    let _ = util::init_logging();

    let res = ga::Builder::new::<
        RealValueIndividual,
        Identity,
        SinglePoint,
        Boltzmann,
        WeakParent,
        RandomPoints,
        FnBasedFitness<RealValueIndividual>,
        AggregatedProbe<RealValueIndividual>,
    >()
    .set_max_generation_count(50_000)
    .set_population_size(100)
    .set_fitness_fn(rastrigin_fitness)
    .set_crossover_operator(ga::operators::crossover::SinglePoint::new())
    .set_replacement_operator(ga::operators::replacement::WeakParent::new())
    .set_mutation_operator(ga::operators::mutation::Identity::new())
    .set_population_generator(ga::population::RandomPoints::with_constraints(
        3,
        vec![-5.12..5.12, -5.12..5.12, -5.12..5.12],
    ))
    .set_selection_operator(ga::operators::selection::Boltzmann::new(0.05, 80.0, 500, false))
    .set_probe(
        ga::probe::AggregatedProbe::new()
            .add_probe(ga::probe::PolicyDrivenProbe::new(
                ga::probe::ElapsedTime::new(std::time::Duration::from_millis(200), std::time::Duration::ZERO),
                ga::probe::StdoutProbe,
            ))
            .add_probe(ga::probe::PolicyDrivenProbe::new(
                ga::probe::GenerationInterval::new(500, 100),
                ga::probe::StdoutProbe,
            )),
    )
    .build()
    .run()
    .unwrap();

    println!("{res:?}");
}

#[cfg(not(feature = "ga"))]
fn main() {
    panic!("Required feature \"ga\" is not enabled");
}