예제 #1
0
        private void loadNetworkToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string         filename;
            OpenFileDialog oDialog = new OpenFileDialog();

            oDialog.AddExtension     = true;
            oDialog.DefaultExt       = "xml";
            oDialog.Title            = "Load Seed Genome";
            oDialog.RestoreDirectory = true;

            // Show Open Dialog and Respond to OK
            if (oDialog.ShowDialog() == DialogResult.OK)
            {
                filename = oDialog.FileName;
            }
            else
            {
                return;
            }


            NeatGenome.NeatGenome seedGenome = null;
            try
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(filename);
                seedGenome = XmlNeatGenomeReaderStatic.Read(doc);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Problem loading genome. \n" + ex.Message);
                return;
            }
            currentBest = GenomeDecoder.DecodeToFloatFastConcurrentNetwork(seedGenome, null);
        }
예제 #2
0
        public void calcFitness(string genomeFile, int type)
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(genomeFile);
            NeatGenome genome = XmlNeatGenomeReaderStatic.Read(doc);

            INetworkEvaluator eval;

            if (type == 0)
            {
                eval = new CTRNNNetworkEvaluator(4, 12, 12);
            }
            else if (type == 1)
            {
                eval = new SUPGNetworkEvaluator(4, 12, 12);
            }
            else
            {
                doClune = true;
                eval    = new CluneNetworkEvaluator(20, 20, 20);
            }

            var tempNet = genome.Decode(null);

            MessageBox.Show(eval.threadSafeEvaluateNetwork(tempNet)[0].ToString());
        }
        public FieldSubs3LQTable(RLClientBase client, int numTeammates, int myUnum)
            : base(client, numTeammates, myUnum, false)
        {
            if (Program.LoadingGenome)
            {
                try
                {
                    var doc = new XmlDocument();
                    doc.Load(Program.LoadedGenomePath);
                    NeatGenome readCPPN = XmlNeatGenomeReaderStatic.Read(doc);

                    var substrate = new MultiLayerSandwichSubstrate(Rows, Cols + 2, NeatExpParams.SubstrateLayers,
                                                                    NeatExpParams.AddBiasToSubstrate, HyperNEATParameters.substrateActivationFunction);

                    SharpNeatLib.NeatGenome.NeatGenome tempGenome = substrate.GenerateGenome(readCPPN.Decode(HyperNEATParameters.substrateActivationFunction));
                    m_loadedNetwork = tempGenome.Decode(HyperNEATParameters.substrateActivationFunction);

                    m_loadingBehaviour = true;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                    m_loadingBehaviour = false;
                }
            }
        }
        /// <summary>
        /// Loads a genome from the specified XML file.
        /// </summary>
        public void loadGenome(String filename)
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(filename);
            genome          = XmlNeatGenomeReaderStatic.Read(doc);
            bestGenomeSoFar = genome;
        }
        public void loadGenome(String filename)
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(filename);
            genome          = XmlNeatGenomeReaderStatic.Read(doc);
            bestGenomeSoFar = genome;
            genomeFilename  = filename;
            //TODO maybe include	initialize();
        }
예제 #6
0
        public void loadSeed(string seedGenomeFile)
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(seedGenomeFile);
            officialSeedGenome = XmlNeatGenomeReaderStatic.Read(doc);
            //since idgen is still in control of genomeIDs, we have to increment it
            //for now... soon win will be in charge. You'll see, things will be different.
            idgen.mostRecentGenomeID(officialSeedGenome.GenomeId);
        }
예제 #7
0
        NeatGenome loadGenome(string genomeFileName)
        {
            //XmlDocument xDoc =
            XmlDocument doc = new XmlDocument();

            doc.Load(genomeFileName);

            //this will read the neatgenome, then we can immediately enter these neurons into the database
            return(XmlNeatGenomeReaderStatic.Read(doc));
        }
