private void btnSearchStart_Click(object sender, EventArgs e) { if(null != _ea) { // Resume existing EA & update GUI state. _ea.StartContinue(); UpdateGuiState(); return; } // Initialise and start a new evolution algorithm. ReadAndUpdateExperimentParams(); // Check number of species is <= the number of the genomes. if(_genomeList.Count < _selectedExperiment.NeatEvolutionAlgorithmParameters.SpecieCount) { __log.ErrorFormat("Genome count must be >= specie count. Genomes=[{0}] Species=[{1}]", _selectedExperiment.NeatEvolutionAlgorithmParameters.SpecieCount, _genomeList.Count); return; } // Create evolution algorithm. _ea = _selectedExperiment.CreateEvolutionAlgorithm(_genomeFactory, _genomeList); // Attach update event listener. _ea.UpdateEvent += new EventHandler(_ea_UpdateEvent); _ea.PausedEvent += new EventHandler(_ea_PausedEvent); // Notify any open views. if(null != _bestGenomeForm) { _bestGenomeForm.Reconnect(_ea); } if(null != _domainForm) { _domainForm.Reconnect(_ea); } foreach(TimeSeriesGraphForm graphForm in _timeSeriesGraphFormList) { graphForm.Reconnect(_ea); } foreach(SummaryGraphForm graphForm in _summaryGraphFormList) { graphForm.Reconnect(_ea); } // Create/open log file if the option is selected. if(chkFileWriteLog.Checked && null==_logFileWriter) { // BEGIN JONATHAN MERLEVEDE CHANGE string filename = txtFileLogBaseName.Text + '_' + DateTime.Now.ToString("yyyyMMdd") + ".csv"; // END JONATHAN MERLEVEDE CHANGE _logFileWriter = new StreamWriter(filename, true); _logFileWriter.WriteLine("ClockTime,Gen,BestFitness,MeanFitness,MeanSpecieChampFitness,ChampComplexity,MeanComplexity,MaxComplexity,TotalEvaluationCount,EvaluationsPerSec,SearchMode"); // BEGIN JONATHAN MERLEVEDE ADDED THIS _neatSimLogger = new NeatSimLogger(txtFileLogBaseName.Text + '_' + DateTime.Now.ToString("yyyyMMdd")); // END JONATHAN MERLEVEDE ADDED THIS } // Start the algorithm & update GUI state. _ea.StartContinue(); UpdateGuiState(); }
static void Main(string[] args) { // This program expects certain command line options, that are defined as annotated properties in the NeatSimConsole.Options class // We instantiate this class... _options = new Options(); // ... and pass the arguments to this program to the options parser, who uses it to set the properties in 'options'. // If the command line options are incorrect, ParseArgumentsStrict prints a help message to the screen and exits... if (!CommandLine.Parser.Default.ParseArgumentsStrict(args, _options)) { // ... therefore, this should really never ever happen. throw new SystemException("Something went wrong parsing arguments."); } // Now, all the properties in 'options' are set. FastRandom.__seedRng = new FastRandom(_options.Seed); // Initialise log4net (log to console). // XmlConfigurator.Configure(new FileInfo("log4net.properties")); // We instatiate a remote batch simulation experiment, and use the properties set in the XML file to initialize the experiment. // The XML file contains properties like the number of generations to run the program for, and the number of individuals in the population. // For properties that are not set in the XML file, we initialize default values. _experiment = new RemoteBatchSimExperiment(); var xmlConfig = new XmlDocument(); try { xmlConfig.Load("neatsim.config.xml"); } catch (FileNotFoundException e) { Console.WriteLine(@"Could not find neatsim.config.xml. Aborting."); return; } _experiment.Initialize("NeatSim", xmlConfig.DocumentElement); // The XML file cannot contain information about the inital number of connected neurons. // We want to initialize our population minimally, and do this by setting an absurdly small initial connections proportion. // The number of connected input neurons will always be at least one. // Note that there is an absurdly small chance that more than a single neuron will be connected in generation one. _experiment.NeatGenomeParameters.InitialInterconnectionsProportion = 0.0000000000001; // 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 ('born' in generation 0). _genomeList = _genomeFactory.CreateGenomeList(_options.PopulationSize, 0); // Create evolution algorithm and attach update events. _ea = _experiment.CreateEvolutionAlgorithm(_genomeFactory, _genomeList); _ea.PausedEvent += (s, e) => Console.WriteLine(_ea.RunState == RunState.Paused ? @"Program is paused" : _ea.RunState == RunState.Running ? @"Program is unpaused." : @"Program is in unknown state..."); _neatSimLogger = new NeatSimLogger(_options.LogFileName + '_' + DateTime.Now.ToString("yyyyMMdd")); // var nextGeneration = _ea.CurrentGeneration; var doneEvent = new AutoResetEvent(false); _ea.UpdateEvent += (s, e) => { if (_ea.CurrentGeneration < nextGeneration) { Console.WriteLine("Aborting!"); return; } Console.WriteLine(string.Format("gen={0:N0} bestFitness={1:N6}", _ea.CurrentGeneration, _ea.Statistics._maxFitness)); SaveChampionGenome(); _neatSimLogger.Log(_ea); if (_ea.CurrentGeneration >= _options.Generations) { _ea.Stop(); _neatSimLogger.Close(); doneEvent.Set(); } nextGeneration++; }; // Start algorithm (it will run on a background thread). _ea.StartContinue(); // Hit return to quit. //Console.ReadLine(); doneEvent.WaitOne(); }