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

            IOFunctions.CreateHistoryFile(bestCromozom, generation);
        }
Beispiel #2
0
 public void CrossOver(Cromozom other)
 {
     CrossOver(ref Configuration.CoreCkFreq, ref other.Configuration.CoreCkFreq);
     CrossOver(ref Configuration.BusCkFreq, ref other.Configuration.BusCkFreq);
     CrossOver(ref Configuration.lg2CacheSize, ref other.Configuration.lg2CacheSize);
     CrossOver(ref Configuration.lg2Sets, ref other.Configuration.lg2Sets);
     CrossOver(ref Configuration.lg2LineSize, ref other.Configuration.lg2LineSize);
     CrossOver(ref Configuration.MissPenalty, ref other.Configuration.MissPenalty);
     CrossOver(ref Configuration.WBPenalty, ref other.Configuration.WBPenalty);
     CrossOver(ref Configuration.lg2StrSize, ref other.Configuration.lg2StrSize);
     CrossOver(ref Configuration.lg2StrSets, ref other.Configuration.lg2StrSets);
     CrossOver(ref Configuration.lg2StrLineSize, ref other.Configuration.lg2StrLineSize);
     CrossOver(ref Configuration.StrMissPenalty, ref other.Configuration.StrMissPenalty);
     CrossOver(ref Configuration.StrWBPenalty, ref other.Configuration.StrWBPenalty);
     CrossOver(ref Configuration.lg2ICacheSize, ref other.Configuration.lg2ICacheSize);
     CrossOver(ref Configuration.lg2ICacheSets, ref other.Configuration.lg2ICacheSets);
     CrossOver(ref Configuration.lg2ICacheLineSize, ref other.Configuration.lg2ICacheLineSize);
     CrossOver(ref Configuration.ICachePenalty, ref other.Configuration.ICachePenalty);
     CrossOver(ref Configuration.NumCaches, ref other.Configuration.NumCaches);
     CrossOver(ref Configuration.BranchStall, ref other.Configuration.BranchStall);
     CrossOver(ref Configuration.StreamEnable, ref other.Configuration.StreamEnable);
     CrossOver(ref Configuration.PrefetchEnable, ref other.Configuration.PrefetchEnable);
     CrossOver(ref Configuration.LockEnable, ref other.Configuration.LockEnable);
     CrossOver(ref Configuration.ProfGranularity, ref other.Configuration.ProfGranularity);
 }
