@@ -10,7 +10,7 @@ use std::fmt::Debug;
1010/// It is generic over:
1111/// * Eval, which could be a float, or any other totally ordered type, so that we can rank solutions to our problem
1212/// * Rng: a random number generator (could be thread rng, etc.)
13- pub trait Chromosome < Rng : rand:: Rng , Eval > {
13+ pub trait Chromosome < Rng : rand:: RngExt , Eval > {
1414 /// Mutates this Chromosome, changing its genes
1515 fn mutate ( & mut self , rng : & mut Rng ) ;
1616
@@ -22,7 +22,7 @@ pub trait Chromosome<Rng: rand::Rng, Eval> {
2222 fn fitness ( & self ) -> Eval ;
2323}
2424
25- pub trait SelectionStrategy < Rng : rand:: Rng > {
25+ pub trait SelectionStrategy < Rng : rand:: RngExt > {
2626 fn new ( rng : Rng ) -> Self ;
2727
2828 /// Selects a portion of the population for reproduction
@@ -37,10 +37,10 @@ pub trait SelectionStrategy<Rng: rand::Rng> {
3737/// A roulette wheel selection strategy
3838/// https://en.wikipedia.org/wiki/Fitness_proportionate_selection
3939#[ allow( dead_code) ]
40- pub struct RouletteWheel < Rng : rand:: Rng > {
40+ pub struct RouletteWheel < Rng : rand:: RngExt > {
4141 rng : Rng ,
4242}
43- impl < Rng : rand:: Rng > SelectionStrategy < Rng > for RouletteWheel < Rng > {
43+ impl < Rng : rand:: RngExt > SelectionStrategy < Rng > for RouletteWheel < Rng > {
4444 fn new ( rng : Rng ) -> Self {
4545 Self { rng }
4646 }
@@ -86,10 +86,10 @@ impl<Rng: rand::Rng> SelectionStrategy<Rng> for RouletteWheel<Rng> {
8686}
8787
8888#[ allow( dead_code) ]
89- pub struct Tournament < const K : usize , Rng : rand:: Rng > {
89+ pub struct Tournament < const K : usize , Rng : rand:: RngExt > {
9090 rng : Rng ,
9191}
92- impl < const K : usize , Rng : rand:: Rng > SelectionStrategy < Rng > for Tournament < K , Rng > {
92+ impl < const K : usize , Rng : rand:: RngExt > SelectionStrategy < Rng > for Tournament < K , Rng > {
9393 fn new ( rng : Rng ) -> Self {
9494 Self { rng }
9595 }
@@ -118,7 +118,7 @@ impl<const K: usize, Rng: rand::Rng> SelectionStrategy<Rng> for Tournament<K, Rn
118118
119119type Comparator < T > = Box < dyn FnMut ( & T , & T ) -> Ordering > ;
120120pub struct GeneticAlgorithm <
121- Rng : rand:: Rng ,
121+ Rng : rand:: RngExt ,
122122 Eval : PartialOrd ,
123123 C : Chromosome < Rng , Eval > ,
124124 Selection : SelectionStrategy < Rng > ,
@@ -140,7 +140,7 @@ pub struct GenericAlgorithmParams {
140140}
141141
142142impl <
143- Rng : rand:: Rng ,
143+ Rng : rand:: RngExt ,
144144 Eval : Into < f64 > + PartialOrd + Debug ,
145145 C : Chromosome < Rng , Eval > + Clone + Debug ,
146146 Selection : SelectionStrategy < Rng > ,
@@ -222,7 +222,7 @@ mod tests {
222222 Tournament ,
223223 } ;
224224 use rand:: rngs:: ThreadRng ;
225- use rand:: { rng, Rng } ;
225+ use rand:: { rng, RngExt } ;
226226 use std:: collections:: HashMap ;
227227 use std:: fmt:: { Debug , Formatter } ;
228228 use std:: ops:: RangeInclusive ;
0 commit comments