public void HasReached_StagnantButNotReachTheGenerationsNumber_False()
        {
            var target     = new FitnessStagnationTermination(4);
            var repository = new MockRepository();
            var ga         = repository.StrictMock <IGeneticAlgorithm>();

            using (repository.Ordered())
            {
                ga.Expect(g => g.BestChromosome).Return(new ChromosomeStub()
                {
                    Fitness = 0.1
                });
                ga.Expect(g => g.BestChromosome).Return(new ChromosomeStub()
                {
                    Fitness = 0.1
                });
                ga.Expect(g => g.BestChromosome).Return(new ChromosomeStub()
                {
                    Fitness = 0.1
                });
            }
            repository.ReplayAll();

            Assert.IsFalse(target.HasReached(ga));
            Assert.IsFalse(target.HasReached(ga));
            Assert.IsFalse(target.HasReached(ga));
        }
Example #2
0
        public void HasReached_StagnantAndReachGenerationNumber_True()
        {
            var target = new FitnessStagnationTermination(3);
            var ga     = Substitute.For <IGeneticAlgorithm>();

            ga.BestChromosome.Returns(new ChromosomeStub()
            {
                Fitness = 0.2
            },
                                      new ChromosomeStub()
            {
                Fitness = 0.2
            },
                                      new ChromosomeStub()
            {
                Fitness = 0.3
            },
                                      new ChromosomeStub()
            {
                Fitness = 0.3
            },
                                      new ChromosomeStub()
            {
                Fitness = 0.3
            });

            Assert.IsFalse(target.HasReached(ga));
            Assert.IsFalse(target.HasReached(ga));
            Assert.IsFalse(target.HasReached(ga));
            Assert.IsFalse(target.HasReached(ga));
            Assert.IsTrue(target.HasReached(ga));
        }
        public ITermination FitnessStagnation()
        {
            var target = new FitnessStagnationTermination(2);
            var ga     = Substitute.For <IGeneticAlgorithm>();

            ga.BestChromosome.Returns(new TspChromosome(10)
            {
                Fitness = 1
            });
            target.HasReached(ga);
            target.HasReached(ga);

            return(target);
        }
Example #4
0
        public void HasReached_StagnantButNotReachTheGenerationsNumber_False()
        {
            var target = new FitnessStagnationTermination(4);
            var ga     = Substitute.For <IGeneticAlgorithm>();

            ga.BestChromosome.Returns(
                new ChromosomeStub()
            {
                Fitness = 0.1
            },
                new ChromosomeStub()
            {
                Fitness = 0.1
            },
                new ChromosomeStub()
            {
                Fitness = 0.1
            });

            Assert.IsFalse(target.HasReached(ga));
            Assert.IsFalse(target.HasReached(ga));
            Assert.IsFalse(target.HasReached(ga));
        }