예제 #8
0
        private void adHocAnalysisToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string       filename;
            StreamWriter sw;

            NeatGenome.NeatGenome seedGenome = null;

            Stats currentStats = new Stats();

            for (FoodGatherParams.resolution = 8; FoodGatherParams.resolution <= 128; FoodGatherParams.resolution *= 2)
            {
                FoodGatherParams.fillFood();
                FoodGatherParams.fillLookups();
                sw = new StreamWriter("logfile" + FoodGatherParams.resolution.ToString() + ".txt");
                for (int run = 1; run <= 20; run++)
                {
                    for (int generation = 1; generation <= 500; generation++)
                    {
                        filename = "run" + run.ToString() + @"\genome_" + generation.ToString() + ".xml";

                        try
                        {
                            XmlDocument doc = new XmlDocument();
                            doc.Load("run" + run.ToString() + "\\genome_" + generation.ToString() + ".xml");
                            seedGenome = XmlNeatGenomeReaderStatic.Read(doc);
                        }
                        catch (Exception ex)
                        {
                            //MessageBox.Show(generation.ToString());
                            currentStats.generation = generation;
                            currentStats.run        = run;
                            writeStats(sw, currentStats);
                            continue;
                            //do some output
                        }


                        currentStats = FoodGathererNetworkEvaluator.postHocAnalyzer(seedGenome);
                        currentStats.CPPNconnections = seedGenome.ConnectionGeneList.Count;
                        currentStats.CPPNneurons     = seedGenome.NeuronGeneList.Count;


                        currentStats.generation = generation;
                        currentStats.run        = run;
                        writeStats(sw, currentStats);
                        //break;
                    }
                    // sw.Flush();
                }
                sw.Close();
            }
        }
        private void loadCCEAGenomesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (var dlg = new OpenFileDialog())
            {
                dlg.Multiselect = true;
                dlg.Filter      = "*.xml|*.xml";
                if (dlg.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                {
                    return;
                }

                var fileNames = dlg.FileNames;
                if (fileNames.Length != 5)
                {
                    MessageBox.Show("You must select 5 files!");
                    return;
                }

                Array.Sort(fileNames);

                INetwork[] predNetworks = new INetwork[5];

                for (int i = 0; i < predNetworks.Length; i++)
                {
                    try
                    {
                        XmlDocument doc = new XmlDocument();
                        doc.Load(fileNames[i]);
                        var genome = XmlNeatGenomeReaderStatic.Read(doc);

                        var curSubstrate = new SkirmishSubstrate(5, 3, 5, HyperNEATParameters.substrateActivationFunction);
                        predNetworks[i] = curSubstrate.GenerateGenome(genome.Decode(null)).Decode(null);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                        return;
                    }
                }

                this.isMulti = false;
                SkirmishNetworkEvaluator.NetworkPerPred = predNetworks;
            }
        }
예제 #10
0
        private void loadGenomeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DialogResult res = openFileDialog1.ShowDialog(this);

            if (res == DialogResult.OK || res == DialogResult.Yes)
            {
                string filename = openFileDialog1.FileName;
                try
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(filename);
                    seedGenome = XmlNeatGenomeReaderStatic.Read(doc);
                    setupSubstrate();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }
        private void loadGenomeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            openFileDialog1.InitialDirectory = Environment.CurrentDirectory;
            // Path.Combine(Environment.CurrentDirectory, @"..\..\..\SeedGenomes");

            DialogResult res = openFileDialog1.ShowDialog(this);

            if (res == DialogResult.OK || res == DialogResult.Yes)
            {
                string filename = openFileDialog1.FileName;
                try
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(filename);
                    seedGenome = XmlNeatGenomeReaderStatic.Read(doc);
                    setupSubstrate();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }
