Beispiel #1
0
 /// <summary>
 /// Получить копию матрицы
 /// </summary>
 /// <returns></returns>
 public VengerMatrix Copy()
 {
     VengerMatrix m = new VengerMatrix(N);
     for (int i = 0; i < N; i++)
         for (int j = 0; j < N; j++)
             m._c[i][j] = new Element(_c[i][j]._value, _c[i][j]._mark);
     return m;
 }
Beispiel #2
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);
        }
Beispiel #3
0
        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();
        }
Beispiel #4
0
 public void minimize(ref VengerMatrix c)
 {
     double tau = c.getMax();
     c.subFromTau(tau);
 }
Beispiel #5
0
        private VengerMatrix _c; // Исходная матрица стоимостей

        #endregion Fields

        #region Constructors

        // Constructors
        public VengerAlgorithm(VengerMatrix c)
        {
            _c = c;
        }
Beispiel #6
0
 /// <summary>
 /// Подготовительный этап.
 /// 1.Вычесть из каждого столбца минимальный находящийся в нем элемент.
 /// 2.Вычесть из каждой строки минимальный находящийся в ней элемент.
 /// </summary>
 /// <returns> Эквивалентная матрица стоимостей </returns>
 private void getNewMatrix(ref VengerMatrix c)
 {
     //VengerMatrix c = _c.Copy();
     for (int i = 0; i < c.N; i++)
     {
         double min = c.getMinInColumn(i);
         c.subFromColumn(i, min);
     }
     for (int i = 0; i < c.N; i++)
     {
         double min = c.getMinInRow(i);
         c.subFromRow(i, min);
     }
 }
Beispiel #7
0
 private LChain buildLChain(VengerMatrix c, int i, int j)
 {
     LChain chain = new LChain(c.N * c.N);
     chain.add(i, j);
     while ((i = c.hasMarkedElementInColumn(j, '*')) != -1)
     {
         chain.add(i, j);
         j = c.hasMarkedElementInRow(i, '\'');
         chain.add(i, j);
     }
     return chain;
 }
Beispiel #8
0
 /// <summary>
 /// Построение первоначальной СНН
 /// </summary>
 /// <param name="c"></param>
 private void buildInitialINS(ref VengerMatrix c)
 {
     c.K = 0;
     for (int j = 0; j < c.N; j++)
         for (int i = 0; i < c.N; i++)
             if (c.get(i, j) == 0.0 && (c.hasMarkedElementInRow(i, '*') == -1))
             {
                 c.markElement(i, j, '*');
                 c.K++;
                 break;
             }
 }