Exemplo n.º 1
0
        public void AddCompleteModule()
        {
            UpdateGenomeAndFactory();
            // Reset evolution process if it is running! (Or ensure it is stopped
            // before calling this method.)
            System.Diagnostics.Debug.WriteLine(
                "\nCreating a module for the genomes. This module will " +
                "create connections for all inputs and outputs. " +
                "(This may be used to simulate traditional interactive " +
                "evolution with no modular functionality.)\n");
            PrepareUIvar();
            //System.Diagnostics.Debug.WriteLine("ui var done");
            // WARNING: 3 parameters is too many!

            //evolutionAlgorithm.GenomeList[0].PrintGenomeStatistics();
            //evolutionAlgorithm.GenomeList[1].PrintGenomeStatistics();
            //evolutionAlgorithm.CurrentChampGenome.PrintGenomeStatistics();

            factory.AddNewModule(evolutionAlgorithm.GenomeList,
                                 evolutionAlgorithm.CurrentChampGenome, uiVar);

            System.Diagnostics.Debug.WriteLine("new module done");
            UpdateGenomeStatistics();
            System.Diagnostics.Debug.WriteLine("statistics done");
            RandomChampion();
            System.Diagnostics.Debug.WriteLine("champion done");
            PopulationReadWrite.SavePopulation(evolutionAlgorithm.UserName);
            // TODO: IMPORTANT NOTICE FROM UNITY IMPORT. See comment at the end of the script.*
            // Easy patch: update the ID generator here.
            System.Diagnostics.Debug.WriteLine("saved done");
            factory.InitializeGeneratorAfterLoad(evolutionAlgorithm.GenomeList);
            System.Diagnostics.Debug.WriteLine("InitializeGeneratorAfterLoad done");
        }
Exemplo n.º 2
0
 /// <summary>
 /// This is specially useful since it is possible that startevolution will be called
 /// after stop evolution (because stopping is not instantaneous!)
 /// </summary>
 static void SaveDataIfRunning(string userName)
 {
     if (ActiveUsersList <NeatGenome> .IsUserRunning(userName))
     {
         PopulationReadWrite.SavePopulation(userName);
     }
 }
Exemplo n.º 3
0
 public static void OnResetEvolution(object sender, EvolutionEventsArgs eventArguments)
 {
     TryStopEvolution(eventArguments.userName);
     PopulationReadWrite.DeleteLocalEvolutionFiles(eventArguments.userName);
     // TODO: Probably unnecessary wait.
     Thread.Sleep(500);
     StartOrRestartEvolution(eventArguments.userName);
 }
Exemplo n.º 4
0
        static void InitializeEvolutionAlgorithm(MyExperiment currentExperiment, string userName)
        {
            // Passing a file path the new evolution algorithm will try to read an existing population.
            string posiblePopulationFile = PopulationReadWrite.PopulationPathForUser(userName);
            // This step will create the evolution algorithm and pass the userName (which currentExperiment already has)
            // to the algorithm constructor, which will add the pair (algorithm, user) to ActiveUsersList
            NeatEvolutionAlgorithm <NeatGenome> evolutionAlgorithm = currentExperiment.CreateEvolutionAlgorithm(posiblePopulationFile);

            evolutionAlgorithm.UpdateEvent += new EventHandler <EvolutionEventsArgs>(WhenUpdateEvent);
            evolutionAlgorithm.PausedEvent += new EventHandler <EvolutionEventsArgs>(WhenPauseEvent);
        }
Exemplo n.º 5
0
        static void ReInitialize(string userName)
        {
            MyExperiment currentExperiment    = CreateNewExperiment(userName);
            var          myEvolutionAlgorithm = ActiveUsersList <NeatGenome> .EvolutionAlgorithmForUser(userName);

            string populationPath = PopulationReadWrite.PopulationPathForUser(userName);

            currentExperiment.ReInitializeEvolution(myEvolutionAlgorithm, populationPath);
            SaveDataIfRunning(userName);
            AddFirstModuleIfNeeded(userName);
            System.Diagnostics.Debug.WriteLine("added module!");
        }
Exemplo n.º 6
0
        /// <summary>
        /// My experiment controls what NEAT will do (how genomes will be
        /// evaluated, their inputs and outputs, etc.)
        /// </summary>
        static MyExperiment CreateNewExperiment(string userName)
        {
            string configFilePath = PopulationReadWrite.GetEvolutionFolderPath() + "Malmo.config.xml";

            return(new MyExperiment(configFilePath, userName));
        }