Esempio n. 1
0
 public void Initialize(int poolSize)
 {
     _pool     = new List <C>();
     _poolSize = poolSize;
     for (int i = 0; i < _poolSize; i++)
     {
         _pool.Add(ChromosomeFactory.CreateChromosome());
     }
 }
        public void ClonePopulation_ChangingCloneDosntChangeOriginal()
        {
            var population = (new double[] { 1, 1, 1, 1 }).ToPopulation("Chromosomes");

            var populationClone = population.Clone();
            var fakeChromosome  = ChromosomeFactory.CreateChromosome(10, "New");

            populationClone.GetChromosomes()[0] = fakeChromosome;

            foreach (var chromosome in population.GetChromosomes())
            {
                Assert.AreNotEqual(fakeChromosome, chromosome);
            }
        }
        public void ChangeHistoryLastGeneration_AlgorithmPopulationNotChanged()
        {
            var expectedPopulation = new double[] { 1, 1 };
            var engine             = new TestGeneticSearchEngineBuilder(2, 10, expectedPopulation).IncludeAllHistory().Build();
            var fakeChromosome     = ChromosomeFactory.CreateChromosome(10, "ChangedChromosome");

            var result = engine.Next();

            result.History[result.History.Count - 1][0] = fakeChromosome;
            result = engine.GetCurrentPopulation();

            foreach (var chromosome in result.Population.GetChromosomes())
            {
                Assert.AreNotEqual(fakeChromosome, chromosome);
            }
        }