예제 #12
0
        static void Main(string[] args)
        {
            NeatGenome seedGenome = null;
            string     filename   = @"seedGenome.xml";

            try
            {
                XmlDocument document = new XmlDocument();
                document.Load(filename);
                seedGenome = XmlNeatGenomeReaderStatic.Read(document);
            }
            catch (Exception e)
            {
                System.Console.WriteLine("Problem loading genome. \n" + e.Message);
            }

            string experimentName = "_2Pref";

            for (int k = 3; k < 10; k++)
            {
                double maxFitness     = 0;
                int    maxGenerations = 400; //150;
                int    populationSize = 300; //100;//150;

                Thread extraWindowThread;
                extraWindowThread = new System.Threading.Thread(delegate()
                {
                    var myForm = new SharpNeatExperiments.Pacman.MyForm1();
                    System.Windows.Forms.Application.Run(myForm);
                });
                extraWindowThread.Start();

                IExperiment exp = null;
                //exp = new SUPGONLYExperiment(4,12,12,5,2);
                //exp = new PacmanExperimentSUPG(4, 12, 12, 5, 2);
                //exp = new SPMMExperiment(4, 12, 12, 5, 2);
                //exp = new SPCExperiment(4, 12, 12, 5, 2);
                exp = new SPSUPGExperiment(4, 12, 12, 5, 6);

                StreamWriter SW;
                SW = File.CreateText("logfile.txt");
                //Change this line for different experiments
                XmlDocument        doc;
                FileInfo           oFileInfo;
                IdGenerator        idgen;
                EvolutionAlgorithm ea;
                if (seedGenome == null)
                {
                    idgen = new IdGenerator();
                    ea    = new EvolutionAlgorithm(new Population(idgen, GenomeFactory.CreateGenomeList(exp.DefaultNeatParameters, idgen, exp.InputNeuronCount, exp.OutputNeuronCount, exp.DefaultNeatParameters.pInitialPopulationInterconnections, populationSize)), exp.PopulationEvaluator, exp.DefaultNeatParameters);
                }
                else
                {
                    idgen = new IdGeneratorFactory().CreateIdGenerator(seedGenome);
                    ea    = new EvolutionAlgorithm(new Population(idgen, GenomeFactory.CreateGenomeList(seedGenome, exp.DefaultNeatParameters.populationSize, exp.DefaultNeatParameters, idgen)), exp.PopulationEvaluator, exp.DefaultNeatParameters);
                }
                bool isNSGAiiEnabled = false;
                for (int j = 0; j < maxGenerations; j++)
                {
                    DateTime dt = DateTime.Now;
                    if (isNSGAiiEnabled)
                    {
                        ea.PerformOneGenerationNSGAii();
                    }
                    else
                    {
                        ea.PerformOneGeneration();
                    }
                    if (ea.BestGenome.Fitness > maxFitness)
                    {
                        maxFitness = ea.BestGenome.Fitness;
                        Console.WriteLine(maxFitness + "maxFitness");
                        Console.WriteLine("objectiveFitness" + ea.BestGenome.MultiObjectiveFitness[0] + " " + ea.BestGenome.MultiObjectiveFitness[1]);
                        doc = new XmlDocument();
                        XmlGenomeWriterStatic.Write(doc, (NeatGenome)ea.BestGenome);
                        oFileInfo = new FileInfo("bestGenome" + j.ToString() + ".xml");
                        doc.Save(oFileInfo.FullName);

                        //MadsXMLWriter(j, maxFitness);
                    }
                    MadsXMLWriter(j, maxFitness, k, experimentName);
                    Console.WriteLine(ea.Generation.ToString() + " " + (maxFitness).ToString() + " " + (DateTime.Now.Subtract(dt)));
                    //Do any post-hoc stuff here


                    SW.WriteLine(ea.Generation.ToString() + " " + (maxFitness).ToString());
                }
                SW.Close();
                //----- Write the genome to an XmlDocument.
                doc = new XmlDocument();
                XmlGenomeWriterStatic.Write(doc, (NeatGenome)ea.BestGenome, ActivationFunctionFactory.GetActivationFunction("NullFn"));
                oFileInfo = new FileInfo("bestGenome" + experimentName + "_" + k + ".xml");
                doc.Save(oFileInfo.FullName);
            }
        }
