Beispiel #1
0
 private void sort_Click(object sender, EventArgs e)
 {
     //Array.Sort(CurrentPop.ind); // works
     //Console.Write(Population.Select(CurrentPop.ind));
     Robot_call.Update_bars(CurrentPop.ind[Population.Pop_size - 1 - _individual]._DNA);
     Robot_call.Update_pts(CurrentPop.ind[Population.Pop_size - 1 - _individual]._DNA);
     Robot_call.Robot_interactive(true);
     Robot_call.Refresh();
     _individual++;
 }
Beispiel #2
0
        private void draw_Click(object sender, EventArgs e)
        {
            int c = 0;

            this.Chart.Series.Clear();
            this.Chart.Titles.Add("Fitness");
            System.Windows.Forms.DataVisualization.Charting.Series series = this.Chart.Series.Add("fitness");
            series.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline;

            double best  = 0.0;
            int    count = 0;

            CurrentPop = new Population(NextPop.ind);
            for (int i = 0; i < 928; i++)
            {
                Generation.Text = i.ToString();
                // CurrentPop = new Population(NextPop.ind);
                if (i == 0)
                {
                    for (int a = 0; a < Population.Pop_size; a++)
                    {
                        CurrentPop.ind[a].Evaluate();
                        c++;
                        series.Points.AddXY(c, CurrentPop.ind[a].fitness);
                        //Robot_call.Robot_interactive(true);
                    }
                    best = CurrentPop.ind[4].fitness;
                }
                else    /*CurrentPop.ind[0].Evaluate();*/
                {
                    c++;
                    series.Points.AddXY(c, CurrentPop.ind[0].fitness);
                }

                Array.Sort(CurrentPop.ind);

                if (best == CurrentPop.ind[Population.Pop_size - 1].fitness)
                {
                    count++;
                }
                else
                {
                    best = CurrentPop.ind[Population.Pop_size - 1].fitness; count = 0;
                }
                if (count > 200)
                {
                    break;
                }

                Individual temp = Population.Evolve_single(CurrentPop.ind, i);
                temp.Evaluate();

                if (temp.fitness < CurrentPop.ind[0].fitness)
                {
                    CurrentPop.ind[0] = temp;
                }
                else
                {
                    CurrentPop.ind[0] = temp;
                }
                //CurrentPop.ind[0] = temp; //Population.Evolve_single(CurrentPop.ind, i).Evaluate();
                //Robot_call.Robot_interactive(true);
                //Robot_call.Refresh();

                //LastPop = new Population(CurrentPop.ind);
                //NextPop = new Population(Population.Evolve(CurrentPop.ind,i));
            }
            // CurrentPop.ind[Population.Pop_size - 1].Evaluate();

            Robot_call.Update_bars(CurrentPop.ind[Population.Pop_size - 1]._DNA);
            Robot_call.Update_pts(CurrentPop.ind[Population.Pop_size - 1]._DNA);
            Robot_call.Robot_interactive(true);
            Robot_call.Refresh();
        }