Beispiel #1
0
        public void TestGeneticSimulation()
        {
            simulation = new GeneticSimulation <BoolGene>(100, 5, new BoolGrowthLimitedFitness(), new AsymmetricCrossoverRecombinator(), new AlphaSelector(), new PieCakeSelector());
            //simulation.GeneDuplicationRate = 0.00001;
            simulation.SimulationTurn += new OnSimulationTurn(TestDelegate);
            simulation.RunSimulation();

            Assert.IsTrue(delegateRun);

            delegateRunCount = 0;
            simulation.RunSimulation(1000);

            Assert.AreEqual(1000, delegateRunCount, "Did not run 1000 times!");

            /* Assert.AreEqual(5.0, simulation.AverageFitness, 0.5, "This may occur, rerun Test and see if it keeps happening!");
             * Assert.AreEqual(5.0, simulation.MostSuccessfullIndividual.Fitness, "This may occur, rerun Test and see if it keeps happening!");*/

            simulation.ResetSimulation();
            delegateRunCount = 0;
            delegateRun      = false;
            simulation.GeneDuplicationRate = 0.01;

            simulation.RunSimulation();

            Assert.IsTrue(delegateRun);

            delegateRunCount = 0;
            simulation.RunSimulation(10);

            /*    Assert.AreEqual(10, delegateRunCount, "Did not run 10 times!");
             *  Assert.IsTrue(simulation.AverageChromosomeLength > 5, "Average Chromosome Lengtrh not > 5");                */
        }
        public void TestGeneticSimulation()
        {
            simulation = new GeneticSimulation<BoolGene>(100, 5, new BoolGrowthLimitedFitness(), new AsymmetricCrossoverRecombinator(), new AlphaSelector() ,new PieCakeSelector());
            //simulation.GeneDuplicationRate = 0.00001;
            simulation.SimulationTurn += new OnSimulationTurn(TestDelegate);
            simulation.RunSimulation();

            Assert.IsTrue(delegateRun);

            delegateRunCount = 0;
            simulation.RunSimulation(1000);

            Assert.AreEqual(1000, delegateRunCount, "Did not run 1000 times!");

               /* Assert.AreEqual(5.0, simulation.AverageFitness, 0.5, "This may occur, rerun Test and see if it keeps happening!");
            Assert.AreEqual(5.0, simulation.MostSuccessfullIndividual.Fitness, "This may occur, rerun Test and see if it keeps happening!");*/

            simulation.ResetSimulation();
            delegateRunCount = 0;
            delegateRun = false;
            simulation.GeneDuplicationRate = 0.01;

            simulation.RunSimulation();

            Assert.IsTrue(delegateRun);

            delegateRunCount = 0;
            simulation.RunSimulation(10);

            /*    Assert.AreEqual(10, delegateRunCount, "Did not run 10 times!");
            Assert.IsTrue(simulation.AverageChromosomeLength > 5, "Average Chromosome Lengtrh not > 5");                */
        }
Beispiel #3
0
        /// <summary>
        /// Simulation start
        /// </summary>
        /// <param name="sender">Sender Object</param>
        /// <param name="e">Event Object</param>
        private void btn_Simuliere_Click(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;
            btn_Simulate.Enabled = false;
            btn_Reset.Enabled    = false;
            btn_AutoSim.Enabled  = false;
            btn_SimAbort.Focus();
            //erster Durchlauf der Simulation
            if (GenSim == null)
            {
                btn_Play.Enabled             = true;
                txt_ChromosomeLength.Enabled = false;
                cmb_Recombinator.Enabled     = false;
                cmb_Selector.Enabled         = false;
                txt_Weight.Enabled           = false;
                txt_Height.Enabled           = false;
                txt_Engine.Enabled           = false;
                txt_MutationsRate.Enabled    = false;
                txt_LossRate.Enabled         = false;
                txt_DuplicationsRate.Enabled = false;
                IntGene.MaxValue             = Convert.ToInt32(txt_Engine.Text);
                MoonSim = new MondlandungsSimulation(Convert.ToInt32(txt_Height.Text), Convert.ToInt32(txt_Engine.Text), Convert.ToInt32(txt_Weight.Text), tsmi_SpacemanHeight.Checked);
                GenSim  = new GeneticSimulation <IntGene>(100, Convert.ToInt32(txt_ChromosomeLength.Text), MoonSim, recombinationProvider, selectionProvider);
                GenSim.SimulationTurn     += OnSimulationTurn;
                GenSim.GeneMutationRate    = Convert.ToDouble(txt_MutationsRate.Text);
                GenSim.GeneDuplicationRate = Convert.ToDouble(txt_DuplicationsRate.Text);
                GenSim.GeneDropRate        = Convert.ToDouble(txt_LossRate.Text);
            }
            //automatisierte Simulation bis Erreichen der Delta-Fitness
            if (sender == btn_AutoSim)
            {
                btn_SimAbort.Focus();
                float fitnessGrenze = Convert.ToSingle(txt_Fitness.Text);
                float startFitness  = GenSim.AverageFitness;
                while (fitnessGrenze + startFitness > GenSim.AverageFitness && !simulationAbort)
                {
                    Application.DoEvents();
                    GenSim.RunSimulation();
                }
                simulationAbort      = false;
                btn_Simulate.Enabled = true;
                btn_Reset.Enabled    = true;
                btn_AutoSim.Enabled  = true;
            }
            //einfache Simulation mit angegebener Rundenzahl
            else
            {
                GenSim.RunSimulation(Convert.ToInt32(txt_RoundNumber.Text));
            }

            if (!closingApplication)
            {
                dgv_Population.Rows.Clear();

                dgv_Population.Rows.Add(GenSim.PoppulationSize);
                for (int i = 0; i < GenSim.PoppulationSize; i++)
                {
                    dgv_Population.Rows[i].Cells[0].Value = GenSim[i].GeneCount.ToString();
                    dgv_Population.Rows[i].Cells[1].Value = GenSim[i].ToString();
                    dgv_Population.Rows[i].Cells[2].Value = GenSim[i].Fitness.ToString();
                    dgv_Population.Rows[i].Tag            = GenSim[i];
                }

                zgc_Simulationsgraph.AxisChange();
                zgc_Simulationsgraph.Invalidate();
                Cursor = Cursors.Default;
                btn_Simulate.Enabled = true;
                btn_Reset.Enabled    = true;
                btn_AutoSim.Enabled  = true;
            }
        }