Exemplo n.º 1
0
 private void miAddObjectLast_Click(object sender, EventArgs e)
 {
     FormTemp form_temp = new FormTemp() { Text = "Введите ширину и высоту прямоугольника:", Width = ClientSize.Width };
     form_temp.ShowDialog(this);
     try
     {
         string[] s = form_temp.String.Split(' ');
         task.ObjectsSizesAdd(task.ObjectsCount, new Vector2d { X = double.Parse(s[0]), Y = double.Parse(s[1]) });
         dgvObjects.DataSource = task.Objects_BindingSource();
         if (form_placement_opt != null && !form_placement_opt.IsDisposed)
             form_placement_opt.Placement = task.PlacementOpt;
         if (form_placement_last != null && !form_placement_last.IsDisposed)
             form_placement_last.Placement = task.PlacementLast;
     }
     catch { }
 }
Exemplo n.º 2
0
 private void miSpeed_Click(object sender, EventArgs e)
 {
     FormTemp form_temp = new FormTemp() { Text = "Введите интервал обновления:", Width = ClientSize.Width };
     form_temp.ShowDialog(this);
     try
     {
         timer1.Interval = int.Parse(form_temp.String);
     }
     catch { }
 }
Exemplo n.º 3
0
        private void miStatistic_Click(object sender, EventArgs e)
        {
            if (form_placement_opt != null && !form_placement_opt.IsDisposed)
                form_placement_opt.Close();
            if (form_placement_last != null && !form_placement_last.IsDisposed)
                form_placement_last.Close();

            Random rand = new Random();
            FormTemp form_temp = new FormTemp() { Text = "Введите количество опытов:", Width = ClientSize.Width };
            form_temp.ShowDialog(this);
            try
            {
                int count_of_oput = int.Parse(form_temp.String);
                StreamWriter sw = new StreamWriter(this.task.TaskIndex.ToString() + ".stc");
                sw.Close();

                for (int i_of_oput = 0; i_of_oput < count_of_oput; i_of_oput++)
                {
                    // Количество итераций метода значимых переменных при одном размещении.
                    int count_of_mzp = rand.Next(1, 10);
                    // Количество всех итераций метода значимых переменных.
                    int count_of_iteration = rand.Next(1, 10);
                    // Количество объектов (не больше 50).
                    int count_of_objects = rand.Next(1, 50);
                    // Размеры объектов от 10 до 110.
                    float min_of_objects = 100 * (float)rand.NextDouble() + 10;
                    float max_of_objects = 100 * (float)rand.NextDouble() + min_of_objects;
                    // Размеры области от 10 до 1000.
                    float min_of_region = 1000 * (float)rand.NextDouble() + 10;
                    float max_of_region = 1000 * (float)rand.NextDouble() + min_of_objects;
                    Task task = new Task();
                    // Создание объектов.
                    for (int i = 0; i < count_of_objects; i++)
                        task.ObjectsSizesAdd(0, new Vector2d { X = (max_of_objects - min_of_objects) * rand.NextDouble() + min_of_objects, Y = (max_of_objects - min_of_objects) * rand.NextDouble() + min_of_objects });
                    task.TaskIndex = this.task.TaskIndex;
                    task.RegionWidth = (max_of_region - min_of_region) * (float)rand.NextDouble() + min_of_region;
                    task.RegionHeight = (max_of_region - min_of_region) * (float)rand.NextDouble() + min_of_region;

                    // Поиск методом случайного поиска.
                    for (int i = 0; i < (count_of_mzp + 1) * count_of_iteration; i++)
                        task.Calculate(true);
                    double opt = task.PlacementOpt.ObjectFunction;


                    task.TaskIndex = task.TaskIndex;
                    task.NumberOfUpgrade = count_of_mzp;
                    // Поиск методом случайного поиска + методом значимых переменных.
                    for (int i = 0; i < count_of_iteration; i++)
                        task.Calculate(true);
                    double opt_mzp = task.PlacementOpt.ObjectFunction;

                    #region Сохранение статистики.
                    if (opt != 0 && !double.IsInfinity(opt) && !double.IsNaN(opt) && opt_mzp != 0 && !double.IsInfinity(opt_mzp) && !double.IsNaN(opt_mzp))
                    {
                        sw = new StreamWriter(task.TaskIndex.ToString() + ".stc", true);
                        int op = 0;
                        if (opt / opt_mzp - 1 > 0)
                            op = 1;
                        if (opt / opt_mzp - 1 < 0)
                            op = -1;
                        sw.WriteLine("{0} {1} {2} {3} {4}", i_of_oput, opt, opt_mzp, opt / opt_mzp - 1, op);
                        sw.Close();
                    }
                    else
                        i_of_oput--;
                    #endregion
                }
                MessageBox.Show(this, "Статистика сохранена в файле " + this.task.TaskIndex.ToString() + ".stc.", "Информация");
            }
            catch { }
        }
