Example #1
0
        static void Main(string[] args)
        {
            var path   = Path.Combine(GraphData.Directory, GraphData.FileName);
            var reader = new FileReader(path);
            var data   = reader.ReadAllText();

            var edges = StringGraph.ToEdgeList(data);

            Console.WriteLine("Input");
            Console.WriteLine("1. The distance of the route A-B-C");
            Console.WriteLine("2. The distance of the route A-D.");
            Console.WriteLine("3. The distance of the route A-D-C.");
            Console.WriteLine("4. The distance of the route A-E-B-C-D.");
            Console.WriteLine("5. The distance of the route A-E-D.");
            Console.WriteLine("6. The number of trips starting at C and ending at C with a maximum of 3 stops.");
            Console.WriteLine("7. The number of trips starting at A and ending at C with exactly 4 stops.");
            Console.WriteLine("8. The length of the shortest route (in terms of distance to travel) from A to C.");
            Console.WriteLine("9. The length of the shortest route (in terms of distance to travel) from B to B.");
            Console.WriteLine("10. The number of different routes from C to C with a distance of less than 30.");
            Console.WriteLine("\n");
            Console.WriteLine("Output");
            PrintDistance(edges, 1, "A-B-C");
            PrintDistance(edges, 2, "A-D");
            PrintDistance(edges, 3, "A-D-C");
            PrintDistance(edges, 4, "A-E-B-C-D");
            PrintDistance(edges, 5, "A-E-D");
            PrintMaxStops(edges, 6, 'C', 'C', 3);
            PrintExactMaxStops(edges, 7, 'A', 'C', 4);
            PrintShortestDistance(edges, 8, 'A', 'C');
            PrintShortestDistance(edges, 9, 'B', 'B');
            PrintDifferentRoutes(edges, 10, 'C', 'C', 30);
        }
Example #2
0
        public void ToEdgeList()
        {
            var edges    = StringGraph.ToEdgeList(_Graph);
            var expected = new List <Edge>()
            {
                new Edge('A', 'B', 5),
                new Edge('B', 'C', 4),
                new Edge('C', 'D', 8),
                new Edge('D', 'C', 8),
                new Edge('D', 'E', 6),
                new Edge('A', 'D', 5),
                new Edge('C', 'E', 2),
                new Edge('E', 'B', 3),
                new Edge('A', 'E', 7),
            };

            for (int i = 0; i < expected.Count; i++)
            {
                Assert.AreEqual(expected[i].From, edges[i].From);
                Assert.AreEqual(expected[i].To, edges[i].To);
                Assert.AreEqual(expected[i].Cost, edges[i].Cost);
            }
        }