示例#1
0
        private void fillTableSimplexMethod(DataGridView dgv, src.SMethod.SimplexMethodSolver slv)
        {
            dgv.Rows.Clear();
            dgv.Columns.Clear();
            if (slv.errMsg != "OK")
            {
                MessageBox.Show(slv.errMsg, "Симплекс-метод", MessageBoxButtons.OK);
            }

            String[] strs = new String[slv.xsStr.Count + 2];
            strs[0] = "";

            for (int i = 0; i < slv.xsStr.Count; i++)
            {
                strs[i + 1] = "-x" + slv.xsStr[i].ToString();
            }
            strs[slv.xsStr.Count + 1] = "1";

            for (int i = 0; i < slv.xsStr.Count + 2; i++)
            {
                dgv.Columns.Add("", strs[i]);
            }
            dgv.Columns[0].DefaultCellStyle.BackColor = Color.LightGray;
            dgv.Rows.Add(strs);
            dgv.Rows[0].DefaultCellStyle.BackColor = Color.LightGray;
            dgv.Columns[0].Width = 50;
            for (int i = 0; i < slv.xsCol.Count - 1; i++)
            {
                strs = new String[slv.xsStr.Count + 2];
                int index = 0;
                if (slv.xsCol[i] != 0)
                {
                    strs[index] = "x" + slv.xsCol[i].ToString() + "=";
                }
                else
                {
                    strs[index] = "0=";
                }

                index++;
                for (int j = 0; j < slv.table.GetLength(1); j++)
                {
                    strs[index] += slv.table[i, j].ToString().Replace(',', '.');
                    index++;
                }
                dgv.Rows.Add(strs);
            }
            strs    = new String[slv.xsStr.Count + 2];
            strs[0] = "Q";
            for (int i = 0; i < slv.table.GetLength(1); i++)
            {
                strs[i + 1] = Math.Abs(slv.table[slv.table.GetLength(0) - 1, i]).ToString().Replace(',', '.') + "\t";
            }

            dgv.Rows.Add(strs);
        }
示例#2
0
        private void fillTableCutAndSimplexMethod(Task task)
        {
            dgvAllCuts.Rows.Clear();
              dgvAllCuts.Columns.Clear();

              dgvAllCuts.Columns.Add("det", "det");
              dgvAllCuts.Columns[0].DefaultCellStyle.BackColor = Color.LightGray;
              for (int i = 0; i < task.AllCuts.Count; i++)
            dgvAllCuts.Columns.Add((i + 1).ToString(), (i + 1).ToString());
              dgvAllCuts.Columns.Add("num", "num");

              String[] str = new String[task.AllCuts.Count + 2];
              str[0] = "det";
              for (int i = 0; i < task.AllCuts.Count; i++)
            str[i + 1] = (i + 1).ToString();
              str[task.AllCuts.Count + 1] = "num";

              dgvAllCuts.Rows.Add(str);
              dgvAllCuts.Rows[0].DefaultCellStyle.BackColor = Color.LightGray;

              List<src.SMethod.Limitation> limits = new List<src.SMethod.Limitation>();
              OrderPair pair = task.order.First();
              while (pair != null) {
            str[0] = pair.Detail.Volume.ToString();
            str[task.AllCuts.Count + 1] = pair.Num.ToString();

            limits.Add(new src.SMethod.Limitation(new double[] { }, pair.Num, src.SMethod.Limitation.Type.Equal));
            for (int i = 0; i < task.AllCuts.Count; i++) {
              str[i + 1] = task.AllCuts[i].CountOf(pair.Detail).ToString();
              limits.Last().equaLine.koeffs.Add(task.AllCuts[i].CountOf(pair.Detail));
            }
            dgvAllCuts.Rows.Add(str);
            pair = task.GetNextOrderPair(pair);
              }
              String[] str2 = new String[task.AllCuts.Count + 2];
              dgvAllCuts.Rows.Add(str2);
              str[0] = "left";
              str[task.AllCuts.Count + 1] = "";

              src.SMethod.EquaLine equa = new src.SMethod.EquaLine(new double[] { }, 0.0);
              for (int i = 0; i < task.AllCuts.Count; i++) {
            str[i + 1] = Math.Round(task.AllCuts[i].Left, 3).ToString().Replace(',', '.');
            equa.koeffs.Add(task.AllCuts[i].Left);
              }

              src.SMethod.Task sTask = new src.SMethod.Task(equa);
              foreach (src.SMethod.Limitation limit in limits)
            sTask.limitations.Add(limit);
              solver = new src.SMethod.SimplexMethodSolver(sTask);

              dgvAllCuts.Rows.Add(str);
              solver.calculateOptimalPlan();
        }
