Ejemplo n.º 1
0
 private void bLoadGraph_Click(object sender, EventArgs e)
 {
     if (rCustomGraph.Text != "")
     {
         try
         {
             string[] rows = rCustomGraph.Text.Split('\n');
             int      n    = rows[0].Split(',').Length;
             int[,] final = new int[n, n];
             for (int i = 0; i < final.GetLength(0); i++)
             {
                 if (rows[i] != "")
                 {
                     string[] numbers = rows[i].Split(',');
                     for (int j = 0; j < final.GetLength(1); j++)
                     {
                         int num = Convert.ToInt16(numbers[j]);
                         if (i != j)
                         {
                             if (num < 0)
                             {
                                 num = 0;
                             }
                             final[i, j] = num;
                         }
                     }
                 }
             }
             if (!GraphConsistency.CheckConsistency(final))
             {
                 MessageBox.Show("Nie wszystkie wierzchołki grafu są połączone");
             }
             else
             {
                 sfmLcanvas1.Graf            = final;
                 NUDsink.Maximum             = NUDsource.Maximum = sfmLcanvas1.Graf.GetLength(0);
                 NUDsource.Value             = NUDsink.Value = 1;
                 sfmLcanvas1.EdmondsKarpMode = false;
                 //wypisywanie poprawionego
                 rCustomGraph.Text = "";
                 for (int i = 0; i < final.GetLength(0); i++)
                 {
                     for (int j = 0; j < final.GetLength(1); j++)
                     {
                         rCustomGraph.Text += final[i, j] + (j != final.GetLength(1) - 1 ? "," : "\n");
                     }
                 }
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show("Macierz pojemności grafu jest nieprawidłowa\nPrzykładowa macierz:\n0,2,4\n2,0,3\n1,2,0\nUjemne elementy i elementy na diagonali zostaną wyzerowane");
         }
     }
 }
Ejemplo n.º 2
0
 public static int[,] Generate(int vcount, bool directed, bool mixed = true)
 {
     int[,] result = new int[0, 0];
     do
     {
         if (directed && mixed)
         {
             result = GenerateDirectedMixed(vcount);
         }
         if (directed && !mixed)
         {
             result = GenerateDirectedNonMixed(vcount);
         }
         if (!directed)
         {
             result = GenerateNonDirected(vcount);
         }
     } while (!GraphConsistency.CheckConsistency(result));
     return(result);
 }