Beispiel #3
0
        static List <string> GetCromozomProperties(Cromozom cromozom)
        {
            List <string> lines = new List <string> ();

            lines.Add("CoreCkFreq " + cromozom.Configuration.CoreCkFreq);
            lines.Add("BusCkFreq " + cromozom.Configuration.BusCkFreq);
            lines.Add("lg2CacheSize " + cromozom.Configuration.lg2CacheSize);
            lines.Add("lg2Sets " + cromozom.Configuration.lg2Sets);
            lines.Add("lg2LineSize " + cromozom.Configuration.lg2LineSize);
            lines.Add("MissPenalty " + cromozom.Configuration.MissPenalty);
            lines.Add("WBPenalty " + cromozom.Configuration.WBPenalty);
            lines.Add("lg2StrSize " + cromozom.Configuration.lg2StrSize);
            lines.Add("lg2StrSets " + cromozom.Configuration.lg2StrSets);
            lines.Add("lg2StrLineSize " + cromozom.Configuration.lg2StrLineSize);
            lines.Add("StrMissPenalty " + cromozom.Configuration.StrMissPenalty);
            lines.Add("StrWBPenalty " + cromozom.Configuration.StrWBPenalty);
            lines.Add("lg2ICacheSize " + cromozom.Configuration.lg2ICacheSize);
            lines.Add("lg2ICacheSets " + cromozom.Configuration.lg2ICacheSets);
            lines.Add("lg2ICacheLineSize " + cromozom.Configuration.lg2ICacheLineSize);
            lines.Add("ICachePenalty " + cromozom.Configuration.ICachePenalty);
            lines.Add("NumCaches " + cromozom.Configuration.NumCaches);
            lines.Add("BranchStall " + cromozom.Configuration.BranchStall);
            lines.Add("StreamEnable " + cromozom.Configuration.StreamEnable);
            lines.Add("PrefetchEnable " + cromozom.Configuration.PrefetchEnable);
            lines.Add("LockEnable " + cromozom.Configuration.LockEnable);
            lines.Add("ProfGranularity " + cromozom.Configuration.ProfGranularity);
            return(lines);
        }
        private void CreateNewGenerationWithTournamentSelection()
        {
            Cromozom tempFirstCromozom;
            Cromozom tempSecondCromozom;

            newCromozomsPopulation = new List <Cromozom> ();

            List <Cromozom> listaNoua = new List <Cromozom> ();

            for (int i = 0; i < 5; i++)
            {
                listaNoua.Add(cromozomsPopulation[rand.Next(0, cromozomsPopulation.Count)]);
            }
            listaNoua = listaNoua.OrderByDescending(s => s.Fitness).ToList();
            ApplyCrossover(listaNoua[0], listaNoua[1]);

            foreach (var cromozom in newCromozomsPopulation)
            {
                if (rand.NextDouble() >= geneticAlgorithmOptions.MutationOccurance)
                {
                    cromozom.Mutate();
                }
            }
            tempFirstCromozom  = newCromozomsPopulation [0];
            tempSecondCromozom = newCromozomsPopulation [1];

            Cromozom[] temporaryCromozomArray = new Cromozom[cromozomsPopulation.Count];
            cromozomsPopulation.CopyTo(temporaryCromozomArray);
            newCromozomsPopulation = temporaryCromozomArray.ToList();
            newCromozomsPopulation.Add(tempFirstCromozom);
            newCromozomsPopulation.Add(tempSecondCromozom);

            newCromozomsPopulation = newCromozomsPopulation.OrderBy(s => s.Fitness).ToList();
            newCromozomsPopulation.RemoveRange(0, 2);
        }
Beispiel #5
0
        protected Cromozom GenerateCromozom(GeneticAlgorithmOptions options)
        {
            Cromozom cromozom = new Cromozom();

            cromozom.Options          = options;
            cromozom.Configuration    = Configuration.NewRadom();
            cromozom.Fitness          = CromozomValues.Fitness;
            cromozom.GenerationNumber = 0;
            return(cromozom);
        }
Beispiel #6
0
        public static void CreateHistoryFile(Cromozom cromozom, int generationNumber)
        {
            var lines = GetCromozomProperties(cromozom);

            lines.Add("Memory " + cromozom.Configuration.Memory);
            lines.Add("Optimization Level " + cromozom.Configuration.OptimizationLevel);
            lines.Add("IPC " + cromozom.Fitness);

            Directory.CreateDirectory("vex/history");
            System.IO.File.WriteAllLines("vex/history/cromozom_generation_" + generationNumber + ".txt", lines);
        }
        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);
        }
        private void ApplyCrossover(Cromozom firstCromozom, Cromozom secondCromozom)
        {
            Cromozom resultFirstCromozom  = firstCromozom.DeepCopy();
            Cromozom resultSecondCromozom = secondCromozom.DeepCopy();

            resultFirstCromozom.CrossOver(resultSecondCromozom);

            resultFirstCromozom.GenerationNumber  = currentGeneration + 1;
            resultSecondCromozom.GenerationNumber = currentGeneration + 1;

            newCromozomsPopulation.Add(resultFirstCromozom);
            newCromozomsPopulation.Add(resultSecondCromozom);
        }
Beispiel #9
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);
        }
Beispiel #10
0
        public Cromozom DeepCopy()
        {
            Cromozom iCopy = (Cromozom)this.MemberwiseClone();

            return(iCopy);
        }
Beispiel #11
0
        public static void CreateConfigFile(Cromozom cromozom, string configFileNumber)
        {
            var lines = GetCromozomProperties(cromozom);

            System.IO.File.WriteAllLines("vex/configurations/vex_" + configFileNumber + ".cfg", lines);
        }