Ejemplo n.º 1
0
 private void SaveNetworkDefinitionToFile(NeatGenome champ, string fileName)
 {
     NeatGenomeXmlIO.Save(champ, true).Save(fileName);
 }
Ejemplo n.º 2
0
        private void EAUpdateEvent(object sender, EventArgs e)
        {
            if (_ea.Statistics._maxFitness > _currentMaxFitness)
            {
                _currentMaxFitness            = _ea.Statistics._maxFitness;
                _lastMaxFitnessImprovementGen = _ea.CurrentGeneration;
            }

            if (_lastLog == 0 || _ea.CurrentGeneration - _lastLog >= _logInterval)
            {
                PrintEAStats();
            }

            if (_ea.CurrentGeneration > 0)
            {
                WriteData();
            }


            //if (!_multiObjectiveParams.Enabled && _noveltySearchParams.Enabled)
            //{
            //    // Novelty search
            //    if (NoveltySearchEnabled)
            //    {
            //        // Novelty search has been completed, so we switch to objective search using the archive as seeded generation.
            //        if (_listEvaluator.NoveltySearchComplete)
            //        {
            //            CreateEAFromNoveltyArchive();
            //        }
            //    }
            //    else
            //    {
            //        //if (_ea.CurrentGeneration - _lastMaxFitnessImprovementGen > 1000)
            //        //{
            //        //    _logger.Info("1000 gens passed since last improvement " + _ea.CurrentGeneration + " " + _lastMaxFitnessImprovementGen);
            //        //    NoveltySearchEnabled = true;
            //        //}
            //    }
            //}



            // Check if the experiment has been aborted, the maximum generations count have been reached, or if the maximum fitness has been reached
            if (_abort || (_maxGenerations > 0 && _ea.CurrentGeneration >= _maxGenerations) || _evaluator.StopConditionSatisfied)
            {
                PrintEAStats();

                if ((MultiObjectiveEnabled || NoveltySearchEnabled) && _evaluator.StopConditionSatisfied)
                {
                    // If the max objective fitness has been found when running multi objective, we must run an objective search,
                    // since the champion is not necessarily the objective champion. Another objective champion could be ranked higher.
                    MultiObjectiveEnabled             = false;
                    NoveltySearchEnabled              = false;
                    _evaluator.StopConditionSatisfied = false;
                    _ea.StartContinue();
                }
                else
                {
                    ExperimentCompleted = true;
                    _ea.RequestPause();
                }
            }

            // Save the best genome to file
            XmlDocument doc = NeatGenomeXmlIO.Save(_ea.CurrentChampGenome, false);

            CreateExperimentDirectoryIfNecessary();

            string file = string.Format(ChampionFile);

            doc.Save(file);
        }