private void button1_Click(object sender, EventArgs e) { if (dataGridView1.Rows[0].Cells[1].Value != null && dataGridView1.Rows[0].Cells[2].Value != null && dataGridView1.Rows[1].Cells[1].Value != null && dataGridView1.Rows[1].Cells[2].Value != null) { //создать начальную популяцию if ((comboBox1.SelectedIndex != -1) && (comboBoxSelectParams.SelectedIndex != -1)) { int z = comboBox1.SelectedIndex; obl[0, 0] = Convert.ToDouble(dataGridView1.Rows[0].Cells[1].Value); obl[0, 1] = Convert.ToDouble(dataGridView1.Rows[0].Cells[2].Value); obl[1, 0] = Convert.ToDouble(dataGridView1.Rows[1].Cells[1].Value); obl[1, 1] = Convert.ToDouble(dataGridView1.Rows[1].Cells[2].Value); population = Convert.ToInt32(dataGridView2.Rows[0].Cells[1].Value); MaxIteration = Convert.ToInt32(dataGridView2.Rows[1].Cells[1].Value); Params param = (comboBoxSelectParams.SelectedIndex == 0) ? Params.Linear : Params.Quadratic; alg = new Algoritm(); Wolf result = alg.FastStartAlg(population, MaxIteration, obl, z, param); dataGridView3.Rows[0].Cells[1].Value = string.Format($"{result.coords[0]:F8}"); dataGridView3.Rows[1].Cells[1].Value = string.Format($"{result.coords[1]:F8}"); dataGridView3.Rows[2].Cells[1].Value = string.Format($"{result.fitness:F8}"); flag2 = true; pictureBox1.Refresh(); } } else { MessageBox.Show("Введите корректные параметры", "Ошибка при запуске алгоритма", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void buttonStart_Click(object sender, EventArgs e) { if (!flag) { //заполнение массива состояний Red[0] = true; for (int i = 1; i < stepsCount; i++) { Red[i] = false; } flag = true; //Начало работы алгоритма algst = new Algoritm { MaxCount = MaxIteration, population = PopulationCount, f = z, D = obl }; algst.FormingPopulation(); algst.currentIteration = 1; // Счетчик итераций dataGridViewIterationInfo.Rows[0].Cells[1].Value = algst.currentIteration; dataGridViewIterationInfo.Rows[1].Cells[1].Value = algst.population; dataGridViewIterationInfo.Rows[2].Cells[1].Value = algst.MaxCount; dataGridViewIterationInfo.Refresh(); pictureBoxDiagramm.Refresh(); pictureBox1.Refresh(); } }
private void buttonAnalysis_Click(object sender, EventArgs e) { if (dataGridView1.Rows[0].Cells[1].Value != null && dataGridView1.Rows[0].Cells[2].Value != null && dataGridView1.Rows[1].Cells[1].Value != null && dataGridView1.Rows[1].Cells[2].Value != null) { if ((comboBox1.SelectedIndex != -1) && (comboBoxSelectParams.SelectedIndex != -1)) { obl[0, 0] = Convert.ToDouble(dataGridView1.Rows[0].Cells[1].Value); obl[0, 1] = Convert.ToDouble(dataGridView1.Rows[0].Cells[2].Value); obl[1, 0] = Convert.ToDouble(dataGridView1.Rows[1].Cells[1].Value); obl[1, 1] = Convert.ToDouble(dataGridView1.Rows[1].Cells[2].Value); List <double> averFuncDeviation = new List <double>(); double minDeviation = 0; int successCount = 0; double eps = Math.Max(Math.Abs(obl[0, 0] - obl[0, 1]), Math.Abs(obl[1, 0] - obl[1, 1])) / 1000f; double averDer = 0; double normalDerivation = 0; int z = comboBox1.SelectedIndex; population = Convert.ToInt32(dataGridView2.Rows[0].Cells[1].Value); MaxIteration = Convert.ToInt32(dataGridView2.Rows[1].Cells[1].Value); Params param = (comboBoxSelectParams.SelectedIndex == 0) ? Params.Linear : Params.Quadratic; for (int i = 0; i < 100; i++) { alg = new Algoritm(); Wolf result = alg.FastStartAlg(population, MaxIteration, obl, z, param); foreach (Vector item in exactPoints) { if ((Math.Abs(result.coords[0] - item[0]) < eps) && (Math.Abs(result.coords[1] - item[1]) < eps)) { successCount++; break; } } averFuncDeviation.Add(Math.Abs(result.fitness - exact)); } double deltaSum = 0; for (int i = 0; i < 100; i++) { deltaSum += averFuncDeviation[i]; } averDer = deltaSum / 100f; averFuncDeviation.Sort(); minDeviation = averFuncDeviation[0]; double dispersion = 0; for (int i = 0; i < 100; i++) { dispersion += Math.Pow(averFuncDeviation[i] - averDer, 2); } normalDerivation = Math.Sqrt((dispersion / 100f)); FileStream fs = new FileStream("protocol.txt", FileMode.Append, FileAccess.Write); StreamWriter r = new StreamWriter(fs); r.Write(String.Format(@"| {0, 4} | {1, 6} | {2, 6} |{3, 22:f6} |{4, 20:f6} |{5, 20:f6} |{6, 12} | |---------------+------------------+---------------------+----------------------------------------+----------------------------------+--------------------------------+---------------------|", z + 1, population, MaxIteration, averDer, minDeviation, normalDerivation, successCount)); r.Write("\n"); r.Close(); fs.Close(); Process.Start("protocol.txt"); } } else { MessageBox.Show("Введите корректные параметры", "Ошибка при запуске алгоритма", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }