Exemplo n.º 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 20 different tests.
            for (int nTestNum = 0; nTestNum < 5; nTestNum++)
            {
                dAbsoluteFitness += CAEvolution.ProgramRunner(progProgram,
                                                              progBestProgramInPreviousGeneration, null, false);
            }

            progProgram.Fitness = 100000 - dAbsoluteFitness;
        }
Exemplo n.º 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 % 20) == 0)
            {
                CAEvolution.ProgramRunner(stsStatistics.MinFitnessProgram,
                                          progBestProgramInPreviousGeneration, pnlMatrixDisplay.CreateGraphics(), true);

                CAEvolution.ProgramRunner(stsStatistics.MinFitnessProgram,
                                          progBestProgramInPreviousGeneration, pnlMatrixDisplay.CreateGraphics(), true);

                CAEvolution.ProgramRunner(stsStatistics.MinFitnessProgram,
                                          progBestProgramInPreviousGeneration, pnlMatrixDisplay.CreateGraphics(), true);
            }

            progBestProgramInPreviousGeneration = stsStatistics.MinFitnessProgram;
        }