Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Выбираем случайную точку
- for (int i = 0; i < xSize.Value; i++)
- {
- x = "x" + (i + 1).ToString();
- double space = Convert.ToDouble(xDiap.Rows[i].Cells[2].Value) - Convert.ToDouble(xDiap.Rows[i].Cells[0].Value);
- x_min_rand[i] = rand.NextDouble() * space + Convert.ToDouble(xDiap.Rows[i].Cells[0].Value);
- func.Parameters[x] = x_min_rand[i];
- }
- // вычисляем функцию
- f = Convert.ToDouble(func.Evaluate());
- for (int p = 0; p < xSize.Value; p++)
- {
- x_min[p] = x_min_rand[p];
- x_min_lin[p] = x_min_rand[p];
- }
- f_min = f;
- while (T > 1E-15)
- {
- for (int i = 0; i < L; i++)
- {
- // Шаг 2.1. Выбираем новую точку х' из eps-окрестности точки х
- for (int j = 0; j < xSize.Value; j++)
- {
- x = "x" + (j + 1).ToString();
- x_min_2[j] = rand.NextDouble() * 2*eps+(x_min[j] - eps);
- double xUp = Convert.ToDouble(xDiap.Rows[j].Cells[2].Value)
- if (x_min_2[j] > xUp)
- {
- x_min_2[j] = xUp;
- }
- double xDown = Convert.ToDouble(xDiap.Rows[j].Cells[0].Value)
- if (x_min_2[j] < xDown)
- {
- x_min_2[j] = xDown;
- }
- func.Parameters[x] = x_min_2[j];
- }
- f2 = Convert.ToDouble(func.Evaluate()); // f(x')
- // Шаг 2.2. Рассчитываем изменение целевой функции
- delta = f2 - f_min;
- // если разница <= 0, то
- if (delta <= 0)
- {
- // x = x'
- for (int p = 0; p < xSize.Value; p++)
- {
- x_min[p] = x_min_2[p];
- }
- f_min = f2;
- }
- else
- {
- // иначе если ...
- if (Math.Exp(-delta / T) > rand.NextDouble())
- {
- // x = x'
- for (int p = 0; p < xSize.Value; p++)
- {
- x_min[p] = x_min_2[p];
- }
- f_min = f2;
- }
- }
- list.Add(counter, f_min);
- if (f_min < f_min_lin)
- {
- f_min_lin = f_min;
- for (int p = 0; p < xSize.Value; p++)
- {
- x_min_lin[p] = x_min[p];
- }
- }
- counter++;
- }
- // Шаг 3. Уменьшаем температуру
- T *= r;
- progressBar1.PerformStep();
- }
Advertisement
Add Comment
Please, Sign In to add comment