Ejemplo n.º 1
0
        public List <Cromozom> Start(GeneticAlgorithmOptions geneticAlgorithmOptions)
        {
            this.geneticAlgorithmOptions = geneticAlgorithmOptions;
            newCromozomsPopulation       = new List <Cromozom> ();
            elitistPercent    = geneticAlgorithmOptions.ElitesPercentage;
            currentGeneration = 0;
            Initialize algorithm = new Initialize();

            cromozomsPopulation = algorithm.GeneratePopulation(geneticAlgorithmOptions);
            int benchmarkCounter = 1;

            while (currentGeneration < geneticAlgorithmOptions.NumberOfGenerations)
            {
                IOFunctions.ClearFiles("./", "ta.log*");
                ClearPastFitness();
                benchmarkCounter = 1;
                foreach (var benchmark in geneticAlgorithmOptions.Benchmarks)
                {
                    for (int i = 0; i < cromozomsPopulation.Count; i++)
                    {
                        ExecutaComandaSimulator(i, benchmark, cromozomsPopulation[i].Configuration.Memory, cromozomsPopulation[i].Configuration.OptimizationLevel);
                        proc.WaitForExit();
                        CalculateFitness(i, benchmarkCounter);
                    }
                    benchmarkCounter++;
                }

                Cromozom[] cromozomPopulationCopy = new Cromozom [cromozomsPopulation.Count];
                cromozomsPopulation.CopyTo(cromozomPopulationCopy);
                AppendHistory(cromozomPopulationCopy.ToList(), currentGeneration);

                if (IsNotLastIteration(geneticAlgorithmOptions.NumberOfGenerations))
                {
                    if (geneticAlgorithmOptions.SelectionMode == AlgorithmSelectionMode.Elitist)
                    {
                        CreateNewGenerationWithElitistSelection();
                    }
                    if (geneticAlgorithmOptions.SelectionMode == AlgorithmSelectionMode.Tournament)
                    {
                        CreateNewGenerationWithTournamentSelection();
                    }

                    cromozomsPopulation = newCromozomsPopulation;
                    IOFunctions.ClearFiles("vex/configurations/", "*cfg");
                    for (int i = 0; i < cromozomsPopulation.Count; i++)
                    {
                        IOFunctions.CreateConfigFile(cromozomsPopulation [i], i.ToString());
                    }
                }

                currentGeneration++;
            }
            return(cromozomsPopulation);
        }
Ejemplo n.º 2
0
        public List <Cromozom> GeneratePopulation(GeneticAlgorithmOptions options)
        {
            List <Cromozom> PopulationList = new List <Cromozom> ();
            int             ct             = 0;

            while (ct < options.NumberOfCromozoms)
            {
                Cromozom cromozom = GenerateCromozom(options);
                cromozom.Index = ct;
                IOFunctions.CreateConfigFile(cromozom, ct.ToString());
                PopulationList.Add(cromozom);
                ct++;
            }
            return(PopulationList);
        }