Beispiel #1
0
        private static void ga_OnGenerationComplete(object sender, GaEventArgs e)
        {
            //get the best solution
            var chromosome = e.Population.GetTop(1)[0];
            BestOfGeneration currentGen = new BestOfGeneration();

            currentGen.BestString = chromosome.ToBinaryString(0, chromosome.Count);
            currentGen.Fitness    = e.Population.MaximumFitness;
            bestGeneration.Add(currentGen);
            int i = 1;

            Console.WriteLine("\n\n\n ----------- GENERATION " + e.Generation + " COMPLETE ------------ ");

            string defaultPath = @".\Trackmania Generation Datalog.txt";

            foreach (BestOfGeneration instruction in bestGeneration)
            {
                Console.WriteLine("Gen" + (i - 1) + ": " + instruction.BestString + "\nFitness: " + instruction.Fitness);
                i++;
                //WRITE TO FILE
            }
            using (System.IO.StreamWriter file = new System.IO.StreamWriter(defaultPath, true))
            {
                file.WriteLine("Gen" + (i - 1) + ": " + currentGen.BestString + "\nFitness: " + currentGen.Fitness);
            }
            Console.WriteLine('\n');
            Console.WriteLine("----------- GENERATION LOG COMPLETE ------------\n\n\n");
        }
Beispiel #2
0
        private static void ga_OnGenerationComplete(object sender, GaEventArgs e)
        {
            //get the best solution
            var chromosome = e.Population.GetTop(1)[0];
            BestOfGeneration currentGen = new BestOfGeneration();

            currentGen.BestString = chromosome.ToBinaryString(0, chromosome.Count);
            currentGen.Fitness    = e.Population.MaximumFitness;
            bestGeneration.Add(currentGen);
            int i = 1;

            Console.WriteLine(" ----------- GENERATION COMPLETE ------------ ");
            foreach (BestOfGeneration instruction in bestGeneration)
            {
                Console.WriteLine("Gen" + i + ": " + instruction.BestString + "\nFitness: " + instruction.Fitness);
                i++;
                //WRITE TO FILE
                using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\Users\Bruger\source\repos\kill me now\trackmaniaGAlog.txt", true))
                {
                    file.WriteLine("Gen" + i + ": " + instruction.BestString + "\nFitness: " + instruction.Fitness);
                }
            }
            Console.WriteLine('\n');

            //Console.WriteLine(chromosome.ToBinaryString(0, chromosome.Count) + "\n FITNESS:" +  e.Population.MaximumFitness);
        }