Beispiel #1
0
        public static GraphMatrixInc ConvertToMatrixInc(GraphList input)
        {
            GraphList from = new GraphList(1);

            from.Set(input);
            int sumc = 0;

            for (int i = 0; i < from.NodesNr; i++)
            {
                sumc += from.CountElem(i);
            }
            sumc = sumc / 2;
            GraphMatrixInc q = new GraphMatrixInc(from.NodesNr, sumc);
            int            c = 0;

            for (int i = 0; i < from.NodesNr; i++)//pobiera po kolei elementy, dodaje do matrixinc i usuwa z listy
            {
                for (int j = 0; j < from.NodesNr; j++)
                {
                    if (from.GetConnection(i, j))
                    {
                        q.MakeConnection(i, j, c);
                        c++;
                        from.RemoveConnection(i, j);
                    }
                    q.setWeight(i, j, input.getWeight(i, j));
                }
            }
            return(q);
        }
Beispiel #2
0
        public static GraphList LoadList(string path)
        {
            if (!File.Exists(path))
            {
                throw new Exception("File does not exist");
            }
            StreamReader sr = new StreamReader(path);

            string[] s = new string [1000];
            s[0] = sr.ReadLine();
            int i = 0;

            while (s[i] != null)
            {
                s[i + 1] = sr.ReadLine();
                i++;
            }


            GraphList graph = new GraphList(i);

            int[] tab    = new int[100];
            int   liczba = 0;

            for (int j = 0; j < i; j++)
            {
                for (int k = 0; k < s[j].Length - 1; k += 4)
                {
                    if (s[j][k] == '\n')
                    {
                        break;
                    }
                    tab[0] = s[j][k] - 48;
                    tab[1] = s[j][k + 1] - 48;
                    tab[2] = s[j][k + 2] - 48;
                    liczba = 100 * tab[0] + 10 * tab[1] + tab[2];
                    if (!graph.GetConnection(j, liczba))
                    {
                        graph.MakeConnection(j, liczba);
                    }
                }
            }



            sr.Close();
            return(graph);
        }
Beispiel #3
0
        public GraphList GetList()
        {
            GraphList List = new GraphList(Items.Count);

            foreach (var item in Items)
            {
                var i = item.NodeNumber;
                foreach (var connection in item.ConnectedNodes)
                {
                    if (List.GetConnection(connection, i))
                    {
                        List.MakeConnection(i, connection);
                    }
                }
            }
            return(List);
        }
Beispiel #4
0
 /// <summary>
 /// Przeszukiwanie w glab, uzupelnia liste o sciezke eulera
 /// </summary>
 /// <param name="f">lista po ktorej sie poruszamy</param>
 /// <param name="p">lista wynikowa, dodajemy do niej pary (skad, dokad) idziemy</param>
 /// <param name="n">aktualny wezel</param>
 /// <param name="c">liczba polaczen</param>
 /// <returns>false gdy nie jest eulerowski</returns>
 private static bool Eul(GraphList f, List <Tuple <int, int> > p, int n, int c)//graf, lista do uzupel, aktualny wezel, liczba polaczen
 {
     if (p.Count == c)
     {
         return(true);
     }
     for (int i = 0; i < f.NodesNr; i++)
     {
         if (f.GetConnection(n, i))
         {
             if (!p.Contains(new Tuple <int, int>(n, i)) && !p.Contains(new Tuple <int, int>(i, n)))
             {
                 p.Add(new Tuple <int, int>(n, i));
                 if (Eul(f, p, i, c))
                 {
                     return(true);
                 }
                 p.Remove(new Tuple <int, int>(n, i));
             }
         }
     }
     return(false);
 }