public void ItHasAValidConstructor()
        {
            var parentSelection = new StochasticUniversalSamplingSelection();

            parentSelection.Setup(_pool, GATestHelper.GetTravelingSalesmanDefaultConfiguration());
            parentSelection.GetParents();
        }
Example #2
0
        public void ItsConstructorsCanSetTheStrategies()
        {
            var task     = GATestHelper.GetDummyTravelingSalesmanTask();
            var settings = new GAConfiguration(task);

            Assert.IsTrue(settings.IsValid());
        }
Example #3
0
        public void ItThrowsAnErrorIfOutOfRange()
        {
            var chromosome = GATestHelper.GetAlphabetCharacterChromosome();
            var mutation   = new InsertMutation();

            mutation.Shift(chromosome, -1, 4);
        }
        public void ItHasAValidConstructor()
        {
            var parentSelection = new RouletteWheelSelection();

            parentSelection.Setup(_pool, GATestHelper.GetTravelingSalesmanDefaultConfiguration());
            parentSelection.GetParents();
        }
        public void ItCanDetermineIfObjectsAreEqualByContentOfGenes()
        {
            var one = GATestHelper.GetAlphabetCharacterChromosome();
            var two = GATestHelper.GetAlphabetCharacterChromosome();

            Assert.AreEqual(one, two);
        }
Example #6
0
        public void ItConstructsProperlyIfAllFitnessScoresAreAboveOrEqualToZero()
        {
            var genome          = GATestHelper.GetTravelingSalesmanPopulation();
            var parentSelection = new RouletteWheelSelection();

            parentSelection.Setup(genome, GATestHelper.GetTravelingSalesmanDefaultConfiguration());
        }
Example #7
0
        public void ItErrorsIfEndIsSameAsStart()
        {
            var chromosome = GATestHelper.GetAlphabetCharacterChromosome();
            var mutation   = new ScrambleMutation();

            mutation.Scramble(chromosome, 2, 2, GATestHelper.GetTravelingSalesmanDefaultConfiguration());
        }
Example #8
0
        public void ItErrorsIfTheIndexesAreOutOfRange()
        {
            var chromosome = GATestHelper.GetAlphabetCharacterChromosome();
            var mutation   = new InversionMutation();

            mutation.Inverse(chromosome, -1, 1);
        }
Example #9
0
        public void ItAllowsAValidParentSelectionType()
        {
            var task = GATestHelper.GetDummyTravelingSalesmanTask();

            task.ParentSelectionStrategy = ParentSelectionStrategy.RouletteWheel;
            var settings = new GAConfiguration(task);
        }
Example #10
0
        public void ItHasAValidConstructor()
        {
            var population = new OrderedPopulation(GATestHelper.GetTravelingSalesmanDefaultConfiguration(), _pool, _possibleValues);

            Assert.IsNotNull(population.Configuration);
            Assert.IsNotNull(population.Chromosomes);
        }
Example #11
0
        public void ItAllowsAValidImmigrationType()
        {
            var task = GATestHelper.GetDummyTravelingSalesmanTask();

            task.ImmigrationStrategy = ImmigrationStrategy.Constant;
            var settings = new GAConfiguration(task);
        }
Example #12
0
        public void ItAllowsAValidMutationType()
        {
            var task = GATestHelper.GetDummyTravelingSalesmanTask();

            task.MutationStrategy = MutationStrategy.Boundary;
            var settings = new GAConfiguration(task);
        }
Example #13
0
        public void ItThrowsAnExceptionIfCrossoverRateIsAboveOne()
        {
            var config = GATestHelper.GetTravelingSalesmanDefaultConfiguration();

            config.CrossoverRate = 1.01;
            config.ValidateProperties();
        }
Example #14
0
        public void ItThrowsAnExceptionIfElitismRateIsBelowZero()
        {
            var config = GATestHelper.GetTravelingSalesmanDefaultConfiguration();

            config.ElitismRate = -0.01;
            config.ValidateProperties();
        }
Example #15
0
        public void ItAllowsAValidCrossoverType()
        {
            var task = GATestHelper.GetDummyTravelingSalesmanTask();

            task.CrossoverStrategy = CrossoverStrategy.AlternatingPosition;
            var settings = new GAConfiguration(task);
        }
Example #16
0
        public void ItDoesNotAllowsAnInvalidCrossoverType()
        {
            var task = GATestHelper.GetDummyTravelingSalesmanTask();

            task.CrossoverStrategy = 0;
            var settings = new GAConfiguration(task);
        }
Example #17
0
        public void ItErrorsIfTheIndexesAreOutOfRange()
        {
            var chromosome = GATestHelper.GetAlphabetCharacterChromosome();
            var mutation   = new ScrambleMutation();

            mutation.Scramble(chromosome, -1, 1, GATestHelper.GetTravelingSalesmanDefaultConfiguration());
        }
