Ejemplo n.º 1
0
        /// <summary>
        /// Loads a list of genomes from the save file fitting the experiment name and the ExperimentFileType.
        /// </summary>
        private static List <NeatGenome> ReadGenomes(INeatExperiment experiment, ExperimentFileType fileType, bool createNewGenesIfNotLoadable = true)
        {
            List <NeatGenome> genomeList    = null;
            NeatGenomeFactory genomeFactory = (NeatGenomeFactory)experiment.CreateGenomeFactory();

            string filePath = GetSaveFilePath(experiment.Name, fileType);

            try
            {
                using (XmlReader xr = XmlReader.Create(filePath))
                {
                    genomeList = NeatGenomeXmlIO.ReadCompleteGenomeList(xr, false, genomeFactory);

                    if (genomeList != null && genomeList.Count > 0)
                    {
                        Utility.Log("Successfully loaded the genomes of the '" + fileType.ToString() + "' for the experiment '" + experiment.Name + "' from the location:\n" + filePath);
                    }
                }
            }
            catch (Exception e1)
            {
                Utility.Log("Error loading genome from file, could not find the file at: " + filePath + "\n" + e1.Message);

                if (createNewGenesIfNotLoadable)
                {
                    genomeList = genomeFactory.CreateGenomeList(experiment.DefaultPopulationSize, 0);
                }
            }
            return(genomeList);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get the absolute path to the requested filetype (population/champion savefile).
        /// </summary>
        public static string GetSaveFilePath(string experimentName, ExperimentFileType fileType)
        {
            string extention;

            switch (fileType)
            {
            case ExperimentFileType.Champion:
                extention = FILE_EXTENTION_CHAMPION;
                break;

            case ExperimentFileType.Population:
                extention = FILE_EXTENTION_POPULATION;
                break;

            default:
                extention = ".UnknownNeatFileType";
                break;
            }
            return(Application.persistentDataPath + "/" + experimentName + extention);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Writes a list of genomes to the save file fitting the experiment name and the ExperimentFileType.
        /// </summary>
        private static bool WriteGenomes(INeatExperiment experiment, IList <NeatGenome> genomeList, ExperimentFileType fileType)
        {
            XmlWriterSettings _xwSettings = new XmlWriterSettings();

            _xwSettings.Indent = true;

            string filePath = GetSaveFilePath(experiment.Name, fileType);

            DirectoryInfo dirInf = new DirectoryInfo(Application.persistentDataPath);

            if (!dirInf.Exists)
            {
                Debug.Log("ExperimentIO - Creating subdirectory");
                dirInf.Create();
            }
            try
            {
                using (XmlWriter xw = XmlWriter.Create(filePath, _xwSettings))
                {
                    NeatGenomeXmlIO.WriteComplete(xw, genomeList, false);
                    Debug.Log("Successfully saved the genomes of the '" + fileType.ToString() + "' for the experiment '" + experiment.Name + "' to the location:\n" + filePath);
                }
            }
            catch (Exception e1)
            {
                Debug.Log("Error saving the genomes of the '" + fileType.ToString() + "' for the experiment '" + experiment.Name + "' to the location:\n" + filePath);
                return(false);
            }
            return(true);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Deletes a certain savefile which fits the ExperimentFileType of the specified experiment
 /// </summary>
 public static void DeleteSaveFile(INeatExperiment experiment, ExperimentFileType fileType)
 {
     File.Delete(GetSaveFilePath(experiment.Name, fileType));
     Debug.Log("ExperimentIO - Deleted savefile of type: " + fileType);
 }