Exemple #1
0
    /// <summary>
    /// Add the values of the current generation to the csv file.
    /// </summary>
    private void AddStatsOfCurrentGenerationToBench()
    {
        // Get fitnesses for each car
        var carFitnesses = new List <float>(PopulationSize);
        var carSizes     = new List <float>(PopulationSize);

        foreach (var dna in GeneticAglorithm.PreviousPopulation) // Previous population is current generation.
        {
            carFitnesses.Add(dna.Fitness);
        }

        foreach (var car in Cars)
        {
            carSizes.Add(GetCarArea(car.GetComponent <Car>()));
        }

        // Get best car.
        var bestCar = Cars[GeneticAglorithm.BestFitnessIndex].GetComponent <Car>();

        BenchData.CarData bestCarData = new BenchData.CarData();
        bestCarData.Speed     = bestCar.Speed;
        bestCarData.TotalArea = GetCarArea(bestCar);

        // Populate bench data
        var benchData = new BenchData();

        benchData.Generation          = GeneticAglorithm.Generation;
        benchData.CarFitnesses        = carFitnesses.ToArray();
        benchData.CarSizes            = carSizes.ToArray();
        benchData.BestCarOfGeneration = bestCarData;

        // Store it for later use
        BenchData.Add(benchData);
    }
Exemple #2
0
 private void WriteTextSafe(BenchData data)
 {
     if (textBox1.InvokeRequired)
     {
         var d = new SafeCallDelegate(WriteTextSafe);
         textBox1.Invoke(d, new object[] { data });
     }
     else
     {
         benchDatas.Add(data);
         textBox1.AppendText(string.Format("{0} {1}: {2}Мб/с{3}",
                                           data.type, data.mode.Replace(Environment.NewLine, " "), data.speed, Environment.NewLine));
         if (radioButton1.Checked)
         {
             dataTable.Rows
             .Find(data.mode)[data.type] = data.speed;
         }
         else
         {
             float maxSpeed = benchDatas
                              .FindAll(x => x.mode.Equals(data.mode))
                              .Max(y => y.speed);
             benchDatas
             .Where(x => x.mode.Equals(data.mode))
             .ToList()
             .ForEach(y =>
                      dataTable.Rows
                      .Find(y.mode)[y.type] = y.speed * 100 / maxSpeed
                      );
         }
         chart.DataBind();
     }
 }