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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
use crate;
use Cow;
/// Flat-slice chromosome contract.
///
/// `LinearChromosome` extends [`ChromosomeT`] with the flat-slice DNA surface
/// used by all traditional GA chromosomes (binary, real-valued, integer-valued,
/// list-based). Any type implementing this trait gains:
///
/// # Examples
///
/// ```rust,no_run
/// use genetic_algorithms::chromosomes::Range as RangeChromosome;
/// use genetic_algorithms::genotypes::Range as RangeGene;
/// use genetic_algorithms::traits::LinearChromosome;
/// use std::borrow::Cow;
///
/// let mut chrom = RangeChromosome::<f64>::default();
/// let genes = vec![RangeGene::default()];
/// chrom.set_dna(Cow::Owned(genes));
/// assert_eq!(chrom.dna().len(), 1);
/// ```
///
/// - `dna()` / `dna_mut()` / `set_dna()` — slice access and zero-copy DNA updates.
/// - `set_fitness_fn<F>()` — installs the user-provided fitness closure.
/// - `new_gene()` — factory method for default gene construction.
/// - **Default `set_gene()`** — in-place single-gene replacement with bounds checking.
/// - **Default `reset()`** — sets fitness to `NaN`, age to `0`, dna to empty.
///
/// # Supertrait relationship
///
/// `LinearChromosome: ChromosomeT`. All operators and engines that call
/// `dna()` / `dna_mut()` / `set_dna()` require `U: LinearChromosome`.
/// Operators that only use `fitness()` / `age()` remain generic over
/// `U: ChromosomeT` and work with any chromosome representation.
///
/// # WASM compatibility
///
/// The default impls contain no `Instant`, no `par_iter()`, and no
/// host-only stdlib — safe for `wasm32-unknown-unknown`.