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
use selection_rate::SelectionRates::*;
use slope_params::SlopeParams;
pub trait SelectionRate: Send + Sync {
fn rate(
&self,
generation: u64,
progress: f64,
n_solutions: usize,
population_fitness: &[f64],
) -> usize;
}
pub enum SelectionRates {
Constant(usize),
Linear(SlopeParams),
Quadratic(SlopeParams),
}
impl SelectionRate for SelectionRates {
fn rate(
&self,
generation: u64,
_progress: f64,
_n_solutions: usize,
_population_fitness: &[f64],
) -> usize {
match self {
Constant(c) => *c,
Linear(sp) => sp
.check_bound(sp.coefficient * generation as f64 + sp.start)
.ceil() as usize,
Quadratic(sp) => sp
.check_bound(sp.coefficient * generation as f64 * generation as f64 + sp.start)
.ceil() as usize,
}
}
}