Beispiel #1
0
 public static void Save(string file, KeepawayConfig conf)
 {
     using (System.IO.StreamWriter write = new System.IO.StreamWriter(file))
     {
         serial.Serialize(write, conf);
     }
 }
Beispiel #2
0
        public static void addToArchive(List <NetworkGenome> GenomesList)
        {
            config = KeepawayConfig.Load("KeepawayConfig.xml");
            List <NetworkGenome> sortedList = GenomesList.OrderByDescending(g => g.Novelty).Take(config.archiveLimit).ToList();

            foreach (NetworkGenome archiveList in sortedList)
            {
                if (archiveList.Novelty > config.archiveThreshold)
                {
                    archive.Add(archiveList.BehaviorType);
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Computes the genome average novelty
        /// based on k nearest neighbors and against the archive
        /// </summary>
        /// <param name="neatGenome"></param>
        /// <param name="genomeList"></param>
        /// <returns></returns>
        public double computeNovelty(NetworkGenome neatGenome, List <NetworkGenome> genomeList)
        {
            config = KeepawayConfig.Load("KeepawayConfig.xml");
            double novelty = 0.0;
            //double dist = 0.0;
            List <NetworkGenome> Genomes = genomeList;
            int           len            = Genomes.Count + archive.Count;
            NetworkGenome neatgenomes;
            List <Pair <double, NetworkGenome> > noveltyList = new List <Pair <double, NetworkGenome> >();

            //if (genomeList.Count == 0) novelty = 0.002;
            foreach (NetworkGenome genome in genomeList)
            {
                //add a list of behaviors
                if (neatGenome != genome)
                {
                    noveltyList.Add(new Pair <double, NetworkGenome>(Behavior.BehaviorDistance(((NetworkGenome)genome).BehaviorType, neatGenome.BehaviorType), ((NetworkGenome)genome)));
                }
            }
            //noveltyList.Sort(CompareFirst);
            //easy break tires
            noveltyList = noveltyList.OrderBy(o => o.First).ThenBy(o => o.Second.Fitness).ToList();
            int neighbors = config.nearestNeighbors;

            if (noveltyList.Count < config.nearestNeighbors)
            {
                neighbors = noveltyList.Count;
            }
            //test against k nearest neighbors
            for (int i = 0; i < neighbors; i++)
            {
                novelty += noveltyList[i].First;
                neatGenome.nearestNeighbors++;
            }
            //test against the archive
            foreach (NetworkGenome inArchive in archive)
            {
                novelty += Behavior.BehaviorDistance(neatGenome.BehaviorType, inArchive.BehaviorType);
            }
            //average novelty of genome x
            novelty /= (neighbors + archive.Count());
            return(novelty);
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            #region Initialization

            timer.AddReferee(kref);

            config = KeepawayConfig.Load("KeepawayConfig.xml");
            HyperNEATKeepawayPlayer.config = config;


            evo.SetParameters("Parameters.xml");

            evo.Evaluator = new EvaluateGenome(HyperNEATKeepaway);
            evo.Initialise();

            sub.GenerateNodes(NodeGeneration);
            sub.GenerateLinks(LinkCreation);

            std.Realtime = false;

            for (int i = 0; i < config.NumKeepers; i++)
            {
                players.Add(new HyperNEATKeepawayPlayer(std, "keepers", i + 1, "l", config.NumKeepers, config.NumTakers));
            }

            for (int i = 0; i < config.NumTakers; i++)
            {
                players.Add(new HyperNEATKeepawayPlayer(std, "takers", i + 1, "r", config.NumKeepers, config.NumTakers));
            }

            for (int i = 0; i < players.Count; i++)
            {
                std.addPlayer(players[i]);
            }



            evo.AllGenerations();


            #endregion
        }
Beispiel #5
0
        /// <summary>
        /// returns the genome diversity
        /// considers the k-nearest neighbors and the archive
        /// </summary>
        /// <param name="GenomesList"></param>
        /// <param name="genomes"></param>
        /// <returns></returns>
        public double DiversityDistance(List <NetworkGenome> GenomesList, NetworkGenome genomes)
        {
            config = KeepawayConfig.Load("KeepawayConfig.xml");
            List <NetworkGenome> Genomes = GenomesList;
            double diversity_dist        = 0;
            List <Pair <double, NetworkGenome> > diversityList = new List <Pair <double, NetworkGenome> >();

            foreach (NetworkGenome networkGenomes in Genomes)
            {
                if (networkGenomes != genomes)
                {
                    diversityList.Add(new Pair <double, NetworkGenome>(this.GenomeCompatibility(genomes, networkGenomes), networkGenomes));
                }
            }

            //diversityList.Sort(CompareFirstFirst);
            //sort order
            diversityList = diversityList.OrderBy(o => o.First).ThenBy(o => o.Second.Fitness).ToList();
            int neighbors = config.nearestNeighbors;

            //if list less than k nearestneighbors
            if (diversityList.Count < config.nearestNeighbors)
            {
                neighbors = diversityList.Count;
            }
            //compute a sum of the first k nearestneighbors distances of genome x
            for (int i = 0; i < neighbors; i++)
            {
                diversity_dist += diversityList[i].First;
                genomes.nearestNeighbors++;
            }
            //test against the archive
            foreach (NetworkGenome inArchive in archiveGD)
            {
                diversity_dist += this.GenomeCompatibility(genomes, inArchive);
            }
            //compute average diversity
            genotype_Diversity = diversity_dist / ((neighbors + archiveGD.Count));

            return(genotype_Diversity);
        }