static void StopNReturn(IDMotorExperiment experiment) { _ea.RequestTerminateAndWait(); // Save performance data IGenomeDecoder <NeatGenome, IBlackBox> deco = experiment.CreateGenomeDecoder(); IBlackBox nn = deco.Decode(_ea.CurrentChampGenome); SavePerformance(nn); SaveValidation(nn); // Save genome to xml file. XmlWriterSettings xwSettings = new XmlWriterSettings(); xwSettings.Indent = true; using (XmlWriter xw = XmlWriter.Create(GenomeFolder + NameFile + "_" + MaxTMin + "m" + ".gnm.xml", xwSettings)) { experiment.SavePopulation(xw, new NeatGenome[] { _ea.CurrentChampGenome }); } Console.WriteLine(NameFile + "finished. Continuing to the next data set => \n"); }
static void Main(string[] args) { for (; ;) { string[] cmdArgs = Console.ReadLine().Split(' '); ControlSignal = unpackControlSignal(csFile); switch (cmdArgs[0]) { case "Evolve": { if (cmdArgs.Length == 2) { safeNamesFile = cmdArgs[1]; } SetSafeNames(); SetDataFiles(); for (i = 0; i < dataFiles.GetLength(0); i++) { SetCurrentNameFile(); // Initialise log4net (log to console). XmlConfigurator.Configure(new FileInfo("log4net.properties")); // Experiment classes encapsulate much of the nuts and bolts of setting up a NEAT search. IDMotorExperiment experiment = new IDMotorExperiment(); //Set training datasets IDMotorUtils.SetData(dataFiles[i]); // Load config XML. xmlConfig.Load("IDMotor.config.xml"); experiment.Initialize("IDMotor", xmlConfig.DocumentElement); // Create a genome factory with our neat genome parameters object and the appropriate number of input and output neuron genes. _genomeFactory = experiment.CreateGenomeFactory(); // Create an initial population of randomly generated genomes. _genomeList = _genomeFactory.CreateGenomeList(1000, 0); // Create evolution algorithm and attach update event. _ea = experiment.CreateEvolutionAlgorithm(_genomeFactory, _genomeList); _ea.UpdateEvent += new EventHandler(ea_UpdateEvent); // Start algorithm (it will run on a background thread). T0 = DateTime.Now; now = T0; next = false; _ea.StartContinue(); while (!(((now - T0).Minutes >= MaxTMin)) || next) { now = DateTime.Now; } StopNReturn(experiment); } break; } case "Validate": { if (cmdArgs.Length == 2) { genomeNameFile = cmdArgs[1]; } StreamReader gnmReader = new StreamReader(genomeNameFile); string[] gnmfiles = gnmReader.ReadToEnd().Split('\n'); gnmReader.Close(); IDMotorExperiment _experiment = new IDMotorExperiment(); xmlConfig = new XmlDocument(); xmlConfig.Load("IDMotor.config.xml"); _experiment.Initialize("IDMotor", xmlConfig.DocumentElement); for (i = 0; i < gnmfiles.GetLength(0); i++) { NameFile = gnmfiles[i].Replace(".gnm.xml", "").Replace("\r", ""); Console.WriteLine("Validating {0}...", NameFile); XmlReader xr = XmlReader.Create(GenomeFolder + NameFile + ".gnm.xml"); _genomeList = _experiment.LoadPopulation(xr); IGenomeDecoder <NeatGenome, IBlackBox> _genomeDecoder = _experiment.CreateGenomeDecoder(); IBlackBox nn = _genomeDecoder.Decode(_genomeList[0]); SaveValidation(nn); Console.WriteLine("Done."); } break; } default: Console.WriteLine("Error, Evolve or Validate only."); break; } // Hit return to quit. Console.ReadLine(); } }