Exemple #1
0
        public void engEngine_EvalFitnessForProgramEvent(BaseProgram progProgram,
                                                         BaseEngine sender)
        {
            if (progBestProgramInPreviousGeneration == null)
            {
                progBestProgramInPreviousGeneration = sender.Population[0][0];
            }

            float dAbsoluteFitness = 0;

            // Attempt to gather from 10 different tests.
            float dWorstCaseScenario = 99999999;

            for (int nTestNum = 0; nTestNum < 5; nTestNum++)
            {
                float dFitness = RunnerEvolution.ProgramRunner(m_cWorld, progProgram,
                                                               null, false);
                if (dFitness < dWorstCaseScenario)
                {
                    dWorstCaseScenario = dFitness;
                }

                /* dAbsoluteFitness += RunnerEvolution.ProgramRunner(m_cWorld, progProgram,
                 *   null, false);*/
            }

            progProgram.Fitness = 1000000 - dWorstCaseScenario;
        }
Exemple #2
0
        public void engEngine_GenerationIsCompleteEvent(Statistics stsStatistics,
                                                        BaseEngine sender)
        {
            strLabelString = "Generation num = " + stsStatistics.GenerationNumber + ", Min fitness = " +
                             stsStatistics.MinFitnessProgram.Fitness + ", Min fitness nodes = " + stsStatistics.MinFitnessProgram.Size;
            ((TreeProgram)stsStatistics.MinFitnessProgram).Draw(pnlDrawProgram.CreateGraphics(), pnlDrawProgram.Width, pnlDrawProgram.Height, this);

            if (((stsStatistics.GenerationNumber % 10) == 0) && (stsStatistics.GenerationNumber != 0))
            {
                for (int i = 0; i < 5; i++)
                {
                    RunnerEvolution.ProgramRunner(m_cWorld, stsStatistics.MinFitnessProgram,
                                                  pnlWorldView.CreateGraphics(), true);
                }
            }


            // Show statistics about the islands. Make a graph about the islands fitnesses.
            progBestProgramInPreviousGeneration = stsStatistics.MinFitnessProgram;

            float dMinimalFitnessInPopulation = stsStatistics.MinFitnessProgram.Fitness;
            float dMaxMinFitnessInIslands     = 0;

            for (int i = 0; i < sender.NumberOfIslands; i++)
            {
                BaseProgram cMinFitnessProgramForIsland = stsStatistics.GetMinFitnessProgramForIsland(i);
                if (cMinFitnessProgramForIsland.Fitness > dMaxMinFitnessInIslands)
                {
                    dMaxMinFitnessInIslands = cMinFitnessProgramForIsland.Fitness;
                }
            }

            int      ISLAND_BAR_WIDTH = (int)(pnlViewIslands.Width / sender.NumberOfIslands);
            Graphics g = pnlViewIslands.CreateGraphics();

            g.Clear(Color.Black);
            for (int i = 0; i < sender.NumberOfIslands; i++)
            {
                float dIslandFitness          = stsStatistics.GetMinFitnessProgramForIsland(i).Fitness;
                float dPrecentageOfMinFitness = (dIslandFitness - dMinimalFitnessInPopulation) / (dMaxMinFitnessInIslands - dMinimalFitnessInPopulation);
                g.FillRectangle(Brushes.RoyalBlue, i * ISLAND_BAR_WIDTH, pnlViewIslands.Height - (pnlViewIslands.Height * dPrecentageOfMinFitness), ISLAND_BAR_WIDTH, pnlViewIslands.Height);
            }

            // Write the max and min fitnesses value on the graph.
            g.DrawString(dMaxMinFitnessInIslands.ToString(), new Font("Times New Roman", 12.0f), Brushes.Red, 0, 0);
            g.DrawString(dMinimalFitnessInPopulation.ToString(), new Font("Times New Roman", 12.0f), Brushes.Red, 0, pnlViewIslands.Height - 20);
        }