示例#3
0
        private void fillTableResult(DataGridView dgv, Task task, src.SMethod.SimplexMethodSolver slv)
        {
            dgv.Rows.Clear();
            dgv.Columns.Clear();

            if (slv.errMsg != "OK")
            {
                return;
            }

            List <OrderPair> savedOrder = new List <OrderPair>();

            foreach (OrderPair p in order)
            {
                savedOrder.Add(new OrderPair(new Detail1D(pgrdOrderDetail, new double[] { p.Detail.Volume }), p.Num));
            }

            String[] strs = new String[3];
            strs[0] = "Число заготовок:";
            strs[1] = "Разрез:";
            strs[2] = "Остатки:";

            dgv.Columns.Add("", ""); dgv.Columns.Add("", ""); dgv.Columns.Add("", "");

            dgv.Rows.Add(strs);
            dgv.Rows[0].DefaultCellStyle.BackColor = Color.LightGray;
            dgv.Columns[0].Width = 150; dgv.Columns[2].Width = 100;

            double allLeft = 0.0;

            for (int i = 0; i < slv.xsCol.Count - 1; i++)
            {
                if (slv.table[i, slv.table.GetLength(1) - 1] == 0.0)
                {
                    continue;
                }

                int rounded = (int)slv.table[i, slv.table.GetLength(1) - 1];

                strs[0] = rounded.ToString();
                strs[1] = "";
                foreach (OrderPair p in task.AllCuts[slv.xsCol[i] - 1].Pairs)
                {
                    for (int j = 0; j < p.Num; j++)
                    {
                        strs[1] += (((Detail1D)p.Detail).Length).ToString().Replace(',', '.');
                        foreach (OrderPair oP in order)
                        {
                            if (((Detail1D)oP.Detail).Length == ((Detail1D)p.Detail).Length)
                            {
                                oP.Num -= rounded;
                                break;
                            }
                        }

                        if (j == p.Num - 1)
                        {
                            if (p != task.AllCuts[slv.xsCol[i] - 1].Pairs.Last())
                            {
                                strs[1] += ",";
                            }
                        }
                        else
                        {
                            strs[1] += ",";
                        }
                    }
                }
                strs[2]  = Math.Round(task.AllCuts[slv.xsCol[i] - 1].Left, 3).ToString().Replace(',', '.');
                allLeft += task.AllCuts[slv.xsCol[i] - 1].Left * rounded;
                dgv.Rows.Add(strs);
            }

            // ЖАДНЫЙ
            List <src.Cut> leftCuts      = greedyAlgorithm();
            double         greedyCutLeft = 0.0;

            foreach (Cut cut in leftCuts)
            {
                strs[0] = "1"; strs[1] = "";
                foreach (OrderPair p in cut.Pairs)
                {
                    for (int j = 0; j < p.Num; j++)
                    {
                        strs[1] += (((Detail1D)p.Detail).Length).ToString().Replace(',', '.');
                        foreach (OrderPair oP in order)
                        {
                            if (((Detail1D)oP.Detail).Length == ((Detail1D)p.Detail).Length)
                            {
                                oP.Num -= 1;
                                break;
                            }
                        }

                        if (j == p.Num - 1)
                        {
                            if (p != cut.Pairs.Last())
                            {
                                strs[1] += ",";
                            }
                        }
                        else
                        {
                            strs[1] += ",";
                        }
                    }
                }
                strs[2]        = Math.Round(cut.Left, 3).ToString().Replace(',', '.');
                greedyCutLeft += cut.Left;
                dgv.Rows.Add(strs);
            }

            strs[0] = strs[1] = strs[2] = "";
            dgv.Rows.Add(strs);
            strs[0] = "Общие:";
            strs[2] = Math.Round(allLeft, 3).ToString().Replace(',', '.') + " + " + Math.Round(greedyCutLeft, 3).ToString().Replace(',', '.');
            dgv.Rows.Add(strs);
            dgv.Rows[dgv.Rows.Count - 1].DefaultCellStyle.BackColor = Color.Gray;

            order = savedOrder;
        }
示例#4
0
        private void fillTableCutAndSimplexMethod(Task task)
        {
            dgvAllCuts.Rows.Clear();
            dgvAllCuts.Columns.Clear();

            dgvAllCuts.Columns.Add("det", "det");
            dgvAllCuts.Columns[0].DefaultCellStyle.BackColor = Color.LightGray;
            for (int i = 0; i < task.AllCuts.Count; i++)
            {
                dgvAllCuts.Columns.Add((i + 1).ToString(), (i + 1).ToString());
            }
            dgvAllCuts.Columns.Add("num", "num");

            String[] str = new String[task.AllCuts.Count + 2];
            str[0] = "det";
            for (int i = 0; i < task.AllCuts.Count; i++)
            {
                str[i + 1] = (i + 1).ToString();
            }
            str[task.AllCuts.Count + 1] = "num";

            dgvAllCuts.Rows.Add(str);
            dgvAllCuts.Rows[0].DefaultCellStyle.BackColor = Color.LightGray;

            List <src.SMethod.Limitation> limits = new List <src.SMethod.Limitation>();
            OrderPair pair = task.order.First();

            while (pair != null)
            {
                str[0] = pair.Detail.Volume.ToString();
                str[task.AllCuts.Count + 1] = pair.Num.ToString();

                limits.Add(new src.SMethod.Limitation(new double[] { }, pair.Num, src.SMethod.Limitation.Type.Equal));
                for (int i = 0; i < task.AllCuts.Count; i++)
                {
                    str[i + 1] = task.AllCuts[i].CountOf(pair.Detail).ToString();
                    limits.Last().equaLine.koeffs.Add(task.AllCuts[i].CountOf(pair.Detail));
                }
                dgvAllCuts.Rows.Add(str);
                pair = task.GetNextOrderPair(pair);
            }
            String[] str2 = new String[task.AllCuts.Count + 2];
            dgvAllCuts.Rows.Add(str2);
            str[0] = "left";
            str[task.AllCuts.Count + 1] = "";

            src.SMethod.EquaLine equa = new src.SMethod.EquaLine(new double[] { }, 0.0);
            for (int i = 0; i < task.AllCuts.Count; i++)
            {
                str[i + 1] = Math.Round(task.AllCuts[i].Left, 3).ToString().Replace(',', '.');
                equa.koeffs.Add(task.AllCuts[i].Left);
            }

            src.SMethod.Task sTask = new src.SMethod.Task(equa);
            foreach (src.SMethod.Limitation limit in limits)
            {
                sTask.limitations.Add(limit);
            }
            solver = new src.SMethod.SimplexMethodSolver(sTask);

            dgvAllCuts.Rows.Add(str);
            solver.calculateOptimalPlan();
        }