Пример #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
            List <Chromosome> population = new List <Chromosome>();
            int totalPop = Convert.ToInt32(numPopulation.Value);

            population = Chromosome.CreatePop(totalPop);
            MessageBox.Show(population[1].GeneX.ToString() + "<<<<<<<<<<<" + population[1].GeneY.ToString() + "<<<<<<<<<<<<" + population[1].targetFuncRes.ToString());

            double[] avgtargetfunc = new double[Convert.ToInt32(numIteration.Value)];
            for (int iteration = 1; iteration <= Convert.ToInt32(numIteration.Value); iteration++)
            {
                population = Iteration(population, Convert.ToDouble(numMutation.Value), Convert.ToInt32(numPopulation.Value));
                double avgoftargetfunc = 0;
                for (int i = 0; i < population.Count; i++)
                {
                    avgoftargetfunc += population[i].targetFuncRes;
                }
                avgoftargetfunc /= population.Count;
                listBox1.Items.Add(Math.Round(avgoftargetfunc, 4));
                avgtargetfunc[iteration - 1] = avgoftargetfunc;
            }
            DrawGraph(avgtargetfunc);
        }