@@ -25,23 +25,20 @@ public class CycleCrossoverTest {
2525
2626 @ Test
2727 public void testCrossoverExample () {
28- // taken from
29- // http://www.rubicite.com/Tutorials/GeneticAlgorithms/CrossoverOperators/CycleCrossoverOperator.aspx
30- final Integer [] p1 = new Integer [] {8 , 4 , 7 , 3 , 6 , 2 , 5 , 1 , 9 , 0 };
31- final Integer [] p2 = new Integer [] {0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 };
28+ // taken from http://www.rubicite.com/Tutorials/GeneticAlgorithms/CrossoverOperators/CycleCrossoverOperator.aspx
29+ final Integer [] p1 = new Integer [] { 8 , 4 , 7 , 3 , 6 , 2 , 5 , 1 , 9 , 0 };
30+ final Integer [] p2 = new Integer [] { 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 };
3231 final DummyListChromosome p1c = new DummyListChromosome (p1 );
3332 final DummyListChromosome p2c = new DummyListChromosome (p2 );
3433
3534 final CrossoverPolicy cp = new CycleCrossover <Integer >();
3635 final ChromosomePair pair = cp .crossover (p1c , p2c );
3736
38- final Integer [] c1 = ((DummyListChromosome ) pair .getFirst ()).getRepresentation ()
39- .toArray (new Integer [p1 .length ]);
40- final Integer [] c2 = ((DummyListChromosome ) pair .getSecond ()).getRepresentation ()
41- .toArray (new Integer [p2 .length ]);
37+ final Integer [] c1 = ((DummyListChromosome ) pair .getFirst ()).getRepresentation ().toArray (new Integer [p1 .length ]);
38+ final Integer [] c2 = ((DummyListChromosome ) pair .getSecond ()).getRepresentation ().toArray (new Integer [p2 .length ]);
4239
43- final Integer [] c1e = new Integer [] {8 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 9 , 0 };
44- final Integer [] c2e = new Integer [] {0 , 4 , 7 , 3 , 6 , 2 , 5 , 1 , 8 , 9 };
40+ final Integer [] c1e = new Integer [] { 8 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 9 , 0 };
41+ final Integer [] c2e = new Integer [] { 0 , 4 , 7 , 3 , 6 , 2 , 5 , 1 , 8 , 9 };
4542
4643 Assert .assertArrayEquals (c1e , c1 );
4744 Assert .assertArrayEquals (c2e , c2 );
@@ -50,30 +47,28 @@ public void testCrossoverExample() {
5047 @ Test
5148 public void testCrossoverExample2 () {
5249 // taken from http://www.scribd.com/doc/54206412/32/Cycle-crossover
53- final Integer [] p1 = new Integer [] {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 };
54- final Integer [] p2 = new Integer [] {9 , 3 , 7 , 8 , 2 , 6 , 5 , 1 , 4 };
50+ final Integer [] p1 = new Integer [] { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 };
51+ final Integer [] p2 = new Integer [] { 9 , 3 , 7 , 8 , 2 , 6 , 5 , 1 , 4 };
5552 final DummyListChromosome p1c = new DummyListChromosome (p1 );
5653 final DummyListChromosome p2c = new DummyListChromosome (p2 );
5754
5855 final CrossoverPolicy cp = new CycleCrossover <Integer >();
5956 final ChromosomePair pair = cp .crossover (p1c , p2c );
6057
61- final Integer [] c1 = ((DummyListChromosome ) pair .getFirst ()).getRepresentation ()
62- .toArray (new Integer [p1 .length ]);
63- final Integer [] c2 = ((DummyListChromosome ) pair .getSecond ()).getRepresentation ()
64- .toArray (new Integer [p2 .length ]);
58+ final Integer [] c1 = ((DummyListChromosome ) pair .getFirst ()).getRepresentation ().toArray (new Integer [p1 .length ]);
59+ final Integer [] c2 = ((DummyListChromosome ) pair .getSecond ()).getRepresentation ().toArray (new Integer [p2 .length ]);
6560
66- final Integer [] c1e = new Integer [] {1 , 3 , 7 , 4 , 2 , 6 , 5 , 8 , 9 };
67- final Integer [] c2e = new Integer [] {9 , 2 , 3 , 8 , 5 , 6 , 7 , 1 , 4 };
61+ final Integer [] c1e = new Integer [] { 1 , 3 , 7 , 4 , 2 , 6 , 5 , 8 , 9 };
62+ final Integer [] c2e = new Integer [] { 9 , 2 , 3 , 8 , 5 , 6 , 7 , 1 , 4 };
6863
6964 Assert .assertArrayEquals (c1e , c1 );
7065 Assert .assertArrayEquals (c2e , c2 );
7166 }
7267
7368 @ Test
7469 public void testCrossover () {
75- final Integer [] p1 = new Integer [] {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 };
76- final Integer [] p2 = new Integer [] {10 , 9 , 8 , 7 , 6 , 5 , 4 , 3 , 2 , 1 };
70+ final Integer [] p1 = new Integer [] { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 };
71+ final Integer [] p2 = new Integer [] { 10 , 9 , 8 , 7 , 6 , 5 , 4 , 3 , 2 , 1 };
7772 final DummyListChromosome p1c = new DummyListChromosome (p1 );
7873 final DummyListChromosome p2c = new DummyListChromosome (p2 );
7974
@@ -82,10 +77,8 @@ public void testCrossover() {
8277 for (int i = 0 ; i < 20 ; i ++) {
8378 final ChromosomePair pair = cp .crossover (p1c , p2c );
8479
85- final Integer [] c1 = ((DummyListChromosome ) pair .getFirst ()).getRepresentation ()
86- .toArray (new Integer [p1 .length ]);
87- final Integer [] c2 = ((DummyListChromosome ) pair .getSecond ()).getRepresentation ()
88- .toArray (new Integer [p2 .length ]);
80+ final Integer [] c1 = ((DummyListChromosome ) pair .getFirst ()).getRepresentation ().toArray (new Integer [p1 .length ]);
81+ final Integer [] c2 = ((DummyListChromosome ) pair .getSecond ()).getRepresentation ().toArray (new Integer [p2 .length ]);
8982
9083 int index = 0 ;
9184 // Determine if it is in the same spot as in the first parent, if
@@ -114,8 +107,8 @@ public void testCrossover() {
114107
115108 @ Test (expected = DimensionMismatchException .class )
116109 public void testCrossoverDimensionMismatchException () {
117- final Integer [] p1 = new Integer [] {1 , 0 , 1 , 0 , 0 , 1 , 0 , 1 , 1 };
118- final Integer [] p2 = new Integer [] {0 , 1 , 1 , 0 , 1 };
110+ final Integer [] p1 = new Integer [] { 1 , 0 , 1 , 0 , 0 , 1 , 0 , 1 , 1 };
111+ final Integer [] p2 = new Integer [] { 0 , 1 , 1 , 0 , 1 };
119112
120113 final BinaryChromosome p1c = new DummyBinaryChromosome (p1 );
121114 final BinaryChromosome p2c = new DummyBinaryChromosome (p2 );
@@ -126,7 +119,7 @@ public void testCrossoverDimensionMismatchException() {
126119
127120 @ Test (expected = MathIllegalArgumentException .class )
128121 public void testCrossoverInvalidFixedLengthChromosomeFirst () {
129- final Integer [] p1 = new Integer [] {1 , 0 , 1 , 0 , 0 , 1 , 0 , 1 , 1 };
122+ final Integer [] p1 = new Integer [] { 1 , 0 , 1 , 0 , 0 , 1 , 0 , 1 , 1 };
130123 final BinaryChromosome p1c = new DummyBinaryChromosome (p1 );
131124 final Chromosome p2c = new Chromosome () {
132125 @ Override
@@ -142,7 +135,7 @@ public double fitness() {
142135
143136 @ Test (expected = MathIllegalArgumentException .class )
144137 public void testCrossoverInvalidFixedLengthChromosomeSecond () {
145- final Integer [] p1 = new Integer [] {1 , 0 , 1 , 0 , 0 , 1 , 0 , 1 , 1 };
138+ final Integer [] p1 = new Integer [] { 1 , 0 , 1 , 0 , 0 , 1 , 0 , 1 , 1 };
146139 final BinaryChromosome p2c = new DummyBinaryChromosome (p1 );
147140 final Chromosome p1c = new Chromosome () {
148141 @ Override
0 commit comments