public void algorithm_loop() { this.output.Focus(); this.output.AppendText("START\n"); do { var eval_list = population.Select(x => evalSelector.Evaluate(x)); var avg = eval_list.Average(); var max = eval_list.Max(); series.Points.AddXY(it, avg); series2.Points.AddXY(it, max); this.output.AppendText(String.Format(" iteracja nr {0} avg:{1:0.000} max:{2:0.000}\n", it++, avg, max)); //wydzielenie podzbiorow var planyGrup = new Dictionary<Grupa, IList<Timetable>>(); foreach (var osobnik in population) { var lista_grup = osobnik.Gens.Select(x => x.Grupa).Distinct(); foreach (var grupa in lista_grup) { Application.DoEvents(); var planGrupy = new Timetable(mutation); IList<TimetableLocus> loci = (from locus in osobnik.Loci where osobnik[locus].Grupa.Equals(grupa) select locus).ToList(); foreach (var locus in loci) planGrupy[locus] = osobnik[locus]; IList<Timetable> lista; if (!planyGrup.TryGetValue(grupa, out lista)) { lista = new List<Timetable>(); planyGrup.Add(grupa, lista); } lista.Add(planGrupy); } } var listaGrup = planyGrup.Keys.ToList(); for (int i = 0; i < listaGrup.Count; i++) { Application.DoEvents(); IGeneticAlgorithmEngine<Timetable> ga_grupy; ga_grupy = new GeneticAlgorithmEngine<Timetable, TimetableLocus, Zajecia>(planyGrup[listaGrup[i]], selector, reproducer, 20); ga_grupy.Iterate(() => { //planGrupy.Value = ga_grupy.Population; return ga_grupy.Population.Select(x => evalSelector.Evaluate(x)).Average() > 0.95; }); planyGrup[listaGrup[i]] = ga_grupy.Population; } //polaczenie podzbiorow var nowaPopulacja = new List<Timetable>(); for (int i = 0; i < population.Count; i++) { Application.DoEvents(); var osobnik = new Timetable(mutation); foreach (var planGrupy in planyGrup) { osobnik.Concat(planGrupy.Value[i]); } } } while ((population.Select(x => evalSelector.Evaluate(x)).Average() < 0.95) && !stop_button); if (!stop_button) { //wypisanie wyniku this.output.AppendText("ZAKOŃCZONO\n"); stop_Click(null, null); stop_button = false; } else { try { output.AppendText("STOP\n"); } catch (Exception){} } }