public Generation(IEnumerable<Chromosome> chromosomes, AlgorithmSettings settings) { Id = 0; InitialChromosomes = chromosomes.ToList(); Settings = settings; Previous = null; }
private void button1_Click(object sender, EventArgs e) { richTextBox1.Text = ""; desc.Clear(); alg = new PGA(); OptimizationModel optModel = new OptimizationModel(func); AlgorithmSettings settings = new AlgorithmSettings() { InitialLoadType = (InitialLoadType)comboBox1.SelectedItem, OptModel = optModel, InitialPointCount = (int)numericUpDown1.Value, SelectionType = (SelectionType)comboBox2.SelectedItem, EndCondition = (EndCondition)comboBox3.SelectedItem, MaxGenerationCount = (int)numericUpDown2.Value, SurvivedCount = (int)numericUpDown3.Value, MutationChance = (double)numericUpDown4.Value, CrossingGenNumber = (int)numericUpDown5.Value, Tolerance = (double)numericUpDown6.Value, MutationChanceAfterCrossing = (double)numericUpDown7.Value, MutationType = (MutationType)comboBox4.SelectedItem }; alg.Run(settings); DrawRezult(alg); WriteRezult(alg); }
public void Run(AlgorithmSettings settings) { settings.OptModel.ResetCallCount(); Chromosome.ResetIdentity(); InitialMesh = MeshService.GetMesh(settings.OptModel, settings.InitialPointCount, settings.InitialLoadType); Generations = new List<Generation>(); Generations.Add(new Generation(InitialMesh.Chromosomes, settings)); int i = 0; while (!Generations[i].IsFinal) { Generations.Add(new Generation(Generations[i])); i++; } CallCount = settings.OptModel.CallCount; Best = Generations[i].BestChromosome; }
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { int progress = 0; optrez.Clear(); finalRez.Clear(); alg = new PGA(); OptimizationModel optModel = new OptimizationModel(func); EnumConverter InitialLoadTypeCollection = new EnumConverter(typeof(InitialLoadType)); EnumConverter EndConditionTypeCollecton = new EnumConverter(typeof(EndCondition)); EnumConverter MutationTypeCollecton = new EnumConverter(typeof(MutationType)); EnumConverter SelectionTypeCollection = new EnumConverter(typeof(SelectionType)); foreach (InitialLoadType il in InitialLoadTypeCollection.GetStandardValues()) { foreach (EndCondition ec in EndConditionTypeCollecton.GetStandardValues()) { foreach (MutationType mt in MutationTypeCollecton.GetStandardValues()) { foreach (SelectionType st in SelectionTypeCollection.GetStandardValues()) { double[] f1m = new double[(int)numericUpDown8.Value]; double[] f2m = new double[(int)numericUpDown8.Value]; double[] fm = new double[(int)numericUpDown8.Value]; double[] x1m = new double[(int)numericUpDown8.Value]; double[] x2m = new double[(int)numericUpDown8.Value]; for (int i = 0; i < (int)numericUpDown8.Value; i++) { AlgorithmSettings settings = new AlgorithmSettings() { InitialLoadType = il, OptModel = optModel, InitialPointCount = (int)numericUpDown1.Value, SelectionType = st, EndCondition = ec, MaxGenerationCount = (int)numericUpDown2.Value, SurvivedCount = (int)numericUpDown3.Value, MutationChance = (double)numericUpDown4.Value, CrossingGenNumber = (int)numericUpDown5.Value, Tolerance = (double)numericUpDown6.Value, MutationChanceAfterCrossing = (double)numericUpDown7.Value, MutationType = mt }; alg.Run(settings); double x1 = alg.Best.X1; double x2 = alg.Best.X2; double f1 = alg.Best.F; double f2 = alg.CallCount; double f = GetCriterion(f1, f2); f1m[i] = f1; f2m[i] = f2; fm[i] = f; x1m[i] = x1; x2m[i] = x2; optrez.Add(new OptRezult() { I = il, E = ec, S = st, M = mt, F1 = f1, F2 = f2, X1 = x1, X2 = x2, F = f }); } progress++; backgroundWorker1.ReportProgress(progress * 100 / 24); finalRez.Add(new OptRezult() { I = il, E = ec, S = st, M = mt, X1 = x1m.Average(), X2 = x2m.Average(), F1 = f1m.Average(), F2 = f2m.Average(), F = fm.Average() }); } } } } }