Esempio n. 1
0
 private void Reproduction(Generation cur)
 {
     for (int i = 0; i < ReproductionsCount; i++)
     {
         Tour tour = (Tour)LastGeneration[i].Clone();
         cur.Add(tour);
     }
 }
Esempio n. 2
0
        public static Generation ResolveNextGeneration(Grid grid, Rules rules, Generation cells)
        {
            var nextGen = new Generation();

            foreach (var cell in cells)
            {
                nextGen.Add(cell.Key, CellAliveNextGen(cell.Value, NeighborsCount(cell.Key, grid, cells), rules));
            }
            return(nextGen);
        }
Esempio n. 3
0
 private void Crossover(Generation cur)
 {
     for (int i = 0; i < CrossoverTries; i++)
     {
         Tour tour = new Tour(LastGeneration, crossoverStrategy, crossoverOperator);
         tour.Improve();
         if (!cur.Contains(tour))
         {
             cur.Add(tour);
         }
     }
 }
Esempio n. 4
0
        public void HasLiveCellsProperty()
        {
            var generation = new Generation();

            Assert.IsFalse(generation.HasLiveCells);

            var cell = new RowCol(0, 0);

            generation.Add(cell, false);
            Assert.IsFalse(generation.HasLiveCells);

            generation[cell] = true;
            Assert.IsTrue(generation.HasLiveCells);
        }
Esempio n. 5
0
        protected override void FirstGeneration(Generation cur)
        {
            RandomGenerate generatingAlgorithm = new RandomGenerate(Task);

            for (int tries = 0; tries < MaxTriesForFirstGeneration; tries++)
            {
                Tour tour = new Tour(generatingAlgorithm);
                tour.Improve();
                if (!cur.Contains(tour))
                {
                    cur.Add(tour);
                }
            }
            cur.Sort();
        }
Esempio n. 6
0
        private void Mutation(Generation cur)
        {
            for (int i = 0; i < MutationTries; i++)
            {
                int index;
                mutationStrategy.Run(LastGeneration, out index);

                Tour tour = mutationOperator.Run(LastGeneration[index]);

                tour.Improve();
                if (!cur.Contains(tour))
                {
                    cur.Add(tour);
                }
            }
        }