Beispiel #1
0
        static void Main(string[] args)
        {
            BellmanFord s = new BellmanFord(6);

            s.AddRoad(1, 2, 7);
            s.AddRoad(2, 4, 2);
            s.AddRoad(1, 3, 6);
            s.AddRoad(3, 4, 5);
            s.AddRoad(4, 5, 3);
            //s.AddRoad(6, 7, 3);



            Console.WriteLine(s.Calculate(1, 5)); // 12

            Console.WriteLine();


            Dijkstra ss = new Dijkstra(6);

            ss.AddRoad(1, 2, 7);
            ss.AddRoad(2, 4, 2);
            ss.AddRoad(1, 3, 6);
            ss.AddRoad(3, 4, 5);
            ss.AddRoad(4, 5, 3);
            //ss.Addroad(4, 5, 3);
            Console.WriteLine(ss.Calculate(1, 5)); // 12

            Console.WriteLine();

            FloydWarshall f = new FloydWarshall(5);

            f.AddRoad(1, 2, 7);
            f.AddRoad(2, 4, 2);
            f.AddRoad(1, 3, 6);
            f.AddRoad(3, 4, 5);
            f.AddRoad(4, 5, 3);
            //s.AddRoad(6, 7, 3);
            Console.WriteLine(f.Calculate(1, 5)); // 12

            Console.WriteLine();

            ShortestPath sh = new ShortestPath(5);

            sh.AddRoad(1, 2, 7);
            sh.AddRoad(2, 4, 2);
            sh.AddRoad(1, 3, 6);
            sh.AddRoad(3, 4, 5);
            sh.AddRoad(4, 5, 3);
            sh.Create(1, 5).ForEach(Console.Write); // 1245
            Console.WriteLine();
            sh.Create(1, 2).ForEach(Console.Write); // 12
            Console.WriteLine();
            sh.Create(1, 4).ForEach(Console.Write); // 124
            Console.WriteLine();
            sh.Create(4, 1).ForEach(Console.Write); // 421
            Console.WriteLine();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            /*
             * BellmanFord bf1 = new BellmanFord(5);
             * bf1.AddRoad(1, 2, 7);
             * bf1.AddRoad(2, 4, 2);
             * bf1.AddRoad(1, 3, 6);
             * bf1.AddRoad(3, 4, 5);
             * bf1.AddRoad(4, 5, 3);
             * Console.WriteLine(bf1.Calculate(1, 5));
             * //   Console.WriteLine(bf1.ToString()); //1 2 5  1 3 1  2 4 3  3 2 2  4 3 4
             */
            /*
             * Dijkstra d = new Dijkstra(6);
             * d.AddRoad(1, 2, 7);
             * d.AddRoad(2, 4, 2);
             * d.AddRoad(1, 3, 6);
             * d.AddRoad(3, 4, 5);
             * d.AddRoad(4, 5, 3);
             * Console.WriteLine(d.Calculate(1, 5)); // 12
             */
            /*
             * FloydWarshall fw = new FloydWarshall(5);
             * fw.AddRoad(1, 2, 7);
             * fw.AddRoad(2, 4, 2);
             * fw.AddRoad(1, 3, 6);
             * fw.AddRoad(3, 4, 5);
             * fw.AddRoad(4, 5, 3);
             * //   Console.WriteLine(fw.ToString()); //1 2 5  1 3 1  2 4 3  3 2 2  4 3 4
             * Console.WriteLine(fw.Calculate(1, 5)); // 12
             */

            ShortestPath sp = new ShortestPath(6);

            sp.AddRoad(1, 2, 7);
            sp.AddRoad(2, 4, 2);
            sp.AddRoad(1, 3, 6);
            sp.AddRoad(3, 4, 5);
            sp.AddRoad(4, 5, 3);
            List <int> result = sp.Calculate(1, 5);
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            /*//Exercise 1
             *
             * BellmanFord s = new BellmanFord(5);
             * s.AddRoad(1, 2, 7);
             * s.AddRoad(2, 4, 2);
             * s.AddRoad(1, 3, 6);
             * s.AddRoad(3, 4, 5);
             * s.AddRoad(4, 5, 3);
             * Console.WriteLine(s.Calculate(1, 5)); // 12*/

            /*//Exercise 2
             * Dijkstra s = new Dijkstra(5);
             * s.AddRoad(1, 2, 7);
             * s.AddRoad(2, 4, 2);
             * s.AddRoad(1, 3, 6);
             * s.AddRoad(3, 4, 5);
             * s.AddRoad(4, 5, 3);
             * Console.WriteLine(s.Calculate(1, 5)); // 12*/

            /*//Exercise 3
             * FloydWarshall fw = new FloydWarshall(5);
             * fw.AddRoad(1, 2, 7);
             * fw.AddRoad(2, 4, 2);
             * fw.AddRoad(1, 3, 6);
             * fw.AddRoad(3, 4, 5);
             * fw.AddRoad(4, 5, 3);
             * Console.WriteLine(fw.Calculate(1, 2)); // 12 (should be 7??)*/

            //Exercise 4
            ShortestPath s = new ShortestPath(5);

            s.AddRoad(1, 2, 7);
            s.AddRoad(2, 4, 2);
            s.AddRoad(1, 3, 6);
            s.AddRoad(3, 4, 5);
            s.AddRoad(4, 5, 3);
            s.Create(1, 5).ForEach(Console.Write); // 1245
        }
        static void Main(string[] args)
        {
            //Ex 1,2,3
            ShortestPath s = new ShortestPath(5);

            s.AddRoad(1, 2, 7);
            s.AddRoad(2, 4, 2);
            s.AddRoad(1, 3, 6);
            s.AddRoad(3, 4, 5);
            s.AddRoad(4, 5, 3);
            //s.AddRoad(6, 7, 3); // -1
            Console.WriteLine(s.Calculate(1, 5)); // 12

            //Ex 4

            /*ShortestPath s = new ShortestPath(5);
             * s.AddRoad(1, 2, 7);
             * s.AddRoad(2, 4, 2);
             * s.AddRoad(1, 3, 6);
             * s.AddRoad(3, 4, 5);
             * s.AddRoad(4, 5, 3);
             * s.Create(1, 5).ForEach(Console.Write); // 1245*/
        }