コード例 #1
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();
            }
        }
コード例 #2
0
        public override void EvaluatePopulation(Population pop, EvolutionAlgorithm ea)
        {
            // Evaluate in single-file each genome within the population.
            // Only evaluate new genomes (those with EvaluationCount==0).
            FoodGatherParams.fillLookups();
            FoodGatherParams.fillFood();
            int count = pop.GenomeList.Count;

            for (int i = 0; i < count; i++)
            {
                IGenome g = pop.GenomeList[i];
                if (g.EvaluationCount != 0)
                {
                    continue;
                }

                INetwork network = g.Decode(activationFn);
                if (network == null)
                {       // Future genomes may not decode - handle the possibility.
                    g.Fitness = EvolutionAlgorithm.MIN_GENOME_FITNESS;
                }
                else
                {
                    g.Fitness          = Math.Max(networkEvaluator.EvaluateNetwork(network), EvolutionAlgorithm.MIN_GENOME_FITNESS);
                    g.ObjectiveFitness = g.Fitness;
                }

                // Reset these genome level statistics.
                g.TotalFitness    = g.Fitness;
                g.EvaluationCount = 1;

                // Update master evaluation counter.
                evaluationCount++;
            }
            if (requestResolutionUp == true)
            {
                requestResolutionUp          = false;
                requestResolutionDown        = false;
                FoodGatherParams.resolution *= 2;
            }
            else if (requestResolutionDown == true)
            {
                requestResolutionUp   = false;
                requestResolutionDown = false;
                if (FoodGatherParams.resolution > 4)
                {
                    FoodGatherParams.resolution /= 2;
                }
            }
        }
コード例 #3
0
 private void playWithNetworkToolStripMenuItem_Click(object sender, EventArgs e)
 {
     FoodGatherParams.fillLookups();
     if (currentBest != null)
     {
         board = new Board(0, 500);
         Robot r;
         if (FoodGatherParams.circle)
         {
             r = new Robot(new PointF(250, 250), (int)FoodGatherParams.resolution, FoodGathererNetworkEvaluator.substrate.generateNetwork(currentBest));
         }
         else
         {
             r = new Robot(new PointF(250, 250), (int)FoodGatherParams.resolution, FoodGathererNetworkEvaluator.substrate.generateNetwork(currentBest));
         }
         board.AddRobot(r);
         this.Refresh();
     }
 }
コード例 #4
0
 private void Demo()
 {
     FoodGatherParams.fillLookups();
     FoodGatherParams.fillFood();
     for (int j = 0; j < FoodGatherParams.foodLocations.Length; j++)
     {
         Robot r;
         board = new Board(0, 500);
         if (FoodGatherParams.circle)
         {
             r = new Robot(new PointF(250, 250), (int)FoodGatherParams.resolution, FoodGathererNetworkEvaluator.substrate.generateNetwork(currentBest));
         }
         else
         {
             r = new Robot(new PointF(250, 250), (int)FoodGatherParams.resolution, FoodGathererNetworkEvaluator.substrate.generateNetwork(currentBest));
         }
         board.AddRobot(r);
         board.AddFood(new Food(FoodGatherParams.foodLocations[j]));
         board.gameView(this);
     }
 }