public void ItWillRunMultipleGenerations()
        {
            var ga         = new OrderedGeneticAlgorithm(_configuration, _exampleGenes);
            var runDetails = ga.Run();

            Assert.AreEqual(_configuration.MaxGenerations, runDetails.CurrentGeneration);
        }
        public void ItSetsTheStartAndEndTimeOfARun()
        {
            var ga  = new OrderedGeneticAlgorithm(_configuration, _exampleGenes);
            var run = ga.Run();

            Assert.AreEqual(_configuration.MaxGenerations, run.CurrentGeneration);
            Assert.IsTrue(run.GetTotalMSToRun() >= 0);
        }
        public void ItReturnsAnObjectWithDetailsOfTheRun()
        {
            var ga  = new OrderedGeneticAlgorithm(_configuration, _exampleGenes);
            var run = ga.Run();

            Assert.AreEqual(_configuration.MaxGenerations, run.CurrentGeneration);
            Assert.AreNotEqual(-1, run.BestChromosome.FitnessScore);
        }
        public override GARun Run(GAConfiguration configuration)
        {
            Configuration = configuration;

            var options = GetOptions();

            GeneticAlgorithm = new OrderedGeneticAlgorithm(Configuration, options);
            return(GeneticAlgorithm.Run());
        }
        public void ItIsRepeatable()
        {
            var ga         = new OrderedGeneticAlgorithm(_configuration, _exampleGenes);
            var runDetails = ga.Run();

            Assert.AreEqual(_configuration.MaxGenerations, runDetails.CurrentGeneration);

            Assert.AreEqual(LastName.Bernard, runDetails.BestChromosome.LastName);
            Assert.AreEqual(80, runDetails.BestChromosome.FitnessScore);
        }
Beispiel #6
0
        private void RunOrderedConfiguration(GAConfiguration config)
        {
            if (!config.IsOrderedConfiguration())
            {
                return;
            }

            var solution = (JarrusOrderedSolution)config.Solution;

            var data = solution.GetOptions();
            var ga   = new OrderedGeneticAlgorithm(config, data);

            Config = config;
            GARun  = ga.GARun;
            RunConfiguration(ga);
        }
        public void ItKeepsTrackOfTheBestScore()
        {
            var ga         = new OrderedGeneticAlgorithm(_configuration, _exampleGenes);
            var runDetails = ga.Run();

            Assert.AreEqual(_configuration.MaxGenerations, runDetails.CurrentGeneration);

            Assert.AreEqual(LastName.Bernard, runDetails.BestChromosome.LastName);
            Assert.AreEqual(FirstName.Anakin, runDetails.BestChromosome.FirstName);
            Assert.AreEqual(80, runDetails.BestChromosome.FitnessScore);

            var lowest       = runDetails.Population.Chromosomes.Select(o => o.FitnessScore).Min();
            var lastBestSeen = runDetails.Population.Chromosomes.Where(o => o.FitnessScore == lowest).First();

            Assert.AreEqual(LastName.Strickland, lastBestSeen.LastName);
            Assert.AreEqual(FirstName.Aylin, lastBestSeen.FirstName);
        }
 public void ItHasAValidConstructor()
 {
     var ga = new OrderedGeneticAlgorithm(_configuration, _exampleGenes);
 }
 public void ItThrowsAnExceptionIfTheGeneLengthIsInvalid()
 {
     var ga = new OrderedGeneticAlgorithm(_configuration, _exampleGenes.Subset(0, 1));
 }
 public void ItThrowsAnExceptionIfTheGenesAreNotSet()
 {
     var ga = new OrderedGeneticAlgorithm(_configuration);
 }
 public void ItThrowsAnExceptionIfTheConfigurationIsNotSet()
 {
     var ga = new OrderedGeneticAlgorithm(null, _exampleGenes);
 }