1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use crate;
/// The result of running a genetic algorithm.
///
/// Contains the final population and the number of generations that were executed.
/// Use [`Population::best`] to retrieve the best individual.
///
/// # Examples
///
/// ```
/// use evolve::{
/// algorithm::ga::GeneticAlgorithm,
/// fitness::Maximize,
/// initialization::Random,
/// operators::sequential::combinator::Fill,
/// operators::sequential::mutation::RandomReset,
/// termination::MaxGenerations,
/// };
/// use std::num::NonZero;
///
/// let mut ga = GeneticAlgorithm::new(
/// Random::new(),
/// MaxGenerations::new(10),
/// |g: &[u8; 2]| g[0] as u16 + g[1] as u16,
/// Fill::from_population_size(RandomReset::new()),
/// NonZero::new(50).unwrap(),
/// rand::rng(),
/// Maximize,
/// );
///
/// let result = ga.run();
/// let fe = |g: &[u8; 2]| g[0] as u16 + g[1] as u16;
/// let best = result.population.best(&fe, &Maximize);
/// println!("generations: {}, best fitness: {:?}", result.generations, best.fitness(&fe));
/// ```