private void CheckForBestInDB(ref List<int> currentBest, ref double fitness, ref double bestEverFitness, ref List<int> BestEverChromo) { List<List<int>> testChromos = new List<List<int>>(); GeneticAlgo.GA_DBDataSetTableAdapters.BestsTableAdapter regionTableAdapter = new GeneticAlgo.GA_DBDataSetTableAdapters.BestsTableAdapter(); GeneticAlgo.GA_DBDataSet.BestsDataTable table = null; if (m_dimension == GA_Type._2D) table = regionTableAdapter.GetDataBy2D(); else table = regionTableAdapter.GetDataBy3D(); string tmp = ""; for (int i = 0; i < table.Rows.Count; i++) { List<int> chromo = new List<int>(); if ((int)table.Rows[i][2] == m_size) { tmp = table.Rows[i][0].ToString(); foreach (char c in tmp) { try { chromo.Add(Convert.ToInt32(c.ToString())); } catch { } } if (chromo.Count == m_size) testChromos.Add(new List<int>(chromo)); } } List<double> fitnesses = new List<double>(); List<int> best = new List<int>(); if (testChromos.Count == 0) return; testChromos.ForEach((chromosome) => { if (chromosome.Count > 0) fitnesses.Add(Eval(ref chromosome, ref best)); }); if (fitness < fitnesses.Max()) { BestEverChromo = testChromos[fitnesses.IndexOf(fitnesses.Max())]; bestEverFitness = fitnesses.Max(); } }
void AddToDB(ref List<int> chromosome, ref double fitness) { if (chromosome.Count == 0) return; GeneticAlgo.GA_DBDataSetTableAdapters.BestsTableAdapter regionTableAdapter = new GeneticAlgo.GA_DBDataSetTableAdapters.BestsTableAdapter(); string chromoString = ""; chromosome.ForEach(chromo => chromoString += chromo.ToString()); regionTableAdapter.Insert((float)fitness, chromoString, m_size, m_dimension == GA_Type._2D ? "2D" : "3D"); }