RSMutator extends Mutator<G, C> { @Override protected MutatorResult<Chromosome<G>> mutate( final Chromosome<G> chromosome, final double p, final Random random ) { final MutatorResult<Chromosome<G>> result; if (chromosome.length() > 1) { final int[] points = Combinatorics.subset(chromosome.length() + 1, 2); final MSeq<G> genes = MSeq.of(chromosome); genes.subSeq(points[0], points[1]).reverse(); result = MutatorResult.of( chromosome.newInstance(genes.toISeq()), points[1] - points[0] - 1 ); } else { result = MutatorResult.of(chromosome); } return result; } RSMutator(final double probability);  RSMutator();   }
@Test(invocationCount = 10) public void mutate() { final PermutationChromosome<Integer> original = PermutationChromosome.ofInteger(50); final RSMutator<EnumGene<Integer>, Integer> mutator = new RSMutator<>(1.0); final MutatorResult<Chromosome<EnumGene<Integer>>> result = mutator.mutate(original, 1, new Random()); final int[] a = original.stream() .mapToInt(EnumGene::allele) .toArray(); final int[] b = result.result().stream() .mapToInt(EnumGene::allele) .toArray(); Assert.assertEquals( result.mutations(), endIndex(a, b) - startIndex(a, b) ); }