Example #1
0
        static void Main(string[] args)
        {
            CreateGraf("input.txt");
            List <Graf> grafs     = ReadAddFile("input.txt");
            Graf        graf      = new Graf(0, 0, 0, 0, 0);
            int         vertCount = grafs.Count - 1;
            int         edgCount  = grafs.Count - 1;

            Console.WriteLine("Vert " + vertCount);
            Console.WriteLine("edge " + edgCount);

            graf.sets = new int[vertCount];
            for (int i = 1; i < vertCount; i++)
            {
                graf.sets[i] = i;
            }

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            graf.BuildSpanningTree(vertCount, grafs);
            stopwatch.Stop();
            TimeSpan ts = stopwatch.Elapsed;

            // Format and display the TimeSpan value.
            string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                                               ts.Hours, ts.Minutes, ts.Seconds,
                                               ts.Milliseconds / 10);

            Console.WriteLine("RunTime " + elapsedTime);

            //graf.DisplayInfo(vertCount);
            // Console.WriteLine("Cost: " + graf.Cost);
            //List<Graf> grafs3 = new List<Graf>();
            //List<Graf> grafs2 = new List<Graf>();
            //grafs3.Add(new Graf(1, 2, 3, 2, 1));
            //grafs3.Add(new Graf(1, 3, 2, 2, 1));
            //Graf graf = new Graf(0, 0, 0, 0, 0);
            //graf.sets = new int[10];
            //for (int i = 1; i < 10; i++)
            //    graf.sets[i] = i;
            //int result = 2;
            //graf.BuildSpanningTree(2, grafs3);
        }
Example #2
0
        public Graf AddVertex(int first, int second, int distance, int vert, int edg)
        {
            Graf graf = new Graf(first, second, distance, vert, edg);

            return(graf);
        }