Exemplo n.º 1
0
        /// <summary>
        /// Inserts a new population in Database.
        /// </summary>
        /// <param name="simId">Simulation id.</param>
        /// <param name="p">Population.</param>
        private void InsertPopulationInDB()
        {
            Population p              = si.Population;
            int        g              = p.Generation;
            string     minFit         = p.GetWorst().GetFitness().ToString(CultureInfo.InvariantCulture);
            string     meanFit        = p.GetMean().GetFitness().ToString(CultureInfo.InvariantCulture);
            string     maxFit         = p.GetBest().GetFitness().ToString(CultureInfo.InvariantCulture);
            string     avgFit         = p.GetAverage().ToString(CultureInfo.InvariantCulture);
            string     simulated_at   = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            string     diversity      = p.MeasureDiversity().ToString(CultureInfo.InvariantCulture);
            string     diversity_main = p.MeasureDiversityMethod();

            System.Collections.Generic.Dictionary <string, double> divMeasures = p.GetDiversityMeasurements();

            query = String.Format("INSERT INTO gannai.population (simulation_id,"
                                  + " generation, min_fitness, max_fitness, avg_fitness, mean_fitness, simulated_at, diversity, diversity_main,"
                                  + " diversity_hamming, diversity_nntd, diversity_fitness)"
                                  + " VALUES('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}', '{10}', '{11}')",
                                  simId, g, minFit, maxFit, avgFit, meanFit, simulated_at, diversity, diversity_main,
                                  divMeasures["Hamming distance"].ToString(CultureInfo.InvariantCulture),
                                  divMeasures["NNTD"].ToString(CultureInfo.InvariantCulture),
                                  divMeasures["Unique fitness"].ToString(CultureInfo.InvariantCulture)
                                  );
            cmd = new MySqlCommand(query, connection);
            cmd.ExecuteNonQuery();
        }
Exemplo n.º 2
0
 public AIPlayer GetBest()
 {
     return(Population.GetBest());
 }