Skip to content

Commit b26fb53

Browse files
committed
note use of populations methods for chromosome recycling
Add API impact
1 parent a80fc9f commit b26fb53

5 files changed

Lines changed: 27 additions & 21 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ these mainly work with the chromosome metadata and are not genotype specific.
4848

4949
General usage by client has little impact, most is internal.
5050

51+
### API Impact
52+
* Replace `BinaryChromosome` with `Chromosome<bool>`
53+
* Remove all other `Chromosome` struct genotype specific prefixes (e.g. `ListChromosome<..>` -> `Chromosome<..>`)
54+
* Use `genetic_algorithm::impl_allele!(CustomAllele);` to implement `Allele` for your CustomAllele
55+
5156
### Changed
5257
* Add associated type `Genotype` to `Mutate` and `Crossover` traits (following
5358
existing `Fitness` pattern).

examples/evolve_scrabble.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use genetic_algorithm::strategy::evolve::prelude::*;
22
use std::collections::{HashMap, HashSet};
3-
use std::hash::{Hash, Hasher};
3+
use std::hash::Hash;
44

55
type Row = usize;
66
type Column = usize;
@@ -13,12 +13,12 @@ pub enum Orientation {
1313

1414
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
1515
pub struct WordPosition(pub Row, pub Column, pub Orientation);
16-
impl Allele for WordPosition {
17-
fn hash_slice(slice: &[Self], hasher: &mut impl Hasher) {
18-
slice.hash(hasher);
19-
}
20-
}
21-
// or genetic_algorithm::impl_allele!(WordPosition)
16+
genetic_algorithm::impl_allele!(WordPosition);
17+
// impl Allele for WordPosition {
18+
// fn hash_slice(slice: &[Self], hasher: &mut impl Hasher) {
19+
// slice.hash(hasher);
20+
// }
21+
// }
2222

2323
#[derive(Clone, Debug)]
2424
struct ScrabbleFitness {

examples/hill_climb_scrabble.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use genetic_algorithm::strategy::hill_climb::prelude::*;
22
use std::collections::{HashMap, HashSet};
3-
use std::hash::{Hash, Hasher};
3+
use std::hash::Hash;
44

55
type Row = usize;
66
type Column = usize;
@@ -13,12 +13,12 @@ pub enum Orientation {
1313

1414
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
1515
struct WordPosition(pub Row, pub Column, pub Orientation);
16-
impl Allele for WordPosition {
17-
fn hash_slice(slice: &[Self], hasher: &mut impl Hasher) {
18-
slice.hash(hasher);
19-
}
20-
}
21-
// or genetic_algorithm::impl_allele!(WordPosition)
16+
genetic_algorithm::impl_allele!(WordPosition);
17+
// impl Allele for WordPosition {
18+
// fn hash_slice(slice: &[Self], hasher: &mut impl Hasher) {
19+
// slice.hash(hasher);
20+
// }
21+
// }
2222

2323
#[derive(Clone, Debug)]
2424
struct ScrabbleFitness {

examples/permutate_scrabble.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use genetic_algorithm::strategy::permutate::prelude::*;
22
use num::{BigUint, ToPrimitive};
33
use std::collections::{HashMap, HashSet};
4-
use std::hash::{Hash, Hasher};
4+
use std::hash::Hash;
55

66
type Row = usize;
77
type Column = usize;
@@ -14,12 +14,12 @@ pub enum Orientation {
1414

1515
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
1616
pub struct WordPosition(pub Row, pub Column, pub Orientation);
17-
impl Allele for WordPosition {
18-
fn hash_slice(slice: &[Self], hasher: &mut impl Hasher) {
19-
slice.hash(hasher);
20-
}
21-
}
22-
// or genetic_algorithm::impl_allele!(WordPosition)
17+
genetic_algorithm::impl_allele!(WordPosition);
18+
// impl Allele for WordPosition {
19+
// fn hash_slice(slice: &[Self], hasher: &mut impl Hasher) {
20+
// slice.hash(hasher);
21+
// }
22+
// }
2323

2424
#[derive(Clone, Debug)]
2525
struct ScrabbleFitness {

src/crossover.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ pub type CrossoverEvolveState<C> = EvolveState<<C as Crossover>::Genotype>;
7878
/// (existing_population_size as f32 * self.selection_rate).ceil() as usize;
7979
///
8080
/// // Important!!! Append offspring as recycled clones from parents (will crossover later)
81+
/// // Use population's methods for safe chromosome recycling
8182
/// state.population.extend_from_within(selected_population_size);
8283
///
8384
/// // Skip the parents, iterate over the freshly appended offspring

0 commit comments

Comments
 (0)