BatchExperiment.Program._ea_UpdateEvent C# (CSharp) Method

_ea_UpdateEvent() static private method

static private _ea_UpdateEvent ( object sender, EventArgs e ) : void
sender object
e EventArgs
return void
        void _ea_UpdateEvent(object sender, EventArgs e)
        {
            // If this run has already finished, don't log anything.
            // This is needed because SharpNEAT calls this an extra
            // time when the algorithm is stopped.
            if (finished)
                return;

            // The average fitness of each genome.
            double averageFitness = _ea.GenomeList.Average(x => x.EvaluationInfo.Fitness);

            // The fitness of the best individual in the population.
            double topFitness = _ea.CurrentChampGenome.EvaluationInfo.Fitness;

            // The generation that just completed.
            int generation = (int)_ea.CurrentGeneration;

            // Write the progress to the console.
            Console.WriteLine("{0} Generation: {1} Best: {2} Avg: {3} Updates: {4}",
                               _name, generation, topFitness, averageFitness, _experiment.Evaluator.UpdatesThisGeneration);

            // Append the progress to the results file in CSV format.
            using (TextWriter writer = new StreamWriter(_filename, true))
                writer.WriteLine(generation + "," + averageFitness + "," + topFitness + "," + _experiment.Evaluator.UpdatesThisGeneration);

            

            // Stop if we've evolved for enough generations
            if (_ea.CurrentGeneration >= MaxGenerations)
            {
                _ea.Stop();
                finished = true;
                Console.WriteLine("{0} Finished!", _name);
            }
        }