@@ 38,6 38,58 @@ where
}
}
+pub struct BinaryStringSingleBitPerturbation<D> {
+ _phantom: PhantomData<D>
+}
+
+impl<D> BinaryStringSingleBitPerturbation<D> {
+ pub fn new() -> Self {
+ Self {
+ _phantom: PhantomData
+ }
+ }
+}
+
+impl<D> PerturbationOperator for BinaryStringSingleBitPerturbation<D>
+where
+ D: Dim,
+ DefaultAllocator: Allocator<D>
+{
+ type Chromosome = BinaryString<D>;
+
+ fn perturb(&self, chromosome: &mut Self::Chromosome, rng: &mut dyn RngCore) {
+ let bit_range = 0..chromosome.vec.len();
+ let flip_bit = rng.random_range(bit_range);
+
+ chromosome.vec[flip_bit] = 1 - chromosome.vec[flip_bit];
+ }
+}
+
+pub struct BinaryStringFlipPerturbation<D> {
+ _phantom: PhantomData<D>
+}
+
+impl<D> BinaryStringFlipPerturbation<D> {
+ pub fn new() -> Self {
+ Self {
+ _phantom: PhantomData
+ }
+ }
+}
+
+impl<D> PerturbationOperator for BinaryStringFlipPerturbation<D>
+where
+ D: Dim,
+ DefaultAllocator: Allocator<D>
+{
+ type Chromosome = BinaryString<D>;
+
+ fn perturb(&self, chromosome: &mut Self::Chromosome, _: &mut dyn RngCore) {
+ chromosome.vec
+ .apply(|c| *c = 1 - *c);
+ }
+}
+
pub struct RandomDistributionPerturbation<const LEN: usize, TDistribution: Distribution<f64>> {
distribution: TDistribution,
parameter: f64