static void Main(string[] args) { // Intercept termination of the console app, to flush and close the output file stream // (apparently the 'finally' block below is not executed if the app is terminated with Ctrl-C). Console.CancelKeyPress += delegate { if (__streamWriter is object) { __streamWriter.Close(); } }; // Read command line arguments. StopCondition?stopCond = ArgUtils.ReadArgs(args, out string?experimentId, out string?filename); if (stopCond is null || experimentId is null || filename is null) { return; } // Initialise log4net (log to console). var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly()); XmlConfigurator.Configure(logRepository, new FileInfo("log4net.properties")); // Create and configure a NEAT experiment instance. INeatExperiment <double>?experiment = InitExperiment(experimentId); if (experiment is null) { return; } // Create an evolution algorithm host. IEvolutionAlgorithmHost eaHost = CreateEvolutionAlgorithmHost(experiment, stopCond); // Open and initialise the output file. __streamWriter = InitOutputFile(filename); try { // Run the main efficacy sampling loop until the process is terminated. for (;;) { Sample s = eaHost.Sample(); __streamWriter.WriteLine($"{s.ElapsedTimeSecs},{s.GenerationCount},{s.BestFitness:0.#####},{s.MeanFitness:0.#####},{s.MaxComplexity:0.#####},{s.MeanComplexity:0.#####},{s.EvaluationCount}"); __streamWriter.Flush(); } } finally { if (__streamWriter is object) { __streamWriter.Close(); } } }
static void Main(string[] args) { Console.CancelKeyPress += delegate { if (null != __streamWriter) { __streamWriter.Close(); } }; string experimentId; string filename; StopCondition stopCond = ArgUtils.ReadArgs(args, out experimentId, out filename); if (null == stopCond) { return; } // Initialise NEAT experiment. IGuiNeatExperiment experiment = InitExperiment(experimentId); if (null == experiment) { return; } // Initialise log4net (log to console). XmlConfigurator.Configure(new FileInfo("log4net.properties")); // Initialise evolution algorithm host. EvolutionAlgorithmHost eaHost = new EvolutionAlgorithmHost(experiment, stopCond); __streamWriter = InitOutputFile(filename); try { for (;;) { double secs; int gens; double fitness = eaHost.Sample(out secs, out gens); __streamWriter.WriteLine($"{secs},{gens},{fitness}"); __streamWriter.Flush(); } } finally { if (null != __streamWriter) { __streamWriter.Close(); } } }
static void Main(string[] args) { Console.CancelKeyPress += delegate { if (null != __streamWriter) { __streamWriter.Close(); } }; string experimentId; string filename; StopCondition stopCond = ArgUtils.ReadArgs(args, out experimentId, out filename); if (null == stopCond) { return; } // Initialise NEAT experiment. IGuiNeatExperiment experiment = InitExperiment(experimentId); if (null == experiment) { return; } // Initialise log4net (log to console). XmlConfigurator.Configure(new FileInfo("log4net.properties")); // Initialise evolution algorithm host. EvolutionAlgorithmHost eaHost = new EvolutionAlgorithmHost(experiment, stopCond); __streamWriter = InitOutputFile(filename); try { for (;;) { Sample s = eaHost.Sample(); __streamWriter.WriteLine($"{s.ElapsedTimeSecs},{s.GenerationCount},{s.BestFitness:0.#####},{s.MeanFitness:0.#####},{s.MaxComplexity:0.#####},{s.MeanComplexity:0.#####},{s.EvaluationCount}"); __streamWriter.Flush(); } } finally { if (null != __streamWriter) { __streamWriter.Close(); } } }