示例#1
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            int n  = tblCosts.Rows.Count;
            VengerMatrix m = new VengerMatrix(n);
            double[][] c = readMatrix();
            m.setMatrix(c);
            VengerAlgorithm va = new VengerAlgorithm(m);
            String s = "";
            Task t = new Task(n, c);
            BranchAndBoundAlgorithm bba = new BranchAndBoundAlgorithm(t);
            double totalCost;
            int[][] path = bba.start(out totalCost);
            txtResult.Text = pathToString(path);
            lblTotalCost.Text = String.Format("Общая стоимость проезда по маршруту: {0} руб.", totalCost);
            /* if (dbg)
                 va.startDebug(max, out opt, out f, out s);
             else
                 va.start(max, out opt, out f);*/

            //        s += printOptimalMatrix(opt, 5);
        }
示例#2
0
文件: Form1.cs 项目: sunny-hell/bmstu
        private void button1_Click(object sender, EventArgs e)
        {
            VengerMatrix m;
            int n;
            double[][] c;
            try
            {
                if (rand)
                {
                    n = Int32.Parse(txtSize.Text);
                    m = new VengerMatrix(n);
                    c = createRandomMatrix(n);
                    m.setMatrix(c);
                    rtbSource.Text = m.print();
                }
                else
                {
                    n = Int32.Parse(txtSize.Text);
                    m = new VengerMatrix(n);
                    c = readMatrix(n);

                    //double[][] c = {
                    //         new double [5]{10.0, 12.0, 7.0, 11.0, 10.0},
                    //         new double [5]{12.0, 5.0, 12.0, 7.0, 12.0},
                    //         new double [5]{8.0, 6.0, 7.0, 8.0, 13.0},
                    //         new double [5]{8.0, 11.0, 5.0, 9.0, 9.0},
                    //         new double [5]{10.0, 8.0, 9.0, 11.0, 11.0}};
                    //int[][] c = {
                    //         new int [5]{0, 0, 0, 0, 0},
                    //         new int [5]{0, 0, 0, 0, 0},
                    //         new int [5]{0, 0, 0, 0, 0},
                    //         new int [5]{0, 0, 0, 0, 0},
                    //         new int [5]{0, 0, 0, 0, 0}};
                    m.setMatrix(c);
                }

                VengerAlgorithm va = new VengerAlgorithm(m);
                String s = "";
                int[][] opt;
                double f;
                Task t = new Task(n, c);
                BranchAndBoundAlgorithm bba = new BranchAndBoundAlgorithm(t);
                bba.start(dbg, out s);

               /* if (dbg)
                    va.startDebug(max, out opt, out f, out s);
                else
                    va.start(max, out opt, out f);*/

            //        s += printOptimalMatrix(opt, 5);

                rtbResult.Text = s; // m.print();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            //for (int i = 0; i < m.N; i++)
            //    rtbResult.Text += (m.getMinInRow(i) + "\t");
            //rtbResult.Text += "\n";

            //VengerMatrix m2 = m.Copy();
            //rtbResult.Text += "\n" + m2.print();
        }