예제 #13
0
        static void Main(string[] args)
        {
            string     folder     = "";
            NeatGenome seedGenome = null;
            string     filename   = null;
            string     shape      = "triangle";
            bool       isMulti    = false;

            for (int j = 0; j < args.Length; j++)
            {
                if (j <= args.Length - 2)
                {
                    switch (args[j])
                    {
                    case "-seed": filename = args[++j];
                        Console.WriteLine("Attempting to use seed from file " + filename);
                        break;

                    case "-folder": folder = args[++j];
                        Console.WriteLine("Attempting to output to folder " + folder);
                        break;

                    case "-shape": shape = args[++j];
                        Console.WriteLine("Attempting to do experiment with shape " + shape);
                        break;

                    case "-multi": isMulti = Boolean.Parse(args[++j]);
                        Console.WriteLine("Experiment is heterogeneous? " + isMulti);
                        break;
                    }
                }
            }

            if (filename != null)
            {
                try
                {
                    XmlDocument document = new XmlDocument();
                    document.Load(filename);
                    seedGenome = XmlNeatGenomeReaderStatic.Read(document);
                }
                catch (Exception e)
                {
                    System.Console.WriteLine("Problem loading genome. \n" + e.Message);
                }
            }

            double       maxFitness     = 0;
            int          maxGenerations = 1000;
            int          populationSize = 150;
            int          inputs         = 4;
            IExperiment  exp            = new SkirmishExperiment(inputs, 1, isMulti, shape);
            StreamWriter SW;

            SW = File.CreateText(folder + "logfile.txt");
            XmlDocument        doc;
            FileInfo           oFileInfo;
            IdGenerator        idgen;
            EvolutionAlgorithm ea;

            if (seedGenome == null)
            {
                idgen = new IdGenerator();
                ea    = new EvolutionAlgorithm(new Population(idgen, GenomeFactory.CreateGenomeList(exp.DefaultNeatParameters, idgen, exp.InputNeuronCount, exp.OutputNeuronCount, exp.DefaultNeatParameters.pInitialPopulationInterconnections, populationSize)), exp.PopulationEvaluator, exp.DefaultNeatParameters);
            }
            else
            {
                idgen = new IdGeneratorFactory().CreateIdGenerator(seedGenome);
                ea    = new EvolutionAlgorithm(new Population(idgen, GenomeFactory.CreateGenomeList(seedGenome, populationSize, exp.DefaultNeatParameters, idgen)), exp.PopulationEvaluator, exp.DefaultNeatParameters);
            }
            for (int j = 0; j < maxGenerations; j++)
            {
                DateTime dt = DateTime.Now;
                ea.PerformOneGeneration();
                if (ea.BestGenome.Fitness > maxFitness)
                {
                    maxFitness = ea.BestGenome.Fitness;
                    doc        = new XmlDocument();
                    XmlGenomeWriterStatic.Write(doc, (NeatGenome)ea.BestGenome);
                    oFileInfo = new FileInfo(folder + "bestGenome" + j.ToString() + ".xml");
                    doc.Save(oFileInfo.FullName);

                    // This will output the substrate, uncomment if you want that

                    /* doc = new XmlDocument();
                     * XmlGenomeWriterStatic.Write(doc, (NeatGenome) SkirmishNetworkEvaluator.substrate.generateMultiGenomeModulus(ea.BestGenome.Decode(null),5));
                     * oFileInfo = new FileInfo(folder + "bestNetwork" + j.ToString() + ".xml");
                     * doc.Save(oFileInfo.FullName);
                     */
                }
                Console.WriteLine(ea.Generation.ToString() + " " + ea.BestGenome.Fitness + " " + (DateTime.Now.Subtract(dt)));
                //Do any post-hoc stuff here

                SW.WriteLine(ea.Generation.ToString() + " " + (maxFitness).ToString());
            }
            SW.Close();

            doc = new XmlDocument();
            XmlGenomeWriterStatic.Write(doc, (NeatGenome)ea.BestGenome, ActivationFunctionFactory.GetActivationFunction("NullFn"));
            oFileInfo = new FileInfo(folder + "bestGenome.xml");
            doc.Save(oFileInfo.FullName);
        }
