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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//! # Evolutionary
//!
//! A fully extensible Rust framework for using paralyzed genetic algorithms to solve problems.
//!
//! Currently, it supports coding in [`Bin`](struct@population::Bin), [`Real`](struct@population::Real),
//! [`Permuted Integers`](struct@population::IntPerm), [`Integers`](struct@population::Int) and any
//! other coding you may want to implement. It also has built in implementation of the following genetic
//! operators:
//!
//! - [`Selection`]
//! - [`Crossover`]
//! - [`Mutation`]
//!
//! You can code your own selection, crossover or mutation implementing the traits and passing them
//! to the `EvolutionBuilder`.
//!
//! ## Example:
//!
//! ```rust
//! use evolutionary::prelude::*;
//!
//! // First you'll need to code your Fitness function:
//! #[derive(Clone)]
//! pub struct MaxFitness;
//!
//! // To do this you need to implement the Fitness trait.
//! impl Fitness<Bin> for MaxFitness {
//! fn calculate_fitness(&self, individual: &Bin) -> f64 {
//! let mut sum = 0.;
//!
//! for i in 0..individual.get_chromosome().len() {
//! if individual.get_gene(i) {
//! sum += 1.;
//! }
//! }
//!
//! sum
//! }
//! }
//!
//! // Then you will be able to build a evolution object using the `EvolutionBuiler`
//! // and setting all the required parameters:
//! fn main() {
//! let mut evolution = EvolutionBuilder::new(30, 10, GeneCod::Bin, ())
//! .with_fitness(MaxFitness)
//! .with_selection(TournamentSelection::default())
//! .with_crossover(NPointsCrossover::default())
//! .with_mutation(BitFlipMutation::default())
//! .with_title("Max".to_string())
//! .with_stop_condition(move |_, iterations, _| iterations >= 100)
//! .build().unwrap();
//!
//! evolution.run();
//!
//! assert_eq!(*evolution.current_best().get_chromosome(), vec![true; 10]);
//! assert_eq!(evolution.current_best_fitness(), 10.0);
//! }
//! ```
//!
//! Find this and other examples in the [examples folder](./examples).
pub use Crossover;
pub use Evolution;
pub use EvolutionBuilder;
pub use Fitness;
pub use Mutation;
pub use Individual;
pub use Selection;