コード例 #1
0
        private void AppendHistory(List <Cromozom> cromozomList, int generation)
        {
            cromozomList = cromozomList.OrderByDescending(s => s.Fitness).ToList();
            Cromozom bestCromozom = cromozomList [0];

            IOFunctions.CreateHistoryFile(bestCromozom, generation);
        }
コード例 #2
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);
        }
コード例 #3
0
ファイル: Initialize.cs プロジェクト: elimelec/sim-outorder
        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);
        }
コード例 #4
0
        private void CalculateFitness(int i, int benchmarkCounter)
        {
            string logNumber = (i + (benchmarkCounter - 1) * cromozomsPopulation.Count).ToString();

            string[] itemeDeCautat = new string[] { "Avg. IPC (with stalls):" };
            if (logNumber.Length == 2)
            {
                logNumber = ("0" + logNumber);
            }
            if (logNumber.Length == 1)
            {
                logNumber = ("00" + logNumber);
            }
            Dictionary <string, double> results = SearchInFile.GetSimulatorValuesByText(IOFunctions.GetLinesFromFile(@"ta.log." + logNumber), itemeDeCautat);

            foreach (String item in itemeDeCautat)
            {
                double adunare   = (cromozomsPopulation [i].Fitness + results [item]);
                double inmultire = benchmarkCounter * 1.0;
                double impartire = adunare / inmultire;
                cromozomsPopulation [i].Fitness = impartire;                 // Media Aritmetica
            }
        }