@@ -204,11 +204,19 @@ where
204204 . iter ( )
205205 . map ( |mutation_type| match & mutation_type {
206206 MutationType :: Range ( bandwidth) => {
207- Some ( Uniform :: new_inclusive ( T :: smallest_increment ( ) , bandwidth) )
207+ if * bandwidth >= T :: smallest_increment ( ) {
208+ Some ( Uniform :: new_inclusive ( T :: smallest_increment ( ) , bandwidth) )
209+ } else {
210+ None
211+ }
208212 }
209213 MutationType :: RangeScaled ( bandwidths) => {
210214 let bandwidth = bandwidths. last ( ) . unwrap ( ) ;
211- Some ( Uniform :: new_inclusive ( T :: smallest_increment ( ) , bandwidth) )
215+ if * bandwidth >= T :: smallest_increment ( ) {
216+ Some ( Uniform :: new_inclusive ( T :: smallest_increment ( ) , bandwidth) )
217+ } else {
218+ None
219+ }
212220 }
213221 _ => None ,
214222 } )
@@ -300,13 +308,19 @@ where
300308 if rng. gen ( ) {
301309 let max_delta_up = allele_range_end - current_value;
302310 let working_delta_up = T :: min ( bandwidth, max_delta_up) ;
303- let delta = rng. gen_range ( T :: smallest_increment ( ) ..=working_delta_up) ;
304- chromosome. genes [ index] += delta; // no need to check again
311+ if working_delta_up >= T :: smallest_increment ( ) {
312+ let delta =
313+ rng. gen_range ( T :: smallest_increment ( ) ..=working_delta_up) ;
314+ chromosome. genes [ index] += delta; // no need to check again
315+ }
305316 } else {
306317 let max_delta_down = current_value - allele_range_start;
307318 let working_delta_down = T :: min ( bandwidth, max_delta_down) ;
308- let delta = rng. gen_range ( T :: smallest_increment ( ) ..=working_delta_down) ;
309- chromosome. genes [ index] -= delta; // no need to check again
319+ if working_delta_down >= T :: smallest_increment ( ) {
320+ let delta =
321+ rng. gen_range ( T :: smallest_increment ( ) ..=working_delta_down) ;
322+ chromosome. genes [ index] -= delta; // no need to check again
323+ }
310324 }
311325 }
312326 }
@@ -660,19 +674,23 @@ where
660674 let mut new_chromosome = population. new_chromosome ( chromosome) ;
661675 let max_delta_down = current_value - allele_range_start;
662676 let working_delta_down = T :: min ( bandwidth, max_delta_down) ;
663- let delta = rng. gen_range ( T :: smallest_increment ( ) ..=working_delta_down) ;
664- new_chromosome. genes [ index] -= delta; // no need to check again
665- new_chromosome. reset_metadata ( self . genes_hashing ) ;
666- population. chromosomes . push ( new_chromosome) ;
677+ if working_delta_down >= T :: smallest_increment ( ) {
678+ let delta = rng. gen_range ( T :: smallest_increment ( ) ..=working_delta_down) ;
679+ new_chromosome. genes [ index] -= delta; // no need to check again
680+ new_chromosome. reset_metadata ( self . genes_hashing ) ;
681+ population. chromosomes . push ( new_chromosome) ;
682+ }
667683 } ;
668684 if current_value < allele_range_end {
669685 let mut new_chromosome = population. new_chromosome ( chromosome) ;
670686 let max_delta_up = allele_range_end - current_value;
671687 let working_delta_up = T :: min ( bandwidth, max_delta_up) ;
672- let delta = rng. gen_range ( T :: smallest_increment ( ) ..=working_delta_up) ;
673- new_chromosome. genes [ index] += delta; // no need to check again
674- new_chromosome. reset_metadata ( self . genes_hashing ) ;
675- population. chromosomes . push ( new_chromosome) ;
688+ if working_delta_up >= T :: smallest_increment ( ) {
689+ let delta = rng. gen_range ( T :: smallest_increment ( ) ..=working_delta_up) ;
690+ new_chromosome. genes [ index] += delta; // no need to check again
691+ new_chromosome. reset_metadata ( self . genes_hashing ) ;
692+ population. chromosomes . push ( new_chromosome) ;
693+ }
676694 } ;
677695 }
678696 fn fill_neighbouring_population_random < R : Rng > (
@@ -1000,11 +1018,19 @@ where
10001018 . iter ( )
10011019 . map ( |mutation_type| match & mutation_type {
10021020 MutationType :: Range ( bandwidth) => {
1003- Some ( Uniform :: new_inclusive ( T :: smallest_increment ( ) , bandwidth) )
1021+ if * bandwidth >= T :: smallest_increment ( ) {
1022+ Some ( Uniform :: new_inclusive ( T :: smallest_increment ( ) , bandwidth) )
1023+ } else {
1024+ None
1025+ }
10041026 }
10051027 MutationType :: RangeScaled ( bandwidths) => {
10061028 let bandwidth = bandwidths. last ( ) . unwrap ( ) ;
1007- Some ( Uniform :: new_inclusive ( T :: smallest_increment ( ) , bandwidth) )
1029+ if * bandwidth >= T :: smallest_increment ( ) {
1030+ Some ( Uniform :: new_inclusive ( T :: smallest_increment ( ) , bandwidth) )
1031+ } else {
1032+ None
1033+ }
10081034 }
10091035 _ => None ,
10101036 } )
0 commit comments