internal void Populate(GridBruteForce opt) { var x1 = opt.X1Array; var x2 = opt.X2Array; var res = opt.Result; dgr.ColumnCount = x1.Length; dgr.RowCount = x2.Length; for (int j = 0; j < x2.Length; j++) { if (x2[j] == res.X2) { dgr.Rows[j].HeaderCell.Style.BackColor = SystemColors.Highlight; } dgr.Rows[j].HeaderCell.Value = x2[j].ToString(); } for (int i = 0; i < x1.Length; i++) { dgr.Columns[i].HeaderCell.Value = x1[i].ToString(); if (x1[i] == res.X1) { dgr.Columns[i].HeaderCell.Style.BackColor = SystemColors.Highlight; } dgr.Columns[i].Width = 45; for (int j = 0; j < x2.Length; j++) { dgr[i, j].Value = opt.Matrix[i, j]; if (opt.Data.CheckRestrictions(x1[i], x2[j])) { dgr[i, j].Style.BackColor = Color.LightGreen; } } } }
public void Run() { Optimize.BasicData data = PrepareValues(); if (data == null) { return; } SetChartArea(data.Bounds); Plotting.Isolines(data).ForEach(s => chart.Series.Add(s)); Optimize opt; switch (method) { case 0: double par_step = Double.Parse(par1TextBox.Text); double par_step2 = Double.Parse(textBox4.Text); opt = new GridBruteForce(data, par_step); logstr = $"{methodcomboBox.Text}, Шаг: {par_step} - " + logstr; break; case 1: uint par_count = uint.Parse(par2TextBox.Text); opt = new MonteCarlo(data, par_count); logstr = $"{methodcomboBox.Text} - " + logstr; break; case 2: double par_eps = Double.Parse(textBox1.Text); Point startPoint = null; if (enableStartPoint.Checked == true) { double x1_0 = Double.Parse(textBox3.Text); double x2_0 = Double.Parse(textBox2.Text); startPoint = new Point(x1_0, x2_0, data.Function.Calc(x1_0, x2_0)); } par_step = Double.Parse(par1TextBox.Text); par_step2 = Double.Parse(textBox4.Text); opt = new HookeJeeves(data, par_eps, par_step, par_step2, startPoint); logstr = $"{methodcomboBox.Text}, Точность: {par_eps} " + logstr; break; case 3: return; break; default: return; break; } try { opt.RunOptimization(); resultlabel.Text = $"{opt.Result}\r\nДлительность: {opt.Duration} мс, {opt.Iterations} итер."; logstr = $"y({opt.Result.X1},{opt.Result.X2})={opt.Result.Y}, {opt.Duration} мс, {opt.Iterations} итер. - " + logstr; chart.Series.Add(Plotting.PlacePoint(opt.Result, Color.Crimson)); TableForm = new TableForm(); if (method == 2) { chart.Series.Add(Plotting.PlacePoints(((HookeJeeves)opt).Points, "path", Color.Black, 3, MarkerStyle.Star5, SeriesChartType.Line)); } Parallel.Invoke(() => { switch (method) { case 0: TableForm.Populate((GridBruteForce)opt); break; case 1: TableForm.Populate(((MonteCarlo)opt).Points); break; case 2: TableForm.Populate(((HookeJeeves)opt).Points); break; case 3: return; break; default: break; } }); } catch (OperationCanceledException) { MessageBox.Show("Не удалось найти точки, удовлетворяющие ограничениям"); resultlabel.Text = "-"; logstr += " - Неудача!"; } listBox1.Items.Add(logstr + "\t\t"); logstr = ""; }