Skip to main content

math_audio_optimisation/
init_random.rs

1use ndarray::{Array1, Array2};
2use rand::Rng;
3
4pub(crate) fn init_random<R: Rng + ?Sized>(
5    n: usize,
6    npop: usize,
7    lower: &Array1<f64>,
8    upper: &Array1<f64>,
9    is_free: &[bool],
10    rng: &mut R,
11) -> Array2<f64> {
12    let mut pop = Array2::<f64>::zeros((npop, n));
13    for i in 0..npop {
14        for j in 0..n {
15            if is_free[j] {
16                let u: f64 = rng.random::<f64>();
17                pop[(i, j)] = lower[j] + u * (upper[j] - lower[j]);
18            } else {
19                pop[(i, j)] = lower[j];
20            }
21        }
22    }
23    pop
24}