Exemplo n.º 4
0
 private void miSteps_Click(object sender, EventArgs e)
 {
     FormTemp form_temp = new FormTemp() { Text = "Введите количество шагов:", Width = ClientSize.Width };
     form_temp.ShowDialog(this);
     try
     {
         int n = int.Parse(form_temp.String);
         for (int i = 0; i < n; i++)
             miStep_Click(sender, e);
     }
     catch { }
 }
Exemplo n.º 5
0
 private void miDelObjects_Click(object sender, EventArgs e)
 {
     FormTemp form_temp = new FormTemp() { Text = "Введите индекс и количество прямоугольников:", Width = ClientSize.Width };
     form_temp.ShowDialog(this);
     try
     {
         string[] s = form_temp.String.Split(' ');
         int n = int.Parse(s[0]);
         int m = int.Parse(s[1]);
         for (int i = 0; i < m; i++)
             task.ObjectsSizesDel(task.ObjectsCount - 1);
         dgvObjects.DataSource = task.Objects_BindingSource();
         if (form_placement_opt != null && !form_placement_opt.IsDisposed)
             form_placement_opt.Placement = task.PlacementOpt;
         if (form_placement_last != null && !form_placement_last.IsDisposed)
             form_placement_last.Placement = task.PlacementLast;
     }
     catch { }
 }
Exemplo n.º 6
0
 private void miDelObjectByIndex_Click(object sender, EventArgs e)
 {
     FormTemp form_temp = new FormTemp() { Text = "Введите индекс прямоугольника:", Width = ClientSize.Width };
     form_temp.ShowDialog(this);
     try
     {
         task.ObjectsSizesDel(int.Parse(form_temp.String));
         dgvObjects.DataSource = task.Objects_BindingSource();
         if (form_placement_opt != null && !form_placement_opt.IsDisposed)
             form_placement_opt.Placement = task.PlacementOpt;
         if (form_placement_last != null && !form_placement_last.IsDisposed)
             form_placement_last.Placement = task.PlacementLast;
     }
     catch { }
 }
Exemplo n.º 7
0
 private void miAddObjects_Click(object sender, EventArgs e)
 {
     Random rand = new Random();
     FormTemp form_temp = new FormTemp() { Text = "Введите количество, минимум и максимум размера прямоугольника:", Width = ClientSize.Width };
     form_temp.ShowDialog(this);
     try
     {
         string[] s = form_temp.String.Split(' ');
         int n = int.Parse(s[0]);
         float min = float.Parse(s[1]);
         float max = float.Parse(s[2]);
         for (int i = 0; i < n; i++)
             task.ObjectsSizesAdd(task.ObjectsCount, new Vector2d { X = (max - min) * rand.NextDouble() + min, Y = (max - min) * rand.NextDouble() + min });
         dgvObjects.DataSource = task.Objects_BindingSource();
         if (form_placement_opt != null && !form_placement_opt.IsDisposed)
             form_placement_opt.Placement = task.PlacementOpt;
         if (form_placement_last != null && !form_placement_last.IsDisposed)
             form_placement_last.Placement = task.PlacementLast;
     }
     catch { }
 }