|
1 | 1 | use crate::allele::Allele; |
2 | | -use std::ops::RangeInclusive; |
3 | 2 |
|
4 | 3 | /// Controls mutation behavior for numeric genotypes (Range and MultiRange). |
5 | 4 | /// |
@@ -304,107 +303,3 @@ pub enum MutationType<T: Allele> { |
304 | 303 | StepScaled(Vec<T>), |
305 | 304 | Discrete, |
306 | 305 | } |
307 | | - |
308 | | -impl<T: Allele> MutationType<T> { |
309 | | - /// Returns the current range bandwidth for Range-based mutations. |
310 | | - /// For scaled variants, returns the bandwidth at the given scale. |
311 | | - /// Returns None for non-Range mutations. |
312 | | - pub fn current_bandwidth(&self, current_scale_index: usize) -> Option<&T> { |
313 | | - match self { |
314 | | - Self::Range(bandwidth) => Some(bandwidth), |
315 | | - Self::RangeScaled(bandwidths) => { |
316 | | - bandwidths.get(current_scale_index.min(bandwidths.len().saturating_sub(1))) |
317 | | - } |
318 | | - _ => None, |
319 | | - } |
320 | | - } |
321 | | - |
322 | | - /// Returns the current step size for Step-based mutations. |
323 | | - /// For scaled variants, returns the step at the given scale. |
324 | | - /// Returns None for non-Step mutations. |
325 | | - pub fn current_step(&self, current_scale_index: usize) -> Option<&T> { |
326 | | - match self { |
327 | | - Self::Step(step) => Some(step), |
328 | | - Self::StepScaled(steps) => { |
329 | | - steps.get(current_scale_index.min(steps.len().saturating_sub(1))) |
330 | | - } |
331 | | - _ => None, |
332 | | - } |
333 | | - } |
334 | | - |
335 | | - /// Returns true if this mutation type uses scaling |
336 | | - pub fn is_scaled(&self) -> bool { |
337 | | - matches!(self, Self::RangeScaled(_) | Self::StepScaled(_)) |
338 | | - } |
339 | | - |
340 | | - /// Returns the maximum number of scales/phases for scaled mutations |
341 | | - pub fn num_scales(&self) -> usize { |
342 | | - match self { |
343 | | - Self::RangeScaled(bandwidths) => bandwidths.len(), |
344 | | - Self::StepScaled(steps) => steps.len(), |
345 | | - _ => 1, |
346 | | - } |
347 | | - } |
348 | | - |
349 | | - /// Determines if the current scale should use post-clamping for Range mutations. |
350 | | - /// - Static Range: always post-clamp (for local search) |
351 | | - /// - RangeScaled: only post-clamp the final scale |
352 | | - /// - Step mutations: always clamp |
353 | | - /// - Others: not applicable |
354 | | - pub fn should_post_clamp(&self, current_scale_index: usize) -> bool { |
355 | | - match self { |
356 | | - Self::Range(_) => true, // Always post-clamp for static Range |
357 | | - Self::RangeScaled(bandwidths) => { |
358 | | - current_scale_index >= bandwidths.len().saturating_sub(1) // Final scale only |
359 | | - } |
360 | | - Self::Step(_) | Self::StepScaled(_) => true, // Always clamp steps |
361 | | - _ => false, |
362 | | - } |
363 | | - } |
364 | | - |
365 | | - /// Returns true if this is the final scale for scaled mutations |
366 | | - pub fn is_final_scale(&self, current_scale_index: usize) -> bool { |
367 | | - match self { |
368 | | - Self::RangeScaled(v) => current_scale_index >= v.len().saturating_sub(1), |
369 | | - Self::StepScaled(v) => current_scale_index >= v.len().saturating_sub(1), |
370 | | - _ => true, // Static mutations are always "final" |
371 | | - } |
372 | | - } |
373 | | - |
374 | | - /// Checks if this mutation is equivalent to Random behavior for the given allele range. |
375 | | - /// Useful for optimization - Random mutations can use more efficient sampling. |
376 | | - pub fn is_full_range( |
377 | | - &self, |
378 | | - allele_range: &RangeInclusive<T>, |
379 | | - current_scale_index: usize, |
380 | | - ) -> bool |
381 | | - where |
382 | | - T: PartialOrd + std::ops::Sub<Output = T> + Copy, |
383 | | - { |
384 | | - match self { |
385 | | - Self::Random | Self::Discrete => true, |
386 | | - Self::Range(bandwidth) => { |
387 | | - let range_width = *allele_range.end() - *allele_range.start(); |
388 | | - *bandwidth >= range_width |
389 | | - } |
390 | | - Self::RangeScaled(bandwidths) => { |
391 | | - let bandwidth = bandwidths |
392 | | - .get(current_scale_index.min(bandwidths.len().saturating_sub(1))) |
393 | | - .unwrap(); |
394 | | - let range_width = *allele_range.end() - *allele_range.start(); |
395 | | - *bandwidth >= range_width |
396 | | - } |
397 | | - _ => false, |
398 | | - } |
399 | | - } |
400 | | - |
401 | | - /// Returns true if this is a Range-type mutation (uniform sampling within bandwidth) |
402 | | - pub fn is_range_based(&self) -> bool { |
403 | | - matches!(self, Self::Range(_) | Self::RangeScaled(_)) |
404 | | - } |
405 | | - |
406 | | - /// Returns true if this is a Step-type mutation (discrete steps up or down) |
407 | | - pub fn is_step_based(&self) -> bool { |
408 | | - matches!(self, Self::Step(_) | Self::StepScaled(_)) |
409 | | - } |
410 | | -} |
0 commit comments