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
//! Multi-range chromosome initializer.
//!
//! Creates genes for [`crate::chromosomes::MultiRangeChromosome`] by sampling
//! each gene's value uniformly from its own `(lo_i, hi_i)` bounds and assigning
//! its own `mutation_rate_i`.
//!
//! # Parallel-slice semantics
//!
//! `bounds` and `mutation_rates` are parallel slices — element `i` in `bounds`
//! corresponds to element `i` in `mutation_rates`. The resulting chromosome has
//! exactly `bounds.len()` genes. If `mutation_rates` is shorter than `bounds`,
//! any remaining genes receive the default rate of `0.1`.
//!
//! # Panics
//!
//! Panics if `lo >= hi` for any bound — `rng.random_range(lo..hi)` requires
//! a non-empty range. Ensure all bounds satisfy `lo < hi`.
use crateMultiRangeGenotype;
use SampleUniform;
use Rng;
use Debug;
/// Initializes a vector of `MultiRangeGenotype` where each gene is sampled
/// from its own `(lo_i, hi_i)` range with its own mutation rate.
///
/// # Arguments
///
/// * `bounds` — One `(lo, hi)` pair per gene position. The resulting vector
/// has exactly `bounds.len()` genes.
/// * `mutation_rates` — One mutation rate per gene position. If shorter than
/// `bounds`, trailing genes receive a default rate of `0.1`.
///
/// # Returns
///
/// A vector of `MultiRangeGenotype<T>` genes, each with value sampled from
/// `[lo_i, hi_i)` and mutation rate set to `mutation_rates[i]` (or `0.1`).
///
/// # Panics
///
/// Panics if any `lo >= hi` (required by `rng.random_range`).
///
/// # Examples
///
/// ```
/// use genetic_algorithms::initializers::multi_range_random_initialization;
///
/// let bounds = vec![(0.0_f64, 1.0), (10.0, 20.0), (-5.0, -1.0)];
/// let rates = vec![0.1, 0.5, 0.2];
/// let genes = multi_range_random_initialization(&bounds, &rates);
/// assert_eq!(genes.len(), 3);
/// for gene in &genes {
/// assert!(gene.value >= gene.lo && gene.value < gene.hi);
/// }
/// ```