@Override protected int crossover(final MSeq<G> that, final MSeq<G> other) { final Random random = RandomRegistry.getRandom(); final int index = random.nextInt(min(that.length(), other.length())); crossover(that, other, index); return 2; }
@Test public void singlePointCrossoverConsistency() { final ISeq<Character> a = CharSeq.toISeq("1234567890"); final ISeq<Character> b = CharSeq.toISeq("ABCDEFGHIJ"); for (int i = 0; i < a.length() + 1; ++i) { final MSeq<Character> ma1 = a.copy(); final MSeq<Character> mb1 = b.copy(); final MSeq<Character> ma2 = a.copy(); final MSeq<Character> mb2 = b.copy(); MultiPointCrossover.crossover(ma1, mb1, new int[]{i}); SinglePointCrossover.crossover(ma2, mb2, i); Assert.assertEquals(ma1, ma2); Assert.assertEquals(mb1, mb2); } }
crossover.crossover(g1c, g2c); MSeq<CharacterGene> g1c2 = g1.copy(); MSeq<CharacterGene> g2c2 = g2.copy(); crossover.crossover(g1c2, g2c2); Assert.assertEquals(g1c2, g2); Assert.assertEquals(g2c2, g1); MSeq<CharacterGene> g1c3 = g1.copy(); MSeq<CharacterGene> g2c3 = g2.copy(); crossover.crossover(g1c3, g2c3); Assert.assertEquals(g1c3.subSeq(0, rv3), g1.subSeq(0, rv3)); Assert.assertEquals(g1c3.subSeq(rv3), g2.subSeq(rv3)); MSeq<CharacterGene> g1c4 = g1.copy(); MSeq<CharacterGene> g2c4 = g2.copy(); crossover.crossover(g1c4, g2c); Assert.assertEquals(g1c4, g1); Assert.assertEquals(g2c4, g2);