Example #1
0
        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();
                }
            }
        }
Example #2
0
        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();
                }
            }
        }