Пример #1
0
        public void EnsureCrossoverTest()
        {
            TownHelper.Initialize();

            var individualA = new Individual(new List <int> {
                0, 9, 1, 8, 2, 7, 3, 6, 4, 5
            });
            var individualB = new Individual(new List <int> {
                0, 1, 2, 3, 4, 5, 6, 7, 8, 9
            });

            var crossoverPointA = 3;
            var crossoverPointB = 1;
            var crossoverPointC = 8;

            var childA = WorldHelper.DoCrossover(individualA, individualB, crossoverPointA);
            var childB = WorldHelper.DoCrossover(individualA, individualB, crossoverPointB);
            var childC = WorldHelper.DoCrossover(individualA, individualB, crossoverPointC);

            var expectedChildASequence = new List <int> {
                0, 9, 1, 2, 3, 4, 5, 6, 7, 8
            };
            var expectedChildBSequence = new List <int> {
                0, 1, 2, 3, 4, 5, 6, 7, 8, 9
            };
            var expectedChildCSequence = new List <int> {
                0, 9, 1, 8, 2, 7, 3, 6, 4, 5
            };

            Assert.IsTrue(childA.Sequence.SequenceEqual(expectedChildASequence));
            Assert.IsTrue(childB.Sequence.SequenceEqual(expectedChildBSequence));
            Assert.IsTrue(childC.Sequence.SequenceEqual(expectedChildCSequence));

            Assert.AreEqual(childA.Sequence.Count(), individualA.Sequence.Count());
            Assert.AreEqual(childB.Sequence.Count(), individualA.Sequence.Count());
            Assert.AreEqual(childC.Sequence.Count(), individualA.Sequence.Count());
        }
Пример #2
0
 private Individual DoCrossover(Individual individualA, Individual individualB)
 {
     return(WorldHelper.DoCrossover(individualA, individualB));
 }