コード例 #1
0
        public void EnsureCandidateParentsUniqueTest()
        {
            var population = DefaultPopulationHelper.GetTestPopulation();

            for (int i = 0; i < 10; i++)
            {
                var(candidateA, candidateB) = WorldHelper.GetCandidateParents(population);

                Assert.IsFalse(candidateA.Sequence.SequenceEqual(candidateB.Sequence));
            }
        }
コード例 #2
0
        public void EnsureRankTest()
        {
            var population = DefaultPopulationHelper.GetTestPopulation();

            MultiObjectiveHelper.UpdatePopulationFitness(population);

            Assert.AreEqual(population[0].Rank, 1);
            Assert.AreEqual(population[1].Rank, 1);
            Assert.AreEqual(population[2].Rank, 1);

            Assert.AreEqual(population[3].Rank, 2);
            Assert.AreEqual(population[4].Rank, 2);
            Assert.AreEqual(population[5].Rank, 2);

            Assert.AreEqual(population[6].Rank, 3);
        }
コード例 #3
0
        public void EnsureCrowdingDistanceTest()
        {
            double epsilon    = 0.00001;
            var    population = DefaultPopulationHelper.GetTestPopulation();

            MultiObjectiveHelper.UpdatePopulationFitness(population);

            Assert.IsTrue(double.IsPositiveInfinity(population[0].CrowdingDistance));
            Assert.IsTrue(Math.Abs(population[1].CrowdingDistance - 0.9428089) < epsilon);
            Assert.IsTrue(double.IsPositiveInfinity(population[2].CrowdingDistance));

            Assert.IsTrue(double.IsPositiveInfinity(population[3].CrowdingDistance));
            Assert.IsTrue(Math.Abs(population[4].CrowdingDistance - 0.9428089) < epsilon);
            Assert.IsTrue(double.IsPositiveInfinity(population[5].CrowdingDistance));

            Assert.IsTrue(double.IsPositiveInfinity(population[6].CrowdingDistance));
        }
コード例 #4
0
        public void EnsureCrowdingDistanceTournamentSelectionTest()
        {
            var population = DefaultPopulationHelper.GetTestPopulation();

            MultiObjectiveHelper.UpdatePopulationFitness(population);

            // Rank 1, float.MaxValue crowding distance
            var individualA = population[0];

            // Rank 1, ~5.65 crowding distance
            var individualB = population[1];

            var fitterIndividualA = WorldHelper.TournamentSelection(individualA, individualB);
            var fitterIndividualB = WorldHelper.TournamentSelection(individualB, individualA);

            Assert.AreEqual(individualA, fitterIndividualA);
            Assert.AreEqual(individualA, fitterIndividualB);
        }
コード例 #5
0
        public void EnsureRankedTournamentSelectionTest()
        {
            var population = DefaultPopulationHelper.GetTestPopulation();

            MultiObjectiveHelper.UpdatePopulationFitness(population);

            // Rank 1
            var individualA = population[1];

            // Rank 2
            var individualB = population[3];

            var fitterIndividualA = WorldHelper.TournamentSelection(individualA, individualB);
            var fitterIndividualB = WorldHelper.TournamentSelection(individualB, individualA);

            Assert.AreEqual(individualA, fitterIndividualA);
            Assert.AreEqual(individualA, fitterIndividualB);
        }