示例#1
0
文件: Cutting.cs 项目: tgr484/Diploma
        public void S_task()
        {
            detailList.reset_cb();
            detailList.update_work_list();
            calc_y_first();
            cuttintgPatternList.Clear();


            while (!detailList.check_empty_wl())
            {
                detailList.sort_by__y();
                calc_barier();
                Cutting_Pattern cp = new Cutting_Pattern(M, L);
                double          _f;
                double          fi;
                double          old_barier  = 0;
                int             place_count = 1;
                int             prev        = 0;
                detailList.current_detail = 0;
                bool was_step_back = false;
                while (cp.h >= detailList.calc_min() && !detailList.check_empty_wl())
                {
                    if (cp.h < detailList.work_list[detailList.current_detail].l && !was_step_back)
                    {
                        detailList.next();
                        continue;
                    }
                    _f = detailList.work_list[detailList.current_detail]._y * cp.h;
                    if (_f >= barier) // step forward //запатчтил остаток
                    {
                        if (detailList.work_list[detailList.current_detail].cb >= place_count)
                        {
                            for (int i = 0; i < place_count; ++i)
                            {
                                cp.add_detail(detailList.work_list[detailList.current_detail]);
                            }
                            detailList.work_list[detailList.current_detail].cb -= place_count;
                        }
                        else
                        {
                            for (int i = 0; i < detailList.work_list[detailList.current_detail].cb; ++i)
                            {
                                cp.add_detail(detailList.work_list[detailList.current_detail]);
                            }
                            detailList.work_list[detailList.current_detail].cb = 0;
                        }
                        fi         = detailList.work_list[detailList.current_detail].y * cp.map[detailList.work_list[detailList.current_detail].i];
                        old_barier = barier;
                        prev       = detailList.current_detail;
                        barier    -= fi;
                        detailList.next();
                        was_step_back = false;
                        place_count   = 1;
                    }
                    else // step back
                    {
                        if (was_step_back)
                        {
                            barier *= 0.8;
                            continue;
                        }
                        detailList.current_detail = prev;
                        try
                        {
                            cp.remove_detail(detailList.work_list[detailList.current_detail]);
                        }
                        catch
                        {
                            detailList.current_detail--;
                            cp.remove_detail(detailList.work_list[detailList.current_detail]);
                        }
                        detailList.work_list[detailList.current_detail].cb += place_count;
                        barier = old_barier;
                        place_count++;
                        was_step_back = true;
                    }
                }
                cuttintgPatternList.Add(cp);

                if (!detailList.check_empty_wl())
                {
                    calc_y();
                }
                //else
            }
        }
示例#2
0
文件: Form1.cs 项目: tgr484/Diploma
        private void button_create_cutting_best_Click_1(object sender, EventArgs e)
        {
            if (Convert.ToDouble(tb_length_A.Text) >= Convert.ToDouble(tb_length_B.Text))
            {
                MessageBox.Show("Интервал неверный", "Ошибка");
                return;
            }
            if (dg_input.Rows.Count < 2)
            {
                MessageBox.Show("Деталей для раскроя должно быть, как минимум две", "Ошибка");
                return;
            }
            if (Convert.ToDouble(tb_length_A.Text) < dl.calc_max())
            {
                MessageBox.Show("Одна из деталей длиннее наименьшей заготовки", "Ошибка");
                return;
            }
            dg_output.Rows.Clear();
            dg_output.Columns.Clear();
            List <Cutting> cuttings = new List <Cutting>();

            dl = new Detail_list(dg_input.RowCount - 1);
            dl.list.Clear();
            dg_to_dl();
            for (int i = Convert.ToInt32(tb_length_A.Text); i <= Convert.ToInt32(tb_length_B.Text); ++i)
            {
                cuttings.Add(new Cutting(i, dl));
            }
            int    best_i    = 0;
            double best_coef = 0;
            int    map_count = 0;

            for (int i = 0; i < cuttings.Count; ++i)
            {
                dl.reset_cb();
                cuttings[i].create_ffd_cutting_map();
                cuttings[i].calc_botton_border();
                if (cuttings[i].cuttintgPatternList.Count > cuttings[i].bottom_border)
                {
                    int j = 0;
                    while (true)
                    {
                        cuttings[i].S_task();
                        ++j;
                        if (cuttings[i].cuttintgPatternList.Count == cuttings[i].bottom_border || j > 100)
                        {
                            break;
                        }
                    }
                }
                cuttings[i].calc_coef();
                if (i == 0)
                {
                    best_i    = 0;
                    best_coef = cuttings[i].cutting_coef;
                    map_count = cuttings[i].cuttintgPatternList.Count;
                }
                else
                {
                    if (cuttings[i].cutting_coef > best_coef || map_count > cuttings[i].cuttintgPatternList.Count)
                    {
                        best_i    = i;
                        best_coef = cuttings[i].cutting_coef;
                        map_count = cuttings[i].cuttintgPatternList.Count;
                    }
                }
            }
            output(cuttings[best_i]);
            label_best.Text = cuttings[best_i].L.ToString();
        }