예제 #14
0
        public void showMovie(string genomeFile, int type)
        {
            if (true) // set to false to use hardcoded output values from a file
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(genomeFile);
                NeatGenome genome = XmlNeatGenomeReaderStatic.Read(doc);

                INetwork   tempNet    = null;
                INetwork   cppn       = null;
                NeatGenome tempGenome = null;

                Substrate substrate;

                if (type == 0)
                {
                    substrate = new CTRNNSubstrate(4, 12, 8, HyperNEATParameters.substrateActivationFunction);
                }
                else if (type == 1)
                {
                    substrate = new SUPGSubstrate(4, 12, 12, HyperNEATParameters.substrateActivationFunction);
                }
                else
                {
                    doClune   = true;
                    substrate = new CluneSubstrate(20, 20, 20, HyperNEATParameters.substrateActivationFunction);
                }

                cppn       = genome.Decode(null);
                tempGenome = substrate.generateGenome(cppn);

                tempNet = tempGenome.Decode(null);

                Controller controller;
                if (type == 0)
                {
                    controller = new Controller(tempNet);
                }
                else if (type == 1)
                {
                    controller = new Controller(tempNet, true, tempGenome, cppn, ((SUPGSubstrate)substrate).getSUPGMap());
                }
                else
                {
                    controller = new Controller(tempNet);
                }


                using (var domain = new Domain())
                {
                    domain.Initialize(controller);
                    domain.RunDraw();
                }
            }
            else
            {
                using (var domain = new Domain())
                {
                    domain.Initialize();
                    domain.RunDraw();
                }
            }
        }
        private void startEvolutionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            NeatGenome seedGenome = null;

            if (EvoSeedFileName != null)
            {
                try
                {
                    XmlDocument document = new XmlDocument();
                    document.Load(EvoSeedFileName);
                    seedGenome = XmlNeatGenomeReaderStatic.Read(document);
                }
                catch (Exception ex)
                {
                    System.Console.WriteLine("Problem loading genome. \n" + ex.Message);
                }
            }

            double      maxFitness     = 0;
            int         maxGenerations = 1000;
            int         populationSize = 150;
            int         inputs         = 4;
            IExperiment exp            = new SkirmishExperiment(inputs, 1, EvoIsMulti, EvoShape);

            w     = SkirmishNetworkEvaluator.lWorldVar(network, 125);
            timer = 0;

            StreamWriter SW;

            SW = File.CreateText(EvoOutputLogFolder + "logfile.txt");
            XmlDocument        doc;
            FileInfo           oFileInfo;
            IdGenerator        idgen;
            EvolutionAlgorithm ea;

            if (seedGenome == null)
            {
                idgen = new IdGenerator();
                ea    = new EvolutionAlgorithm(
                    new Population(idgen,
                                   GenomeFactory.CreateGenomeList(
                                       exp.DefaultNeatParameters, idgen,
                                       exp.InputNeuronCount, exp.OutputNeuronCount,
                                       exp.DefaultNeatParameters.pInitialPopulationInterconnections,
                                       populationSize)),
                    exp.PopulationEvaluator, exp.DefaultNeatParameters);
            }
            else
            {
                idgen = new IdGeneratorFactory().CreateIdGenerator(seedGenome);
                ea    = new EvolutionAlgorithm(new Population(idgen, GenomeFactory.CreateGenomeList(seedGenome, populationSize, exp.DefaultNeatParameters, idgen)), exp.PopulationEvaluator, exp.DefaultNeatParameters);
            }
            for (int j = 0; j < maxGenerations; j++)
            {
                DateTime dt = DateTime.Now;
                ea.PerformOneGeneration();
                if (ea.BestGenome.Fitness > maxFitness)
                {
                    maxFitness = ea.BestGenome.Fitness;
                    doc        = new XmlDocument();
                    XmlGenomeWriterStatic.Write(doc, (NeatGenome)ea.BestGenome);
                    oFileInfo = new FileInfo(EvoOutputLogFolder + "bestGenome" + j.ToString() + ".xml");
                    doc.Save(oFileInfo.FullName);

                    // This will output the substrate, uncomment if you want that

                    /* doc = new XmlDocument();
                     * XmlGenomeWriterStatic.Write(doc, (NeatGenome) SkirmishNetworkEvaluator.substrate.generateMultiGenomeModulus(ea.BestGenome.Decode(null),5));
                     * oFileInfo = new FileInfo(folder + "bestNetwork" + j.ToString() + ".xml");
                     * doc.Save(oFileInfo.FullName);
                     */
                }
                Console.WriteLine(ea.Generation.ToString() + " " + ea.BestGenome.Fitness + " " + (DateTime.Now.Subtract(dt)));
                //Do any post-hoc stuff here

                SW.WriteLine(ea.Generation.ToString() + " " + (maxFitness).ToString());
            }
            SW.Close();

            doc = new XmlDocument();
            XmlGenomeWriterStatic.Write(doc, (NeatGenome)ea.BestGenome, ActivationFunctionFactory.GetActivationFunction("NullFn"));
            oFileInfo = new FileInfo(EvoOutputLogFolder + "bestGenome.xml");
            doc.Save(oFileInfo.FullName);
        }