Ejemplo n.º 1
0
        public void ElitismStrategy_GetElitistGeneticEntities_NullPopulation()
        {
            MockElitismStrategy strategy = new MockElitismStrategy();

            strategy.Initialize(GetGeneticAlgorithm(.1));
            Assert.Throws <ArgumentNullException>(() => strategy.GetEliteEntities(null));
        }
Ejemplo n.º 2
0
        public async Task ElitismStrategy_GetElitistGeneticEntities()
        {
            double           elitismRatio         = .1;
            int              totalGeneticEntities = 100;
            GeneticAlgorithm algorithm            = GetGeneticAlgorithm(elitismRatio);
            await algorithm.InitializeAsync();

            MockPopulation population = new MockPopulation();

            population.Initialize(algorithm);
            for (int i = 0; i < totalGeneticEntities; i++)
            {
                MockEntity entity = new MockEntity();
                entity.Initialize(algorithm);
                population.Entities.Add(entity);
            }
            algorithm.Environment.Populations.Add(population);
            MockElitismStrategy strategy = (MockElitismStrategy)algorithm.ElitismStrategy;

            strategy.Initialize(algorithm);

            IList <GeneticEntity> geneticEntities = strategy.GetEliteEntities(population);

            Assert.Equal(Convert.ToInt32(Math.Round(elitismRatio * totalGeneticEntities)), geneticEntities.Count);
        }
Ejemplo n.º 3
0
        public void ElitismStrategy_GetElitistGeneticEntities_EmptyPopulation()
        {
            GeneticAlgorithm    algorithm = GetGeneticAlgorithm(.1);
            MockElitismStrategy strategy  = new MockElitismStrategy();

            strategy.Initialize(algorithm);
            MockPopulation pop = new MockPopulation();

            pop.Initialize(algorithm);
            Assert.Throws <ArgumentException>(() => strategy.GetEliteEntities(pop));
        }