Example #1
0
        static void Main(string[] args)
        {
            int  VertacyCount = 10;
            int  EdgesCount   = 20;
            bool Symmetric    = false;

            MatrixGraph <string, float> x = new MatrixGraph <string, float>(VertacyCount, Symmetric);

            for (int i = 0; i < VertacyCount; i++)
            {
                x.Data[i] = GetRandomString();
            }
            Random r = new Random(DateTime.Now.Millisecond);

            for (int i = 0; i < EdgesCount;)
            {
                int index1 = r.Next(0, x.Size);
                int index2 = r.Next(0, x.Size);
                if (index1 != index2)
                {
                    x.Connect(index1, index2, r.Next(0, 11));
                    i++;
                }
            }

            foreach (string y in x.Data)
            {
                Console.WriteLine("Created node : " + y + " ");
            }

            Console.WriteLine();
            PrintConnections(x.Connections);

            for (int i = 0; i < x.Size; i++)
            {
                for (int j = 0; j < x.Size; j++)
                {
                    if (i == j)
                    {
                        continue;
                    }
                    Console.BackgroundColor = ConsoleColor.White;
                    Console.ForegroundColor = ConsoleColor.Black;
                    Console.Write("Paths from " + i + " to " + j + " !");
                    Console.ResetColor();
                    Console.WriteLine();
                    Dictionary <string, List <float> > Paths = x.DFSAllPaths(i, j);
                    if (Paths.Count == 0)
                    {
                        Console.BackgroundColor = ConsoleColor.Red;
                        Console.ForegroundColor = ConsoleColor.Black;
                        Console.Write("No paths found!");
                        Console.ResetColor();
                        Console.WriteLine();
                    }
                    for (int k = 0; k < Paths.Count; k++)
                    {
                        Console.WriteLine("Path : " + Paths.Keys.ToList()[k]);
                        foreach (float l in Paths.Values.ToList()[k])
                        {
                            Console.Write(l + " ");
                        }
                        Console.Write("\t");
                        Console.BackgroundColor = ConsoleColor.White;
                        Console.ForegroundColor = ConsoleColor.Black;
                        Console.Write("Path weight : " + Paths.Values.ToList()[k].Sum() + "\t Path grade: " + (Paths.Values.ToList()[k].Sum()) / Paths.Values.ToList()[k].Count());
                        Console.ResetColor();
                        Console.WriteLine();
                        Console.WriteLine();
                    }
                }
            }

            Console.ReadKey();
        }