示例#1
0
        public void RenewPopulation_EngineNotStated_ThrowException()
        {
            var engine =
                new TestGeneticSearchEngineBuilder(2, 4, new TestPopulationManager(new double[] { 2, 2 })).Build();

            engine.RenewPopulation(0.5);
            Assert.Fail("Should have thrown an exception by now");
        }
示例#2
0
        public void RenewPopulation_BedPercentage_ThrowException(double percentage)
        {
            var engine =
                new TestGeneticSearchEngineBuilder(2, 4, new TestPopulationManager(new double[] { 2, 2 })).Build();

            engine.Next();

            engine.RenewPopulation(percentage);
            Assert.Fail("Should have thrown an exception by now");
        }
示例#3
0
        public void RenewPopulation_EngineRunning_ThrowException()
        {
            using (var engine =
                       new TestGeneticSearchEngineBuilder(2, int.MaxValue, new TestPopulationManager(new double[] { 2, 2 })).Build())
            {
                Task.Run(() => engine.Run());
                Thread.Sleep(50); // Give the eingine some time to start

                engine.RenewPopulation(0.5);
                Assert.Fail("Should have thrown an exception by now");
            }
        }
示例#4
0
        public void RenewPercantagePopulation_PercentageRenewed(double percent)
        {
            var populationManager = new TestPopulationManager(new double[] { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 });

            populationManager.SetPopulationGenerated(new[] { new double[] { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 } });
            var engine =
                new TestGeneticSearchEngineBuilder(10, int.MaxValue, populationManager).Build();

            engine.Next();

            var result        = engine.RenewPopulation(percent);
            var threeCounters = result.Population.Count(chromosme => chromosme.Evaluation == 3);

            Assert.AreEqual(percent * 10, threeCounters);
        }
示例#5
0
        public void RenewPopulation_CheckPopulationRenewedSentToNextGeneration()
        {
            var populationManager = new TestPopulationManager(new double[] { 2, 2 }, c => c.Evaluate() + 1);

            populationManager.SetPopulationGenerated(new[] { new double[] { 3, 3 } });
            var engine =
                new TestGeneticSearchEngineBuilder(2, int.MaxValue, populationManager).Build();

            engine.Next();
            engine.RenewPopulation(1);
            var result = engine.Next();

            foreach (var chromosme in result.Population)
            {
                Assert.AreEqual(4, chromosme.Evaluation);
            }
        }