Пример #1
0
        private void Save()
        {
            this.Current.Genomes.Sort((Comparison <NetworkGenome>)((b, a) => a.Fitness.CompareTo(b.Fitness)));
            NetworkGenome genome = this.Current.Genomes[0];

            this.Champions.Add(genome);
            this.Current.Genomes.Sort((Comparison <NetworkGenome>)((a, b) => a.Species.CompareTo(b.Species)));
            if (this.Saves.Champions.save && this.Generation % this.Saves.Champions.inteval == 0)
            {
                NetworkGenome.SaveToFile(genome, this.Saves.Champions.path + "G" + this.Generation.ToString("0000") + "Champ.xml");
            }
            if (this.Saves.Populations.save && this.Generation % this.Saves.Populations.inteval == 0)
            {
                Population.SaveToXml(this.Saves.Populations.path + "G" + this.Generation.ToString("0000") + "Pop.xml", this.Current);
            }
            if (this.Saves.PopulationStatistics.save && (this.Generation % this.Saves.PopulationStatistics.inteval == 0 || this.Generation == 1))
            {
                this.PopulationStatsFile.WriteLine((string)(object)this.Current.Generation + (object)"\t" + (string)(object)this.Current.MeanFitness + "\t" + (string)(object)this.Current.MaxFitness);
            }
            if (this.Saves.Species.save && this.Generation % this.Saves.Species.inteval == 0)
            {
                for (int index = 0; index < this.species.Count; ++index)
                {
                    Species.SaveToXml(this.Saves.Species.path + "G" + this.Generation.ToString("0000") + "Species" + index.ToString("0000") + ".xml", this.species[index]);
                }
            }
            if (!this.Saves.SpeciesStatistics.save || this.Generation % this.Saves.SpeciesStatistics.inteval != 0)
            {
                return;
            }
            this.WriteSpeciesStats();
        }
Пример #2
0
        //by phillip
        static void MapWeights(NetworkGenome genome, DecodedNetworks cppn)
        {
            double[]       coords = new double[4];
            double[]       output;
            LinkGene       temp;
            SubstrateNodes source;
            SubstrateNodes target;

            int linkId = 0;

            for (int i = 1; i < genome.Links.Count; i++)
            {
                temp   = genome.Links[i];
                source = (SubstrateNodes)genome.Nodes[temp.Source];
                target = (SubstrateNodes)genome.Nodes[temp.Target];
                if (temp.Source != 0)
                {
                    coords[0] = source.Coordinate[0];
                    coords[1] = source.Coordinate[1];
                }
                else
                {
                    coords[0] = target.Coordinate[0];
                    coords[1] = target.Coordinate[1];
                }
                coords[2] = target.Coordinate[0];
                coords[3] = target.Coordinate[1];
                cppn.Flush();
                cppn.SetInputs(coords);
                cppn.ActivateNetwork(5);
                output = cppn.GetOutputs();


                if (source.Id != 0)
                {
                    temp.Weight = output[0];
                }
                else
                {
                    temp.Weight = output[1];
                }
            }

            if (saveSub)
            {
                NetworkGenome.SaveToFile(genome, "Sub.xml");
                saveSub = false;
            }
        }
Пример #3
0
 private void PerformTest()
 {
     if (this.Tests.Directory.test || this.Tests.Genome.test)
     {
         int num = this.Evaluator(this.Current.Genomes, true) ? 1 : 0;
         if (this.Tests.Genome.test)
         {
             NetworkGenome.SaveToFile(this.Current.Genomes[0], this.Tests.Genome.path);
         }
         else
         {
             using (StreamWriter streamWriter = new StreamWriter(this.Tests.Directory.path + "Results.txt"))
             {
                 for (int index = 0; index < this.Current.Genomes.Count; ++index)
                 {
                     streamWriter.WriteLine(this.Current.Genomes[index].Fitness);
                 }
             }
         }
     }
     else
     {
         if (!this.Tests.ChampionsAtEnd.test)
         {
             return;
         }
         int num = this.Evaluator(this.Champions, true) ? 1 : 0;
         using (StreamWriter streamWriter = new StreamWriter(this.Tests.ChampionsAtEnd.path + "ChampResults.txt"))
         {
             for (int index = 0; index < this.Champions.Count; ++index)
             {
                 streamWriter.WriteLine(this.Champions[index].Fitness);
             }
         }
     }
 }