コード例 #1
0
ファイル: GuidelinePool.cs プロジェクト: velkan14/tool-log2
        public void Run()
        {
            if (running)
            {
                return;
            }

            //create the elite operator
            var elite = new Elite(ElitismPercentage);

            //create the crossover operator
            var crossover = new CrossoverIndex(CrossOverPercentage, ChromosomeUtils.NUMBER_GENES, true, GAF.Operators.CrossoverType.DoublePoint, ReplacementMethod.GenerationalReplacement);

            //create the mutation operator
            var mutate = new BinaryMutate(MutationPercentage);
            //create the GA
            var ga = new GeneticAlgorithm(population, fitness.CalculateFitness);

            //add the operators
            ga.Operators.Add(elite);
            ga.Operators.Add(crossover);
            ga.Operators.Add(mutate);

            ga.OnRunComplete += OnRunComplete;

            //run the GA
            running = true;
            ga.Run(TerminateFunction);
        }
コード例 #2
0
        internal void Run(AreaManager areaManager, Population conv, Population inno, Population obj)
        {
            if (running)
            {
                return;
            }

            cells = originalMap.SpawnCells;


            Chromosome chrom = ChromosomeUtils.ChromosomeFromMap(originalMap);

            string binaryString = chrom.ToBinaryString();

            convergenceFitness = new ConvergenceFitness(cells, binaryString);
            guidelineFitness   = new Guideline(cells, areaManager, MaxMonsters, MaxItens, HordesPercentage)
            {
                MaxItemsLever      = LeverMaxItem,
                MaxMonstersLever   = LeverMaxMonster,
                AmountHordesLever  = LeverAmountHordes,
                DangerLever        = LeverDanger,
                AccessibilityLever = LeverAccessibility
            };

            double total = GuidelinePercentage + UserPercentage + InnovationPercentage;

            guidelineLevel   = GuidelinePercentage / total;
            ConvergenceLevel = UserPercentage / total;
            innovationLevel  = InnovationPercentage / total;

            //we can create an empty population as we will be creating the
            //initial solutions manually.
            var population = new Population(InitialPopulation, cells.Count * ChromosomeUtils.NUMBER_GENES, true, true, ParentSelectionMethod.StochasticUniversalSampling);

            population.Solutions.Clear();

            population.Solutions.AddRange(obj.GetTop(10));
            population.Solutions.AddRange(inno.GetTop(10));
            population.Solutions.AddRange(conv.GetTop(10));

            //create the elite operator
            var elite = new Elite(ElitismPercentage);

            //create the crossover operator
            var crossover = new CrossoverIndex(CrossOverPercentage, ChromosomeUtils.NUMBER_GENES, true, GAF.Operators.CrossoverType.DoublePoint, ReplacementMethod.GenerationalReplacement);

            //create the mutation operator
            var mutate = new BinaryMutate(MutationPercentage);
            //create the GA
            var ga = new GeneticAlgorithm(population, CalculateFitness);

            //add the operators
            ga.Operators.Add(elite);
            ga.Operators.Add(crossover);
            //ga.Operators.Add(mutate);

            ga.OnRunComplete += OnRunComplete;

            //run the GA
            running = true;
            ga.Run(TerminateFunction);
        }