@@ -180,27 +180,31 @@ where
180180 MutationType :: Range ( _) => {
181181 // post-clamp
182182 let current_value = chromosome. genes [ index] ;
183- let delta = self . allele_bandwidth_sampler . as_ref ( ) . unwrap ( ) . sample ( rng) ;
184- if rng. gen ( ) {
185- chromosome. genes [ index] =
186- T :: clamped_add ( current_value, delta, * self . allele_range . end ( ) ) ;
187- } else {
188- chromosome. genes [ index] =
189- T :: clamped_sub ( current_value, delta, * self . allele_range . start ( ) ) ;
190- }
191- }
192- MutationType :: RangeScaled ( bandwidths) => {
193- if self . current_scale_index >= bandwidths. len ( ) . saturating_sub ( 1 ) {
194- // post-clamp
195- let current_value = chromosome. genes [ index] ;
196- let delta = self . allele_bandwidth_sampler . as_ref ( ) . unwrap ( ) . sample ( rng) ;
183+ if let Some ( sampler) = self . allele_bandwidth_sampler . as_ref ( ) {
184+ let delta = sampler. sample ( rng) ;
197185 if rng. gen ( ) {
198186 chromosome. genes [ index] =
199187 T :: clamped_add ( current_value, delta, * self . allele_range . end ( ) ) ;
200188 } else {
201189 chromosome. genes [ index] =
202190 T :: clamped_sub ( current_value, delta, * self . allele_range . start ( ) ) ;
203191 }
192+ }
193+ }
194+ MutationType :: RangeScaled ( bandwidths) => {
195+ if self . current_scale_index >= bandwidths. len ( ) . saturating_sub ( 1 ) {
196+ // post-clamp
197+ let current_value = chromosome. genes [ index] ;
198+ if let Some ( sampler) = self . allele_bandwidth_sampler . as_ref ( ) {
199+ let delta = sampler. sample ( rng) ;
200+ if rng. gen ( ) {
201+ chromosome. genes [ index] =
202+ T :: clamped_add ( current_value, delta, * self . allele_range . end ( ) ) ;
203+ } else {
204+ chromosome. genes [ index] =
205+ T :: clamped_sub ( current_value, delta, * self . allele_range . start ( ) ) ;
206+ }
207+ }
204208 } else {
205209 // pre-clamp
206210 let bandwidth = bandwidths[ self . current_scale_index ] ;
@@ -534,27 +538,29 @@ where
534538 population : & mut Population < T > ,
535539 rng : & mut R ,
536540 ) {
537- let allele_range_start = * self . allele_range . start ( ) ;
538- let allele_range_end = * self . allele_range . end ( ) ;
541+ if let Some ( sampler) = self . allele_bandwidth_sampler . as_ref ( ) {
542+ let allele_range_start = * self . allele_range . start ( ) ;
543+ let allele_range_end = * self . allele_range . end ( ) ;
539544
540- ( 0 ..self . genes_size ) . for_each ( |index| {
541- let current_value = chromosome. genes [ index] ;
542- let delta = self . allele_bandwidth_sampler . as_ref ( ) . unwrap ( ) . sample ( rng) ;
543- if allele_range_start < current_value {
544- let mut new_chromosome = population. new_chromosome ( chromosome) ;
545- new_chromosome. genes [ index] =
546- T :: clamped_sub ( current_value, delta, allele_range_start) ;
547- new_chromosome. reset_metadata ( self . genes_hashing ) ;
548- population. chromosomes . push ( new_chromosome) ;
549- } ;
550- if current_value < allele_range_end {
551- let mut new_chromosome = population. new_chromosome ( chromosome) ;
552- new_chromosome. genes [ index] =
553- T :: clamped_add ( current_value, delta, allele_range_end) ;
554- new_chromosome. reset_metadata ( self . genes_hashing ) ;
555- population. chromosomes . push ( new_chromosome) ;
556- } ;
557- } ) ;
545+ ( 0 ..self . genes_size ) . for_each ( |index| {
546+ let current_value = chromosome. genes [ index] ;
547+ let delta = sampler. sample ( rng) ;
548+ if allele_range_start < current_value {
549+ let mut new_chromosome = population. new_chromosome ( chromosome) ;
550+ new_chromosome. genes [ index] =
551+ T :: clamped_sub ( current_value, delta, allele_range_start) ;
552+ new_chromosome. reset_metadata ( self . genes_hashing ) ;
553+ population. chromosomes . push ( new_chromosome) ;
554+ } ;
555+ if current_value < allele_range_end {
556+ let mut new_chromosome = population. new_chromosome ( chromosome) ;
557+ new_chromosome. genes [ index] =
558+ T :: clamped_add ( current_value, delta, allele_range_end) ;
559+ new_chromosome. reset_metadata ( self . genes_hashing ) ;
560+ population. chromosomes . push ( new_chromosome) ;
561+ } ;
562+ } ) ;
563+ }
558564 }
559565 fn fill_neighbouring_population_range_pre_clamp < R : Rng > (
560566 & self ,
0 commit comments