Example #18
0
        public void ItsConstructorDeterminesTheGeneSize()
        {
            var random       = GATestHelper.GetRandomInteger(1, 255);
            var doubleChromo = new OrderedChromosome(random);

            Assert.AreEqual(random, doubleChromo.Genes.Length);
        }
Example #19
0
        public void ItDoesNotAllowsAnInvalidParentSelectionType()
        {
            var task = GATestHelper.GetDummyTravelingSalesmanTask();

            task.ParentSelectionStrategy = 0;
            var settings = new GAConfiguration(task);
        }
Example #20
0
        public void ItAllowsAValidRetirementType()
        {
            var task = GATestHelper.GetDummyTravelingSalesmanTask();

            task.RetirementStrategy = RetirementStrategy.MaxChildren;
            var settings = new GAConfiguration(task);
        }
Example #21
0
        public void ItThrowsAnExceptionIfOutOfRange()
        {
            var chromosome = GATestHelper.GetAlphabetCharacterChromosome();
            var mutation   = new SwapMutation();

            mutation.FlipGenes(chromosome, -1, 2);
        }
Example #22
0
        public void ItAllowsRetirementTypeMaxChildrenWhenRetirementMaximumIsAboveOne()
        {
            var task = GATestHelper.GetDummyTravelingSalesmanTask();

            task.RetirementStrategy = RetirementStrategy.MaxChildren;
            task.MaxRetirement      = 2;
            var settings = new GAConfiguration(task);
        }
Example #23
0
        public void ItCanFlipGenes()
        {
            var chromosome = GATestHelper.GetAlphabetCharacterChromosome();
            var mutation   = new SwapMutation();

            mutation.FlipGenes(chromosome, 1, 2);
            Assert.AreEqual("A,C,B,D,E,F,G,H,I,J", chromosome.ToString());
        }
Example #24
0
        public void ItAllowsRetirementTypeNoneWhenRetirementMaximumIsBelowZero()
        {
            var task = GATestHelper.GetDummyTravelingSalesmanTask();

            task.RetirementStrategy = RetirementStrategy.None;
            task.MaxRetirement      = 1;
            var settings = new GAConfiguration(task);
        }
Example #25
0
        public void ItCanAdvanceToTheNextGeneration()
        {
            var population = new OrderedPopulation(GATestHelper.GetTravelingSalesmanDefaultConfiguration(), _pool, _possibleValues);
            var nextGen    = population.Advance();

            Assert.AreEqual(0, population.GenerationNumber);
            Assert.AreEqual(1, nextGen.GenerationNumber);
        }
Example #26
0
        public void ItThrowsAnExceptionIfRetirementTypeMaxChildrenWhenRetirementMaximumIsBelowZero()
        {
            var task = GATestHelper.GetDummyTravelingSalesmanTask();

            task.RetirementStrategy = RetirementStrategy.MaxChildren;
            task.MaxRetirement      = 0;
            var settings = new GAConfiguration(task);
        }
Example #27
0
        public void ItCanDetermineIfTheChromosomeShouldRetireBasedOnAge()
        {
            var chromosome = GATestHelper.GetTravelingSalesmanChromosome();

            chromosome.Age = 100;

            Assert.IsTrue(chromosome.ShouldRetire(GATestHelper.GetTravelingSalesmanDefaultConfiguration()));
        }
Example #28
0
        public void ItCanGenerateAGenome()
        {
            var configuration = GATestHelper.GetTravelingSalesmanDefaultConfiguration();
            var chromosome    = GATestHelper.GetTravelingSalesmanChromosome();
            var pool          = PopulationGenerator.GenerateOrderedPopulation(configuration, chromosome.Genes);

            Assert.AreEqual(configuration.PopulationSize, pool.Length);
        }
Example #29
0
        public void ItCanCopyObjects()
        {
            var task   = GATestHelper.GetDummyTravelingSalesmanTask();
            var config = new GAConfiguration(task);

            Assert.AreEqual(task.MutationStrategy, config.MutationStrategy);
            Assert.AreEqual(task.CrossoverStrategy, config.CrossoverStrategy);
            Assert.AreEqual(task.ParentSelectionStrategy, config.ParentSelectionStrategy);
        }
Example #30
0
        public void ItCanShift()
        {
            var chromosome = GATestHelper.GetAlphabetCharacterChromosome();
            var mutation   = new InsertMutation();

            mutation.Shift(chromosome, 1, 4);

            Assert.AreEqual("A,E,B,C,D,F,G,H,I,J", chromosome.ToString());
        }