Skip to content

Commit 3007654

Browse files
committed
remove scale_index from chromosome_permutations_size(), simply add all ranges when multiple ranges
1 parent 0502b72 commit 3007654

20 files changed

+84
-93
lines changed

CHANGELOG.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919
* Scale down and repeat after grid is fully traversed
2020
* _Note: Not implemented for relative or random mutation types_
2121
* _Note: Not implemented for `DynamicMatrixGenotype` and
22-
`StaticMatrixGenotype`, as matrix has no use for permutation_
22+
`StaticMatrixGenotype`, as matrix has no use in permutation_
2323
* _Note: Scales should be symmetrical around zero, as always, but good to
2424
remember_
2525
* _Note: As an added benefit the generic `StrategyBuilder` with deferred
2626
specialization can now also be used for `RangeGenotype` and
2727
`MultiRangeGenotype`_
2828
* Keep track of `scale_generation` next to `current_generation` in
29-
`StrategyState`, resets every scale increment
29+
`StrategyState`, resets every scale increment, no use yet
3030
* Add `mutation_type_allows_permutation()` guard on `Genotype` and check in
3131
`Permutate` strategy builder
3232

3333
### Changed
34-
* Add `chromosome` and `scale_index` parameters to `PermutateGenotype` trait
35-
functions, ignore for all existing implementations
36-
* Use `scale_generation` in `PermutateReporterSimple` progress, resetting
37-
progress counter per scale
34+
* Add `chromosome` and `scale_index` parameters to `PermutateGenotype`
35+
`chromosome_permutations_into_iter()` function, ignore for all existing
36+
implementations, used by `RangeGenotype` and `MultiRangeGenotype`
3837

3938
## [0.20.4] - 2025-05-15
4039
### Fixed

