Exemplo n.º 1
0
    /// <summary>
    /// save changes
    /// </summary>
    private void Save()
    {
        XmlWriterSettings _xwSettings = new XmlWriterSettings();

        _xwSettings.Indent = true;
        // Save genomes to xml file.
        DirectoryInfo dirInf = new DirectoryInfo(Application.dataPath);

        if (!dirInf.Exists)
        {
            if (Utility.DebugLog)
            {
                Debug.Log("Creating subdirectory");
            }
            dirInf.Create();
        }
        using (XmlWriter xw = XmlWriter.Create(popFileSavePath + ".xml", _xwSettings)) {
            experiment.SavePopulation(xw, _ea.GenomeList);
        }
        // Also save the best genome

        using (XmlWriter xw = XmlWriter.Create(champFileSavePath + ".xml", _xwSettings)) {
            experiment.SavePopulation(xw, new NeatGenome[] { _ea.CurrentChampGenome });
        }
    }
Exemplo n.º 2
0
    void ea_PauseEvent(object sender, EventArgs e)
    {
        Time.timeScale = 1;
        Utility.Log("Done ea'ing (and neat'ing)");

        XmlWriterSettings _xwSettings = new XmlWriterSettings();

        _xwSettings.Indent = true;
        // Save genomes to xml file.
        DirectoryInfo dirInf = new DirectoryInfo(Application.persistentDataPath);

        if (!dirInf.Exists)
        {
            Debug.Log("Creating subdirectory");
            dirInf.Create();
        }
        using (XmlWriter xw = XmlWriter.Create(popFileSavePath, _xwSettings)) {
            experiment.SavePopulation(xw, _ea.GenomeList);
        }
        // Also save the best genome

        using (XmlWriter xw = XmlWriter.Create(champFileSavePath, _xwSettings)) {
            experiment.SavePopulation(xw, new NeatGenome[] { _ea.CurrentChampGenome });
        }
        DateTime endTime = DateTime.Now;

        Utility.Log("Total time elapsed: " + (endTime - startTime));

        System.IO.StreamReader stream = new System.IO.StreamReader(popFileSavePath);



        EARunning = false;
    }
Exemplo n.º 3
0
    void ea_UpdateEvent(object sender, EventArgs e)
    {
        Utility.Log(string.Format("gen={0:N0} bestFitness={1:N6}",
                                  _ea.CurrentGeneration, _ea.Statistics._maxFitness));



        Fitness = _ea.Statistics._maxFitness;

        Generation = _ea.CurrentGeneration;

        if (MaxAllFitness < Fitness)
        {
            MaxAllFitness = (float)Fitness;

            float timeTemp = Time.timeScale;
            Time.timeScale    = 0;
            AllGenerationBest = _ea.CurrentChampGenome;

            XmlWriterSettings _xwSettings = new XmlWriterSettings();
            _xwSettings.Indent = true;

            NeatGenome genome = null;

            bool fileAlreadyExist = File.Exists(champFileSavePath2);

            try
            {
                using (XmlReader xr = XmlReader.Create(champFileSavePath2)) {
                    genome = NeatGenomeXmlIO.ReadCompleteGenomeList(xr, false, (NeatGenomeFactory)experiment.CreateGenomeFactory()) [0];
                }
            }catch (Exception ex) {
            }

            using (XmlWriter xw = XmlWriter.Create(champFileSavePath2, _xwSettings))
            {
                if ((fileAlreadyExist && genome.EvaluationInfo.Fitness < MaxAllFitness) || !fileAlreadyExist)
                {
                    experiment.SavePopulation(xw, new NeatGenome[] { _ea.CurrentChampGenome });
                    Debug.Log("saved new best: " + AllGenerationBest.EvaluationInfo.Fitness);
                }
            }
            Time.timeScale = timeTemp;


//			Debug.Log(_ea.CurrentChampGenome.EvaluationInfo.Fitness+" vs "+AllGenerationBest.EvaluationInfo.Fitness);
        }
    }
Exemplo n.º 4
0
    /// <summary>
    /// Allows to specify other save paths (e.g.: used from NeatGenomeFactory
    /// before adding a new module so the genome diversity is not lost if we
    /// want to reset the addition of the new module, which overwrites every
    /// genome with the champion!)
    /// </summary>
    public void SavePopulation(string directoryPath, string popPath, string champPath)
    {
        XmlWriterSettings _xwSettings = new XmlWriterSettings();

        _xwSettings.Indent = true;

        CreateDirectoryIfNew(directoryPath);

        // Save genomes to xml file.
        using (XmlWriter xw = XmlWriter.Create(popPath, _xwSettings))
        {
            experiment.SavePopulation(xw, _ea.GenomeList);
        }
        // Also save the best genome
        using (XmlWriter xw = XmlWriter.Create(champPath, _xwSettings))
        {
            experiment.SavePopulation(xw, new NeatGenome[] { _ea.CurrentChampGenome });
        }
    }
Exemplo n.º 5
0
    void ea_UpdateEvent(object sender, EventArgs e)
    {
        Utility.Log(string.Format("gen={0:N0} bestFitness={1:N6}",
                                  _ea.CurrentGeneration, _ea.Statistics._maxFitness));

        Fitness     = (float)_ea.Statistics._maxFitness;
        MeanFitness = (float)_ea.Statistics._meanFitness;
        if (bestFitness < Fitness)
        {
            //map [getIndex (rain)] = _ea.CurrentChampGenome;

            XmlWriterSettings _xwSettings = new XmlWriterSettings();
            _xwSettings.Indent = true;
            // Save genomes to xml file.
            DirectoryInfo dirInf = new DirectoryInfo(Application.persistentDataPath + string.Format("/{0}", folder_prefix));
            if (!dirInf.Exists)
            {
                Debug.Log("Creating subdirectory");
                dirInf.Create();
            }

            using (XmlWriter xw = XmlWriter.Create(champFileSavePath, _xwSettings)) {
                experiment.SavePopulation(xw, new NeatGenome[] { _ea.CurrentChampGenome });
            }

            bestFitness = Fitness;
            Debug.Log("New best saved: " + bestFitness);
            TrialDuration = bestFitness * 50.0f > 70.0f ? bestFitness * 50.0f : 70.0f;
            if (TrialDuration > 450.0f)
            {
                TrialDuration = 450.0f;
            }
        }

        Generation    = _ea.CurrentGeneration;
        ChampAvgSpeed = _ea.CurrentChampGenome.EvaluationInfo.AvgSpeed;
    }