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
97
98
99
100
101
102
103
104
105
106
107
//! Genetic Algorithms library with flexible genotypes, chromosomes, and operators.
//!
//! This crate provides a modular and efficient framework for building Genetic Algorithms (GAs).
//! It focuses on:
//! - Clear abstractions (traits for genes and chromosomes).
//! - Efficient data handling using Cow to avoid unnecessary clones.
//! - Composable operators (selection, crossover, mutation, survivor).
//! - Parallelism for fitness evaluation and reproduction.
//!
//! Key concepts:
//! - Genotypes: reusable gene types (e.g., Binary, Range) that implement `GeneT`.
//! - Chromosomes: sequences of genes that implement `ChromosomeT` and hold fitness and age.
//! - GA Orchestrator: `ga::Ga` coordinates the lifecycle (init, selection, crossover, mutation, survivor, evaluation).
//! - Configuration: a cohesive configuration model to tune operators and limits.
//!
//! Quickstart (example):
//! ```ignore
//! use genetic_algorithms::configuration::ProblemSolving;
//! use genetic_algorithms::genotypes::Range as RangeGene;
//! use genetic_algorithms::chromosomes::Range as RangeChromosome;
//! use genetic_algorithms::ga::Ga;
//! use genetic_algorithms::initializers::range_random_initialization;
//! use genetic_algorithms::operations::{Crossover, Mutation, Selection, Survivor};
//! use genetic_algorithms::traits::{ConfigurationT, CrossoverConfig, MutationConfig, SelectionConfig, StoppingConfig};
//!
//! const N: i32 = 8;
//!
//! fn fitness_fn(dna: &[RangeGene<i32>]) -> f64 {
//! // ... compute fitness ...
//! 0.0
//! }
//!
//! let alleles = vec![RangeGene::new(0, vec![(0, N - 1)], 0)];
//! let alleles_clone = alleles.clone();
//! let mut ga = Ga::new()
//! .with_genes_per_chromosome(N)
//! .with_population_size(100)
//! .with_initialization_fn(move |genes_per_chromosome, _, _| {
//! range_random_initialization(genes_per_chromosome, Some(&alleles_clone), Some(false))
//! })
//! .with_fitness_fn(fitness_fn)
//! .with_selection_method(Selection::Tournament)
//! .with_crossover_method(Crossover::Uniform)
//! .with_mutation_method(Mutation::Swap) // Swap or value-mutation for Range<i32> chromosomes
//! .with_problem_solving(ProblemSolving::Minimization)
//! .with_survivor_method(Survivor::Fitness)
//! .with_max_generations(5000)
//! .with_fitness_target(0.0)
//! .build()
//! .expect("Invalid configuration");
//! let _population = ga.run();
//! ```
//!
//! Modules of interest:
//! - `traits`: core traits for genes, chromosomes, and configuration.
//! - `chromosomes`: concrete chromosome implementations (Binary, Range).
//! - `genotypes`: concrete gene implementations (Binary, Range).
//! - `operations`: selection, crossover, mutation, survivor operators.
//! - `ga`: genetic algorithm orchestrator.
//! - `population`: population management and best tracking.
//! - `fitness`: helpers to wrap user fitness functions.
//! - `initializers`: utilities to build initial DNA.
//!
//! Performance notes:
//! - Chromosome DNA is set via a single `set_dna(Cow<[Gene]>)` method to avoid extra copies.
//! - Operators use pre-allocation and move semantics where possible.
//! - Parallel evaluation leverages threads to scale fitness computation.
extern crate core;
pub use LogObserver;
pub use IslandGaObserver;
pub use Nsga2Observer;
pub use TracingObserver;
pub use MetricsObserver;
pub use AllObserver;
pub use CompositeObserver;
pub use GaObserver;
pub use NoopObserver;
pub use ExtensionEvent;
pub use TerminationCause;