examples/permutate_scrabble.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ impl StrategyReporter for CustomReporter {
237237
) {
238238
if state.current_generation() % self.0 == 0 {
239239
let progress = (BigUint::from(state.current_generation() * 100)
240-
/ &genotype.chromosome_permutations_size(None))
240+
/ &genotype.chromosome_permutations_size())
241241
.to_u8();
242242
println!(
243243
"progress: {}, current_generation: {}, best_generation: {}",

src/genotype.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ pub trait PermutateGenotype: Genotype {
237237
) -> Box<dyn Iterator<Item = Self::Chromosome> + Send + 'a>;
238238

239239
/// chromosome iterator size for the all possible gene combinations for [Permutate](crate::strategy::permutate::Permutate)
240-
fn chromosome_permutations_size(&self, _scale_index: Option<usize>) -> BigUint;
240+
fn chromosome_permutations_size(&self) -> BigUint;
241241

242242
/// not all mutation_types implemented for certain genotypes
243243
fn mutation_type_allows_permutation(&self) -> bool {

src/genotype/binary.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ impl PermutateGenotype for Binary {
254254
)
255255
}
256256
}
257-
fn chromosome_permutations_size(&self, _scale_index: Option<usize>) -> BigUint {
257+
fn chromosome_permutations_size(&self) -> BigUint {
258258
if self.seed_genes_list.is_empty() {
259259
BigUint::from(2u8).pow(self.genes_size() as u32)
260260
} else {
@@ -307,7 +307,7 @@ impl fmt::Display for Binary {
307307
writeln!(
308308
f,
309309
" chromosome_permutations_size: {}",
310-
self.chromosome_permutations_size(None)
310+
self.chromosome_permutations_size()
311311
)?;
312312
writeln!(
313313
f,

src/genotype/bit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ impl PermutateGenotype for Bit {
335335
)
336336
}
337337
}
338-
fn chromosome_permutations_size(&self, _scale_index: Option<usize>) -> BigUint {
338+
fn chromosome_permutations_size(&self) -> BigUint {
339339
if self.seed_genes_list.is_empty() {
340340
BigUint::from(2u8).pow(self.genes_size() as u32)
341341
} else {
@@ -388,7 +388,7 @@ impl fmt::Display for Bit {
388388
writeln!(
389389
f,
390390
" chromosome_permutations_size: {}",
391-
self.chromosome_permutations_size(None)
391+
self.chromosome_permutations_size()
392392
)?;
393393
writeln!(
394394
f,

src/genotype/list.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ impl<T: Allele + PartialEq + Hash> PermutateGenotype for List<T> {
296296
}
297297
}
298298

299-
fn chromosome_permutations_size(&self, _scale_index: Option<usize>) -> BigUint {
299+
fn chromosome_permutations_size(&self) -> BigUint {
300300
if self.seed_genes_list.is_empty() {
301301
BigUint::from(self.allele_list.len()).pow(self.genes_size() as u32)
302302
} else {
@@ -351,7 +351,7 @@ impl<T: Allele + PartialEq + Hash> fmt::Display for List<T> {
351351
writeln!(
352352
f,
353353
" chromosome_permutations_size: {}",
354-
self.chromosome_permutations_size(None)
354+
self.chromosome_permutations_size()
355355
)?;
356356
writeln!(
357357
f,

src/genotype/multi_list.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ impl<T: Allele + PartialEq + Hash> PermutateGenotype for MultiList<T> {
341341
}
342342
}
343343

344-
fn chromosome_permutations_size(&self, _scale_index: Option<usize>) -> BigUint {
344+
fn chromosome_permutations_size(&self) -> BigUint {
345345
if self.seed_genes_list.is_empty() {
346346
self.allele_list_sizes
347347
.iter()
@@ -403,7 +403,7 @@ impl<T: Allele + PartialEq + Hash> fmt::Display for MultiList<T> {
403403
writeln!(
404404
f,
405405
" chromosome_permutations_size: {}",
406-
self.chromosome_permutations_size(None)
406+
self.chromosome_permutations_size()
407407
)?;
408408
writeln!(
409409
f,

src/genotype/multi_range.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -609,14 +609,12 @@ where
609609
}
610610
}
611611

612-
fn chromosome_permutations_size(&self, scale_index: Option<usize>) -> BigUint {
612+
fn chromosome_permutations_size(&self) -> BigUint {
613613
if self.seed_genes_list.is_empty() {
614614
match self.mutation_type {
615-
MutationType::Scaled => self
616-
.permutable_allele_sizes_scaled(scale_index.unwrap())
617-
.iter()
618-
.map(|v| BigUint::from(*v))
619-
.product(),
615+
MutationType::Scaled => (0..self.max_scale_index().unwrap())
616+
.map(|scale_index| self.chromosome_permutations_size_scaled(scale_index))
617+
.sum(),
620618
MutationType::Relative => {
621619
panic!("RangeGenotype is not permutable for MutationType::Relative")
622620
}
@@ -857,11 +855,16 @@ where
857855
writeln!(f, " genes_size: {}", self.genes_size)?;
858856
writeln!(f, " mutation_type: {:?}", self.mutation_type)?;
859857

860-
if let Some(max_scale_index) = self.max_scale_index() {
861-
let sizes: Vec<BigUint> = (0..max_scale_index)
858+
if self.mutation_type_allows_permutation() {
859+
let size_per_scale: Vec<BigUint> = (0..self.max_scale_index().unwrap())
862860
.map(|scale_index| self.chromosome_permutations_size_scaled(scale_index))
863861
.collect();
864-
writeln!(f, " chromosome_permutations_size (per scale): {:?}", sizes)?;
862+
writeln!(
863+
f,
864+
" chromosome_permutations_size: {}, per scale {:?}",
865+
self.chromosome_permutations_size(),
866+
size_per_scale
867+
)?;
865868
} else {
866869
writeln!(f, " chromosome_permutations_size: uncountable")?;
867870
}

src/genotype/multi_unique.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ impl<T: Allele + Hash> PermutateGenotype for MultiUnique<T> {
358358
}
359359
}
360360

361-
fn chromosome_permutations_size(&self, _scale_index: Option<usize>) -> BigUint {
361+
fn chromosome_permutations_size(&self) -> BigUint {
362362
if self.seed_genes_list.is_empty() {
363363
self.allele_list_sizes
364364
.iter()
@@ -427,7 +427,7 @@ impl<T: Allele + Hash> fmt::Display for MultiUnique<T> {
427427
writeln!(
428428
f,
429429
" chromosome_permutations_size: {}",
430-
self.chromosome_permutations_size(None)
430+
self.chromosome_permutations_size()
431431
)?;
432432
writeln!(
433433
f,

src/genotype/range.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -550,13 +550,12 @@ where
550550
}
551551
}
552552

553-
fn chromosome_permutations_size(&self, scale_index: Option<usize>) -> BigUint {
553+
fn chromosome_permutations_size(&self) -> BigUint {
554554
if self.seed_genes_list.is_empty() {
555555
match self.mutation_type {
556-
MutationType::Scaled => {
557-
BigUint::from(self.permutable_allele_size_scaled(scale_index.unwrap()))
558-
.pow(self.genes_size() as u32)
559-
}
556+
MutationType::Scaled => (0..self.max_scale_index().unwrap())
557+
.map(|scale_index| self.chromosome_permutations_size_scaled(scale_index))
558+
.sum(),
560559
MutationType::Relative => {
561560
panic!("RangeGenotype is not permutable for MutationType::Relative")
562561
}
@@ -769,11 +768,16 @@ where
769768
writeln!(f, " genes_size: {}", self.genes_size)?;
770769
writeln!(f, " mutation_type: {:?}", self.mutation_type)?;
771770

772-
if let Some(max_scale_index) = self.max_scale_index() {
773-
let sizes: Vec<BigUint> = (0..max_scale_index)
771+
if self.mutation_type_allows_permutation() {
772+
let size_per_scale: Vec<BigUint> = (0..self.max_scale_index().unwrap())
774773
.map(|scale_index| self.chromosome_permutations_size_scaled(scale_index))
775774
.collect();
776-
writeln!(f, " chromosome_permutations_size (per scale): {:?}", sizes)?;
775+
writeln!(
776+
f,
777+
" chromosome_permutations_size: {}, per scale {:?}",
778+
self.chromosome_permutations_size(),
779+
size_per_scale
780+
)?;
777781
} else {
778782
writeln!(f, " chromosome_permutations_size: uncountable")?;
779783
}

0 commit comments

Comments
 (0)